diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1998-02-14 18:50:37 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1998-02-14 18:50:37 +0000 |
commit | 3b291c0e8b8fe20433d61bf8f810c613e3a0ec2c (patch) | |
tree | 6a8a1ce1860c0862e596778629ccb6302fe4dd5a /sys/netinet | |
parent | f66b48a343f8e6b8ba7a0ccfe9464627b21aaf5e (diff) |
wildcard ifaces; finally, after HE said it's ok
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/in_pcb.c | 12 | ||||
-rw-r--r-- | sys/netinet/ip_input.c | 54 | ||||
-rw-r--r-- | sys/netinet/ip_var.h | 4 |
3 files changed, 43 insertions, 27 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index ce69820bb54..e0b35d2c4c6 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.22 1998/02/14 10:55:10 deraadt Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.23 1998/02/14 18:50:35 mickey Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -189,7 +189,7 @@ in_pcbbind(v, nam) reuseport = SO_REUSEADDR|SO_REUSEPORT; } else if (sin->sin_addr.s_addr != INADDR_ANY) { sin->sin_port = 0; /* yech... */ - if (ifa_ifwithaddr(sintosa(sin)) == 0) + if (in_iawithaddr(sin->sin_addr, NULL) == 0) return (EADDRNOTAVAIL); } if (lport) { @@ -656,12 +656,10 @@ in_pcblookup(table, faddr, fport_arg, laddr, lport_arg, flags) if (laddr.s_addr != INADDR_ANY) wildcard++; } - if (wildcard && (flags & INPLOOKUP_WILDCARD) == 0) - continue; - if (wildcard < matchwild) { + if ((!wildcard || (flags & INPLOOKUP_WILDCARD)) && + wildcard < matchwild) { match = inp; - matchwild = wildcard; - if (matchwild == 0) + if ((matchwild = wildcard) == 0) break; } } diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index fc76ac7eb38..7b6991b2afe 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.29 1998/02/03 21:11:08 deraadt Exp $ */ +/* $OpenBSD: ip_input.c,v 1.30 1998/02/14 18:50:36 mickey Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -196,7 +196,6 @@ ipintr() register struct ip *ip; register struct mbuf *m; register struct ipq *fp; - register struct in_ifaddr *ia; struct ipqent *ipqe; int hlen, mff, s; @@ -306,23 +305,9 @@ next: /* * Check our list of addresses, to see if the packet is for us. */ - for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) { - if (ip->ip_dst.s_addr == ia->ia_addr.sin_addr.s_addr) - goto ours; - if (((ip_directedbcast == 0) || (ip_directedbcast && - ia->ia_ifp == m->m_pkthdr.rcvif)) && - (ia->ia_ifp->if_flags & IFF_BROADCAST)) { - if (ip->ip_dst.s_addr == ia->ia_broadaddr.sin_addr.s_addr || - ip->ip_dst.s_addr == ia->ia_netbroadcast.s_addr || - /* - * Look for all-0's host part (old broadcast addr), - * either for subnet or net. - */ - ip->ip_dst.s_addr == ia->ia_subnet || - ip->ip_dst.s_addr == ia->ia_net) - goto ours; - } - } + if (in_iawithaddr(ip->ip_dst, m)) + goto ours; + if (IN_MULTICAST(ip->ip_dst.s_addr)) { struct in_multi *inm; #ifdef MROUTING @@ -478,6 +463,37 @@ bad: goto next; } +struct in_ifaddr * +in_iawithaddr(ina, m) + struct in_addr ina; + register struct mbuf *m; +{ + register struct in_ifaddr *ia; + + for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) { + if ((ina.s_addr == ia->ia_addr.sin_addr.s_addr) || + ((ia->ia_ifp->if_flags & (IFF_LOOPBACK|IFF_LINK1)) == + (IFF_LOOPBACK|IFF_LINK1) && + ia->ia_subnet == (ina.s_addr & ia->ia_subnetmask))) + return ia; + if (m && ((ip_directedbcast == 0) || (ip_directedbcast && + ia->ia_ifp == m->m_pkthdr.rcvif)) && + (ia->ia_ifp->if_flags & IFF_BROADCAST)) { + if (ina.s_addr == ia->ia_broadaddr.sin_addr.s_addr || + ina.s_addr == ia->ia_netbroadcast.s_addr || + /* + * Look for all-0's host part (old broadcast addr), + * either for subnet or net. + */ + ina.s_addr == ia->ia_subnet || + ina.s_addr == ia->ia_net) + return ia; + } + } + + return NULL; +} + /* * Take incoming datagram fragment and try to * reassemble it into whole datagram. If a chain for diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index bb192317902..77afb80f922 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.7 1998/02/01 21:46:03 deraadt Exp $ */ +/* $OpenBSD: ip_var.h,v 1.8 1998/02/14 18:50:36 mickey Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -178,6 +178,8 @@ int ip_pcbopts __P((struct mbuf **, struct mbuf *)); struct ip * ip_reass __P((struct ipqent *, struct ipq *)); struct in_ifaddr * + in_iawithaddr __P((struct in_addr, struct mbuf *)); +struct in_ifaddr * ip_rtaddr __P((struct in_addr)); int ip_setmoptions __P((int, struct ip_moptions **, struct mbuf *)); void ip_slowtimo __P((void)); |