2 * Copyright (c) 1988, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)rtsock.c 8.5 (Berkeley) 11/2/94
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/sysctl.h>
43 #include <sys/malloc.h>
45 #include <sys/socket.h>
46 #include <sys/socketvar.h>
47 #include <sys/domain.h>
48 #include <sys/protosw.h>
51 #include <net/route.h>
52 #include <net/raw_cb.h>
54 MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
56 static struct sockaddr route_dst = { 2, PF_ROUTE, };
57 static struct sockaddr route_src = { 2, PF_ROUTE, };
58 static struct sockaddr sa_zero = { sizeof(sa_zero), AF_INET, };
59 static struct sockproto route_proto = { PF_ROUTE, };
65 struct sysctl_req *w_req;
69 rt_msg1 __P((int, struct rt_addrinfo *));
70 static int rt_msg2 __P((int,
71 struct rt_addrinfo *, caddr_t, struct walkarg *));
72 static int rt_xaddrs __P((caddr_t, caddr_t, struct rt_addrinfo *));
73 static int sysctl_dumpentry __P((struct radix_node *rn, void *vw));
74 static int sysctl_iflist __P((int af, struct walkarg *w));
75 static int route_output __P((struct mbuf *, struct socket *));
76 static void rt_setmetrics __P((u_long, struct rt_metrics *, struct rt_metrics *));
78 /* Sleazy use of local variables throughout file, warning!!!! */
79 #define dst info.rti_info[RTAX_DST]
80 #define gate info.rti_info[RTAX_GATEWAY]
81 #define netmask info.rti_info[RTAX_NETMASK]
82 #define genmask info.rti_info[RTAX_GENMASK]
83 #define ifpaddr info.rti_info[RTAX_IFP]
84 #define ifaaddr info.rti_info[RTAX_IFA]
85 #define brdaddr info.rti_info[RTAX_BRD]
88 * It really doesn't make any sense at all for this code to share much
89 * with raw_usrreq.c, since its functionality is so restricted. XXX
92 rts_abort(struct socket *so)
96 error = raw_usrreqs.pru_abort(so);
101 /* pru_accept is EOPNOTSUPP */
104 rts_attach(struct socket *so, int proto, struct proc *p)
109 if (sotorawcb(so) != 0)
110 return EISCONN; /* XXX panic? */
111 MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK); /* XXX */
114 bzero(rp, sizeof *rp);
117 * The splnet() is necessary to block protocols from sending
118 * error notifications (like RTM_REDIRECT or RTM_LOSING) while
119 * this PCB is extant but incompletely initialized.
120 * Probably we should try to do more of this work beforehand and
124 so->so_pcb = (caddr_t)rp;
125 error = raw_usrreqs.pru_attach(so, proto, p);
132 switch(rp->rcb_proto.sp_protocol) {
137 route_cb.ip6_count++;
140 route_cb.ipx_count++;
146 rp->rcb_faddr = &route_src;
147 route_cb.any_count++;
149 so->so_options |= SO_USELOOPBACK;
155 rts_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
159 error = raw_usrreqs.pru_bind(so, nam, p); /* xxx just EINVAL */
165 rts_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
169 error = raw_usrreqs.pru_connect(so, nam, p); /* XXX just EINVAL */
174 /* pru_connect2 is EOPNOTSUPP */
175 /* pru_control is EOPNOTSUPP */
178 rts_detach(struct socket *so)
180 struct rawcb *rp = sotorawcb(so);
185 switch(rp->rcb_proto.sp_protocol) {
190 route_cb.ip6_count--;
193 route_cb.ipx_count--;
199 route_cb.any_count--;
201 error = raw_usrreqs.pru_detach(so);
207 rts_disconnect(struct socket *so)
211 error = raw_usrreqs.pru_disconnect(so);
216 /* pru_listen is EOPNOTSUPP */
219 rts_peeraddr(struct socket *so, struct sockaddr **nam)
223 error = raw_usrreqs.pru_peeraddr(so, nam);
228 /* pru_rcvd is EOPNOTSUPP */
229 /* pru_rcvoob is EOPNOTSUPP */
232 rts_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
233 struct mbuf *control, struct proc *p)
237 error = raw_usrreqs.pru_send(so, flags, m, nam, control, p);
242 /* pru_sense is null */
245 rts_shutdown(struct socket *so)
249 error = raw_usrreqs.pru_shutdown(so);
255 rts_sockaddr(struct socket *so, struct sockaddr **nam)
259 error = raw_usrreqs.pru_sockaddr(so, nam);
264 static struct pr_usrreqs route_usrreqs = {
265 rts_abort, pru_accept_notsupp, rts_attach, rts_bind, rts_connect,
266 pru_connect2_notsupp, pru_control_notsupp, rts_detach, rts_disconnect,
267 pru_listen_notsupp, rts_peeraddr, pru_rcvd_notsupp, pru_rcvoob_notsupp,
268 rts_send, pru_sense_null, rts_shutdown, rts_sockaddr,
269 sosend, soreceive, sopoll
275 register struct mbuf *m;
278 register struct rt_msghdr *rtm = 0;
279 register struct rtentry *rt = 0;
280 struct rtentry *saved_nrt = 0;
281 struct radix_node_head *rnh;
282 struct rt_addrinfo info;
284 struct ifnet *ifp = 0;
285 struct ifaddr *ifa = 0;
287 #define senderr(e) { error = e; goto flush;}
288 if (m == 0 || ((m->m_len < sizeof(long)) &&
289 (m = m_pullup(m, sizeof(long))) == 0))
291 if ((m->m_flags & M_PKTHDR) == 0)
292 panic("route_output");
293 len = m->m_pkthdr.len;
294 if (len < sizeof(*rtm) ||
295 len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
299 R_Malloc(rtm, struct rt_msghdr *, len);
304 m_copydata(m, 0, len, (caddr_t)rtm);
305 if (rtm->rtm_version != RTM_VERSION) {
307 senderr(EPROTONOSUPPORT);
309 rtm->rtm_pid = curproc->p_pid;
310 info.rti_addrs = rtm->rtm_addrs;
311 if (rt_xaddrs((caddr_t)(rtm + 1), len + (caddr_t)rtm, &info)) {
315 if (dst == 0 || (dst->sa_family >= AF_MAX)
316 || (gate != 0 && (gate->sa_family >= AF_MAX)))
319 struct radix_node *t;
320 t = rn_addmask((caddr_t)genmask, 0, 1);
321 if (t && Bcmp((caddr_t *)genmask + 1, (caddr_t *)t->rn_key + 1,
322 *(u_char *)t->rn_key - 1) == 0)
323 genmask = (struct sockaddr *)(t->rn_key);
327 switch (rtm->rtm_type) {
332 error = rtrequest(RTM_ADD, dst, gate, netmask,
333 rtm->rtm_flags, &saved_nrt);
334 if (error == 0 && saved_nrt) {
335 rt_setmetrics(rtm->rtm_inits,
336 &rtm->rtm_rmx, &saved_nrt->rt_rmx);
337 saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
338 saved_nrt->rt_rmx.rmx_locks |=
339 (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
340 saved_nrt->rt_refcnt--;
341 saved_nrt->rt_genmask = genmask;
346 error = rtrequest(RTM_DELETE, dst, gate, netmask,
347 rtm->rtm_flags, &saved_nrt);
349 if ((rt = saved_nrt))
358 if ((rnh = rt_tables[dst->sa_family]) == 0) {
359 senderr(EAFNOSUPPORT);
360 } else if ((rt = (struct rtentry *)
361 rnh->rnh_lookup(dst, netmask, rnh)) != NULL)
365 switch(rtm->rtm_type) {
370 gate = rt->rt_gateway;
371 netmask = rt_mask(rt);
372 genmask = rt->rt_genmask;
373 if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) {
376 ifpaddr = ifp->if_addrhead.tqh_first->ifa_addr;
377 ifaaddr = rt->rt_ifa->ifa_addr;
378 rtm->rtm_index = ifp->if_index;
384 len = rt_msg2(rtm->rtm_type, &info, (caddr_t)0,
385 (struct walkarg *)0);
386 if (len > rtm->rtm_msglen) {
387 struct rt_msghdr *new_rtm;
388 R_Malloc(new_rtm, struct rt_msghdr *, len);
391 Bcopy(rtm, new_rtm, rtm->rtm_msglen);
392 Free(rtm); rtm = new_rtm;
394 (void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm,
395 (struct walkarg *)0);
396 rtm->rtm_flags = rt->rt_flags;
397 rtm->rtm_rmx = rt->rt_rmx;
398 rtm->rtm_addrs = info.rti_addrs;
402 if (gate && (error = rt_setgate(rt, rt_key(rt), gate)))
406 * If they tried to change things but didn't specify
407 * the required gateway, then just use the old one.
408 * This can happen if the user tries to change the
409 * flags on the default route without changing the
410 * default gateway. Changing flags still doesn't work.
412 if ((rt->rt_flags & RTF_GATEWAY) && !gate)
413 gate = rt->rt_gateway;
415 /* new gateway could require new ifaddr, ifp;
416 flags may also be different; ifp may be specified
417 by ll sockaddr when protocol address is ambiguous */
418 if (ifpaddr && (ifa = ifa_ifwithnet(ifpaddr)) &&
419 (ifp = ifa->ifa_ifp) && (ifaaddr || gate))
420 ifa = ifaof_ifpforaddr(ifaaddr ? ifaaddr : gate,
422 else if ((ifaaddr && (ifa = ifa_ifwithaddr(ifaaddr))) ||
423 (gate && (ifa = ifa_ifwithroute(rt->rt_flags,
427 register struct ifaddr *oifa = rt->rt_ifa;
429 if (oifa && oifa->ifa_rtrequest)
430 oifa->ifa_rtrequest(RTM_DELETE,
438 rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
440 if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
441 rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, gate);
443 rt->rt_genmask = genmask;
448 rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
449 rt->rt_rmx.rmx_locks |=
450 (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
462 rtm->rtm_errno = error;
464 rtm->rtm_flags |= RTF_DONE;
469 register struct rawcb *rp = 0;
471 * Check to see if we don't want our own messages.
473 if ((so->so_options & SO_USELOOPBACK) == 0) {
474 if (route_cb.any_count <= 1) {
480 /* There is another listener, so construct message */
484 m_copyback(m, 0, rtm->rtm_msglen, (caddr_t)rtm);
488 rp->rcb_proto.sp_family = 0; /* Avoid us */
490 route_proto.sp_protocol = dst->sa_family;
491 raw_input(m, &route_proto, &route_src, &route_dst);
493 rp->rcb_proto.sp_family = PF_ROUTE;
499 rt_setmetrics(which, in, out)
501 register struct rt_metrics *in, *out;
503 #define metric(f, e) if (which & (f)) out->e = in->e;
504 metric(RTV_RPIPE, rmx_recvpipe);
505 metric(RTV_SPIPE, rmx_sendpipe);
506 metric(RTV_SSTHRESH, rmx_ssthresh);
507 metric(RTV_RTT, rmx_rtt);
508 metric(RTV_RTTVAR, rmx_rttvar);
509 metric(RTV_HOPCOUNT, rmx_hopcount);
510 metric(RTV_MTU, rmx_mtu);
511 metric(RTV_EXPIRE, rmx_expire);
516 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
517 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
521 * Extract the addresses of the passed sockaddrs.
522 * Do a little sanity checking so as to avoid bad memory references.
523 * This data is derived straight from userland.
526 rt_xaddrs(cp, cplim, rtinfo)
527 register caddr_t cp, cplim;
528 register struct rt_addrinfo *rtinfo;
530 register struct sockaddr *sa;
533 bzero(rtinfo->rti_info, sizeof(rtinfo->rti_info));
534 for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
535 if ((rtinfo->rti_addrs & (1 << i)) == 0)
537 sa = (struct sockaddr *)cp;
541 if ( (cp + sa->sa_len) > cplim ) {
546 * there are no more.. quit now
547 * If there are more bits, they are in error.
548 * I've seen this. route(1) can evidently generate these.
549 * This causes kernel to core dump.
550 * for compatibility, If we see this, point to a safe address.
552 if (sa->sa_len == 0) {
553 rtinfo->rti_info[i] = &sa_zero;
554 return (0); /* should be EINVAL but for compat */
558 rtinfo->rti_info[i] = sa;
565 rt_msg1(type, rtinfo)
567 register struct rt_addrinfo *rtinfo;
569 register struct rt_msghdr *rtm;
570 register struct mbuf *m;
572 register struct sockaddr *sa;
575 m = m_gethdr(M_DONTWAIT, MT_DATA);
582 len = sizeof(struct ifa_msghdr);
587 len = sizeof(struct ifma_msghdr);
591 len = sizeof(struct if_msghdr);
595 len = sizeof(struct rt_msghdr);
599 m->m_pkthdr.len = m->m_len = len;
600 m->m_pkthdr.rcvif = 0;
601 rtm = mtod(m, struct rt_msghdr *);
602 bzero((caddr_t)rtm, len);
603 for (i = 0; i < RTAX_MAX; i++) {
604 if ((sa = rtinfo->rti_info[i]) == NULL)
606 rtinfo->rti_addrs |= (1 << i);
607 dlen = ROUNDUP(sa->sa_len);
608 m_copyback(m, len, dlen, (caddr_t)sa);
611 if (m->m_pkthdr.len != len) {
615 rtm->rtm_msglen = len;
616 rtm->rtm_version = RTM_VERSION;
617 rtm->rtm_type = type;
622 rt_msg2(type, rtinfo, cp, w)
624 register struct rt_addrinfo *rtinfo;
629 int len, dlen, second_time = 0;
632 rtinfo->rti_addrs = 0;
638 len = sizeof(struct ifa_msghdr);
642 len = sizeof(struct if_msghdr);
646 len = sizeof(struct rt_msghdr);
651 for (i = 0; i < RTAX_MAX; i++) {
652 register struct sockaddr *sa;
654 if ((sa = rtinfo->rti_info[i]) == 0)
656 rtinfo->rti_addrs |= (1 << i);
657 dlen = ROUNDUP(sa->sa_len);
659 bcopy((caddr_t)sa, cp, (unsigned)dlen);
664 if (cp == 0 && w != NULL && !second_time) {
665 register struct walkarg *rw = w;
668 if (rw->w_tmemsize < len) {
670 free(rw->w_tmem, M_RTABLE);
671 rw->w_tmem = (caddr_t)
672 malloc(len, M_RTABLE, M_NOWAIT);
674 rw->w_tmemsize = len;
684 register struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
686 rtm->rtm_version = RTM_VERSION;
687 rtm->rtm_type = type;
688 rtm->rtm_msglen = len;
694 * This routine is called to generate a message from the routing
695 * socket indicating that a redirect has occured, a routing lookup
696 * has failed, or that a protocol has detected timeouts to a particular
700 rt_missmsg(type, rtinfo, flags, error)
701 int type, flags, error;
702 register struct rt_addrinfo *rtinfo;
704 register struct rt_msghdr *rtm;
705 register struct mbuf *m;
706 struct sockaddr *sa = rtinfo->rti_info[RTAX_DST];
708 if (route_cb.any_count == 0)
710 m = rt_msg1(type, rtinfo);
713 rtm = mtod(m, struct rt_msghdr *);
714 rtm->rtm_flags = RTF_DONE | flags;
715 rtm->rtm_errno = error;
716 rtm->rtm_addrs = rtinfo->rti_addrs;
717 route_proto.sp_protocol = sa ? sa->sa_family : 0;
718 raw_input(m, &route_proto, &route_src, &route_dst);
722 * This routine is called to generate a message from the routing
723 * socket indicating that the status of a network interface has changed.
727 register struct ifnet *ifp;
729 register struct if_msghdr *ifm;
731 struct rt_addrinfo info;
733 if (route_cb.any_count == 0)
735 bzero((caddr_t)&info, sizeof(info));
736 m = rt_msg1(RTM_IFINFO, &info);
739 ifm = mtod(m, struct if_msghdr *);
740 ifm->ifm_index = ifp->if_index;
741 ifm->ifm_flags = (u_short)ifp->if_flags;
742 ifm->ifm_data = ifp->if_data;
744 route_proto.sp_protocol = 0;
745 raw_input(m, &route_proto, &route_src, &route_dst);
749 * This is called to generate messages from the routing socket
750 * indicating a network interface has had addresses associated with it.
751 * if we ever reverse the logic and replace messages TO the routing
752 * socket indicate a request to configure interfaces, then it will
753 * be unnecessary as the routing socket will automatically generate
757 rt_newaddrmsg(cmd, ifa, error, rt)
759 register struct ifaddr *ifa;
760 register struct rtentry *rt;
762 struct rt_addrinfo info;
763 struct sockaddr *sa = 0;
766 struct ifnet *ifp = ifa->ifa_ifp;
768 if (route_cb.any_count == 0)
770 for (pass = 1; pass < 3; pass++) {
771 bzero((caddr_t)&info, sizeof(info));
772 if ((cmd == RTM_ADD && pass == 1) ||
773 (cmd == RTM_DELETE && pass == 2)) {
774 register struct ifa_msghdr *ifam;
775 int ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR;
777 ifaaddr = sa = ifa->ifa_addr;
778 ifpaddr = ifp->if_addrhead.tqh_first->ifa_addr;
779 netmask = ifa->ifa_netmask;
780 brdaddr = ifa->ifa_dstaddr;
781 if ((m = rt_msg1(ncmd, &info)) == NULL)
783 ifam = mtod(m, struct ifa_msghdr *);
784 ifam->ifam_index = ifp->if_index;
785 ifam->ifam_metric = ifa->ifa_metric;
786 ifam->ifam_flags = ifa->ifa_flags;
787 ifam->ifam_addrs = info.rti_addrs;
789 if ((cmd == RTM_ADD && pass == 2) ||
790 (cmd == RTM_DELETE && pass == 1)) {
791 register struct rt_msghdr *rtm;
795 netmask = rt_mask(rt);
796 dst = sa = rt_key(rt);
797 gate = rt->rt_gateway;
798 if ((m = rt_msg1(cmd, &info)) == NULL)
800 rtm = mtod(m, struct rt_msghdr *);
801 rtm->rtm_index = ifp->if_index;
802 rtm->rtm_flags |= rt->rt_flags;
803 rtm->rtm_errno = error;
804 rtm->rtm_addrs = info.rti_addrs;
806 route_proto.sp_protocol = sa ? sa->sa_family : 0;
807 raw_input(m, &route_proto, &route_src, &route_dst);
812 * This is the analogue to the rt_newaddrmsg which performs the same
813 * function but for multicast group memberhips. This is easier since
814 * there is no route state to worry about.
817 rt_newmaddrmsg(cmd, ifma)
819 struct ifmultiaddr *ifma;
821 struct rt_addrinfo info;
823 struct ifnet *ifp = ifma->ifma_ifp;
824 struct ifma_msghdr *ifmam;
826 if (route_cb.any_count == 0)
829 bzero((caddr_t)&info, sizeof(info));
830 ifaaddr = ifma->ifma_addr;
831 if (ifp && ifp->if_addrhead.tqh_first)
832 ifpaddr = ifp->if_addrhead.tqh_first->ifa_addr;
836 * If a link-layer address is present, present it as a ``gateway''
837 * (similarly to how ARP entries, e.g., are presented).
839 gate = ifma->ifma_lladdr;
840 if ((m = rt_msg1(cmd, &info)) == NULL)
842 ifmam = mtod(m, struct ifma_msghdr *);
843 ifmam->ifmam_index = ifp->if_index;
844 ifmam->ifmam_addrs = info.rti_addrs;
845 route_proto.sp_protocol = ifma->ifma_addr->sa_family;
846 raw_input(m, &route_proto, &route_src, &route_dst);
850 * This is used in dumping the kernel table via sysctl().
853 sysctl_dumpentry(rn, vw)
854 struct radix_node *rn;
857 register struct walkarg *w = vw;
858 register struct rtentry *rt = (struct rtentry *)rn;
860 struct rt_addrinfo info;
862 if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
864 bzero((caddr_t)&info, sizeof(info));
866 gate = rt->rt_gateway;
867 netmask = rt_mask(rt);
868 genmask = rt->rt_genmask;
869 size = rt_msg2(RTM_GET, &info, 0, w);
870 if (w->w_req && w->w_tmem) {
871 register struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
873 rtm->rtm_flags = rt->rt_flags;
874 rtm->rtm_use = rt->rt_use;
875 rtm->rtm_rmx = rt->rt_rmx;
876 rtm->rtm_index = rt->rt_ifp->if_index;
877 rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
878 rtm->rtm_addrs = info.rti_addrs;
879 error = SYSCTL_OUT(w->w_req, (caddr_t)rtm, size);
888 register struct walkarg *w;
890 register struct ifnet *ifp;
891 register struct ifaddr *ifa;
892 struct rt_addrinfo info;
895 bzero((caddr_t)&info, sizeof(info));
896 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) {
897 if (w->w_arg && w->w_arg != ifp->if_index)
899 ifa = ifp->if_addrhead.tqh_first;
900 ifpaddr = ifa->ifa_addr;
901 len = rt_msg2(RTM_IFINFO, &info, (caddr_t)0, w);
903 if (w->w_req && w->w_tmem) {
904 register struct if_msghdr *ifm;
906 ifm = (struct if_msghdr *)w->w_tmem;
907 ifm->ifm_index = ifp->if_index;
908 ifm->ifm_flags = (u_short)ifp->if_flags;
909 ifm->ifm_data = ifp->if_data;
910 ifm->ifm_addrs = info.rti_addrs;
911 error = SYSCTL_OUT(w->w_req,(caddr_t)ifm, len);
915 while ((ifa = ifa->ifa_link.tqe_next) != 0) {
916 if (af && af != ifa->ifa_addr->sa_family)
918 if (curproc->p_prison && prison_if(curproc, ifa->ifa_addr))
920 ifaaddr = ifa->ifa_addr;
921 netmask = ifa->ifa_netmask;
922 brdaddr = ifa->ifa_dstaddr;
923 len = rt_msg2(RTM_NEWADDR, &info, 0, w);
924 if (w->w_req && w->w_tmem) {
925 register struct ifa_msghdr *ifam;
927 ifam = (struct ifa_msghdr *)w->w_tmem;
928 ifam->ifam_index = ifa->ifa_ifp->if_index;
929 ifam->ifam_flags = ifa->ifa_flags;
930 ifam->ifam_metric = ifa->ifa_metric;
931 ifam->ifam_addrs = info.rti_addrs;
932 error = SYSCTL_OUT(w->w_req, w->w_tmem, len);
937 ifaaddr = netmask = brdaddr = 0;
943 sysctl_rtsock(SYSCTL_HANDLER_ARGS)
945 int *name = (int *)arg1;
946 u_int namelen = arg2;
947 register struct radix_node_head *rnh;
948 int i, s, error = EINVAL;
959 Bzero(&w, sizeof(w));
969 for (i = 1; i <= AF_MAX; i++)
970 if ((rnh = rt_tables[i]) && (af == 0 || af == i) &&
971 (error = rnh->rnh_walktree(rnh,
972 sysctl_dumpentry, &w)))
977 error = sysctl_iflist(af, &w);
981 free(w.w_tmem, M_RTABLE);
985 SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsock, "");
988 * Definitions of protocols supported in the ROUTE domain.
991 extern struct domain routedomain; /* or at least forward */
993 static struct protosw routesw[] = {
994 { SOCK_RAW, &routedomain, 0, PR_ATOMIC|PR_ADDR,
995 0, route_output, raw_ctlinput, 0,
1002 static struct domain routedomain =
1003 { PF_ROUTE, "route", 0, 0, 0,
1004 routesw, &routesw[sizeof(routesw)/sizeof(routesw[0])] };