- Bring in patch to make.1 related to previous patch.
[dragonfly.git] / sys / net / rtsock.c
CommitLineData
f3ed2586
JH
1/*
2 * Copyright (c) 2004, 2005 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Jeffrey M. Hsu.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of The DragonFly Project nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific, prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/*
34 * Copyright (c) 2004, 2005 Jeffrey M. Hsu. All rights reserved.
35 *
36 * License terms: all terms for the DragonFly license above plus the following:
37 *
38 * 4. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 *
41 * This product includes software developed by Jeffrey M. Hsu
42 * for the DragonFly Project.
43 *
44 * This requirement may be waived with permission from Jeffrey Hsu.
45 * Permission will be granted to any DragonFly user for free.
46 * This requirement will sunset and may be removed on Jan 31, 2006,
47 * after which the standard DragonFly license (as shown above) will
48 * apply.
49 */
50
984263bc
MD
51/*
52 * Copyright (c) 1988, 1991, 1993
53 * The Regents of the University of California. All rights reserved.
54 *
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
57 * are met:
58 * 1. Redistributions of source code must retain the above copyright
59 * notice, this list of conditions and the following disclaimer.
60 * 2. Redistributions in binary form must reproduce the above copyright
61 * notice, this list of conditions and the following disclaimer in the
62 * documentation and/or other materials provided with the distribution.
63 * 3. All advertising materials mentioning features or use of this software
64 * must display the following acknowledgement:
65 * This product includes software developed by the University of
66 * California, Berkeley and its contributors.
67 * 4. Neither the name of the University nor the names of its contributors
68 * may be used to endorse or promote products derived from this software
69 * without specific prior written permission.
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
72 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
74 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
77 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
78 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
79 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
80 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
81 * SUCH DAMAGE.
82 *
83 * @(#)rtsock.c 8.7 (Berkeley) 10/12/95
84 * $FreeBSD: src/sys/net/rtsock.c,v 1.44.2.11 2002/12/04 14:05:41 ru Exp $
f3ed2586 85 * $DragonFly: src/sys/net/rtsock.c,v 1.20 2005/01/06 17:59:32 hsu Exp $
984263bc
MD
86 */
87
984263bc
MD
88#include <sys/param.h>
89#include <sys/systm.h>
90#include <sys/kernel.h>
91#include <sys/sysctl.h>
92#include <sys/proc.h>
93#include <sys/malloc.h>
94#include <sys/mbuf.h>
47e78ae8 95#include <sys/protosw.h>
984263bc
MD
96#include <sys/socket.h>
97#include <sys/socketvar.h>
98#include <sys/domain.h>
984263bc 99
deffea2e
JS
100#include <machine/stdarg.h>
101
984263bc
MD
102#include <net/if.h>
103#include <net/route.h>
104#include <net/raw_cb.h>
105
106MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
107
f23061d4
JH
108static struct route_cb {
109 int ip_count;
110 int ip6_count;
111 int ipx_count;
112 int ns_count;
113 int any_count;
114} route_cb;
115
984263bc
MD
116static struct sockaddr route_dst = { 2, PF_ROUTE, };
117static struct sockaddr route_src = { 2, PF_ROUTE, };
5fe66e68 118static struct sockaddr sa_zero = { sizeof sa_zero, AF_INET, };
984263bc
MD
119static struct sockproto route_proto = { PF_ROUTE, };
120
121struct walkarg {
122 int w_tmemsize;
123 int w_op, w_arg;
124 caddr_t w_tmem;
125 struct sysctl_req *w_req;
126};
127
128static struct mbuf *
158abb01 129 rt_msg1 (int, struct rt_addrinfo *);
47e78ae8 130static int rt_msg2 (int, struct rt_addrinfo *, caddr_t, struct walkarg *);
ef87f48d 131static int rt_xaddrs (char *, char *, struct rt_addrinfo *);
158abb01
RG
132static int sysctl_dumpentry (struct radix_node *rn, void *vw);
133static int sysctl_iflist (int af, struct walkarg *w);
deffea2e 134static int route_output(struct mbuf *, struct socket *, ...);
47e78ae8 135static void rt_setmetrics (u_long, struct rt_metrics *,
f23061d4 136 struct rt_metrics *);
984263bc 137
984263bc
MD
138/*
139 * It really doesn't make any sense at all for this code to share much
140 * with raw_usrreq.c, since its functionality is so restricted. XXX
141 */
142static int
143rts_abort(struct socket *so)
144{
145 int s, error;
f23061d4 146
984263bc
MD
147 s = splnet();
148 error = raw_usrreqs.pru_abort(so);
149 splx(s);
150 return error;
151}
152
153/* pru_accept is EOPNOTSUPP */
154
155static int
e4700d00 156rts_attach(struct socket *so, int proto, struct pru_attach_info *ai)
984263bc
MD
157{
158 struct rawcb *rp;
159 int s, error;
160
ef87f48d 161 if (sotorawcb(so) != NULL)
984263bc 162 return EISCONN; /* XXX panic? */
f23061d4 163
984263bc 164 MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK|M_ZERO);
ef87f48d 165 if (rp == NULL)
984263bc
MD
166 return ENOBUFS;
167
168 /*
169 * The splnet() is necessary to block protocols from sending
170 * error notifications (like RTM_REDIRECT or RTM_LOSING) while
171 * this PCB is extant but incompletely initialized.
172 * Probably we should try to do more of this work beforehand and
173 * eliminate the spl.
174 */
175 s = splnet();
ef87f48d 176 so->so_pcb = rp;
e4700d00 177 error = raw_attach(so, proto, ai->sb_rlimit);
984263bc
MD
178 rp = sotorawcb(so);
179 if (error) {
180 splx(s);
181 free(rp, M_PCB);
182 return error;
183 }
184 switch(rp->rcb_proto.sp_protocol) {
185 case AF_INET:
186 route_cb.ip_count++;
187 break;
188 case AF_INET6:
189 route_cb.ip6_count++;
190 break;
191 case AF_IPX:
192 route_cb.ipx_count++;
193 break;
194 case AF_NS:
195 route_cb.ns_count++;
196 break;
197 }
198 rp->rcb_faddr = &route_src;
199 route_cb.any_count++;
200 soisconnected(so);
201 so->so_options |= SO_USELOOPBACK;
202 splx(s);
203 return 0;
204}
205
206static int
dadab5e9 207rts_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
984263bc
MD
208{
209 int s, error;
f23061d4 210
984263bc 211 s = splnet();
dadab5e9 212 error = raw_usrreqs.pru_bind(so, nam, td); /* xxx just EINVAL */
984263bc
MD
213 splx(s);
214 return error;
215}
216
217static int
dadab5e9 218rts_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
984263bc
MD
219{
220 int s, error;
f23061d4 221
984263bc 222 s = splnet();
dadab5e9 223 error = raw_usrreqs.pru_connect(so, nam, td); /* XXX just EINVAL */
984263bc
MD
224 splx(s);
225 return error;
226}
227
228/* pru_connect2 is EOPNOTSUPP */
229/* pru_control is EOPNOTSUPP */
230
231static int
232rts_detach(struct socket *so)
233{
234 struct rawcb *rp = sotorawcb(so);
235 int s, error;
236
237 s = splnet();
ef87f48d 238 if (rp != NULL) {
984263bc
MD
239 switch(rp->rcb_proto.sp_protocol) {
240 case AF_INET:
241 route_cb.ip_count--;
242 break;
243 case AF_INET6:
244 route_cb.ip6_count--;
245 break;
246 case AF_IPX:
247 route_cb.ipx_count--;
248 break;
249 case AF_NS:
250 route_cb.ns_count--;
251 break;
252 }
253 route_cb.any_count--;
254 }
255 error = raw_usrreqs.pru_detach(so);
256 splx(s);
257 return error;
258}
259
260static int
261rts_disconnect(struct socket *so)
262{
263 int s, error;
f23061d4 264
984263bc
MD
265 s = splnet();
266 error = raw_usrreqs.pru_disconnect(so);
267 splx(s);
268 return error;
269}
270
271/* pru_listen is EOPNOTSUPP */
272
273static int
274rts_peeraddr(struct socket *so, struct sockaddr **nam)
275{
276 int s, error;
f23061d4 277
984263bc
MD
278 s = splnet();
279 error = raw_usrreqs.pru_peeraddr(so, nam);
280 splx(s);
281 return error;
282}
283
284/* pru_rcvd is EOPNOTSUPP */
285/* pru_rcvoob is EOPNOTSUPP */
286
287static int
288rts_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
dadab5e9 289 struct mbuf *control, struct thread *td)
984263bc
MD
290{
291 int s, error;
f23061d4 292
984263bc 293 s = splnet();
dadab5e9 294 error = raw_usrreqs.pru_send(so, flags, m, nam, control, td);
984263bc
MD
295 splx(s);
296 return error;
297}
298
299/* pru_sense is null */
300
301static int
302rts_shutdown(struct socket *so)
303{
304 int s, error;
f23061d4 305
984263bc
MD
306 s = splnet();
307 error = raw_usrreqs.pru_shutdown(so);
308 splx(s);
309 return error;
310}
311
312static int
313rts_sockaddr(struct socket *so, struct sockaddr **nam)
314{
315 int s, error;
f23061d4 316
984263bc
MD
317 s = splnet();
318 error = raw_usrreqs.pru_sockaddr(so, nam);
319 splx(s);
320 return error;
321}
322
323static struct pr_usrreqs route_usrreqs = {
324 rts_abort, pru_accept_notsupp, rts_attach, rts_bind, rts_connect,
325 pru_connect2_notsupp, pru_control_notsupp, rts_detach, rts_disconnect,
326 pru_listen_notsupp, rts_peeraddr, pru_rcvd_notsupp, pru_rcvoob_notsupp,
327 rts_send, pru_sense_null, rts_shutdown, rts_sockaddr,
328 sosend, soreceive, sopoll
329};
330
331/*ARGSUSED*/
332static int
deffea2e 333route_output(struct mbuf *m, struct socket *so, ...)
984263bc 334{
2e9572df
JH
335 struct rt_msghdr *rtm = NULL;
336 struct rtentry *rt = NULL;
337 struct rtentry *saved_nrt = NULL;
984263bc 338 struct radix_node_head *rnh;
2e9572df
JH
339 struct ifnet *ifp = NULL;
340 struct ifaddr *ifa = NULL;
f23061d4 341 struct rawcb *rp = NULL;
deffea2e 342 struct pr_output_info *oi;
ef87f48d
JH
343 struct rt_addrinfo info;
344 int len, error = 0;
deffea2e
JS
345 __va_list ap;
346
347 __va_start(ap, so);
348 oi = __va_arg(ap, struct pr_output_info *);
349 __va_end(ap);
984263bc 350
ef87f48d 351#define gotoerr(e) { error = e; goto flush;}
2e9572df
JH
352 if (m == NULL || ((m->m_len < sizeof(long)) &&
353 (m = m_pullup(m, sizeof(long))) == NULL))
984263bc 354 return (ENOBUFS);
ef87f48d 355 if (!(m->m_flags & M_PKTHDR))
984263bc
MD
356 panic("route_output");
357 len = m->m_pkthdr.len;
5fe66e68 358 if (len < sizeof *rtm ||
984263bc 359 len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
ef87f48d
JH
360 info.sa_dst = NULL;
361 gotoerr(EINVAL);
984263bc
MD
362 }
363 R_Malloc(rtm, struct rt_msghdr *, len);
ef87f48d
JH
364 if (rtm == NULL) {
365 info.sa_dst = NULL;
366 gotoerr(ENOBUFS);
984263bc
MD
367 }
368 m_copydata(m, 0, len, (caddr_t)rtm);
369 if (rtm->rtm_version != RTM_VERSION) {
ef87f48d
JH
370 info.sa_dst = NULL;
371 gotoerr(EPROTONOSUPPORT);
984263bc 372 }
47e78ae8 373 rtm->rtm_pid = oi->p_pid;
5fe66e68 374 bzero(&info, sizeof info);
984263bc 375 info.rti_addrs = rtm->rtm_addrs;
ef87f48d
JH
376 if (rt_xaddrs((char *)(rtm + 1), len + (char *)rtm, &info)) {
377 info.sa_dst = NULL;
378 gotoerr(EINVAL);
984263bc
MD
379 }
380 info.rti_flags = rtm->rtm_flags;
ef87f48d
JH
381 if (info.sa_dst == NULL || info.sa_dst->sa_family >= AF_MAX ||
382 (info.sa_gateway != NULL && (info.sa_gateway->sa_family >= AF_MAX)))
383 gotoerr(EINVAL);
384
385 if (info.sa_genmask != NULL) {
984263bc 386 struct radix_node *t;
ef87f48d
JH
387 int klen;
388
389 t = rn_addmask((char *)info.sa_genmask, TRUE, 1);
390 if (t != NULL &&
391 info.sa_genmask->sa_len >= (klen = *(u_char *)t->rn_key) &&
392 bcmp((char *)info.sa_genmask + 1, (char *)t->rn_key + 1,
393 klen - 1) == 0)
394 info.sa_genmask = (struct sockaddr *)(t->rn_key);
984263bc 395 else
ef87f48d 396 gotoerr(ENOBUFS);
984263bc
MD
397 }
398
399 /*
400 * Verify that the caller has the appropriate privilege; RTM_GET
401 * is the only operation the non-superuser is allowed.
402 */
dadab5e9 403 if (rtm->rtm_type != RTM_GET && suser_cred(so->so_cred, 0) != 0)
ef87f48d 404 gotoerr(EPERM);
984263bc
MD
405
406 switch (rtm->rtm_type) {
407
408 case RTM_ADD:
ef87f48d
JH
409 if (info.sa_gateway == NULL)
410 gotoerr(EINVAL);
984263bc 411 error = rtrequest1(RTM_ADD, &info, &saved_nrt);
ef87f48d 412 if (error == 0 && saved_nrt != NULL) {
984263bc
MD
413 rt_setmetrics(rtm->rtm_inits,
414 &rtm->rtm_rmx, &saved_nrt->rt_rmx);
415 saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
416 saved_nrt->rt_rmx.rmx_locks |=
417 (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
418 saved_nrt->rt_refcnt--;
ef87f48d 419 saved_nrt->rt_genmask = info.sa_genmask;
984263bc
MD
420 }
421 break;
422
423 case RTM_DELETE:
424 error = rtrequest1(RTM_DELETE, &info, &saved_nrt);
425 if (error == 0) {
426 if ((rt = saved_nrt))
427 rt->rt_refcnt++;
428 goto report;
429 }
430 break;
431
432 case RTM_GET:
433 case RTM_CHANGE:
434 case RTM_LOCK:
ef87f48d
JH
435 if ((rnh = rt_tables[info.sa_dst->sa_family]) == NULL) {
436 gotoerr(EAFNOSUPPORT);
2e9572df 437 } else if ((rt = (struct rtentry *) rnh->rnh_lookup(
ef87f48d 438 (char *)info.sa_dst, (char *)info.sa_netmask, rnh)) != NULL)
984263bc
MD
439 rt->rt_refcnt++;
440 else
ef87f48d 441 gotoerr(ESRCH);
984263bc
MD
442 switch(rtm->rtm_type) {
443
444 case RTM_GET:
445 report:
ef87f48d
JH
446 info.sa_dst = rt_key(rt);
447 info.sa_gateway = rt->rt_gateway;
448 info.sa_netmask = rt_mask(rt);
449 info.sa_genmask = rt->rt_genmask;
984263bc
MD
450 if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) {
451 ifp = rt->rt_ifp;
452 if (ifp) {
ef87f48d
JH
453 info.sa_ifpaddr =
454 TAILQ_FIRST(&ifp->if_addrhead)->
455 ifa_addr;
456 info.sa_ifaaddr = rt->rt_ifa->ifa_addr;
984263bc 457 if (ifp->if_flags & IFF_POINTOPOINT)
ef87f48d
JH
458 info.sa_bcastaddr =
459 rt->rt_ifa->ifa_dstaddr;
984263bc
MD
460 rtm->rtm_index = ifp->if_index;
461 } else {
ef87f48d
JH
462 info.sa_ifpaddr = NULL;
463 info.sa_ifaaddr = NULL;
984263bc
MD
464 }
465 }
ef87f48d 466 len = rt_msg2(rtm->rtm_type, &info, NULL, NULL);
984263bc
MD
467 if (len > rtm->rtm_msglen) {
468 struct rt_msghdr *new_rtm;
469 R_Malloc(new_rtm, struct rt_msghdr *, len);
ef87f48d
JH
470 if (new_rtm == NULL)
471 gotoerr(ENOBUFS);
2e9572df 472 bcopy(rtm, new_rtm, rtm->rtm_msglen);
984263bc
MD
473 Free(rtm); rtm = new_rtm;
474 }
f23061d4 475 rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, NULL);
984263bc
MD
476 rtm->rtm_flags = rt->rt_flags;
477 rtm->rtm_rmx = rt->rt_rmx;
478 rtm->rtm_addrs = info.rti_addrs;
479 break;
480
481 case RTM_CHANGE:
ef87f48d
JH
482 /*
483 * new gateway could require new ifaddr, ifp;
484 * flags may also be different; ifp may be specified
485 * by ll sockaddr when protocol address is ambiguous
486 */
487 if (((rt->rt_flags & RTF_GATEWAY) &&
488 info.sa_gateway != NULL) ||
489 info.sa_ifpaddr != NULL ||
490 (info.sa_ifaaddr != NULL &&
0c3c561c 491 sa_equal(info.sa_ifaaddr, rt->rt_ifa->ifa_addr))) {
984263bc 492 if ((error = rt_getifa(&info)) != 0)
ef87f48d 493 gotoerr(error);
984263bc 494 }
ef87f48d
JH
495 if (info.sa_gateway != NULL &&
496 (error = rt_setgate(rt, rt_key(rt),
f23061d4 497 info.sa_gateway)) != 0)
ef87f48d 498 gotoerr(error);
984263bc 499 if ((ifa = info.rti_ifa) != NULL) {
82ed7fc2 500 struct ifaddr *oifa = rt->rt_ifa;
ef87f48d 501
984263bc 502 if (oifa != ifa) {
f23061d4
JH
503 if (oifa && oifa->ifa_rtrequest)
504 oifa->ifa_rtrequest(RTM_DELETE,
505 rt, &info);
506 IFAFREE(rt->rt_ifa);
507 rt->rt_ifa = ifa;
508 IFAREF(ifa);
509 rt->rt_ifp = info.rti_ifp;
984263bc
MD
510 }
511 }
512 rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
f23061d4 513 &rt->rt_rmx);
984263bc
MD
514 if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
515 rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, &info);
ef87f48d
JH
516 if (info.sa_genmask != NULL)
517 rt->rt_genmask = info.sa_genmask;
984263bc
MD
518 /*
519 * Fall into
520 */
521 case RTM_LOCK:
522 rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
523 rt->rt_rmx.rmx_locks |=
524 (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
525 break;
526 }
527 break;
528
529 default:
ef87f48d 530 gotoerr(EOPNOTSUPP);
984263bc
MD
531 }
532
533flush:
534 if (rtm) {
535 if (error)
536 rtm->rtm_errno = error;
537 else
538 rtm->rtm_flags |= RTF_DONE;
539 }
540 if (rt)
541 rtfree(rt);
984263bc
MD
542 /*
543 * Check to see if we don't want our own messages.
544 */
ef87f48d 545 if (!(so->so_options & SO_USELOOPBACK)) {
984263bc
MD
546 if (route_cb.any_count <= 1) {
547 if (rtm)
548 Free(rtm);
549 m_freem(m);
550 return (error);
551 }
552 /* There is another listener, so construct message */
553 rp = sotorawcb(so);
554 }
555 if (rtm) {
556 m_copyback(m, 0, rtm->rtm_msglen, (caddr_t)rtm);
557 if (m->m_pkthdr.len < rtm->rtm_msglen) {
558 m_freem(m);
559 m = NULL;
560 } else if (m->m_pkthdr.len > rtm->rtm_msglen)
561 m_adj(m, rtm->rtm_msglen - m->m_pkthdr.len);
562 Free(rtm);
563 }
ef87f48d 564 if (rp != NULL)
984263bc 565 rp->rcb_proto.sp_family = 0; /* Avoid us */
ef87f48d
JH
566 if (info.sa_dst != NULL)
567 route_proto.sp_protocol = info.sa_dst->sa_family;
568 if (m != NULL)
984263bc 569 raw_input(m, &route_proto, &route_src, &route_dst);
ef87f48d 570 if (rp != NULL)
984263bc 571 rp->rcb_proto.sp_family = PF_ROUTE;
984263bc
MD
572 return (error);
573}
574
575static void
ef87f48d 576rt_setmetrics(u_long which, struct rt_metrics *in, struct rt_metrics *out)
984263bc 577{
2e9572df
JH
578#define setmetric(flag, elt) if (which & (flag)) out->elt = in->elt;
579 setmetric(RTV_RPIPE, rmx_recvpipe);
580 setmetric(RTV_SPIPE, rmx_sendpipe);
581 setmetric(RTV_SSTHRESH, rmx_ssthresh);
582 setmetric(RTV_RTT, rmx_rtt);
583 setmetric(RTV_RTTVAR, rmx_rttvar);
584 setmetric(RTV_HOPCOUNT, rmx_hopcount);
585 setmetric(RTV_MTU, rmx_mtu);
586 setmetric(RTV_EXPIRE, rmx_expire);
587#undef setmetric
984263bc
MD
588}
589
590#define ROUNDUP(a) \
591 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
592#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
593
984263bc
MD
594/*
595 * Extract the addresses of the passed sockaddrs.
596 * Do a little sanity checking so as to avoid bad memory references.
597 * This data is derived straight from userland.
598 */
599static int
ef87f48d 600rt_xaddrs(char *cp, char *cplim, struct rt_addrinfo *rtinfo)
984263bc 601{
82ed7fc2
RG
602 struct sockaddr *sa;
603 int i;
984263bc
MD
604
605 for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
606 if ((rtinfo->rti_addrs & (1 << i)) == 0)
607 continue;
608 sa = (struct sockaddr *)cp;
609 /*
610 * It won't fit.
611 */
0c3c561c 612 if ((cp + sa->sa_len) > cplim) {
984263bc
MD
613 return (EINVAL);
614 }
615
616 /*
ef87f48d 617 * There are no more... Quit now.
984263bc 618 * If there are more bits, they are in error.
ef87f48d 619 * I've seen this. route(1) can evidently generate these.
984263bc 620 * This causes kernel to core dump.
ef87f48d 621 * For compatibility, if we see this, point to a safe address.
984263bc
MD
622 */
623 if (sa->sa_len == 0) {
624 rtinfo->rti_info[i] = &sa_zero;
625 return (0); /* should be EINVAL but for compat */
626 }
627
ef87f48d 628 /* Accept the sockaddr. */
984263bc
MD
629 rtinfo->rti_info[i] = sa;
630 ADVANCE(cp, sa);
631 }
632 return (0);
633}
634
635static struct mbuf *
0c3c561c 636rt_msg1(int type, struct rt_addrinfo *rtinfo)
984263bc 637{
82ed7fc2
RG
638 struct rt_msghdr *rtm;
639 struct mbuf *m;
640 int i;
641 struct sockaddr *sa;
984263bc
MD
642 int len, dlen;
643
644 switch (type) {
645
646 case RTM_DELADDR:
647 case RTM_NEWADDR:
648 len = sizeof(struct ifa_msghdr);
649 break;
650
651 case RTM_DELMADDR:
652 case RTM_NEWMADDR:
653 len = sizeof(struct ifma_msghdr);
654 break;
655
656 case RTM_IFINFO:
657 len = sizeof(struct if_msghdr);
658 break;
659
660 case RTM_IFANNOUNCE:
661 len = sizeof(struct if_announcemsghdr);
662 break;
663
664 default:
665 len = sizeof(struct rt_msghdr);
666 }
667 if (len > MCLBYTES)
668 panic("rt_msg1");
74f1caca 669 m = m_gethdr(MB_DONTWAIT, MT_DATA);
984263bc 670 if (m && len > MHLEN) {
74f1caca 671 MCLGET(m, MB_DONTWAIT);
ef87f48d 672 if (!(m->m_flags & M_EXT)) {
984263bc
MD
673 m_free(m);
674 m = NULL;
675 }
676 }
ef87f48d 677 if (m == NULL)
984263bc
MD
678 return (m);
679 m->m_pkthdr.len = m->m_len = len;
ef87f48d 680 m->m_pkthdr.rcvif = NULL;
984263bc 681 rtm = mtod(m, struct rt_msghdr *);
ef87f48d 682 bzero(rtm, len);
984263bc
MD
683 for (i = 0; i < RTAX_MAX; i++) {
684 if ((sa = rtinfo->rti_info[i]) == NULL)
685 continue;
686 rtinfo->rti_addrs |= (1 << i);
687 dlen = ROUNDUP(sa->sa_len);
688 m_copyback(m, len, dlen, (caddr_t)sa);
689 len += dlen;
690 }
691 if (m->m_pkthdr.len != len) {
692 m_freem(m);
693 return (NULL);
694 }
695 rtm->rtm_msglen = len;
696 rtm->rtm_version = RTM_VERSION;
697 rtm->rtm_type = type;
698 return (m);
699}
700
701static int
ef87f48d 702rt_msg2(int type, struct rt_addrinfo *rtinfo, caddr_t cp, struct walkarg *w)
984263bc 703{
82ed7fc2 704 int i;
ef87f48d
JH
705 int len, dlen;
706 boolean_t second_time = FALSE;
984263bc
MD
707 caddr_t cp0;
708
ef87f48d 709 rtinfo->rti_addrs = NULL;
984263bc
MD
710again:
711 switch (type) {
712
713 case RTM_DELADDR:
714 case RTM_NEWADDR:
715 len = sizeof(struct ifa_msghdr);
716 break;
717
718 case RTM_IFINFO:
719 len = sizeof(struct if_msghdr);
720 break;
721
722 default:
723 len = sizeof(struct rt_msghdr);
724 }
725 cp0 = cp;
ef87f48d 726 if (cp != NULL)
984263bc 727 cp += len;
ef87f48d 728
984263bc 729 for (i = 0; i < RTAX_MAX; i++) {
82ed7fc2 730 struct sockaddr *sa;
984263bc 731
ef87f48d 732 if ((sa = rtinfo->rti_info[i]) == NULL)
984263bc
MD
733 continue;
734 rtinfo->rti_addrs |= (1 << i);
735 dlen = ROUNDUP(sa->sa_len);
ef87f48d
JH
736 if (cp != NULL) {
737 bcopy(sa, cp, dlen);
984263bc
MD
738 cp += dlen;
739 }
740 len += dlen;
741 }
742 len = ALIGN(len);
ef87f48d 743 if (cp == NULL && w != NULL && !second_time) {
82ed7fc2 744 struct walkarg *rw = w;
984263bc 745
ef87f48d 746 if (rw->w_req != NULL) {
984263bc
MD
747 if (rw->w_tmemsize < len) {
748 if (rw->w_tmem)
749 free(rw->w_tmem, M_RTABLE);
ef87f48d
JH
750 rw->w_tmem = malloc(len, M_RTABLE,
751 M_INTWAIT | M_NULLOK);
984263bc
MD
752 if (rw->w_tmem)
753 rw->w_tmemsize = len;
754 }
ef87f48d 755 if (rw->w_tmem != NULL) {
984263bc 756 cp = rw->w_tmem;
ef87f48d 757 second_time = TRUE;
984263bc
MD
758 goto again;
759 }
760 }
761 }
ef87f48d 762 if (cp != NULL) {
82ed7fc2 763 struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
984263bc
MD
764
765 rtm->rtm_version = RTM_VERSION;
766 rtm->rtm_type = type;
767 rtm->rtm_msglen = len;
768 }
769 return (len);
770}
771
772/*
773 * This routine is called to generate a message from the routing
f23061d4 774 * socket indicating that a redirect has occurred, a routing lookup
984263bc
MD
775 * has failed, or that a protocol has detected timeouts to a particular
776 * destination.
777 */
778void
f23061d4 779rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error)
984263bc 780{
0c3c561c 781 struct sockaddr *dst = rtinfo->rti_info[RTAX_DST];
82ed7fc2
RG
782 struct rt_msghdr *rtm;
783 struct mbuf *m;
984263bc
MD
784
785 if (route_cb.any_count == 0)
786 return;
787 m = rt_msg1(type, rtinfo);
ef87f48d 788 if (m == NULL)
984263bc
MD
789 return;
790 rtm = mtod(m, struct rt_msghdr *);
791 rtm->rtm_flags = RTF_DONE | flags;
792 rtm->rtm_errno = error;
793 rtm->rtm_addrs = rtinfo->rti_addrs;
0c3c561c 794 route_proto.sp_protocol = (dst != NULL) ? dst->sa_family : 0;
984263bc
MD
795 raw_input(m, &route_proto, &route_src, &route_dst);
796}
797
f3ed2586
JH
798void
799rt_dstmsg(int type, struct sockaddr *dst, int error)
800{
801 struct rt_msghdr *rtm;
802 struct rt_addrinfo addrs;
803 struct mbuf *m;
804
805 if (route_cb.any_count == 0)
806 return;
807 bzero(&addrs, sizeof(struct rt_addrinfo));
808 addrs.rti_info[RTAX_DST] = dst;
809 m = rt_msg1(type, &addrs);
810 if (m == NULL)
811 return;
812 rtm = mtod(m, struct rt_msghdr *);
813 rtm->rtm_flags = RTF_DONE;
814 rtm->rtm_errno = error;
815 rtm->rtm_addrs = addrs.rti_addrs;
816 route_proto.sp_protocol = (dst != NULL) ? dst->sa_family : 0;
817 raw_input(m, &route_proto, &route_src, &route_dst);
818}
819
984263bc
MD
820/*
821 * This routine is called to generate a message from the routing
822 * socket indicating that the status of a network interface has changed.
823 */
824void
0c3c561c 825rt_ifmsg(struct ifnet *ifp)
984263bc 826{
82ed7fc2 827 struct if_msghdr *ifm;
984263bc
MD
828 struct mbuf *m;
829 struct rt_addrinfo info;
830
831 if (route_cb.any_count == 0)
832 return;
5fe66e68 833 bzero(&info, sizeof info);
984263bc 834 m = rt_msg1(RTM_IFINFO, &info);
ef87f48d 835 if (m == NULL)
984263bc
MD
836 return;
837 ifm = mtod(m, struct if_msghdr *);
838 ifm->ifm_index = ifp->if_index;
839 ifm->ifm_flags = (u_short)ifp->if_flags;
840 ifm->ifm_data = ifp->if_data;
ef87f48d 841 ifm->ifm_addrs = NULL;
984263bc
MD
842 route_proto.sp_protocol = 0;
843 raw_input(m, &route_proto, &route_src, &route_dst);
844}
845
372316d9
JH
846static void
847rt_ifamsg(int cmd, struct ifaddr *ifa)
848{
849 struct ifa_msghdr *ifam;
850 struct rt_addrinfo info;
851 struct mbuf *m;
852 struct sockaddr *sa;
853 struct ifnet *ifp = ifa->ifa_ifp;
854
5fe66e68 855 bzero(&info, sizeof info);
ef87f48d
JH
856 info.sa_ifaaddr = sa = ifa->ifa_addr;
857 info.sa_ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr;
858 info.sa_netmask = ifa->ifa_netmask;
859 info.sa_bcastaddr = ifa->ifa_dstaddr;
f23061d4
JH
860
861 m = rt_msg1(cmd, &info);
862 if (m == NULL)
372316d9 863 return;
f23061d4 864
372316d9
JH
865 ifam = mtod(m, struct ifa_msghdr *);
866 ifam->ifam_index = ifp->if_index;
867 ifam->ifam_metric = ifa->ifa_metric;
868 ifam->ifam_flags = ifa->ifa_flags;
869 ifam->ifam_addrs = info.rti_addrs;
870
871 route_proto.sp_protocol = sa ? sa->sa_family : 0;
f23061d4 872
372316d9
JH
873 raw_input(m, &route_proto, &route_src, &route_dst);
874}
875
f3ed2586
JH
876void
877rt_rtmsg(int cmd, struct rtentry *rt, struct ifnet *ifp, int error)
372316d9
JH
878{
879 struct rt_msghdr *rtm;
880 struct rt_addrinfo info;
881 struct mbuf *m;
f3ed2586 882 struct sockaddr *dst;
372316d9
JH
883
884 if (rt == NULL)
885 return;
f23061d4 886
5fe66e68 887 bzero(&info, sizeof info);
f3ed2586 888 info.sa_dst = dst = rt_key(rt);
ef87f48d 889 info.sa_gateway = rt->rt_gateway;
f3ed2586
JH
890 info.sa_netmask = rt_mask(rt);
891 if (ifp != NULL)
892 info.sa_ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr;
893 info.sa_ifaaddr = rt->rt_ifa->ifa_addr;
f23061d4
JH
894
895 m = rt_msg1(cmd, &info);
896 if (m == NULL)
372316d9 897 return;
f23061d4 898
372316d9 899 rtm = mtod(m, struct rt_msghdr *);
f3ed2586
JH
900 if (ifp != NULL)
901 rtm->rtm_index = ifp->if_index;
372316d9
JH
902 rtm->rtm_flags |= rt->rt_flags;
903 rtm->rtm_errno = error;
904 rtm->rtm_addrs = info.rti_addrs;
905
f3ed2586 906 route_proto.sp_protocol = (dst != NULL) ? dst->sa_family : 0;
f23061d4 907
372316d9
JH
908 raw_input(m, &route_proto, &route_src, &route_dst);
909}
910
984263bc
MD
911/*
912 * This is called to generate messages from the routing socket
913 * indicating a network interface has had addresses associated with it.
914 * if we ever reverse the logic and replace messages TO the routing
915 * socket indicate a request to configure interfaces, then it will
916 * be unnecessary as the routing socket will automatically generate
917 * copies of it.
918 */
919void
0c3c561c 920rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt)
984263bc 921{
984263bc
MD
922 if (route_cb.any_count == 0)
923 return;
984263bc 924
372316d9
JH
925 if (cmd == RTM_ADD) {
926 rt_ifamsg(RTM_NEWADDR, ifa);
f3ed2586 927 rt_rtmsg(RTM_ADD, rt, ifa->ifa_ifp, error);
372316d9
JH
928 } else {
929 KASSERT((cmd == RTM_DELETE), ("unknown cmd %d", cmd));
f3ed2586 930 rt_rtmsg(RTM_DELETE, rt, ifa->ifa_ifp, error);
372316d9 931 rt_ifamsg(RTM_DELADDR, ifa);
984263bc
MD
932 }
933}
934
935/*
936 * This is the analogue to the rt_newaddrmsg which performs the same
937 * function but for multicast group memberhips. This is easier since
938 * there is no route state to worry about.
939 */
940void
0c3c561c 941rt_newmaddrmsg(int cmd, struct ifmultiaddr *ifma)
984263bc
MD
942{
943 struct rt_addrinfo info;
ef87f48d 944 struct mbuf *m = NULL;
984263bc
MD
945 struct ifnet *ifp = ifma->ifma_ifp;
946 struct ifma_msghdr *ifmam;
947
948 if (route_cb.any_count == 0)
949 return;
950
5fe66e68 951 bzero(&info, sizeof info);
ef87f48d
JH
952 info.sa_ifaaddr = ifma->ifma_addr;
953 if (ifp != NULL && TAILQ_FIRST(&ifp->if_addrhead) != NULL)
954 info.sa_ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr;
984263bc 955 else
ef87f48d 956 info.sa_ifpaddr = NULL;
984263bc
MD
957 /*
958 * If a link-layer address is present, present it as a ``gateway''
959 * (similarly to how ARP entries, e.g., are presented).
960 */
ef87f48d 961 info.sa_gateway = ifma->ifma_lladdr;
f23061d4
JH
962
963 m = rt_msg1(cmd, &info);
964 if (m == NULL)
984263bc 965 return;
f23061d4 966
984263bc
MD
967 ifmam = mtod(m, struct ifma_msghdr *);
968 ifmam->ifmam_index = ifp->if_index;
969 ifmam->ifmam_addrs = info.rti_addrs;
970 route_proto.sp_protocol = ifma->ifma_addr->sa_family;
f23061d4 971
984263bc
MD
972 raw_input(m, &route_proto, &route_src, &route_dst);
973}
974
975/*
976 * This is called to generate routing socket messages indicating
977 * network interface arrival and departure.
978 */
979void
980rt_ifannouncemsg(ifp, what)
981 struct ifnet *ifp;
982 int what;
983{
984 struct if_announcemsghdr *ifan;
985 struct mbuf *m;
986 struct rt_addrinfo info;
987
988 if (route_cb.any_count == 0)
989 return;
f23061d4 990
5fe66e68 991 bzero(&info, sizeof info);
f23061d4 992
984263bc
MD
993 m = rt_msg1(RTM_IFANNOUNCE, &info);
994 if (m == NULL)
995 return;
f23061d4 996
984263bc
MD
997 ifan = mtod(m, struct if_announcemsghdr *);
998 ifan->ifan_index = ifp->if_index;
5fe66e68 999 strlcpy(ifan->ifan_name, ifp->if_xname, sizeof ifan->ifan_name);
984263bc 1000 ifan->ifan_what = what;
f23061d4 1001
984263bc 1002 route_proto.sp_protocol = 0;
f23061d4 1003
984263bc
MD
1004 raw_input(m, &route_proto, &route_src, &route_dst);
1005 }
1006
1007/*
1008 * This is used in dumping the kernel table via sysctl().
1009 */
1010int
1011sysctl_dumpentry(rn, vw)
1012 struct radix_node *rn;
1013 void *vw;
1014{
82ed7fc2
RG
1015 struct walkarg *w = vw;
1016 struct rtentry *rt = (struct rtentry *)rn;
984263bc
MD
1017 int error = 0, size;
1018 struct rt_addrinfo info;
1019
1020 if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
1021 return 0;
f23061d4 1022
5fe66e68 1023 bzero(&info, sizeof info);
ef87f48d
JH
1024 info.sa_dst = rt_key(rt);
1025 info.sa_gateway = rt->rt_gateway;
1026 info.sa_netmask = rt_mask(rt);
1027 info.sa_genmask = rt->rt_genmask;
1028 if (rt->rt_ifp != NULL) {
1029 info.sa_ifpaddr =
1030 TAILQ_FIRST(&rt->rt_ifp->if_addrhead)->ifa_addr;
1031 info.sa_ifaaddr = rt->rt_ifa->ifa_addr;
984263bc 1032 if (rt->rt_ifp->if_flags & IFF_POINTOPOINT)
ef87f48d 1033 info.sa_bcastaddr = rt->rt_ifa->ifa_dstaddr;
984263bc 1034 }
ef87f48d
JH
1035 size = rt_msg2(RTM_GET, &info, NULL, w);
1036 if (w->w_req != NULL && w->w_tmem != NULL) {
82ed7fc2 1037 struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
984263bc
MD
1038
1039 rtm->rtm_flags = rt->rt_flags;
1040 rtm->rtm_use = rt->rt_use;
1041 rtm->rtm_rmx = rt->rt_rmx;
1042 rtm->rtm_index = rt->rt_ifp->if_index;
1043 rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
1044 rtm->rtm_addrs = info.rti_addrs;
5fe66e68 1045 error = SYSCTL_OUT(w->w_req, rtm, size);
984263bc
MD
1046 return (error);
1047 }
1048 return (error);
1049}
1050
1051int
1052sysctl_iflist(af, w)
1053 int af;
82ed7fc2 1054 struct walkarg *w;
984263bc 1055{
82ed7fc2
RG
1056 struct ifnet *ifp;
1057 struct ifaddr *ifa;
984263bc
MD
1058 struct rt_addrinfo info;
1059 int len, error = 0;
1060
5fe66e68 1061 bzero(&info, sizeof info);
984263bc
MD
1062 TAILQ_FOREACH(ifp, &ifnet, if_link) {
1063 if (w->w_arg && w->w_arg != ifp->if_index)
1064 continue;
1065 ifa = TAILQ_FIRST(&ifp->if_addrhead);
ef87f48d
JH
1066 info.sa_ifpaddr = ifa->ifa_addr;
1067 len = rt_msg2(RTM_IFINFO, &info, NULL, w);
1068 info.sa_ifpaddr = NULL;
1069 if (w->w_req != NULL && w->w_tmem != NULL) {
82ed7fc2 1070 struct if_msghdr *ifm;
984263bc
MD
1071
1072 ifm = (struct if_msghdr *)w->w_tmem;
1073 ifm->ifm_index = ifp->if_index;
1074 ifm->ifm_flags = (u_short)ifp->if_flags;
1075 ifm->ifm_data = ifp->if_data;
1076 ifm->ifm_addrs = info.rti_addrs;
5fe66e68 1077 error = SYSCTL_OUT(w->w_req, ifm, len);
984263bc
MD
1078 if (error)
1079 return (error);
1080 }
ef87f48d 1081 while ((ifa = TAILQ_NEXT(ifa, ifa_link)) != NULL) {
984263bc
MD
1082 if (af && af != ifa->ifa_addr->sa_family)
1083 continue;
dadab5e9 1084 if (curproc->p_ucred->cr_prison && prison_if(curthread, ifa->ifa_addr))
984263bc 1085 continue;
ef87f48d
JH
1086 info.sa_ifaaddr = ifa->ifa_addr;
1087 info.sa_netmask = ifa->ifa_netmask;
1088 info.sa_bcastaddr = ifa->ifa_dstaddr;
1089 len = rt_msg2(RTM_NEWADDR, &info, NULL, w);
984263bc 1090 if (w->w_req && w->w_tmem) {
82ed7fc2 1091 struct ifa_msghdr *ifam;
984263bc
MD
1092
1093 ifam = (struct ifa_msghdr *)w->w_tmem;
1094 ifam->ifam_index = ifa->ifa_ifp->if_index;
1095 ifam->ifam_flags = ifa->ifa_flags;
1096 ifam->ifam_metric = ifa->ifa_metric;
1097 ifam->ifam_addrs = info.rti_addrs;
1098 error = SYSCTL_OUT(w->w_req, w->w_tmem, len);
1099 if (error)
1100 return (error);
1101 }
1102 }
ef87f48d 1103 info.sa_netmask = info.sa_ifaaddr = info.sa_bcastaddr = NULL;
984263bc
MD
1104 }
1105 return (0);
1106}
1107
1108static int
1109sysctl_rtsock(SYSCTL_HANDLER_ARGS)
1110{
1111 int *name = (int *)arg1;
1112 u_int namelen = arg2;
82ed7fc2 1113 struct radix_node_head *rnh;
984263bc
MD
1114 int i, s, error = EINVAL;
1115 u_char af;
1116 struct walkarg w;
1117
1118 name ++;
1119 namelen--;
1120 if (req->newptr)
1121 return (EPERM);
1122 if (namelen != 3)
1123 return (EINVAL);
1124 af = name[0];
5fe66e68 1125 bzero(&w, sizeof w);
984263bc
MD
1126 w.w_op = name[1];
1127 w.w_arg = name[2];
1128 w.w_req = req;
1129
1130 s = splnet();
1131 switch (w.w_op) {
1132
1133 case NET_RT_DUMP:
1134 case NET_RT_FLAGS:
1135 for (i = 1; i <= AF_MAX; i++)
1136 if ((rnh = rt_tables[i]) && (af == 0 || af == i) &&
1137 (error = rnh->rnh_walktree(rnh,
f23061d4 1138 sysctl_dumpentry, &w)))
984263bc
MD
1139 break;
1140 break;
1141
1142 case NET_RT_IFLIST:
1143 error = sysctl_iflist(af, &w);
1144 }
1145 splx(s);
1146 if (w.w_tmem)
1147 free(w.w_tmem, M_RTABLE);
1148 return (error);
1149}
1150
1151SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsock, "");
1152
1153/*
1154 * Definitions of protocols supported in the ROUTE domain.
1155 */
1156
1157extern struct domain routedomain; /* or at least forward */
1158
1159static struct protosw routesw[] = {
1160{ SOCK_RAW, &routedomain, 0, PR_ATOMIC|PR_ADDR,
1161 0, route_output, raw_ctlinput, 0,
9eeaa8a9 1162 cpu0_soport,
984263bc
MD
1163 raw_init, 0, 0, 0,
1164 &route_usrreqs
1165}
1166};
1167
1168static struct domain routedomain =
1169 { PF_ROUTE, "route", 0, 0, 0,
5fe66e68 1170 routesw, &routesw[(sizeof routesw)/(sizeof routesw[0])] };
984263bc
MD
1171
1172DOMAIN_SET(route);