diff options
author | yar <yar@FreeBSD.org> | 2006-06-29 19:22:05 +0000 |
---|---|---|
committer | yar <yar@FreeBSD.org> | 2006-06-29 19:22:05 +0000 |
commit | ba19b1ecd4d6f2950416c0596e5007ae8ffb5360 (patch) | |
tree | 3d6a9cdea9fbb33471c0beed7b40c5ae89e5a37c /sys/net | |
parent | fb752eb168e0c0461ca9c98b0c8452c4d96ec4a7 (diff) | |
download | FreeBSD-src-ba19b1ecd4d6f2950416c0596e5007ae8ffb5360.zip FreeBSD-src-ba19b1ecd4d6f2950416c0596e5007ae8ffb5360.tar.gz |
There is a consensus that ifaddr.ifa_addr should never be NULL,
except in places dealing with ifaddr creation or destruction; and
in such special places incomplete ifaddrs should never be linked
to system-wide data structures. Therefore we can eliminate all the
superfluous checks for "ifa->ifa_addr != NULL" and get ready
to the system crashing honestly instead of masking possible bugs.
Suggested by: glebius, jhb, ru
Diffstat (limited to 'sys/net')
-rw-r--r-- | sys/net/if.c | 10 | ||||
-rw-r--r-- | sys/net/if_atmsubr.c | 4 | ||||
-rw-r--r-- | sys/net/if_stf.c | 2 | ||||
-rw-r--r-- | sys/net/if_tun.c | 33 |
4 files changed, 20 insertions, 29 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index f92c930..d540c95 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -581,12 +581,11 @@ if_purgeaddrs(struct ifnet *ifp) struct ifaddr *ifa, *next; TAILQ_FOREACH_SAFE(ifa, &ifp->if_addrhead, ifa_link, next) { - - if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_LINK) + if (ifa->ifa_addr->sa_family == AF_LINK) continue; #ifdef INET /* XXX: Ugly!! ad hoc just for INET */ - if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { + if (ifa->ifa_addr->sa_family == AF_INET) { struct ifaliasreq ifr; bzero(&ifr, sizeof(ifr)); @@ -599,7 +598,7 @@ if_purgeaddrs(struct ifnet *ifp) } #endif /* INET */ #ifdef INET6 - if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6) { + if (ifa->ifa_addr->sa_family == AF_INET6) { in6_purgeaddr(ifa); /* ifp_addrhead is already updated */ continue; @@ -2404,8 +2403,7 @@ if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len) * the address change. */ TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { - if (ifa->ifa_addr != NULL && - ifa->ifa_addr->sa_family == AF_INET) + if (ifa->ifa_addr->sa_family == AF_INET) arp_ifinit(ifp, ifa); } #endif diff --git a/sys/net/if_atmsubr.c b/sys/net/if_atmsubr.c index 00f89d0..d3f7956 100644 --- a/sys/net/if_atmsubr.c +++ b/sys/net/if_atmsubr.c @@ -387,8 +387,8 @@ atm_ifattach(struct ifnet *ifp) #elif defined(__FreeBSD__) || defined(__bsdi__) for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) #endif - if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) && - sdl->sdl_family == AF_LINK) { + if (ifa->ifa_addr->sa_family == AF_LINK) { + sdl = (struct sockaddr_dl *)ifa->ifa_addr; sdl->sdl_type = IFT_ATM; sdl->sdl_alen = ifp->if_addrlen; #ifdef notyet /* if using ATMARP, store hardware address using the next line */ diff --git a/sys/net/if_stf.c b/sys/net/if_stf.c index 23f51cc..594b648 100644 --- a/sys/net/if_stf.c +++ b/sys/net/if_stf.c @@ -368,8 +368,6 @@ stf_getsrcifa6(ifp) struct in_addr in; TAILQ_FOREACH(ia, &ifp->if_addrlist, ifa_list) { - if (ia->ifa_addr == NULL) - continue; if (ia->ifa_addr->sa_family != AF_INET6) continue; sin6 = (struct sockaddr_in6 *)ia->ifa_addr; diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index deee367..b0d0e42 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -393,28 +393,23 @@ tuninit(struct ifnet *ifp) ifp->if_drv_flags |= IFF_DRV_RUNNING; getmicrotime(&ifp->if_lastchange); - TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { - if (ifa->ifa_addr == NULL) - error = EFAULT; - /* XXX: Should maybe return straight off? */ - else { #ifdef INET - if (ifa->ifa_addr->sa_family == AF_INET) { - struct sockaddr_in *si; - - si = (struct sockaddr_in *)ifa->ifa_addr; - mtx_lock(&tp->tun_mtx); - if (si->sin_addr.s_addr) - tp->tun_flags |= TUN_IASET; - - si = (struct sockaddr_in *)ifa->ifa_dstaddr; - if (si && si->sin_addr.s_addr) - tp->tun_flags |= TUN_DSTADDR; - mtx_unlock(&tp->tun_mtx); - } -#endif + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family == AF_INET) { + struct sockaddr_in *si; + + si = (struct sockaddr_in *)ifa->ifa_addr; + mtx_lock(&tp->tun_mtx); + if (si->sin_addr.s_addr) + tp->tun_flags |= TUN_IASET; + + si = (struct sockaddr_in *)ifa->ifa_dstaddr; + if (si && si->sin_addr.s_addr) + tp->tun_flags |= TUN_DSTADDR; + mtx_unlock(&tp->tun_mtx); } } +#endif return (error); } |