aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/in.c
diff options
context:
space:
mode:
authorQing Li <qingli@FreeBSD.org>2009-05-12 07:41:20 +0000
committerQing Li <qingli@FreeBSD.org>2009-05-12 07:41:20 +0000
commitebc90701ac6c1f814c5bd6f3e19f0113ebe06156 (patch)
treeab586010af35714de80f60362baec475ab4ae625 /sys/netinet/in.c
parent12aa4fdca9ea8e0ff4210db4dbef64c9fe5ecb23 (diff)
downloadsrc-ebc90701ac6c1f814c5bd6f3e19f0113ebe06156.tar.gz
src-ebc90701ac6c1f814c5bd6f3e19f0113ebe06156.zip
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
Notes
Notes: svn path=/head/; revision=192011
Diffstat (limited to 'sys/netinet/in.c')
-rw-r--r--sys/netinet/in.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index 81803265398f..84750a6365b6 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -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_ifaddr *ia, struct sockaddr_in *sin,
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_ifaddr *ia, struct sockaddr_in *sin,
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>