Diff below stops mixing interface address flags with routing entry ones
and makes it explicitly which flag are used especially with the cloning
flag.
This is part of my work to cleanup the rtinit() interface to be able to
reuse it for creating local route entries.
This diff should not introduce any behavior change, I appreciate tests
and oks.
Martin
Index: net/if_var.h
===================================================================
RCS file: /home/ncvs/src/sys/net/if_var.h,v
retrieving revision 1.5
diff -u -p -r1.5 if_var.h
--- net/if_var.h 20 Mar 2014 13:19:06 -0000 1.5
+++ net/if_var.h 24 Mar 2014 12:19:03 -0000
@@ -290,11 +290,12 @@ struct ifaddr {
TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
/* check or clean routes (+ or -)'d */
void (*ifa_rtrequest)(int, struct rtentry *);
- u_int ifa_flags; /* mostly rt_flags for cloning */
+ u_int ifa_flags; /* interface flags, see below */
u_int ifa_refcnt; /* count of references */
int ifa_metric; /* cost of going out this interface */
};
-#define IFA_ROUTE RTF_UP /* route installed */
+
+#define IFA_ROUTE 0x01 /* Automagicaly installed route
*/
/*
* Interface multicast address.
Index: net/route.c
===================================================================
RCS file: /home/ncvs/src/sys/net/route.c,v
retrieving revision 1.156
diff -u -p -r1.156 route.c
--- net/route.c 21 Mar 2014 10:44:42 -0000 1.156
+++ net/route.c 24 Mar 2014 12:19:03 -0000
@@ -1118,7 +1118,7 @@ rtinit(struct ifaddr *ifa, int cmd, int
}
bzero(&info, sizeof(info));
info.rti_ifa = ifa;
- info.rti_flags = flags | ifa->ifa_flags;
+ info.rti_flags = flags;
info.rti_info[RTAX_DST] = dst;
if (cmd == RTM_ADD)
info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
Index: netinet/if_ether.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/if_ether.c,v
retrieving revision 1.122
diff -u -p -r1.122 if_ether.c
--- netinet/if_ether.c 18 Mar 2014 14:55:49 -0000 1.122
+++ netinet/if_ether.c 24 Mar 2014 12:19:03 -0000
@@ -867,7 +867,6 @@ arp_ifinit(struct arpcom *ac, struct ifa
&satosin(ifa->ifa_addr)->sin_addr.s_addr,
ac->ac_enaddr);
ifa->ifa_rtrequest = arp_rtrequest;
- ifa->ifa_flags |= RTF_CLONING;
}
/*
Index: netinet/in.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in.c,v
retrieving revision 1.93
diff -u -p -r1.93 in.c
--- netinet/in.c 21 Mar 2014 10:32:17 -0000 1.93
+++ netinet/in.c 24 Mar 2014 12:19:03 -0000
@@ -329,9 +329,9 @@ in_control(struct socket *so, u_long cmd
}
if (ia->ia_flags & IFA_ROUTE) {
ia->ia_ifa.ifa_dstaddr = sintosa(&oldaddr);
- rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST);
+ rtinit(&ia->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST);
ia->ia_ifa.ifa_dstaddr = sintosa(&ia->ia_dstaddr);
- rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP);
+ rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP | RTF_HOST);
}
splx(s);
break;
@@ -807,7 +807,7 @@ in_scrubhost(struct in_ifaddr *ia0)
if ((ia->ia_flags & IFA_ROUTE) != 0)
continue;
- rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_HOST);
+ rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST);
ia0->ia_flags &= ~IFA_ROUTE;
error = rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP | RTF_HOST);
if (!error)
@@ -816,7 +816,7 @@ in_scrubhost(struct in_ifaddr *ia0)
return (error);
}
- rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_HOST);
+ rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST);
ia0->ia_flags &= ~IFA_ROUTE;
return (0);
@@ -858,7 +858,7 @@ in_addprefix(struct in_ifaddr *ia0)
/* move to a real interface instead of carp interface */
if (ia->ia_ifp->if_type == IFT_CARP &&
ia0->ia_ifp->if_type != IFT_CARP) {
- rtinit(&ia->ia_ifa, RTM_DELETE, 0);
+ rtinit(&ia->ia_ifa, RTM_DELETE, RTF_UP | RTF_CLONING);
ia->ia_flags &= ~IFA_ROUTE;
break;
}
@@ -873,7 +873,7 @@ in_addprefix(struct in_ifaddr *ia0)
/*
* noone seem to have prefix route. insert it.
*/
- error = rtinit(&ia0->ia_ifa, RTM_ADD, RTF_UP);
+ error = rtinit(&ia0->ia_ifa, RTM_ADD, RTF_UP | RTF_CLONING);
if (!error)
ia0->ia_flags |= IFA_ROUTE;
return error;
@@ -918,9 +918,9 @@ in_scrubprefix(struct in_ifaddr *ia0)
/*
* if we got a matching prefix route, move IFA_ROUTE to him
*/
- rtinit(&ia0->ia_ifa, RTM_DELETE, 0);
+ rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_CLONING);
ia0->ia_flags &= ~IFA_ROUTE;
- error = rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP);
+ error = rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP | RTF_CLONING);
if (error == 0)
ia->ia_flags |= IFA_ROUTE;
return error;
@@ -929,7 +929,7 @@ in_scrubprefix(struct in_ifaddr *ia0)
/*
* noone seem to have prefix route. remove it.
*/
- rtinit(&ia0->ia_ifa, RTM_DELETE, 0);
+ rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_CLONING);
ia0->ia_flags &= ~IFA_ROUTE;
return 0;
}
Index: netinet/in_var.h
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in_var.h,v
retrieving revision 1.33
diff -u -p -r1.33 in_var.h
--- netinet/in_var.h 21 Jan 2014 10:18:26 -0000 1.33
+++ netinet/in_var.h 24 Mar 2014 12:19:03 -0000
@@ -47,7 +47,7 @@
struct in_ifaddr {
struct ifaddr ia_ifa; /* protocol-independent info */
#define ia_ifp ia_ifa.ifa_ifp
-#define ia_flags ia_ifa.ifa_flags
+#define ia_flags ia_ifa.ifa_flags
/* ia_net{,mask} in host order */
u_int32_t ia_net; /* network number of interface */
u_int32_t ia_netmask; /* mask of net part */
Index: netinet/ip_carp.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/ip_carp.c,v
retrieving revision 1.224
diff -u -p -r1.224 ip_carp.c
--- netinet/ip_carp.c 21 Mar 2014 13:48:28 -0000 1.224
+++ netinet/ip_carp.c 24 Mar 2014 12:19:03 -0000
@@ -459,7 +459,6 @@ carp_setroute(struct carp_softc *sc, int
case RTM_ADD:
if (hr_otherif) {
ifa->ifa_rtrequest = NULL;
- ifa->ifa_flags &= ~RTF_CLONING;
memset(&info, 0, sizeof(info));
info.rti_info[RTAX_DST] = ifa->ifa_addr;
info.rti_info[RTAX_GATEWAY] =
ifa->ifa_addr;
@@ -485,7 +484,6 @@ carp_setroute(struct carp_softc *sc, int
}
ifa->ifa_rtrequest = arp_rtrequest;
- ifa->ifa_flags |= RTF_CLONING;
memset(&info, 0, sizeof(info));
info.rti_info[RTAX_DST] = &sa;
@@ -2222,7 +2220,6 @@ carp_ioctl(struct ifnet *ifp, u_long cmd
* request so that the routes are setup correctly.
*/
ifa->ifa_rtrequest = arp_rtrequest;
- ifa->ifa_flags |= RTF_CLONING;
error = carp_set_addr(sc, satosin(ifa->ifa_addr));
break;
Index: netinet6/in6.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/in6.c,v
retrieving revision 1.132
diff -u -p -r1.132 in6.c
--- netinet6/in6.c 12 Feb 2014 10:03:07 -0000 1.132
+++ netinet6/in6.c 24 Mar 2014 12:19:03 -0000
@@ -895,10 +895,9 @@ in6_update_ifa(struct ifnet *ifp, struct
*/
if (dst6.sin6_family == AF_INET6 &&
!IN6_ARE_ADDR_EQUAL(&dst6.sin6_addr, &ia6->ia_dstaddr.sin6_addr)) {
- int e;
if ((ia6->ia_flags & IFA_ROUTE) != 0 &&
- (e = rtinit(&(ia6->ia_ifa), (int)RTM_DELETE, RTF_HOST)) !=
0) {
+ rtinit(&ia6->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST)) {
nd6log((LOG_ERR, "in6_update_ifa: failed to remove "
"a route to the old destination: %s\n",
inet_ntop(AF_INET6, &ia6->ia_addr.sin6_addr,
@@ -1165,8 +1164,8 @@ in6_purgeaddr(struct ifaddr *ifa)
if ((ia6->ia_flags & IFA_ROUTE) != 0 && ia6->ia_dstaddr.sin6_len != 0) {
int e;
- if ((e = rtinit(&(ia6->ia_ifa), (int)RTM_DELETE, RTF_HOST))
- != 0) {
+ if ((e = rtinit(&ia6->ia_ifa, RTM_DELETE,
+ RTF_UP | RTF_HOST)) != 0) {
char addr[INET6_ADDRSTRLEN];
log(LOG_ERR, "in6_purgeaddr: failed to remove "
"a route to the p2p destination: %s on %s, "
@@ -1509,8 +1508,7 @@ in6_ifinit(struct ifnet *ifp, struct in6
*/
plen = in6_mask2len(&ia6->ia_prefixmask.sin6_addr, NULL); /* XXX */
if (plen == 128 && ia6->ia_dstaddr.sin6_family == AF_INET6) {
- if ((error = rtinit(&(ia6->ia_ifa), (int)RTM_ADD,
- RTF_UP | RTF_HOST)) != 0)
+ if ((error = rtinit(&ia6->ia_ifa, RTM_ADD, RTF_UP | RTF_HOST)))
return (error);
ia6->ia_flags |= IFA_ROUTE;
}
Index: netinet6/in6_var.h
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/in6_var.h,v
retrieving revision 1.47
diff -u -p -r1.47 in6_var.h
--- netinet6/in6_var.h 21 Jan 2014 10:18:26 -0000 1.47
+++ netinet6/in6_var.h 24 Mar 2014 12:19:03 -0000
@@ -99,7 +99,7 @@ struct in6_ifextra {
struct in6_ifaddr {
struct ifaddr ia_ifa; /* protocol-independent info */
#define ia_ifp ia_ifa.ifa_ifp
-#define ia_flags ia_ifa.ifa_flags
+#define ia_flags ia_ifa.ifa_flags
struct sockaddr_in6 ia_addr; /* interface address */
struct sockaddr_in6 ia_net; /* network number of interface */
Index: netinet6/nd6.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/nd6.c,v
retrieving revision 1.112
diff -u -p -r1.112 nd6.c
--- netinet6/nd6.c 11 Mar 2014 10:31:29 -0000 1.112
+++ netinet6/nd6.c 24 Mar 2014 12:19:03 -0000
@@ -689,8 +689,7 @@ nd6_lookup(struct in6_addr *addr6, int c
* called in rtrequest1 via ifa->ifa_rtrequest.
*/
bzero(&info, sizeof(info));
- info.rti_flags = (ifa->ifa_flags | RTF_HOST |
- RTF_LLINFO) & ~RTF_CLONING;
+ info.rti_flags = RTF_UP | RTF_HOST | RTF_LLINFO;
info.rti_info[RTAX_DST] = sin6tosa(&sin6);
info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
if ((e = rtrequest1(RTM_ADD, &info, RTP_CONNECTED,
Index: netinet6/nd6_rtr.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.79
diff -u -p -r1.79 nd6_rtr.c
--- netinet6/nd6_rtr.c 18 Mar 2014 10:47:34 -0000 1.79
+++ netinet6/nd6_rtr.c 24 Mar 2014 12:19:03 -0000
@@ -1630,16 +1630,11 @@ nd6_prefix_onlink(struct nd_prefix *pr)
mask6.sin6_len = sizeof(mask6);
mask6.sin6_addr = pr->ndpr_mask;
/* rtrequest1() will probably set RTF_UP, but we're not sure. */
- rtflags = ifa->ifa_flags | RTF_UP;
- if (nd6_need_cache(ifp)) {
- /* explicitly set in case ifa_flags does not set the flag. */
+ rtflags = RTF_UP;
+ if (nd6_need_cache(ifp))
rtflags |= RTF_CLONING;
- } else {
- /*
- * explicitly clear the cloning bit in case ifa_flags sets it.
- */
+ else
rtflags &= ~RTF_CLONING;
- }
bzero(&info, sizeof(info));
info.rti_flags = rtflags;