]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd: Add packed data structures for building j/p messages
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 10 Feb 2017 19:05:42 +0000 (14:05 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 24 Feb 2017 15:03:40 +0000 (10:03 -0500)
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>
pimd/pim_msg.c
pimd/pim_msg.h

index 4378ac99f769f98818651b2859b12bf6bd660f78..3a8ccb887e9e69dae87f0a35a258209a48c3d04c 100644 (file)
@@ -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);
 }
index 3be37ac3680615f8157f1f8b3ca8ab73d1e971b2..3af8486d5d0a99f13f401c9cd950acbbbf67b616 100644 (file)
@@ -45,6 +45,44 @@ struct pim_msg_header {
   uint16_t checksum;
 } __attribute__ ((packed));
 
+struct pim_encoded_ipv4_unicast {
+  uint8_t  family;
+  uint8_t  reserved;
+  struct in_addr addr;
+} __attribute__ ((packed));
+
+struct pim_encoded_group_ipv4 {
+  uint8_t        ne;
+  uint8_t        family;
+  uint8_t        reserved;
+  uint8_t        mask;
+  struct in_addr addr;
+} __attribute__ ((packed));
+
+struct pim_encoded_source_ipv4 {
+  uint8_t        ne;
+  uint8_t        family;
+  uint8_t        bits;
+  uint8_t        mask;
+  struct in_addr addr;
+} __attribute__ ((packed));
+
+struct pim_jp_groups {
+  struct pim_encoded_group_ipv4  g;
+  uint16_t                       joins;
+  uint16_t                       prunes;
+  struct pim_encoded_source_ipv4 s[1];
+} __attribute__ ((packed));
+
+struct pim_jp {
+  struct pim_msg_header           header;
+  struct pim_encoded_ipv4_unicast addr;
+  uint8_t                         reserved;
+  uint8_t                         num_groups;
+  uint16_t                        holdtime;
+  struct pim_jp_groups            groups[1];
+} __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_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);