xref: /freebsd/sys/net/rtsock.c (revision 75c13541908625d7ee0894cc03f96ab773f7dae2)
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  *
3378a82810SGarrett Wollman  *	@(#)rtsock.c	8.5 (Berkeley) 11/2/94
3475c13541SPoul-Henning Kamp  *	$Id: rtsock.c,v 1.38 1999/01/27 22:42:14 dillon Exp $
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37a29f300eSGarrett Wollman 
38df8bae1dSRodney W. Grimes #include <sys/param.h>
39df8bae1dSRodney W. Grimes #include <sys/systm.h>
40748e0b0aSGarrett Wollman #include <sys/kernel.h>
4152041295SPoul-Henning Kamp #include <sys/sysctl.h>
42df8bae1dSRodney W. Grimes #include <sys/proc.h>
434d1d4912SBruce Evans #include <sys/malloc.h>
44df8bae1dSRodney W. Grimes #include <sys/mbuf.h>
45df8bae1dSRodney W. Grimes #include <sys/socket.h>
46df8bae1dSRodney W. Grimes #include <sys/socketvar.h>
47df8bae1dSRodney W. Grimes #include <sys/domain.h>
48df8bae1dSRodney W. Grimes #include <sys/protosw.h>
49df8bae1dSRodney W. Grimes 
50df8bae1dSRodney W. Grimes #include <net/if.h>
51df8bae1dSRodney W. Grimes #include <net/route.h>
52df8bae1dSRodney W. Grimes #include <net/raw_cb.h>
53df8bae1dSRodney W. Grimes 
54a1c995b6SPoul-Henning Kamp MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables");
55a1c995b6SPoul-Henning Kamp 
5652041295SPoul-Henning Kamp static struct	sockaddr route_dst = { 2, PF_ROUTE, };
5752041295SPoul-Henning Kamp static struct	sockaddr route_src = { 2, PF_ROUTE, };
58076d0761SJulian Elischer static struct	sockaddr sa_zero   = { sizeof(sa_zero), AF_INET, };
5952041295SPoul-Henning Kamp static struct	sockproto route_proto = { PF_ROUTE, };
60df8bae1dSRodney W. Grimes 
61df8bae1dSRodney W. Grimes struct walkarg {
6252041295SPoul-Henning Kamp 	int	w_tmemsize;
6352041295SPoul-Henning Kamp 	int	w_op, w_arg;
6452041295SPoul-Henning Kamp 	caddr_t	w_tmem;
6552041295SPoul-Henning Kamp 	struct sysctl_req *w_req;
66df8bae1dSRodney W. Grimes };
67df8bae1dSRodney W. Grimes 
68df8bae1dSRodney W. Grimes static struct mbuf *
69df8bae1dSRodney W. Grimes 		rt_msg1 __P((int, struct rt_addrinfo *));
70df8bae1dSRodney W. Grimes static int	rt_msg2 __P((int,
71df8bae1dSRodney W. Grimes 		    struct rt_addrinfo *, caddr_t, struct walkarg *));
72076d0761SJulian Elischer static int	rt_xaddrs __P((caddr_t, caddr_t, struct rt_addrinfo *));
7352041295SPoul-Henning Kamp static int	sysctl_dumpentry __P((struct radix_node *rn, void *vw));
7452041295SPoul-Henning Kamp static int	sysctl_iflist __P((int af, struct walkarg *w));
7552041295SPoul-Henning Kamp static int	 route_output __P((struct mbuf *, struct socket *));
7652041295SPoul-Henning Kamp static void	 rt_setmetrics __P((u_long, struct rt_metrics *, struct rt_metrics *));
77df8bae1dSRodney W. Grimes 
78df8bae1dSRodney W. Grimes /* Sleazy use of local variables throughout file, warning!!!! */
79df8bae1dSRodney W. Grimes #define dst	info.rti_info[RTAX_DST]
80df8bae1dSRodney W. Grimes #define gate	info.rti_info[RTAX_GATEWAY]
81df8bae1dSRodney W. Grimes #define netmask	info.rti_info[RTAX_NETMASK]
82df8bae1dSRodney W. Grimes #define genmask	info.rti_info[RTAX_GENMASK]
83df8bae1dSRodney W. Grimes #define ifpaddr	info.rti_info[RTAX_IFP]
84df8bae1dSRodney W. Grimes #define ifaaddr	info.rti_info[RTAX_IFA]
85df8bae1dSRodney W. Grimes #define brdaddr	info.rti_info[RTAX_BRD]
86df8bae1dSRodney W. Grimes 
87a29f300eSGarrett Wollman /*
88a29f300eSGarrett Wollman  * It really doesn't make any sense at all for this code to share much
89a29f300eSGarrett Wollman  * with raw_usrreq.c, since its functionality is so restricted.  XXX
90a29f300eSGarrett Wollman  */
9152041295SPoul-Henning Kamp static int
92a29f300eSGarrett Wollman rts_abort(struct socket *so)
93df8bae1dSRodney W. Grimes {
94a29f300eSGarrett Wollman 	int s, error;
95df8bae1dSRodney W. Grimes 	s = splnet();
96a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_abort(so);
97df8bae1dSRodney W. Grimes 	splx(s);
98a29f300eSGarrett Wollman 	return error;
99df8bae1dSRodney W. Grimes }
100a29f300eSGarrett Wollman 
101a29f300eSGarrett Wollman /* pru_accept is EOPNOTSUPP */
102a29f300eSGarrett Wollman 
103a29f300eSGarrett Wollman static int
104a29f300eSGarrett Wollman rts_attach(struct socket *so, int proto, struct proc *p)
105a29f300eSGarrett Wollman {
106a29f300eSGarrett Wollman 	struct rawcb *rp;
107a29f300eSGarrett Wollman 	int s, error;
108a29f300eSGarrett Wollman 
109a29f300eSGarrett Wollman 	if (sotorawcb(so) != 0)
110a29f300eSGarrett Wollman 		return EISCONN;	/* XXX panic? */
111a29f300eSGarrett Wollman 	MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK); /* XXX */
112a29f300eSGarrett Wollman 	if (rp == 0)
113a29f300eSGarrett Wollman 		return ENOBUFS;
114a29f300eSGarrett Wollman 	bzero(rp, sizeof *rp);
115a29f300eSGarrett Wollman 
116a29f300eSGarrett Wollman 	/*
117a29f300eSGarrett Wollman 	 * The splnet() is necessary to block protocols from sending
118a29f300eSGarrett Wollman 	 * error notifications (like RTM_REDIRECT or RTM_LOSING) while
119a29f300eSGarrett Wollman 	 * this PCB is extant but incompletely initialized.
120a29f300eSGarrett Wollman 	 * Probably we should try to do more of this work beforehand and
121a29f300eSGarrett Wollman 	 * eliminate the spl.
122a29f300eSGarrett Wollman 	 */
123a29f300eSGarrett Wollman 	s = splnet();
124a29f300eSGarrett Wollman 	so->so_pcb = (caddr_t)rp;
125a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_attach(so, proto, p);
126a29f300eSGarrett Wollman 	rp = sotorawcb(so);
127a29f300eSGarrett Wollman 	if (error) {
128a29f300eSGarrett Wollman 		splx(s);
129a29f300eSGarrett Wollman 		free(rp, M_PCB);
130a29f300eSGarrett Wollman 		return error;
131a29f300eSGarrett Wollman 	}
132a29f300eSGarrett Wollman 	switch(rp->rcb_proto.sp_protocol) {
133a29f300eSGarrett Wollman 	case AF_INET:
134df8bae1dSRodney W. Grimes 		route_cb.ip_count++;
135a29f300eSGarrett Wollman 		break;
136a29f300eSGarrett Wollman 	case AF_IPX:
137cc6a66f2SJulian Elischer 		route_cb.ipx_count++;
138a29f300eSGarrett Wollman 		break;
139a29f300eSGarrett Wollman 	case AF_NS:
140df8bae1dSRodney W. Grimes 		route_cb.ns_count++;
141a29f300eSGarrett Wollman 		break;
142a29f300eSGarrett Wollman 	case AF_ISO:
143df8bae1dSRodney W. Grimes 		route_cb.iso_count++;
144a29f300eSGarrett Wollman 		break;
145a29f300eSGarrett Wollman 	}
146df8bae1dSRodney W. Grimes 	rp->rcb_faddr = &route_src;
147df8bae1dSRodney W. Grimes 	route_cb.any_count++;
148df8bae1dSRodney W. Grimes 	soisconnected(so);
149df8bae1dSRodney W. Grimes 	so->so_options |= SO_USELOOPBACK;
150df8bae1dSRodney W. Grimes 	splx(s);
151a29f300eSGarrett Wollman 	return 0;
152df8bae1dSRodney W. Grimes }
153df8bae1dSRodney W. Grimes 
154a29f300eSGarrett Wollman static int
15557bf258eSGarrett Wollman rts_bind(struct socket *so, struct sockaddr *nam, struct proc *p)
156a29f300eSGarrett Wollman {
157a29f300eSGarrett Wollman 	int s, error;
158a29f300eSGarrett Wollman 	s = splnet();
159a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_bind(so, nam, p); /* xxx just EINVAL */
160a29f300eSGarrett Wollman 	splx(s);
161a29f300eSGarrett Wollman 	return error;
162a29f300eSGarrett Wollman }
163a29f300eSGarrett Wollman 
164a29f300eSGarrett Wollman static int
16557bf258eSGarrett Wollman rts_connect(struct socket *so, struct sockaddr *nam, struct proc *p)
166a29f300eSGarrett Wollman {
167a29f300eSGarrett Wollman 	int s, error;
168a29f300eSGarrett Wollman 	s = splnet();
169a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_connect(so, nam, p); /* XXX just EINVAL */
170a29f300eSGarrett Wollman 	splx(s);
171a29f300eSGarrett Wollman 	return error;
172a29f300eSGarrett Wollman }
173a29f300eSGarrett Wollman 
174a29f300eSGarrett Wollman /* pru_connect2 is EOPNOTSUPP */
175a29f300eSGarrett Wollman /* pru_control is EOPNOTSUPP */
176a29f300eSGarrett Wollman 
177a29f300eSGarrett Wollman static int
178a29f300eSGarrett Wollman rts_detach(struct socket *so)
179a29f300eSGarrett Wollman {
180a29f300eSGarrett Wollman 	struct rawcb *rp = sotorawcb(so);
181a29f300eSGarrett Wollman 	int s, error;
182a29f300eSGarrett Wollman 
183a29f300eSGarrett Wollman 	s = splnet();
184a29f300eSGarrett Wollman 	if (rp != 0) {
185a29f300eSGarrett Wollman 		switch(rp->rcb_proto.sp_protocol) {
186a29f300eSGarrett Wollman 		case AF_INET:
187a29f300eSGarrett Wollman 			route_cb.ip_count--;
188a29f300eSGarrett Wollman 			break;
189a29f300eSGarrett Wollman 		case AF_IPX:
190a29f300eSGarrett Wollman 			route_cb.ipx_count--;
191a29f300eSGarrett Wollman 			break;
192a29f300eSGarrett Wollman 		case AF_NS:
193a29f300eSGarrett Wollman 			route_cb.ns_count--;
194a29f300eSGarrett Wollman 			break;
195a29f300eSGarrett Wollman 		case AF_ISO:
196a29f300eSGarrett Wollman 			route_cb.iso_count--;
197a29f300eSGarrett Wollman 			break;
198a29f300eSGarrett Wollman 		}
199a29f300eSGarrett Wollman 		route_cb.any_count--;
200a29f300eSGarrett Wollman 	}
201a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_detach(so);
202a29f300eSGarrett Wollman 	splx(s);
203a29f300eSGarrett Wollman 	return error;
204a29f300eSGarrett Wollman }
205a29f300eSGarrett Wollman 
206a29f300eSGarrett Wollman static int
207a29f300eSGarrett Wollman rts_disconnect(struct socket *so)
208a29f300eSGarrett Wollman {
209a29f300eSGarrett Wollman 	int s, error;
210a29f300eSGarrett Wollman 	s = splnet();
211a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_disconnect(so);
212a29f300eSGarrett Wollman 	splx(s);
213a29f300eSGarrett Wollman 	return error;
214a29f300eSGarrett Wollman }
215a29f300eSGarrett Wollman 
216a29f300eSGarrett Wollman /* pru_listen is EOPNOTSUPP */
217a29f300eSGarrett Wollman 
218a29f300eSGarrett Wollman static int
21957bf258eSGarrett Wollman rts_peeraddr(struct socket *so, struct sockaddr **nam)
220a29f300eSGarrett Wollman {
221a29f300eSGarrett Wollman 	int s, error;
222a29f300eSGarrett Wollman 	s = splnet();
223a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_peeraddr(so, nam);
224a29f300eSGarrett Wollman 	splx(s);
225a29f300eSGarrett Wollman 	return error;
226a29f300eSGarrett Wollman }
227a29f300eSGarrett Wollman 
228a29f300eSGarrett Wollman /* pru_rcvd is EOPNOTSUPP */
229a29f300eSGarrett Wollman /* pru_rcvoob is EOPNOTSUPP */
230a29f300eSGarrett Wollman 
231a29f300eSGarrett Wollman static int
23257bf258eSGarrett Wollman rts_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
233a29f300eSGarrett Wollman 	 struct mbuf *control, struct proc *p)
234a29f300eSGarrett Wollman {
235a29f300eSGarrett Wollman 	int s, error;
236a29f300eSGarrett Wollman 	s = splnet();
237a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_send(so, flags, m, nam, control, p);
238a29f300eSGarrett Wollman 	splx(s);
239a29f300eSGarrett Wollman 	return error;
240a29f300eSGarrett Wollman }
241a29f300eSGarrett Wollman 
242a29f300eSGarrett Wollman /* pru_sense is null */
243a29f300eSGarrett Wollman 
244a29f300eSGarrett Wollman static int
245a29f300eSGarrett Wollman rts_shutdown(struct socket *so)
246a29f300eSGarrett Wollman {
247a29f300eSGarrett Wollman 	int s, error;
248a29f300eSGarrett Wollman 	s = splnet();
249a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_shutdown(so);
250a29f300eSGarrett Wollman 	splx(s);
251a29f300eSGarrett Wollman 	return error;
252a29f300eSGarrett Wollman }
253a29f300eSGarrett Wollman 
254a29f300eSGarrett Wollman static int
25557bf258eSGarrett Wollman rts_sockaddr(struct socket *so, struct sockaddr **nam)
256a29f300eSGarrett Wollman {
257a29f300eSGarrett Wollman 	int s, error;
258a29f300eSGarrett Wollman 	s = splnet();
259a29f300eSGarrett Wollman 	error = raw_usrreqs.pru_sockaddr(so, nam);
260a29f300eSGarrett Wollman 	splx(s);
261a29f300eSGarrett Wollman 	return error;
262a29f300eSGarrett Wollman }
263a29f300eSGarrett Wollman 
264a29f300eSGarrett Wollman static struct pr_usrreqs route_usrreqs = {
265a29f300eSGarrett Wollman 	rts_abort, pru_accept_notsupp, rts_attach, rts_bind, rts_connect,
266a29f300eSGarrett Wollman 	pru_connect2_notsupp, pru_control_notsupp, rts_detach, rts_disconnect,
267a29f300eSGarrett Wollman 	pru_listen_notsupp, rts_peeraddr, pru_rcvd_notsupp, pru_rcvoob_notsupp,
268a29f300eSGarrett Wollman 	rts_send, pru_sense_null, rts_shutdown, rts_sockaddr,
269f8f6cbbaSPeter Wemm 	sosend, soreceive, sopoll
270a29f300eSGarrett Wollman };
271a29f300eSGarrett Wollman 
272df8bae1dSRodney W. Grimes /*ARGSUSED*/
27352041295SPoul-Henning Kamp static int
274df8bae1dSRodney W. Grimes route_output(m, so)
275df8bae1dSRodney W. Grimes 	register struct mbuf *m;
276df8bae1dSRodney W. Grimes 	struct socket *so;
277df8bae1dSRodney W. Grimes {
278df8bae1dSRodney W. Grimes 	register struct rt_msghdr *rtm = 0;
279df8bae1dSRodney W. Grimes 	register struct rtentry *rt = 0;
280df8bae1dSRodney W. Grimes 	struct rtentry *saved_nrt = 0;
28178a82810SGarrett Wollman 	struct radix_node_head *rnh;
282df8bae1dSRodney W. Grimes 	struct rt_addrinfo info;
283df8bae1dSRodney W. Grimes 	int len, error = 0;
284df8bae1dSRodney W. Grimes 	struct ifnet *ifp = 0;
285df8bae1dSRodney W. Grimes 	struct ifaddr *ifa = 0;
286df8bae1dSRodney W. Grimes 
287df8bae1dSRodney W. Grimes #define senderr(e) { error = e; goto flush;}
288df8bae1dSRodney W. Grimes 	if (m == 0 || ((m->m_len < sizeof(long)) &&
289df8bae1dSRodney W. Grimes 		       (m = m_pullup(m, sizeof(long))) == 0))
290df8bae1dSRodney W. Grimes 		return (ENOBUFS);
291df8bae1dSRodney W. Grimes 	if ((m->m_flags & M_PKTHDR) == 0)
292df8bae1dSRodney W. Grimes 		panic("route_output");
293df8bae1dSRodney W. Grimes 	len = m->m_pkthdr.len;
294df8bae1dSRodney W. Grimes 	if (len < sizeof(*rtm) ||
295df8bae1dSRodney W. Grimes 	    len != mtod(m, struct rt_msghdr *)->rtm_msglen) {
296df8bae1dSRodney W. Grimes 		dst = 0;
297df8bae1dSRodney W. Grimes 		senderr(EINVAL);
298df8bae1dSRodney W. Grimes 	}
299df8bae1dSRodney W. Grimes 	R_Malloc(rtm, struct rt_msghdr *, len);
300df8bae1dSRodney W. Grimes 	if (rtm == 0) {
301df8bae1dSRodney W. Grimes 		dst = 0;
302df8bae1dSRodney W. Grimes 		senderr(ENOBUFS);
303df8bae1dSRodney W. Grimes 	}
304df8bae1dSRodney W. Grimes 	m_copydata(m, 0, len, (caddr_t)rtm);
305df8bae1dSRodney W. Grimes 	if (rtm->rtm_version != RTM_VERSION) {
306df8bae1dSRodney W. Grimes 		dst = 0;
307df8bae1dSRodney W. Grimes 		senderr(EPROTONOSUPPORT);
308df8bae1dSRodney W. Grimes 	}
309df8bae1dSRodney W. Grimes 	rtm->rtm_pid = curproc->p_pid;
310df8bae1dSRodney W. Grimes 	info.rti_addrs = rtm->rtm_addrs;
311076d0761SJulian Elischer 	if (rt_xaddrs((caddr_t)(rtm + 1), len + (caddr_t)rtm, &info)) {
312076d0761SJulian Elischer 		dst = 0;
313076d0761SJulian Elischer 		senderr(EINVAL);
314076d0761SJulian Elischer 	}
315ed07cc7fSGarrett Wollman 	if (dst == 0 || (dst->sa_family >= AF_MAX)
316ed07cc7fSGarrett Wollman 	    || (gate != 0 && (gate->sa_family >= AF_MAX)))
317df8bae1dSRodney W. Grimes 		senderr(EINVAL);
318df8bae1dSRodney W. Grimes 	if (genmask) {
319df8bae1dSRodney W. Grimes 		struct radix_node *t;
32078a82810SGarrett Wollman 		t = rn_addmask((caddr_t)genmask, 0, 1);
321df8bae1dSRodney W. Grimes 		if (t && Bcmp(genmask, t->rn_key, *(u_char *)genmask) == 0)
322df8bae1dSRodney W. Grimes 			genmask = (struct sockaddr *)(t->rn_key);
323df8bae1dSRodney W. Grimes 		else
324df8bae1dSRodney W. Grimes 			senderr(ENOBUFS);
325df8bae1dSRodney W. Grimes 	}
326df8bae1dSRodney W. Grimes 	switch (rtm->rtm_type) {
327df8bae1dSRodney W. Grimes 
328df8bae1dSRodney W. Grimes 	case RTM_ADD:
329df8bae1dSRodney W. Grimes 		if (gate == 0)
330df8bae1dSRodney W. Grimes 			senderr(EINVAL);
331df8bae1dSRodney W. Grimes 		error = rtrequest(RTM_ADD, dst, gate, netmask,
332df8bae1dSRodney W. Grimes 					rtm->rtm_flags, &saved_nrt);
333df8bae1dSRodney W. Grimes 		if (error == 0 && saved_nrt) {
334df8bae1dSRodney W. Grimes 			rt_setmetrics(rtm->rtm_inits,
335df8bae1dSRodney W. Grimes 				&rtm->rtm_rmx, &saved_nrt->rt_rmx);
33695b6073cSDavid Greenman 			saved_nrt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
33795b6073cSDavid Greenman 			saved_nrt->rt_rmx.rmx_locks |=
33895b6073cSDavid Greenman 				(rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
339df8bae1dSRodney W. Grimes 			saved_nrt->rt_refcnt--;
340df8bae1dSRodney W. Grimes 			saved_nrt->rt_genmask = genmask;
341df8bae1dSRodney W. Grimes 		}
342df8bae1dSRodney W. Grimes 		break;
343df8bae1dSRodney W. Grimes 
344df8bae1dSRodney W. Grimes 	case RTM_DELETE:
345df8bae1dSRodney W. Grimes 		error = rtrequest(RTM_DELETE, dst, gate, netmask,
34678a82810SGarrett Wollman 				rtm->rtm_flags, &saved_nrt);
34778a82810SGarrett Wollman 		if (error == 0) {
348c9a84156SDavid Greenman 			if ((rt = saved_nrt))
34978a82810SGarrett Wollman 				rt->rt_refcnt++;
35078a82810SGarrett Wollman 			goto report;
35178a82810SGarrett Wollman 		}
352df8bae1dSRodney W. Grimes 		break;
353df8bae1dSRodney W. Grimes 
354df8bae1dSRodney W. Grimes 	case RTM_GET:
355df8bae1dSRodney W. Grimes 	case RTM_CHANGE:
356df8bae1dSRodney W. Grimes 	case RTM_LOCK:
35778a82810SGarrett Wollman 		if ((rnh = rt_tables[dst->sa_family]) == 0) {
35878a82810SGarrett Wollman 			senderr(EAFNOSUPPORT);
359831a80b0SMatthew Dillon 		} else if ((rt = (struct rtentry *)
360831a80b0SMatthew Dillon 				rnh->rnh_lookup(dst, netmask, rnh)) != NULL)
36178a82810SGarrett Wollman 			rt->rt_refcnt++;
36278a82810SGarrett Wollman 		else
363df8bae1dSRodney W. Grimes 			senderr(ESRCH);
364df8bae1dSRodney W. Grimes 		switch(rtm->rtm_type) {
365df8bae1dSRodney W. Grimes 
366df8bae1dSRodney W. Grimes 		case RTM_GET:
36778a82810SGarrett Wollman 		report:
368df8bae1dSRodney W. Grimes 			dst = rt_key(rt);
369df8bae1dSRodney W. Grimes 			gate = rt->rt_gateway;
370df8bae1dSRodney W. Grimes 			netmask = rt_mask(rt);
371df8bae1dSRodney W. Grimes 			genmask = rt->rt_genmask;
372df8bae1dSRodney W. Grimes 			if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) {
373df440948SPoul-Henning Kamp 				ifp = rt->rt_ifp;
374df440948SPoul-Henning Kamp 				if (ifp) {
37559562606SGarrett Wollman 					ifpaddr = ifp->if_addrhead.tqh_first->ifa_addr;
376df8bae1dSRodney W. Grimes 					ifaaddr = rt->rt_ifa->ifa_addr;
377df8bae1dSRodney W. Grimes 					rtm->rtm_index = ifp->if_index;
378df8bae1dSRodney W. Grimes 				} else {
379df8bae1dSRodney W. Grimes 					ifpaddr = 0;
380df8bae1dSRodney W. Grimes 					ifaaddr = 0;
381df8bae1dSRodney W. Grimes 			    }
382df8bae1dSRodney W. Grimes 			}
38378a82810SGarrett Wollman 			len = rt_msg2(rtm->rtm_type, &info, (caddr_t)0,
384df8bae1dSRodney W. Grimes 				(struct walkarg *)0);
385df8bae1dSRodney W. Grimes 			if (len > rtm->rtm_msglen) {
386df8bae1dSRodney W. Grimes 				struct rt_msghdr *new_rtm;
387df8bae1dSRodney W. Grimes 				R_Malloc(new_rtm, struct rt_msghdr *, len);
388df8bae1dSRodney W. Grimes 				if (new_rtm == 0)
389df8bae1dSRodney W. Grimes 					senderr(ENOBUFS);
390df8bae1dSRodney W. Grimes 				Bcopy(rtm, new_rtm, rtm->rtm_msglen);
391df8bae1dSRodney W. Grimes 				Free(rtm); rtm = new_rtm;
392df8bae1dSRodney W. Grimes 			}
39378a82810SGarrett Wollman 			(void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm,
394df8bae1dSRodney W. Grimes 				(struct walkarg *)0);
395df8bae1dSRodney W. Grimes 			rtm->rtm_flags = rt->rt_flags;
396df8bae1dSRodney W. Grimes 			rtm->rtm_rmx = rt->rt_rmx;
397df8bae1dSRodney W. Grimes 			rtm->rtm_addrs = info.rti_addrs;
398df8bae1dSRodney W. Grimes 			break;
399df8bae1dSRodney W. Grimes 
400df8bae1dSRodney W. Grimes 		case RTM_CHANGE:
4011db1fffaSBill Fenner 			if (gate && (error = rt_setgate(rt, rt_key(rt), gate)))
4021db1fffaSBill Fenner 				senderr(error);
4035df72964SGarrett Wollman 
4045df72964SGarrett Wollman 			/*
4055df72964SGarrett Wollman 			 * If they tried to change things but didn't specify
4065df72964SGarrett Wollman 			 * the required gateway, then just use the old one.
4075df72964SGarrett Wollman 			 * This can happen if the user tries to change the
4085df72964SGarrett Wollman 			 * flags on the default route without changing the
4095df72964SGarrett Wollman 			 * default gateway.  Changing flags still doesn't work.
4105df72964SGarrett Wollman 			 */
4115df72964SGarrett Wollman 			if ((rt->rt_flags & RTF_GATEWAY) && !gate)
4125df72964SGarrett Wollman 				gate = rt->rt_gateway;
4135df72964SGarrett Wollman 
414df8bae1dSRodney W. Grimes 			/* new gateway could require new ifaddr, ifp;
415df8bae1dSRodney W. Grimes 			   flags may also be different; ifp may be specified
416df8bae1dSRodney W. Grimes 			   by ll sockaddr when protocol address is ambiguous */
417df8bae1dSRodney W. Grimes 			if (ifpaddr && (ifa = ifa_ifwithnet(ifpaddr)) &&
4183aa72005SBill Fenner 			    (ifp = ifa->ifa_ifp) && (ifaaddr || gate))
419df8bae1dSRodney W. Grimes 				ifa = ifaof_ifpforaddr(ifaaddr ? ifaaddr : gate,
420df8bae1dSRodney W. Grimes 							ifp);
421df8bae1dSRodney W. Grimes 			else if ((ifaaddr && (ifa = ifa_ifwithaddr(ifaaddr))) ||
4223aa72005SBill Fenner 				 (gate && (ifa = ifa_ifwithroute(rt->rt_flags,
4233aa72005SBill Fenner 							rt_key(rt), gate))))
424df8bae1dSRodney W. Grimes 				ifp = ifa->ifa_ifp;
425df8bae1dSRodney W. Grimes 			if (ifa) {
426df8bae1dSRodney W. Grimes 				register struct ifaddr *oifa = rt->rt_ifa;
427df8bae1dSRodney W. Grimes 				if (oifa != ifa) {
428df8bae1dSRodney W. Grimes 				    if (oifa && oifa->ifa_rtrequest)
429df8bae1dSRodney W. Grimes 					oifa->ifa_rtrequest(RTM_DELETE,
430df8bae1dSRodney W. Grimes 								rt, gate);
431df8bae1dSRodney W. Grimes 				    IFAFREE(rt->rt_ifa);
432df8bae1dSRodney W. Grimes 				    rt->rt_ifa = ifa;
433df8bae1dSRodney W. Grimes 				    ifa->ifa_refcnt++;
434df8bae1dSRodney W. Grimes 				    rt->rt_ifp = ifp;
435df8bae1dSRodney W. Grimes 				}
436df8bae1dSRodney W. Grimes 			}
437df8bae1dSRodney W. Grimes 			rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx,
438df8bae1dSRodney W. Grimes 					&rt->rt_rmx);
439df8bae1dSRodney W. Grimes 			if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
440df8bae1dSRodney W. Grimes 			       rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, gate);
441df8bae1dSRodney W. Grimes 			if (genmask)
442df8bae1dSRodney W. Grimes 				rt->rt_genmask = genmask;
443df8bae1dSRodney W. Grimes 			/*
444df8bae1dSRodney W. Grimes 			 * Fall into
445df8bae1dSRodney W. Grimes 			 */
446df8bae1dSRodney W. Grimes 		case RTM_LOCK:
447df8bae1dSRodney W. Grimes 			rt->rt_rmx.rmx_locks &= ~(rtm->rtm_inits);
448df8bae1dSRodney W. Grimes 			rt->rt_rmx.rmx_locks |=
449df8bae1dSRodney W. Grimes 				(rtm->rtm_inits & rtm->rtm_rmx.rmx_locks);
450df8bae1dSRodney W. Grimes 			break;
451df8bae1dSRodney W. Grimes 		}
452df8bae1dSRodney W. Grimes 		break;
453df8bae1dSRodney W. Grimes 
454df8bae1dSRodney W. Grimes 	default:
455df8bae1dSRodney W. Grimes 		senderr(EOPNOTSUPP);
456df8bae1dSRodney W. Grimes 	}
457df8bae1dSRodney W. Grimes 
458df8bae1dSRodney W. Grimes flush:
459df8bae1dSRodney W. Grimes 	if (rtm) {
460df8bae1dSRodney W. Grimes 		if (error)
461df8bae1dSRodney W. Grimes 			rtm->rtm_errno = error;
462df8bae1dSRodney W. Grimes 		else
463df8bae1dSRodney W. Grimes 			rtm->rtm_flags |= RTF_DONE;
464df8bae1dSRodney W. Grimes 	}
465df8bae1dSRodney W. Grimes 	if (rt)
466df8bae1dSRodney W. Grimes 		rtfree(rt);
467df8bae1dSRodney W. Grimes     {
468df8bae1dSRodney W. Grimes 	register struct rawcb *rp = 0;
469df8bae1dSRodney W. Grimes 	/*
470df8bae1dSRodney W. Grimes 	 * Check to see if we don't want our own messages.
471df8bae1dSRodney W. Grimes 	 */
472df8bae1dSRodney W. Grimes 	if ((so->so_options & SO_USELOOPBACK) == 0) {
473df8bae1dSRodney W. Grimes 		if (route_cb.any_count <= 1) {
474df8bae1dSRodney W. Grimes 			if (rtm)
475df8bae1dSRodney W. Grimes 				Free(rtm);
476df8bae1dSRodney W. Grimes 			m_freem(m);
477df8bae1dSRodney W. Grimes 			return (error);
478df8bae1dSRodney W. Grimes 		}
479df8bae1dSRodney W. Grimes 		/* There is another listener, so construct message */
480df8bae1dSRodney W. Grimes 		rp = sotorawcb(so);
481df8bae1dSRodney W. Grimes 	}
482df8bae1dSRodney W. Grimes 	if (rtm) {
483df8bae1dSRodney W. Grimes 		m_copyback(m, 0, rtm->rtm_msglen, (caddr_t)rtm);
484df8bae1dSRodney W. Grimes 		Free(rtm);
485df8bae1dSRodney W. Grimes 	}
486df8bae1dSRodney W. Grimes 	if (rp)
487df8bae1dSRodney W. Grimes 		rp->rcb_proto.sp_family = 0; /* Avoid us */
488df8bae1dSRodney W. Grimes 	if (dst)
489df8bae1dSRodney W. Grimes 		route_proto.sp_protocol = dst->sa_family;
490df8bae1dSRodney W. Grimes 	raw_input(m, &route_proto, &route_src, &route_dst);
491df8bae1dSRodney W. Grimes 	if (rp)
492df8bae1dSRodney W. Grimes 		rp->rcb_proto.sp_family = PF_ROUTE;
493df8bae1dSRodney W. Grimes     }
494df8bae1dSRodney W. Grimes 	return (error);
495df8bae1dSRodney W. Grimes }
496df8bae1dSRodney W. Grimes 
49752041295SPoul-Henning Kamp static void
498df8bae1dSRodney W. Grimes rt_setmetrics(which, in, out)
499df8bae1dSRodney W. Grimes 	u_long which;
500df8bae1dSRodney W. Grimes 	register struct rt_metrics *in, *out;
501df8bae1dSRodney W. Grimes {
502df8bae1dSRodney W. Grimes #define metric(f, e) if (which & (f)) out->e = in->e;
503df8bae1dSRodney W. Grimes 	metric(RTV_RPIPE, rmx_recvpipe);
504df8bae1dSRodney W. Grimes 	metric(RTV_SPIPE, rmx_sendpipe);
505df8bae1dSRodney W. Grimes 	metric(RTV_SSTHRESH, rmx_ssthresh);
506df8bae1dSRodney W. Grimes 	metric(RTV_RTT, rmx_rtt);
507df8bae1dSRodney W. Grimes 	metric(RTV_RTTVAR, rmx_rttvar);
508df8bae1dSRodney W. Grimes 	metric(RTV_HOPCOUNT, rmx_hopcount);
509df8bae1dSRodney W. Grimes 	metric(RTV_MTU, rmx_mtu);
510df8bae1dSRodney W. Grimes 	metric(RTV_EXPIRE, rmx_expire);
511df8bae1dSRodney W. Grimes #undef metric
512df8bae1dSRodney W. Grimes }
513df8bae1dSRodney W. Grimes 
514df8bae1dSRodney W. Grimes #define ROUNDUP(a) \
515df8bae1dSRodney W. Grimes 	((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
516df8bae1dSRodney W. Grimes #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
517df8bae1dSRodney W. Grimes 
518076d0761SJulian Elischer 
5197f33a738SJulian Elischer /*
5207f33a738SJulian Elischer  * Extract the addresses of the passed sockaddrs.
5217f33a738SJulian Elischer  * Do a little sanity checking so as to avoid bad memory references.
522076d0761SJulian Elischer  * This data is derived straight from userland.
5237f33a738SJulian Elischer  */
524076d0761SJulian Elischer static int
525df8bae1dSRodney W. Grimes rt_xaddrs(cp, cplim, rtinfo)
526df8bae1dSRodney W. Grimes 	register caddr_t cp, cplim;
527df8bae1dSRodney W. Grimes 	register struct rt_addrinfo *rtinfo;
528df8bae1dSRodney W. Grimes {
529df8bae1dSRodney W. Grimes 	register struct sockaddr *sa;
530df8bae1dSRodney W. Grimes 	register int i;
531df8bae1dSRodney W. Grimes 
532df8bae1dSRodney W. Grimes 	bzero(rtinfo->rti_info, sizeof(rtinfo->rti_info));
533076d0761SJulian Elischer 	for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) {
534df8bae1dSRodney W. Grimes 		if ((rtinfo->rti_addrs & (1 << i)) == 0)
535df8bae1dSRodney W. Grimes 			continue;
536ff6d0a59SJulian Elischer 		sa = (struct sockaddr *)cp;
5377f33a738SJulian Elischer 		/*
538076d0761SJulian Elischer 		 * It won't fit.
5397f33a738SJulian Elischer 		 */
540076d0761SJulian Elischer 		if ( (cp + sa->sa_len) > cplim ) {
541076d0761SJulian Elischer 			return (EINVAL);
542076d0761SJulian Elischer 		}
5439a969a6eSMike Smith 
5447f33a738SJulian Elischer 		/*
5457f33a738SJulian Elischer 		 * there are no more.. quit now
5467f33a738SJulian Elischer 		 * If there are more bits, they are in error.
5477f33a738SJulian Elischer 		 * I've seen this. route(1) can evidently generate these.
5487f33a738SJulian Elischer 		 * This causes kernel to core dump.
549076d0761SJulian Elischer 		 * for compatibility, If we see this, point to a safe address.
5507f33a738SJulian Elischer 		 */
551076d0761SJulian Elischer 		if (sa->sa_len == 0) {
552076d0761SJulian Elischer 			rtinfo->rti_info[i] = &sa_zero;
553076d0761SJulian Elischer 			return (0); /* should be EINVAL but for compat */
554df8bae1dSRodney W. Grimes 		}
555076d0761SJulian Elischer 
556076d0761SJulian Elischer 		/* accept it */
557076d0761SJulian Elischer 		rtinfo->rti_info[i] = sa;
558076d0761SJulian Elischer 		ADVANCE(cp, sa);
559076d0761SJulian Elischer 	}
560076d0761SJulian Elischer 	return (0);
561df8bae1dSRodney W. Grimes }
562df8bae1dSRodney W. Grimes 
563df8bae1dSRodney W. Grimes static struct mbuf *
564df8bae1dSRodney W. Grimes rt_msg1(type, rtinfo)
565df8bae1dSRodney W. Grimes 	int type;
566df8bae1dSRodney W. Grimes 	register struct rt_addrinfo *rtinfo;
567df8bae1dSRodney W. Grimes {
568df8bae1dSRodney W. Grimes 	register struct rt_msghdr *rtm;
569df8bae1dSRodney W. Grimes 	register struct mbuf *m;
570df8bae1dSRodney W. Grimes 	register int i;
571df8bae1dSRodney W. Grimes 	register struct sockaddr *sa;
572df8bae1dSRodney W. Grimes 	int len, dlen;
573df8bae1dSRodney W. Grimes 
574df8bae1dSRodney W. Grimes 	m = m_gethdr(M_DONTWAIT, MT_DATA);
575df8bae1dSRodney W. Grimes 	if (m == 0)
576df8bae1dSRodney W. Grimes 		return (m);
577df8bae1dSRodney W. Grimes 	switch (type) {
578df8bae1dSRodney W. Grimes 
579df8bae1dSRodney W. Grimes 	case RTM_DELADDR:
580df8bae1dSRodney W. Grimes 	case RTM_NEWADDR:
581df8bae1dSRodney W. Grimes 		len = sizeof(struct ifa_msghdr);
582df8bae1dSRodney W. Grimes 		break;
583df8bae1dSRodney W. Grimes 
584477180fbSGarrett Wollman 	case RTM_DELMADDR:
585477180fbSGarrett Wollman 	case RTM_NEWMADDR:
586477180fbSGarrett Wollman 		len = sizeof(struct ifma_msghdr);
587477180fbSGarrett Wollman 		break;
588477180fbSGarrett Wollman 
589df8bae1dSRodney W. Grimes 	case RTM_IFINFO:
590df8bae1dSRodney W. Grimes 		len = sizeof(struct if_msghdr);
591df8bae1dSRodney W. Grimes 		break;
592df8bae1dSRodney W. Grimes 
593df8bae1dSRodney W. Grimes 	default:
594df8bae1dSRodney W. Grimes 		len = sizeof(struct rt_msghdr);
595df8bae1dSRodney W. Grimes 	}
596df8bae1dSRodney W. Grimes 	if (len > MHLEN)
597df8bae1dSRodney W. Grimes 		panic("rt_msg1");
598df8bae1dSRodney W. Grimes 	m->m_pkthdr.len = m->m_len = len;
599df8bae1dSRodney W. Grimes 	m->m_pkthdr.rcvif = 0;
600df8bae1dSRodney W. Grimes 	rtm = mtod(m, struct rt_msghdr *);
601df8bae1dSRodney W. Grimes 	bzero((caddr_t)rtm, len);
602df8bae1dSRodney W. Grimes 	for (i = 0; i < RTAX_MAX; i++) {
603df8bae1dSRodney W. Grimes 		if ((sa = rtinfo->rti_info[i]) == NULL)
604df8bae1dSRodney W. Grimes 			continue;
605df8bae1dSRodney W. Grimes 		rtinfo->rti_addrs |= (1 << i);
606df8bae1dSRodney W. Grimes 		dlen = ROUNDUP(sa->sa_len);
607df8bae1dSRodney W. Grimes 		m_copyback(m, len, dlen, (caddr_t)sa);
608df8bae1dSRodney W. Grimes 		len += dlen;
609df8bae1dSRodney W. Grimes 	}
610df8bae1dSRodney W. Grimes 	if (m->m_pkthdr.len != len) {
611df8bae1dSRodney W. Grimes 		m_freem(m);
612df8bae1dSRodney W. Grimes 		return (NULL);
613df8bae1dSRodney W. Grimes 	}
614df8bae1dSRodney W. Grimes 	rtm->rtm_msglen = len;
615df8bae1dSRodney W. Grimes 	rtm->rtm_version = RTM_VERSION;
616df8bae1dSRodney W. Grimes 	rtm->rtm_type = type;
617df8bae1dSRodney W. Grimes 	return (m);
618df8bae1dSRodney W. Grimes }
619df8bae1dSRodney W. Grimes 
620df8bae1dSRodney W. Grimes static int
621df8bae1dSRodney W. Grimes rt_msg2(type, rtinfo, cp, w)
622df8bae1dSRodney W. Grimes 	int type;
623df8bae1dSRodney W. Grimes 	register struct rt_addrinfo *rtinfo;
624df8bae1dSRodney W. Grimes 	caddr_t cp;
625df8bae1dSRodney W. Grimes 	struct walkarg *w;
626df8bae1dSRodney W. Grimes {
627df8bae1dSRodney W. Grimes 	register int i;
628df8bae1dSRodney W. Grimes 	int len, dlen, second_time = 0;
629df8bae1dSRodney W. Grimes 	caddr_t cp0;
630df8bae1dSRodney W. Grimes 
631df8bae1dSRodney W. Grimes 	rtinfo->rti_addrs = 0;
632df8bae1dSRodney W. Grimes again:
633df8bae1dSRodney W. Grimes 	switch (type) {
634df8bae1dSRodney W. Grimes 
635df8bae1dSRodney W. Grimes 	case RTM_DELADDR:
636df8bae1dSRodney W. Grimes 	case RTM_NEWADDR:
637df8bae1dSRodney W. Grimes 		len = sizeof(struct ifa_msghdr);
638df8bae1dSRodney W. Grimes 		break;
639df8bae1dSRodney W. Grimes 
640df8bae1dSRodney W. Grimes 	case RTM_IFINFO:
641df8bae1dSRodney W. Grimes 		len = sizeof(struct if_msghdr);
642df8bae1dSRodney W. Grimes 		break;
643df8bae1dSRodney W. Grimes 
644df8bae1dSRodney W. Grimes 	default:
645df8bae1dSRodney W. Grimes 		len = sizeof(struct rt_msghdr);
646df8bae1dSRodney W. Grimes 	}
647df440948SPoul-Henning Kamp 	cp0 = cp;
648df440948SPoul-Henning Kamp 	if (cp0)
649df8bae1dSRodney W. Grimes 		cp += len;
650df8bae1dSRodney W. Grimes 	for (i = 0; i < RTAX_MAX; i++) {
651df8bae1dSRodney W. Grimes 		register struct sockaddr *sa;
652df8bae1dSRodney W. Grimes 
653df8bae1dSRodney W. Grimes 		if ((sa = rtinfo->rti_info[i]) == 0)
654df8bae1dSRodney W. Grimes 			continue;
655df8bae1dSRodney W. Grimes 		rtinfo->rti_addrs |= (1 << i);
656df8bae1dSRodney W. Grimes 		dlen = ROUNDUP(sa->sa_len);
657df8bae1dSRodney W. Grimes 		if (cp) {
658df8bae1dSRodney W. Grimes 			bcopy((caddr_t)sa, cp, (unsigned)dlen);
659df8bae1dSRodney W. Grimes 			cp += dlen;
660df8bae1dSRodney W. Grimes 		}
661df8bae1dSRodney W. Grimes 		len += dlen;
662df8bae1dSRodney W. Grimes 	}
663df8bae1dSRodney W. Grimes 	if (cp == 0 && w != NULL && !second_time) {
664df8bae1dSRodney W. Grimes 		register struct walkarg *rw = w;
665df8bae1dSRodney W. Grimes 
66652041295SPoul-Henning Kamp 		if (rw->w_req) {
667df8bae1dSRodney W. Grimes 			if (rw->w_tmemsize < len) {
668df8bae1dSRodney W. Grimes 				if (rw->w_tmem)
669df8bae1dSRodney W. Grimes 					free(rw->w_tmem, M_RTABLE);
670df440948SPoul-Henning Kamp 				rw->w_tmem = (caddr_t)
671df440948SPoul-Henning Kamp 					malloc(len, M_RTABLE, M_NOWAIT);
672df440948SPoul-Henning Kamp 				if (rw->w_tmem)
673df8bae1dSRodney W. Grimes 					rw->w_tmemsize = len;
674df8bae1dSRodney W. Grimes 			}
675df8bae1dSRodney W. Grimes 			if (rw->w_tmem) {
676df8bae1dSRodney W. Grimes 				cp = rw->w_tmem;
677df8bae1dSRodney W. Grimes 				second_time = 1;
678df8bae1dSRodney W. Grimes 				goto again;
67952041295SPoul-Henning Kamp 			}
680df8bae1dSRodney W. Grimes 		}
681df8bae1dSRodney W. Grimes 	}
682df8bae1dSRodney W. Grimes 	if (cp) {
683df8bae1dSRodney W. Grimes 		register struct rt_msghdr *rtm = (struct rt_msghdr *)cp0;
684df8bae1dSRodney W. Grimes 
685df8bae1dSRodney W. Grimes 		rtm->rtm_version = RTM_VERSION;
686df8bae1dSRodney W. Grimes 		rtm->rtm_type = type;
687df8bae1dSRodney W. Grimes 		rtm->rtm_msglen = len;
688df8bae1dSRodney W. Grimes 	}
689df8bae1dSRodney W. Grimes 	return (len);
690df8bae1dSRodney W. Grimes }
691df8bae1dSRodney W. Grimes 
692df8bae1dSRodney W. Grimes /*
693df8bae1dSRodney W. Grimes  * This routine is called to generate a message from the routing
694df8bae1dSRodney W. Grimes  * socket indicating that a redirect has occured, a routing lookup
695df8bae1dSRodney W. Grimes  * has failed, or that a protocol has detected timeouts to a particular
696df8bae1dSRodney W. Grimes  * destination.
697df8bae1dSRodney W. Grimes  */
698df8bae1dSRodney W. Grimes void
699df8bae1dSRodney W. Grimes rt_missmsg(type, rtinfo, flags, error)
700df8bae1dSRodney W. Grimes 	int type, flags, error;
701df8bae1dSRodney W. Grimes 	register struct rt_addrinfo *rtinfo;
702df8bae1dSRodney W. Grimes {
703df8bae1dSRodney W. Grimes 	register struct rt_msghdr *rtm;
704df8bae1dSRodney W. Grimes 	register struct mbuf *m;
705df8bae1dSRodney W. Grimes 	struct sockaddr *sa = rtinfo->rti_info[RTAX_DST];
706df8bae1dSRodney W. Grimes 
707df8bae1dSRodney W. Grimes 	if (route_cb.any_count == 0)
708df8bae1dSRodney W. Grimes 		return;
709df8bae1dSRodney W. Grimes 	m = rt_msg1(type, rtinfo);
710df8bae1dSRodney W. Grimes 	if (m == 0)
711df8bae1dSRodney W. Grimes 		return;
712df8bae1dSRodney W. Grimes 	rtm = mtod(m, struct rt_msghdr *);
713df8bae1dSRodney W. Grimes 	rtm->rtm_flags = RTF_DONE | flags;
714df8bae1dSRodney W. Grimes 	rtm->rtm_errno = error;
715df8bae1dSRodney W. Grimes 	rtm->rtm_addrs = rtinfo->rti_addrs;
716df8bae1dSRodney W. Grimes 	route_proto.sp_protocol = sa ? sa->sa_family : 0;
717df8bae1dSRodney W. Grimes 	raw_input(m, &route_proto, &route_src, &route_dst);
718df8bae1dSRodney W. Grimes }
719df8bae1dSRodney W. Grimes 
720df8bae1dSRodney W. Grimes /*
721df8bae1dSRodney W. Grimes  * This routine is called to generate a message from the routing
722df8bae1dSRodney W. Grimes  * socket indicating that the status of a network interface has changed.
723df8bae1dSRodney W. Grimes  */
724df8bae1dSRodney W. Grimes void
725df8bae1dSRodney W. Grimes rt_ifmsg(ifp)
726df8bae1dSRodney W. Grimes 	register struct ifnet *ifp;
727df8bae1dSRodney W. Grimes {
728df8bae1dSRodney W. Grimes 	register struct if_msghdr *ifm;
729df8bae1dSRodney W. Grimes 	struct mbuf *m;
730df8bae1dSRodney W. Grimes 	struct rt_addrinfo info;
731df8bae1dSRodney W. Grimes 
732df8bae1dSRodney W. Grimes 	if (route_cb.any_count == 0)
733df8bae1dSRodney W. Grimes 		return;
734df8bae1dSRodney W. Grimes 	bzero((caddr_t)&info, sizeof(info));
735df8bae1dSRodney W. Grimes 	m = rt_msg1(RTM_IFINFO, &info);
736df8bae1dSRodney W. Grimes 	if (m == 0)
737df8bae1dSRodney W. Grimes 		return;
738df8bae1dSRodney W. Grimes 	ifm = mtod(m, struct if_msghdr *);
739df8bae1dSRodney W. Grimes 	ifm->ifm_index = ifp->if_index;
7402624cf89SGarrett Wollman 	ifm->ifm_flags = (u_short)ifp->if_flags;
741df8bae1dSRodney W. Grimes 	ifm->ifm_data = ifp->if_data;
742df8bae1dSRodney W. Grimes 	ifm->ifm_addrs = 0;
743df8bae1dSRodney W. Grimes 	route_proto.sp_protocol = 0;
744df8bae1dSRodney W. Grimes 	raw_input(m, &route_proto, &route_src, &route_dst);
745df8bae1dSRodney W. Grimes }
746df8bae1dSRodney W. Grimes 
747df8bae1dSRodney W. Grimes /*
748df8bae1dSRodney W. Grimes  * This is called to generate messages from the routing socket
749df8bae1dSRodney W. Grimes  * indicating a network interface has had addresses associated with it.
750df8bae1dSRodney W. Grimes  * if we ever reverse the logic and replace messages TO the routing
751df8bae1dSRodney W. Grimes  * socket indicate a request to configure interfaces, then it will
752df8bae1dSRodney W. Grimes  * be unnecessary as the routing socket will automatically generate
753df8bae1dSRodney W. Grimes  * copies of it.
754df8bae1dSRodney W. Grimes  */
755df8bae1dSRodney W. Grimes void
756df8bae1dSRodney W. Grimes rt_newaddrmsg(cmd, ifa, error, rt)
757df8bae1dSRodney W. Grimes 	int cmd, error;
758df8bae1dSRodney W. Grimes 	register struct ifaddr *ifa;
759df8bae1dSRodney W. Grimes 	register struct rtentry *rt;
760df8bae1dSRodney W. Grimes {
761df8bae1dSRodney W. Grimes 	struct rt_addrinfo info;
76226f9a767SRodney W. Grimes 	struct sockaddr *sa = 0;
763df8bae1dSRodney W. Grimes 	int pass;
76426f9a767SRodney W. Grimes 	struct mbuf *m = 0;
765df8bae1dSRodney W. Grimes 	struct ifnet *ifp = ifa->ifa_ifp;
766df8bae1dSRodney W. Grimes 
767df8bae1dSRodney W. Grimes 	if (route_cb.any_count == 0)
768df8bae1dSRodney W. Grimes 		return;
769df8bae1dSRodney W. Grimes 	for (pass = 1; pass < 3; pass++) {
770df8bae1dSRodney W. Grimes 		bzero((caddr_t)&info, sizeof(info));
771df8bae1dSRodney W. Grimes 		if ((cmd == RTM_ADD && pass == 1) ||
772df8bae1dSRodney W. Grimes 		    (cmd == RTM_DELETE && pass == 2)) {
773df8bae1dSRodney W. Grimes 			register struct ifa_msghdr *ifam;
774df8bae1dSRodney W. Grimes 			int ncmd = cmd == RTM_ADD ? RTM_NEWADDR : RTM_DELADDR;
775df8bae1dSRodney W. Grimes 
776df8bae1dSRodney W. Grimes 			ifaaddr = sa = ifa->ifa_addr;
77759562606SGarrett Wollman 			ifpaddr = ifp->if_addrhead.tqh_first->ifa_addr;
778df8bae1dSRodney W. Grimes 			netmask = ifa->ifa_netmask;
779df8bae1dSRodney W. Grimes 			brdaddr = ifa->ifa_dstaddr;
780df8bae1dSRodney W. Grimes 			if ((m = rt_msg1(ncmd, &info)) == NULL)
781df8bae1dSRodney W. Grimes 				continue;
782df8bae1dSRodney W. Grimes 			ifam = mtod(m, struct ifa_msghdr *);
783df8bae1dSRodney W. Grimes 			ifam->ifam_index = ifp->if_index;
784df8bae1dSRodney W. Grimes 			ifam->ifam_metric = ifa->ifa_metric;
785df8bae1dSRodney W. Grimes 			ifam->ifam_flags = ifa->ifa_flags;
786df8bae1dSRodney W. Grimes 			ifam->ifam_addrs = info.rti_addrs;
787df8bae1dSRodney W. Grimes 		}
788df8bae1dSRodney W. Grimes 		if ((cmd == RTM_ADD && pass == 2) ||
789df8bae1dSRodney W. Grimes 		    (cmd == RTM_DELETE && pass == 1)) {
790df8bae1dSRodney W. Grimes 			register struct rt_msghdr *rtm;
791df8bae1dSRodney W. Grimes 
792df8bae1dSRodney W. Grimes 			if (rt == 0)
793df8bae1dSRodney W. Grimes 				continue;
794df8bae1dSRodney W. Grimes 			netmask = rt_mask(rt);
795df8bae1dSRodney W. Grimes 			dst = sa = rt_key(rt);
796df8bae1dSRodney W. Grimes 			gate = rt->rt_gateway;
797df8bae1dSRodney W. Grimes 			if ((m = rt_msg1(cmd, &info)) == NULL)
798df8bae1dSRodney W. Grimes 				continue;
799df8bae1dSRodney W. Grimes 			rtm = mtod(m, struct rt_msghdr *);
800df8bae1dSRodney W. Grimes 			rtm->rtm_index = ifp->if_index;
801df8bae1dSRodney W. Grimes 			rtm->rtm_flags |= rt->rt_flags;
802df8bae1dSRodney W. Grimes 			rtm->rtm_errno = error;
803df8bae1dSRodney W. Grimes 			rtm->rtm_addrs = info.rti_addrs;
804df8bae1dSRodney W. Grimes 		}
805df8bae1dSRodney W. Grimes 		route_proto.sp_protocol = sa ? sa->sa_family : 0;
806df8bae1dSRodney W. Grimes 		raw_input(m, &route_proto, &route_src, &route_dst);
807df8bae1dSRodney W. Grimes 	}
808df8bae1dSRodney W. Grimes }
809df8bae1dSRodney W. Grimes 
810477180fbSGarrett Wollman /*
811477180fbSGarrett Wollman  * This is the analogue to the rt_newaddrmsg which performs the same
812477180fbSGarrett Wollman  * function but for multicast group memberhips.  This is easier since
813477180fbSGarrett Wollman  * there is no route state to worry about.
814477180fbSGarrett Wollman  */
815477180fbSGarrett Wollman void
816477180fbSGarrett Wollman rt_newmaddrmsg(cmd, ifma)
817477180fbSGarrett Wollman 	int cmd;
818477180fbSGarrett Wollman 	struct ifmultiaddr *ifma;
819477180fbSGarrett Wollman {
820477180fbSGarrett Wollman 	struct rt_addrinfo info;
821477180fbSGarrett Wollman 	struct mbuf *m = 0;
822477180fbSGarrett Wollman 	struct ifnet *ifp = ifma->ifma_ifp;
823477180fbSGarrett Wollman 	struct ifma_msghdr *ifmam;
824477180fbSGarrett Wollman 
825477180fbSGarrett Wollman 	if (route_cb.any_count == 0)
826477180fbSGarrett Wollman 		return;
827477180fbSGarrett Wollman 
828477180fbSGarrett Wollman 	bzero((caddr_t)&info, sizeof(info));
829477180fbSGarrett Wollman 	ifaaddr = ifma->ifma_addr;
830477180fbSGarrett Wollman 	ifpaddr = ifp->if_addrhead.tqh_first->ifa_addr;
831477180fbSGarrett Wollman 	/*
832477180fbSGarrett Wollman 	 * If a link-layer address is present, present it as a ``gateway''
833477180fbSGarrett Wollman 	 * (similarly to how ARP entries, e.g., are presented).
834477180fbSGarrett Wollman 	 */
835477180fbSGarrett Wollman 	gate = ifma->ifma_lladdr;
836477180fbSGarrett Wollman 	if ((m = rt_msg1(cmd, &info)) == NULL)
837477180fbSGarrett Wollman 		return;
838477180fbSGarrett Wollman 	ifmam = mtod(m, struct ifma_msghdr *);
839477180fbSGarrett Wollman 	ifmam->ifmam_index = ifp->if_index;
840477180fbSGarrett Wollman 	ifmam->ifmam_addrs = info.rti_addrs;
841477180fbSGarrett Wollman 	route_proto.sp_protocol = ifma->ifma_addr->sa_family;
842477180fbSGarrett Wollman 	raw_input(m, &route_proto, &route_src, &route_dst);
843477180fbSGarrett Wollman }
84452041295SPoul-Henning Kamp 
845df8bae1dSRodney W. Grimes /*
846df8bae1dSRodney W. Grimes  * This is used in dumping the kernel table via sysctl().
847df8bae1dSRodney W. Grimes  */
848df8bae1dSRodney W. Grimes int
8494ab32c34SBruce Evans sysctl_dumpentry(rn, vw)
850df8bae1dSRodney W. Grimes 	struct radix_node *rn;
8514ab32c34SBruce Evans 	void *vw;
852df8bae1dSRodney W. Grimes {
8534ab32c34SBruce Evans 	register struct walkarg *w = vw;
854df8bae1dSRodney W. Grimes 	register struct rtentry *rt = (struct rtentry *)rn;
855df8bae1dSRodney W. Grimes 	int error = 0, size;
856df8bae1dSRodney W. Grimes 	struct rt_addrinfo info;
857df8bae1dSRodney W. Grimes 
858df8bae1dSRodney W. Grimes 	if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg))
859df8bae1dSRodney W. Grimes 		return 0;
860df8bae1dSRodney W. Grimes 	bzero((caddr_t)&info, sizeof(info));
861df8bae1dSRodney W. Grimes 	dst = rt_key(rt);
862df8bae1dSRodney W. Grimes 	gate = rt->rt_gateway;
863df8bae1dSRodney W. Grimes 	netmask = rt_mask(rt);
864df8bae1dSRodney W. Grimes 	genmask = rt->rt_genmask;
865df8bae1dSRodney W. Grimes 	size = rt_msg2(RTM_GET, &info, 0, w);
86652041295SPoul-Henning Kamp 	if (w->w_req && w->w_tmem) {
867df8bae1dSRodney W. Grimes 		register struct rt_msghdr *rtm = (struct rt_msghdr *)w->w_tmem;
868df8bae1dSRodney W. Grimes 
869df8bae1dSRodney W. Grimes 		rtm->rtm_flags = rt->rt_flags;
870df8bae1dSRodney W. Grimes 		rtm->rtm_use = rt->rt_use;
871df8bae1dSRodney W. Grimes 		rtm->rtm_rmx = rt->rt_rmx;
872df8bae1dSRodney W. Grimes 		rtm->rtm_index = rt->rt_ifp->if_index;
873df8bae1dSRodney W. Grimes 		rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
874df8bae1dSRodney W. Grimes 		rtm->rtm_addrs = info.rti_addrs;
87552041295SPoul-Henning Kamp 		error = SYSCTL_OUT(w->w_req, (caddr_t)rtm, size);
87652041295SPoul-Henning Kamp 		return (error);
877df8bae1dSRodney W. Grimes 	}
878df8bae1dSRodney W. Grimes 	return (error);
879df8bae1dSRodney W. Grimes }
880df8bae1dSRodney W. Grimes 
881df8bae1dSRodney W. Grimes int
882df8bae1dSRodney W. Grimes sysctl_iflist(af, w)
883df8bae1dSRodney W. Grimes 	int	af;
884df8bae1dSRodney W. Grimes 	register struct	walkarg *w;
885df8bae1dSRodney W. Grimes {
886df8bae1dSRodney W. Grimes 	register struct ifnet *ifp;
887df8bae1dSRodney W. Grimes 	register struct ifaddr *ifa;
888df8bae1dSRodney W. Grimes 	struct	rt_addrinfo info;
889df8bae1dSRodney W. Grimes 	int	len, error = 0;
890df8bae1dSRodney W. Grimes 
891df8bae1dSRodney W. Grimes 	bzero((caddr_t)&info, sizeof(info));
89229412182SGarrett Wollman 	for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) {
893df8bae1dSRodney W. Grimes 		if (w->w_arg && w->w_arg != ifp->if_index)
894df8bae1dSRodney W. Grimes 			continue;
89559562606SGarrett Wollman 		ifa = ifp->if_addrhead.tqh_first;
896df8bae1dSRodney W. Grimes 		ifpaddr = ifa->ifa_addr;
897df8bae1dSRodney W. Grimes 		len = rt_msg2(RTM_IFINFO, &info, (caddr_t)0, w);
898df8bae1dSRodney W. Grimes 		ifpaddr = 0;
89952041295SPoul-Henning Kamp 		if (w->w_req && w->w_tmem) {
900df8bae1dSRodney W. Grimes 			register struct if_msghdr *ifm;
901df8bae1dSRodney W. Grimes 
902df8bae1dSRodney W. Grimes 			ifm = (struct if_msghdr *)w->w_tmem;
903df8bae1dSRodney W. Grimes 			ifm->ifm_index = ifp->if_index;
9042624cf89SGarrett Wollman 			ifm->ifm_flags = (u_short)ifp->if_flags;
905df8bae1dSRodney W. Grimes 			ifm->ifm_data = ifp->if_data;
906df8bae1dSRodney W. Grimes 			ifm->ifm_addrs = info.rti_addrs;
90752041295SPoul-Henning Kamp 			error = SYSCTL_OUT(w->w_req,(caddr_t)ifm, len);
908df440948SPoul-Henning Kamp 			if (error)
909df8bae1dSRodney W. Grimes 				return (error);
910df8bae1dSRodney W. Grimes 		}
91159562606SGarrett Wollman 		while ((ifa = ifa->ifa_link.tqe_next) != 0) {
912df8bae1dSRodney W. Grimes 			if (af && af != ifa->ifa_addr->sa_family)
913df8bae1dSRodney W. Grimes 				continue;
91475c13541SPoul-Henning Kamp 			if (curproc->p_prison && prison_if(curproc, ifa->ifa_addr))
91575c13541SPoul-Henning Kamp 				continue;
916df8bae1dSRodney W. Grimes 			ifaaddr = ifa->ifa_addr;
917df8bae1dSRodney W. Grimes 			netmask = ifa->ifa_netmask;
918df8bae1dSRodney W. Grimes 			brdaddr = ifa->ifa_dstaddr;
919df8bae1dSRodney W. Grimes 			len = rt_msg2(RTM_NEWADDR, &info, 0, w);
92052041295SPoul-Henning Kamp 			if (w->w_req && w->w_tmem) {
921df8bae1dSRodney W. Grimes 				register struct ifa_msghdr *ifam;
922df8bae1dSRodney W. Grimes 
923df8bae1dSRodney W. Grimes 				ifam = (struct ifa_msghdr *)w->w_tmem;
924df8bae1dSRodney W. Grimes 				ifam->ifam_index = ifa->ifa_ifp->if_index;
925df8bae1dSRodney W. Grimes 				ifam->ifam_flags = ifa->ifa_flags;
926df8bae1dSRodney W. Grimes 				ifam->ifam_metric = ifa->ifa_metric;
927df8bae1dSRodney W. Grimes 				ifam->ifam_addrs = info.rti_addrs;
92852041295SPoul-Henning Kamp 				error = SYSCTL_OUT(w->w_req, w->w_tmem, len);
929df440948SPoul-Henning Kamp 				if (error)
930df8bae1dSRodney W. Grimes 					return (error);
931df8bae1dSRodney W. Grimes 			}
932df8bae1dSRodney W. Grimes 		}
933df8bae1dSRodney W. Grimes 		ifaaddr = netmask = brdaddr = 0;
934df8bae1dSRodney W. Grimes 	}
935df8bae1dSRodney W. Grimes 	return (0);
936df8bae1dSRodney W. Grimes }
937df8bae1dSRodney W. Grimes 
93852041295SPoul-Henning Kamp static int
93952041295SPoul-Henning Kamp sysctl_rtsock SYSCTL_HANDLER_ARGS
940df8bae1dSRodney W. Grimes {
94152041295SPoul-Henning Kamp 	int	*name = (int *)arg1;
94252041295SPoul-Henning Kamp 	u_int	namelen = arg2;
943df8bae1dSRodney W. Grimes 	register struct radix_node_head *rnh;
944df8bae1dSRodney W. Grimes 	int	i, s, error = EINVAL;
945df8bae1dSRodney W. Grimes 	u_char  af;
946df8bae1dSRodney W. Grimes 	struct	walkarg w;
947df8bae1dSRodney W. Grimes 
94852041295SPoul-Henning Kamp 	name ++;
94952041295SPoul-Henning Kamp 	namelen--;
95052041295SPoul-Henning Kamp 	if (req->newptr)
951df8bae1dSRodney W. Grimes 		return (EPERM);
952df8bae1dSRodney W. Grimes 	if (namelen != 3)
953df8bae1dSRodney W. Grimes 		return (EINVAL);
954df8bae1dSRodney W. Grimes 	af = name[0];
955df8bae1dSRodney W. Grimes 	Bzero(&w, sizeof(w));
956df8bae1dSRodney W. Grimes 	w.w_op = name[1];
957df8bae1dSRodney W. Grimes 	w.w_arg = name[2];
95852041295SPoul-Henning Kamp 	w.w_req = req;
959df8bae1dSRodney W. Grimes 
960df8bae1dSRodney W. Grimes 	s = splnet();
961df8bae1dSRodney W. Grimes 	switch (w.w_op) {
962df8bae1dSRodney W. Grimes 
963df8bae1dSRodney W. Grimes 	case NET_RT_DUMP:
964df8bae1dSRodney W. Grimes 	case NET_RT_FLAGS:
965df8bae1dSRodney W. Grimes 		for (i = 1; i <= AF_MAX; i++)
966df8bae1dSRodney W. Grimes 			if ((rnh = rt_tables[i]) && (af == 0 || af == i) &&
967df8bae1dSRodney W. Grimes 			    (error = rnh->rnh_walktree(rnh,
968df8bae1dSRodney W. Grimes 							sysctl_dumpentry, &w)))
969df8bae1dSRodney W. Grimes 				break;
970df8bae1dSRodney W. Grimes 		break;
971df8bae1dSRodney W. Grimes 
972df8bae1dSRodney W. Grimes 	case NET_RT_IFLIST:
973df8bae1dSRodney W. Grimes 		error = sysctl_iflist(af, &w);
974df8bae1dSRodney W. Grimes 	}
975df8bae1dSRodney W. Grimes 	splx(s);
976df8bae1dSRodney W. Grimes 	if (w.w_tmem)
977df8bae1dSRodney W. Grimes 		free(w.w_tmem, M_RTABLE);
978df8bae1dSRodney W. Grimes 	return (error);
979df8bae1dSRodney W. Grimes }
980df8bae1dSRodney W. Grimes 
98152041295SPoul-Henning Kamp SYSCTL_NODE(_net, PF_ROUTE, routetable, CTLFLAG_RD, sysctl_rtsock, "");
98252041295SPoul-Henning Kamp 
983df8bae1dSRodney W. Grimes /*
984df8bae1dSRodney W. Grimes  * Definitions of protocols supported in the ROUTE domain.
985df8bae1dSRodney W. Grimes  */
986df8bae1dSRodney W. Grimes 
987df8bae1dSRodney W. Grimes extern struct domain routedomain;		/* or at least forward */
988df8bae1dSRodney W. Grimes 
98952041295SPoul-Henning Kamp static struct protosw routesw[] = {
990df8bae1dSRodney W. Grimes { SOCK_RAW,	&routedomain,	0,		PR_ATOMIC|PR_ADDR,
9916ddbf1e2SGary Palmer   0,		route_output,	raw_ctlinput,	0,
992a29f300eSGarrett Wollman   0,
993a29f300eSGarrett Wollman   raw_init,	0,		0,		0,
994a29f300eSGarrett Wollman   &route_usrreqs
995df8bae1dSRodney W. Grimes }
996df8bae1dSRodney W. Grimes };
997df8bae1dSRodney W. Grimes 
99852041295SPoul-Henning Kamp static struct domain routedomain =
999df8bae1dSRodney W. Grimes     { PF_ROUTE, "route", route_init, 0, 0,
1000df8bae1dSRodney W. Grimes       routesw, &routesw[sizeof(routesw)/sizeof(routesw[0])] };
100178a82810SGarrett Wollman 
1002748e0b0aSGarrett Wollman DOMAIN_SET(route);
1003