Lots of passing src/dst around, but it is what it is.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
uint32_t metric_preference, uint32_t route_metric,
uint32_t rpt_bit_flag)
{
+ struct pim_interface *pim_ifp = ifp->info;
uint8_t *buf_pastend = pim_msg + buf_size;
uint8_t *pim_msg_curr;
int pim_msg_size;
Add PIM header
*/
pim_msg_size = pim_msg_curr - pim_msg;
- pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_ASSERT, false);
+ pim_msg_build_header(pim_ifp->primary_address,
+ qpim_all_pim_routers_addr, pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_ASSERT, false);
return pim_msg_size;
}
static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp,
uint32_t pim_mtu, pim_addr dst_addr, bool no_fwd)
{
+ struct pim_interface *pim_ifp = ifp->info;
struct bsmmsg_grpinfo *grpinfo, *curgrp;
uint8_t *firstgrp_ptr;
uint8_t *pkt;
< (PIM_BSM_GRP_LEN + PIM_BSM_RP_LEN))) {
/* No space to fit in more rp, send this pkt */
this_pkt_len = pim_mtu - this_pkt_rem;
- pim_msg_build_header(pak_start, this_pkt_len,
- PIM_MSG_TYPE_BOOTSTRAP,
- no_fwd);
+ pim_msg_build_header(
+ pim_ifp->primary_address, dst_addr,
+ pak_start, this_pkt_len,
+ PIM_MSG_TYPE_BOOTSTRAP, no_fwd);
pim_bsm_send_intf(pak_start, this_pkt_len, ifp,
dst_addr);
/* Send if we have any unsent packet */
if (pak_pending) {
this_pkt_len = pim_mtu - this_pkt_rem;
- pim_msg_build_header(pak_start, this_pkt_len,
+ pim_msg_build_header(pim_ifp->primary_address, dst_addr,
+ pak_start, this_pkt_len,
PIM_MSG_TYPE_BOOTSTRAP, no_fwd);
pim_bsm_send_intf(pak_start, (pim_mtu - this_pkt_rem), ifp,
dst_addr);
zlog_debug("%s: pim_bsm_frag_send returned %s",
__func__, ret ? "TRUE" : "FALSE");
} else {
- pim_msg_build_header(buf, len, PIM_MSG_TYPE_BOOTSTRAP,
+ pim_msg_build_header(pim_ifp->primary_address, dst_addr,
+ buf, len, PIM_MSG_TYPE_BOOTSTRAP,
no_fwd);
if (!pim_bsm_send_intf(buf, len, ifp, dst_addr)) {
if (PIM_DEBUG_BSM)
}
} else {
/* Pim header needs to be constructed */
- pim_msg_build_header(bsfrag->data, bsfrag->size,
+ pim_msg_build_header(pim_ifp->primary_address, dst_addr,
+ bsfrag->data, bsfrag->size,
PIM_MSG_TYPE_BOOTSTRAP, no_fwd);
ret = pim_bsm_send_intf(bsfrag->data, bsfrag->size, ifp,
dst_addr);
group_size = pim_msg_get_jp_group_size(group->sources);
if (group_size > packet_left) {
- pim_msg_build_header(pim_msg, packet_size,
+ pim_msg_build_header(pim_ifp->primary_address,
+ qpim_all_pim_routers_addr, pim_msg,
+ packet_size,
PIM_MSG_TYPE_JOIN_PRUNE, false);
if (pim_msg_send(pim_ifp->pim_sock_fd,
pim_ifp->primary_address,
grp = (struct pim_jp_groups *)curr_ptr;
if (packet_left < sizeof(struct pim_jp_groups)
|| msg->num_groups == 255) {
- pim_msg_build_header(pim_msg, packet_size,
+ pim_msg_build_header(pim_ifp->primary_address,
+ qpim_all_pim_routers_addr, pim_msg,
+ packet_size,
PIM_MSG_TYPE_JOIN_PRUNE, false);
if (pim_msg_send(pim_ifp->pim_sock_fd,
pim_ifp->primary_address,
if (!new_packet) {
// msg->num_groups = htons (msg->num_groups);
- pim_msg_build_header(pim_msg, packet_size,
- PIM_MSG_TYPE_JOIN_PRUNE, false);
+ pim_msg_build_header(
+ pim_ifp->primary_address, qpim_all_pim_routers_addr,
+ pim_msg, packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false);
if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address,
qpim_all_pim_routers_addr, pim_msg,
packet_size,
#include "pim_jp_agg.h"
#include "pim_oil.h"
-void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size,
- uint8_t pim_msg_type, bool no_fwd)
+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)
{
struct pim_msg_header *header = (struct pim_msg_header *)pim_msg;
+ struct iovec iov[2], *iovp = iov;
+
+ /*
+ * The checksum for Registers is done only on the first 8 bytes of the
+ * packet, including the PIM header and the next 4 bytes, excluding the
+ * data packet portion
+ *
+ * for IPv6, the pseudoheader upper-level protocol length is also
+ * truncated, so let's just set it here before everything else.
+ */
+ if (pim_msg_type == PIM_MSG_TYPE_REGISTER)
+ pim_msg_size = PIM_MSG_REGISTER_LEN;
+
+#if PIM_IPV == 6
+ struct ipv6_ph phdr = {
+ .src = src,
+ .dst = dst,
+ .ulpl = htonl(pim_msg_size),
+ .next_hdr = IPPROTO_PIM,
+ };
+
+ iovp->iov_base = &phdr;
+ iovp->iov_len = sizeof(phdr);
+ iovp++;
+#endif
/*
* Write header
header->Nbit = no_fwd;
header->reserved = 0;
-
header->checksum = 0;
- /*
- * The checksum for Registers is done only on the first 8 bytes of the
- * packet,
- * including the PIM header and the next 4 bytes, excluding the data
- * packet portion
- */
- if (pim_msg_type == PIM_MSG_TYPE_REGISTER)
- header->checksum = in_cksum(pim_msg, PIM_MSG_REGISTER_LEN);
- else
- header->checksum = in_cksum(pim_msg, pim_msg_size);
+ iovp->iov_base = header;
+ iovp->iov_len = pim_msg_size;
+ iovp++;
+
+ header->checksum = in_cksumv(iov, iovp - iov);
}
uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr)
}
#endif
-void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size,
- uint8_t pim_msg_type, bool no_fwd);
+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);
assert(pim_msg_size >= PIM_PIM_MIN_LEN);
assert(pim_msg_size <= PIM_PIM_BUFSIZE_WRITE);
- pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_HELLO, false);
+ pim_msg_build_header(pim_ifp->primary_address,
+ qpim_all_pim_routers_addr, pim_msg, pim_msg_size,
+ PIM_MSG_TYPE_HELLO, false);
if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address,
qpim_all_pim_routers_addr, pim_msg, pim_msg_size,
length = pim_encode_addr_ucast(b1, sg->src);
b1length += length;
- pim_msg_build_header(buffer, b1length + PIM_MSG_REGISTER_STOP_LEN,
+ pim_msg_build_header(src, originator, buffer,
+ b1length + PIM_MSG_REGISTER_STOP_LEN,
PIM_MSG_TYPE_REG_STOP, false);
pinfo = (struct pim_interface *)ifp->info;
memcpy(b1, (const unsigned char *)buf, buf_size);
- pim_msg_build_header(buffer, buf_size + PIM_MSG_REGISTER_LEN,
+ pim_msg_build_header(src, rpg->rpf_addr.u.prefix4, buffer,
+ buf_size + PIM_MSG_REGISTER_LEN,
PIM_MSG_TYPE_REGISTER, false);
++pinfo->pim_ifstat_reg_send;