In complemence to ifa_add_loopback_route() and ifa_del_loopback_route()

provide function ifa_switch_loopback_route() that will be used in case when
an interface address used for a loopback route goes away, but we have another
interface address with same address value and want to preserve loopback
route.

Sponsored by:	Netflix
Sponsored by:	Nginx, Inc.
This commit is contained in:
Gleb Smirnoff 2013-11-05 07:36:17 +00:00
parent b1b9dcae46
commit 9a6356bc31
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=257690
2 changed files with 20 additions and 0 deletions

View File

@ -1525,6 +1525,25 @@ ifa_del_loopback_route(struct ifaddr *ifa, struct sockaddr *ia)
return (error);
}
int
ifa_switch_loopback_route(struct ifaddr *ifa, struct sockaddr *sa)
{
struct rtentry *rt;
rt = rtalloc1_fib(sa, 0, 0, 0);
if (rt == NULL) {
log(LOG_DEBUG, "%s: fail", __func__);
return (EHOSTUNREACH);
}
((struct sockaddr_dl *)rt->rt_gateway)->sdl_type =
ifa->ifa_ifp->if_type;
((struct sockaddr_dl *)rt->rt_gateway)->sdl_index =
ifa->ifa_ifp->if_index;
RTFREE_LOCKED(rt);
return (0);
}
/*
* XXX: Because sockaddr_dl has deeper structure than the sockaddr
* structs used to represent other address families, it is necessary

View File

@ -502,6 +502,7 @@ struct ifnet *ifunit_ref(const char *);
int ifa_add_loopback_route(struct ifaddr *, struct sockaddr *);
int ifa_del_loopback_route(struct ifaddr *, struct sockaddr *);
int ifa_switch_loopback_route(struct ifaddr *, struct sockaddr *);
struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
int ifa_ifwithaddr_check(struct sockaddr *);