summaryrefslogtreecommitdiffstats
path: root/sys/net
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2013-11-05 07:36:17 +0000
committerglebius <glebius@FreeBSD.org>2013-11-05 07:36:17 +0000
commit592c1d7a8e9590ce76786fe68d0cac491b6b23e6 (patch)
tree1e5fe56d0aee7cbf5a8082b2b2be8c8e2dfc1d13 /sys/net
parentbce78dfe179929ceecbfdee04dfb909517d70d13 (diff)
downloadFreeBSD-src-592c1d7a8e9590ce76786fe68d0cac491b6b23e6.zip
FreeBSD-src-592c1d7a8e9590ce76786fe68d0cac491b6b23e6.tar.gz
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.
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c19
-rw-r--r--sys/net/if_var.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 17c36d1..9383b63 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -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
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 22ccbd9..26163ad 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -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 *);
OpenPOWER on IntegriCloud