1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1988, 1991, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 3328070a0eSRuslan Ermilov * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 34c3aac50fSPeter Wemm * $FreeBSD$ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37a29f300eSGarrett Wollman 38df8bae1dSRodney W. Grimes #include <sys/param.h> 39960ed29cSSeigo Tanimura #include <sys/domain.h> 40748e0b0aSGarrett Wollman #include <sys/kernel.h> 41960ed29cSSeigo Tanimura #include <sys/jail.h> 424d1d4912SBruce Evans #include <sys/malloc.h> 43df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 44960ed29cSSeigo Tanimura #include <sys/proc.h> 45960ed29cSSeigo Tanimura #include <sys/protosw.h> 46960ed29cSSeigo Tanimura #include <sys/signalvar.h> 47df8bae1dSRodney W. Grimes #include <sys/socket.h> 48df8bae1dSRodney W. Grimes #include <sys/socketvar.h> 49960ed29cSSeigo Tanimura #include <sys/sysctl.h> 50960ed29cSSeigo Tanimura #include <sys/systm.h> 51df8bae1dSRodney W. Grimes 52df8bae1dSRodney W. Grimes #include <net/if.h> 53df8bae1dSRodney W. Grimes #include <net/raw_cb.h> 54960ed29cSSeigo Tanimura #include <net/route.h> 55df8bae1dSRodney W. Grimes 56a1c995b6SPoul-Henning Kamp MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables"); 57a1c995b6SPoul-Henning Kamp 5852041295SPoul-Henning Kamp static struct sockaddr route_dst = { 2, PF_ROUTE, }; 5952041295SPoul-Henning Kamp static struct sockaddr route_src = { 2, PF_ROUTE, }; 60076d0761SJulian Elischer static struct sockaddr sa_zero = { sizeof(sa_zero), AF_INET, }; 6152041295SPoul-Henning Kamp static struct sockproto route_proto = { PF_ROUTE, }; 62df8bae1dSRodney W. Grimes 63df8bae1dSRodney W. Grimes struct walkarg { 6452041295SPoul-Henning Kamp int w_tmemsize; 6552041295SPoul-Henning Kamp int w_op, w_arg; 6652041295SPoul-Henning Kamp caddr_t w_tmem; 6752041295SPoul-Henning Kamp struct sysctl_req *w_req; 68df8bae1dSRodney W. Grimes }; 69df8bae1dSRodney W. Grimes 70df8bae1dSRodney W. Grimes static struct mbuf * 71929ddbbbSAlfred Perlstein rt_msg1(int, struct rt_addrinfo *); 72929ddbbbSAlfred Perlstein static int rt_msg2(int, struct rt_addrinfo *, caddr_t, struct walkarg *); 73929ddbbbSAlfred Perlstein static int rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *); 74929ddbbbSAlfred Perlstein static int sysctl_dumpentry(struct radix_node *rn, void *vw); 75929ddbbbSAlfred Perlstein static int sysctl_iflist(int af, struct walkarg *w); 76929ddbbbSAlfred Perlstein static int route_output(struct mbuf *, struct socket *); 77929ddbbbSAlfred Perlstein static void rt_setmetrics(u_long, struct rt_metrics *, struct rt_metrics *); 78df8bae1dSRodney W. Grimes 79df8bae1dSRodney W. Grimes /* Sleazy use of local variables throughout file, warning!!!! */ 80df8bae1dSRodney W. Grimes #define dst info.rti_info[RTAX_DST] 81df8bae1dSRodney W. Grimes #define gate info.rti_info[RTAX_GATEWAY] 82df8bae1dSRodney W. Grimes #define netmask info.rti_info[RTAX_NETMASK] 83df8bae1dSRodney W. Grimes #define genmask info.rti_info[RTAX_GENMASK] 84df8bae1dSRodney W. Grimes #define ifpaddr info.rti_info[RTAX_IFP] 85df8bae1dSRodney W. Grimes #define ifaaddr info.rti_info[RTAX_IFA] 86df8bae1dSRodney W. Grimes #define brdaddr info.rti_info[RTAX_BRD] 87df8bae1dSRodney W. Grimes 88a29f300eSGarrett Wollman /* 89a29f300eSGarrett Wollman * It really doesn't make any sense at all for this code to share much 90a29f300eSGarrett Wollman * with raw_usrreq.c, since its functionality is so restricted. XXX 91a29f300eSGarrett Wollman */ 9252041295SPoul-Henning Kamp static int 93a29f300eSGarrett Wollman rts_abort(struct socket *so) 94df8bae1dSRodney W. Grimes { 95a29f300eSGarrett Wollman int s, error; 96df8bae1dSRodney W. Grimes s = splnet(); 97a29f300eSGarrett Wollman error = raw_usrreqs.pru_abort(so); 98df8bae1dSRodney W. Grimes splx(s); 99a29f300eSGarrett Wollman return error; 100df8bae1dSRodney W. Grimes } 101a29f300eSGarrett Wollman 102a29f300eSGarrett Wollman /* pru_accept is EOPNOTSUPP */ 103a29f300eSGarrett Wollman 104a29f300eSGarrett Wollman static int 105b40ce416SJulian Elischer rts_attach(struct socket *so, int proto, struct thread *td) 106a29f300eSGarrett Wollman { 107a29f300eSGarrett Wollman struct rawcb *rp; 108a29f300eSGarrett Wollman int s, error; 109a29f300eSGarrett Wollman 110a29f300eSGarrett Wollman if (sotorawcb(so) != 0) 111a29f300eSGarrett Wollman return EISCONN; /* XXX panic? */ 1127cc0979fSDavid Malone /* XXX */ 1137cc0979fSDavid Malone MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK | M_ZERO); 114a29f300eSGarrett Wollman if (rp == 0) 115a29f300eSGarrett Wollman return ENOBUFS; 116a29f300eSGarrett Wollman 117a29f300eSGarrett Wollman /* 118a29f300eSGarrett Wollman * The splnet() is necessary to block protocols from sending 119a29f300eSGarrett Wollman * error notifications (like RTM_REDIRECT or RTM_LOSING) while 120a29f300eSGarrett Wollman * this PCB is extant but incompletely initialized. 121a29f300eSGarrett Wollman * Probably we should try to do more of this work beforehand and 122a29f300eSGarrett Wollman * eliminate the spl. 123a29f300eSGarrett Wollman */ 124a29f300eSGarrett Wollman s = splnet(); 125a29f300eSGarrett Wollman so->so_pcb = (caddr_t)rp; 126162c0b2eSRuslan Ermilov error = raw_attach(so, proto); 127a29f300eSGarrett Wollman rp = sotorawcb(so); 128a29f300eSGarrett Wollman if (error) { 129a29f300eSGarrett Wollman splx(s); 1307ba271aeSJonathan Chen so->so_pcb = NULL; 131a29f300eSGarrett Wollman free(rp, M_PCB); 132a29f300eSGarrett Wollman return error; 133a29f300eSGarrett Wollman } 134a29f300eSGarrett Wollman switch(rp->rcb_proto.sp_protocol) { 135a29f300eSGarrett Wollman case AF_INET: 136df8bae1dSRodney W. Grimes route_cb.ip_count++; 137a29f300eSGarrett Wollman break; 138899ce4f4SYoshinobu Inoue case AF_INET6: 139899ce4f4SYoshinobu Inoue route_cb.ip6_count++; 140899ce4f4SYoshinobu Inoue break; 141a29f300eSGarrett Wollman case AF_IPX: 142cc6a66f2SJulian Elischer route_cb.ipx_count++; 143a29f300eSGarrett Wollman break; 144a29f300eSGarrett Wollman case AF_NS: 145df8bae1dSRodney W. Grimes route_cb.ns_count++; 146a29f300eSGarrett Wollman break; 147a29f300eSGarrett Wollman } 148df8bae1dSRodney W. Grimes rp->rcb_faddr = &route_src; 149df8bae1dSRodney W. Grimes route_cb.any_count++; 15003e49181SSeigo Tanimura soisconnected(so); 151df8bae1dSRodney W. Grimes so->so_options |= SO_USELOOPBACK; 152df8bae1dSRodney W. Grimes splx(s); 153a29f300eSGarrett Wollman return 0; 154df8bae1dSRodney W. Grimes } 155df8bae1dSRodney W. Grimes 156a29f300eSGarrett Wollman static int 157b40ce416SJulian Elischer rts_bind(struct socket *so, struct sockaddr *nam, struct thread *td) 158a29f300eSGarrett Wollman { 159a29f300eSGarrett Wollman int s, error; 160a29f300eSGarrett Wollman s = splnet(); 161b40ce416SJulian Elischer error = raw_usrreqs.pru_bind(so, nam, td); /* xxx just EINVAL */ 162a29f300eSGarrett Wollman splx(s); 163a29f300eSGarrett Wollman return error; 164a29f300eSGarrett Wollman } 165a29f300eSGarrett Wollman 166a29f300eSGarrett Wollman static int 167b40ce416SJulian Elischer rts_connect(struct socket *so, struct sockaddr *nam, struct thread *td) 168a29f300eSGarrett Wollman { 169a29f300eSGarrett Wollman int s, error; 170a29f300eSGarrett Wollman s = splnet(); 171b40ce416SJulian Elischer error = raw_usrreqs.pru_connect(so, nam, td); /* XXX just EINVAL */ 172a29f300eSGarrett Wollman splx(s); 173a29f300eSGarrett Wollman return error; 174a29f300eSGarrett Wollman } 175a29f300eSGarrett Wollman 176a29f300eSGarrett Wollman /* pru_connect2 is EOPNOTSUPP */ 177a29f300eSGarrett Wollman /* pru_control is EOPNOTSUPP */ 178a29f300eSGarrett Wollman 179a29f300eSGarrett Wollman static int 180a29f300eSGarrett Wollman rts_detach(struct socket *so) 181a29f300eSGarrett Wollman { 182a29f300eSGarrett Wollman struct rawcb *rp = sotorawcb(so); 183a29f300eSGarrett Wollman int s, error; 184a29f300eSGarrett Wollman 185a29f300eSGarrett Wollman s = splnet(); 186a29f300eSGarrett Wollman if (rp != 0) { 187a29f300eSGarrett Wollman switch(rp->rcb_proto.sp_protocol) { 188a29f300eSGarrett Wollman case AF_INET: 189a29f300eSGarrett Wollman route_cb.ip_count--; 190a29f300eSGarrett Wollman break; 191899ce4f4SYoshinobu Inoue case AF_INET6: 192899ce4f4SYoshinobu Inoue route_cb.ip6_count--; 193899ce4f4SYoshinobu Inoue break; 194a29f300eSGarrett Wollman case AF_IPX: 195a29f300eSGarrett Wollman route_cb.ipx_count--; 196a29f300eSGarrett Wollman break; 197a29f300eSGarrett Wollman case AF_NS: 198a29f300eSGarrett Wollman route_cb.ns_count--; 199a29f300eSGarrett Wollman break; 200a29f300eSGarrett Wollman } 201a29f300eSGarrett Wollman route_cb.any_count--; 202a29f300eSGarrett Wollman } 203a29f300eSGarrett Wollman error = raw_usrreqs.pru_detach(so); 204a29f300eSGarrett Wollman splx(s); 205a29f300eSGarrett Wollman return error; 206a29f300eSGarrett Wollman } 207a29f300eSGarrett Wollman 208a29f300eSGarrett Wollman static int 209a29f300eSGarrett Wollman rts_disconnect(struct socket *so) 210a29f300eSGarrett Wollman { 211a29f300eSGarrett Wollman int s, error; 212a29f300eSGarrett Wollman s = splnet(); 213a29f300eSGarrett Wollman error = raw_usrreqs.pru_disconnect(so); 214a29f300eSGarrett Wollman splx(s); 215a29f300eSGarrett Wollman return error; 216a29f300eSGarrett Wollman } 217a29f300eSGarrett Wollman 218a29f300eSGarrett Wollman /* pru_listen is EOPNOTSUPP */ 219a29f300eSGarrett Wollman 220a29f300eSGarrett Wollman static int 22157bf258eSGarrett Wollman rts_peeraddr(struct socket *so, struct sockaddr **nam) 222a29f300eSGarrett Wollman { 223a29f300eSGarrett Wollman int s, error; 224a29f300eSGarrett Wollman s = splnet(); 225a29f300eSGarrett Wollman error = raw_usrreqs.pru_peeraddr(so, nam); 226a29f300eSGarrett Wollman splx(s); 227a29f300eSGarrett Wollman return error; 228a29f300eSGarrett Wollman } 229a29f300eSGarrett Wollman 230a29f300eSGarrett Wollman /* pru_rcvd is EOPNOTSUPP */ 231a29f300eSGarrett Wollman /* pru_rcvoob is EOPNOTSUPP */ 232a29f300eSGarrett Wollman 233a29f300eSGarrett Wollman static int 23457bf258eSGarrett Wollman rts_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, 235b40ce416SJulian Elischer struct mbuf *control, struct thread *td) 236a29f300eSGarrett Wollman { 237a29f300eSGarrett Wollman int s, error; 238a29f300eSGarrett Wollman s = splnet(); 239b40ce416SJulian Elischer error = raw_usrreqs.pru_send(so, flags, m, nam, control, td); 240a29f300eSGarrett Wollman splx(s); 241a29f300eSGarrett Wollman return error; 242a29f300eSGarrett Wollman } 243a29f300eSGarrett Wollman 244a29f300eSGarrett Wollman /* pru_sense is null */ 245a29f300eSGarrett Wollman 246a29f300eSGarrett Wollman static int 247a29f300eSGarrett Wollman rts_shutdown(struct socket *so) 248a29f300eSGarrett Wollman { 249a29f300eSGarrett Wollman int s, error; 250a29f300eSGarrett Wollman s = splnet(); 251a29f300eSGarrett Wollman error = raw_usrreqs.pru_shutdown(so); 252a29f300eSGarrett Wollman splx(s); 253a29f300eSGarrett Wollman return error; 254a29f300eSGarrett Wollman } 255a29f300eSGarrett Wollman 256a29f300eSGarrett Wollman static int 25757bf258eSGarrett Wollman rts_sockaddr(struct socket *so, struct sockaddr **nam) 258a29f300eSGarrett Wollman { 259a29f300eSGarrett Wollman int s, error; 260a29f300eSGarrett Wollman s = splnet(); 261a29f300eSGarrett Wollman error = raw_usrreqs.pru_sockaddr(so, nam); 262a29f300eSGarrett Wollman splx(s); 263a29f300eSGarrett Wollman return error; 264a29f300eSGarrett Wollman } 265a29f300eSGarrett Wollman 266a29f300eSGarrett Wollman static struct pr_usrreqs route_usrreqs = { 267a29f300eSGarrett Wollman rts_abort, pru_accept_notsupp, rts_attach, rts_bind, rts_connect, 268a29f300eSGarrett Wollman pru_connect2_notsupp, pru_control_notsupp, rts_detach, rts_disconnect, 269a29f300eSGarrett Wollman pru_listen_notsupp, rts_peeraddr, pru_rcvd_notsupp, pru_rcvoob_notsupp, 270a29f300eSGarrett Wollman rts_send, pru_sense_null, rts_shutdown, rts_sockaddr, 271f8f6cbbaSPeter Wemm sosend, soreceive, sopoll 272a29f300eSGarrett Wollman }; 273a29f300eSGarrett Wollman 274df8bae1dSRodney W. Grimes /*ARGSUSED*/ 27552041295SPoul-Henning Kamp static int 276df8bae1dSRodney W. Grimes route_output(m, so) 277df8bae1dSRodney W. Grimes register struct mbuf *m; 278df8bae1dSRodney W. Grimes struct socket *so; 279df8bae1dSRodney W. Grimes { 280df8bae1dSRodney W. Grimes register struct rt_msghdr *rtm = 0; 281df8bae1dSRodney W. Grimes register struct rtentry *rt = 0; 282df8bae1dSRodney W. Grimes struct rtentry *saved_nrt = 0; 28378a82810SGarrett Wollman struct radix_node_head *rnh; 284df8bae1dSRodney W. Grimes struct rt_addrinfo info; 285df8bae1dSRodney W. Grimes int len, error = 0; 286df8bae1dSRodney W. Grimes struct ifnet *ifp = 0; 287df8bae1dSRodney W. Grimes struct ifaddr *ifa = 0; 288df8bae1dSRodney W. Grimes 289df8bae1dSRodney W. Grimes #define senderr(e) { error = e; goto flush;} 290df8bae1dSRodney W. Grimes if (m == 0 || ((m->m_len < sizeof(long)) && 291df8bae1dSRodney W. Grimes (m = m_pullup(m, sizeof(long))) == 0)) 292df8bae1dSRodney W. Grimes return (ENOBUFS); 293df8bae1dSRodney W. Grimes if ((m->m_flags & M_PKTHDR) == 0) 294df8bae1dSRodney W. Grimes panic("route_output"); 295df8bae1dSRodney W. Grimes len = m->m_pkthdr.len; 296df8bae1dSRodney W. Grimes if (len < sizeof(*rtm) || 297df8bae1dSRodney W. Grimes len != mtod(m, struct rt_msghdr *)->rtm_msglen) { 298df8bae1dSRodney W. Grimes dst = 0; 299df8bae1dSRodney W. Grimes senderr(EINVAL); 300df8bae1dSRodney W. Grimes } 301df8bae1dSRodney W. Grimes R_Malloc(rtm, struct rt_msghdr *, len); 302df8bae1dSRodney W. Grimes if (rtm == 0) { 303df8bae1dSRodney W. Grimes dst = 0; 304df8bae1dSRodney W. Grimes senderr(ENOBUFS); 305df8bae1dSRodney W. Grimes } 306df8bae1dSRodney W. Grimes m_copydata(m, 0, len, (caddr_t)rtm); 307df8bae1dSRodney W. Grimes if (rtm->rtm_version != RTM_VERSION) { 308df8bae1dSRodney W. Grimes dst = 0; 309df8bae1dSRodney W. Grimes senderr(EPROTONOSUPPORT); 310df8bae1dSRodney W. Grimes } 311df8bae1dSRodney W. Grimes rtm->rtm_pid = curproc->p_pid; 3128071913dSRuslan Ermilov bzero(&info, sizeof(info)); 313df8bae1dSRodney W. Grimes info.rti_addrs = rtm->rtm_addrs; 314076d0761SJulian Elischer if (rt_xaddrs((caddr_t)(rtm + 1), len + (caddr_t)rtm, &info)) { 315076d0761SJulian Elischer dst = 0; 316076d0761SJulian Elischer senderr(EINVAL); 317076d0761SJulian Elischer } 3188071913dSRuslan Ermilov info.rti_flags = rtm->rtm_flags; 319ed07cc7fSGarrett Wollman if (dst == 0 || (dst->sa_family >= AF_MAX) 320ed07cc7fSGarrett Wollman || (gate != 0 && (gate->sa_family >= AF_MAX))) 321df8bae1dSRodney W. Grimes senderr(EINVAL); 322df8bae1dSRodney W. Grimes if (genmask) { 323df8bae1dSRodney W. Grimes struct radix_node *t; 32478a82810SGarrett Wollman t = rn_addmask((caddr_t)genmask, 0, 1); 325920eb79fSRuslan Ermilov if (t && Bcmp((caddr_t *)genmask + 1, (caddr_t *)t->rn_key + 1, 326920eb79fSRuslan Ermilov *(u_char *)t->rn_key - 1) == 0) 327df8bae1dSRodney W. Grimes genmask = (struct sockaddr *)(t->rn_key); 328df8bae1dSRodney W. Grimes else 329df8bae1dSRodney W. Grimes senderr(ENOBUFS); 330df8bae1dSRodney W. Grimes } 331162c0b2eSRuslan Ermilov 332162c0b2eSRuslan Ermilov /* 333162c0b2eSRuslan Ermilov * Verify that the caller has the appropriate privilege; RTM_GET 334162c0b2eSRuslan Ermilov * is the only operation the non-superuser is allowed. 335162c0b2eSRuslan Ermilov */ 33644731cabSJohn Baldwin if (rtm->rtm_type != RTM_GET && (error = suser(curthread)) != 0) 337dadb6c3bSRuslan Ermilov senderr(error); 338162c0b2eSRuslan Ermilov 339df8bae1dSRodney W. Grimes switch (rtm->rtm_type) { 340df8bae1dSRodney W. Grimes 341df8bae1dSRodney W. Grimes case RTM_ADD: 342df8bae1dSRodney W. Grimes if (gate == 0) 343df8bae1dSRodney W. Grimes senderr(EINVAL); 3448071913dSRuslan Ermilov error = rtrequest1(RTM_ADD, &info, &saved_nrt); 345df8bae1dSRodney W. Grimes if (error == 0 && saved_nrt) { 346df8bae1dSRodney W. Grimes rt_setmetrics(rtm->rtm_inits, 347df8bae1dSRodney W. Grimes &rtm->rtm_rmx, &saved_nrt->rt_rmx); 34895b6073cSDavid Greenman saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits); 34995b6073cSDavid Greenman saved_nrt->rt_rmx.rmx_locks |= 35095b6073cSDavid Greenman (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks); 351df8bae1dSRodney W. Grimes saved_nrt->rt_refcnt--; 352df8bae1dSRodney W. Grimes saved_nrt->rt_genmask = genmask; 353df8bae1dSRodney W. Grimes } 354df8bae1dSRodney W. Grimes break; 355df8bae1dSRodney W. Grimes 356df8bae1dSRodney W. Grimes case RTM_DELETE: 3578071913dSRuslan Ermilov error = rtrequest1(RTM_DELETE, &info, &saved_nrt); 35878a82810SGarrett Wollman if (error == 0) { 35971eba915SRuslan Ermilov rt = saved_nrt; 36078a82810SGarrett Wollman goto report; 36178a82810SGarrett Wollman } 362df8bae1dSRodney W. Grimes break; 363df8bae1dSRodney W. Grimes 364df8bae1dSRodney W. Grimes case RTM_GET: 365df8bae1dSRodney W. Grimes case RTM_CHANGE: 366df8bae1dSRodney W. Grimes case RTM_LOCK: 36778a82810SGarrett Wollman if ((rnh = rt_tables[dst->sa_family]) == 0) { 36878a82810SGarrett Wollman senderr(EAFNOSUPPORT); 369956b0b65SJeffrey Hsu } 370956b0b65SJeffrey Hsu RADIX_NODE_HEAD_LOCK(rnh); 371956b0b65SJeffrey Hsu rt = (struct rtentry *) rnh->rnh_lookup(dst, netmask, rnh); 372956b0b65SJeffrey Hsu RADIX_NODE_HEAD_UNLOCK(rnh); 373956b0b65SJeffrey Hsu if (rt != NULL) 37478a82810SGarrett Wollman rt->rt_refcnt++; 37578a82810SGarrett Wollman else 376df8bae1dSRodney W. Grimes senderr(ESRCH); 377956b0b65SJeffrey Hsu 378df8bae1dSRodney W. Grimes switch(rtm->rtm_type) { 379df8bae1dSRodney W. Grimes 380df8bae1dSRodney W. Grimes case RTM_GET: 38178a82810SGarrett Wollman report: 382df8bae1dSRodney W. Grimes dst = rt_key(rt); 383df8bae1dSRodney W. Grimes gate = rt->rt_gateway; 384df8bae1dSRodney W. Grimes netmask = rt_mask(rt); 385df8bae1dSRodney W. Grimes genmask = rt->rt_genmask; 386df8bae1dSRodney W. Grimes if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) { 387df440948SPoul-Henning Kamp ifp = rt->rt_ifp; 388df440948SPoul-Henning Kamp if (ifp) { 38922f29826SPoul-Henning Kamp ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr; 390df8bae1dSRodney W. Grimes ifaaddr = rt->rt_ifa->ifa_addr; 39128070a0eSRuslan Ermilov if (ifp->if_flags & IFF_POINTOPOINT) 39228070a0eSRuslan Ermilov brdaddr = rt->rt_ifa->ifa_dstaddr; 393df8bae1dSRodney W. Grimes rtm->rtm_index = ifp->if_index; 394df8bae1dSRodney W. Grimes } else { 395df8bae1dSRodney W. Grimes ifpaddr = 0; 396df8bae1dSRodney W. Grimes ifaaddr = 0; 397df8bae1dSRodney W. Grimes } 398df8bae1dSRodney W. Grimes } 39978a82810SGarrett Wollman len = rt_msg2(rtm->rtm_type, &info, (caddr_t)0, 400df8bae1dSRodney W. Grimes (struct walkarg *)0); 401df8bae1dSRodney W. Grimes if (len > rtm->rtm_msglen) { 402df8bae1dSRodney W. Grimes struct rt_msghdr *new_rtm; 403df8bae1dSRodney W. Grimes R_Malloc(new_rtm, struct rt_msghdr *, len); 404df8bae1dSRodney W. Grimes if (new_rtm == 0) 405df8bae1dSRodney W. Grimes senderr(ENOBUFS); 406df8bae1dSRodney W. Grimes Bcopy(rtm, new_rtm, rtm->rtm_msglen); 407df8bae1dSRodney W. Grimes Free(rtm); rtm = new_rtm; 408df8bae1dSRodney W. Grimes } 40978a82810SGarrett Wollman (void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, 410df8bae1dSRodney W. Grimes (struct walkarg *)0); 411df8bae1dSRodney W. Grimes rtm->rtm_flags = rt->rt_flags; 412df8bae1dSRodney W. Grimes rtm->rtm_rmx = rt->rt_rmx; 413df8bae1dSRodney W. Grimes rtm->rtm_addrs = info.rti_addrs; 414df8bae1dSRodney W. Grimes break; 415df8bae1dSRodney W. Grimes 416df8bae1dSRodney W. Grimes case RTM_CHANGE: 417df8bae1dSRodney W. Grimes /* new gateway could require new ifaddr, ifp; 418df8bae1dSRodney W. Grimes flags may also be different; ifp may be specified 419df8bae1dSRodney W. Grimes by ll sockaddr when protocol address is ambiguous */ 420b30a244cSJeffrey Hsu /* compare two sockaddr structures */ 421b30a244cSJeffrey Hsu #define sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0) 42202a5d63eSBrian Somers if ((rt->rt_flags & RTF_GATEWAY && gate != NULL) || 42302a5d63eSBrian Somers ifpaddr != NULL || 42402a5d63eSBrian Somers (ifaaddr != NULL && 425b30a244cSJeffrey Hsu !sa_equal(ifaaddr, rt->rt_ifa->ifa_addr))) { 4268071913dSRuslan Ermilov if ((error = rt_getifa(&info)) != 0) 4278071913dSRuslan Ermilov senderr(error); 42802a5d63eSBrian Somers } 4298071913dSRuslan Ermilov if (gate != NULL && 4308071913dSRuslan Ermilov (error = rt_setgate(rt, rt_key(rt), gate)) != 0) 4318071913dSRuslan Ermilov senderr(error); 4328071913dSRuslan Ermilov if ((ifa = info.rti_ifa) != NULL) { 433df8bae1dSRodney W. Grimes register struct ifaddr *oifa = rt->rt_ifa; 434df8bae1dSRodney W. Grimes if (oifa != ifa) { 43519fc74fbSJeffrey Hsu if (oifa) { 43619fc74fbSJeffrey Hsu if (oifa->ifa_rtrequest) 4378071913dSRuslan Ermilov oifa->ifa_rtrequest(RTM_DELETE, rt, 4388071913dSRuslan Ermilov &info); 43912e552d6SJeffrey Hsu IFAFREE(oifa); 44019fc74fbSJeffrey Hsu } 44119fc74fbSJeffrey Hsu IFAREF(ifa); 442df8bae1dSRodney W. Grimes rt->rt_ifa = ifa; 4438071913dSRuslan Ermilov rt->rt_ifp = info.rti_ifp; 444df8bae1dSRodney W. Grimes } 445df8bae1dSRodney W. Grimes } 446df8bae1dSRodney W. Grimes rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx, 447df8bae1dSRodney W. Grimes &rt->rt_rmx); 448df8bae1dSRodney W. Grimes if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest) 4498071913dSRuslan Ermilov rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, &info); 450df8bae1dSRodney W. Grimes if (genmask) 451df8bae1dSRodney W. Grimes rt->rt_genmask = genmask; 45293b0017fSPhilippe Charnier /* FALLTHROUGH */ 453df8bae1dSRodney W. Grimes case RTM_LOCK: 454df8bae1dSRodney W. Grimes rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits); 455df8bae1dSRodney W. Grimes rt->rt_rmx.rmx_locks |= 456df8bae1dSRodney W. Grimes (rtm->rtm_inits & rtm->rtm_rmx.rmx_locks); 457df8bae1dSRodney W. Grimes break; 458df8bae1dSRodney W. Grimes } 459df8bae1dSRodney W. Grimes break; 460df8bae1dSRodney W. Grimes 461df8bae1dSRodney W. Grimes default: 462df8bae1dSRodney W. Grimes senderr(EOPNOTSUPP); 463df8bae1dSRodney W. Grimes } 464df8bae1dSRodney W. Grimes 465df8bae1dSRodney W. Grimes flush: 466df8bae1dSRodney W. Grimes if (rtm) { 467df8bae1dSRodney W. Grimes if (error) 468df8bae1dSRodney W. Grimes rtm->rtm_errno = error; 469df8bae1dSRodney W. Grimes else 470df8bae1dSRodney W. Grimes rtm->rtm_flags |= RTF_DONE; 471df8bae1dSRodney W. Grimes } 472df8bae1dSRodney W. Grimes if (rt) 473df8bae1dSRodney W. Grimes rtfree(rt); 474df8bae1dSRodney W. Grimes { 475df8bae1dSRodney W. Grimes register struct rawcb *rp = 0; 476df8bae1dSRodney W. Grimes /* 477df8bae1dSRodney W. Grimes * Check to see if we don't want our own messages. 478df8bae1dSRodney W. Grimes */ 479df8bae1dSRodney W. Grimes if ((so->so_options & SO_USELOOPBACK) == 0) { 480df8bae1dSRodney W. Grimes if (route_cb.any_count <= 1) { 481df8bae1dSRodney W. Grimes if (rtm) 482df8bae1dSRodney W. Grimes Free(rtm); 483df8bae1dSRodney W. Grimes m_freem(m); 484df8bae1dSRodney W. Grimes return (error); 485df8bae1dSRodney W. Grimes } 486df8bae1dSRodney W. Grimes /* There is another listener, so construct message */ 487df8bae1dSRodney W. Grimes rp = sotorawcb(so); 4884cc20ab1SSeigo Tanimura } 489df8bae1dSRodney W. Grimes if (rtm) { 490df8bae1dSRodney W. Grimes m_copyback(m, 0, rtm->rtm_msglen, (caddr_t)rtm); 49103311056SHajimu UMEMOTO if (m->m_pkthdr.len < rtm->rtm_msglen) { 49203311056SHajimu UMEMOTO m_freem(m); 49303311056SHajimu UMEMOTO m = NULL; 49403311056SHajimu UMEMOTO } else if (m->m_pkthdr.len > rtm->rtm_msglen) 49503311056SHajimu UMEMOTO m_adj(m, rtm->rtm_msglen - m->m_pkthdr.len); 496df8bae1dSRodney W. Grimes Free(rtm); 497df8bae1dSRodney W. Grimes } 498df8bae1dSRodney W. Grimes if (rp) 499df8bae1dSRodney W. Grimes rp->rcb_proto.sp_family = 0; /* Avoid us */ 500df8bae1dSRodney W. Grimes if (dst) 501df8bae1dSRodney W. Grimes route_proto.sp_protocol = dst->sa_family; 50203311056SHajimu UMEMOTO if (m) 503df8bae1dSRodney W. Grimes raw_input(m, &route_proto, &route_src, &route_dst); 504df8bae1dSRodney W. Grimes if (rp) 505df8bae1dSRodney W. Grimes rp->rcb_proto.sp_family = PF_ROUTE; 506df8bae1dSRodney W. Grimes } 507df8bae1dSRodney W. Grimes return (error); 508df8bae1dSRodney W. Grimes } 509df8bae1dSRodney W. Grimes 51052041295SPoul-Henning Kamp static void 511df8bae1dSRodney W. Grimes rt_setmetrics(which, in, out) 512df8bae1dSRodney W. Grimes u_long which; 513df8bae1dSRodney W. Grimes register struct rt_metrics *in, *out; 514df8bae1dSRodney W. Grimes { 515df8bae1dSRodney W. Grimes #define metric(f, e) if (which & (f)) out->e = in->e; 516df8bae1dSRodney W. Grimes metric(RTV_RPIPE, rmx_recvpipe); 517df8bae1dSRodney W. Grimes metric(RTV_SPIPE, rmx_sendpipe); 518df8bae1dSRodney W. Grimes metric(RTV_SSTHRESH, rmx_ssthresh); 519df8bae1dSRodney W. Grimes metric(RTV_RTT, rmx_rtt); 520df8bae1dSRodney W. Grimes metric(RTV_RTTVAR, rmx_rttvar); 521df8bae1dSRodney W. Grimes metric(RTV_HOPCOUNT, rmx_hopcount); 522df8bae1dSRodney W. Grimes metric(RTV_MTU, rmx_mtu); 523df8bae1dSRodney W. Grimes metric(RTV_EXPIRE, rmx_expire); 524df8bae1dSRodney W. Grimes #undef metric 525df8bae1dSRodney W. Grimes } 526df8bae1dSRodney W. Grimes 527df8bae1dSRodney W. Grimes #define ROUNDUP(a) \ 528df8bae1dSRodney W. Grimes ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) 529df8bae1dSRodney W. Grimes #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) 530df8bae1dSRodney W. Grimes 531076d0761SJulian Elischer 5327f33a738SJulian Elischer /* 5337f33a738SJulian Elischer * Extract the addresses of the passed sockaddrs. 5347f33a738SJulian Elischer * Do a little sanity checking so as to avoid bad memory references. 535076d0761SJulian Elischer * This data is derived straight from userland. 5367f33a738SJulian Elischer */ 537076d0761SJulian Elischer static int 538df8bae1dSRodney W. Grimes rt_xaddrs(cp, cplim, rtinfo) 539df8bae1dSRodney W. Grimes register caddr_t cp, cplim; 540df8bae1dSRodney W. Grimes register struct rt_addrinfo *rtinfo; 541df8bae1dSRodney W. Grimes { 542df8bae1dSRodney W. Grimes register struct sockaddr *sa; 543df8bae1dSRodney W. Grimes register int i; 544df8bae1dSRodney W. Grimes 545076d0761SJulian Elischer for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) { 546df8bae1dSRodney W. Grimes if ((rtinfo->rti_addrs & (1 << i)) == 0) 547df8bae1dSRodney W. Grimes continue; 548ff6d0a59SJulian Elischer sa = (struct sockaddr *)cp; 5497f33a738SJulian Elischer /* 550076d0761SJulian Elischer * It won't fit. 5517f33a738SJulian Elischer */ 552076d0761SJulian Elischer if ( (cp + sa->sa_len) > cplim ) { 553076d0761SJulian Elischer return (EINVAL); 554076d0761SJulian Elischer } 5559a969a6eSMike Smith 5567f33a738SJulian Elischer /* 5577f33a738SJulian Elischer * there are no more.. quit now 5587f33a738SJulian Elischer * If there are more bits, they are in error. 5597f33a738SJulian Elischer * I've seen this. route(1) can evidently generate these. 5607f33a738SJulian Elischer * This causes kernel to core dump. 561076d0761SJulian Elischer * for compatibility, If we see this, point to a safe address. 5627f33a738SJulian Elischer */ 563076d0761SJulian Elischer if (sa->sa_len == 0) { 564076d0761SJulian Elischer rtinfo->rti_info[i] = &sa_zero; 565076d0761SJulian Elischer return (0); /* should be EINVAL but for compat */ 566df8bae1dSRodney W. Grimes } 567076d0761SJulian Elischer 568076d0761SJulian Elischer /* accept it */ 569076d0761SJulian Elischer rtinfo->rti_info[i] = sa; 570076d0761SJulian Elischer ADVANCE(cp, sa); 571076d0761SJulian Elischer } 572076d0761SJulian Elischer return (0); 573df8bae1dSRodney W. Grimes } 574df8bae1dSRodney W. Grimes 575df8bae1dSRodney W. Grimes static struct mbuf * 576df8bae1dSRodney W. Grimes rt_msg1(type, rtinfo) 577df8bae1dSRodney W. Grimes int type; 578df8bae1dSRodney W. Grimes register struct rt_addrinfo *rtinfo; 579df8bae1dSRodney W. Grimes { 580df8bae1dSRodney W. Grimes register struct rt_msghdr *rtm; 581df8bae1dSRodney W. Grimes register struct mbuf *m; 582df8bae1dSRodney W. Grimes register int i; 583df8bae1dSRodney W. Grimes register struct sockaddr *sa; 584df8bae1dSRodney W. Grimes int len, dlen; 585df8bae1dSRodney W. Grimes 586df8bae1dSRodney W. Grimes switch (type) { 587df8bae1dSRodney W. Grimes 588df8bae1dSRodney W. Grimes case RTM_DELADDR: 589df8bae1dSRodney W. Grimes case RTM_NEWADDR: 590df8bae1dSRodney W. Grimes len = sizeof(struct ifa_msghdr); 591df8bae1dSRodney W. Grimes break; 592df8bae1dSRodney W. Grimes 593477180fbSGarrett Wollman case RTM_DELMADDR: 594477180fbSGarrett Wollman case RTM_NEWMADDR: 595477180fbSGarrett Wollman len = sizeof(struct ifma_msghdr); 596477180fbSGarrett Wollman break; 597477180fbSGarrett Wollman 598df8bae1dSRodney W. Grimes case RTM_IFINFO: 599df8bae1dSRodney W. Grimes len = sizeof(struct if_msghdr); 600df8bae1dSRodney W. Grimes break; 601df8bae1dSRodney W. Grimes 6027b6edd04SRuslan Ermilov case RTM_IFANNOUNCE: 6037b6edd04SRuslan Ermilov len = sizeof(struct if_announcemsghdr); 6047b6edd04SRuslan Ermilov break; 6057b6edd04SRuslan Ermilov 606df8bae1dSRodney W. Grimes default: 607df8bae1dSRodney W. Grimes len = sizeof(struct rt_msghdr); 608df8bae1dSRodney W. Grimes } 60933841545SHajimu UMEMOTO if (len > MCLBYTES) 610df8bae1dSRodney W. Grimes panic("rt_msg1"); 61133841545SHajimu UMEMOTO m = m_gethdr(M_DONTWAIT, MT_DATA); 61233841545SHajimu UMEMOTO if (m && len > MHLEN) { 61333841545SHajimu UMEMOTO MCLGET(m, M_DONTWAIT); 61433841545SHajimu UMEMOTO if ((m->m_flags & M_EXT) == 0) { 61533841545SHajimu UMEMOTO m_free(m); 61633841545SHajimu UMEMOTO m = NULL; 61733841545SHajimu UMEMOTO } 61833841545SHajimu UMEMOTO } 61933841545SHajimu UMEMOTO if (m == 0) 62033841545SHajimu UMEMOTO return (m); 621df8bae1dSRodney W. Grimes m->m_pkthdr.len = m->m_len = len; 622df8bae1dSRodney W. Grimes m->m_pkthdr.rcvif = 0; 623df8bae1dSRodney W. Grimes rtm = mtod(m, struct rt_msghdr *); 624df8bae1dSRodney W. Grimes bzero((caddr_t)rtm, len); 625df8bae1dSRodney W. Grimes for (i = 0; i < RTAX_MAX; i++) { 626df8bae1dSRodney W. Grimes if ((sa = rtinfo->rti_info[i]) == NULL) 627df8bae1dSRodney W. Grimes continue; 628df8bae1dSRodney W. Grimes rtinfo->rti_addrs |= (1 << i); 629df8bae1dSRodney W. Grimes dlen = ROUNDUP(sa->sa_len); 630df8bae1dSRodney W. Grimes m_copyback(m, len, dlen, (caddr_t)sa); 631df8bae1dSRodney W. Grimes len += dlen; 632df8bae1dSRodney W. Grimes } 633df8bae1dSRodney W. Grimes if (m->m_pkthdr.len != len) { 634df8bae1dSRodney W. Grimes m_freem(m); 635df8bae1dSRodney W. Grimes return (NULL); 636df8bae1dSRodney W. Grimes } 637df8bae1dSRodney W. Grimes rtm->rtm_msglen = len; 638df8bae1dSRodney W. Grimes rtm->rtm_version = RTM_VERSION; 639df8bae1dSRodney W. Grimes rtm->rtm_type = type; 640df8bae1dSRodney W. Grimes return (m); 641df8bae1dSRodney W. Grimes } 642df8bae1dSRodney W. Grimes 643df8bae1dSRodney W. Grimes static int 644df8bae1dSRodney W. Grimes rt_msg2(type, rtinfo, cp, w) 645df8bae1dSRodney W. Grimes int type; 646df8bae1dSRodney W. Grimes register struct rt_addrinfo *rtinfo; 647df8bae1dSRodney W. Grimes caddr_t cp; 648df8bae1dSRodney W. Grimes struct walkarg *w; 649df8bae1dSRodney W. Grimes { 650df8bae1dSRodney W. Grimes register int i; 651df8bae1dSRodney W. Grimes int len, dlen, second_time = 0; 652df8bae1dSRodney W. Grimes caddr_t cp0; 653df8bae1dSRodney W. Grimes 654df8bae1dSRodney W. Grimes rtinfo->rti_addrs = 0; 655df8bae1dSRodney W. Grimes again: 656df8bae1dSRodney W. Grimes switch (type) { 657df8bae1dSRodney W. Grimes 658df8bae1dSRodney W. Grimes case RTM_DELADDR: 659df8bae1dSRodney W. Grimes case RTM_NEWADDR: 660df8bae1dSRodney W. Grimes len = sizeof(struct ifa_msghdr); 661df8bae1dSRodney W. Grimes break; 662df8bae1dSRodney W. Grimes 663df8bae1dSRodney W. Grimes case RTM_IFINFO: 664df8bae1dSRodney W. Grimes len = sizeof(struct if_msghdr); 665df8bae1dSRodney W. Grimes break; 666df8bae1dSRodney W. Grimes 667df8bae1dSRodney W. Grimes default: 668df8bae1dSRodney W. Grimes len = sizeof(struct rt_msghdr); 669df8bae1dSRodney W. Grimes } 670df440948SPoul-Henning Kamp cp0 = cp; 671df440948SPoul-Henning Kamp if (cp0) 672df8bae1dSRodney W. Grimes cp += len; 673df8bae1dSRodney W. Grimes for (i = 0; i < RTAX_MAX; i++) { 674df8bae1dSRodney W. Grimes register struct sockaddr *sa; 675df8bae1dSRodney W. Grimes 676df8bae1dSRodney W. Grimes if ((sa = rtinfo->rti_info[i]) == 0) 677df8bae1dSRodney W. Grimes continue; 678df8bae1dSRodney W. Grimes rtinfo->rti_addrs |= (1 << i); 679df8bae1dSRodney W. Grimes dlen = ROUNDUP(sa->sa_len); 680df8bae1dSRodney W. Grimes if (cp) { 681df8bae1dSRodney W. Grimes bcopy((caddr_t)sa, cp, (unsigned)dlen); 682df8bae1dSRodney W. Grimes cp += dlen; 683df8bae1dSRodney W. Grimes } 684df8bae1dSRodney W. Grimes len += dlen; 685df8bae1dSRodney W. Grimes } 686694ff264SAndrew Gallatin len = ALIGN(len); 687df8bae1dSRodney W. Grimes if (cp == 0 && w != NULL && !second_time) { 688df8bae1dSRodney W. Grimes register struct walkarg *rw = w; 689df8bae1dSRodney W. Grimes 69052041295SPoul-Henning Kamp if (rw->w_req) { 691df8bae1dSRodney W. Grimes if (rw->w_tmemsize < len) { 692df8bae1dSRodney W. Grimes if (rw->w_tmem) 693df8bae1dSRodney W. Grimes free(rw->w_tmem, M_RTABLE); 694df440948SPoul-Henning Kamp rw->w_tmem = (caddr_t) 695df440948SPoul-Henning Kamp malloc(len, M_RTABLE, M_NOWAIT); 696df440948SPoul-Henning Kamp if (rw->w_tmem) 697df8bae1dSRodney W. Grimes rw->w_tmemsize = len; 698df8bae1dSRodney W. Grimes } 699df8bae1dSRodney W. Grimes if (rw->w_tmem) { 700df8bae1dSRodney W. Grimes cp = rw->w_tmem; 701df8bae1dSRodney W. Grimes second_time = 1; 702df8bae1dSRodney W. Grimes goto again; 70352041295SPoul-Henning Kamp } 704df8bae1dSRodney W. Grimes } 705df8bae1dSRodney W. Grimes } 706df8bae1dSRodney W. Grimes if (cp) { 707df8bae1dSRodney W. Grimes register struct rt_msghdr *rtm = (struct rt_msghdr *)cp0; 708df8bae1dSRodney W. Grimes 709df8bae1dSRodney W. Grimes rtm->rtm_version = RTM_VERSION; 710df8bae1dSRodney W. Grimes rtm->rtm_type = type; 711df8bae1dSRodney W. Grimes rtm->rtm_msglen = len; 712df8bae1dSRodney W. Grimes } 713df8bae1dSRodney W. Grimes return (len); 714df8bae1dSRodney W. Grimes } 715df8bae1dSRodney W. Grimes 716df8bae1dSRodney W. Grimes /* 717df8bae1dSRodney W. Grimes * This routine is called to generate a message from the routing 718df8bae1dSRodney W. Grimes * socket indicating that a redirect has occured, a routing lookup 719df8bae1dSRodney W. Grimes * has failed, or that a protocol has detected timeouts to a particular 720df8bae1dSRodney W. Grimes * destination. 721df8bae1dSRodney W. Grimes */ 722df8bae1dSRodney W. Grimes void 723df8bae1dSRodney W. Grimes rt_missmsg(type, rtinfo, flags, error) 724df8bae1dSRodney W. Grimes int type, flags, error; 725df8bae1dSRodney W. Grimes register struct rt_addrinfo *rtinfo; 726df8bae1dSRodney W. Grimes { 727df8bae1dSRodney W. Grimes register struct rt_msghdr *rtm; 728df8bae1dSRodney W. Grimes register struct mbuf *m; 729df8bae1dSRodney W. Grimes struct sockaddr *sa = rtinfo->rti_info[RTAX_DST]; 730df8bae1dSRodney W. Grimes 731df8bae1dSRodney W. Grimes if (route_cb.any_count == 0) 732df8bae1dSRodney W. Grimes return; 733df8bae1dSRodney W. Grimes m = rt_msg1(type, rtinfo); 734df8bae1dSRodney W. Grimes if (m == 0) 735df8bae1dSRodney W. Grimes return; 736df8bae1dSRodney W. Grimes rtm = mtod(m, struct rt_msghdr *); 737df8bae1dSRodney W. Grimes rtm->rtm_flags = RTF_DONE | flags; 738df8bae1dSRodney W. Grimes rtm->rtm_errno = error; 739df8bae1dSRodney W. Grimes rtm->rtm_addrs = rtinfo->rti_addrs; 740df8bae1dSRodney W. Grimes route_proto.sp_protocol = sa ? sa->sa_family : 0; 741df8bae1dSRodney W. Grimes raw_input(m, &route_proto, &route_src, &route_dst); 742df8bae1dSRodney W. Grimes } 743df8bae1dSRodney W. Grimes 744df8bae1dSRodney W. Grimes /* 745df8bae1dSRodney W. Grimes * This routine is called to generate a message from the routing 746df8bae1dSRodney W. Grimes * socket indicating that the status of a network interface has changed. 747df8bae1dSRodney W. Grimes */ 748df8bae1dSRodney W. Grimes void 749df8bae1dSRodney W. Grimes rt_ifmsg(ifp) 750df8bae1dSRodney W. Grimes register struct ifnet *ifp; 751df8bae1dSRodney W. Grimes { 752df8bae1dSRodney W. Grimes register struct if_msghdr *ifm; 753df8bae1dSRodney W. Grimes struct mbuf *m; 754df8bae1dSRodney W. Grimes struct rt_addrinfo info; 755df8bae1dSRodney W. Grimes 756df8bae1dSRodney W. Grimes if (route_cb.any_count == 0) 757df8bae1dSRodney W. Grimes return; 758df8bae1dSRodney W. Grimes bzero((caddr_t)&info, sizeof(info)); 759df8bae1dSRodney W. Grimes m = rt_msg1(RTM_IFINFO, &info); 760df8bae1dSRodney W. Grimes if (m == 0) 761df8bae1dSRodney W. Grimes return; 762df8bae1dSRodney W. Grimes ifm = mtod(m, struct if_msghdr *); 763df8bae1dSRodney W. Grimes ifm->ifm_index = ifp->if_index; 76462f76486SMaxim Sobolev ifm->ifm_flags = ifp->if_flags; 765df8bae1dSRodney W. Grimes ifm->ifm_data = ifp->if_data; 766df8bae1dSRodney W. Grimes ifm->ifm_addrs = 0; 767df8bae1dSRodney W. Grimes route_proto.sp_protocol = 0; 768df8bae1dSRodney W. Grimes raw_input(m, &route_proto, &route_src, &route_dst); 769df8bae1dSRodney W. Grimes } 770df8bae1dSRodney W. Grimes 771df8bae1dSRodney W. Grimes /* 772df8bae1dSRodney W. Grimes * This is called to generate messages from the routing socket 773df8bae1dSRodney W. Grimes * indicating a network interface has had addresses associated with it. 774df8bae1dSRodney W. Grimes * if we ever reverse the logic and replace messages TO the routing 775df8bae1dSRodney W. Grimes * socket indicate a request to configure interfaces, then it will 776df8bae1dSRodney W. Grimes * be unnecessary as the routing socket will automatically generate 777df8bae1dSRodney W. Grimes * copies of it. 778df8bae1dSRodney W. Grimes */ 779df8bae1dSRodney W. Grimes void 780df8bae1dSRodney W. Grimes rt_newaddrmsg(cmd, ifa, error, rt) 781df8bae1dSRodney W. Grimes int cmd, error; 782df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 783df8bae1dSRodney W. Grimes register struct rtentry *rt; 784df8bae1dSRodney W. Grimes { 785df8bae1dSRodney W. Grimes struct rt_addrinfo info; 78626f9a767SRodney W. Grimes struct sockaddr *sa = 0; 787df8bae1dSRodney W. Grimes int pass; 78826f9a767SRodney W. Grimes struct mbuf *m = 0; 789df8bae1dSRodney W. Grimes struct ifnet *ifp = ifa->ifa_ifp; 790df8bae1dSRodney W. Grimes 791df8bae1dSRodney W. Grimes if (route_cb.any_count == 0) 792df8bae1dSRodney W. Grimes return; 793df8bae1dSRodney W. Grimes for (pass = 1; pass < 3; pass++) { 794df8bae1dSRodney W. Grimes bzero((caddr_t)&info, sizeof(info)); 795df8bae1dSRodney W. Grimes if ((cmd == RTM_ADD && pass == 1) || 796df8bae1dSRodney W. Grimes (cmd == RTM_DELETE && pass == 2)) { 797df8bae1dSRodney W. Grimes register struct ifa_msghdr *ifam; 798df8bae1dSRodney W. Grimes int ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR; 799df8bae1dSRodney W. Grimes 800df8bae1dSRodney W. Grimes ifaaddr = sa = ifa->ifa_addr; 80122f29826SPoul-Henning Kamp ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr; 802df8bae1dSRodney W. Grimes netmask = ifa->ifa_netmask; 803df8bae1dSRodney W. Grimes brdaddr = ifa->ifa_dstaddr; 804df8bae1dSRodney W. Grimes if ((m = rt_msg1(ncmd, &info)) == NULL) 805df8bae1dSRodney W. Grimes continue; 806df8bae1dSRodney W. Grimes ifam = mtod(m, struct ifa_msghdr *); 807df8bae1dSRodney W. Grimes ifam->ifam_index = ifp->if_index; 808df8bae1dSRodney W. Grimes ifam->ifam_metric = ifa->ifa_metric; 809df8bae1dSRodney W. Grimes ifam->ifam_flags = ifa->ifa_flags; 810df8bae1dSRodney W. Grimes ifam->ifam_addrs = info.rti_addrs; 811df8bae1dSRodney W. Grimes } 812df8bae1dSRodney W. Grimes if ((cmd == RTM_ADD && pass == 2) || 813df8bae1dSRodney W. Grimes (cmd == RTM_DELETE && pass == 1)) { 814df8bae1dSRodney W. Grimes register struct rt_msghdr *rtm; 815df8bae1dSRodney W. Grimes 816df8bae1dSRodney W. Grimes if (rt == 0) 817df8bae1dSRodney W. Grimes continue; 818df8bae1dSRodney W. Grimes netmask = rt_mask(rt); 819df8bae1dSRodney W. Grimes dst = sa = rt_key(rt); 820df8bae1dSRodney W. Grimes gate = rt->rt_gateway; 821df8bae1dSRodney W. Grimes if ((m = rt_msg1(cmd, &info)) == NULL) 822df8bae1dSRodney W. Grimes continue; 823df8bae1dSRodney W. Grimes rtm = mtod(m, struct rt_msghdr *); 824df8bae1dSRodney W. Grimes rtm->rtm_index = ifp->if_index; 825df8bae1dSRodney W. Grimes rtm->rtm_flags |= rt->rt_flags; 826df8bae1dSRodney W. Grimes rtm->rtm_errno = error; 827df8bae1dSRodney W. Grimes rtm->rtm_addrs = info.rti_addrs; 828df8bae1dSRodney W. Grimes } 829df8bae1dSRodney W. Grimes route_proto.sp_protocol = sa ? sa->sa_family : 0; 830df8bae1dSRodney W. Grimes raw_input(m, &route_proto, &route_src, &route_dst); 831df8bae1dSRodney W. Grimes } 832df8bae1dSRodney W. Grimes } 833df8bae1dSRodney W. Grimes 834477180fbSGarrett Wollman /* 835477180fbSGarrett Wollman * This is the analogue to the rt_newaddrmsg which performs the same 836477180fbSGarrett Wollman * function but for multicast group memberhips. This is easier since 837477180fbSGarrett Wollman * there is no route state to worry about. 838477180fbSGarrett Wollman */ 839477180fbSGarrett Wollman void 840477180fbSGarrett Wollman rt_newmaddrmsg(cmd, ifma) 841477180fbSGarrett Wollman int cmd; 842477180fbSGarrett Wollman struct ifmultiaddr *ifma; 843477180fbSGarrett Wollman { 844477180fbSGarrett Wollman struct rt_addrinfo info; 845477180fbSGarrett Wollman struct mbuf *m = 0; 846477180fbSGarrett Wollman struct ifnet *ifp = ifma->ifma_ifp; 847477180fbSGarrett Wollman struct ifma_msghdr *ifmam; 848477180fbSGarrett Wollman 849477180fbSGarrett Wollman if (route_cb.any_count == 0) 850477180fbSGarrett Wollman return; 851477180fbSGarrett Wollman 852477180fbSGarrett Wollman bzero((caddr_t)&info, sizeof(info)); 853477180fbSGarrett Wollman ifaaddr = ifma->ifma_addr; 85422f29826SPoul-Henning Kamp if (ifp && TAILQ_FIRST(&ifp->if_addrhead)) 85522f29826SPoul-Henning Kamp ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr; 8568bf72aefSHajimu UMEMOTO else 8578bf72aefSHajimu UMEMOTO ifpaddr = NULL; 858477180fbSGarrett Wollman /* 859477180fbSGarrett Wollman * If a link-layer address is present, present it as a ``gateway'' 860477180fbSGarrett Wollman * (similarly to how ARP entries, e.g., are presented). 861477180fbSGarrett Wollman */ 862477180fbSGarrett Wollman gate = ifma->ifma_lladdr; 863477180fbSGarrett Wollman if ((m = rt_msg1(cmd, &info)) == NULL) 864477180fbSGarrett Wollman return; 865477180fbSGarrett Wollman ifmam = mtod(m, struct ifma_msghdr *); 866477180fbSGarrett Wollman ifmam->ifmam_index = ifp->if_index; 867477180fbSGarrett Wollman ifmam->ifmam_addrs = info.rti_addrs; 868477180fbSGarrett Wollman route_proto.sp_protocol = ifma->ifma_addr->sa_family; 869477180fbSGarrett Wollman raw_input(m, &route_proto, &route_src, &route_dst); 870477180fbSGarrett Wollman } 87152041295SPoul-Henning Kamp 872df8bae1dSRodney W. Grimes /* 8737b6edd04SRuslan Ermilov * This is called to generate routing socket messages indicating 8747b6edd04SRuslan Ermilov * network interface arrival and departure. 8757b6edd04SRuslan Ermilov */ 8767b6edd04SRuslan Ermilov void 8777b6edd04SRuslan Ermilov rt_ifannouncemsg(ifp, what) 8787b6edd04SRuslan Ermilov struct ifnet *ifp; 8797b6edd04SRuslan Ermilov int what; 8807b6edd04SRuslan Ermilov { 8817b6edd04SRuslan Ermilov struct if_announcemsghdr *ifan; 8827b6edd04SRuslan Ermilov struct mbuf *m; 8837b6edd04SRuslan Ermilov struct rt_addrinfo info; 8847b6edd04SRuslan Ermilov 8857b6edd04SRuslan Ermilov if (route_cb.any_count == 0) 8867b6edd04SRuslan Ermilov return; 8877b6edd04SRuslan Ermilov bzero((caddr_t)&info, sizeof(info)); 8887b6edd04SRuslan Ermilov m = rt_msg1(RTM_IFANNOUNCE, &info); 8897b6edd04SRuslan Ermilov if (m == NULL) 8907b6edd04SRuslan Ermilov return; 8917b6edd04SRuslan Ermilov ifan = mtod(m, struct if_announcemsghdr *); 8927b6edd04SRuslan Ermilov ifan->ifan_index = ifp->if_index; 8937b6edd04SRuslan Ermilov snprintf(ifan->ifan_name, sizeof(ifan->ifan_name), 8947b6edd04SRuslan Ermilov "%s%d", ifp->if_name, ifp->if_unit); 8957b6edd04SRuslan Ermilov ifan->ifan_what = what; 8967b6edd04SRuslan Ermilov route_proto.sp_protocol = 0; 8977b6edd04SRuslan Ermilov raw_input(m, &route_proto, &route_src, &route_dst); 8987b6edd04SRuslan Ermilov } 8997b6edd04SRuslan Ermilov 9007b6edd04SRuslan Ermilov /* 901df8bae1dSRodney W. Grimes * This is used in dumping the kernel table via sysctl(). 902df8bae1dSRodney W. Grimes */ 90337c84183SPoul-Henning Kamp static int 9044ab32c34SBruce Evans sysctl_dumpentry(rn, vw) 905df8bae1dSRodney W. Grimes struct radix_node *rn; 9064ab32c34SBruce Evans void *vw; 907df8bae1dSRodney W. Grimes { 9084ab32c34SBruce Evans register struct walkarg *w = vw; 909df8bae1dSRodney W. Grimes register struct rtentry *rt = (struct rtentry *)rn; 910df8bae1dSRodney W. Grimes int error = 0, size; 911df8bae1dSRodney W. Grimes struct rt_addrinfo info; 912df8bae1dSRodney W. Grimes 913df8bae1dSRodney W. Grimes if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg)) 914df8bae1dSRodney W. Grimes return 0; 915df8bae1dSRodney W. Grimes bzero((caddr_t)&info, sizeof(info)); 916df8bae1dSRodney W. Grimes dst = rt_key(rt); 917df8bae1dSRodney W. Grimes gate = rt->rt_gateway; 918df8bae1dSRodney W. Grimes netmask = rt_mask(rt); 919df8bae1dSRodney W. Grimes genmask = rt->rt_genmask; 92028070a0eSRuslan Ermilov if (rt->rt_ifp) { 92128070a0eSRuslan Ermilov ifpaddr = TAILQ_FIRST(&rt->rt_ifp->if_addrhead)->ifa_addr; 92228070a0eSRuslan Ermilov ifaaddr = rt->rt_ifa->ifa_addr; 92328070a0eSRuslan Ermilov if (rt->rt_ifp->if_flags & IFF_POINTOPOINT) 92428070a0eSRuslan Ermilov brdaddr = rt->rt_ifa->ifa_dstaddr; 92528070a0eSRuslan Ermilov } 926df8bae1dSRodney W. Grimes size = rt_msg2(RTM_GET, &info, 0, w); 92752041295SPoul-Henning Kamp if (w->w_req && w->w_tmem) { 928df8bae1dSRodney W. Grimes register struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem; 929df8bae1dSRodney W. Grimes 930df8bae1dSRodney W. Grimes rtm->rtm_flags = rt->rt_flags; 931df8bae1dSRodney W. Grimes rtm->rtm_use = rt->rt_use; 932df8bae1dSRodney W. Grimes rtm->rtm_rmx = rt->rt_rmx; 933df8bae1dSRodney W. Grimes rtm->rtm_index = rt->rt_ifp->if_index; 934df8bae1dSRodney W. Grimes rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0; 935df8bae1dSRodney W. Grimes rtm->rtm_addrs = info.rti_addrs; 93652041295SPoul-Henning Kamp error = SYSCTL_OUT(w->w_req, (caddr_t)rtm, size); 93752041295SPoul-Henning Kamp return (error); 938df8bae1dSRodney W. Grimes } 939df8bae1dSRodney W. Grimes return (error); 940df8bae1dSRodney W. Grimes } 941df8bae1dSRodney W. Grimes 94237c84183SPoul-Henning Kamp static int 943df8bae1dSRodney W. Grimes sysctl_iflist(af, w) 944df8bae1dSRodney W. Grimes int af; 945df8bae1dSRodney W. Grimes register struct walkarg *w; 946df8bae1dSRodney W. Grimes { 947df8bae1dSRodney W. Grimes register struct ifnet *ifp; 948df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 949df8bae1dSRodney W. Grimes struct rt_addrinfo info; 950df8bae1dSRodney W. Grimes int len, error = 0; 951df8bae1dSRodney W. Grimes 952df8bae1dSRodney W. Grimes bzero((caddr_t)&info, sizeof(info)); 953b30a244cSJeffrey Hsu /* IFNET_RLOCK(); */ /* could sleep XXX */ 954fc2ffbe6SPoul-Henning Kamp TAILQ_FOREACH(ifp, &ifnet, if_link) { 955df8bae1dSRodney W. Grimes if (w->w_arg && w->w_arg != ifp->if_index) 956df8bae1dSRodney W. Grimes continue; 95722f29826SPoul-Henning Kamp ifa = TAILQ_FIRST(&ifp->if_addrhead); 958df8bae1dSRodney W. Grimes ifpaddr = ifa->ifa_addr; 959df8bae1dSRodney W. Grimes len = rt_msg2(RTM_IFINFO, &info, (caddr_t)0, w); 960df8bae1dSRodney W. Grimes ifpaddr = 0; 96152041295SPoul-Henning Kamp if (w->w_req && w->w_tmem) { 962df8bae1dSRodney W. Grimes register struct if_msghdr *ifm; 963df8bae1dSRodney W. Grimes 964df8bae1dSRodney W. Grimes ifm = (struct if_msghdr *)w->w_tmem; 965df8bae1dSRodney W. Grimes ifm->ifm_index = ifp->if_index; 96662f76486SMaxim Sobolev ifm->ifm_flags = ifp->if_flags; 967df8bae1dSRodney W. Grimes ifm->ifm_data = ifp->if_data; 968df8bae1dSRodney W. Grimes ifm->ifm_addrs = info.rti_addrs; 96952041295SPoul-Henning Kamp error = SYSCTL_OUT(w->w_req,(caddr_t)ifm, len); 970df440948SPoul-Henning Kamp if (error) 971a35b06c5SJonathan Lemon goto done; 972df8bae1dSRodney W. Grimes } 97322f29826SPoul-Henning Kamp while ((ifa = TAILQ_NEXT(ifa, ifa_link)) != 0) { 974df8bae1dSRodney W. Grimes if (af && af != ifa->ifa_addr->sa_family) 975df8bae1dSRodney W. Grimes continue; 976a854ed98SJohn Baldwin if (jailed(curthread->td_ucred) && 977a854ed98SJohn Baldwin prison_if(curthread->td_ucred, ifa->ifa_addr)) 97875c13541SPoul-Henning Kamp continue; 979df8bae1dSRodney W. Grimes ifaaddr = ifa->ifa_addr; 980df8bae1dSRodney W. Grimes netmask = ifa->ifa_netmask; 981df8bae1dSRodney W. Grimes brdaddr = ifa->ifa_dstaddr; 982df8bae1dSRodney W. Grimes len = rt_msg2(RTM_NEWADDR, &info, 0, w); 98352041295SPoul-Henning Kamp if (w->w_req && w->w_tmem) { 984df8bae1dSRodney W. Grimes register struct ifa_msghdr *ifam; 985df8bae1dSRodney W. Grimes 986df8bae1dSRodney W. Grimes ifam = (struct ifa_msghdr *)w->w_tmem; 987df8bae1dSRodney W. Grimes ifam->ifam_index = ifa->ifa_ifp->if_index; 988df8bae1dSRodney W. Grimes ifam->ifam_flags = ifa->ifa_flags; 989df8bae1dSRodney W. Grimes ifam->ifam_metric = ifa->ifa_metric; 990df8bae1dSRodney W. Grimes ifam->ifam_addrs = info.rti_addrs; 99152041295SPoul-Henning Kamp error = SYSCTL_OUT(w->w_req, w->w_tmem, len); 992df440948SPoul-Henning Kamp if (error) 993a35b06c5SJonathan Lemon goto done; 994df8bae1dSRodney W. Grimes } 995df8bae1dSRodney W. Grimes } 996df8bae1dSRodney W. Grimes ifaaddr = netmask = brdaddr = 0; 997df8bae1dSRodney W. Grimes } 998a35b06c5SJonathan Lemon done: 999b30a244cSJeffrey Hsu /* IFNET_RUNLOCK(); */ /* XXX */ 1000a35b06c5SJonathan Lemon return (error); 1001df8bae1dSRodney W. Grimes } 1002df8bae1dSRodney W. Grimes 100352041295SPoul-Henning Kamp static int 100482d9ae4eSPoul-Henning Kamp sysctl_rtsock(SYSCTL_HANDLER_ARGS) 1005df8bae1dSRodney W. Grimes { 100652041295SPoul-Henning Kamp int *name = (int *)arg1; 100752041295SPoul-Henning Kamp u_int namelen = arg2; 1008df8bae1dSRodney W. Grimes register struct radix_node_head *rnh; 1009df8bae1dSRodney W. Grimes int i, s, error = EINVAL; 1010df8bae1dSRodney W. Grimes u_char af; 1011df8bae1dSRodney W. Grimes struct walkarg w; 1012df8bae1dSRodney W. Grimes 101352041295SPoul-Henning Kamp name ++; 101452041295SPoul-Henning Kamp namelen--; 101552041295SPoul-Henning Kamp if (req->newptr) 1016df8bae1dSRodney W. Grimes return (EPERM); 1017df8bae1dSRodney W. Grimes if (namelen != 3) 1018f7a54d06SCrist J. Clark return ((namelen < 3) ? EISDIR : ENOTDIR); 1019df8bae1dSRodney W. Grimes af = name[0]; 1020b2aaf46eSJeffrey Hsu if (af > AF_MAX) 1021b2aaf46eSJeffrey Hsu return (EINVAL); 1022df8bae1dSRodney W. Grimes Bzero(&w, sizeof(w)); 1023df8bae1dSRodney W. Grimes w.w_op = name[1]; 1024df8bae1dSRodney W. Grimes w.w_arg = name[2]; 102552041295SPoul-Henning Kamp w.w_req = req; 1026df8bae1dSRodney W. Grimes 1027df8bae1dSRodney W. Grimes s = splnet(); 1028df8bae1dSRodney W. Grimes switch (w.w_op) { 1029df8bae1dSRodney W. Grimes 1030df8bae1dSRodney W. Grimes case NET_RT_DUMP: 1031df8bae1dSRodney W. Grimes case NET_RT_FLAGS: 1032956b0b65SJeffrey Hsu if (af != 0) { 1033956b0b65SJeffrey Hsu if ((rnh = rt_tables[af]) != NULL) { 1034956b0b65SJeffrey Hsu RADIX_NODE_HEAD_LOCK(rnh); 1035956b0b65SJeffrey Hsu error = rnh->rnh_walktree(rnh, 1036956b0b65SJeffrey Hsu sysctl_dumpentry, &w); 1037956b0b65SJeffrey Hsu RADIX_NODE_HEAD_UNLOCK(rnh); 1038956b0b65SJeffrey Hsu } else 1039956b0b65SJeffrey Hsu error = EAFNOSUPPORT; 1040956b0b65SJeffrey Hsu } else { 1041df8bae1dSRodney W. Grimes for (i = 1; i <= AF_MAX; i++) 1042956b0b65SJeffrey Hsu if ((rnh = rt_tables[i]) != NULL) { 1043956b0b65SJeffrey Hsu RADIX_NODE_HEAD_LOCK(rnh); 1044956b0b65SJeffrey Hsu error = rnh->rnh_walktree(rnh, 1045956b0b65SJeffrey Hsu sysctl_dumpentry, &w); 1046956b0b65SJeffrey Hsu RADIX_NODE_HEAD_UNLOCK(rnh); 1047956b0b65SJeffrey Hsu if (error) 1048df8bae1dSRodney W. Grimes break; 1049956b0b65SJeffrey Hsu } 1050956b0b65SJeffrey Hsu } 1051df8bae1dSRodney W. Grimes break; 1052df8bae1dSRodney W. Grimes 1053df8bae1dSRodney W. Grimes case NET_RT_IFLIST: 1054df8bae1dSRodney W. Grimes error = sysctl_iflist(af, &w); 1055df8bae1dSRodney W. Grimes } 1056df8bae1dSRodney W. Grimes splx(s); 1057df8bae1dSRodney W. Grimes if (w.w_tmem) 1058df8bae1dSRodney W. Grimes free(w.w_tmem, M_RTABLE); 1059df8bae1dSRodney W. Grimes return (error); 1060df8bae1dSRodney W. Grimes } 1061df8bae1dSRodney W. Grimes 106252041295SPoul-Henning Kamp SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsock, ""); 106352041295SPoul-Henning Kamp 1064df8bae1dSRodney W. Grimes /* 1065df8bae1dSRodney W. Grimes * Definitions of protocols supported in the ROUTE domain. 1066df8bae1dSRodney W. Grimes */ 1067df8bae1dSRodney W. Grimes 1068df8bae1dSRodney W. Grimes extern struct domain routedomain; /* or at least forward */ 1069df8bae1dSRodney W. Grimes 107052041295SPoul-Henning Kamp static struct protosw routesw[] = { 1071df8bae1dSRodney W. Grimes { SOCK_RAW, &routedomain, 0, PR_ATOMIC|PR_ADDR, 10726ddbf1e2SGary Palmer 0, route_output, raw_ctlinput, 0, 1073a29f300eSGarrett Wollman 0, 1074a29f300eSGarrett Wollman raw_init, 0, 0, 0, 1075a29f300eSGarrett Wollman &route_usrreqs 1076df8bae1dSRodney W. Grimes } 1077df8bae1dSRodney W. Grimes }; 1078df8bae1dSRodney W. Grimes 107952041295SPoul-Henning Kamp static struct domain routedomain = 1080cb64988fSLuoqi Chen { PF_ROUTE, "route", 0, 0, 0, 1081df8bae1dSRodney W. Grimes routesw, &routesw[sizeof(routesw)/sizeof(routesw[0])] }; 108278a82810SGarrett Wollman 1083748e0b0aSGarrett Wollman DOMAIN_SET(route); 1084