svn commit: r192011 - head/sys/netinet
Qing Li
qingli at FreeBSD.org
Tue May 12 07:41:21 UTC 2009
Author: qingli
Date: Tue May 12 07:41:20 2009
New Revision: 192011
URL: http://svn.freebsd.org/changeset/base/192011
Log:
This patch adds a host route to an interface address (that is assigned
to a non loopback/ppp link types) through the loopback interface. Prior
to the new L2/L3 rewrite, this host route is implicitly added by the L2
code during RTM_RESOLVE of that interface address. This host route is
deleted when that interface is removed.
Reviewed by: kmacy
Modified:
head/sys/netinet/in.c
Modified: head/sys/netinet/in.c
==============================================================================
--- head/sys/netinet/in.c Tue May 12 05:49:02 2009 (r192010)
+++ head/sys/netinet/in.c Tue May 12 07:41:20 2009 (r192011)
@@ -45,12 +45,15 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/sysctl.h>
+#include <sys/syslog.h>
#include <sys/vimage.h>
#include <net/if.h>
+#include <net/if_dl.h>
#include <net/if_llatbl.h>
#include <net/if_types.h>
#include <net/route.h>
+#include <net/vnet.h>
#include <netinet/in.h>
#include <netinet/in_var.h>
@@ -814,6 +817,9 @@ in_ifinit(struct ifnet *ifp, struct in_i
INIT_VNET_INET(ifp->if_vnet);
register u_long i = ntohl(sin->sin_addr.s_addr);
struct sockaddr_in oldaddr;
+ struct rtentry *rt = NULL;
+ struct rt_addrinfo info;
+ static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
int s = splimp(), flags = RTF_UP, error = 0;
oldaddr = ia->ia_addr;
@@ -900,6 +906,29 @@ in_ifinit(struct ifnet *ifp, struct in_i
if ((error = in_addprefix(ia, flags)) != 0)
return (error);
+ /*
+ * add a loopback route to self
+ */
+ if (!(ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
+ bzero(&info, sizeof(info));
+ info.rti_ifp = V_loif;
+ info.rti_flags = ia->ia_flags | RTF_HOST | RTF_STATIC;
+ info.rti_info[RTAX_DST] = (struct sockaddr *)&ia->ia_addr;
+ info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl;
+ error = rtrequest1_fib(RTM_ADD, &info, &rt, 0);
+
+ if (error == 0 && rt != NULL) {
+ RT_LOCK(rt);
+ ((struct sockaddr_dl *)rt->rt_gateway)->sdl_type =
+ rt->rt_ifp->if_type;
+ ((struct sockaddr_dl *)rt->rt_gateway)->sdl_index =
+ rt->rt_ifp->if_index;
+ RT_REMREF(rt);
+ RT_UNLOCK(rt);
+ } else if (error != 0)
+ log(LOG_INFO, "in_ifinit: insertion failed\n");
+ }
+
return (error);
}
@@ -979,10 +1008,28 @@ in_scrubprefix(struct in_ifaddr *target)
struct in_ifaddr *ia;
struct in_addr prefix, mask, p;
int error;
+ struct rt_addrinfo info;
+ struct sockaddr_dl null_sdl;
if ((target->ia_flags & IFA_ROUTE) == 0)
return (0);
+ if (!(target->ia_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) {
+ bzero(&null_sdl, sizeof(null_sdl));
+ null_sdl.sdl_len = sizeof(null_sdl);
+ null_sdl.sdl_family = AF_LINK;
+ null_sdl.sdl_type = V_loif->if_type;
+ null_sdl.sdl_index = V_loif->if_index;
+ bzero(&info, sizeof(info));
+ info.rti_flags = target->ia_flags | RTF_HOST | RTF_STATIC;
+ info.rti_info[RTAX_DST] = (struct sockaddr *)&target->ia_addr;
+ info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&null_sdl;
+ error = rtrequest1_fib(RTM_DELETE, &info, NULL, 0);
+
+ if (error != 0)
+ log(LOG_INFO, "in_scrubprefix: deletion failed\n");
+ }
+
if (rtinitflags(target))
prefix = target->ia_dstaddr.sin_addr;
else {
@@ -1136,7 +1183,6 @@ in_purgemaddrs(struct ifnet *ifp)
IN_MULTI_UNLOCK();
}
-#include <sys/syslog.h>
#include <net/if_dl.h>
#include <netinet/if_ether.h>
More information about the svn-src-all
mailing list