From: Donald Sharp Date: Thu, 1 Jun 2017 22:59:43 +0000 (-0400) Subject: pimd: Bind pim kernel fd to appropriate vrf X-Git-Tag: frr-4.0-dev~468^2~72 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=90450a3d252d73f9dc05c8803a2101d28436dd79;p=mirror%2Ffrr.git pimd: Bind pim kernel fd to appropriate vrf Bind the pim kernel fd to the appropriate vrf, modify the callback up into pim with the IGMP report to retrieve the incoming interface and use that to lookup the correct interface to use. Signed-off-by: Donald Sharp --- diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 124166880c..2d8b2b7979 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1582,15 +1582,3 @@ int pim_if_connected_to_source(struct interface *ifp, struct in_addr src) return 0; } - -struct interface *pim_if_lookup_address_vrf(struct in_addr src, vrf_id_t vrf_id) -{ - struct listnode *ifnode; - struct interface *ifp; - - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) { - if (pim_if_connected_to_source(ifp, src) && ifp->info) - return ifp; - } - return NULL; -} diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index e4b1b8e675..703b83b05d 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -161,9 +161,6 @@ void pim_if_addr_del_all(struct interface *ifp); void pim_if_addr_del_all_igmp(struct interface *ifp); void pim_if_addr_del_all_pim(struct interface *ifp); -struct interface *pim_if_lookup_address_vrf(struct in_addr src, - vrf_id_t vrf_id); - int pim_if_add_vif(struct interface *ifp); int pim_if_del_vif(struct interface *ifp); void pim_if_add_vif_all(struct pim_instance *pim); diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 5b826b0580..884295dbbd 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -529,7 +529,7 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, } static int pim_mroute_msg(struct pim_instance *pim, const char *buf, - int buf_size) + int buf_size, ifindex_t ifindex) { struct interface *ifp; struct pim_interface *pim_ifp; @@ -552,22 +552,11 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, * the source * of the IP packet. */ - ifp = pim_if_lookup_address_vrf(ip_hdr->ip_src, pim->vrf_id); + ifp = if_lookup_by_index(ifindex, pim->vrf_id); - if (!ifp) { - if (PIM_DEBUG_MROUTE_DETAIL) { - pim_inet4_dump("", ip_hdr->ip_src, - ip_src_str, sizeof(ip_src_str)); - pim_inet4_dump("", ip_hdr->ip_dst, - ip_dst_str, sizeof(ip_dst_str)); - - zlog_warn( - "%s(%s): igmp kernel upcall could not find usable interface for %s -> %s", - __PRETTY_FUNCTION__, pim->vrf->name, - ip_src_str, ip_dst_str); - } + if (!ifp) return 0; - } + pim_ifp = ifp->info; ifaddr = pim_find_primary_addr(ifp); igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list, @@ -653,11 +642,13 @@ static int mroute_read(struct thread *t) int result = 0; int cont = 1; int rd; - + ifindex_t ifindex; pim = THREAD_ARG(t); while (cont) { - rd = read(pim->mroute_socket, buf, sizeof(buf)); + rd = pim_socket_recvfromto(pim->mroute_socket, (uint8_t *)buf, + sizeof(buf), NULL, NULL, NULL, NULL, + &ifindex); if (rd <= 0) { if (errno == EINTR) continue; @@ -673,7 +664,7 @@ static int mroute_read(struct thread *t) goto done; } - result = pim_mroute_msg(pim, buf, rd); + result = pim_mroute_msg(pim, buf, rd, ifindex); count++; if (count % qpim_packet_process == 0) @@ -707,6 +698,9 @@ int pim_mroute_socket_enable(struct pim_instance *pim) fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); + setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, pim->vrf->name, + strlen(pim->vrf->name)); + if (pimd_privs.change(ZPRIVS_LOWER)) zlog_err("pim_mroute_socket_enable: could not lower privs, %s", safe_strerror(errno));