From d1fd950aa0b90be439e4c45e84877a6558765f31 Mon Sep 17 00:00:00 2001 From: Mobashshera Rasool Date: Tue, 1 Mar 2022 23:10:39 -0800 Subject: [PATCH] pim6d: Abstract api to get src and dst from ip hdr IPv4 uses "struct ip" and IPv6 uses "struct ip6_hdr" as headers. Get the src and dst in pim_sgaddr. Added api pim_sgaddr_from_iphdr to do so. Signed-off-by: Mobashshera Rasool --- pimd/pim_msg.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h index 522e94504a..456c356d9f 100644 --- a/pimd/pim_msg.h +++ b/pimd/pim_msg.h @@ -21,6 +21,9 @@ #define PIM_MSG_H #include +#if PIM_IPV == 6 +#include +#endif #include "pim_jp_agg.h" @@ -181,6 +184,30 @@ struct pim_jp { struct pim_jp_groups groups[1]; } __attribute__((packed)); +#if PIM_IPV == 4 +static inline pim_sgaddr pim_sgaddr_from_iphdr(const void *iphdr) +{ + const struct ip *ipv4_hdr = iphdr; + pim_sgaddr sg; + + sg.src = ipv4_hdr->ip_src; + sg.grp = ipv4_hdr->ip_dst; + + return sg; +} +#else +static inline pim_sgaddr pim_sgaddr_from_iphdr(const void *iphdr) +{ + const struct ip6_hdr *ipv6_hdr = iphdr; + pim_sgaddr sg; + + sg.src = ipv6_hdr->ip6_src; + sg.grp = ipv6_hdr->ip6_dst; + + return sg; +} +#endif + void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, uint8_t pim_msg_type, bool no_fwd); uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr); -- 2.39.5