X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=pbrd%2Fpbr_nht.c;h=6103bd7db5e2cf71a6e85f90cc018c480b040aac;hb=c52e2ecf95a9be318912caacc0851d9307e679f7;hp=5be96e86d00c030abd80036423b86586493e8941;hpb=1b6e597ccae19986679b7e2d2b4fcc8b66bd6328;p=mirror_frr.git diff --git a/pbrd/pbr_nht.c b/pbrd/pbr_nht.c index 5be96e86d..6103bd7db 100644 --- a/pbrd/pbr_nht.c +++ b/pbrd/pbr_nht.c @@ -69,7 +69,7 @@ static void *pbr_nhrc_hash_alloc(void *p) return nhrc; } -static int pbr_nhrc_hash_equal(const void *arg1, const void *arg2) +static bool pbr_nhrc_hash_equal(const void *arg1, const void *arg2) { const struct nexthop *nh1, *nh2; @@ -139,7 +139,7 @@ static uint32_t pbr_nh_hash_key(void *arg) return key; } -static int pbr_nh_hash_equal(const void *arg1, const void *arg2) +static bool pbr_nh_hash_equal(const void *arg1, const void *arg2) { const struct pbr_nexthop_cache *pbrnc1 = (const struct pbr_nexthop_cache *)arg1; @@ -147,25 +147,25 @@ static int pbr_nh_hash_equal(const void *arg1, const void *arg2) (const struct pbr_nexthop_cache *)arg2; if (pbrnc1->nexthop->vrf_id != pbrnc2->nexthop->vrf_id) - return 0; + return false; if (pbrnc1->nexthop->ifindex != pbrnc2->nexthop->ifindex) - return 0; + return false; if (pbrnc1->nexthop->type != pbrnc2->nexthop->type) - return 0; + return false; switch (pbrnc1->nexthop->type) { case NEXTHOP_TYPE_IFINDEX: - return 1; + return true; case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4: return pbrnc1->nexthop->gate.ipv4.s_addr == pbrnc2->nexthop->gate.ipv4.s_addr; case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6: - return !memcmp(&pbrnc1->nexthop->gate.ipv6, - &pbrnc2->nexthop->gate.ipv6, 16); + return !!memcmp(&pbrnc1->nexthop->gate.ipv6, + &pbrnc2->nexthop->gate.ipv6, 16); case NEXTHOP_TYPE_BLACKHOLE: return pbrnc1->nexthop->bh_type == pbrnc2->nexthop->bh_type; } @@ -173,7 +173,7 @@ static int pbr_nh_hash_equal(const void *arg1, const void *arg2) /* * We should not get here */ - return 0; + return false; } static void pbr_nhgc_delete(struct pbr_nexthop_group_cache *p) @@ -192,7 +192,7 @@ static void *pbr_nhgc_alloc(void *p) new = XCALLOC(MTYPE_PBR_NHG, sizeof(*new)); strcpy(new->name, pnhgc->name); - new->table_id = pbr_nht_get_next_tableid(); + new->table_id = pbr_nht_get_next_tableid(false); DEBUGD(&pbr_dbg_nht, "%s: NHT: %s assigned Table ID: %u", __PRETTY_FUNCTION__, new->name, new->table_id); @@ -218,6 +218,9 @@ void pbr_nhgroup_add_cb(const char *name) pnhgc = pbr_nht_add_group(name); + if (!pnhgc) + return; + DEBUGD(&pbr_dbg_nht, "%s: Added nexthop-group %s", __PRETTY_FUNCTION__, name); @@ -234,6 +237,13 @@ void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, struct pbr_nexthop_cache pnhc_find = {}; struct pbr_nexthop_cache *pnhc; + if (!pbr_nht_get_next_tableid(true)) { + zlog_warn( + "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", + __PRETTY_FUNCTION__, nhgc->name); + return; + } + /* find pnhgc by name */ strlcpy(pnhgc_find.name, nhgc->name, sizeof(pnhgc_find.name)); pnhgc = hash_get(pbr_nhg_hash, &pnhgc_find, pbr_nhgc_alloc); @@ -268,7 +278,7 @@ void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc, /* find pnhgc by name */ strlcpy(pnhgc_find.name, nhgc->name, sizeof(pnhgc_find.name)); - pnhgc = hash_get(pbr_nhg_hash, &pnhgc_find, pbr_nhgc_alloc); + pnhgc = hash_lookup(pbr_nhg_hash, &pnhgc_find); /* delete pnhc from pnhgc->nhh */ pnhc_find.nexthop = (struct nexthop *)nhop; @@ -470,18 +480,6 @@ void pbr_nht_change_group(const char *name) pbr_nht_install_nexthop_group(pnhgc, nhgc->nhg); } -/* - * Since we are writing into the name field which is PBR_MAP_NAMELEN - * size, we are expecting this to field to be at max 100 bytes. - * Newer compilers understand that the %s portion may be up to - * 100 bytes( because of the size of the string. The %u portion - * is expected to be 10 bytes. So in `theory` there are situations - * where we might truncate. The reality this is never going to - * happen( who is going to create a nexthop group name that is - * over say 30 characters? ). As such we are expecting the - * calling function to subtract 10 from the size_t l before - * we pass it in to get around this new gcc fun. - */ char *pbr_nht_nexthop_make_name(char *name, size_t l, uint32_t seqno, char *buffer) { @@ -497,8 +495,16 @@ void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms) struct pbr_nexthop_cache lookup; memset(&find, 0, sizeof(find)); - pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_MAP_NAMELEN - 10, + pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_NHC_NAMELEN, pbrms->seqno, find.name); + + if (!pbr_nht_get_next_tableid(true)) { + zlog_warn( + "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", + __PRETTY_FUNCTION__, find.name); + return; + } + if (!pbrms->internal_nhg_name) pbrms->internal_nhg_name = XSTRDUP(MTYPE_TMP, find.name); @@ -559,11 +565,18 @@ struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name) struct pbr_nexthop_group_cache *pnhgc; struct pbr_nexthop_group_cache lookup; + if (!pbr_nht_get_next_tableid(true)) { + zlog_warn( + "%s: Exhausted all table identifiers; cannot create nexthop-group cache for nexthop-group '%s'", + __PRETTY_FUNCTION__, name); + return NULL; + } + nhgc = nhgc_find(name); if (!nhgc) { - zlog_warn("%s: Could not find group %s to add", - __PRETTY_FUNCTION__, name); + DEBUGD(&pbr_dbg_nht, "%s: Could not find nhgc with name: %s\n", + __PRETTY_FUNCTION__, name); return NULL; } @@ -573,13 +586,13 @@ struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name) pnhgc); for (ALL_NEXTHOPS(nhgc->nhg, nhop)) { - struct pbr_nexthop_cache lookup; + struct pbr_nexthop_cache lookupc; struct pbr_nexthop_cache *pnhc; - lookup.nexthop = nhop; - pnhc = hash_lookup(pnhgc->nhh, &lookup); + lookupc.nexthop = nhop; + pnhc = hash_lookup(pnhgc->nhh, &lookupc); if (!pnhc) { - pnhc = hash_get(pnhgc->nhh, &lookup, pbr_nh_alloc); + pnhc = hash_get(pnhgc->nhh, &lookupc, pbr_nh_alloc); pnhc->parent = pnhgc; } } @@ -711,7 +724,7 @@ static uint32_t pbr_nhg_hash_key(void *arg) return jhash(&nhgc->name, strlen(nhgc->name), 0x52c34a96); } -static int pbr_nhg_hash_equal(const void *arg1, const void *arg2) +static bool pbr_nhg_hash_equal(const void *arg1, const void *arg2) { const struct pbr_nexthop_group_cache *nhgc1 = (const struct pbr_nexthop_group_cache *)arg1; @@ -721,8 +734,7 @@ static int pbr_nhg_hash_equal(const void *arg1, const void *arg2) return !strcmp(nhgc1->name, nhgc2->name); } - -uint32_t pbr_nht_get_next_tableid(void) +uint32_t pbr_nht_get_next_tableid(bool peek) { uint32_t i; bool found = false; @@ -735,7 +747,7 @@ uint32_t pbr_nht_get_next_tableid(void) } if (found) { - nhg_tableid[i] = true; + nhg_tableid[i] = !peek; return i; } else return 0;