diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-04-10 13:47:22 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-04-10 13:47:22 +0000 |
commit | e11d6a96c6407cab89d8308023585638234b759e (patch) | |
tree | 98be7f3f4757d2deefa44b3784ff1327fb9cf4f5 /sys | |
parent | af6cd88a028214570cecb5b78955e01dda5a9092 (diff) |
Retire rtinit() an use rt_ifa_add(9) and rt_ifa_del(9) to manage
connected routes to prefixes/hosts.
Since the introduction of rt_ifa_addloop(9) and rt_ifa_delloop(9),
rtinit() was just a wrapper, so use the underlying functions
directly and document them.
Inputs from and ok mikeb@, manpage tweaks from jmc@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if.c | 4 | ||||
-rw-r--r-- | sys/net/route.c | 27 | ||||
-rw-r--r-- | sys/net/route.h | 5 | ||||
-rw-r--r-- | sys/netinet/in.c | 31 | ||||
-rw-r--r-- | sys/netinet6/in6.c | 12 |
5 files changed, 30 insertions, 49 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 90408dac42e..12a37ec4b2b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.282 2014/03/20 13:19:06 mpi Exp $ */ +/* $OpenBSD: if.c,v 1.283 2014/04/10 13:47:21 mpi Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -368,7 +368,7 @@ if_free_sadl(struct ifnet *ifp) return; s = splnet(); - rtinit(ifa, RTM_DELETE, 0); + rt_ifa_del(ifa, 0, ifa->ifa_addr); ifa_del(ifp, ifa); ifafree(ifp->if_lladdr); ifp->if_lladdr = NULL; diff --git a/sys/net/route.c b/sys/net/route.c index d0e80e51646..f32f10eb9eb 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.158 2014/04/03 08:22:10 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.159 2014/04/10 13:47:21 mpi Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -150,9 +150,6 @@ int rtflushclone1(struct radix_node *, void *, u_int); void rtflushclone(struct radix_node_head *, struct rtentry *); int rt_if_remove_rtdelete(struct radix_node *, void *, u_int); -int rt_ifa_add(struct ifaddr *, int, struct sockaddr *); -int rt_ifa_del(struct ifaddr *, int, struct sockaddr *); - #define LABELID_MAX 50000 struct rt_label { @@ -1079,28 +1076,6 @@ rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst, bzero((caddr_t)cp2, (unsigned)(cplim2 - cp2)); } -/* - * Set up a routing table entry, normally - * for an interface. - */ -int -rtinit(struct ifaddr *ifa, int cmd, int flags) -{ - struct sockaddr *dst; - int error; - - KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE); - - dst = flags & RTF_HOST ? ifa->ifa_dstaddr : ifa->ifa_addr; - - if (cmd == RTM_ADD) - error = rt_ifa_add(ifa, flags, dst); - else - error = rt_ifa_del(ifa, flags, dst); - - return (error); -} - int rt_ifa_add(struct ifaddr *ifa, int flags, struct sockaddr *dst) { diff --git a/sys/net/route.h b/sys/net/route.h index 7139dcfe7e6..499d8d15bc6 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,4 +1,4 @@ -/* $OpenBSD: route.h,v 1.90 2014/04/03 08:22:10 mpi Exp $ */ +/* $OpenBSD: route.h,v 1.91 2014/04/10 13:47:21 mpi Exp $ */ /* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */ /* @@ -401,7 +401,8 @@ struct rtentry * rtalloc1(struct sockaddr *, int, u_int); void rtfree(struct rtentry *); int rt_getifa(struct rt_addrinfo *, u_int); -int rtinit(struct ifaddr *, int, int); +int rt_ifa_add(struct ifaddr *, int, struct sockaddr *); +int rt_ifa_del(struct ifaddr *, int, struct sockaddr *); void rt_ifa_addloop(struct ifaddr *); void rt_ifa_delloop(struct ifaddr *); int rtioctl(u_long, caddr_t, struct proc *); diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 6c1c9f423cb..3340bf927d1 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in.c,v 1.94 2014/03/27 10:39:23 mpi Exp $ */ +/* $OpenBSD: in.c,v 1.95 2014/04/10 13:47:21 mpi Exp $ */ /* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */ /* @@ -328,10 +328,9 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) return (error); } if (ia->ia_flags & IFA_ROUTE) { - ia->ia_ifa.ifa_dstaddr = sintosa(&oldaddr); - rtinit(&ia->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST); - ia->ia_ifa.ifa_dstaddr = sintosa(&ia->ia_dstaddr); - rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP | RTF_HOST); + rt_ifa_del(&ia->ia_ifa, RTF_HOST, sintosa(&oldaddr)); + rt_ifa_add(&ia->ia_ifa, RTF_UP | RTF_HOST, + ia->ia_ifa.ifa_dstaddr); } splx(s); break; @@ -773,7 +772,8 @@ in_addhost(struct in_ifaddr *ia0) return (0); } - error = rtinit(&ia0->ia_ifa, RTM_ADD, RTF_UP | RTF_HOST); + error = rt_ifa_add(&ia0->ia_ifa, RTF_UP | RTF_HOST, + ia0->ia_ifa.ifa_dstaddr); if (!error) ia0->ia_flags |= IFA_ROUTE; @@ -807,16 +807,17 @@ in_scrubhost(struct in_ifaddr *ia0) if ((ia->ia_flags & IFA_ROUTE) != 0) continue; - rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST); + rt_ifa_del(&ia0->ia_ifa, RTF_HOST, ia0->ia_ifa.ifa_dstaddr); ia0->ia_flags &= ~IFA_ROUTE; - error = rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP | RTF_HOST); + error = rt_ifa_add(&ia->ia_ifa, RTF_UP | RTF_HOST, + ia->ia_ifa.ifa_dstaddr); if (!error) ia->ia_flags |= IFA_ROUTE; return (error); } - rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST); + rt_ifa_del(&ia0->ia_ifa, RTF_HOST, ia0->ia_ifa.ifa_dstaddr); ia0->ia_flags &= ~IFA_ROUTE; return (0); @@ -858,7 +859,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, RTF_UP | RTF_CLONING); + rt_ifa_del(&ia->ia_ifa, 0, ia->ia_ifa.ifa_addr); ia->ia_flags &= ~IFA_ROUTE; break; } @@ -873,7 +874,8 @@ in_addprefix(struct in_ifaddr *ia0) /* * noone seem to have prefix route. insert it. */ - error = rtinit(&ia0->ia_ifa, RTM_ADD, RTF_UP | RTF_CLONING); + error = rt_ifa_add(&ia0->ia_ifa, RTF_UP | RTF_CLONING, + ia0->ia_ifa.ifa_addr); if (!error) ia0->ia_flags |= IFA_ROUTE; return error; @@ -918,9 +920,10 @@ in_scrubprefix(struct in_ifaddr *ia0) /* * if we got a matching prefix route, move IFA_ROUTE to him */ - rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_CLONING); + rt_ifa_del(&ia0->ia_ifa, 0, ia0->ia_ifa.ifa_addr); ia0->ia_flags &= ~IFA_ROUTE; - error = rtinit(&ia->ia_ifa, RTM_ADD, RTF_UP | RTF_CLONING); + error = rt_ifa_add(&ia->ia_ifa, RTF_UP | RTF_CLONING, + ia->ia_ifa.ifa_addr); if (error == 0) ia->ia_flags |= IFA_ROUTE; return error; @@ -929,7 +932,7 @@ in_scrubprefix(struct in_ifaddr *ia0) /* * noone seem to have prefix route. remove it. */ - rtinit(&ia0->ia_ifa, RTM_DELETE, RTF_UP | RTF_CLONING); + rt_ifa_del(&ia0->ia_ifa, 0, ia0->ia_ifa.ifa_addr); ia0->ia_flags &= ~IFA_ROUTE; return 0; } diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 16ef0833f21..4dcdf1d2f84 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.134 2014/04/03 08:22:10 mpi Exp $ */ +/* $OpenBSD: in6.c,v 1.135 2014/04/10 13:47:21 mpi Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -750,9 +750,10 @@ 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)) { + struct ifaddr *ifa = &ia6->ia_ifa; if ((ia6->ia_flags & IFA_ROUTE) != 0 && - rtinit(&ia6->ia_ifa, RTM_DELETE, RTF_UP | RTF_HOST)) { + rt_ifa_del(ifa, RTF_HOST, ifa->ifa_dstaddr) != 0) { 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, @@ -1020,8 +1021,7 @@ 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, RTM_DELETE, - RTF_UP | RTF_HOST)) != 0) { + if ((e = rt_ifa_del(ifa, RTF_HOST, ifa->ifa_dstaddr)) != 0) { char addr[INET6_ADDRSTRLEN]; log(LOG_ERR, "in6_purgeaddr: failed to remove " "a route to the p2p destination: %s on %s, " @@ -1388,7 +1388,9 @@ 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, RTM_ADD, RTF_UP | RTF_HOST))) + ifa = &ia6->ia_ifa; + error = rt_ifa_add(ifa, RTF_UP | RTF_HOST, ifa->ifa_dstaddr); + if (error != 0) return (error); ia6->ia_flags |= IFA_ROUTE; } |