#include "prefix.h"
#include "command.h"
#include "filter.h"
+#include "jhash.h"
+#include "stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_lcommunity.h"
{
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. */
/* 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)
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);
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;