]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: fix IGMP receive handling
authorNathan Bahr <nbahr@atcorp.com>
Wed, 19 Aug 2020 19:26:41 +0000 (14:26 -0500)
committerJafar Al-Gharaibeh <jafar@atcorp.com>
Wed, 26 Aug 2020 15:46:42 +0000 (10:46 -0500)
IGMP packets received from a source that does not match the subnet
of any configured addresses on the receive interface should be
ignored.
Also, find and use the correct IGMP socket object for the received
IGMP packet.

Signed-off-by: Nathan Bahr <nbahr@atcorp.com>
Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
pimd/pim_iface.c
pimd/pim_iface.h
pimd/pim_mroute.c

index 88bcc48f8080ede2b30d04f1b905b07137c91409..0caa360df92a7a4cc76fb70766c442b04f5f2d45 100644 (file)
@@ -1504,14 +1504,14 @@ void pim_if_create_pimreg(struct pim_instance *pim)
        }
 }
 
-int pim_if_connected_to_source(struct interface *ifp, struct in_addr src)
+struct prefix *pim_if_connected_to_source(struct interface *ifp, struct in_addr src)
 {
        struct listnode *cnode;
        struct connected *c;
        struct prefix p;
 
        if (!ifp)
-               return 0;
+               return NULL;
 
        p.family = AF_INET;
        p.u.prefix4 = src;
@@ -1520,11 +1520,11 @@ int pim_if_connected_to_source(struct interface *ifp, struct in_addr src)
        for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
                if ((c->address->family == AF_INET)
                    && prefix_match(CONNECTED_PREFIX(c), &p)) {
-                       return 1;
+                       return CONNECTED_PREFIX(c);
                }
        }
 
-       return 0;
+       return NULL;
 }
 
 bool pim_if_is_vrf_device(struct interface *ifp)
index 13aaf8d3b252d88744ed667d4ef5d9524add0689..8decfef74d399b5e71bf1c18393158495f4f7538 100644 (file)
@@ -223,7 +223,7 @@ void pim_if_update_assert_tracking_desired(struct interface *ifp);
 
 void pim_if_create_pimreg(struct pim_instance *pim);
 
-int pim_if_connected_to_source(struct interface *ifp, struct in_addr src);
+struct prefix *pim_if_connected_to_source(struct interface *ifp, struct in_addr src);
 int pim_update_source_set(struct interface *ifp, struct in_addr source);
 
 bool pim_if_is_vrf_device(struct interface *ifp);
index 9060b6a95aad3ecd88ecff3ed13b7823020f1b0a..0bccba397b1463732226af7d52bd2f46efbd352e 100644 (file)
@@ -592,12 +592,9 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf,
        struct pim_interface *pim_ifp;
        const struct ip *ip_hdr;
        const struct igmpmsg *msg;
-       char ip_src_str[INET_ADDRSTRLEN] = "";
-       char ip_dst_str[INET_ADDRSTRLEN] = "";
-       char src_str[INET_ADDRSTRLEN] = "<src?>";
-       char grp_str[INET_ADDRSTRLEN] = "<grp?>";
        struct in_addr ifaddr;
        struct igmp_sock *igmp;
+       const struct prefix *connected_src;
 
        if (buf_size < (int)sizeof(struct ip))
                return 0;
@@ -617,34 +614,37 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf,
                if (!ifp || !ifp->info)
                        return 0;
 
+               connected_src = pim_if_connected_to_source(ifp, ip_hdr->ip_src);
+
+               if (!connected_src) {
+                       if (PIM_DEBUG_IGMP_PACKETS) {
+                               zlog_debug("Recv IGMP packet on interface: %s from a non-connected source: %pI4",
+                                          ifp->name, &ip_hdr->ip_src);
+                       }
+                       return 0;
+               }
+
                pim_ifp = ifp->info;
-               ifaddr = pim_find_primary_addr(ifp);
-               igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list,
-                                                  ifaddr);
+               ifaddr = connected_src->u.prefix4;
+               igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list, ifaddr);
 
                if (PIM_DEBUG_MROUTE) {
-                       pim_inet4_dump("<src?>", ip_hdr->ip_src, ip_src_str,
-                                      sizeof(ip_src_str));
-                       pim_inet4_dump("<dst?>", ip_hdr->ip_dst, ip_dst_str,
-                                      sizeof(ip_dst_str));
-
                        zlog_debug(
-                               "%s(%s): igmp kernel upcall on %s(%p) for %s -> %s",
+                               "%s(%s): igmp kernel upcall on %s(%p) for %pI4 -> %pI4",
                                __func__, pim->vrf->name, ifp->name, igmp,
-                               ip_src_str, ip_dst_str);
+                               &ip_hdr->ip_src, &ip_hdr->ip_dst);
                }
                if (igmp)
                        pim_igmp_packet(igmp, (char *)buf, buf_size);
-
+               else if (PIM_DEBUG_IGMP_PACKETS) {
+                       zlog_debug("No IGMP socket on interface: %s with connected source: %pFX",
+                                  ifp->name, connected_src);
+               }
        } else if (ip_hdr->ip_p) {
                if (PIM_DEBUG_MROUTE_DETAIL) {
-                       pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str,
-                                      sizeof(src_str));
-                       pim_inet4_dump("<grp?>", ip_hdr->ip_dst, grp_str,
-                                      sizeof(grp_str));
                        zlog_debug(
-                               "%s: no kernel upcall proto=%d src: %s dst: %s msg_size=%d",
-                               __func__, ip_hdr->ip_p, src_str, grp_str,
+                               "%s: no kernel upcall proto=%d src: %pI4 dst: %pI4 msg_size=%d",
+                               __func__, ip_hdr->ip_p, &ip_hdr->ip_src, &ip_hdr->ip_dst,
                                buf_size);
                }
 
@@ -656,15 +656,11 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf,
                if (!ifp)
                        return 0;
                if (PIM_DEBUG_MROUTE) {
-                       pim_inet4_dump("<src?>", msg->im_src, src_str,
-                                      sizeof(src_str));
-                       pim_inet4_dump("<grp?>", msg->im_dst, grp_str,
-                                      sizeof(grp_str));
                        zlog_debug(
-                               "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%s,%s) on %s vifi=%d  size=%d",
+                               "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI4,%pI4) on %s vifi=%d  size=%d",
                                __func__, igmpmsgtype2str[msg->im_msgtype],
                                msg->im_msgtype, ip_hdr->ip_p,
-                               pim->mroute_socket, src_str, grp_str, ifp->name,
+                               pim->mroute_socket, &msg->im_src, &msg->im_dst, ifp->name,
                                msg->im_vif, buf_size);
                }