summaryrefslogtreecommitdiff
path: root/pimd/pim_msg.h
diff options
context:
space:
mode:
Diffstat (limited to 'pimd/pim_msg.h')
-rw-r--r--pimd/pim_msg.h40
1 files changed, 38 insertions, 2 deletions
diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h
index 522e94504a..733210af3a 100644
--- a/pimd/pim_msg.h
+++ b/pimd/pim_msg.h
@@ -21,6 +21,9 @@
#define PIM_MSG_H
#include <netinet/in.h>
+#if PIM_IPV == 6
+#include <netinet/ip6.h>
+#endif
#include "pim_jp_agg.h"
@@ -158,10 +161,18 @@ struct pim_encoded_source_ipv6 {
typedef struct pim_encoded_ipv4_unicast pim_encoded_unicast;
typedef struct pim_encoded_group_ipv4 pim_encoded_group;
typedef struct pim_encoded_source_ipv4 pim_encoded_source;
+typedef struct ip ipv_hdr;
+#define IPV_SRC(ip_hdr) ((ip_hdr))->ip_src
+#define IPV_DST(ip_hdr) ((ip_hdr))->ip_dst
+#define IPV_LEN(ip_hdr) ((ip_hdr))->ip_len
#else
typedef struct pim_encoded_ipv6_unicast pim_encoded_unicast;
typedef struct pim_encoded_group_ipv6 pim_encoded_group;
typedef struct pim_encoded_source_ipv6 pim_encoded_source;
+typedef struct ip6_hdr ipv_hdr;
+#define IPV_SRC(ip_hdr) ((ip_hdr))->ip6_src
+#define IPV_DST(ip_hdr) ((ip_hdr))->ip6_dst
+#define IPV_LEN(ip_hdr) ((ip_hdr))->ip6_plen
#endif
/* clang-format on */
@@ -181,8 +192,33 @@ struct pim_jp {
struct pim_jp_groups groups[1];
} __attribute__((packed));
-void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size,
- uint8_t pim_msg_type, bool no_fwd);
+#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(pim_addr src, pim_addr dst, 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);
uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, struct in_addr addr);