]> git.puffer.fish Git - matthieu/frr.git/commitdiff
pim6d: IPv6 headers are always stripped on receive
authorDavid Lamparter <equinox@opensourcerouting.org>
Fri, 25 Mar 2022 10:30:13 +0000 (11:30 +0100)
committerMobashshera Rasool <mrasool@vmware.com>
Fri, 25 Mar 2022 11:24:15 +0000 (04:24 -0700)
IPV6_HDRINCL is a TX-only option (unlike IP_HDRINCL), so on RX there
never are IPv6 headers to be looked at / skipped over.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
pimd/pim_pim.c
pimd/pim_pim.h

index 46040ab3ea7877221a80b51ac276a58b9ab9c4d6..82f735465a178367bee2875009ad61e70c6d2090 100644 (file)
@@ -149,10 +149,13 @@ static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, pim_addr addr)
        return true;
 }
 
-int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
+int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len,
+                  pim_sgaddr sg)
 {
+#if PIM_IPV == 4
        struct ip *ip_hdr = (struct ip *)buf;
        size_t ip_hlen; /* ip header length in bytes */
+#endif
        uint8_t *pim_msg;
        uint32_t pim_msg_len = 0;
        uint16_t pim_checksum; /* received checksum */
@@ -160,8 +163,8 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
        struct pim_neighbor *neigh;
        struct pim_msg_header *header;
        bool   no_fwd;
-       pim_sgaddr sg;
 
+#if PIM_IPV == 4
        if (len < sizeof(*ip_hdr)) {
                if (PIM_DEBUG_PIM_PACKETS)
                        zlog_debug(
@@ -171,10 +174,15 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
        }
 
        ip_hlen = ip_hdr->ip_hl << 2; /* ip_hl gives length in 4-byte words */
-       sg = pim_sgaddr_from_iphdr(buf);
+       sg = pim_sgaddr_from_iphdr(ip_hdr);
 
        pim_msg = buf + ip_hlen;
        pim_msg_len = len - ip_hlen;
+#else
+       /* NB: header is not included in IPv6 RX */
+       pim_msg = buf;
+       pim_msg_len = len;
+#endif
 
        header = (struct pim_msg_header *)pim_msg;
        if (pim_msg_len < PIM_PIM_MIN_LEN) {
@@ -332,6 +340,8 @@ static void pim_sock_read(struct thread *t)
        pim_ifp = ifp->info;
 
        while (cont) {
+               pim_sgaddr sg;
+
                len = pim_socket_recvfromto(fd, buf, sizeof(buf), &from,
                                            &fromlen, &to, &tolen, &ifindex);
                if (len < 0) {
@@ -361,7 +371,15 @@ static void pim_sock_read(struct thread *t)
                                        ifindex);
                        goto done;
                }
-               int fail = pim_pim_packet(ifp, buf, len);
+#if PIM_IPV == 4
+               sg.src = ((struct sockaddr_in *)&from)->sin_addr;
+               sg.grp = ((struct sockaddr_in *)&to)->sin_addr;
+#else
+               sg.src = ((struct sockaddr_in6 *)&from)->sin6_addr;
+               sg.grp = ((struct sockaddr_in6 *)&to)->sin6_addr;
+#endif
+
+               int fail = pim_pim_packet(ifp, buf, len, sg);
                if (fail) {
                        if (PIM_DEBUG_PIM_PACKETS)
                                zlog_debug("%s: pim_pim_packet() return=%d",
index 1931e8cee83a5a78c2c1497ef37dd4bf4ec8a60d..822d8a18faf4fcbe13f5d7a06da840f28a209291 100644 (file)
@@ -54,7 +54,8 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message);
 void pim_hello_restart_now(struct interface *ifp);
 void pim_hello_restart_triggered(struct interface *ifp);
 
-int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len);
+int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len,
+                  pim_sgaddr sg);
 
 int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg,
                 int pim_msg_size, const char *ifname);