Changeset View
Standalone View
sys/net/if.c
Show First 20 Lines • Show All 2,911 Lines • ▼ Show 20 Lines | struct ifconf32 { | ||||
int32_t ifc_len; | int32_t ifc_len; | ||||
union { | union { | ||||
uint32_t ifcu_buf; | uint32_t ifcu_buf; | ||||
uint32_t ifcu_req; | uint32_t ifcu_req; | ||||
} ifc_ifcu; | } ifc_ifcu; | ||||
}; | }; | ||||
#define SIOCGIFCONF32 _IOWR('i', 36, struct ifconf32) | #define SIOCGIFCONF32 _IOWR('i', 36, struct ifconf32) | ||||
#endif | #endif | ||||
#ifdef COMPAT_FREEBSD32 | |||||
static void | |||||
ifmr_init(struct ifmediareq *ifmr, caddr_t data) | |||||
{ | |||||
struct ifmediareq32 *ifmr32; | |||||
ifmr32 = (struct ifmediareq32 *)data; | |||||
memcpy(ifmr->ifm_name, ifmr32->ifm_name, | |||||
sizeof(ifmr->ifm_name)); | |||||
ifmr->ifm_current = ifmr32->ifm_current; | |||||
ifmr->ifm_mask = ifmr32->ifm_mask; | |||||
ifmr->ifm_status = ifmr32->ifm_status; | |||||
ifmr->ifm_active = ifmr32->ifm_active; | |||||
ifmr->ifm_count = ifmr32->ifm_count; | |||||
ifmr->ifm_ulist = (int *)(uintptr_t)ifmr32->ifm_ulist; | |||||
} | |||||
static void | |||||
ifmr_update(const struct ifmediareq *ifmr, caddr_t data) | |||||
{ | |||||
struct ifmediareq32 *ifmr32; | |||||
ifmr32 = (struct ifmediareq32 *)data; | |||||
ifmr32->ifm_current = ifmr->ifm_current; | |||||
ifmr32->ifm_mask = ifmr->ifm_mask; | |||||
ifmr32->ifm_status = ifmr->ifm_status; | |||||
ifmr32->ifm_active = ifmr->ifm_active; | |||||
ifmr32->ifm_count = ifmr->ifm_count; | |||||
} | |||||
#endif | |||||
/* | /* | ||||
* Interface ioctls. | * Interface ioctls. | ||||
*/ | */ | ||||
int | int | ||||
ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) | ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) | ||||
{ | { | ||||
#ifdef COMPAT_FREEBSD32 | #ifdef COMPAT_FREEBSD32 | ||||
caddr_t saved_data = NULL; | union { | ||||
kib: Why do you need the initialization there? | |||||
Done Inline Actions
Actually, after further thinking, I could just always initialize these to 'cmd' and 'data'. It doesn't hurt for them to be set for non-compat ioctls (the switch at the end just wouldn't match anything for non-compat ioctls). I can do that down below before the first switch though rather than doing it during assignment, though doing it during assignment here would actually be consistent with Warner's recent language about read-only variables that are never changed in a block. jhb: > Why do you need the initialization there?
Actually, after further thinking, I could just… | |||||
struct ifconf ifc; | |||||
struct ifmediareq ifmr; | struct ifmediareq ifmr; | ||||
struct ifmediareq *ifmrp = NULL; | } thunk; | ||||
caddr_t saved_data; | |||||
u_long saved_cmd; | |||||
struct ifconf32 *ifc32; | |||||
struct ifmediareq32 *ifmr32; | |||||
Not Done Inline Actionsthis assumes that '0' is not a value for some of ioctls. I think we need something along the lines of _IOC_INVALID (IOC_VOID | IOC_INOUT) in ioccom.h kib: this assumes that '0' is not a value for some of ioctls.
I think we need something along the… | |||||
Done Inline Actions
Hmmm, I would not oppose such a value, though I think 0 is in fact invalid as an ioctl value. jhb: > this assumes that '0' is not a value for some of ioctls.
>
> I think we need something along… | |||||
#endif | #endif | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
struct ifreq *ifr; | struct ifreq *ifr; | ||||
int error; | int error; | ||||
int oif_flags; | int oif_flags; | ||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
bool shutdown; | bool shutdown; | ||||
#endif | #endif | ||||
CURVNET_SET(so->so_vnet); | CURVNET_SET(so->so_vnet); | ||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
/* Make sure the VNET is stable. */ | /* Make sure the VNET is stable. */ | ||||
shutdown = VNET_IS_SHUTTING_DOWN(so->so_vnet); | shutdown = VNET_IS_SHUTTING_DOWN(so->so_vnet); | ||||
if (shutdown) { | if (shutdown) { | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
#endif | #endif | ||||
switch (cmd) { | |||||
case SIOCGIFCONF: | |||||
error = ifconf(cmd, data); | |||||
goto out_noref; | |||||
#ifdef COMPAT_FREEBSD32 | #ifdef COMPAT_FREEBSD32 | ||||
saved_cmd = cmd; | |||||
saved_data = data; | |||||
switch (cmd) { | |||||
case SIOCGIFCONF32: | case SIOCGIFCONF32: | ||||
{ | |||||
struct ifconf32 *ifc32; | |||||
struct ifconf ifc; | |||||
ifc32 = (struct ifconf32 *)data; | ifc32 = (struct ifconf32 *)data; | ||||
ifc.ifc_len = ifc32->ifc_len; | thunk.ifc.ifc_len = ifc32->ifc_len; | ||||
ifc.ifc_buf = PTRIN(ifc32->ifc_buf); | thunk.ifc.ifc_buf = PTRIN(ifc32->ifc_buf); | ||||
data = (caddr_t)&thunk.ifc; | |||||
error = ifconf(SIOCGIFCONF, (void *)&ifc); | cmd = SIOCGIFCONF; | ||||
if (error == 0) | break; | ||||
ifc32->ifc_len = ifc.ifc_len; | |||||
goto out_noref; | |||||
} | |||||
#endif | |||||
} | |||||
#ifdef COMPAT_FREEBSD32 | |||||
switch (cmd) { | |||||
case SIOCGIFMEDIA32: | case SIOCGIFMEDIA32: | ||||
case SIOCGIFXMEDIA32: | case SIOCGIFXMEDIA32: | ||||
ifmrp = &ifmr; | ifmr32 = (struct ifmediareq32 *)data; | ||||
ifmr_init(ifmrp, data); | memcpy(thunk.ifmr.ifm_name, ifmr32->ifm_name, | ||||
sizeof(thunk.ifmr.ifm_name)); | |||||
thunk.ifmr.ifm_current = ifmr32->ifm_current; | |||||
thunk.ifmr.ifm_mask = ifmr32->ifm_mask; | |||||
thunk.ifmr.ifm_status = ifmr32->ifm_status; | |||||
thunk.ifmr.ifm_active = ifmr32->ifm_active; | |||||
thunk.ifmr.ifm_count = ifmr32->ifm_count; | |||||
thunk.ifmr.ifm_ulist = PTRIN(ifmr32->ifm_ulist); | |||||
data = (caddr_t)&thunk.ifmr; | |||||
cmd = _IOC_NEWTYPE(cmd, struct ifmediareq); | cmd = _IOC_NEWTYPE(cmd, struct ifmediareq); | ||||
saved_data = data; | break; | ||||
data = (caddr_t)ifmrp; | |||||
} | } | ||||
#endif | #endif | ||||
Done Inline ActionsI suppose I could add a default case here which initializes saved_cmd and saved_data. jhb: I suppose I could add a default case here which initializes `saved_cmd` and `saved_data`. | |||||
switch (cmd) { | |||||
case SIOCGIFCONF: | |||||
error = ifconf(cmd, data); | |||||
goto out_noref; | |||||
} | |||||
ifr = (struct ifreq *)data; | ifr = (struct ifreq *)data; | ||||
switch (cmd) { | switch (cmd) { | ||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
case SIOCSIFRVNET: | case SIOCSIFRVNET: | ||||
error = priv_check(td, PRIV_NET_SETIFVNET); | error = priv_check(td, PRIV_NET_SETIFVNET); | ||||
if (error == 0) | if (error == 0) | ||||
error = if_vmove_reclaim(td, ifr->ifr_name, | error = if_vmove_reclaim(td, ifr->ifr_name, | ||||
ifr->ifr_jid); | ifr->ifr_jid); | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | #ifdef INET6 | ||||
if (ifp->if_flags & IFF_UP) | if (ifp->if_flags & IFF_UP) | ||||
in6_if_up(ifp); | in6_if_up(ifp); | ||||
#endif | #endif | ||||
} | } | ||||
out_ref: | out_ref: | ||||
if_rele(ifp); | if_rele(ifp); | ||||
out_noref: | out_noref: | ||||
CURVNET_RESTORE(); | |||||
#ifdef COMPAT_FREEBSD32 | #ifdef COMPAT_FREEBSD32 | ||||
if (ifmrp != NULL) { | if (error != 0) | ||||
KASSERT((cmd == SIOCGIFMEDIA || cmd == SIOCGIFXMEDIA), | return (error); | ||||
("ifmrp non-NULL, but cmd is not an ifmedia req 0x%lx", | switch (saved_cmd) { | ||||
cmd)); | case SIOCGIFCONF32: | ||||
data = saved_data; | ifc32->ifc_len = thunk.ifc.ifc_len; | ||||
Done Inline Actionsifc32 is already initialized kib: ifc32 is already initialized | |||||
Done Inline ActionsWhile it is, I don't think the compiler is smart enough to realize that it is. jhb: While it is, I don't think the compiler is smart enough to realize that it is. | |||||
Done Inline ActionsTurns out, GCC and clang are both fine with this, so I'll drop these. jhb: Turns out, GCC and clang are both fine with this, so I'll drop these. | |||||
ifmr_update(ifmrp, data); | break; | ||||
case SIOCGIFMEDIA32: | |||||
case SIOCGIFXMEDIA32: | |||||
ifmr32->ifm_current = thunk.ifmr.ifm_current; | |||||
ifmr32->ifm_mask = thunk.ifmr.ifm_mask; | |||||
Done Inline Actionsifmr32 is already initialized, no? kib: ifmr32 is already initialized, no? | |||||
ifmr32->ifm_status = thunk.ifmr.ifm_status; | |||||
ifmr32->ifm_active = thunk.ifmr.ifm_active; | |||||
ifmr32->ifm_count = thunk.ifmr.ifm_count; | |||||
break; | |||||
Done Inline Actionserror != 0 kib: error != 0 | |||||
} | } | ||||
#endif | #endif | ||||
CURVNET_RESTORE(); | |||||
return (error); | return (error); | ||||
} | } | ||||
/* | /* | ||||
* The code common to handling reference counted flags, | * The code common to handling reference counted flags, | ||||
* e.g., in ifpromisc() and if_allmulti(). | * e.g., in ifpromisc() and if_allmulti(). | ||||
* The "pflag" argument can specify a permanent mode flag to check, | * The "pflag" argument can specify a permanent mode flag to check, | ||||
* such as IFF_PPROMISC for promiscuous mode; should be 0 if none. | * such as IFF_PPROMISC for promiscuous mode; should be 0 if none. | ||||
▲ Show 20 Lines • Show All 1,487 Lines • Show Last 20 Lines |
Why do you need the initialization there?