summaryrefslogtreecommitdiff
path: root/kernel-7.1/freebsd-route-messages-respect-fib-2.patch
blob: 93a2ae7579af903564c0c42eb97fc8bc699e0c4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
--- ./sys/net/rtsock.c.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/net/rtsock.c	2009-09-11 00:07:13.000000000 +0000
@@ -83,4 +83,9 @@
     &rtsintrq.ifq_maxlen, 0, "maximum routing socket dispatch queue length");
 
+struct rt_dispatch_ctx {
+	unsigned short family;  /* Socket family */
+	int            fibnum;  /* FIB for message or -1 for all */
+};	
+
 struct walkarg {
 	int	w_tmemsize;
@@ -104,5 +109,5 @@
 static void	rt_getmetrics(const struct rt_metrics_lite *in,
 			struct rt_metrics *out);
-static void	rt_dispatch(struct mbuf *, const struct sockaddr *);
+static void	rt_dispatch(struct mbuf *, const struct sockaddr *, int);
 
 static void
@@ -123,17 +128,19 @@
 {
 	struct sockproto route_proto;
-	unsigned short *family;
+	struct rt_dispatch_ctx *ctx;
 	struct m_tag *tag;
+	int fibnum = -1;
 
 	route_proto.sp_family = PF_ROUTE;
-	tag = m_tag_find(m, PACKET_TAG_RTSOCKFAM, NULL);
+	tag = m_tag_find(m, PACKET_TAG_RTSOCK, NULL);
 	if (tag != NULL) {
-		family = (unsigned short *)(tag + 1);
-		route_proto.sp_protocol = *family;
+		ctx = (struct rt_dispatch_ctx*)(tag + 1);
+		route_proto.sp_protocol = ctx->family;
+		fibnum = ctx->fibnum;
 		m_tag_delete(m, tag);
 	} else
 		route_proto.sp_protocol = 0;
 
-	raw_input(m, &route_proto, &route_src);
+	raw_input(m, &route_proto, &route_src, fibnum);
 }
 
@@ -605,8 +612,8 @@
 			unsigned short family = rp->rcb_proto.sp_family;
 			rp->rcb_proto.sp_family = 0;
-			rt_dispatch(m, info.rti_info[RTAX_DST]);
+			rt_dispatch(m, info.rti_info[RTAX_DST], so->so_fibnum);
 			rp->rcb_proto.sp_family = family;
 		} else
-			rt_dispatch(m, info.rti_info[RTAX_DST]);
+			rt_dispatch(m, info.rti_info[RTAX_DST], so->so_fibnum);
 	}
     }
@@ -829,5 +836,5 @@
  */
 void
-rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
+rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error, int fibnum)
 {
 	struct rt_msghdr *rtm;
@@ -844,5 +851,5 @@
 	rtm->rtm_errno = error;
 	rtm->rtm_addrs = rtinfo->rti_addrs;
-	rt_dispatch(m, sa);
+	rt_dispatch(m, sa, fibnum);
 }
 
@@ -869,5 +876,5 @@
 	ifm->ifm_data = ifp->if_data;
 	ifm->ifm_addrs = 0;
-	rt_dispatch(m, NULL);
+	rt_dispatch(m, NULL, -1);
 }
 
@@ -881,5 +888,5 @@
  */
 void
-rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
+rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt, int fibnum)
 {
 	struct rt_addrinfo info;
@@ -937,5 +944,5 @@
 			rtm->rtm_addrs = info.rti_addrs;
 		}
-		rt_dispatch(m, sa);
+		rt_dispatch(m, sa, fibnum);
 	}
 }
@@ -973,5 +980,5 @@
 	ifmam->ifmam_index = ifp->if_index;
 	ifmam->ifmam_addrs = info.rti_addrs;
-	rt_dispatch(m, ifma->ifma_addr);
+	rt_dispatch(m, ifma->ifma_addr, -1);
 }
 
@@ -1033,5 +1040,5 @@
 			m->m_pkthdr.len += data_len;
 		mtod(m, struct if_announcemsghdr *)->ifan_msglen += data_len;
-		rt_dispatch(m, NULL);
+		rt_dispatch(m, NULL, -1);
 	}
 }
@@ -1049,10 +1056,11 @@
 	m = rt_makeifannouncemsg(ifp, RTM_IFANNOUNCE, what, &info);
 	if (m != NULL)
-		rt_dispatch(m, NULL);
+		rt_dispatch(m, NULL, -1);
 }
 
 static void
-rt_dispatch(struct mbuf *m, const struct sockaddr *sa)
+rt_dispatch(struct mbuf *m, const struct sockaddr *sa, int fibnum)
 {
+	struct rt_dispatch_ctx *ctx;
 	struct m_tag *tag;
 
@@ -1060,14 +1068,16 @@
 	 * Preserve the family from the sockaddr, if any, in an m_tag for
 	 * use when injecting the mbuf into the routing socket buffer from
-	 * the netisr.
+	 * the netisr. Additionally save the fibnum if needed.
 	 */
-	if (sa != NULL) {
-		tag = m_tag_get(PACKET_TAG_RTSOCKFAM, sizeof(unsigned short),
-		    M_NOWAIT);
+	if (sa != NULL || fibnum >= 0) {
+		tag = m_tag_get(PACKET_TAG_RTSOCK, 
+		                sizeof(struct rt_dispatch_ctx*), M_NOWAIT);
 		if (tag == NULL) {
 			m_freem(m);
 			return;
 		}
-		*(unsigned short *)(tag + 1) = sa->sa_family;
+		ctx = (struct rt_dispatch_ctx*)(tag + 1);
+		ctx->family = sa->sa_family;
+		ctx->fibnum = fibnum;
 		m_tag_prepend(m, tag);
 	}
--- ./sys/net/raw_usrreq.c.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/net/raw_usrreq.c	2009-09-11 00:07:13.000000000 +0000
@@ -68,5 +68,5 @@
  */
 void
-raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src)
+raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src, int fibnum)
 {
 	struct rawcb *rp;
@@ -82,4 +82,7 @@
 		    rp->rcb_proto.sp_protocol != proto->sp_protocol)
 			continue;
+		if (fibnum >= 0 && rp->rcb_socket &&
+		    fibnum != rp->rcb_socket->so_fibnum) 
+			continue; 
 		if (last) {
 			struct mbuf *n;
--- ./sys/net/raw_cb.h.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/net/raw_cb.h	2009-09-11 00:07:13.000000000 +0000
@@ -71,5 +71,5 @@
 int	 raw_attach(struct socket *, int);
 void	 raw_detach(struct rawcb *);
-void	 raw_input(struct mbuf *, struct sockproto *, struct sockaddr *);
+void	 raw_input(struct mbuf *, struct sockproto *, struct sockaddr *, int);
 
 /*
--- ./sys/net/route.c.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/net/route.c	2009-09-11 00:08:28.000000000 +0000
@@ -338,5 +338,5 @@
 				info.rti_info[RTAX_IFA] = newrt->rt_ifa->ifa_addr;
 			}
-			rt_missmsg(RTM_ADD, &info, newrt->rt_flags, 0);
+			rt_missmsg(RTM_ADD, &info, newrt->rt_flags, 0, fibnum);
 		} else {
 			KASSERT(rt == newrt, ("locking wrong route"));
@@ -362,5 +362,5 @@
 			bzero(&info, sizeof(info));
 			info.rti_info[RTAX_DST] = dst;
-			rt_missmsg(msgtype, &info, 0, err);
+			rt_missmsg(msgtype, &info, 0, err, fibnum);
 		}
 	}
@@ -575,5 +575,5 @@
 	info.rti_info[RTAX_NETMASK] = netmask;
 	info.rti_info[RTAX_AUTHOR] = src;
-	rt_missmsg(RTM_REDIRECT, &info, flags, error);
+	rt_missmsg(RTM_REDIRECT, &info, flags, error, fibnum);
 }
 
@@ -1464,5 +1464,5 @@
 			 */
 			RT_LOCK(rt);
-			rt_newaddrmsg(cmd, ifa, error, rt);
+			rt_newaddrmsg(cmd, ifa, error, rt, fibnum);
 			if (cmd == RTM_DELETE) {
 				/*
--- ./sys/net/route.h.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/net/route.h	2009-09-11 00:07:13.000000000 +0000
@@ -350,6 +350,6 @@
 void	 rt_ifannouncemsg(struct ifnet *, int);
 void	 rt_ifmsg(struct ifnet *);
-void	 rt_missmsg(int, struct rt_addrinfo *, int, int);
-void	 rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *);
+void	 rt_missmsg(int, struct rt_addrinfo *, int, int, int);
+void	 rt_newaddrmsg(int, struct ifaddr *, int, struct rtentry *, int);
 void	 rt_newmaddrmsg(int, struct ifmultiaddr *);
 int	 rt_setgate(struct rtentry *, struct sockaddr *, struct sockaddr *);
--- ./sys/netinet6/nd6_rtr.c.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/netinet6/nd6_rtr.c	2009-09-11 00:07:13.000000000 +0000
@@ -444,5 +444,5 @@
 	}
 
-	rt_missmsg(cmd, &info, rt->rt_flags, 0);
+	rt_missmsg(cmd, &info, rt->rt_flags, 0, -1);
 }
 
--- ./sys/netinet6/in6.c.orig	2009-06-10 10:31:11.000000000 +0000
+++ ./sys/netinet6/in6.c	2009-09-11 00:09:37.000000000 +0000
@@ -190,5 +190,5 @@
 		}
 
-		rt_newaddrmsg(cmd, ifa, e, nrt);
+		rt_newaddrmsg(cmd, ifa, e, nrt, -1);
 		if (cmd == RTM_DELETE)
 			RTFREE_LOCKED(nrt);
--- ./sys/sys/mbuf.h.orig	2008-11-25 02:59:29.000000000 +0000
+++ ./sys/sys/mbuf.h	2009-09-11 00:10:16.000000000 +0000
@@ -852,5 +852,5 @@
 #define	PACKET_TAG_MACLABEL	(19 | MTAG_PERSISTENT) /* MAC label */
 #define	PACKET_TAG_PF				21 /* PF + ALTQ information */
-#define	PACKET_TAG_RTSOCKFAM			25 /* rtsock sa family */
+#define	PACKET_TAG_RTSOCK			25 /* rtsock extra info */
 #define	PACKET_TAG_IPOPTIONS			27 /* Saved IP options */
 #define	PACKET_TAG_CARP                         28 /* CARP info */