From c6e49a3d6c2e71354c9e8c0d30443242e0c95e59 Mon Sep 17 00:00:00 2001 From: mpi Date: Wed, 7 May 2014 08:26:38 +0000 Subject: [PATCH] Remove the last hacks concerning the global list of IPv4 addresses in the source address selection logic. These hacks were only relevant for the NFS diskless boot code in order to pick the local broadcast address of the only configured interface. So, be explicit and set this address directly. Tested by florian@, ok henning@, beck@, chrisz@ --- sys/netinet/in_pcb.c | 23 ++++------------------- sys/netinet/ip_input.c | 8 +------- sys/nfs/nfs_boot.c | 14 ++++++++++---- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 7a08d386c81..ec4d707d3bd 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.c,v 1.154 2014/04/18 10:48:29 jca Exp $ */ +/* $OpenBSD: in_pcb.c,v 1.155 2014/05/07 08:26:38 mpi Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* @@ -230,8 +230,6 @@ in_pcbbind(struct inpcb *inp, struct mbuf *nam, struct proc *p) return in6_pcbbind(inp, nam, p); #endif /* INET6 */ - if (TAILQ_EMPTY(&in_ifaddr)) - return (EADDRNOTAVAIL); if (inp->inp_lport || inp->inp_laddr.s_addr != INADDR_ANY) return (EINVAL); if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) == 0 && @@ -781,17 +779,6 @@ in_selectsrc(struct in_addr **insrc, struct sockaddr_in *sin, struct sockaddr_in *sin2; struct in_ifaddr *ia = NULL; - if (!TAILQ_EMPTY(&in_ifaddr)) { - if (sin->sin_addr.s_addr == INADDR_ANY) - sin->sin_addr = - TAILQ_FIRST(&in_ifaddr)->ia_addr.sin_addr; - else if (sin->sin_addr.s_addr == INADDR_BROADCAST && - (TAILQ_FIRST(&in_ifaddr)->ia_ifp->if_flags & IFF_BROADCAST) && - TAILQ_FIRST(&in_ifaddr)->ia_broadaddr.sin_addr.s_addr) - sin->sin_addr = - TAILQ_FIRST(&in_ifaddr)->ia_broadaddr.sin_addr; - } - /* * If the source address is not specified but the socket(if any) * is already bound, use the bound address. @@ -850,11 +837,9 @@ in_selectsrc(struct in_addr **insrc, struct sockaddr_in *sin, */ if (ro->ro_rt && ro->ro_rt->rt_ifp) ia = ifatoia(ro->ro_rt->rt_ifa); - if (ia == NULL) { - ia = TAILQ_FIRST(&in_ifaddr); - if (ia == NULL) - return (EADDRNOTAVAIL); - } + + if (ia == NULL) + return (EADDRNOTAVAIL); *insrc = &ia->ia_addr.sin_addr; return (0); diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 3570648998b..c24403dae0b 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.231 2014/04/21 12:22:26 henning Exp $ */ +/* $OpenBSD: ip_input.c,v 1.232 2014/05/07 08:26:38 mpi Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -238,12 +238,6 @@ ipv4_input(struct mbuf *m) ifp = m->m_pkthdr.rcvif; - /* - * If no IP addresses have been set yet but the interfaces - * are receiving, can't do anything with incoming packets yet. - */ - if (TAILQ_EMPTY(&in_ifaddr)) - goto bad; ipstat.ips_total++; if (m->m_len < sizeof (struct ip) && (m = m_pullup(m, sizeof (struct ip))) == NULL) { diff --git a/sys/nfs/nfs_boot.c b/sys/nfs/nfs_boot.c index c3d6752570a..116f8e24a6b 100644 --- a/sys/nfs/nfs_boot.c +++ b/sys/nfs/nfs_boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_boot.c,v 1.31 2014/03/20 09:18:01 mpi Exp $ */ +/* $OpenBSD: nfs_boot.c,v 1.32 2014/05/07 08:26:38 mpi Exp $ */ /* $NetBSD: nfs_boot.c,v 1.26 1996/05/07 02:51:25 thorpej Exp $ */ /* @@ -121,6 +121,7 @@ nfs_boot_init(struct nfs_diskless *nd, struct proc *procp) struct sockaddr_in *sin; struct ifnet *ifp; struct socket *so; + struct ifaddr *ifa; char addr[INET_ADDRSTRLEN]; int error; @@ -192,18 +193,23 @@ nfs_boot_init(struct nfs_diskless *nd, struct proc *procp) soclose(so); + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { + if (ifa->ifa_addr->sa_family == AF_INET) + break; + } + if (ifa == NULL) + panic("nfs_boot: address not configured on %s", ifp->if_xname); + /* * Get client name and gateway address. * RPC: bootparam/whoami - * Use the old broadcast address for the WHOAMI - * call because we do not yet know our netmask. * The server address returned by the WHOAMI call * is used for all subsequent bootparam RPCs. */ bzero((caddr_t)&bp_sin, sizeof(bp_sin)); bp_sin.sin_len = sizeof(bp_sin); bp_sin.sin_family = AF_INET; - bp_sin.sin_addr.s_addr = INADDR_BROADCAST; + bp_sin.sin_addr.s_addr = ifatoia(ifa)->ia_broadaddr.sin_addr.s_addr; hostnamelen = MAXHOSTNAMELEN; /* this returns gateway IP address */ -- 2.20.1