diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 0a450834e3..438a0c9b64 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -418,7 +418,7 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, Add PIM header */ pim_msg_size = pim_msg_curr - pim_msg; - pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_ASSERT); + pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_ASSERT, false); return pim_msg_size; } diff --git a/pimd/pim_join.c b/pimd/pim_join.c index cbacaf3ea8..5e1a4f0c5e 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -519,7 +519,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) 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_TYPE_JOIN_PRUNE); + 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, @@ -576,7 +576,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) if (packet_left < sizeof(struct pim_jp_groups) || msg->num_groups == 255) { pim_msg_build_header(pim_msg, packet_size, - PIM_MSG_TYPE_JOIN_PRUNE); + 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, @@ -596,7 +596,7 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) if (!new_packet) { // msg->num_groups = htons (msg->num_groups); pim_msg_build_header(pim_msg, packet_size, - PIM_MSG_TYPE_JOIN_PRUNE); + 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, diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index 63688f87e0..2e467502b1 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -39,7 +39,7 @@ #include "pim_oil.h" void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, - uint8_t pim_msg_type) + uint8_t pim_msg_type, bool no_fwd) { struct pim_msg_header *header = (struct pim_msg_header *)pim_msg; @@ -48,6 +48,7 @@ void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, */ header->ver = PIM_PROTO_VERSION; header->type = pim_msg_type; + header->Nbit = no_fwd; header->reserved = 0; diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h index ad9b5d9c01..5f50303967 100644 --- a/pimd/pim_msg.h +++ b/pimd/pim_msg.h @@ -23,6 +23,8 @@ #include #include "pim_jp_agg.h" + +#define PIM_HDR_LEN sizeof(struct pim_msg_header) /* Number Description ---------- ------------------ @@ -41,11 +43,20 @@ enum pim_msg_address_family { /* * Network Order pim_msg_hdr + * ========================= + * PIM Header definition as per RFC 5059. N bit introduced to indicate + * do-not-forward option in PIM Boot strap Message. + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |PIM Ver| Type |N| Reserved | Checksum | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */ struct pim_msg_header { uint8_t type : 4; uint8_t ver : 4; - uint8_t reserved; + uint8_t Nbit : 1; /* No Fwd Bit */ + uint8_t reserved : 7; uint16_t checksum; } __attribute__((packed)); @@ -58,7 +69,9 @@ struct pim_encoded_ipv4_unicast { struct pim_encoded_group_ipv4 { uint8_t ne; uint8_t family; - uint8_t reserved; + uint8_t bidir : 1; /* Bidir bit */ + uint8_t reserved : 6; /* Reserved */ + uint8_t sz : 1; /* scope zone bit */ uint8_t mask; struct in_addr addr; } __attribute__((packed)); @@ -88,7 +101,7 @@ struct pim_jp { } __attribute__((packed)); void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, - uint8_t pim_msg_type); + 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); diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 71b0d47928..e9d44b9c3c 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -39,6 +39,7 @@ #include "pim_msg.h" #include "pim_register.h" #include "pim_errors.h" +#include "pim_bsm.h" static int on_pim_hello_send(struct thread *t); static int pim_hello_send(struct interface *ifp, uint16_t holdtime); @@ -273,6 +274,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; + default: if (PIM_DEBUG_PIM_PACKETS) { zlog_debug( @@ -634,7 +636,7 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) zassert(pim_msg_size >= PIM_PIM_MIN_LEN); zassert(pim_msg_size <= PIM_PIM_BUFSIZE_WRITE); - pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_HELLO); + pim_msg_build_header(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, diff --git a/pimd/pim_register.c b/pimd/pim_register.c index 431236eebe..3fe7e8bf64 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -94,7 +94,7 @@ void pim_register_stop_send(struct interface *ifp, struct prefix_sg *sg, b1length += length; pim_msg_build_header(buffer, b1length + PIM_MSG_REGISTER_STOP_LEN, - PIM_MSG_TYPE_REG_STOP); + PIM_MSG_TYPE_REG_STOP, false); pinfo = (struct pim_interface *)ifp->info; if (!pinfo) { @@ -208,7 +208,7 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, memcpy(b1, (const unsigned char *)buf, buf_size); pim_msg_build_header(buffer, buf_size + PIM_MSG_REGISTER_LEN, - PIM_MSG_TYPE_REGISTER); + PIM_MSG_TYPE_REGISTER, false); ++pinfo->pim_ifstat_reg_send;