svn commit: r257690 - head/sys/net

Gleb Smirnoff glebius at FreeBSD.org
Tue Nov 5 07:36:18 UTC 2013


Author: glebius
Date: Tue Nov  5 07:36:17 2013
New Revision: 257690
URL: http://svnweb.freebsd.org/changeset/base/257690

Log:
  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.

Modified:
  head/sys/net/if.c
  head/sys/net/if_var.h

Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c	Tue Nov  5 07:32:09 2013	(r257689)
+++ head/sys/net/if.c	Tue Nov  5 07:36:17 2013	(r257690)
@@ -1525,6 +1525,25 @@ ifa_del_loopback_route(struct ifaddr *if
 	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

Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h	Tue Nov  5 07:32:09 2013	(r257689)
+++ head/sys/net/if_var.h	Tue Nov  5 07:36:17 2013	(r257690)
@@ -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 *);


More information about the svn-src-all mailing list