Lines 410-424
ip_input(struct mbuf *m)
Link Here
|
410 |
|
411 |
|
411 |
IP_PROBE(receive, NULL, NULL, ip, m->m_pkthdr.rcvif, ip, NULL); |
412 |
IP_PROBE(receive, NULL, NULL, ip, m->m_pkthdr.rcvif, ip, NULL); |
412 |
|
413 |
|
413 |
/* 127/8 must not appear on wire - RFC1122 */ |
414 |
IFNET_RLOCK_NOSLEEP(); |
414 |
ifp = m->m_pkthdr.rcvif; |
415 |
ifp = m->m_pkthdr.rcvif; |
|
|
416 |
if (ifp == NULL || (ifp->if_flags & IFF_DYING)) { |
417 |
IFNET_RUNLOCK_NOSLEEP(); |
418 |
IPSTAT_INC(ips_odropped); |
419 |
goto bad; |
420 |
} |
421 |
if_ref(ifp); |
422 |
IFNET_RUNLOCK_NOSLEEP(); |
423 |
|
424 |
/* 127/8 must not appear on wire - RFC1122 */ |
415 |
if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || |
425 |
if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || |
416 |
(ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { |
426 |
(ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { |
417 |
if ((ifp->if_flags & IFF_LOOPBACK) == 0) { |
427 |
if ((ifp->if_flags & IFF_LOOPBACK) == 0) { |
418 |
IPSTAT_INC(ips_badaddr); |
428 |
IPSTAT_INC(ips_badaddr); |
|
|
429 |
if_rele(ifp); |
419 |
goto bad; |
430 |
goto bad; |
420 |
} |
431 |
} |
421 |
} |
432 |
} |
|
|
433 |
if_rele(ifp); |
422 |
|
434 |
|
423 |
if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED) { |
435 |
if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED) { |
424 |
sum = !(m->m_pkthdr.csum_flags & CSUM_IP_VALID); |
436 |
sum = !(m->m_pkthdr.csum_flags & CSUM_IP_VALID); |
Lines 490-498
tooshort:
Link Here
|
490 |
if (m == NULL) /* consumed by filter */ |
502 |
if (m == NULL) /* consumed by filter */ |
491 |
return; |
503 |
return; |
492 |
|
504 |
|
|
|
505 |
/* |
506 |
* PFIL may have changed m->m_pkthdr.rcvif (ifp), |
507 |
* so do not use ifp from this point without re-init/lock. |
508 |
*/ |
509 |
|
493 |
ip = mtod(m, struct ip *); |
510 |
ip = mtod(m, struct ip *); |
494 |
dchg = (odst.s_addr != ip->ip_dst.s_addr); |
511 |
dchg = (odst.s_addr != ip->ip_dst.s_addr); |
495 |
ifp = m->m_pkthdr.rcvif; |
|
|
496 |
|
512 |
|
497 |
if (m->m_flags & M_FASTFWD_OURS) { |
513 |
if (m->m_flags & M_FASTFWD_OURS) { |
498 |
m->m_flags &= ~M_FASTFWD_OURS; |
514 |
m->m_flags &= ~M_FASTFWD_OURS; |
Lines 539-544
passin:
Link Here
|
539 |
(m->m_flags & (M_MCAST|M_BCAST)) == 0) |
555 |
(m->m_flags & (M_MCAST|M_BCAST)) == 0) |
540 |
goto ours; |
556 |
goto ours; |
541 |
|
557 |
|
|
|
558 |
IFNET_RLOCK_NOSLEEP(); |
559 |
ifp = m->m_pkthdr.rcvif; |
560 |
if (ifp == NULL || (ifp->if_flags & IFF_DYING)) { |
561 |
IFNET_RUNLOCK_NOSLEEP(); |
562 |
IPSTAT_INC(ips_odropped); |
563 |
goto bad; |
564 |
} |
565 |
if_ref(ifp); |
566 |
IFNET_RUNLOCK_NOSLEEP(); |
567 |
|
542 |
/* |
568 |
/* |
543 |
* Enable a consistency check between the destination address |
569 |
* Enable a consistency check between the destination address |
544 |
* and the arrival interface for a unicast packet (the RFC 1122 |
570 |
* and the arrival interface for a unicast packet (the RFC 1122 |
Lines 558-570
passin:
Link Here
|
558 |
* checked with carp_iamatch() and carp_forus(). |
584 |
* checked with carp_iamatch() and carp_forus(). |
559 |
*/ |
585 |
*/ |
560 |
checkif = V_ip_checkinterface && (V_ipforwarding == 0) && |
586 |
checkif = V_ip_checkinterface && (V_ipforwarding == 0) && |
561 |
ifp != NULL && ((ifp->if_flags & IFF_LOOPBACK) == 0) && |
587 |
((ifp->if_flags & IFF_LOOPBACK) == 0) && |
562 |
ifp->if_carp == NULL && (dchg == 0); |
588 |
ifp->if_carp == NULL && (dchg == 0); |
563 |
|
589 |
|
564 |
/* |
590 |
/* |
565 |
* Check for exact addresses in the hash bucket. |
591 |
* Check for exact addresses in the hash bucket. |
566 |
*/ |
592 |
*/ |
567 |
/* IN_IFADDR_RLOCK(); */ |
593 |
IN_IFADDR_RLOCK(); |
568 |
LIST_FOREACH(ia, INADDR_HASH(ip->ip_dst.s_addr), ia_hash) { |
594 |
LIST_FOREACH(ia, INADDR_HASH(ip->ip_dst.s_addr), ia_hash) { |
569 |
/* |
595 |
/* |
570 |
* If the address matches, verify that the packet |
596 |
* If the address matches, verify that the packet |
Lines 574-584
passin:
Link Here
|
574 |
if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr && |
600 |
if (IA_SIN(ia)->sin_addr.s_addr == ip->ip_dst.s_addr && |
575 |
(!checkif || ia->ia_ifp == ifp)) { |
601 |
(!checkif || ia->ia_ifp == ifp)) { |
576 |
ifa_ref(&ia->ia_ifa); |
602 |
ifa_ref(&ia->ia_ifa); |
577 |
/* IN_IFADDR_RUNLOCK(); */ |
603 |
IN_IFADDR_RUNLOCK(); |
578 |
goto ours; |
604 |
goto ours_rele; |
579 |
} |
605 |
} |
580 |
} |
606 |
} |
581 |
/* IN_IFADDR_RUNLOCK(); */ |
607 |
IN_IFADDR_RUNLOCK(); |
582 |
|
608 |
|
583 |
/* |
609 |
/* |
584 |
* Check for broadcast addresses. |
610 |
* Check for broadcast addresses. |
Lines 588-594
passin:
Link Here
|
588 |
* be handled via ip_forward() and ether_output() with the loopback |
614 |
* be handled via ip_forward() and ether_output() with the loopback |
589 |
* into the stack for SIMPLEX interfaces handled by ether_output(). |
615 |
* into the stack for SIMPLEX interfaces handled by ether_output(). |
590 |
*/ |
616 |
*/ |
591 |
if (ifp != NULL && ifp->if_flags & IFF_BROADCAST) { |
617 |
if (ifp->if_flags & IFF_BROADCAST) { |
592 |
IF_ADDR_RLOCK(ifp); |
618 |
IF_ADDR_RLOCK(ifp); |
593 |
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { |
619 |
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { |
594 |
if (ifa->ifa_addr->sa_family != AF_INET) |
620 |
if (ifa->ifa_addr->sa_family != AF_INET) |
Lines 598-616
passin:
Link Here
|
598 |
ip->ip_dst.s_addr) { |
624 |
ip->ip_dst.s_addr) { |
599 |
ifa_ref(ifa); |
625 |
ifa_ref(ifa); |
600 |
IF_ADDR_RUNLOCK(ifp); |
626 |
IF_ADDR_RUNLOCK(ifp); |
601 |
goto ours; |
627 |
goto ours_rele; |
602 |
} |
628 |
} |
603 |
#ifdef BOOTP_COMPAT |
629 |
#ifdef BOOTP_COMPAT |
604 |
if (IA_SIN(ia)->sin_addr.s_addr == INADDR_ANY) { |
630 |
if (IA_SIN(ia)->sin_addr.s_addr == INADDR_ANY) { |
605 |
ifa_ref(ifa); |
631 |
ifa_ref(ifa); |
606 |
IF_ADDR_RUNLOCK(ifp); |
632 |
IF_ADDR_RUNLOCK(ifp); |
607 |
goto ours; |
633 |
goto ours_rele; |
608 |
} |
634 |
} |
609 |
#endif |
635 |
#endif |
610 |
} |
636 |
} |
611 |
IF_ADDR_RUNLOCK(ifp); |
637 |
IF_ADDR_RUNLOCK(ifp); |
612 |
ia = NULL; |
638 |
ia = NULL; |
613 |
} |
639 |
} |
|
|
640 |
if_rele(ifp); |
614 |
/* RFC 3927 2.7: Do not forward datagrams for 169.254.0.0/16. */ |
641 |
/* RFC 3927 2.7: Do not forward datagrams for 169.254.0.0/16. */ |
615 |
if (IN_LINKLOCAL(ntohl(ip->ip_dst.s_addr))) { |
642 |
if (IN_LINKLOCAL(ntohl(ip->ip_dst.s_addr))) { |
616 |
IPSTAT_INC(ips_cantforward); |
643 |
IPSTAT_INC(ips_cantforward); |
Lines 681-686
passin:
Link Here
|
681 |
} |
708 |
} |
682 |
return; |
709 |
return; |
683 |
|
710 |
|
|
|
711 |
ours_rele: |
712 |
if_rele(ifp); |
684 |
ours: |
713 |
ours: |
685 |
#ifdef IPSTEALTH |
714 |
#ifdef IPSTEALTH |
686 |
/* |
715 |
/* |