diff options
author | Donald Sharp <sharpd@cumulusnetwroks.com> | 2016-07-27 22:33:41 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-12-22 02:26:04 +0100 |
commit | 346cffe31ef871d7876aacafea9cf4086146f110 (patch) | |
tree | dc263ae1062b386a4aa37fb56599c3943cd37f16 /pimd/pim_msg.c | |
parent | pimd: Start abstraction for WC and RPT bits (diff) | |
download | frr-346cffe31ef871d7876aacafea9cf4086146f110.tar.xz frr-346cffe31ef871d7876aacafea9cf4086146f110.zip |
pimd: Revamp send of join/prune to actually set bits right.
When a *,G report is sent, the RPT and WC bits
are set as well as the source is the RP address
for the group.
If this routers idea of the RP for this group is
different than the idea of the RP from the sender
than that particular *,G can be dropped.
Ticket: CM-12031
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'pimd/pim_msg.c')
-rw-r--r-- | pimd/pim_msg.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index 2027d4211..61fc480bf 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -22,11 +22,13 @@ #include <zebra.h> #include "if.h" +#include "log.h" #include "pimd.h" #include "pim_pim.h" #include "pim_msg.h" #include "pim_util.h" +#include "pim_str.h" void pim_msg_build_header(uint8_t *pim_msg, int pim_msg_size, uint8_t pim_msg_type) @@ -105,3 +107,95 @@ pim_msg_addr_encode_ipv4_source(uint8_t *buf, int buf_size, return buf + ENCODED_IPV4_SOURCE_SIZE; } + +int +pim_msg_join_prune_encode (uint8_t *buf, int buf_size, int is_join, + struct in_addr source, struct in_addr group, + struct in_addr upstream, int holdtime) +{ + uint8_t *pim_msg = buf; + uint8_t *pim_msg_curr = buf + PIM_MSG_HEADER_LEN; + uint8_t *end = buf + buf_size; + struct in_addr stosend; + uint8_t bits; + int remain; + + remain = end - pim_msg_curr; + pim_msg_curr = pim_msg_addr_encode_ipv4_ucast (pim_msg_curr, buf_size - PIM_MSG_HEADER_LEN, upstream); + if (!pim_msg_curr) { + char dst_str[100]; + pim_inet4_dump("<dst?>", upstream, dst_str, sizeof(dst_str)); + zlog_warn("%s: failure encoding destination address %s: space left=%d", + __PRETTY_FUNCTION__, dst_str, remain); + return -3; + } + + remain = end - pim_msg_curr; + if (remain < 4) { + zlog_warn("%s: group will not fit: space left=%d", + __PRETTY_FUNCTION__, remain); + return -4; + } + + *pim_msg_curr = 0; /* reserved */ + ++pim_msg_curr; + *pim_msg_curr = 1; /* number of groups */ + ++pim_msg_curr; + + *((uint16_t *) pim_msg_curr) = htons(holdtime); + ++pim_msg_curr; + ++pim_msg_curr; + + remain = end - pim_msg_curr; + pim_msg_curr = pim_msg_addr_encode_ipv4_group (pim_msg_curr, remain, + group); + if (!pim_msg_curr) { + char group_str[100]; + pim_inet4_dump("<grp?>", group, group_str, sizeof(group_str)); + zlog_warn("%s: failure encoding group address %s: space left=%d", + __PRETTY_FUNCTION__, group_str, remain); + return -5; + } + + remain = end - pim_msg_curr; + if (remain < 4) { + zlog_warn("%s: sources will not fit: space left=%d", + __PRETTY_FUNCTION__, remain); + return -6; + } + + /* number of joined sources */ + *((uint16_t *) pim_msg_curr) = htons(is_join ? 1 : 0); + ++pim_msg_curr; + ++pim_msg_curr; + + /* number of pruned sources */ + *((uint16_t *) pim_msg_curr) = htons(is_join ? 0 : 1); + ++pim_msg_curr; + ++pim_msg_curr; + + remain = end - pim_msg_curr; + if (source.s_addr == INADDR_ANY) + { + bits = PIM_ENCODE_SPARSE_BIT | PIM_ENCODE_WC_BIT | PIM_ENCODE_RPT_BIT; + stosend = qpim_rp.rpf_addr; + } + else + { + bits = PIM_ENCODE_SPARSE_BIT; + stosend = source; + } + pim_msg_curr = pim_msg_addr_encode_ipv4_source (pim_msg_curr, remain, stosend, bits); + if (!pim_msg_curr) { + char source_str[100]; + pim_inet4_dump("<src?>", source, source_str, sizeof(source_str)); + zlog_warn("%s: failure encoding source address %s: space left=%d", + __PRETTY_FUNCTION__, source_str, remain); + return -7; + } + + remain = pim_msg_curr - pim_msg; + pim_msg_build_header (pim_msg, remain, PIM_MSG_TYPE_JOIN_PRUNE); + + return remain; +} |