diff options
-rw-r--r-- | share/man/man4/lo.4 | 24 | ||||
-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 |
4 files changed, 64 insertions, 30 deletions
diff --git a/share/man/man4/lo.4 b/share/man/man4/lo.4 index 0491936b493..f73e93a9439 100644 --- a/share/man/man4/lo.4 +++ b/share/man/man4/lo.4 @@ -1,3 +1,4 @@ +.\" $OpenBSD: lo.4,v 1.4 1998/02/14 18:50:34 mickey Exp $ .\" $NetBSD: lo.4,v 1.3 1994/11/30 16:22:23 jtc Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 @@ -40,8 +41,7 @@ .Nm lo .Nd software loopback network interface .Sh SYNOPSIS -.Sy pseudo-device -.Nm loop +.Sy pseudo-device Nm loop Em <number> .Sh DESCRIPTION The .Nm loop @@ -60,6 +60,14 @@ The loopback should .Em never be configured first unless no hardware interfaces exist. +.Pp +Configuring loopback interface for +.Xr inet 4 +with +.Em link1 +flag set you achieve a functionality such as equivalent to setting +the whole set of addresses wich belongs to the sub/super-net of the +address and netmask configured on the interface. .Sh DIAGNOSTICS .Bl -diag .It lo%d: can't handle af%d. @@ -67,15 +75,25 @@ The interface was handed a message with addresses formatted in an unsuitable address family; the packet was dropped. .El +.Sh EXAMPLES +ifconfig lo1 inet 192.168.1.1 netmask 255.255.255.0 link1 +this would configure lo1 the way equivalent to: +.Pp +awk 'BEGIN {for(i=1;i<255;i++) \ +print "ifconfig lo1 inet 192.168.1."i" netmask 255.255.255.255"}'|sh .Sh SEE ALSO .Xr intro 4 , .Xr inet 4 , -.Xr ns 4 +.Xr ns 4 , +.Xr ifconfig 8 .Sh HISTORY The .Nm device appeared in .Bx 4.2 . +.Pp +The wildcard functionality first appeared in +.Ox 2.2 . .Sh BUGS Previous versions of the system enabled the loopback interface automatically, using a nonstandard Internet address (127.1). 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)); |