]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_lcommunity.c
lib, bgpd: implement pthread lifecycle management
[mirror_frr.git] / bgpd / bgp_lcommunity.c
index ad7cb36afeed6e4187111030e2db440b700ee732..54e9fd889457757d563c5772a9d56dd6bc66d15b 100644 (file)
@@ -25,6 +25,8 @@
 #include "prefix.h"
 #include "command.h"
 #include "filter.h"
+#include "jhash.h"
+#include "stream.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_lcommunity.h"
@@ -230,26 +232,8 @@ unsigned int lcommunity_hash_make(void *arg)
 {
        const struct lcommunity *lcom = arg;
        int size = lcom_length(lcom);
-       u_int8_t *pnt = lcom->val;
-       unsigned int key = 0;
-       int c;
-
-       for (c = 0; c < size; c += LCOMMUNITY_SIZE) {
-               key += pnt[c];
-               key += pnt[c + 1];
-               key += pnt[c + 2];
-               key += pnt[c + 3];
-               key += pnt[c + 4];
-               key += pnt[c + 5];
-               key += pnt[c + 6];
-               key += pnt[c + 7];
-               key += pnt[c + 8];
-               key += pnt[c + 9];
-               key += pnt[c + 10];
-               key += pnt[c + 11];
-       }
 
-       return key;
+       return jhash(lcom->val, size, 0xab125423);
 }
 
 /* Compare two Large Communities Attribute structure.  */
@@ -272,7 +256,9 @@ struct hash *lcommunity_hash(void)
 /* Initialize Large Comminities related hash. */
 void lcommunity_init(void)
 {
-       lcomhash = hash_create(lcommunity_hash_make, lcommunity_cmp, NULL);
+       lcomhash = hash_create(lcommunity_hash_make,
+                              lcommunity_cmp,
+                              "BGP lcommunity hash");
 }
 
 void lcommunity_finish(void)
@@ -446,20 +432,10 @@ char *lcommunity_lcom2str(struct lcommunity *lcom, int format)
 
                pnt = lcom->val + (i * LCOMMUNITY_SIZE);
 
-               globaladmin = (*pnt++ << 24);
-               globaladmin |= (*pnt++ << 16);
-               globaladmin |= (*pnt++ << 8);
-               globaladmin |= (*pnt++);
-
-               localdata1 = (*pnt++ << 24);
-               localdata1 |= (*pnt++ << 16);
-               localdata1 |= (*pnt++ << 8);
-               localdata1 |= (*pnt++);
-
-               localdata2 = (*pnt++ << 24);
-               localdata2 |= (*pnt++ << 16);
-               localdata2 |= (*pnt++ << 8);
-               localdata2 |= (*pnt++);
+               pnt = ptr_get_be32(pnt, &globaladmin);
+               pnt = ptr_get_be32(pnt, &localdata1);
+               pnt = ptr_get_be32(pnt, &localdata2);
+               (void)pnt; /* consume value */
 
                len = sprintf(str_buf + str_pnt, "%u:%u:%u", globaladmin,
                              localdata1, localdata2);
@@ -523,10 +499,10 @@ void lcommunity_del_val(struct lcommunity *lcom, u_char *ptr)
 
                        if (lcom->size > 0)
                                lcom->val =
-                                       XREALLOC(MTYPE_COMMUNITY_VAL, lcom->val,
+                                       XREALLOC(MTYPE_LCOMMUNITY_VAL, lcom->val,
                                                 lcom_length(lcom));
                        else {
-                               XFREE(MTYPE_COMMUNITY_VAL, lcom->val);
+                               XFREE(MTYPE_LCOMMUNITY_VAL, lcom->val);
                                lcom->val = NULL;
                        }
                        return;