diff options
author | wollman <wollman@FreeBSD.org> | 1996-12-13 21:29:07 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 1996-12-13 21:29:07 +0000 |
commit | 3417f9411098d1cd19c5db539c0768e778b83a1c (patch) | |
tree | 782c07e423375f5e3235e7a677261301a91e59c6 /sys/netinet | |
parent | 4ad813db29ba756a35db6540961c86a4c1f5592b (diff) | |
download | FreeBSD-src-3417f9411098d1cd19c5db539c0768e778b83a1c.zip FreeBSD-src-3417f9411098d1cd19c5db539c0768e778b83a1c.tar.gz |
Convert the interface address and IP interface address structures
to TAILQs. Fix places which referenced these for no good reason
that I can see (the references remain, but were fixed to compile
again; they are still questionable).
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/in.c | 76 | ||||
-rw-r--r-- | sys/netinet/in_pcb.c | 17 | ||||
-rw-r--r-- | sys/netinet/in_var.h | 33 | ||||
-rw-r--r-- | sys/netinet/ip_divert.c | 6 | ||||
-rw-r--r-- | sys/netinet/ip_fw.c | 7 | ||||
-rw-r--r-- | sys/netinet/ip_icmp.c | 6 | ||||
-rw-r--r-- | sys/netinet/ip_input.c | 11 | ||||
-rw-r--r-- | sys/netinet/ip_output.c | 5 |
8 files changed, 70 insertions, 91 deletions
diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 878f3bb..4e1df85 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in.c 8.4 (Berkeley) 1/9/95 - * $Id: in.c,v 1.24 1996/04/07 06:59:52 davidg Exp $ + * $Id: in.c,v 1.25 1996/09/09 20:17:24 wollman Exp $ */ #include <sys/param.h> @@ -89,11 +89,13 @@ in_localaddr(in) register struct in_ifaddr *ia; if (subnetsarelocal) { - for (ia = in_ifaddr; ia; ia = ia->ia_next) + for (ia = in_ifaddrhead.tqh_first; ia; + ia = ia->ia_link.tqe_next) if ((i & ia->ia_netmask) == ia->ia_net) return (1); } else { - for (ia = in_ifaddr; ia; ia = ia->ia_next) + for (ia = in_ifaddrhead.tqh_first; ia; + ia = ia->ia_link.tqe_next) if ((i & ia->ia_subnetmask) == ia->ia_subnet) return (1); } @@ -171,7 +173,8 @@ in_control(so, cmd, data, ifp) * the first one on the interface. */ if (ifp) - for (iap = in_ifaddr; iap; iap = iap->ia_next) + for (iap = in_ifaddrhead.tqh_first; iap; + iap = iap->ia_link.tqe_next) if (iap->ia_ifp == ifp) { if (((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr.s_addr == iap->ia_addr.sin_addr.s_addr) { @@ -214,37 +217,24 @@ in_control(so, cmd, data, ifp) if (ifp == 0) panic("in_control"); if (ia == (struct in_ifaddr *)0) { - oia = (struct in_ifaddr *) - malloc(sizeof *oia, M_IFADDR, M_WAITOK); - if (oia == (struct in_ifaddr *)NULL) + ia = (struct in_ifaddr *) + malloc(sizeof *ia, M_IFADDR, M_WAITOK); + if (ia == (struct in_ifaddr *)NULL) return (ENOBUFS); - bzero((caddr_t)oia, sizeof *oia); - ia = in_ifaddr; + bzero((caddr_t)ia, sizeof *ia); /* * Protect from ipintr() traversing address list * while we're modifying it. */ s = splnet(); - - if (ia) { - for ( ; ia->ia_next; ia = ia->ia_next) - continue; - ia->ia_next = oia; - } else - in_ifaddr = oia; - ia = oia; - ifa = ifp->if_addrlist; - if (ifa) { - for ( ; ifa->ifa_next; ifa = ifa->ifa_next) - continue; - ifa->ifa_next = (struct ifaddr *) ia; - } else - ifp->if_addrlist = (struct ifaddr *) ia; - ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr; - ia->ia_ifa.ifa_dstaddr - = (struct sockaddr *)&ia->ia_dstaddr; - ia->ia_ifa.ifa_netmask - = (struct sockaddr *)&ia->ia_sockmask; + + TAILQ_INSERT_TAIL(&in_ifaddrhead, ia, ia_link); + ifa = &ia->ia_ifa; + TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link); + + ifa->ifa_addr = (struct sockaddr *)&ia->ia_addr; + ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr; + ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask; ia->ia_sockmask.sin_len = 8; if (ifp->if_flags & IFF_BROADCAST) { ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr); @@ -371,29 +361,10 @@ in_control(so, cmd, data, ifp) */ s = splnet(); - if ((ifa = ifp->if_addrlist) == (struct ifaddr *)ia) - ifp->if_addrlist = ifa->ifa_next; - else { - while (ifa->ifa_next && - (ifa->ifa_next != (struct ifaddr *)ia)) - ifa = ifa->ifa_next; - if (ifa->ifa_next) - ifa->ifa_next = ((struct ifaddr *)ia)->ifa_next; - else - printf("Couldn't unlink inifaddr from ifp\n"); - } + ifa = &ia->ia_ifa; + TAILQ_REMOVE(&ifp->if_addrhead, ifa, ifa_link); oia = ia; - if (oia == (ia = in_ifaddr)) - in_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 - printf("Didn't unlink inifadr from list\n"); - } - + TAILQ_REMOVE(&in_ifaddrhead, oia, ia_link); if (!oia->ia_multiaddrs.lh_first) { IFAFREE(&oia->ia_ifa); FREE(mk, M_IPMADDR); @@ -603,7 +574,8 @@ in_broadcast(in, ifp) * with a broadcast address. */ #define ia ((struct in_ifaddr *)ifa) - for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) + for (ifa = ifp->if_addrhead.tqh_first; ifa; + ifa = ifa->ifa_link.tqe_next) if (ifa->ifa_addr->sa_family == AF_INET && (in.s_addr == ia->ia_broadaddr.sin_addr.s_addr || in.s_addr == ia->ia_netbroadcast.s_addr || diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index e5da5fc..31fceab 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 - * $Id: in_pcb.c,v 1.22 1996/10/07 19:06:07 davidg Exp $ + * $Id: in_pcb.c,v 1.23 1996/10/30 06:13:09 peter Exp $ */ #include <sys/param.h> @@ -147,7 +147,7 @@ in_pcbbind(inp, nam) int wild = 0, reuseport = (so->so_options & SO_REUSEPORT); int error; - if (in_ifaddr == 0) + if (TAILQ_EMPTY(&in_ifaddrhead)) /* XXX broken! */ return (EADDRNOTAVAIL); if (inp->inp_lport || inp->inp_laddr.s_addr != INADDR_ANY) return (EINVAL); @@ -289,7 +289,7 @@ in_pcbladdr(inp, nam, plocal_sin) return (EAFNOSUPPORT); if (sin->sin_port == 0) return (EADDRNOTAVAIL); - if (in_ifaddr) { + if (!TAILQ_EMPTY(&in_ifaddrhead)) { /* * If the destination address is INADDR_ANY, * use the primary local address. @@ -301,10 +301,10 @@ in_pcbladdr(inp, nam, plocal_sin) #define sintosa(sin) ((struct sockaddr *)(sin)) #define ifatoia(ifa) ((struct in_ifaddr *)(ifa)) if (sin->sin_addr.s_addr == INADDR_ANY) - sin->sin_addr = IA_SIN(in_ifaddr)->sin_addr; + sin->sin_addr = IA_SIN(in_ifaddrhead.tqh_first)->sin_addr; else if (sin->sin_addr.s_addr == (u_long)INADDR_BROADCAST && - (in_ifaddr->ia_ifp->if_flags & IFF_BROADCAST)) - sin->sin_addr = satosin(&in_ifaddr->ia_broadaddr)->sin_addr; + (in_ifaddrhead.tqh_first->ia_ifp->if_flags & IFF_BROADCAST)) + sin->sin_addr = satosin(&in_ifaddrhead.tqh_first->ia_broadaddr)->sin_addr; } if (inp->inp_laddr.s_addr == INADDR_ANY) { register struct route *ro; @@ -349,7 +349,7 @@ in_pcbladdr(inp, nam, plocal_sin) ia = ifatoia(ifa_ifwithnet(sintosa(sin))); sin->sin_port = fport; if (ia == 0) - ia = in_ifaddr; + ia = in_ifaddrhead.tqh_first; if (ia == 0) return (EADDRNOTAVAIL); } @@ -366,7 +366,8 @@ in_pcbladdr(inp, nam, plocal_sin) imo = inp->inp_moptions; if (imo->imo_multicast_ifp != NULL) { ifp = imo->imo_multicast_ifp; - for (ia = in_ifaddr; ia; ia = ia->ia_next) + for (ia = in_ifaddrhead.tqh_first; ia; + ia = ia->ia_link.tqe_next) if (ia->ia_ifp == ifp) break; if (ia == 0) diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h index c71c85a..f349a41 100644 --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)in_var.h 8.2 (Berkeley) 1/9/95 - * $Id: in_var.h,v 1.16 1996/02/05 20:35:59 wollman Exp $ + * $Id: in_var.h,v 1.17 1996/03/14 16:59:19 fenner Exp $ */ #ifndef _NETINET_IN_VAR_H_ @@ -55,6 +55,7 @@ struct in_ifaddr { u_long ia_subnet; /* subnet number, including net */ u_long ia_subnetmask; /* mask of subnet part */ struct in_addr ia_netbroadcast; /* to recognize net broadcasts */ + TAILQ_ENTRY(in_ifaddr) ia_link; /* tailq macro glue */ struct in_ifaddr *ia_next; /* next in list of internet addresses */ struct sockaddr_in ia_addr; /* reserve space for interface name */ struct sockaddr_in ia_dstaddr; /* reserve space for broadcast addr */ @@ -83,7 +84,7 @@ struct in_aliasreq { #ifdef KERNEL -extern struct in_ifaddr *in_ifaddr; +extern TAILQ_HEAD(in_ifaddrhead, in_ifaddr) in_ifaddrhead; extern struct ifqueue ipintrq; /* ip packet input queue */ extern struct in_addr zeroin_addr; extern u_char inetctlerrmap[]; @@ -101,15 +102,15 @@ extern int rtq_toomany; /* XXX */ { \ register struct in_ifaddr *ia; \ \ - for (ia = in_ifaddr; \ + for (ia = in_ifaddrhead.tqh_first; \ ia != NULL && ((ia->ia_ifp->if_flags & IFF_POINTOPOINT)? \ IA_DSTSIN(ia):IA_SIN(ia))->sin_addr.s_addr != (addr).s_addr; \ - ia = ia->ia_next) \ + ia = ia->ia_link.tqe_next) \ continue; \ if (ia == NULL) \ - for (ia = in_ifaddr; \ + for (ia = in_ifaddrhead.tqh_first; \ ia != NULL; \ - ia = ia->ia_next) \ + ia = ia->ia_link.tqe_next) \ if (ia->ia_ifp->if_flags & IFF_POINTOPOINT && \ IA_SIN(ia)->sin_addr.s_addr == (addr).s_addr) \ break; \ @@ -124,9 +125,9 @@ extern int rtq_toomany; /* XXX */ /* struct ifnet *ifp; */ \ /* struct in_ifaddr *ia; */ \ { \ - for ((ia) = in_ifaddr; \ + for ((ia) = in_ifaddrhead.tqh_first; \ (ia) != NULL && (ia)->ia_ifp != (ifp); \ - (ia) = (ia)->ia_next) \ + (ia) = (ia)->ia_link.tqe_next) \ continue; \ } #endif @@ -178,7 +179,7 @@ struct in_multistep { /* struct in_addr addr; */ \ /* struct ifnet *ifp; */ \ /* struct in_multi *inm; */ \ -{ \ +do { \ register struct in_ifaddr *ia; \ \ IFP_TO_IA((ifp), ia); \ @@ -189,7 +190,7 @@ struct in_multistep { (inm) != NULL && (inm)->inm_addr.s_addr != (addr).s_addr; \ (inm) = inm->inm_entry.le_next) \ continue; \ -} +} while(0) /* * Macro to step through all of the in_multi records, one at a time. @@ -201,28 +202,28 @@ struct in_multistep { #define IN_NEXT_MULTI(step, inm) \ /* struct in_multistep step; */ \ /* struct in_multi *inm; */ \ -{ \ +do { \ if (((inm) = (step).i_inm) != NULL) \ (step).i_inm = (inm)->inm_entry.le_next; \ else \ while ((step).i_ia != NULL) { \ (inm) = (step).i_ia->ia_multiaddrs.lh_first; \ - (step).i_ia = (step).i_ia->ia_next; \ + (step).i_ia = (step).i_ia->ia_link.tqe_next; \ if ((inm) != NULL) { \ (step).i_inm = (inm)->inm_entry.le_next; \ break; \ } \ } \ -} +} while(0) #define IN_FIRST_MULTI(step, inm) \ /* struct in_multistep step; */ \ /* struct in_multi *inm; */ \ -{ \ - (step).i_ia = in_ifaddr; \ +do { \ + (step).i_ia = in_ifaddrhead.tqh_first; \ (step).i_inm = NULL; \ IN_NEXT_MULTI((step), (inm)); \ -} +} while(0) struct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *)); void in_delmulti __P((struct in_multi *)); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 7720f84..4e3afa8 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ip_divert.c,v 1.2 1996/06/14 00:28:38 archie Exp $ + * $Id: ip_divert.c,v 1.1 1996/07/10 19:44:22 julian Exp $ */ #include <sys/param.h> @@ -148,8 +148,8 @@ div_input(struct mbuf *m, int hlen) HTONS(ip->ip_id); /* Find IP address for recieve interface */ - for (ifa = m->m_pkthdr.rcvif->if_addrlist; - ifa != NULL; ifa = ifa->ifa_next) { + for (ifa = m->m_pkthdr.rcvif->if_addrhead.tqh_first; + ifa != NULL; ifa = ifa->ifa_link.tqe_next) { if (ifa->ifa_addr == NULL) continue; if (ifa->ifa_addr->sa_family != AF_INET) diff --git a/sys/netinet/ip_fw.c b/sys/netinet/ip_fw.c index 77739b4..d85041f 100644 --- a/sys/netinet/ip_fw.c +++ b/sys/netinet/ip_fw.c @@ -12,7 +12,7 @@ * * This software is provided ``AS IS'' without any warranties of any kind. * - * $Id: ip_fw.c,v 1.50 1996/10/12 19:38:50 alex Exp $ + * $Id: ip_fw.c,v 1.51 1996/10/12 19:49:36 bde Exp $ */ /* @@ -299,7 +299,7 @@ ip_fw_chk(struct ip **pip, int hlen, * first adress */ if (rif != NULL) - ia = rif->if_addrlist; + ia = rif->if_addrhead.tqh_first; /* * Go down the chain, looking for enlightment @@ -347,7 +347,8 @@ ip_fw_chk(struct ip **pip, int hlen, if (!(f->fw_flg & IP_FW_F_IFNAME) && f->fw_via_ip.s_addr) { int match = 0; - for (ia_p = ia; ia_p != NULL; ia_p = ia_p->ifa_next) { + for (ia_p = ia; ia_p != NULL; + ia_p = ia_p->ifa_link.tqe_next) { if ((ia_p->ifa_addr == NULL)) continue; if (ia_p->ifa_addr->sa_family != AF_INET) diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 8fc9eaa..1dbcc43 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94 - * $Id: ip_icmp.c,v 1.21 1996/07/24 18:46:17 wollman Exp $ + * $Id: ip_icmp.c,v 1.22 1996/09/20 08:23:54 pst Exp $ */ #include <sys/param.h> @@ -509,7 +509,7 @@ icmp_reflect(m) * or anonymous), use the address which corresponds * to the incoming interface. */ - for (ia = in_ifaddr; ia; ia = ia->ia_next) { + for (ia = in_ifaddrhead.tqh_first; ia; ia = ia->ia_link.tqe_next) { if (t.s_addr == IA_SIN(ia)->sin_addr.s_addr) break; if (ia->ia_ifp && (ia->ia_ifp->if_flags & IFF_BROADCAST) && @@ -525,7 +525,7 @@ icmp_reflect(m) * and was received on an interface with no IP address. */ if (ia == (struct in_ifaddr *)0) - ia = in_ifaddr; + ia = in_ifaddrhead.tqh_first; t = IA_SIN(ia)->sin_addr; ip->ip_src = t; ip->ip_ttl = MAXTTL; diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 20256b8..969834c 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 - * $Id: ip_input.c,v 1.51 1996/11/11 04:56:15 fenner Exp $ + * $Id: ip_input.c,v 1.52 1996/12/11 03:26:36 davidg Exp $ * $ANA: ip_input.c,v 1.5 1996/09/18 14:34:59 wollman Exp $ */ @@ -102,7 +102,7 @@ extern struct domain inetdomain; extern struct protosw inetsw[]; u_char ip_protox[IPPROTO_MAX]; static int ipqmaxlen = IFQ_MAXLEN; -struct in_ifaddr *in_ifaddr; /* first inet address */ +struct in_ifaddrhead in_ifaddrhead; /* first inet address */ struct ifqueue ipintrq; SYSCTL_INT(_net_inet_ip, IPCTL_INTRQMAXLEN, intr_queue_maxlen, CTLFLAG_RD, &ipintrq.ifq_maxlen, 0, ""); @@ -179,6 +179,7 @@ ip_init() register struct protosw *pr; register int i; + TAILQ_INIT(&in_ifaddrhead); pr = pffindproto(PF_INET, IPPROTO_RAW, SOCK_RAW); if (pr == 0) panic("ip_init"); @@ -223,8 +224,10 @@ ip_input(struct mbuf *m) /* * If no IP addresses have been set yet but the interfaces * are receiving, can't do anything with incoming packets yet. + * XXX This is broken! We should be able to receive broadcasts + * and multicasts even without any local addresses configured. */ - if (in_ifaddr == NULL) + if (TAILQ_EMPTY(&in_ifaddrhead)) goto bad; ipstat.ips_total++; @@ -358,7 +361,7 @@ tooshort: /* * Check our list of addresses, to see if the packet is for us. */ - for (ia = in_ifaddr; ia; ia = ia->ia_next) { + for (ia = in_ifaddrhead.tqh_first; ia; ia = ia->ia_link.tqe_next) { #define satosin(sa) ((struct sockaddr_in *)(sa)) if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr) diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 8addbe6..ba5b4bd 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 - * $Id: ip_output.c,v 1.44 1996/10/22 22:26:02 sos Exp $ + * $Id: ip_output.c,v 1.45 1996/11/11 04:56:19 fenner Exp $ */ #define _IP_VHL @@ -227,7 +227,8 @@ ip_output(m0, opt, ro, flags, imo) if (ip->ip_src.s_addr == INADDR_ANY) { register struct in_ifaddr *ia; - for (ia = in_ifaddr; ia; ia = ia->ia_next) + for (ia = in_ifaddrhead.tqh_first; ia; + ia = ia->ia_link.tqe_next) if (ia->ia_ifp == ifp) { ip->ip_src = IA_SIN(ia)->sin_addr; break; |