summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2014-03-27 10:39:24 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2014-03-27 10:39:24 +0000
commitaae25658bc1380b4a14aca6bf7f930c2894149a8 (patch)
treedba50823ed1e17cb568556e24641bc4ad5dfa56c /sys
parentf717b944041261c893a2722a34efda2347534d69 (diff)
Stop mixing interface address flags with routing entry ones.
Instead of always copying ifa_flags to the routing entry flags when creating a route by calling rtinit(), explicitly pass the RTF_CLONING flag when required. This means ifa_flags are now *only* used to check if an address has an associated route that was created by the kernel auto-magically. ok benno@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if_var.h7
-rw-r--r--sys/net/route.c4
-rw-r--r--sys/netinet/if_ether.c3
-rw-r--r--sys/netinet/in.c20
-rw-r--r--sys/netinet/in_var.h4
-rw-r--r--sys/netinet/ip_carp.c5
-rw-r--r--sys/netinet6/in6.c12
-rw-r--r--sys/netinet6/in6_var.h4
-rw-r--r--sys/netinet6/nd6.c5
-rw-r--r--sys/netinet6/nd6_rtr.c13
10 files changed, 33 insertions, 44 deletions
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 6b1cc75c543..dcf193f30c8 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_var.h,v 1.5 2014/03/20 13:19:06 mpi Exp $ */
+/* $OpenBSD: if_var.h,v 1.6 2014/03/27 10:39:23 mpi Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -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 /* Auto-magically installed route */
/*
* Interface multicast address.
diff --git a/sys/net/route.c b/sys/net/route.c
index c650cedc6d9..2b0e08c8648 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.156 2014/03/21 10:44:42 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.157 2014/03/27 10:39:23 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -1118,7 +1118,7 @@ rtinit(struct ifaddr *ifa, int cmd, int flags)
}
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;
diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c
index d73018f7e78..af3f3cdfb86 100644
--- a/sys/netinet/if_ether.c
+++ b/sys/netinet/if_ether.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ether.c,v 1.122 2014/03/18 14:55:49 mikeb Exp $ */
+/* $OpenBSD: if_ether.c,v 1.123 2014/03/27 10:39:23 mpi Exp $ */
/* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */
/*
@@ -867,7 +867,6 @@ arp_ifinit(struct arpcom *ac, struct ifaddr *ifa)
&satosin(ifa->ifa_addr)->sin_addr.s_addr,
ac->ac_enaddr);
ifa->ifa_rtrequest = arp_rtrequest;
- ifa->ifa_flags |= RTF_CLONING;
}
/*
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index a094d9a46ba..6c1c9f423cb 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.c,v 1.93 2014/03/21 10:32:17 mpi Exp $ */
+/* $OpenBSD: in.c,v 1.94 2014/03/27 10:39:23 mpi Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
@@ -329,9 +329,9 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp)
}
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;
}
diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h
index a3c388fe3e1..c8d7caed508 100644
--- a/sys/netinet/in_var.h
+++ b/sys/netinet/in_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_var.h,v 1.33 2014/01/21 10:18:26 mpi Exp $ */
+/* $OpenBSD: in_var.h,v 1.34 2014/03/27 10:39:23 mpi Exp $ */
/* $NetBSD: in_var.h,v 1.16 1996/02/13 23:42:15 christos Exp $ */
/*
@@ -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 */
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c
index 58635844535..7d9ad85434d 100644
--- a/sys/netinet/ip_carp.c
+++ b/sys/netinet/ip_carp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_carp.c,v 1.224 2014/03/21 13:48:28 mpi Exp $ */
+/* $OpenBSD: ip_carp.c,v 1.225 2014/03/27 10:39:23 mpi Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff. All rights reserved.
@@ -459,7 +459,6 @@ carp_setroute(struct carp_softc *sc, int cmd)
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 cmd)
}
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, caddr_t addr)
* 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;
diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c
index a4bfd9f0568..4e063c0bc03 100644
--- a/sys/netinet6/in6.c
+++ b/sys/netinet6/in6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6.c,v 1.132 2014/02/12 10:03:07 mpi Exp $ */
+/* $OpenBSD: in6.c,v 1.133 2014/03/27 10:39:23 mpi Exp $ */
/* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */
/*
@@ -895,10 +895,9 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra,
*/
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_ifaddr *ia6, int newhost)
*/
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;
}
diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h
index 56eef418e44..7ce3d7f76de 100644
--- a/sys/netinet6/in6_var.h
+++ b/sys/netinet6/in6_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_var.h,v 1.47 2014/01/21 10:18:26 mpi Exp $ */
+/* $OpenBSD: in6_var.h,v 1.48 2014/03/27 10:39:23 mpi Exp $ */
/* $KAME: in6_var.h,v 1.55 2001/02/16 12:49:45 itojun Exp $ */
/*
@@ -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 */
diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c
index 6d5a909fc1d..293a886f9d3 100644
--- a/sys/netinet6/nd6.c
+++ b/sys/netinet6/nd6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6.c,v 1.112 2014/03/11 10:31:29 mpi Exp $ */
+/* $OpenBSD: nd6.c,v 1.113 2014/03/27 10:39:23 mpi Exp $ */
/* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */
/*
@@ -689,8 +689,7 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp,
* 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,
diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c
index 6065bc1c544..f6f6d2fe381 100644
--- a/sys/netinet6/nd6_rtr.c
+++ b/sys/netinet6/nd6_rtr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nd6_rtr.c,v 1.79 2014/03/18 10:47:34 mpi Exp $ */
+/* $OpenBSD: nd6_rtr.c,v 1.80 2014/03/27 10:39:23 mpi Exp $ */
/* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */
/*
@@ -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;