diff options
author | 2013-03-25 14:40:56 +0000 | |
---|---|---|
committer | 2013-03-25 14:40:56 +0000 | |
commit | a0fa8079210a385c1e323ee3c2424198d60ab01d (patch) | |
tree | c58ec14ed9f8ced58e390f2914229f2c825c19b1 | |
parent | sync w/ospfd: improve snapshot handling; ok claudio, sthen (diff) | |
download | wireguard-openbsd-a0fa8079210a385c1e323ee3c2424198d60ab01d.tar.xz wireguard-openbsd-a0fa8079210a385c1e323ee3c2424198d60ab01d.zip |
Substitute the handcrafted list of IPv6 addresses by a proper TAILQ.
ok bluhm@, mikeb@
-rw-r--r-- | sys/netinet/ip_carp.c | 4 | ||||
-rw-r--r-- | sys/netinet6/icmp6.c | 4 | ||||
-rw-r--r-- | sys/netinet6/in6.c | 47 | ||||
-rw-r--r-- | sys/netinet6/in6_ifattach.c | 24 | ||||
-rw-r--r-- | sys/netinet6/in6_pcb.c | 6 | ||||
-rw-r--r-- | sys/netinet6/in6_var.h | 12 | ||||
-rw-r--r-- | sys/netinet6/ip6_input.c | 5 | ||||
-rw-r--r-- | sys/netinet6/nd6.c | 10 | ||||
-rw-r--r-- | sys/netinet6/nd6_rtr.c | 8 |
9 files changed, 42 insertions, 78 deletions
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 1538238e398..35cce892b9e 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_carp.c,v 1.199 2013/03/22 01:41:12 tedu Exp $ */ +/* $OpenBSD: ip_carp.c,v 1.200 2013/03/25 14:40:56 mpi Exp $ */ /* * Copyright (c) 2002 Michael Shalayeff. All rights reserved. @@ -2109,7 +2109,7 @@ carp_set_addr6(struct carp_softc *sc, struct sockaddr_in6 *sin6) /* we have to do this by hand to ensure we don't match on ourselves */ ia_if = NULL; - for (ia = in6_ifaddr; ia; ia = ia->ia_next) { + TAILQ_FOREACH(ia, &in6_ifaddr, ia_list) { int i; for (i = 0; i < 4; i++) { diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 2fb34c20bf8..30c3651a876 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.121 2013/03/22 01:41:12 tedu Exp $ */ +/* $OpenBSD: icmp6.c,v 1.122 2013/03/25 14:40:56 mpi Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -2040,7 +2040,7 @@ icmp6_reflect(struct mbuf *m, size_t off) * (for example) when we encounter an error while forwarding procedure * destined to a duplicated address of ours. */ - for (ia = in6_ifaddr; ia; ia = ia->ia_next) + TAILQ_FOREACH(ia, &in6_ifaddr, ia_list) if (IN6_ARE_ADDR_EQUAL(&t, &ia->ia_addr.sin6_addr) && (ia->ia6_flags & (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY)) == 0) { src = &t; diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 14c37566eaa..3648372103f 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.108 2013/03/22 01:41:12 tedu Exp $ */ +/* $OpenBSD: in6.c,v 1.109 2013/03/25 14:40:57 mpi Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -267,7 +267,7 @@ in6_ifremloop(struct ifaddr *ifa) * (probably p2p) interfaces. * XXX: we should avoid such a configuration in IPv6... */ - for (ia = in6_ifaddr; ia; ia = ia->ia_next) { + TAILQ_FOREACH(ia, &in6_ifaddr, ia_list) { if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa), &ia->ia_addr.sin6_addr)) { ia_count++; if (ia_count > 1) @@ -743,7 +743,6 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, struct in6_ifaddr *ia) { int error = 0, hostIsNew = 0, plen = -1; - struct in6_ifaddr *oia; struct sockaddr_in6 dst6; struct in6_addrlifetime *lt; struct in6_multi_mship *imm; @@ -899,12 +898,7 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, (struct sockaddr *)&ia->ia_prefixmask; ia->ia_ifp = ifp; - if ((oia = in6_ifaddr) != NULL) { - for ( ; oia->ia_next; oia = oia->ia_next) - continue; - oia->ia_next = ia; - } else - in6_ifaddr = ia; + TAILQ_INSERT_TAIL(&in6_ifaddr, ia, ia_list); ia->ia_addr = ifra->ifra_addr; ifa_add(ifp, &ia->ia_ifa); } @@ -1235,46 +1229,33 @@ in6_purgeaddr(struct ifaddr *ifa) void in6_unlink_ifa(struct in6_ifaddr *ia, struct ifnet *ifp) { - struct in6_ifaddr *oia; int s = splnet(); ifa_del(ifp, &ia->ia_ifa); - oia = ia; - if (oia == (ia = in6_ifaddr)) - in6_ifaddr = ia->ia_next; - else { - while (ia->ia_next && (ia->ia_next != oia)) - ia = ia->ia_next; - if (ia->ia_next) - ia->ia_next = oia->ia_next; - else { - /* search failed */ - printf("Couldn't unlink in6_ifaddr from in6_ifaddr\n"); - } - } + TAILQ_REMOVE(&in6_ifaddr, ia, ia_list); - if (!LIST_EMPTY(&oia->ia6_multiaddrs)) { - in6_savemkludge(oia); + if (!LIST_EMPTY(&ia->ia6_multiaddrs)) { + in6_savemkludge(ia); } /* Release the reference to the base prefix. */ - if (oia->ia6_ndpr == NULL) { - if (!IN6_IS_ADDR_LINKLOCAL(IA6_IN6(oia))) + if (ia->ia6_ndpr == NULL) { + if (!IN6_IS_ADDR_LINKLOCAL(IA6_IN6(ia))) log(LOG_NOTICE, "in6_unlink_ifa: interface address " - "%p has no prefix\n", oia); + "%p has no prefix\n", ia); } else { - oia->ia6_flags &= ~IN6_IFF_AUTOCONF; - if (--oia->ia6_ndpr->ndpr_refcnt == 0) - prelist_remove(oia->ia6_ndpr); - oia->ia6_ndpr = NULL; + ia->ia6_flags &= ~IN6_IFF_AUTOCONF; + if (--ia->ia6_ndpr->ndpr_refcnt == 0) + prelist_remove(ia->ia6_ndpr); + ia->ia6_ndpr = NULL; } /* * release another refcnt for the link from in6_ifaddr. * Note that we should decrement the refcnt at least once for all *BSD. */ - ifafree(&oia->ia_ifa); + ifafree(&ia->ia_ifa); splx(s); } diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index da97be5c5ca..00ef34a6bc5 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_ifattach.c,v 1.58 2013/03/07 09:03:16 mpi Exp $ */ +/* $OpenBSD: in6_ifattach.c,v 1.59 2013/03/25 14:40:57 mpi Exp $ */ /* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */ /* @@ -653,7 +653,7 @@ in6_ifattach(struct ifnet *ifp, struct ifnet *altifp) void in6_ifdetach(struct ifnet *ifp) { - struct in6_ifaddr *ia, *oia; + struct in6_ifaddr *ia; struct ifaddr *ifa, *next; struct rtentry *rt; struct sockaddr_in6 sin6; @@ -717,23 +717,9 @@ in6_ifdetach(struct ifnet *ifp) ifa_del(ifp, &ia->ia_ifa); ifafree(&ia->ia_ifa); - /* also remove from the IPv6 address chain(itojun&jinmei) */ - oia = ia; - if (oia == (ia = in6_ifaddr)) - in6_ifaddr = ia->ia_next; - else { - while (ia->ia_next && (ia->ia_next != oia)) - ia = ia->ia_next; - if (ia->ia_next) - ia->ia_next = oia->ia_next; - else { - nd6log((LOG_ERR, - "%s: didn't unlink in6ifaddr from list\n", - ifp->if_xname)); - } - } - - ifafree(&oia->ia_ifa); + /* also remove from the IPv6 address list */ + TAILQ_REMOVE(&in6_ifaddr, ia, ia_list); + ifafree(&ia->ia_ifa); } /* cleanup multicast address kludge table, if there is any */ diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index acf98f22a99..22c130cf21b 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.51 2013/03/04 14:42:25 bluhm Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.52 2013/03/25 14:40:57 mpi Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -129,8 +129,6 @@ #include <dev/rndvar.h> -extern struct in6_ifaddr *in6_ifaddr; - /* * Globals */ @@ -176,7 +174,7 @@ in6_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p) * REMINDER: Once up to speed, flow label processing should go here, * too. (Same with in6_pcbconnect.) */ - if (in6_ifaddr == 0) + if (TAILQ_EMPTY(&in6_ifaddr)) return EADDRNOTAVAIL; if (inp->inp_lport != 0 || !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h index 055cad62c24..357cacbef2a 100644 --- a/sys/netinet6/in6_var.h +++ b/sys/netinet6/in6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_var.h,v 1.38 2013/03/22 01:41:12 tedu Exp $ */ +/* $OpenBSD: in6_var.h,v 1.39 2013/03/25 14:40:57 mpi Exp $ */ /* $KAME: in6_var.h,v 1.55 2001/02/16 12:49:45 itojun Exp $ */ /* @@ -99,12 +99,13 @@ struct in6_ifaddr { struct ifaddr ia_ifa; /* protocol-independent info */ #define ia_ifp ia_ifa.ifa_ifp #define ia_flags ia_ifa.ifa_flags + struct sockaddr_in6 ia_addr; /* interface address */ struct sockaddr_in6 ia_net; /* network number of interface */ struct sockaddr_in6 ia_dstaddr; /* space for destination addr */ struct sockaddr_in6 ia_prefixmask; /* prefix mask */ u_int32_t ia_plen; /* prefix length */ - struct in6_ifaddr *ia_next; /* next in6 list of IP6 addresses */ + TAILQ_ENTRY(in6_ifaddr) ia_list; /* list of IP6 addresses */ LIST_HEAD(in6_multihead, in6_multi) ia6_multiaddrs; /* list of multicast addresses */ int ia6_flags; @@ -452,7 +453,8 @@ struct in6_rrenumreq { #endif #ifdef _KERNEL -extern struct in6_ifaddr *in6_ifaddr; +TAILQ_HEAD(in6_ifaddrhead, in6_ifaddr); +extern struct in6_ifaddrhead in6_ifaddr; extern struct icmp6stat icmp6stat; #define in6_ifstat_inc(ifp, tag) \ @@ -554,7 +556,7 @@ do { \ else \ while ((step).i_ia != NULL) { \ (in6m) = LIST_FIRST(&(step).i_ia->ia6_multiaddrs); \ - (step).i_ia = (step).i_ia->ia_next; \ + (step).i_ia = TAILQ_NEXT((step).i_ia, ia_list); \ if ((in6m) != NULL) { \ (step).i_in6m = LIST_NEXT((in6m), in6m_entry); \ break; \ @@ -566,7 +568,7 @@ do { \ /* struct in6_multistep step; */ \ /* struct in6_multi *in6m */ \ do { \ - (step).i_ia = in6_ifaddr; \ + (step).i_ia = TAILQ_FIRST(&in6_ifaddr); \ (step).i_in6m = NULL; \ IN6_NEXT_MULTI((step), (in6m)); \ } while (0) diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 81f7dc91d01..aa18db46f59 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.107 2013/03/14 11:18:37 mpi Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.108 2013/03/25 14:40:57 mpi Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -122,7 +122,7 @@ extern struct ip6protosw inet6sw[]; u_char ip6_protox[IPPROTO_MAX]; static int ip6qmaxlen = IFQ_MAXLEN; -struct in6_ifaddr *in6_ifaddr; +struct in6_ifaddrhead in6_ifaddr; struct ifqueue ip6intrq; struct ip6stat ip6stat; @@ -155,6 +155,7 @@ ip6_init(void) pr->pr_protocol < IPPROTO_MAX) ip6_protox[pr->pr_protocol] = pr - inet6sw; IFQ_SET_MAXLEN(&ip6intrq, ip6qmaxlen); + TAILQ_INIT(&in6_ifaddr); ip6_randomid_init(); nd6_init(); frag6_init(); diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 52394f0bd36..eb2c8c82459 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.96 2013/03/22 00:59:25 bluhm Exp $ */ +/* $OpenBSD: nd6.c,v 1.97 2013/03/25 14:40:57 mpi Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -526,8 +526,7 @@ nd6_timer(void *ignored_arg) * However, from a stricter spec-conformance standpoint, we should * rather separate address lifetimes and prefix lifetimes. */ - for (ia6 = in6_ifaddr; ia6; ia6 = nia6) { - nia6 = ia6->ia_next; + TAILQ_FOREACH_SAFE(ia6, &in6_ifaddr, ia_list, nia6) { /* check address lifetime */ if (IFA6_IS_INVALID(ia6)) { in6_purgeaddr(&ia6->ia_ifa); @@ -1372,10 +1371,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp) continue; /* XXX */ /* do we really have to remove addresses as well? */ - for (ia = in6_ifaddr; ia; ia = ia_next) { - /* ia might be removed. keep the next ptr. */ - ia_next = ia->ia_next; - + TAILQ_FOREACH_SAFE(ia, &in6_ifaddr, ia_list, ia_next) { if ((ia->ia6_flags & IN6_IFF_AUTOCONF) == 0) continue; diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index b59280c6797..a5cd36f1a19 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.68 2013/03/11 14:08:04 mpi Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.69 2013/03/25 14:40:57 mpi Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -1508,7 +1508,7 @@ pfxlist_onlink_check(void) * always be attached. * The precise detection logic is same as the one for prefixes. */ - for (ifa = in6_ifaddr; ifa; ifa = ifa->ia_next) { + TAILQ_FOREACH(ifa, &in6_ifaddr, ia_list) { if (!(ifa->ia6_flags & IN6_IFF_AUTOCONF)) continue; @@ -1525,7 +1525,7 @@ pfxlist_onlink_check(void) break; } if (ifa) { - for (ifa = in6_ifaddr; ifa; ifa = ifa->ia_next) { + TAILQ_FOREACH(ifa, &in6_ifaddr, ia_list) { if ((ifa->ia6_flags & IN6_IFF_AUTOCONF) == 0) continue; @@ -1539,7 +1539,7 @@ pfxlist_onlink_check(void) } } else { - for (ifa = in6_ifaddr; ifa; ifa = ifa->ia_next) { + TAILQ_FOREACH(ifa, &in6_ifaddr, ia_list) { if ((ifa->ia6_flags & IN6_IFF_AUTOCONF) == 0) continue; |