Changeset View
Changeset View
Standalone View
Standalone View
sys/net/if.c
Show First 20 Lines • Show All 268 Lines • ▼ Show 20 Lines | |||||
static void do_link_state_change(void *, int); | static void do_link_state_change(void *, int); | ||||
static int if_getgroup(struct ifgroupreq *, struct ifnet *); | static int if_getgroup(struct ifgroupreq *, struct ifnet *); | ||||
static int if_getgroupmembers(struct ifgroupreq *); | static int if_getgroupmembers(struct ifgroupreq *); | ||||
static void if_delgroups(struct ifnet *); | static void if_delgroups(struct ifnet *); | ||||
static void if_attach_internal(struct ifnet *, int, struct if_clone *); | static void if_attach_internal(struct ifnet *, int, struct if_clone *); | ||||
static int if_detach_internal(struct ifnet *, int, struct if_clone **); | static int if_detach_internal(struct ifnet *, int, struct if_clone **); | ||||
static void if_siocaddmulti(void *, int); | static void if_siocaddmulti(void *, int); | ||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
static void if_vmove(struct ifnet *, struct vnet *); | static int if_vmove(struct ifnet *, struct vnet *); | ||||
#endif | #endif | ||||
#ifdef INET6 | #ifdef INET6 | ||||
/* | /* | ||||
* XXX: declare here to avoid to include many inet6 related files.. | * XXX: declare here to avoid to include many inet6 related files.. | ||||
* should be more generalized? | * should be more generalized? | ||||
*/ | */ | ||||
extern void nd6_setmtu(struct ifnet *); | extern void nd6_setmtu(struct ifnet *); | ||||
▲ Show 20 Lines • Show All 966 Lines • ▼ Show 20 Lines | |||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
/* | /* | ||||
* if_vmove() performs a limited version of if_detach() in current | * if_vmove() performs a limited version of if_detach() in current | ||||
* vnet and if_attach()es the ifnet to the vnet specified as 2nd arg. | * vnet and if_attach()es the ifnet to the vnet specified as 2nd arg. | ||||
* An attempt is made to shrink if_index in current vnet, find an | * An attempt is made to shrink if_index in current vnet, find an | ||||
* unused if_index in target vnet and calls if_grow() if necessary, | * unused if_index in target vnet and calls if_grow() if necessary, | ||||
* and finally find an unused if_xname for the target vnet. | * and finally find an unused if_xname for the target vnet. | ||||
*/ | */ | ||||
static void | static int | ||||
if_vmove(struct ifnet *ifp, struct vnet *new_vnet) | if_vmove(struct ifnet *ifp, struct vnet *new_vnet) | ||||
{ | { | ||||
struct if_clone *ifc; | struct if_clone *ifc; | ||||
#ifdef DEV_BPF | #ifdef DEV_BPF | ||||
u_int bif_dlt, bif_hdrlen; | u_int bif_dlt, bif_hdrlen; | ||||
#endif | #endif | ||||
void *old; | void *old; | ||||
int rc; | int rc; | ||||
Show All 9 Lines | #endif | ||||
/* | /* | ||||
* Detach from current vnet, but preserve LLADDR info, do not | * Detach from current vnet, but preserve LLADDR info, do not | ||||
* mark as dead etc. so that the ifnet can be reattached later. | * mark as dead etc. so that the ifnet can be reattached later. | ||||
* If we cannot find it, we lost the race to someone else. | * If we cannot find it, we lost the race to someone else. | ||||
*/ | */ | ||||
rc = if_detach_internal(ifp, 1, &ifc); | rc = if_detach_internal(ifp, 1, &ifc); | ||||
if (rc != 0) | if (rc != 0) | ||||
return; | return (rc); | ||||
/* | /* | ||||
* Unlink the ifnet from ifindex_table[] in current vnet, and shrink | * Unlink the ifnet from ifindex_table[] in current vnet, and shrink | ||||
* the if_index for that vnet if possible. | * the if_index for that vnet if possible. | ||||
* | * | ||||
* NOTE: IFNET_WLOCK/IFNET_WUNLOCK() are assumed to be unvirtualized, | * NOTE: IFNET_WLOCK/IFNET_WUNLOCK() are assumed to be unvirtualized, | ||||
* or we'd lock on one vnet and unlock on another. | * or we'd lock on one vnet and unlock on another. | ||||
*/ | */ | ||||
Show All 27 Lines | restart: | ||||
if_attach_internal(ifp, 1, ifc); | if_attach_internal(ifp, 1, ifc); | ||||
#ifdef DEV_BPF | #ifdef DEV_BPF | ||||
if (ifp->if_bpf == NULL) | if (ifp->if_bpf == NULL) | ||||
bpfattach(ifp, bif_dlt, bif_hdrlen); | bpfattach(ifp, bif_dlt, bif_hdrlen); | ||||
#endif | #endif | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
return (0); | |||||
} | } | ||||
/* | /* | ||||
* Move an ifnet to or from another child prison/vnet, specified by the jail id. | * Move an ifnet to or from another child prison/vnet, specified by the jail id. | ||||
*/ | */ | ||||
static int | static int | ||||
if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid) | if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid) | ||||
{ | { | ||||
struct prison *pr; | struct prison *pr; | ||||
struct ifnet *difp; | struct ifnet *difp; | ||||
int error; | |||||
/* Try to find the prison within our visibility. */ | /* Try to find the prison within our visibility. */ | ||||
sx_slock(&allprison_lock); | sx_slock(&allprison_lock); | ||||
pr = prison_find_child(td->td_ucred->cr_prison, jid); | pr = prison_find_child(td->td_ucred->cr_prison, jid); | ||||
sx_sunlock(&allprison_lock); | sx_sunlock(&allprison_lock); | ||||
if (pr == NULL) | if (pr == NULL) | ||||
return (ENXIO); | return (ENXIO); | ||||
prison_hold_locked(pr); | prison_hold_locked(pr); | ||||
Show All 19 Lines | if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid) | ||||
if (ifp->if_vnet->vnet_shutdown) { | if (ifp->if_vnet->vnet_shutdown) { | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
prison_free(pr); | prison_free(pr); | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
/* Move the interface into the child jail/vnet. */ | /* Move the interface into the child jail/vnet. */ | ||||
if_vmove(ifp, pr->pr_vnet); | error = if_vmove(ifp, pr->pr_vnet); | ||||
/* Report the new if_xname back to the userland. */ | /* Report the new if_xname back to the userland on success. */ | ||||
if (error == 0) | |||||
sprintf(ifname, "%s", ifp->if_xname); | sprintf(ifname, "%s", ifp->if_xname); | ||||
prison_free(pr); | prison_free(pr); | ||||
return (0); | return (error); | ||||
} | } | ||||
static int | static int | ||||
if_vmove_reclaim(struct thread *td, char *ifname, int jid) | if_vmove_reclaim(struct thread *td, char *ifname, int jid) | ||||
{ | { | ||||
struct prison *pr; | struct prison *pr; | ||||
struct vnet *vnet_dst; | struct vnet *vnet_dst; | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
int error; | |||||
/* Try to find the prison within our visibility. */ | /* Try to find the prison within our visibility. */ | ||||
sx_slock(&allprison_lock); | sx_slock(&allprison_lock); | ||||
pr = prison_find_child(td->td_ucred->cr_prison, jid); | pr = prison_find_child(td->td_ucred->cr_prison, jid); | ||||
sx_sunlock(&allprison_lock); | sx_sunlock(&allprison_lock); | ||||
if (pr == NULL) | if (pr == NULL) | ||||
return (ENXIO); | return (ENXIO); | ||||
prison_hold_locked(pr); | prison_hold_locked(pr); | ||||
Show All 19 Lines | if_vmove_reclaim(struct thread *td, char *ifname, int jid) | ||||
/* Make sure the VNET is stable. */ | /* Make sure the VNET is stable. */ | ||||
if (ifp->if_vnet->vnet_shutdown) { | if (ifp->if_vnet->vnet_shutdown) { | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
prison_free(pr); | prison_free(pr); | ||||
return (EBUSY); | return (EBUSY); | ||||
} | } | ||||
/* Get interface back from child jail/vnet. */ | /* Get interface back from child jail/vnet. */ | ||||
if_vmove(ifp, vnet_dst); | error = if_vmove(ifp, vnet_dst); | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
/* Report the new if_xname back to the userland. */ | /* Report the new if_xname back to the userland on success. */ | ||||
if (error == 0) | |||||
sprintf(ifname, "%s", ifp->if_xname); | sprintf(ifname, "%s", ifp->if_xname); | ||||
prison_free(pr); | prison_free(pr); | ||||
return (0); | return (error); | ||||
} | } | ||||
#endif /* VIMAGE */ | #endif /* VIMAGE */ | ||||
/* | /* | ||||
* Add a group to an interface | * Add a group to an interface | ||||
*/ | */ | ||||
int | int | ||||
if_addgroup(struct ifnet *ifp, const char *groupname) | if_addgroup(struct ifnet *ifp, const char *groupname) | ||||
▲ Show 20 Lines • Show All 3,125 Lines • Show Last 20 Lines |