rtsock.c revision 1.100.2.2 1 1.100.2.2 christos /* $NetBSD: rtsock.c,v 1.100.2.2 2008/03/29 20:47:02 christos Exp $ */
2 1.100.2.2 christos
3 1.100.2.2 christos /*
4 1.100.2.2 christos * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 1.100.2.2 christos * All rights reserved.
6 1.100.2.2 christos *
7 1.100.2.2 christos * Redistribution and use in source and binary forms, with or without
8 1.100.2.2 christos * modification, are permitted provided that the following conditions
9 1.100.2.2 christos * are met:
10 1.100.2.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.100.2.2 christos * notice, this list of conditions and the following disclaimer.
12 1.100.2.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.100.2.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.100.2.2 christos * documentation and/or other materials provided with the distribution.
15 1.100.2.2 christos * 3. Neither the name of the project nor the names of its contributors
16 1.100.2.2 christos * may be used to endorse or promote products derived from this software
17 1.100.2.2 christos * without specific prior written permission.
18 1.100.2.2 christos *
19 1.100.2.2 christos * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 1.100.2.2 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.100.2.2 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.100.2.2 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 1.100.2.2 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.100.2.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.100.2.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.100.2.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.100.2.2 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.100.2.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.100.2.2 christos * SUCH DAMAGE.
30 1.100.2.2 christos */
31 1.100.2.2 christos
32 1.100.2.2 christos /*
33 1.100.2.2 christos * Copyright (c) 1988, 1991, 1993
34 1.100.2.2 christos * The Regents of the University of California. All rights reserved.
35 1.100.2.2 christos *
36 1.100.2.2 christos * Redistribution and use in source and binary forms, with or without
37 1.100.2.2 christos * modification, are permitted provided that the following conditions
38 1.100.2.2 christos * are met:
39 1.100.2.2 christos * 1. Redistributions of source code must retain the above copyright
40 1.100.2.2 christos * notice, this list of conditions and the following disclaimer.
41 1.100.2.2 christos * 2. Redistributions in binary form must reproduce the above copyright
42 1.100.2.2 christos * notice, this list of conditions and the following disclaimer in the
43 1.100.2.2 christos * documentation and/or other materials provided with the distribution.
44 1.100.2.2 christos * 3. Neither the name of the University nor the names of its contributors
45 1.100.2.2 christos * may be used to endorse or promote products derived from this software
46 1.100.2.2 christos * without specific prior written permission.
47 1.100.2.2 christos *
48 1.100.2.2 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 1.100.2.2 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 1.100.2.2 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 1.100.2.2 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 1.100.2.2 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 1.100.2.2 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 1.100.2.2 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 1.100.2.2 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 1.100.2.2 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 1.100.2.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 1.100.2.2 christos * SUCH DAMAGE.
59 1.100.2.2 christos *
60 1.100.2.2 christos * @(#)rtsock.c 8.7 (Berkeley) 10/12/95
61 1.100.2.2 christos */
62 1.100.2.2 christos
63 1.100.2.2 christos #include <sys/cdefs.h>
64 1.100.2.2 christos __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.100.2.2 2008/03/29 20:47:02 christos Exp $");
65 1.100.2.2 christos
66 1.100.2.2 christos #include "opt_inet.h"
67 1.100.2.2 christos #include "opt_compat_netbsd.h"
68 1.100.2.2 christos
69 1.100.2.2 christos #include <sys/param.h>
70 1.100.2.2 christos #include <sys/systm.h>
71 1.100.2.2 christos #include <sys/proc.h>
72 1.100.2.2 christos #include <sys/mbuf.h>
73 1.100.2.2 christos #include <sys/socket.h>
74 1.100.2.2 christos #include <sys/socketvar.h>
75 1.100.2.2 christos #include <sys/domain.h>
76 1.100.2.2 christos #include <sys/protosw.h>
77 1.100.2.2 christos #include <sys/sysctl.h>
78 1.100.2.2 christos #include <sys/kauth.h>
79 1.100.2.2 christos #include <sys/intr.h>
80 1.100.2.2 christos #ifdef RTSOCK_DEBUG
81 1.100.2.2 christos #include <netinet/in.h>
82 1.100.2.2 christos #endif /* RTSOCK_DEBUG */
83 1.100.2.2 christos
84 1.100.2.2 christos #include <net/if.h>
85 1.100.2.2 christos #include <net/route.h>
86 1.100.2.2 christos #include <net/raw_cb.h>
87 1.100.2.2 christos
88 1.100.2.2 christos #if defined(COMPAT_14) || defined(COMPAT_50)
89 1.100.2.2 christos #include <compat/net/if.h>
90 1.100.2.2 christos #endif
91 1.100.2.2 christos
92 1.100.2.2 christos #include <machine/stdarg.h>
93 1.100.2.2 christos
94 1.100.2.2 christos DOMAIN_DEFINE(routedomain); /* forward declare and add to link set */
95 1.100.2.2 christos
96 1.100.2.2 christos struct sockaddr route_dst = { .sa_len = 2, .sa_family = PF_ROUTE, };
97 1.100.2.2 christos struct sockaddr route_src = { .sa_len = 2, .sa_family = PF_ROUTE, };
98 1.100.2.2 christos
99 1.100.2.2 christos int route_maxqlen = IFQ_MAXLEN;
100 1.100.2.2 christos static struct ifqueue route_intrq;
101 1.100.2.2 christos static void *route_sih;
102 1.100.2.2 christos
103 1.100.2.2 christos static int rt_msg2(int, struct rt_addrinfo *, void *, struct rt_walkarg *, int *);
104 1.100.2.2 christos static int rt_xaddrs(u_char, const char *, const char *, struct rt_addrinfo *);
105 1.100.2.2 christos static struct mbuf *rt_makeifannouncemsg(struct ifnet *, int, int,
106 1.100.2.2 christos struct rt_addrinfo *);
107 1.100.2.2 christos static int sysctl_dumpentry(struct rtentry *, void *);
108 1.100.2.2 christos static int sysctl_iflist(int, struct rt_walkarg *, int);
109 1.100.2.2 christos static int sysctl_rtable(SYSCTLFN_PROTO);
110 1.100.2.2 christos static inline void rt_adjustcount(int, int);
111 1.100.2.2 christos
112 1.100.2.2 christos /* Sleazy use of local variables throughout file, warning!!!! */
113 1.100.2.2 christos #define dst info.rti_info[RTAX_DST]
114 1.100.2.2 christos #define gate info.rti_info[RTAX_GATEWAY]
115 1.100.2.2 christos #define netmask info.rti_info[RTAX_NETMASK]
116 1.100.2.2 christos #define ifpaddr info.rti_info[RTAX_IFP]
117 1.100.2.2 christos #define ifaaddr info.rti_info[RTAX_IFA]
118 1.100.2.2 christos #define brdaddr info.rti_info[RTAX_BRD]
119 1.100.2.2 christos
120 1.100.2.2 christos static inline void
121 1.100.2.2 christos rt_adjustcount(int af, int cnt)
122 1.100.2.2 christos {
123 1.100.2.2 christos route_cb.any_count += cnt;
124 1.100.2.2 christos switch (af) {
125 1.100.2.2 christos case AF_INET:
126 1.100.2.2 christos route_cb.ip_count += cnt;
127 1.100.2.2 christos return;
128 1.100.2.2 christos #ifdef INET6
129 1.100.2.2 christos case AF_INET6:
130 1.100.2.2 christos route_cb.ip6_count += cnt;
131 1.100.2.2 christos return;
132 1.100.2.2 christos #endif
133 1.100.2.2 christos case AF_IPX:
134 1.100.2.2 christos route_cb.ipx_count += cnt;
135 1.100.2.2 christos return;
136 1.100.2.2 christos case AF_NS:
137 1.100.2.2 christos route_cb.ns_count += cnt;
138 1.100.2.2 christos return;
139 1.100.2.2 christos case AF_ISO:
140 1.100.2.2 christos route_cb.iso_count += cnt;
141 1.100.2.2 christos return;
142 1.100.2.2 christos }
143 1.100.2.2 christos }
144 1.100.2.2 christos static inline void
145 1.100.2.2 christos cvtmetrics(struct ort_metrics *ortm, const struct rt_metrics *rtm)
146 1.100.2.2 christos {
147 1.100.2.2 christos ortm->rmx_locks = rtm->rmx_locks;
148 1.100.2.2 christos ortm->rmx_mtu = rtm->rmx_mtu;
149 1.100.2.2 christos ortm->rmx_hopcount = rtm->rmx_hopcount;
150 1.100.2.2 christos ortm->rmx_expire = rtm->rmx_expire;
151 1.100.2.2 christos ortm->rmx_recvpipe = rtm->rmx_recvpipe;
152 1.100.2.2 christos ortm->rmx_sendpipe = rtm->rmx_sendpipe;
153 1.100.2.2 christos ortm->rmx_ssthresh = rtm->rmx_ssthresh;
154 1.100.2.2 christos ortm->rmx_rtt = rtm->rmx_rtt;
155 1.100.2.2 christos ortm->rmx_rttvar = rtm->rmx_rttvar;
156 1.100.2.2 christos ortm->rmx_pksent = rtm->rmx_pksent;
157 1.100.2.2 christos }
158 1.100.2.2 christos
159 1.100.2.2 christos /*ARGSUSED*/
160 1.100.2.2 christos int
161 1.100.2.2 christos route_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
162 1.100.2.2 christos struct mbuf *control, struct lwp *l)
163 1.100.2.2 christos {
164 1.100.2.2 christos int error = 0;
165 1.100.2.2 christos struct rawcb *rp = sotorawcb(so);
166 1.100.2.2 christos int s;
167 1.100.2.2 christos
168 1.100.2.2 christos if (req == PRU_ATTACH) {
169 1.100.2.2 christos MALLOC(rp, struct rawcb *, sizeof(*rp), M_PCB, M_WAITOK);
170 1.100.2.2 christos if ((so->so_pcb = rp) != NULL)
171 1.100.2.2 christos memset(so->so_pcb, 0, sizeof(*rp));
172 1.100.2.2 christos
173 1.100.2.2 christos }
174 1.100.2.2 christos if (req == PRU_DETACH && rp)
175 1.100.2.2 christos rt_adjustcount(rp->rcb_proto.sp_protocol, -1);
176 1.100.2.2 christos s = splsoftnet();
177 1.100.2.2 christos
178 1.100.2.2 christos /*
179 1.100.2.2 christos * Don't call raw_usrreq() in the attach case, because
180 1.100.2.2 christos * we want to allow non-privileged processes to listen on
181 1.100.2.2 christos * and send "safe" commands to the routing socket.
182 1.100.2.2 christos */
183 1.100.2.2 christos if (req == PRU_ATTACH) {
184 1.100.2.2 christos if (l == NULL)
185 1.100.2.2 christos error = EACCES;
186 1.100.2.2 christos else
187 1.100.2.2 christos error = raw_attach(so, (int)(long)nam);
188 1.100.2.2 christos } else
189 1.100.2.2 christos error = raw_usrreq(so, req, m, nam, control, l);
190 1.100.2.2 christos
191 1.100.2.2 christos rp = sotorawcb(so);
192 1.100.2.2 christos if (req == PRU_ATTACH && rp) {
193 1.100.2.2 christos if (error) {
194 1.100.2.2 christos free((void *)rp, M_PCB);
195 1.100.2.2 christos splx(s);
196 1.100.2.2 christos return error;
197 1.100.2.2 christos }
198 1.100.2.2 christos rt_adjustcount(rp->rcb_proto.sp_protocol, 1);
199 1.100.2.2 christos rp->rcb_laddr = &route_src;
200 1.100.2.2 christos rp->rcb_faddr = &route_dst;
201 1.100.2.2 christos soisconnected(so);
202 1.100.2.2 christos so->so_options |= SO_USELOOPBACK;
203 1.100.2.2 christos }
204 1.100.2.2 christos splx(s);
205 1.100.2.2 christos return error;
206 1.100.2.2 christos }
207 1.100.2.2 christos
208 1.100.2.2 christos static const struct sockaddr *
209 1.100.2.2 christos intern_netmask(const struct sockaddr *mask)
210 1.100.2.2 christos {
211 1.100.2.2 christos struct radix_node *rn;
212 1.100.2.2 christos extern struct radix_node_head *mask_rnhead;
213 1.100.2.2 christos
214 1.100.2.2 christos if (mask != NULL &&
215 1.100.2.2 christos (rn = rn_search(mask, mask_rnhead->rnh_treetop)))
216 1.100.2.2 christos mask = (const struct sockaddr *)rn->rn_key;
217 1.100.2.2 christos
218 1.100.2.2 christos return mask;
219 1.100.2.2 christos }
220 1.100.2.2 christos
221 1.100.2.2 christos /*ARGSUSED*/
222 1.100.2.2 christos int
223 1.100.2.2 christos route_output(struct mbuf *m, ...)
224 1.100.2.2 christos {
225 1.100.2.2 christos struct sockproto proto = { .sp_family = PF_ROUTE, };
226 1.100.2.2 christos struct rt_msghdr *rtm = NULL;
227 1.100.2.2 christos struct rtentry *rt = NULL;
228 1.100.2.2 christos struct rtentry *saved_nrt = NULL;
229 1.100.2.2 christos struct rt_addrinfo info;
230 1.100.2.2 christos int len, error = 0;
231 1.100.2.2 christos struct ifnet *ifp = NULL;
232 1.100.2.2 christos struct ifaddr *ifa = NULL;
233 1.100.2.2 christos struct socket *so;
234 1.100.2.2 christos va_list ap;
235 1.100.2.2 christos sa_family_t family;
236 1.100.2.2 christos
237 1.100.2.2 christos va_start(ap, m);
238 1.100.2.2 christos so = va_arg(ap, struct socket *);
239 1.100.2.2 christos va_end(ap);
240 1.100.2.2 christos
241 1.100.2.2 christos #define senderr(e) do { error = e; goto flush;} while (/*CONSTCOND*/ 0)
242 1.100.2.2 christos if (m == NULL || ((m->m_len < sizeof(int32_t)) &&
243 1.100.2.2 christos (m = m_pullup(m, sizeof(int32_t))) == NULL))
244 1.100.2.2 christos return ENOBUFS;
245 1.100.2.2 christos if ((m->m_flags & M_PKTHDR) == 0)
246 1.100.2.2 christos panic("route_output");
247 1.100.2.2 christos len = m->m_pkthdr.len;
248 1.100.2.2 christos if (len < sizeof(*rtm) ||
249 1.100.2.2 christos len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
250 1.100.2.2 christos dst = NULL;
251 1.100.2.2 christos senderr(EINVAL);
252 1.100.2.2 christos }
253 1.100.2.2 christos R_Malloc(rtm, struct rt_msghdr *, len);
254 1.100.2.2 christos if (rtm == NULL) {
255 1.100.2.2 christos dst = NULL;
256 1.100.2.2 christos senderr(ENOBUFS);
257 1.100.2.2 christos }
258 1.100.2.2 christos m_copydata(m, 0, len, (void *)rtm);
259 1.100.2.2 christos if (rtm->rtm_version != RTM_VERSION) {
260 1.100.2.2 christos dst = NULL;
261 1.100.2.2 christos senderr(EPROTONOSUPPORT);
262 1.100.2.2 christos }
263 1.100.2.2 christos rtm->rtm_pid = curproc->p_pid;
264 1.100.2.2 christos memset(&info, 0, sizeof(info));
265 1.100.2.2 christos info.rti_addrs = rtm->rtm_addrs;
266 1.100.2.2 christos if (rt_xaddrs(rtm->rtm_type, (void *)(rtm + 1), len + (char *)rtm, &info))
267 1.100.2.2 christos senderr(EINVAL);
268 1.100.2.2 christos info.rti_flags = rtm->rtm_flags;
269 1.100.2.2 christos #ifdef RTSOCK_DEBUG
270 1.100.2.2 christos if (dst->sa_family == AF_INET) {
271 1.100.2.2 christos printf("%s: extracted dst %s\n", __func__,
272 1.100.2.2 christos inet_ntoa(((const struct sockaddr_in *)dst)->sin_addr));
273 1.100.2.2 christos }
274 1.100.2.2 christos #endif /* RTSOCK_DEBUG */
275 1.100.2.2 christos if (dst == NULL || (dst->sa_family >= AF_MAX))
276 1.100.2.2 christos senderr(EINVAL);
277 1.100.2.2 christos if (gate != NULL && (gate->sa_family >= AF_MAX))
278 1.100.2.2 christos senderr(EINVAL);
279 1.100.2.2 christos
280 1.100.2.2 christos /*
281 1.100.2.2 christos * Verify that the caller has the appropriate privilege; RTM_GET
282 1.100.2.2 christos * is the only operation the non-superuser is allowed.
283 1.100.2.2 christos */
284 1.100.2.2 christos if (kauth_authorize_network(curlwp->l_cred, KAUTH_NETWORK_ROUTE,
285 1.100.2.2 christos 0, rtm, NULL, NULL) != 0)
286 1.100.2.2 christos senderr(EACCES);
287 1.100.2.2 christos
288 1.100.2.2 christos switch (rtm->rtm_type) {
289 1.100.2.2 christos
290 1.100.2.2 christos case RTM_ADD:
291 1.100.2.2 christos if (gate == NULL)
292 1.100.2.2 christos senderr(EINVAL);
293 1.100.2.2 christos error = rtrequest1(rtm->rtm_type, &info, &saved_nrt);
294 1.100.2.2 christos if (error == 0 && saved_nrt) {
295 1.100.2.2 christos rt_setmetrics(rtm->rtm_inits,
296 1.100.2.2 christos &rtm->rtm_rmx, &saved_nrt->rt_rmx);
297 1.100.2.2 christos saved_nrt->rt_refcnt--;
298 1.100.2.2 christos }
299 1.100.2.2 christos break;
300 1.100.2.2 christos
301 1.100.2.2 christos case RTM_DELETE:
302 1.100.2.2 christos error = rtrequest1(rtm->rtm_type, &info, &saved_nrt);
303 1.100.2.2 christos if (error == 0) {
304 1.100.2.2 christos (rt = saved_nrt)->rt_refcnt++;
305 1.100.2.2 christos goto report;
306 1.100.2.2 christos }
307 1.100.2.2 christos break;
308 1.100.2.2 christos
309 1.100.2.2 christos case RTM_GET:
310 1.100.2.2 christos case RTM_CHANGE:
311 1.100.2.2 christos case RTM_LOCK:
312 1.100.2.2 christos /* XXX This will mask dst with netmask before
313 1.100.2.2 christos * searching. It did not used to do that. --dyoung
314 1.100.2.2 christos */
315 1.100.2.2 christos error = rtrequest(RTM_GET, dst, gate, netmask, 0, &rt);
316 1.100.2.2 christos if (error != 0)
317 1.100.2.2 christos senderr(error);
318 1.100.2.2 christos if (rtm->rtm_type != RTM_GET) {/* XXX: too grotty */
319 1.100.2.2 christos struct radix_node *rn;
320 1.100.2.2 christos
321 1.100.2.2 christos if (memcmp(dst, rt_getkey(rt), dst->sa_len) != 0)
322 1.100.2.2 christos senderr(ESRCH);
323 1.100.2.2 christos netmask = intern_netmask(netmask);
324 1.100.2.2 christos for (rn = rt->rt_nodes; rn; rn = rn->rn_dupedkey)
325 1.100.2.2 christos if (netmask == (const struct sockaddr *)rn->rn_mask)
326 1.100.2.2 christos break;
327 1.100.2.2 christos if (rn == NULL)
328 1.100.2.2 christos senderr(ETOOMANYREFS);
329 1.100.2.2 christos rt = (struct rtentry *)rn;
330 1.100.2.2 christos }
331 1.100.2.2 christos
332 1.100.2.2 christos switch (rtm->rtm_type) {
333 1.100.2.2 christos case RTM_GET:
334 1.100.2.2 christos report:
335 1.100.2.2 christos dst = rt_getkey(rt);
336 1.100.2.2 christos gate = rt->rt_gateway;
337 1.100.2.2 christos netmask = rt_mask(rt);
338 1.100.2.2 christos if ((rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) == 0)
339 1.100.2.2 christos ;
340 1.100.2.2 christos else if ((ifp = rt->rt_ifp) != NULL) {
341 1.100.2.2 christos const struct ifaddr *rtifa;
342 1.100.2.2 christos ifpaddr = ifp->if_dl->ifa_addr;
343 1.100.2.2 christos /* rtifa used to be simply rt->rt_ifa.
344 1.100.2.2 christos * If rt->rt_ifa != NULL, then
345 1.100.2.2 christos * rt_get_ifa() != NULL. So this
346 1.100.2.2 christos * ought to still be safe. --dyoung
347 1.100.2.2 christos */
348 1.100.2.2 christos rtifa = rt_get_ifa(rt);
349 1.100.2.2 christos ifaaddr = rtifa->ifa_addr;
350 1.100.2.2 christos #ifdef RTSOCK_DEBUG
351 1.100.2.2 christos if (ifaaddr->sa_family == AF_INET) {
352 1.100.2.2 christos printf("%s: copying out RTAX_IFA %s ",
353 1.100.2.2 christos __func__,
354 1.100.2.2 christos inet_ntoa(((const struct sockaddr_in *)ifaaddr)->sin_addr));
355 1.100.2.2 christos printf("for dst %s ifa_getifa %p ifa_seqno %p\n",
356 1.100.2.2 christos inet_ntoa(((const struct sockaddr_in *)dst)->sin_addr),
357 1.100.2.2 christos (void *)rtifa->ifa_getifa, rtifa->ifa_seqno);
358 1.100.2.2 christos }
359 1.100.2.2 christos #endif /* RTSOCK_DEBUG */
360 1.100.2.2 christos if (ifp->if_flags & IFF_POINTOPOINT)
361 1.100.2.2 christos brdaddr = rtifa->ifa_dstaddr;
362 1.100.2.2 christos else
363 1.100.2.2 christos brdaddr = NULL;
364 1.100.2.2 christos rtm->rtm_index = ifp->if_index;
365 1.100.2.2 christos } else {
366 1.100.2.2 christos ifpaddr = NULL;
367 1.100.2.2 christos ifaaddr = NULL;
368 1.100.2.2 christos }
369 1.100.2.2 christos (void)rt_msg2(rtm->rtm_type, &info, NULL, NULL, &len);
370 1.100.2.2 christos if (len > rtm->rtm_msglen) {
371 1.100.2.2 christos struct rt_msghdr *new_rtm;
372 1.100.2.2 christos R_Malloc(new_rtm, struct rt_msghdr *, len);
373 1.100.2.2 christos if (new_rtm == NULL)
374 1.100.2.2 christos senderr(ENOBUFS);
375 1.100.2.2 christos Bcopy(rtm, new_rtm, rtm->rtm_msglen);
376 1.100.2.2 christos Free(rtm); rtm = new_rtm;
377 1.100.2.2 christos }
378 1.100.2.2 christos (void)rt_msg2(rtm->rtm_type, &info, (void *)rtm,
379 1.100.2.2 christos NULL, 0);
380 1.100.2.2 christos rtm->rtm_flags = rt->rt_flags;
381 1.100.2.2 christos cvtmetrics(&rtm->rtm_rmx, &rt->rt_rmx);
382 1.100.2.2 christos rtm->rtm_addrs = info.rti_addrs;
383 1.100.2.2 christos break;
384 1.100.2.2 christos
385 1.100.2.2 christos case RTM_CHANGE:
386 1.100.2.2 christos /*
387 1.100.2.2 christos * new gateway could require new ifaddr, ifp;
388 1.100.2.2 christos * flags may also be different; ifp may be specified
389 1.100.2.2 christos * by ll sockaddr when protocol address is ambiguous
390 1.100.2.2 christos */
391 1.100.2.2 christos if ((error = rt_getifa(&info)) != 0)
392 1.100.2.2 christos senderr(error);
393 1.100.2.2 christos if (gate && rt_setgate(rt, gate))
394 1.100.2.2 christos senderr(EDQUOT);
395 1.100.2.2 christos /* new gateway could require new ifaddr, ifp;
396 1.100.2.2 christos flags may also be different; ifp may be specified
397 1.100.2.2 christos by ll sockaddr when protocol address is ambiguous */
398 1.100.2.2 christos if (ifpaddr && (ifa = ifa_ifwithnet(ifpaddr)) &&
399 1.100.2.2 christos (ifp = ifa->ifa_ifp) && (ifaaddr || gate))
400 1.100.2.2 christos ifa = ifaof_ifpforaddr(ifaaddr ? ifaaddr : gate,
401 1.100.2.2 christos ifp);
402 1.100.2.2 christos else if ((ifaaddr && (ifa = ifa_ifwithaddr(ifaaddr))) ||
403 1.100.2.2 christos (gate && (ifa = ifa_ifwithroute(rt->rt_flags,
404 1.100.2.2 christos rt_getkey(rt), gate))))
405 1.100.2.2 christos ifp = ifa->ifa_ifp;
406 1.100.2.2 christos if (ifa) {
407 1.100.2.2 christos struct ifaddr *oifa = rt->rt_ifa;
408 1.100.2.2 christos if (oifa != ifa) {
409 1.100.2.2 christos if (oifa && oifa->ifa_rtrequest) {
410 1.100.2.2 christos oifa->ifa_rtrequest(RTM_DELETE,
411 1.100.2.2 christos rt, &info);
412 1.100.2.2 christos }
413 1.100.2.2 christos rt_replace_ifa(rt, ifa);
414 1.100.2.2 christos rt->rt_ifp = ifp;
415 1.100.2.2 christos }
416 1.100.2.2 christos }
417 1.100.2.2 christos rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
418 1.100.2.2 christos &rt->rt_rmx);
419 1.100.2.2 christos if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
420 1.100.2.2 christos rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, &info);
421 1.100.2.2 christos /*
422 1.100.2.2 christos * Fall into
423 1.100.2.2 christos */
424 1.100.2.2 christos case RTM_LOCK:
425 1.100.2.2 christos rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
426 1.100.2.2 christos rt->rt_rmx.rmx_locks |=
427 1.100.2.2 christos (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
428 1.100.2.2 christos break;
429 1.100.2.2 christos }
430 1.100.2.2 christos break;
431 1.100.2.2 christos
432 1.100.2.2 christos default:
433 1.100.2.2 christos senderr(EOPNOTSUPP);
434 1.100.2.2 christos }
435 1.100.2.2 christos
436 1.100.2.2 christos flush:
437 1.100.2.2 christos if (rtm) {
438 1.100.2.2 christos if (error)
439 1.100.2.2 christos rtm->rtm_errno = error;
440 1.100.2.2 christos else
441 1.100.2.2 christos rtm->rtm_flags |= RTF_DONE;
442 1.100.2.2 christos }
443 1.100.2.2 christos family = dst ? dst->sa_family : 0;
444 1.100.2.2 christos if (rt)
445 1.100.2.2 christos rtfree(rt);
446 1.100.2.2 christos {
447 1.100.2.2 christos struct rawcb *rp = NULL;
448 1.100.2.2 christos /*
449 1.100.2.2 christos * Check to see if we don't want our own messages.
450 1.100.2.2 christos */
451 1.100.2.2 christos if ((so->so_options & SO_USELOOPBACK) == 0) {
452 1.100.2.2 christos if (route_cb.any_count <= 1) {
453 1.100.2.2 christos if (rtm)
454 1.100.2.2 christos Free(rtm);
455 1.100.2.2 christos m_freem(m);
456 1.100.2.2 christos return error;
457 1.100.2.2 christos }
458 1.100.2.2 christos /* There is another listener, so construct message */
459 1.100.2.2 christos rp = sotorawcb(so);
460 1.100.2.2 christos }
461 1.100.2.2 christos if (rtm) {
462 1.100.2.2 christos m_copyback(m, 0, rtm->rtm_msglen, (void *)rtm);
463 1.100.2.2 christos if (m->m_pkthdr.len < rtm->rtm_msglen) {
464 1.100.2.2 christos m_freem(m);
465 1.100.2.2 christos m = NULL;
466 1.100.2.2 christos } else if (m->m_pkthdr.len > rtm->rtm_msglen)
467 1.100.2.2 christos m_adj(m, rtm->rtm_msglen - m->m_pkthdr.len);
468 1.100.2.2 christos Free(rtm);
469 1.100.2.2 christos }
470 1.100.2.2 christos if (rp)
471 1.100.2.2 christos rp->rcb_proto.sp_family = 0; /* Avoid us */
472 1.100.2.2 christos if (family)
473 1.100.2.2 christos proto.sp_protocol = family;
474 1.100.2.2 christos if (m)
475 1.100.2.2 christos raw_input(m, &proto, &route_src, &route_dst);
476 1.100.2.2 christos if (rp)
477 1.100.2.2 christos rp->rcb_proto.sp_family = PF_ROUTE;
478 1.100.2.2 christos }
479 1.100.2.2 christos return error;
480 1.100.2.2 christos }
481 1.100.2.2 christos
482 1.100.2.2 christos void
483 1.100.2.2 christos rt_setmetrics(u_long which, const struct ort_metrics *in, struct rt_metrics *out)
484 1.100.2.2 christos {
485 1.100.2.2 christos #define metric(f, e) if (which & (f)) out->e = in->e;
486 1.100.2.2 christos metric(RTV_RPIPE, rmx_recvpipe);
487 1.100.2.2 christos metric(RTV_SPIPE, rmx_sendpipe);
488 1.100.2.2 christos metric(RTV_SSTHRESH, rmx_ssthresh);
489 1.100.2.2 christos metric(RTV_RTT, rmx_rtt);
490 1.100.2.2 christos metric(RTV_RTTVAR, rmx_rttvar);
491 1.100.2.2 christos metric(RTV_HOPCOUNT, rmx_hopcount);
492 1.100.2.2 christos metric(RTV_MTU, rmx_mtu);
493 1.100.2.2 christos /* XXX time_t: Will not work after 2038 */
494 1.100.2.2 christos metric(RTV_EXPIRE, rmx_expire);
495 1.100.2.2 christos #undef metric
496 1.100.2.2 christos }
497 1.100.2.2 christos
498 1.100.2.2 christos #define ROUNDUP(a) \
499 1.100.2.2 christos ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
500 1.100.2.2 christos #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
501 1.100.2.2 christos
502 1.100.2.2 christos static int
503 1.100.2.2 christos rt_xaddrs(u_char rtmtype, const char *cp, const char *cplim, struct rt_addrinfo *rtinfo)
504 1.100.2.2 christos {
505 1.100.2.2 christos const struct sockaddr *sa = NULL; /* Quell compiler warning */
506 1.100.2.2 christos int i;
507 1.100.2.2 christos
508 1.100.2.2 christos for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
509 1.100.2.2 christos if ((rtinfo->rti_addrs & (1 << i)) == 0)
510 1.100.2.2 christos continue;
511 1.100.2.2 christos rtinfo->rti_info[i] = sa = (const struct sockaddr *)cp;
512 1.100.2.2 christos ADVANCE(cp, sa);
513 1.100.2.2 christos }
514 1.100.2.2 christos
515 1.100.2.2 christos /* Check for extra addresses specified, except RTM_GET asking for interface info. */
516 1.100.2.2 christos if (rtmtype == RTM_GET) {
517 1.100.2.2 christos if (((rtinfo->rti_addrs & (~((1 << RTAX_IFP) | (1 << RTAX_IFA)))) & (~0 << i)) != 0)
518 1.100.2.2 christos return 1;
519 1.100.2.2 christos } else {
520 1.100.2.2 christos if ((rtinfo->rti_addrs & (~0 << i)) != 0)
521 1.100.2.2 christos return 1;
522 1.100.2.2 christos }
523 1.100.2.2 christos /* Check for bad data length. */
524 1.100.2.2 christos if (cp != cplim) {
525 1.100.2.2 christos if (i == RTAX_NETMASK + 1 && sa &&
526 1.100.2.2 christos cp - ROUNDUP(sa->sa_len) + sa->sa_len == cplim)
527 1.100.2.2 christos /*
528 1.100.2.2 christos * The last sockaddr was netmask.
529 1.100.2.2 christos * We accept this for now for the sake of old
530 1.100.2.2 christos * binaries or third party softwares.
531 1.100.2.2 christos */
532 1.100.2.2 christos ;
533 1.100.2.2 christos else
534 1.100.2.2 christos return 1;
535 1.100.2.2 christos }
536 1.100.2.2 christos return 0;
537 1.100.2.2 christos }
538 1.100.2.2 christos
539 1.100.2.2 christos struct mbuf *
540 1.100.2.2 christos rt_msg1(int type, struct rt_addrinfo *rtinfo, void *data, int datalen)
541 1.100.2.2 christos {
542 1.100.2.2 christos struct rt_msghdr *rtm;
543 1.100.2.2 christos struct mbuf *m;
544 1.100.2.2 christos int i;
545 1.100.2.2 christos const struct sockaddr *sa;
546 1.100.2.2 christos int len, dlen;
547 1.100.2.2 christos
548 1.100.2.2 christos m = m_gethdr(M_DONTWAIT, MT_DATA);
549 1.100.2.2 christos if (m == NULL)
550 1.100.2.2 christos return m;
551 1.100.2.2 christos MCLAIM(m, &routedomain.dom_mowner);
552 1.100.2.2 christos switch (type) {
553 1.100.2.2 christos
554 1.100.2.2 christos case RTM_DELADDR:
555 1.100.2.2 christos case RTM_NEWADDR:
556 1.100.2.2 christos len = sizeof(struct ifa_msghdr);
557 1.100.2.2 christos break;
558 1.100.2.2 christos
559 1.100.2.2 christos #ifdef COMPAT_14
560 1.100.2.2 christos case RTM_OOIFINFO:
561 1.100.2.2 christos len = sizeof(struct if_msghdr14);
562 1.100.2.2 christos break;
563 1.100.2.2 christos #endif
564 1.100.2.2 christos #ifdef COMPAT_50
565 1.100.2.2 christos case RTM_OIFINFO:
566 1.100.2.2 christos len = sizeof(struct if_msghdr50);
567 1.100.2.2 christos break;
568 1.100.2.2 christos #endif
569 1.100.2.2 christos
570 1.100.2.2 christos case RTM_IFINFO:
571 1.100.2.2 christos len = sizeof(struct if_msghdr);
572 1.100.2.2 christos break;
573 1.100.2.2 christos
574 1.100.2.2 christos case RTM_IFANNOUNCE:
575 1.100.2.2 christos case RTM_IEEE80211:
576 1.100.2.2 christos len = sizeof(struct if_announcemsghdr);
577 1.100.2.2 christos break;
578 1.100.2.2 christos
579 1.100.2.2 christos default:
580 1.100.2.2 christos len = sizeof(struct rt_msghdr);
581 1.100.2.2 christos }
582 1.100.2.2 christos if (len > MHLEN + MLEN)
583 1.100.2.2 christos panic("rt_msg1: message too long");
584 1.100.2.2 christos else if (len > MHLEN) {
585 1.100.2.2 christos m->m_next = m_get(M_DONTWAIT, MT_DATA);
586 1.100.2.2 christos if (m->m_next == NULL) {
587 1.100.2.2 christos m_freem(m);
588 1.100.2.2 christos return NULL;
589 1.100.2.2 christos }
590 1.100.2.2 christos MCLAIM(m->m_next, m->m_owner);
591 1.100.2.2 christos m->m_pkthdr.len = len;
592 1.100.2.2 christos m->m_len = MHLEN;
593 1.100.2.2 christos m->m_next->m_len = len - MHLEN;
594 1.100.2.2 christos } else {
595 1.100.2.2 christos m->m_pkthdr.len = m->m_len = len;
596 1.100.2.2 christos }
597 1.100.2.2 christos m->m_pkthdr.rcvif = NULL;
598 1.100.2.2 christos m_copyback(m, 0, datalen, data);
599 1.100.2.2 christos rtm = mtod(m, struct rt_msghdr *);
600 1.100.2.2 christos for (i = 0; i < RTAX_MAX; i++) {
601 1.100.2.2 christos if ((sa = rtinfo->rti_info[i]) == NULL)
602 1.100.2.2 christos continue;
603 1.100.2.2 christos rtinfo->rti_addrs |= (1 << i);
604 1.100.2.2 christos dlen = ROUNDUP(sa->sa_len);
605 1.100.2.2 christos m_copyback(m, len, dlen, sa);
606 1.100.2.2 christos len += dlen;
607 1.100.2.2 christos }
608 1.100.2.2 christos if (m->m_pkthdr.len != len) {
609 1.100.2.2 christos m_freem(m);
610 1.100.2.2 christos return NULL;
611 1.100.2.2 christos }
612 1.100.2.2 christos rtm->rtm_msglen = len;
613 1.100.2.2 christos rtm->rtm_version = RTM_VERSION;
614 1.100.2.2 christos rtm->rtm_type = type;
615 1.100.2.2 christos return m;
616 1.100.2.2 christos }
617 1.100.2.2 christos
618 1.100.2.2 christos /*
619 1.100.2.2 christos * rt_msg2
620 1.100.2.2 christos *
621 1.100.2.2 christos * fills 'cp' or 'w'.w_tmem with the routing socket message and
622 1.100.2.2 christos * returns the length of the message in 'lenp'.
623 1.100.2.2 christos *
624 1.100.2.2 christos * if walkarg is 0, cp is expected to be 0 or a buffer large enough to hold
625 1.100.2.2 christos * the message
626 1.100.2.2 christos * otherwise walkarg's w_needed is updated and if the user buffer is
627 1.100.2.2 christos * specified and w_needed indicates space exists the information is copied
628 1.100.2.2 christos * into the temp space (w_tmem). w_tmem is [re]allocated if necessary,
629 1.100.2.2 christos * if the allocation fails ENOBUFS is returned.
630 1.100.2.2 christos */
631 1.100.2.2 christos static int
632 1.100.2.2 christos rt_msg2(int type, struct rt_addrinfo *rtinfo, void *cpv, struct rt_walkarg *w,
633 1.100.2.2 christos int *lenp)
634 1.100.2.2 christos {
635 1.100.2.2 christos int i;
636 1.100.2.2 christos int len, dlen, second_time = 0;
637 1.100.2.2 christos char *cp0, *cp = cpv;
638 1.100.2.2 christos
639 1.100.2.2 christos rtinfo->rti_addrs = 0;
640 1.100.2.2 christos again:
641 1.100.2.2 christos switch (type) {
642 1.100.2.2 christos
643 1.100.2.2 christos case RTM_DELADDR:
644 1.100.2.2 christos case RTM_NEWADDR:
645 1.100.2.2 christos len = sizeof(struct ifa_msghdr);
646 1.100.2.2 christos break;
647 1.100.2.2 christos #ifdef COMPAT_14
648 1.100.2.2 christos case RTM_OOIFINFO:
649 1.100.2.2 christos len = sizeof(struct if_msghdr14);
650 1.100.2.2 christos break;
651 1.100.2.2 christos #endif
652 1.100.2.2 christos #ifdef COMPAT_50
653 1.100.2.2 christos case RTM_OIFINFO:
654 1.100.2.2 christos len = sizeof(struct if_msghdr50);
655 1.100.2.2 christos break;
656 1.100.2.2 christos #endif
657 1.100.2.2 christos
658 1.100.2.2 christos case RTM_IFINFO:
659 1.100.2.2 christos len = sizeof(struct if_msghdr);
660 1.100.2.2 christos break;
661 1.100.2.2 christos
662 1.100.2.2 christos default:
663 1.100.2.2 christos len = sizeof(struct rt_msghdr);
664 1.100.2.2 christos }
665 1.100.2.2 christos if ((cp0 = cp) != NULL)
666 1.100.2.2 christos cp += len;
667 1.100.2.2 christos for (i = 0; i < RTAX_MAX; i++) {
668 1.100.2.2 christos const struct sockaddr *sa;
669 1.100.2.2 christos
670 1.100.2.2 christos if ((sa = rtinfo->rti_info[i]) == NULL)
671 1.100.2.2 christos continue;
672 1.100.2.2 christos rtinfo->rti_addrs |= (1 << i);
673 1.100.2.2 christos dlen = ROUNDUP(sa->sa_len);
674 1.100.2.2 christos if (cp) {
675 1.100.2.2 christos bcopy(sa, cp, (unsigned)dlen);
676 1.100.2.2 christos cp += dlen;
677 1.100.2.2 christos }
678 1.100.2.2 christos len += dlen;
679 1.100.2.2 christos }
680 1.100.2.2 christos if (cp == NULL && w != NULL && !second_time) {
681 1.100.2.2 christos struct rt_walkarg *rw = w;
682 1.100.2.2 christos
683 1.100.2.2 christos rw->w_needed += len;
684 1.100.2.2 christos if (rw->w_needed <= 0 && rw->w_where) {
685 1.100.2.2 christos if (rw->w_tmemsize < len) {
686 1.100.2.2 christos if (rw->w_tmem)
687 1.100.2.2 christos free(rw->w_tmem, M_RTABLE);
688 1.100.2.2 christos rw->w_tmem = (void *) malloc(len, M_RTABLE,
689 1.100.2.2 christos M_NOWAIT);
690 1.100.2.2 christos if (rw->w_tmem)
691 1.100.2.2 christos rw->w_tmemsize = len;
692 1.100.2.2 christos }
693 1.100.2.2 christos if (rw->w_tmem) {
694 1.100.2.2 christos cp = rw->w_tmem;
695 1.100.2.2 christos second_time = 1;
696 1.100.2.2 christos goto again;
697 1.100.2.2 christos } else {
698 1.100.2.2 christos rw->w_tmemneeded = len;
699 1.100.2.2 christos return ENOBUFS;
700 1.100.2.2 christos }
701 1.100.2.2 christos }
702 1.100.2.2 christos }
703 1.100.2.2 christos if (cp) {
704 1.100.2.2 christos struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
705 1.100.2.2 christos
706 1.100.2.2 christos rtm->rtm_version = RTM_VERSION;
707 1.100.2.2 christos rtm->rtm_type = type;
708 1.100.2.2 christos rtm->rtm_msglen = len;
709 1.100.2.2 christos }
710 1.100.2.2 christos if (lenp)
711 1.100.2.2 christos *lenp = len;
712 1.100.2.2 christos return 0;
713 1.100.2.2 christos }
714 1.100.2.2 christos
715 1.100.2.2 christos /*
716 1.100.2.2 christos * This routine is called to generate a message from the routing
717 1.100.2.2 christos * socket indicating that a redirect has occurred, a routing lookup
718 1.100.2.2 christos * has failed, or that a protocol has detected timeouts to a particular
719 1.100.2.2 christos * destination.
720 1.100.2.2 christos */
721 1.100.2.2 christos void
722 1.100.2.2 christos rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
723 1.100.2.2 christos {
724 1.100.2.2 christos struct rt_msghdr rtm;
725 1.100.2.2 christos struct mbuf *m;
726 1.100.2.2 christos const struct sockaddr *sa = rtinfo->rti_info[RTAX_DST];
727 1.100.2.2 christos
728 1.100.2.2 christos if (route_cb.any_count == 0)
729 1.100.2.2 christos return;
730 1.100.2.2 christos memset(&rtm, 0, sizeof(rtm));
731 1.100.2.2 christos rtm.rtm_flags = RTF_DONE | flags;
732 1.100.2.2 christos rtm.rtm_errno = error;
733 1.100.2.2 christos m = rt_msg1(type, rtinfo, (void *)&rtm, sizeof(rtm));
734 1.100.2.2 christos if (m == NULL)
735 1.100.2.2 christos return;
736 1.100.2.2 christos mtod(m, struct rt_msghdr *)->rtm_addrs = rtinfo->rti_addrs;
737 1.100.2.2 christos route_enqueue(m, sa ? sa->sa_family : 0);
738 1.100.2.2 christos }
739 1.100.2.2 christos
740 1.100.2.2 christos /*
741 1.100.2.2 christos * This routine is called to generate a message from the routing
742 1.100.2.2 christos * socket indicating that the status of a network interface has changed.
743 1.100.2.2 christos */
744 1.100.2.2 christos void
745 1.100.2.2 christos rt_ifmsg(struct ifnet *ifp)
746 1.100.2.2 christos {
747 1.100.2.2 christos struct if_msghdr ifm;
748 1.100.2.2 christos struct mbuf *m;
749 1.100.2.2 christos struct rt_addrinfo info;
750 1.100.2.2 christos
751 1.100.2.2 christos if (route_cb.any_count == 0)
752 1.100.2.2 christos return;
753 1.100.2.2 christos (void)memset(&info, 0, sizeof(info));
754 1.100.2.2 christos (void)memset(&ifm, 0, sizeof(ifm));
755 1.100.2.2 christos ifm.ifm_index = ifp->if_index;
756 1.100.2.2 christos ifm.ifm_flags = ifp->if_flags;
757 1.100.2.2 christos ifm.ifm_data = ifp->if_data;
758 1.100.2.2 christos ifm.ifm_addrs = 0;
759 1.100.2.2 christos m = rt_msg1(RTM_IFINFO, &info, (void *)&ifm, sizeof(ifm));
760 1.100.2.2 christos if (m == NULL)
761 1.100.2.2 christos return;
762 1.100.2.2 christos route_enqueue(m, 0);
763 1.100.2.2 christos #ifdef COMPAT_14
764 1.100.2.2 christos compat_14_rt_ifmsg(ifp, &ifm);
765 1.100.2.2 christos #endif
766 1.100.2.2 christos #ifdef COMPAT_50
767 1.100.2.2 christos compat_50_rt_ifmsg(ifp, &ifm);
768 1.100.2.2 christos #endif
769 1.100.2.2 christos }
770 1.100.2.2 christos
771 1.100.2.2 christos
772 1.100.2.2 christos /*
773 1.100.2.2 christos * This is called to generate messages from the routing socket
774 1.100.2.2 christos * indicating a network interface has had addresses associated with it.
775 1.100.2.2 christos * if we ever reverse the logic and replace messages TO the routing
776 1.100.2.2 christos * socket indicate a request to configure interfaces, then it will
777 1.100.2.2 christos * be unnecessary as the routing socket will automatically generate
778 1.100.2.2 christos * copies of it.
779 1.100.2.2 christos */
780 1.100.2.2 christos void
781 1.100.2.2 christos rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
782 1.100.2.2 christos {
783 1.100.2.2 christos struct rt_addrinfo info;
784 1.100.2.2 christos const struct sockaddr *sa = NULL;
785 1.100.2.2 christos int pass;
786 1.100.2.2 christos struct mbuf *m = NULL;
787 1.100.2.2 christos struct ifnet *ifp = ifa->ifa_ifp;
788 1.100.2.2 christos
789 1.100.2.2 christos if (route_cb.any_count == 0)
790 1.100.2.2 christos return;
791 1.100.2.2 christos for (pass = 1; pass < 3; pass++) {
792 1.100.2.2 christos memset(&info, 0, sizeof(info));
793 1.100.2.2 christos if ((cmd == RTM_ADD && pass == 1) ||
794 1.100.2.2 christos (cmd == RTM_DELETE && pass == 2)) {
795 1.100.2.2 christos struct ifa_msghdr ifam;
796 1.100.2.2 christos int ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR;
797 1.100.2.2 christos
798 1.100.2.2 christos ifaaddr = sa = ifa->ifa_addr;
799 1.100.2.2 christos ifpaddr = ifp->if_dl->ifa_addr;
800 1.100.2.2 christos netmask = ifa->ifa_netmask;
801 1.100.2.2 christos brdaddr = ifa->ifa_dstaddr;
802 1.100.2.2 christos memset(&ifam, 0, sizeof(ifam));
803 1.100.2.2 christos ifam.ifam_index = ifp->if_index;
804 1.100.2.2 christos ifam.ifam_metric = ifa->ifa_metric;
805 1.100.2.2 christos ifam.ifam_flags = ifa->ifa_flags;
806 1.100.2.2 christos m = rt_msg1(ncmd, &info, (void *)&ifam, sizeof(ifam));
807 1.100.2.2 christos if (m == NULL)
808 1.100.2.2 christos continue;
809 1.100.2.2 christos mtod(m, struct ifa_msghdr *)->ifam_addrs =
810 1.100.2.2 christos info.rti_addrs;
811 1.100.2.2 christos }
812 1.100.2.2 christos if ((cmd == RTM_ADD && pass == 2) ||
813 1.100.2.2 christos (cmd == RTM_DELETE && pass == 1)) {
814 1.100.2.2 christos struct rt_msghdr rtm;
815 1.100.2.2 christos
816 1.100.2.2 christos if (rt == NULL)
817 1.100.2.2 christos continue;
818 1.100.2.2 christos netmask = rt_mask(rt);
819 1.100.2.2 christos dst = sa = rt_getkey(rt);
820 1.100.2.2 christos gate = rt->rt_gateway;
821 1.100.2.2 christos memset(&rtm, 0, sizeof(rtm));
822 1.100.2.2 christos rtm.rtm_index = ifp->if_index;
823 1.100.2.2 christos rtm.rtm_flags |= rt->rt_flags;
824 1.100.2.2 christos rtm.rtm_errno = error;
825 1.100.2.2 christos m = rt_msg1(cmd, &info, (void *)&rtm, sizeof(rtm));
826 1.100.2.2 christos if (m == NULL)
827 1.100.2.2 christos continue;
828 1.100.2.2 christos mtod(m, struct rt_msghdr *)->rtm_addrs = info.rti_addrs;
829 1.100.2.2 christos }
830 1.100.2.2 christos route_enqueue(m, sa ? sa->sa_family : 0);
831 1.100.2.2 christos }
832 1.100.2.2 christos }
833 1.100.2.2 christos
834 1.100.2.2 christos static struct mbuf *
835 1.100.2.2 christos rt_makeifannouncemsg(struct ifnet *ifp, int type, int what,
836 1.100.2.2 christos struct rt_addrinfo *info)
837 1.100.2.2 christos {
838 1.100.2.2 christos struct if_announcemsghdr ifan;
839 1.100.2.2 christos
840 1.100.2.2 christos memset(info, 0, sizeof(*info));
841 1.100.2.2 christos memset(&ifan, 0, sizeof(ifan));
842 1.100.2.2 christos ifan.ifan_index = ifp->if_index;
843 1.100.2.2 christos strlcpy(ifan.ifan_name, ifp->if_xname, sizeof(ifan.ifan_name));
844 1.100.2.2 christos ifan.ifan_what = what;
845 1.100.2.2 christos return rt_msg1(type, info, (void *)&ifan, sizeof(ifan));
846 1.100.2.2 christos }
847 1.100.2.2 christos
848 1.100.2.2 christos /*
849 1.100.2.2 christos * This is called to generate routing socket messages indicating
850 1.100.2.2 christos * network interface arrival and departure.
851 1.100.2.2 christos */
852 1.100.2.2 christos void
853 1.100.2.2 christos rt_ifannouncemsg(struct ifnet *ifp, int what)
854 1.100.2.2 christos {
855 1.100.2.2 christos struct mbuf *m;
856 1.100.2.2 christos struct rt_addrinfo info;
857 1.100.2.2 christos
858 1.100.2.2 christos if (route_cb.any_count == 0)
859 1.100.2.2 christos return;
860 1.100.2.2 christos m = rt_makeifannouncemsg(ifp, RTM_IFANNOUNCE, what, &info);
861 1.100.2.2 christos if (m == NULL)
862 1.100.2.2 christos return;
863 1.100.2.2 christos route_enqueue(m, 0);
864 1.100.2.2 christos }
865 1.100.2.2 christos
866 1.100.2.2 christos /*
867 1.100.2.2 christos * This is called to generate routing socket messages indicating
868 1.100.2.2 christos * IEEE80211 wireless events.
869 1.100.2.2 christos * XXX we piggyback on the RTM_IFANNOUNCE msg format in a clumsy way.
870 1.100.2.2 christos */
871 1.100.2.2 christos void
872 1.100.2.2 christos rt_ieee80211msg(struct ifnet *ifp, int what, void *data, size_t data_len)
873 1.100.2.2 christos {
874 1.100.2.2 christos struct mbuf *m;
875 1.100.2.2 christos struct rt_addrinfo info;
876 1.100.2.2 christos
877 1.100.2.2 christos if (route_cb.any_count == 0)
878 1.100.2.2 christos return;
879 1.100.2.2 christos m = rt_makeifannouncemsg(ifp, RTM_IEEE80211, what, &info);
880 1.100.2.2 christos if (m == NULL)
881 1.100.2.2 christos return;
882 1.100.2.2 christos /*
883 1.100.2.2 christos * Append the ieee80211 data. Try to stick it in the
884 1.100.2.2 christos * mbuf containing the ifannounce msg; otherwise allocate
885 1.100.2.2 christos * a new mbuf and append.
886 1.100.2.2 christos *
887 1.100.2.2 christos * NB: we assume m is a single mbuf.
888 1.100.2.2 christos */
889 1.100.2.2 christos if (data_len > M_TRAILINGSPACE(m)) {
890 1.100.2.2 christos struct mbuf *n = m_get(M_NOWAIT, MT_DATA);
891 1.100.2.2 christos if (n == NULL) {
892 1.100.2.2 christos m_freem(m);
893 1.100.2.2 christos return;
894 1.100.2.2 christos }
895 1.100.2.2 christos (void)memcpy(mtod(n, void *), data, data_len);
896 1.100.2.2 christos n->m_len = data_len;
897 1.100.2.2 christos m->m_next = n;
898 1.100.2.2 christos } else if (data_len > 0) {
899 1.100.2.2 christos (void)memcpy(mtod(m, uint8_t *) + m->m_len, data, data_len);
900 1.100.2.2 christos m->m_len += data_len;
901 1.100.2.2 christos }
902 1.100.2.2 christos if (m->m_flags & M_PKTHDR)
903 1.100.2.2 christos m->m_pkthdr.len += data_len;
904 1.100.2.2 christos mtod(m, struct if_announcemsghdr *)->ifan_msglen += data_len;
905 1.100.2.2 christos route_enqueue(m, 0);
906 1.100.2.2 christos }
907 1.100.2.2 christos
908 1.100.2.2 christos /*
909 1.100.2.2 christos * This is used in dumping the kernel table via sysctl().
910 1.100.2.2 christos */
911 1.100.2.2 christos static int
912 1.100.2.2 christos sysctl_dumpentry(struct rtentry *rt, void *v)
913 1.100.2.2 christos {
914 1.100.2.2 christos struct rt_walkarg *w = v;
915 1.100.2.2 christos int error = 0, size;
916 1.100.2.2 christos struct rt_addrinfo info;
917 1.100.2.2 christos
918 1.100.2.2 christos if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
919 1.100.2.2 christos return 0;
920 1.100.2.2 christos memset(&info, 0, sizeof(info));
921 1.100.2.2 christos dst = rt_getkey(rt);
922 1.100.2.2 christos gate = rt->rt_gateway;
923 1.100.2.2 christos netmask = rt_mask(rt);
924 1.100.2.2 christos if (rt->rt_ifp) {
925 1.100.2.2 christos const struct ifaddr *rtifa;
926 1.100.2.2 christos ifpaddr = rt->rt_ifp->if_dl->ifa_addr;
927 1.100.2.2 christos /* rtifa used to be simply rt->rt_ifa. If rt->rt_ifa != NULL,
928 1.100.2.2 christos * then rt_get_ifa() != NULL. So this ought to still be safe.
929 1.100.2.2 christos * --dyoung
930 1.100.2.2 christos */
931 1.100.2.2 christos rtifa = rt_get_ifa(rt);
932 1.100.2.2 christos ifaaddr = rtifa->ifa_addr;
933 1.100.2.2 christos if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
934 1.100.2.2 christos brdaddr = rtifa->ifa_dstaddr;
935 1.100.2.2 christos }
936 1.100.2.2 christos if ((error = rt_msg2(RTM_GET, &info, 0, w, &size)))
937 1.100.2.2 christos return error;
938 1.100.2.2 christos if (w->w_where && w->w_tmem && w->w_needed <= 0) {
939 1.100.2.2 christos struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
940 1.100.2.2 christos
941 1.100.2.2 christos rtm->rtm_flags = rt->rt_flags;
942 1.100.2.2 christos rtm->rtm_use = rt->rt_use;
943 1.100.2.2 christos cvtmetrics(&rtm->rtm_rmx, &rt->rt_rmx);
944 1.100.2.2 christos KASSERT(rt->rt_ifp != NULL);
945 1.100.2.2 christos rtm->rtm_index = rt->rt_ifp->if_index;
946 1.100.2.2 christos rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
947 1.100.2.2 christos rtm->rtm_addrs = info.rti_addrs;
948 1.100.2.2 christos if ((error = copyout(rtm, w->w_where, size)) != 0)
949 1.100.2.2 christos w->w_where = NULL;
950 1.100.2.2 christos else
951 1.100.2.2 christos w->w_where = (char *)w->w_where + size;
952 1.100.2.2 christos }
953 1.100.2.2 christos return error;
954 1.100.2.2 christos }
955 1.100.2.2 christos
956 1.100.2.2 christos static int
957 1.100.2.2 christos sysctl_iflist(int af, struct rt_walkarg *w, int type)
958 1.100.2.2 christos {
959 1.100.2.2 christos struct ifnet *ifp;
960 1.100.2.2 christos struct ifaddr *ifa;
961 1.100.2.2 christos struct rt_addrinfo info;
962 1.100.2.2 christos int len, error = 0;
963 1.100.2.2 christos
964 1.100.2.2 christos memset(&info, 0, sizeof(info));
965 1.100.2.2 christos IFNET_FOREACH(ifp) {
966 1.100.2.2 christos if (w->w_arg && w->w_arg != ifp->if_index)
967 1.100.2.2 christos continue;
968 1.100.2.2 christos if (IFADDR_EMPTY(ifp))
969 1.100.2.2 christos continue;
970 1.100.2.2 christos ifpaddr = ifp->if_dl->ifa_addr;
971 1.100.2.2 christos switch (type) {
972 1.100.2.2 christos case NET_RT_IFLIST:
973 1.100.2.2 christos error = rt_msg2(RTM_IFINFO, &info, NULL, w, &len);
974 1.100.2.2 christos break;
975 1.100.2.2 christos #ifdef COMPAT_14
976 1.100.2.2 christos case NET_RT_OOIFLIST:
977 1.100.2.2 christos error = rt_msg2(RTM_OOIFINFO, &info, NULL, w, &len);
978 1.100.2.2 christos break;
979 1.100.2.2 christos #endif
980 1.100.2.2 christos #ifdef COMPAT_50
981 1.100.2.2 christos case NET_RT_OIFLIST:
982 1.100.2.2 christos error = rt_msg2(RTM_OIFINFO, &info, NULL, w, &len);
983 1.100.2.2 christos break;
984 1.100.2.2 christos #endif
985 1.100.2.2 christos default:
986 1.100.2.2 christos panic("sysctl_iflist(1)");
987 1.100.2.2 christos }
988 1.100.2.2 christos if (error)
989 1.100.2.2 christos return error;
990 1.100.2.2 christos ifpaddr = NULL;
991 1.100.2.2 christos if (w->w_where && w->w_tmem && w->w_needed <= 0) {
992 1.100.2.2 christos switch (type) {
993 1.100.2.2 christos case NET_RT_IFLIST: {
994 1.100.2.2 christos struct if_msghdr *ifm;
995 1.100.2.2 christos
996 1.100.2.2 christos ifm = (struct if_msghdr *)w->w_tmem;
997 1.100.2.2 christos ifm->ifm_index = ifp->if_index;
998 1.100.2.2 christos ifm->ifm_flags = ifp->if_flags;
999 1.100.2.2 christos ifm->ifm_data = ifp->if_data;
1000 1.100.2.2 christos ifm->ifm_addrs = info.rti_addrs;
1001 1.100.2.2 christos error = copyout(ifm, w->w_where, len);
1002 1.100.2.2 christos if (error)
1003 1.100.2.2 christos return error;
1004 1.100.2.2 christos w->w_where = (char *)w->w_where + len;
1005 1.100.2.2 christos break;
1006 1.100.2.2 christos }
1007 1.100.2.2 christos
1008 1.100.2.2 christos #ifdef COMPAT_14
1009 1.100.2.2 christos case NET_RT_OOIFLIST:
1010 1.100.2.2 christos error = compat_14_iflist(ifp, w, &info, len);
1011 1.100.2.2 christos if (error)
1012 1.100.2.2 christos return error;
1013 1.100.2.2 christos break;
1014 1.100.2.2 christos #endif
1015 1.100.2.2 christos #ifdef COMPAT_50
1016 1.100.2.2 christos case NET_RT_OIFLIST:
1017 1.100.2.2 christos error = compat_50_iflist(ifp, w, &info, len);
1018 1.100.2.2 christos if (error)
1019 1.100.2.2 christos return error;
1020 1.100.2.2 christos break;
1021 1.100.2.2 christos #endif
1022 1.100.2.2 christos default:
1023 1.100.2.2 christos panic("sysctl_iflist(2)");
1024 1.100.2.2 christos }
1025 1.100.2.2 christos }
1026 1.100.2.2 christos IFADDR_FOREACH(ifa, ifp) {
1027 1.100.2.2 christos if (af && af != ifa->ifa_addr->sa_family)
1028 1.100.2.2 christos continue;
1029 1.100.2.2 christos ifaaddr = ifa->ifa_addr;
1030 1.100.2.2 christos netmask = ifa->ifa_netmask;
1031 1.100.2.2 christos brdaddr = ifa->ifa_dstaddr;
1032 1.100.2.2 christos if ((error = rt_msg2(RTM_NEWADDR, &info, 0, w, &len)))
1033 1.100.2.2 christos return error;
1034 1.100.2.2 christos if (w->w_where && w->w_tmem && w->w_needed <= 0) {
1035 1.100.2.2 christos struct ifa_msghdr *ifam;
1036 1.100.2.2 christos
1037 1.100.2.2 christos ifam = (struct ifa_msghdr *)w->w_tmem;
1038 1.100.2.2 christos ifam->ifam_index = ifa->ifa_ifp->if_index;
1039 1.100.2.2 christos ifam->ifam_flags = ifa->ifa_flags;
1040 1.100.2.2 christos ifam->ifam_metric = ifa->ifa_metric;
1041 1.100.2.2 christos ifam->ifam_addrs = info.rti_addrs;
1042 1.100.2.2 christos error = copyout(w->w_tmem, w->w_where, len);
1043 1.100.2.2 christos if (error)
1044 1.100.2.2 christos return error;
1045 1.100.2.2 christos w->w_where = (char *)w->w_where + len;
1046 1.100.2.2 christos }
1047 1.100.2.2 christos }
1048 1.100.2.2 christos ifaaddr = netmask = brdaddr = NULL;
1049 1.100.2.2 christos }
1050 1.100.2.2 christos return 0;
1051 1.100.2.2 christos }
1052 1.100.2.2 christos
1053 1.100.2.2 christos static int
1054 1.100.2.2 christos sysctl_rtable(SYSCTLFN_ARGS)
1055 1.100.2.2 christos {
1056 1.100.2.2 christos void *where = oldp;
1057 1.100.2.2 christos size_t *given = oldlenp;
1058 1.100.2.2 christos const void *new = newp;
1059 1.100.2.2 christos int i, s, error = EINVAL;
1060 1.100.2.2 christos u_char af;
1061 1.100.2.2 christos struct rt_walkarg w;
1062 1.100.2.2 christos
1063 1.100.2.2 christos if (namelen == 1 && name[0] == CTL_QUERY)
1064 1.100.2.2 christos return sysctl_query(SYSCTLFN_CALL(rnode));
1065 1.100.2.2 christos
1066 1.100.2.2 christos if (new)
1067 1.100.2.2 christos return EPERM;
1068 1.100.2.2 christos if (namelen != 3)
1069 1.100.2.2 christos return EINVAL;
1070 1.100.2.2 christos af = name[0];
1071 1.100.2.2 christos w.w_tmemneeded = 0;
1072 1.100.2.2 christos w.w_tmemsize = 0;
1073 1.100.2.2 christos w.w_tmem = NULL;
1074 1.100.2.2 christos again:
1075 1.100.2.2 christos /* we may return here if a later [re]alloc of the t_mem buffer fails */
1076 1.100.2.2 christos if (w.w_tmemneeded) {
1077 1.100.2.2 christos w.w_tmem = (void *) malloc(w.w_tmemneeded, M_RTABLE, M_WAITOK);
1078 1.100.2.2 christos w.w_tmemsize = w.w_tmemneeded;
1079 1.100.2.2 christos w.w_tmemneeded = 0;
1080 1.100.2.2 christos }
1081 1.100.2.2 christos w.w_op = name[1];
1082 1.100.2.2 christos w.w_arg = name[2];
1083 1.100.2.2 christos w.w_given = *given;
1084 1.100.2.2 christos w.w_needed = 0 - w.w_given;
1085 1.100.2.2 christos w.w_where = where;
1086 1.100.2.2 christos
1087 1.100.2.2 christos s = splsoftnet();
1088 1.100.2.2 christos switch (w.w_op) {
1089 1.100.2.2 christos
1090 1.100.2.2 christos case NET_RT_DUMP:
1091 1.100.2.2 christos case NET_RT_FLAGS:
1092 1.100.2.2 christos for (i = 1; i <= AF_MAX; i++)
1093 1.100.2.2 christos if ((af == 0 || af == i) &&
1094 1.100.2.2 christos (error = rt_walktree(i, sysctl_dumpentry, &w)))
1095 1.100.2.2 christos break;
1096 1.100.2.2 christos break;
1097 1.100.2.2 christos
1098 1.100.2.2 christos #ifdef COMPAT_14
1099 1.100.2.2 christos case NET_RT_OOIFLIST:
1100 1.100.2.2 christos error = sysctl_iflist(af, &w, w.w_op);
1101 1.100.2.2 christos break;
1102 1.100.2.2 christos #endif
1103 1.100.2.2 christos #ifdef COMPAT_50
1104 1.100.2.2 christos case NET_RT_OIFLIST:
1105 1.100.2.2 christos error = sysctl_iflist(af, &w, w.w_op);
1106 1.100.2.2 christos break;
1107 1.100.2.2 christos #endif
1108 1.100.2.2 christos
1109 1.100.2.2 christos case NET_RT_IFLIST:
1110 1.100.2.2 christos error = sysctl_iflist(af, &w, w.w_op);
1111 1.100.2.2 christos }
1112 1.100.2.2 christos splx(s);
1113 1.100.2.2 christos
1114 1.100.2.2 christos /* check to see if we couldn't allocate memory with NOWAIT */
1115 1.100.2.2 christos if (error == ENOBUFS && w.w_tmem == 0 && w.w_tmemneeded)
1116 1.100.2.2 christos goto again;
1117 1.100.2.2 christos
1118 1.100.2.2 christos if (w.w_tmem)
1119 1.100.2.2 christos free(w.w_tmem, M_RTABLE);
1120 1.100.2.2 christos w.w_needed += w.w_given;
1121 1.100.2.2 christos if (where) {
1122 1.100.2.2 christos *given = (char *)w.w_where - (char *)where;
1123 1.100.2.2 christos if (*given < w.w_needed)
1124 1.100.2.2 christos return ENOMEM;
1125 1.100.2.2 christos } else {
1126 1.100.2.2 christos *given = (11 * w.w_needed) / 10;
1127 1.100.2.2 christos }
1128 1.100.2.2 christos return error;
1129 1.100.2.2 christos }
1130 1.100.2.2 christos
1131 1.100.2.2 christos /*
1132 1.100.2.2 christos * Routing message software interrupt routine
1133 1.100.2.2 christos */
1134 1.100.2.2 christos static void
1135 1.100.2.2 christos route_intr(void *cookie)
1136 1.100.2.2 christos {
1137 1.100.2.2 christos struct sockproto proto = { .sp_family = PF_ROUTE, };
1138 1.100.2.2 christos struct mbuf *m;
1139 1.100.2.2 christos int s;
1140 1.100.2.2 christos
1141 1.100.2.2 christos while (!IF_IS_EMPTY(&route_intrq)) {
1142 1.100.2.2 christos s = splnet();
1143 1.100.2.2 christos IF_DEQUEUE(&route_intrq, m);
1144 1.100.2.2 christos splx(s);
1145 1.100.2.2 christos if (m == NULL)
1146 1.100.2.2 christos break;
1147 1.100.2.2 christos proto.sp_protocol = M_GETCTX(m, uintptr_t);
1148 1.100.2.2 christos raw_input(m, &proto, &route_src, &route_dst);
1149 1.100.2.2 christos }
1150 1.100.2.2 christos }
1151 1.100.2.2 christos
1152 1.100.2.2 christos /*
1153 1.100.2.2 christos * Enqueue a message to the software interrupt routine.
1154 1.100.2.2 christos */
1155 1.100.2.2 christos void
1156 1.100.2.2 christos route_enqueue(struct mbuf *m, int family)
1157 1.100.2.2 christos {
1158 1.100.2.2 christos int s, wasempty;
1159 1.100.2.2 christos
1160 1.100.2.2 christos s = splnet();
1161 1.100.2.2 christos if (IF_QFULL(&route_intrq)) {
1162 1.100.2.2 christos IF_DROP(&route_intrq);
1163 1.100.2.2 christos m_freem(m);
1164 1.100.2.2 christos } else {
1165 1.100.2.2 christos wasempty = IF_IS_EMPTY(&route_intrq);
1166 1.100.2.2 christos M_SETCTX(m, (uintptr_t)family);
1167 1.100.2.2 christos IF_ENQUEUE(&route_intrq, m);
1168 1.100.2.2 christos if (wasempty)
1169 1.100.2.2 christos softint_schedule(route_sih);
1170 1.100.2.2 christos }
1171 1.100.2.2 christos splx(s);
1172 1.100.2.2 christos }
1173 1.100.2.2 christos
1174 1.100.2.2 christos void
1175 1.100.2.2 christos rt_init(void)
1176 1.100.2.2 christos {
1177 1.100.2.2 christos
1178 1.100.2.2 christos route_intrq.ifq_maxlen = route_maxqlen;
1179 1.100.2.2 christos route_sih = softint_establish(SOFTINT_NET, route_intr, NULL);
1180 1.100.2.2 christos }
1181 1.100.2.2 christos
1182 1.100.2.2 christos /*
1183 1.100.2.2 christos * Definitions of protocols supported in the ROUTE domain.
1184 1.100.2.2 christos */
1185 1.100.2.2 christos
1186 1.100.2.2 christos const struct protosw routesw[] = {
1187 1.100.2.2 christos {
1188 1.100.2.2 christos .pr_type = SOCK_RAW,
1189 1.100.2.2 christos .pr_domain = &routedomain,
1190 1.100.2.2 christos .pr_flags = PR_ATOMIC|PR_ADDR,
1191 1.100.2.2 christos .pr_input = raw_input,
1192 1.100.2.2 christos .pr_output = route_output,
1193 1.100.2.2 christos .pr_ctlinput = raw_ctlinput,
1194 1.100.2.2 christos .pr_usrreq = route_usrreq,
1195 1.100.2.2 christos .pr_init = raw_init,
1196 1.100.2.2 christos },
1197 1.100.2.2 christos };
1198 1.100.2.2 christos
1199 1.100.2.2 christos struct domain routedomain = {
1200 1.100.2.2 christos .dom_family = PF_ROUTE,
1201 1.100.2.2 christos .dom_name = "route",
1202 1.100.2.2 christos .dom_init = route_init,
1203 1.100.2.2 christos .dom_protosw = routesw,
1204 1.100.2.2 christos .dom_protoswNPROTOSW = &routesw[__arraycount(routesw)],
1205 1.100.2.2 christos };
1206 1.100.2.2 christos
1207 1.100.2.2 christos SYSCTL_SETUP(sysctl_net_route_setup, "sysctl net.route subtree setup")
1208 1.100.2.2 christos {
1209 1.100.2.2 christos const struct sysctlnode *rnode = NULL;
1210 1.100.2.2 christos
1211 1.100.2.2 christos sysctl_createv(clog, 0, NULL, NULL,
1212 1.100.2.2 christos CTLFLAG_PERMANENT,
1213 1.100.2.2 christos CTLTYPE_NODE, "net", NULL,
1214 1.100.2.2 christos NULL, 0, NULL, 0,
1215 1.100.2.2 christos CTL_NET, CTL_EOL);
1216 1.100.2.2 christos
1217 1.100.2.2 christos sysctl_createv(clog, 0, NULL, &rnode,
1218 1.100.2.2 christos CTLFLAG_PERMANENT,
1219 1.100.2.2 christos CTLTYPE_NODE, "route",
1220 1.100.2.2 christos SYSCTL_DESCR("PF_ROUTE information"),
1221 1.100.2.2 christos NULL, 0, NULL, 0,
1222 1.100.2.2 christos CTL_NET, PF_ROUTE, CTL_EOL);
1223 1.100.2.2 christos sysctl_createv(clog, 0, NULL, NULL,
1224 1.100.2.2 christos CTLFLAG_PERMANENT,
1225 1.100.2.2 christos CTLTYPE_NODE, "rtable",
1226 1.100.2.2 christos SYSCTL_DESCR("Routing table information"),
1227 1.100.2.2 christos sysctl_rtable, 0, NULL, 0,
1228 1.100.2.2 christos CTL_NET, PF_ROUTE, 0 /* any protocol */, CTL_EOL);
1229 1.100.2.2 christos sysctl_createv(clog, 0, &rnode, NULL,
1230 1.100.2.2 christos CTLFLAG_PERMANENT,
1231 1.100.2.2 christos CTLTYPE_STRUCT, "stats",
1232 1.100.2.2 christos SYSCTL_DESCR("Routing statistics"),
1233 1.100.2.2 christos NULL, 0, &rtstat, sizeof(rtstat),
1234 1.100.2.2 christos CTL_CREATE, CTL_EOL);
1235 1.100.2.2 christos }
1236