diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-02-10 14:05:42 -0500 | 
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-02-24 10:03:40 -0500 | 
| commit | 74ac496fcbf976bebaa76728090c68c74865a66d (patch) | |
| tree | b83351d5cdadac1cfef1f693b5d17441f88fb0a1 /pimd/pim_msg.c | |
| parent | f8e7d7992fe201052e3969bdd4aab217ffd4d505 (diff) | |
pimd: Add packed data structures for building j/p messages
Switch pim over to using packed data structures for building
Join/Prune messages to be sent.
This is a pre-cursor to the ability to handle the ability
to aggregate Join/Prune messages together.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'pimd/pim_msg.c')
| -rw-r--r-- | pimd/pim_msg.c | 166 | 
1 files changed, 69 insertions, 97 deletions
diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index 4378ac99f7..3a8ccb887e 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -161,25 +161,16 @@ pim_msg_addr_encode_ipv4_source(uint8_t *buf,   */  int  pim_msg_join_prune_encode (uint8_t *buf, size_t buf_size, int is_join, -			   struct pim_upstream *up, -			   struct in_addr upstream, int holdtime) +                           struct pim_upstream *up, +                           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; -  uint16_t *prunes = NULL; -  uint16_t *joins = NULL; +  struct pim_jp *msg = (struct pim_jp *)buf;    struct in_addr stosend;    uint8_t bits; -  int remain; -  size_t min_len = PIM_MSG_HEADER_LEN + PIM_JP_GROUP_HEADER_SIZE + -    PIM_ENCODED_IPV4_SOURCE_SIZE;   // Only 1 source -  assert(buf_size > min_len); +  assert(buf_size > sizeof (struct pim_jp)); -  remain = end - pim_msg_curr; -  pim_msg_curr = pim_msg_addr_encode_ipv4_ucast (pim_msg_curr, upstream); -  if (!pim_msg_curr) { +  if (!pim_msg_addr_encode_ipv4_ucast ((uint8_t *)&msg->addr, upstream)) {      char dst_str[INET_ADDRSTRLEN];      pim_inet4_dump("<dst?>", upstream, dst_str, sizeof(dst_str));      zlog_warn("%s: failure encoding destination address %s", @@ -187,40 +178,22 @@ pim_msg_join_prune_encode (uint8_t *buf, size_t buf_size, int is_join,      return -3;    } -  *pim_msg_curr = 0; /* reserved */ -  ++pim_msg_curr; -  *pim_msg_curr = 1; /* number of groups */ -  ++pim_msg_curr; +  msg->reserved   = 0; +  msg->num_groups = 1; +  msg->holdtime   = htons(holdtime); -  *((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, up->sg.grp); -  if (!pim_msg_curr) { +  if (!pim_msg_addr_encode_ipv4_group ((uint8_t *)&msg->groups[0].g, up->sg.grp)) {      char group_str[INET_ADDRSTRLEN];      pim_inet4_dump("<grp?>", up->sg.grp, group_str, sizeof(group_str));      zlog_warn("%s: failure encoding group address %s", -	      __PRETTY_FUNCTION__, group_str); +              __PRETTY_FUNCTION__, group_str);      return -5;    } -  remain = end - pim_msg_curr; - -  /* number of joined sources */ -  joins = (uint16_t *)pim_msg_curr; -  *joins = htons(is_join ? 1 : 0); -  ++pim_msg_curr; -  ++pim_msg_curr; +  /* number of joined/pruned sources */ +  msg->groups[0].joins  = htons(is_join ? 1 : 0); +  msg->groups[0].prunes = htons(is_join ? 0 : 1); -  /* number of pruned sources */ -  prunes = (uint16_t *)pim_msg_curr; -  *prunes = htons(is_join ? 0 : 1); -  ++pim_msg_curr; -  ++pim_msg_curr; - -  remain = end - pim_msg_curr;    if (up->sg.src.s_addr == INADDR_ANY)      {        struct pim_rpf *rpf = pim_rp_g (up->sg.grp); @@ -232,15 +205,14 @@ pim_msg_join_prune_encode (uint8_t *buf, size_t buf_size, int is_join,        bits = PIM_ENCODE_SPARSE_BIT;        stosend = up->sg.src;      } -  pim_msg_curr = pim_msg_addr_encode_ipv4_source (pim_msg_curr, stosend, bits); -  if (!pim_msg_curr) { + +  if (!pim_msg_addr_encode_ipv4_source ((uint8_t *)&msg->groups[0].s[0], stosend, bits)) {      char source_str[INET_ADDRSTRLEN];      pim_inet4_dump("<src?>", up->sg.src, source_str, sizeof(source_str));      zlog_warn("%s: failure encoding source address %s", -	      __PRETTY_FUNCTION__, source_str); +              __PRETTY_FUNCTION__, source_str);      return -7;    } -  remain = pim_msg_curr - pim_msg;    /*     * This is not implemented correctly at this point in time @@ -254,61 +226,61 @@ pim_msg_join_prune_encode (uint8_t *buf, size_t buf_size, int is_join,        int send_prune = 0;        zlog_debug ("%s: Considering (%s) children for (S,G,rpt) prune", -		  __PRETTY_FUNCTION__, up->sg_str); +                  __PRETTY_FUNCTION__, up->sg_str);        for (ALL_LIST_ELEMENTS_RO (up->sources, up_node, child)) -	{ -	  if (child->sptbit == PIM_UPSTREAM_SPTBIT_TRUE) -	    { -	      if (!pim_rpf_is_same(&up->rpf, &child->rpf)) -		{ -		  send_prune = 1; -		  if (PIM_DEBUG_PIM_PACKETS) -		    zlog_debug ("%s: SPT Bit and RPF'(%s) != RPF'(S,G): Add Prune (%s,rpt) to compound message", -				__PRETTY_FUNCTION__, up->sg_str, child->sg_str); -		} -	      else -		if (PIM_DEBUG_PIM_PACKETS) -		  zlog_debug ("%s: SPT Bit and RPF'(%s) == RPF'(S,G): Not adding Prune for (%s,rpt)", -			      __PRETTY_FUNCTION__, up->sg_str, child->sg_str); -	    } -	  else if (pim_upstream_is_sg_rpt (child)) -	    { -	      if (pim_upstream_empty_inherited_olist (child)) -		{ -		  send_prune = 1; -		  if (PIM_DEBUG_PIM_PACKETS) -		    zlog_debug ("%s: inherited_olist(%s,rpt) is NULL, Add Prune to compound message", -				__PRETTY_FUNCTION__, child->sg_str); -		} -	      else if (!pim_rpf_is_same (&up->rpf, &child->rpf)) -		{ -		  send_prune = 1; -		  if (PIM_DEBUG_PIM_PACKETS) -		    zlog_debug ("%s: RPF'(%s) != RPF'(%s,rpt), Add Prune to compound message", -				__PRETTY_FUNCTION__, up->sg_str, child->sg_str); -		} -	      else -		if (PIM_DEBUG_PIM_PACKETS) -		  zlog_debug ("%s: RPF'(%s) == RPF'(%s,rpt), Do not add Prune to compound message", -			      __PRETTY_FUNCTION__, up->sg_str, child->sg_str); -	    } -	  else -	    if (PIM_DEBUG_PIM_PACKETS) -	      zlog_debug ("%s: SPT bit is not set for (%s)", -			  __PRETTY_FUNCTION__, child->sg_str); -	  if (send_prune) -	    { -	      pim_msg_curr = pim_msg_addr_encode_ipv4_source (pim_msg_curr, remain, -							      child->sg.src, -							      PIM_ENCODE_SPARSE_BIT | PIM_ENCODE_RPT_BIT); -	      remain = pim_msg_curr - pim_msg; -	      *prunes = htons(ntohs(*prunes) + 1); -	      send_prune = 0; -	    } -	} +        { +          if (child->sptbit == PIM_UPSTREAM_SPTBIT_TRUE) +            { +              if (!pim_rpf_is_same(&up->rpf, &child->rpf)) +                { +                  send_prune = 1; +                  if (PIM_DEBUG_PIM_PACKETS) +                    zlog_debug ("%s: SPT Bit and RPF'(%s) != RPF'(S,G): Add Prune (%s,rpt) to compound message", +                                __PRETTY_FUNCTION__, up->sg_str, child->sg_str); +                } +              else +                if (PIM_DEBUG_PIM_PACKETS) +                  zlog_debug ("%s: SPT Bit and RPF'(%s) == RPF'(S,G): Not adding Prune for (%s,rpt)", +                              __PRETTY_FUNCTION__, up->sg_str, child->sg_str); +            } +          else if (pim_upstream_is_sg_rpt (child)) +            { +              if (pim_upstream_empty_inherited_olist (child)) +                { +                  send_prune = 1; +                  if (PIM_DEBUG_PIM_PACKETS) +                    zlog_debug ("%s: inherited_olist(%s,rpt) is NULL, Add Prune to compound message", +                                __PRETTY_FUNCTION__, child->sg_str); +                } +              else if (!pim_rpf_is_same (&up->rpf, &child->rpf)) +                { +                  send_prune = 1; +                  if (PIM_DEBUG_PIM_PACKETS) +                    zlog_debug ("%s: RPF'(%s) != RPF'(%s,rpt), Add Prune to compound message", +                                __PRETTY_FUNCTION__, up->sg_str, child->sg_str); +                } +              else +                if (PIM_DEBUG_PIM_PACKETS) +                  zlog_debug ("%s: RPF'(%s) == RPF'(%s,rpt), Do not add Prune to compound message", +                              __PRETTY_FUNCTION__, up->sg_str, child->sg_str); +            } +          else +            if (PIM_DEBUG_PIM_PACKETS) +              zlog_debug ("%s: SPT bit is not set for (%s)", +                          __PRETTY_FUNCTION__, child->sg_str); +          if (send_prune) +            { +              pim_msg_curr = pim_msg_addr_encode_ipv4_source (pim_msg_curr, remain, +                                                              child->sg.src, +                                                              PIM_ENCODE_SPARSE_BIT | PIM_ENCODE_RPT_BIT); +              remain = pim_msg_curr - pim_msg; +              *prunes = htons(ntohs(*prunes) + 1); +              send_prune = 0; +            } +        }      }  #endif -  pim_msg_build_header (pim_msg, remain, PIM_MSG_TYPE_JOIN_PRUNE); +  pim_msg_build_header (buf, sizeof (struct pim_jp), PIM_MSG_TYPE_JOIN_PRUNE); -  return remain; +  return sizeof (struct pim_jp);  }  | 
