if.c (331722) | if.c (332281) |
---|---|
1/*- 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if.c 8.5 (Berkeley) 1/9/95 | 1/*- 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if.c 8.5 (Berkeley) 1/9/95 |
30 * $FreeBSD: stable/11/sys/net/if.c 331722 2018-03-29 02:50:57Z eadler $ | 30 * $FreeBSD: stable/11/sys/net/if.c 332281 2018-04-08 15:52:32Z brooks $ |
31 */ 32 33#include "opt_compat.h" 34#include "opt_inet6.h" 35#include "opt_inet.h" 36 37#include <sys/param.h> 38#include <sys/types.h> --- 11 unchanged lines hidden (view full) --- 50#include <sys/kernel.h> 51#include <sys/lock.h> 52#include <sys/refcount.h> 53#include <sys/module.h> 54#include <sys/rwlock.h> 55#include <sys/sockio.h> 56#include <sys/syslog.h> 57#include <sys/sysctl.h> | 31 */ 32 33#include "opt_compat.h" 34#include "opt_inet6.h" 35#include "opt_inet.h" 36 37#include <sys/param.h> 38#include <sys/types.h> --- 11 unchanged lines hidden (view full) --- 50#include <sys/kernel.h> 51#include <sys/lock.h> 52#include <sys/refcount.h> 53#include <sys/module.h> 54#include <sys/rwlock.h> 55#include <sys/sockio.h> 56#include <sys/syslog.h> 57#include <sys/sysctl.h> |
58#include <sys/sysent.h> |
|
58#include <sys/taskqueue.h> 59#include <sys/domain.h> 60#include <sys/jail.h> 61#include <sys/priv.h> 62 63#include <machine/stdarg.h> 64#include <vm/uma.h> 65 --- 26 unchanged lines hidden (view full) --- 92#endif /* INET6 */ 93#endif /* INET || INET6 */ 94 95#include <security/mac/mac_framework.h> 96 97#ifdef COMPAT_FREEBSD32 98#include <sys/mount.h> 99#include <compat/freebsd32/freebsd32.h> | 59#include <sys/taskqueue.h> 60#include <sys/domain.h> 61#include <sys/jail.h> 62#include <sys/priv.h> 63 64#include <machine/stdarg.h> 65#include <vm/uma.h> 66 --- 26 unchanged lines hidden (view full) --- 93#endif /* INET6 */ 94#endif /* INET || INET6 */ 95 96#include <security/mac/mac_framework.h> 97 98#ifdef COMPAT_FREEBSD32 99#include <sys/mount.h> 100#include <compat/freebsd32/freebsd32.h> |
101 102struct ifreq_buffer32 { 103 uint32_t length; /* (size_t) */ 104 uint32_t buffer; /* (void *) */ 105}; 106 107/* 108 * Interface request structure used for socket 109 * ioctl's. All interface ioctl's must have parameter 110 * definitions which begin with ifr_name. The 111 * remainder may be interface specific. 112 */ 113struct ifreq32 { 114 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 115 union { 116 struct sockaddr ifru_addr; 117 struct sockaddr ifru_dstaddr; 118 struct sockaddr ifru_broadaddr; 119 struct ifreq_buffer32 ifru_buffer; 120 short ifru_flags[2]; 121 short ifru_index; 122 int ifru_jid; 123 int ifru_metric; 124 int ifru_mtu; 125 int ifru_phys; 126 int ifru_media; 127 uint32_t ifru_data; 128 int ifru_cap[2]; 129 u_int ifru_fib; 130 u_char ifru_vlan_pcp; 131 } ifr_ifru; 132}; 133CTASSERT(sizeof(struct ifreq) == sizeof(struct ifreq32)); 134CTASSERT(__offsetof(struct ifreq, ifr_ifru) == 135 __offsetof(struct ifreq32, ifr_ifru)); |
|
100#endif 101 | 136#endif 137 |
138union ifreq_union { 139 struct ifreq ifr; 140#ifdef COMPAT_FREEBSD32 141 struct ifreq32 ifr32; 142#endif 143}; 144 |
|
102SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 103SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); 104 105SYSCTL_INT(_net_link, OID_AUTO, ifqmaxlen, CTLFLAG_RDTUN, 106 &ifqmaxlen, 0, "max send queue size"); 107 108/* Log link state change events */ 109static int log_link_state_change = 1; --- 2187 unchanged lines hidden (view full) --- 2297 TAILQ_FOREACH(ifp, &V_ifnet, if_link) { 2298 if (strncmp(name, ifp->if_xname, IFNAMSIZ) == 0) 2299 break; 2300 } 2301 IFNET_RUNLOCK_NOSLEEP(); 2302 return (ifp); 2303} 2304 | 145SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 146SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); 147 148SYSCTL_INT(_net_link, OID_AUTO, ifqmaxlen, CTLFLAG_RDTUN, 149 &ifqmaxlen, 0, "max send queue size"); 150 151/* Log link state change events */ 152static int log_link_state_change = 1; --- 2187 unchanged lines hidden (view full) --- 2340 TAILQ_FOREACH(ifp, &V_ifnet, if_link) { 2341 if (strncmp(name, ifp->if_xname, IFNAMSIZ) == 0) 2342 break; 2343 } 2344 IFNET_RUNLOCK_NOSLEEP(); 2345 return (ifp); 2346} 2347 |
2348static void * 2349ifr_buffer_get_buffer(void *data) 2350{ 2351 union ifreq_union *ifrup; 2352 2353 ifrup = data; 2354#ifdef COMPAT_FREEBSD32 2355 if (SV_CURPROC_FLAG(SV_ILP32)) 2356 return ((void *)(uintptr_t) 2357 ifrup->ifr32.ifr_ifru.ifru_buffer.buffer); 2358#endif 2359 return (ifrup->ifr.ifr_ifru.ifru_buffer.buffer); 2360} 2361 2362static void 2363ifr_buffer_set_buffer_null(void *data) 2364{ 2365 union ifreq_union *ifrup; 2366 2367 ifrup = data; 2368#ifdef COMPAT_FREEBSD32 2369 if (SV_CURPROC_FLAG(SV_ILP32)) 2370 ifrup->ifr32.ifr_ifru.ifru_buffer.buffer = 0; 2371 else 2372#endif 2373 ifrup->ifr.ifr_ifru.ifru_buffer.buffer = NULL; 2374} 2375 2376static size_t 2377ifr_buffer_get_length(void *data) 2378{ 2379 union ifreq_union *ifrup; 2380 2381 ifrup = data; 2382#ifdef COMPAT_FREEBSD32 2383 if (SV_CURPROC_FLAG(SV_ILP32)) 2384 return (ifrup->ifr32.ifr_ifru.ifru_buffer.length); 2385#endif 2386 return (ifrup->ifr.ifr_ifru.ifru_buffer.length); 2387} 2388 2389static void 2390ifr_buffer_set_length(void *data, size_t len) 2391{ 2392 union ifreq_union *ifrup; 2393 2394 ifrup = data; 2395#ifdef COMPAT_FREEBSD32 2396 if (SV_CURPROC_FLAG(SV_ILP32)) 2397 ifrup->ifr32.ifr_ifru.ifru_buffer.length = len; 2398 else 2399#endif 2400 ifrup->ifr.ifr_ifru.ifru_buffer.length = len; 2401} 2402 |
|
2305/* 2306 * Hardware specific interface ioctls. 2307 */ 2308static int 2309ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) 2310{ 2311 struct ifreq *ifr; 2312 int error = 0, do_ifup = 0; --- 44 unchanged lines hidden (view full) --- 2357 case SIOCGIFDESCR: 2358 error = 0; 2359 sx_slock(&ifdescr_sx); 2360 if (ifp->if_description == NULL) 2361 error = ENOMSG; 2362 else { 2363 /* space for terminating nul */ 2364 descrlen = strlen(ifp->if_description) + 1; | 2403/* 2404 * Hardware specific interface ioctls. 2405 */ 2406static int 2407ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) 2408{ 2409 struct ifreq *ifr; 2410 int error = 0, do_ifup = 0; --- 44 unchanged lines hidden (view full) --- 2455 case SIOCGIFDESCR: 2456 error = 0; 2457 sx_slock(&ifdescr_sx); 2458 if (ifp->if_description == NULL) 2459 error = ENOMSG; 2460 else { 2461 /* space for terminating nul */ 2462 descrlen = strlen(ifp->if_description) + 1; |
2365 if (ifr->ifr_buffer.length < descrlen) 2366 ifr->ifr_buffer.buffer = NULL; | 2463 if (ifr_buffer_get_length(ifr) < descrlen) 2464 ifr_buffer_set_buffer_null(ifr); |
2367 else 2368 error = copyout(ifp->if_description, | 2465 else 2466 error = copyout(ifp->if_description, |
2369 ifr->ifr_buffer.buffer, descrlen); 2370 ifr->ifr_buffer.length = descrlen; | 2467 ifr_buffer_get_buffer(ifr), descrlen); 2468 ifr_buffer_set_length(ifr, descrlen); |
2371 } 2372 sx_sunlock(&ifdescr_sx); 2373 break; 2374 2375 case SIOCSIFDESCR: 2376 error = priv_check(td, PRIV_NET_SETIFDESCR); 2377 if (error) 2378 return (error); 2379 2380 /* 2381 * Copy only (length-1) bytes to make sure that 2382 * if_description is always nul terminated. The 2383 * length parameter is supposed to count the 2384 * terminating nul in. 2385 */ | 2469 } 2470 sx_sunlock(&ifdescr_sx); 2471 break; 2472 2473 case SIOCSIFDESCR: 2474 error = priv_check(td, PRIV_NET_SETIFDESCR); 2475 if (error) 2476 return (error); 2477 2478 /* 2479 * Copy only (length-1) bytes to make sure that 2480 * if_description is always nul terminated. The 2481 * length parameter is supposed to count the 2482 * terminating nul in. 2483 */ |
2386 if (ifr->ifr_buffer.length > ifdescr_maxlen) | 2484 if (ifr_buffer_get_length(ifr) > ifdescr_maxlen) |
2387 return (ENAMETOOLONG); | 2485 return (ENAMETOOLONG); |
2388 else if (ifr->ifr_buffer.length == 0) | 2486 else if (ifr_buffer_get_length(ifr) == 0) |
2389 descrbuf = NULL; 2390 else { | 2487 descrbuf = NULL; 2488 else { |
2391 descrbuf = malloc(ifr->ifr_buffer.length, M_IFDESCR, 2392 M_WAITOK | M_ZERO); 2393 error = copyin(ifr->ifr_buffer.buffer, descrbuf, 2394 ifr->ifr_buffer.length - 1); | 2489 descrbuf = malloc(ifr_buffer_get_length(ifr), 2490 M_IFDESCR, M_WAITOK | M_ZERO); 2491 error = copyin(ifr_buffer_get_buffer(ifr), descrbuf, 2492 ifr_buffer_get_length(ifr) - 1); |
2395 if (error) { 2396 free(descrbuf, M_IFDESCR); 2397 break; 2398 } 2399 } 2400 2401 sx_xlock(&ifdescr_sx); 2402 odescrbuf = ifp->if_description; --- 1802 unchanged lines hidden --- | 2493 if (error) { 2494 free(descrbuf, M_IFDESCR); 2495 break; 2496 } 2497 } 2498 2499 sx_xlock(&ifdescr_sx); 2500 odescrbuf = ifp->if_description; --- 1802 unchanged lines hidden --- |