From 984c84f48600a9c6b7b0513e3ad8f234465dec1e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 27 Jul 2016 15:27:52 -0400 Subject: [PATCH] pimd: Start abstraction for WC and RPT bits Start the abstraction of the WC and RPT bits so we can send the data as appropriate. Signed-off-by: Donald Sharp --- pimd/pim_cmd.c | 3 ++- pimd/pim_join.c | 3 ++- pimd/pim_msg.c | 8 ++++---- pimd/pim_msg.h | 7 ++++++- pimd/pim_tlv.c | 27 +++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 68899d8c7c..c089a3fd3f 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -4624,7 +4624,8 @@ static int recv_joinprune(struct vty *vty, remain = buf_pastend - pim_msg_curr; pim_msg_curr = pim_msg_addr_encode_ipv4_source(pim_msg_curr, remain, - source_addr); + source_addr, + PIM_ENCODE_SPARSE_BIT); if (!pim_msg_curr) { vty_out(vty, "Failure encoding source address %s: space left=%d%s", source_str, remain, VTY_NEWLINE); diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 5a2ff744e5..2806320c02 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -431,7 +431,8 @@ int pim_joinprune_send(struct interface *ifp, remain = pastend - pim_msg_curr; pim_msg_curr = pim_msg_addr_encode_ipv4_source(pim_msg_curr, remain, - sg->u.sg.src); + sg->u.sg.src, + PIM_ENCODE_SPARSE_BIT); if (!pim_msg_curr) { char source_str[100]; pim_inet4_dump("", sg->u.sg.src, source_str, sizeof(source_str)); diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index 92382ccc4d..2027d42119 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -87,9 +87,9 @@ uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, return buf + ENCODED_IPV4_GROUP_SIZE; } -uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf, - int buf_size, - struct in_addr addr) +uint8_t * +pim_msg_addr_encode_ipv4_source(uint8_t *buf, int buf_size, + struct in_addr addr, uint8_t bits) { const int ENCODED_IPV4_SOURCE_SIZE = 8; @@ -99,7 +99,7 @@ uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf, buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */ buf[1] = '\0'; /* native encoding */ - buf[2] = 4; /* reserved = 0 | S bit = 1 | W bit = 0 | R bit = 0 */ + buf[2] = bits; buf[3] = 32; /* mask len */ memcpy(buf+4, &addr, sizeof(struct in_addr)); diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h index ece900db5f..4a13040af6 100644 --- a/pimd/pim_msg.h +++ b/pimd/pim_msg.h @@ -44,8 +44,13 @@ uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, int buf_size, struct in_addr addr); + +#define PIM_ENCODE_SPARSE_BIT 0x04 +#define PIM_ENCODE_WC_BIT 0x02 +#define PIM_ENCODE_RPT_BIT 0x01 uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf, int buf_size, - struct in_addr addr); + struct in_addr addr, + uint8_t bits); #endif /* PIM_MSG_H */ diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index 5269bb5efe..93227d6339 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -96,6 +96,33 @@ uint8_t *pim_tlv_append_uint32(uint8_t *buf, #define ucast_ipv4_encoding_len (2 + sizeof(struct in_addr)) +/* + * An Encoded-Unicast address takes the following format: + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Addr Family | Encoding Type | Unicast Address + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+... + * + * Addr Family + * The PIM address family of the 'Unicast Address' field of this + * address. + * + * Values 0-127 are as assigned by the IANA for Internet Address * Families in [7]. Values 128-250 are reserved to be assigned by + * the IANA for PIM-specific Address Families. Values 251 though + * 255 are designated for private use. As there is no assignment + * authority for this space, collisions should be expected. + * + * Encoding Type + * The type of encoding used within a specific Address Family. The + * value '0' is reserved for this field and represents the native + * encoding of the Address Family. + * + * Unicast Address + * The unicast address as represented by the given Address Family + * and Encoding Type. + */ int pim_encode_addr_ucast (uint8_t *buf, struct prefix *p) { -- 2.39.5