From: David Lamparter Date: Fri, 25 Mar 2022 10:30:13 +0000 (+0100) Subject: pim6d: IPv6 headers are always stripped on receive X-Git-Tag: pim6-testing-20220430~153^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=refs%2Fpull%2F10677%2Fhead;p=mirror%2Ffrr.git pim6d: IPv6 headers are always stripped on receive 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 --- diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 46040ab3ea..82f735465a 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -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", diff --git a/pimd/pim_pim.h b/pimd/pim_pim.h index 1931e8cee8..822d8a18fa 100644 --- a/pimd/pim_pim.h +++ b/pimd/pim_pim.h @@ -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);