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
This commit is contained in:
parent
e54e7d6dae
commit
4b97d7affd
10
sys/net/if.c
10
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
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
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_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
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -654,7 +654,7 @@ in_arpinput(m)
|
||||
* as a dummy address for the rest of the function.
|
||||
*/
|
||||
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
|
||||
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) {
|
||||
if (ifa->ifa_addr->sa_family == AF_INET) {
|
||||
ia = ifatoia(ifa);
|
||||
goto match;
|
||||
}
|
||||
|
@ -206,8 +206,6 @@ divert_packet(struct mbuf *m, int incoming)
|
||||
|
||||
/* Find IP address for receive interface */
|
||||
TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrhead, ifa_link) {
|
||||
if (ifa->ifa_addr == NULL)
|
||||
continue;
|
||||
if (ifa->ifa_addr->sa_family != AF_INET)
|
||||
continue;
|
||||
divsrc.sin_addr =
|
||||
|
@ -465,8 +465,6 @@ iface_match(struct ifnet *ifp, ipfw_insn_if *cmd)
|
||||
|
||||
/* XXX lock? */
|
||||
TAILQ_FOREACH(ia, &ifp->if_addrhead, ifa_link) {
|
||||
if (ia->ifa_addr == NULL)
|
||||
continue;
|
||||
if (ia->ifa_addr->sa_family != AF_INET)
|
||||
continue;
|
||||
if (cmd->p.ip.s_addr == ((struct sockaddr_in *)
|
||||
@ -575,8 +573,6 @@ search_ip6_addr_net (struct in6_addr * ip6_addr)
|
||||
|
||||
TAILQ_FOREACH(mdc, &ifnet, if_link)
|
||||
TAILQ_FOREACH(mdc2, &mdc->if_addrlist, ifa_list) {
|
||||
if (!mdc2->ifa_addr)
|
||||
continue;
|
||||
if (mdc2->ifa_addr->sa_family == AF_INET6) {
|
||||
fdm = (struct in6_ifaddr *)mdc2;
|
||||
copia = fdm->ia_addr.sin6_addr;
|
||||
|
@ -1696,8 +1696,6 @@ in6_ifinit(ifp, ia, sin6, newhost)
|
||||
* and to validate the address if necessary.
|
||||
*/
|
||||
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
|
||||
if (ifa->ifa_addr == NULL)
|
||||
continue; /* just for safety */
|
||||
if (ifa->ifa_addr->sa_family != AF_INET6)
|
||||
continue;
|
||||
ifacount++;
|
||||
@ -1830,8 +1828,6 @@ in6ifa_ifpforlinklocal(ifp, ignoreflags)
|
||||
struct ifaddr *ifa;
|
||||
|
||||
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
|
||||
if (ifa->ifa_addr == NULL)
|
||||
continue; /* just for safety */
|
||||
if (ifa->ifa_addr->sa_family != AF_INET6)
|
||||
continue;
|
||||
if (IN6_IS_ADDR_LINKLOCAL(IFA_IN6(ifa))) {
|
||||
@ -1857,8 +1853,6 @@ in6ifa_ifpwithaddr(ifp, addr)
|
||||
struct ifaddr *ifa;
|
||||
|
||||
TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
|
||||
if (ifa->ifa_addr == NULL)
|
||||
continue; /* just for safety */
|
||||
if (ifa->ifa_addr->sa_family != AF_INET6)
|
||||
continue;
|
||||
if (IN6_ARE_ADDR_EQUAL(addr, IFA_IN6(ifa)))
|
||||
|
@ -494,8 +494,6 @@ MALLOC_DECLARE(M_IP6MADDR);
|
||||
do { \
|
||||
struct ifaddr *ifa; \
|
||||
TAILQ_FOREACH(ifa, &(ifp)->if_addrlist, ifa_list) { \
|
||||
if (!ifa->ifa_addr) \
|
||||
continue; \
|
||||
if (ifa->ifa_addr->sa_family == AF_INET6) \
|
||||
break; \
|
||||
} \
|
||||
|
@ -1048,10 +1048,11 @@ bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
|
||||
|
||||
sdl = NULL;
|
||||
TAILQ_FOREACH(ifa, &ifctx->ifp->if_addrhead, ifa_link)
|
||||
if (ifa->ifa_addr->sa_family == AF_LINK &&
|
||||
(sdl = ((struct sockaddr_dl *) ifa->ifa_addr)) != NULL &&
|
||||
sdl->sdl_type == IFT_ETHER)
|
||||
break;
|
||||
if (ifa->ifa_addr->sa_family == AF_LINK) {
|
||||
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
||||
if (sdl->sdl_type == IFT_ETHER)
|
||||
break;
|
||||
}
|
||||
|
||||
if (sdl == NULL)
|
||||
panic("bootpc: Unable to find HW address for %s",
|
||||
|
@ -132,8 +132,8 @@ nfs_setup_diskless(void)
|
||||
IFNET_RLOCK();
|
||||
TAILQ_FOREACH(ifp, &ifnet, if_link) {
|
||||
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
|
||||
if ((ifa->ifa_addr->sa_family == AF_LINK) &&
|
||||
(sdl = ((struct sockaddr_dl *)ifa->ifa_addr))) {
|
||||
if (ifa->ifa_addr->sa_family == AF_LINK) {
|
||||
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
||||
if ((sdl->sdl_type == ourdl.sdl_type) &&
|
||||
(sdl->sdl_alen == ourdl.sdl_alen) &&
|
||||
!bcmp(LLADDR(sdl),
|
||||
|
Loading…
x
Reference in New Issue
Block a user