summaryrefslogtreecommitdiff
path: root/pimd/pim_pim.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2022-03-12 22:43:05 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2022-03-28 14:13:22 +0200
commitcc362d24aa2a7a0342134f1d52572189a49f2cbb (patch)
tree38e84be2e49d98911603fbf12e529576fda47789 /pimd/pim_pim.c
parent7993f685c1df878d1ff1ff1e4794f6eef95d6fbd (diff)
pim6d: send PIM packets
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'pimd/pim_pim.c')
-rw-r--r--pimd/pim_pim.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c
index 82f735465a..1c8e31212e 100644
--- a/pimd/pim_pim.c
+++ b/pimd/pim_pim.c
@@ -522,8 +522,9 @@ void pim_sock_reset(struct interface *ifp)
pim_ifstat_reset(ifp);
}
+#if PIM_IPV == 4
static uint16_t ip_id = 0;
-
+#endif
static int pim_msg_send_frame(int fd, char *buf, size_t len,
struct sockaddr *dst, size_t salen,
@@ -578,19 +579,13 @@ static int pim_msg_send_frame(int fd, char *buf, size_t len,
int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg,
int pim_msg_size, const char *ifname)
{
- struct sockaddr_in to;
socklen_t tolen;
unsigned char buffer[10000];
unsigned char *msg_start;
uint8_t ttl;
struct pim_msg_header *header;
- struct ip *ip;
memset(buffer, 0, 10000);
- int sendlen = sizeof(struct ip) + pim_msg_size;
-
- msg_start = buffer + sizeof(struct ip);
- memcpy(msg_start, pim_msg, pim_msg_size);
header = (struct pim_msg_header *)pim_msg;
/*
@@ -620,7 +615,11 @@ int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg,
break;
}
- ip = (struct ip *)buffer;
+#if PIM_IPV == 4
+ struct ip *ip = (struct ip *)buffer;
+ struct sockaddr_in to = {};
+ int sendlen = sizeof(*ip) + pim_msg_size;
+
ip->ip_id = htons(++ip_id);
ip->ip_hl = 5;
ip->ip_v = 4;
@@ -631,17 +630,34 @@ int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg,
ip->ip_ttl = ttl;
ip->ip_len = htons(sendlen);
- if (PIM_DEBUG_PIM_PACKETS) {
- char dst_str[INET_ADDRSTRLEN];
- pim_inet4_dump("<dst?>", dst, dst_str, sizeof(dst_str));
- zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x", __func__,
- dst_str, ifname, pim_msg_size, header->checksum);
- }
-
- memset(&to, 0, sizeof(to));
to.sin_family = AF_INET;
to.sin_addr = dst;
tolen = sizeof(to);
+#else
+ struct ip6_hdr *ip = (struct ip6_hdr *)buffer;
+ struct sockaddr_in6 to = {};
+ int sendlen = sizeof(*ip) + pim_msg_size;
+
+ ip->ip6_flow = 0;
+ ip->ip6_vfc = (6 << 4) | (IPTOS_PREC_INTERNETCONTROL >> 4);
+ ip->ip6_plen = htons(pim_msg_size);
+ ip->ip6_nxt = PIM_IP_PROTO_PIM;
+ ip->ip6_hlim = ttl;
+ ip->ip6_src = src;
+ ip->ip6_dst = dst;
+
+ to.sin6_family = AF_INET6;
+ to.sin6_addr = dst;
+ tolen = sizeof(to);
+#endif
+
+ msg_start = buffer + sizeof(*ip);
+ memcpy(msg_start, pim_msg, pim_msg_size);
+
+ if (PIM_DEBUG_PIM_PACKETS)
+ zlog_debug("%s: to %pPA on %s: msg_size=%d checksum=%x",
+ __func__, &dst, ifname, pim_msg_size,
+ header->checksum);
if (PIM_DEBUG_PIM_PACKETDUMP_SEND) {
pim_pkt_dump(__func__, pim_msg, pim_msg_size);
@@ -661,20 +677,16 @@ static int hello_send(struct interface *ifp, uint16_t holdtime)
pim_ifp = ifp->info;
- if (PIM_DEBUG_PIM_HELLO) {
- char dst_str[INET_ADDRSTRLEN];
- pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr, dst_str,
- sizeof(dst_str));
+ if (PIM_DEBUG_PIM_HELLO)
zlog_debug(
- "%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d",
- __func__, dst_str, ifp->name, holdtime,
- pim_ifp->pim_propagation_delay_msec,
+ "%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d",
+ __func__, &qpim_all_pim_routers_addr, ifp->name,
+ holdtime, pim_ifp->pim_propagation_delay_msec,
pim_ifp->pim_override_interval_msec,
PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPPRESSION(
pim_ifp->options),
pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id,
listcount(ifp->connected));
- }
pim_tlv_size = pim_hello_build_tlv(
ifp, pim_msg + PIM_PIM_MIN_LEN,