Mon Jul 7 10:18:20 2014 UTC ()
return EOPNOTSUPP for pr_stat instead of returning success since we
don't fill in the struct stat passed to us.


(rtr)
diff -r1.150 -r1.151 src/sys/net/rtsock.c

cvs diff -r1.150 -r1.151 src/sys/net/rtsock.c (switch to unified diff)

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