Changeset View
Changeset View
Standalone View
Standalone View
head/sys/net/if.c
Show First 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | |||||
static int ifconf(u_long, caddr_t); | static int ifconf(u_long, caddr_t); | ||||
static void *if_grow(void); | static void *if_grow(void); | ||||
static void if_input_default(struct ifnet *, struct mbuf *); | static void if_input_default(struct ifnet *, struct mbuf *); | ||||
static int if_requestencap_default(struct ifnet *, struct if_encap_req *); | static int if_requestencap_default(struct ifnet *, struct if_encap_req *); | ||||
static void if_route(struct ifnet *, int flag, int fam); | static void if_route(struct ifnet *, int flag, int fam); | ||||
static int if_setflag(struct ifnet *, int, int, int *, int); | static int if_setflag(struct ifnet *, int, int, int *, int); | ||||
static int if_transmit(struct ifnet *ifp, struct mbuf *m); | static int if_transmit(struct ifnet *ifp, struct mbuf *m); | ||||
static void if_unroute(struct ifnet *, int flag, int fam); | static void if_unroute(struct ifnet *, int flag, int fam); | ||||
static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); | |||||
static int if_delmulti_locked(struct ifnet *, struct ifmultiaddr *, int); | static int if_delmulti_locked(struct ifnet *, struct ifmultiaddr *, int); | ||||
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 **); | ||||
#ifdef VIMAGE | #ifdef VIMAGE | ||||
▲ Show 20 Lines • Show All 581 Lines • ▼ Show 20 Lines | #endif | ||||
sdl->sdl_len = socksize; | sdl->sdl_len = socksize; | ||||
sdl->sdl_family = AF_LINK; | sdl->sdl_family = AF_LINK; | ||||
bcopy(ifp->if_xname, sdl->sdl_data, namelen); | bcopy(ifp->if_xname, sdl->sdl_data, namelen); | ||||
sdl->sdl_nlen = namelen; | sdl->sdl_nlen = namelen; | ||||
sdl->sdl_index = ifp->if_index; | sdl->sdl_index = ifp->if_index; | ||||
sdl->sdl_type = ifp->if_type; | sdl->sdl_type = ifp->if_type; | ||||
ifp->if_addr = ifa; | ifp->if_addr = ifa; | ||||
ifa->ifa_ifp = ifp; | ifa->ifa_ifp = ifp; | ||||
ifa->ifa_rtrequest = link_rtrequest; | |||||
ifa->ifa_addr = (struct sockaddr *)sdl; | ifa->ifa_addr = (struct sockaddr *)sdl; | ||||
sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl); | sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl); | ||||
ifa->ifa_netmask = (struct sockaddr *)sdl; | ifa->ifa_netmask = (struct sockaddr *)sdl; | ||||
sdl->sdl_len = masklen; | sdl->sdl_len = masklen; | ||||
while (namelen != 0) | while (namelen != 0) | ||||
sdl->sdl_data[--namelen] = 0xff; | sdl->sdl_data[--namelen] = 0xff; | ||||
CK_STAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link); | CK_STAILQ_INSERT_HEAD(&ifp->if_addrhead, ifa, ifa_link); | ||||
/* Reliably crash if used uninitialized. */ | /* Reliably crash if used uninitialized. */ | ||||
▲ Show 20 Lines • Show All 1,013 Lines • ▼ Show 20 Lines | if (refcount_release(&ifa->ifa_refcnt)) | ||||
epoch_call(net_epoch_preempt, &ifa->ifa_epoch_ctx, ifa_destroy); | epoch_call(net_epoch_preempt, &ifa->ifa_epoch_ctx, ifa_destroy); | ||||
} | } | ||||
static int | static int | ||||
ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa, | ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa, | ||||
struct sockaddr *ia) | struct sockaddr *ia) | ||||
{ | { | ||||
struct epoch_tracker et; | |||||
int error; | int error; | ||||
struct rt_addrinfo info; | struct rt_addrinfo info; | ||||
struct sockaddr_dl null_sdl; | struct sockaddr_dl null_sdl; | ||||
struct ifnet *ifp; | struct ifnet *ifp; | ||||
ifp = ifa->ifa_ifp; | ifp = ifa->ifa_ifp; | ||||
bzero(&info, sizeof(info)); | bzero(&info, sizeof(info)); | ||||
if (cmd != RTM_DELETE) | if (cmd != RTM_DELETE) | ||||
info.rti_ifp = V_loif; | info.rti_ifp = V_loif; | ||||
if (cmd == RTM_ADD) { | |||||
/* explicitly specify (loopback) ifa */ | |||||
if (info.rti_ifp != NULL) { | |||||
NET_EPOCH_ENTER(et); | |||||
info.rti_ifa = ifaof_ifpforaddr(ifa->ifa_addr, info.rti_ifp); | |||||
if (info.rti_ifa != NULL) | |||||
ifa_ref(info.rti_ifa); | |||||
NET_EPOCH_EXIT(et); | |||||
} | |||||
} | |||||
info.rti_flags = ifa->ifa_flags | RTF_HOST | RTF_STATIC | RTF_PINNED; | info.rti_flags = ifa->ifa_flags | RTF_HOST | RTF_STATIC | RTF_PINNED; | ||||
info.rti_info[RTAX_DST] = ia; | info.rti_info[RTAX_DST] = ia; | ||||
info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl; | info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl; | ||||
link_init_sdl(ifp, (struct sockaddr *)&null_sdl, ifp->if_type); | link_init_sdl(ifp, (struct sockaddr *)&null_sdl, ifp->if_type); | ||||
error = rtrequest1_fib(cmd, &info, NULL, ifp->if_fib); | error = rtrequest1_fib(cmd, &info, NULL, ifp->if_fib); | ||||
if (error != 0 && | if (error != 0 && | ||||
▲ Show 20 Lines • Show All 290 Lines • ▼ Show 20 Lines | |||||
* Used in several address selecting functions. | * Used in several address selecting functions. | ||||
*/ | */ | ||||
int | int | ||||
ifa_preferred(struct ifaddr *cur, struct ifaddr *next) | ifa_preferred(struct ifaddr *cur, struct ifaddr *next) | ||||
{ | { | ||||
return (cur->ifa_carp && (!next->ifa_carp || | return (cur->ifa_carp && (!next->ifa_carp || | ||||
((*carp_master_p)(next) && !(*carp_master_p)(cur)))); | ((*carp_master_p)(next) && !(*carp_master_p)(cur)))); | ||||
} | |||||
#include <net/if_llatbl.h> | |||||
/* | |||||
* Default action when installing a route with a Link Level gateway. | |||||
* Lookup an appropriate real ifa to point to. | |||||
* This should be moved to /sys/net/link.c eventually. | |||||
*/ | |||||
static void | |||||
link_rtrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info) | |||||
{ | |||||
struct epoch_tracker et; | |||||
struct ifaddr *ifa, *oifa; | |||||
struct sockaddr *dst; | |||||
struct ifnet *ifp; | |||||
if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == NULL) || | |||||
((ifp = ifa->ifa_ifp) == NULL) || ((dst = rt_key(rt)) == NULL)) | |||||
return; | |||||
NET_EPOCH_ENTER(et); | |||||
ifa = ifaof_ifpforaddr(dst, ifp); | |||||
if (ifa) { | |||||
oifa = rt->rt_ifa; | |||||
if (oifa != ifa) { | |||||
ifa_free(oifa); | |||||
ifa_ref(ifa); | |||||
} | |||||
rt->rt_ifa = ifa; | |||||
if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest) | |||||
ifa->ifa_rtrequest(cmd, rt, info); | |||||
} | |||||
NET_EPOCH_EXIT(et); | |||||
} | } | ||||
struct sockaddr_dl * | struct sockaddr_dl * | ||||
link_alloc_sdl(size_t size, int flags) | link_alloc_sdl(size_t size, int flags) | ||||
{ | { | ||||
return (malloc(size, M_TEMP, flags)); | return (malloc(size, M_TEMP, flags)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,371 Lines • Show Last 20 Lines |