summaryrefslogtreecommitdiff
path: root/kernel-9.0/freebsd-route-messages-respect-fib-2.patch
blob: cd4b99f670754b087d1a13e8b333d0dee2fb05a8 (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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
--- ./sys/net/rtsock.c.orig	2009-08-31 15:26:03.000000000 +0000
+++ ./sys/net/rtsock.c	2009-08-31 19:06:53.000000000 +0000
@@ -93,4 +93,9 @@
 SYSCTL_NODE(_net, OID_AUTO, route, CTLFLAG_RD, 0, "");
 
+struct rt_dispatch_ctx {
+	unsigned short family;  /* Socket family */
+	int            fibnum;  /* FIB for message or -1 for all */
+};	
+
 struct walkarg {
 	int	w_tmemsize;
@@ -114,5 +119,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 struct netisr_handler rtsock_nh = {
@@ -155,17 +160,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);
 }
 
@@ -784,8 +791,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);
 	}
     }
@@ -1010,5 +1017,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;
@@ -1025,5 +1032,5 @@
 	rtm->rtm_errno = error;
 	rtm->rtm_addrs = rtinfo->rti_addrs;
-	rt_dispatch(m, sa);
+	rt_dispatch(m, sa, fibnum);
 }
 
@@ -1050,5 +1057,5 @@
 	ifm->ifm_data = ifp->if_data;
 	ifm->ifm_addrs = 0;
-	rt_dispatch(m, NULL);
+	rt_dispatch(m, NULL, -1);
 }
 
@@ -1062,5 +1069,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;
@@ -1120,5 +1127,5 @@
 			rtm->rtm_addrs = info.rti_addrs;
 		}
-		rt_dispatch(m, sa);
+		rt_dispatch(m, sa, fibnum);
 	}
 }
@@ -1156,5 +1163,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);
 }
 
@@ -1216,5 +1223,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);
 	}
 }
@@ -1232,10 +1239,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;
 
@@ -1243,14 +1251,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	2009-08-31 16:04:58.000000000 +0000
+++ ./sys/net/raw_usrreq.c	2009-08-31 18:34:38.000000000 +0000
@@ -70,5 +70,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;
@@ -84,4 +84,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	2009-08-31 18:34:56.000000000 +0000
+++ ./sys/net/raw_cb.h	2009-08-31 18:35:05.000000000 +0000
@@ -73,5 +73,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	2009-08-31 18:18:30.000000000 +0000
+++ ./sys/net/route.c	2009-08-31 18:59:20.000000000 +0000
@@ -384,5 +384,5 @@
 		bzero(&info, sizeof(info));
 		info.rti_info[RTAX_DST] = dst;
-		rt_missmsg(msgtype, &info, 0, err);
+		rt_missmsg(msgtype, &info, 0, err, fibnum);
 	}	
 done:
@@ -609,5 +609,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);
 	if (ifa != NULL)
 		ifa_free(ifa);
@@ -1433,5 +1433,5 @@
 				rt->rt_ifp->if_index;
 			}
-			rt_newaddrmsg(cmd, ifa, error, rt);
+			rt_newaddrmsg(cmd, ifa, error, rt, fibnum);
 			if (cmd == RTM_DELETE) {
 				/*
--- ./sys/net/route.h.orig	2009-08-31 18:56:05.000000000 +0000
+++ ./sys/net/route.h	2009-08-31 18:59:32.000000000 +0000
@@ -381,6 +381,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	2009-08-31 18:19:54.000000000 +0000
+++ ./sys/netinet6/nd6_rtr.c	2009-08-31 19:09:27.000000000 +0000
@@ -449,5 +449,5 @@
 		ifa = NULL;
 
-	rt_missmsg(cmd, &info, rt->rt_flags, 0);
+	rt_missmsg(cmd, &info, rt->rt_flags, 0, -1);
 	if (ifa != NULL)
 		ifa_free(ifa);
--- ./sys/netinet6/in6.c.orig	2009-08-31 19:00:43.000000000 +0000
+++ ./sys/netinet6/in6.c	2009-08-31 19:01:00.000000000 +0000
@@ -1238,5 +1238,5 @@
 	rt_key(&rt0) = (struct sockaddr *)&addr;
 	rt0.rt_flags = RTF_HOST | RTF_STATIC;
-	rt_newaddrmsg(RTM_DELETE, ifa, 0, &rt0);
+	rt_newaddrmsg(RTM_DELETE, ifa, 0, &rt0, -1);
 
 	/*
@@ -1831,5 +1831,5 @@
 		rt_key(&rt) = (struct sockaddr *)&addr;
 		rt.rt_flags = RTF_UP | RTF_HOST | RTF_STATIC;
-		rt_newaddrmsg(RTM_ADD, &ia->ia_ifa, 0, &rt);
+		rt_newaddrmsg(RTM_ADD, &ia->ia_ifa, 0, &rt, -1);
 	}
 
--- ./sys/sys/mbuf.h.orig	2009-08-31 18:26:12.000000000 +0000
+++ ./sys/sys/mbuf.h	2009-08-31 18:26:24.000000000 +0000
@@ -897,5 +897,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 */
--- sys/netinet/in.c.orig	2009-09-28 23:45:49.000000000 +0000
+++ sys/netinet/in.c	2009-09-28 23:46:35.000000000 +0000
@@ -1012,5 +1012,5 @@
 					rt_newaddrmsg(RTM_ADD, 
 						      (struct ifaddr *)target,
-						      0, &msg_rt);
+						      0, &msg_rt, -1);
 					RTFREE(pfx_ro.ro_rt);
 				}
@@ -1073,5 +1073,5 @@
 		rt_newaddrmsg(RTM_DELETE, 
 			      (struct ifaddr *)target,
-			      0, &rt);
+			      0, &rt, -1);
 		return (0);
 	}