| 642 | } |
| 643 | |
| 644 | static void |
| 645 | carp_input_c(struct mbuf *m, struct carp_header *ch, sa_family_t af) |
| 646 | { |
| 647 | struct ifnet *ifp = m->m_pkthdr.rcvif; |
| 648 | struct ifaddr *ifa, *match; |
| 649 | struct carp_softc *sc; |
| 650 | uint64_t tmp_counter; |
| 651 | struct timeval sc_tv, ch_tv; |
| 652 | int error; |
| 653 | |
| 654 | NET_EPOCH_ASSERT(); |
| 655 | |
| 656 | /* |
| 657 | * Verify that the VHID is valid on the receiving interface. |
| 658 | * |
| 659 | * There should be just one match. If there are none |
| 660 | * the VHID is not valid and we drop the packet. If |
| 661 | * there are multiple VHID matches, take just the first |
| 662 | * one, for compatibility with previous code. While we're |
| 663 | * scanning, check for obvious loops in the network topology |
| 664 | * (these should never happen, and as noted above, we may |
| 665 | * miss real loops; this is just a double-check). |
| 666 | */ |
| 667 | error = 0; |
| 668 | match = NULL; |
| 669 | IFNET_FOREACH_IFA(ifp, ifa) { |
| 670 | if (match == NULL && ifa->ifa_carp != NULL && |
| 671 | ifa->ifa_addr->sa_family == af && |
| 672 | ifa->ifa_carp->sc_vhid == ch->carp_vhid) |
| 673 | match = ifa; |
| 674 | if (ch->carp_vhid == 0 && carp_source_is_self(m, ifa, af)) |
| 675 | error = ELOOP; |
| 676 | } |
| 677 | ifa = error ? NULL : match; |
| 678 | if (ifa != NULL) |
| 679 | ifa_ref(ifa); |
| 680 | |
| 681 | if (ifa == NULL) { |
| 682 | if (error == ELOOP) { |
| 683 | CARP_DEBUG("dropping looped packet on interface %s\n", |
| 684 | ifp->if_xname); |
| 685 | CARPSTATS_INC(carps_badif); /* ??? */ |
| 686 | } else { |
| 687 | CARPSTATS_INC(carps_badvhid); |
| 688 | } |
| 689 | m_freem(m); |
| 690 | return; |
| 691 | } |
| 692 | |
| 693 | /* verify the CARP version. */ |
| 694 | if (ch->carp_version != CARP_VERSION) { |
| 695 | CARPSTATS_INC(carps_badver); |
| 696 | CARP_DEBUG("%s: invalid version %d\n", ifp->if_xname, |
| 697 | ch->carp_version); |
| 698 | ifa_free(ifa); |
| 699 | m_freem(m); |
| 700 | return; |
| 701 | } |
no test coverage detected