Skip to content

Commit 9f8968f

Browse files
committed
*: Allow 16 bit size for nexthops
Currently FRR is limiting the nexthop count to a uint8_t not a uint16_t. This leads to issues when the nexthop count is 256 which results in the count to overflow to 0 causing problems in the code. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
1 parent 382e4e9 commit 9f8968f

File tree

12 files changed

+41
-57
lines changed

12 files changed

+41
-57
lines changed

bgpd/bgp_addpath.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ void bgp_addpath_type_changed(struct bgp *bgp)
361361
}
362362
}
363363

364-
int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type,
365-
uint8_t paths)
364+
int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type, uint16_t paths)
366365
{
367366
int action = CAPABILITY_ACTION_UNSET;
368367

@@ -392,8 +391,7 @@ int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type,
392391
* change take effect.
393392
*/
394393
void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
395-
enum bgp_addpath_strat addpath_type,
396-
uint8_t paths)
394+
enum bgp_addpath_strat addpath_type, uint16_t paths)
397395
{
398396
struct bgp *bgp = peer->bgp;
399397
enum bgp_addpath_strat old_type;

bgpd/bgp_addpath.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ bool bgp_addpath_tx_path(enum bgp_addpath_strat strat,
6262
* Change the type of addpath used for a peer.
6363
*/
6464
void bgp_addpath_set_peer_type(struct peer *peer, afi_t afi, safi_t safi,
65-
enum bgp_addpath_strat addpath_type,
66-
uint8_t paths);
65+
enum bgp_addpath_strat addpath_type, uint16_t paths);
6766

6867
void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_dest *dest, afi_t afi,
6968
safi_t safi);
7069

7170
void bgp_addpath_type_changed(struct bgp *bgp);
72-
extern int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type,
73-
uint8_t paths);
71+
extern int bgp_addpath_capability_action(enum bgp_addpath_strat addpath_type, uint16_t paths);
7472
#endif

bgpd/bgp_nexthop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct bgp_nexthop_cache {
3838
uint32_t metric;
3939

4040
/* Nexthop number and nexthop linked list.*/
41-
uint8_t nexthop_num;
41+
uint16_t nexthop_num;
4242

4343
/* This flag is set to TRUE for a bnc that is gateway IP overlay index
4444
* nexthop.

bgpd/bgp_nht.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ static void bgp_nht_ifp_table_handle(struct bgp *bgp,
761761
{
762762
struct bgp_nexthop_cache *bnc;
763763
struct nexthop *nhop;
764-
uint8_t other_nh_count;
764+
uint16_t other_nh_count;
765765
bool nhop_ll_found = false;
766766
bool nhop_found = false;
767767

pimd/pim_nht.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim,
573573
ifindex_t first_ifindex;
574574
struct interface *ifp = NULL;
575575
uint32_t hash_val = 0, mod_val = 0;
576-
uint8_t nh_iter = 0, found = 0;
576+
uint16_t nh_iter = 0, found = 0;
577577
uint32_t i, num_nbrs = 0;
578578
struct pim_interface *pim_ifp;
579579

@@ -947,7 +947,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim,
947947
struct interface *ifps[router->multipath], *ifp;
948948
int first_ifindex;
949949
int found = 0;
950-
uint8_t i = 0;
950+
uint16_t i = 0;
951951
uint32_t hash_val = 0, mod_val = 0;
952952
uint32_t num_nbrs = 0;
953953
struct pim_interface *pim_ifp;

pimd/pim_nht.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct pim_nexthop_cache {
2323
uint32_t metric;
2424
uint32_t distance;
2525
/* Nexthop number and nexthop linked list. */
26-
uint8_t nexthop_num;
26+
uint16_t nexthop_num;
2727
struct nexthop *nexthop;
2828
int64_t last_update;
2929
uint16_t flags;

zebra/rt_netlink.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -591,12 +591,9 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb,
591591
return nh;
592592
}
593593

594-
static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id,
595-
struct nexthop_group *ng,
596-
struct rtmsg *rtm,
597-
struct rtnexthop *rtnh,
598-
struct rtattr **tb,
599-
void *prefsrc, vrf_id_t vrf_id)
594+
static uint16_t parse_multipath_nexthops_unicast(ns_id_t ns_id, struct nexthop_group *ng,
595+
struct rtmsg *rtm, struct rtnexthop *rtnh,
596+
struct rtattr **tb, void *prefsrc, vrf_id_t vrf_id)
600597
{
601598
void *gate = NULL;
602599
struct interface *ifp = NULL;
@@ -721,7 +718,7 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id,
721718
rtnh = RTNH_NEXT(rtnh);
722719
}
723720

724-
uint8_t nhop_num = nexthop_group_nexthop_num(ng);
721+
uint16_t nhop_num = nexthop_group_nexthop_num(ng);
725722

726723
return nhop_num;
727724
}
@@ -1000,7 +997,7 @@ int netlink_route_change_read_unicast_internal(struct nlmsghdr *h,
1000997
(struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);
1001998

1002999
if (!nhe_id) {
1003-
uint8_t nhop_num;
1000+
uint16_t nhop_num;
10041001

10051002
/* Use temporary list of nexthops; parse
10061003
* message payload's nexthops.
@@ -2644,11 +2641,9 @@ int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in)
26442641
/* Char length to debug ID with */
26452642
#define ID_LENGTH 10
26462643

2647-
static bool _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size,
2648-
uint32_t id,
2649-
const struct nh_grp *z_grp,
2650-
const uint8_t count, bool resilient,
2651-
const struct nhg_resilience *nhgr)
2644+
static bool _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size, uint32_t id,
2645+
const struct nh_grp *z_grp, const uint16_t count,
2646+
bool resilient, const struct nhg_resilience *nhgr)
26522647
{
26532648
struct nexthop_grp grp[count];
26542649
/* Need space for max group size, "/", and null term */
@@ -3285,7 +3280,7 @@ static int netlink_nexthop_process_group(struct rtattr **tb,
32853280
struct nh_grp *z_grp, int z_grp_size,
32863281
struct nhg_resilience *nhgr)
32873282
{
3288-
uint8_t count = 0;
3283+
uint16_t count = 0;
32893284
/* linux/nexthop.h group struct */
32903285
struct nexthop_grp *n_grp = NULL;
32913286

@@ -3358,7 +3353,7 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
33583353
struct nexthop nh = {.weight = 1};
33593354
struct nh_grp grp[MULTIPATH_NUM] = {};
33603355
/* Count of nexthops in group array */
3361-
uint8_t grp_count = 0;
3356+
uint16_t grp_count = 0;
33623357
struct rtattr *tb[NHA_MAX + 1] = {};
33633358

33643359
frrtrace(3, frr_zebra, netlink_nexthop_change, h, ns_id, startup);

zebra/zapi_msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ int zsend_redistribute_route(int cmd, struct zserv *client,
517517
struct zapi_nexthop *api_nh;
518518
struct nexthop *nexthop;
519519
const struct prefix *p, *src_p;
520-
uint8_t count = 0;
520+
uint16_t count = 0;
521521
afi_t afi;
522522
size_t stream_size =
523523
MAX(ZEBRA_MAX_PACKET_SIZ, sizeof(struct zapi_route));

zebra/zebra_dplane.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct dplane_nexthop_info {
8686

8787
struct nexthop_group ng;
8888
struct nh_grp nh_grp[MULTIPATH_NUM];
89-
uint8_t nh_grp_count;
89+
uint16_t nh_grp_count;
9090
};
9191

9292
/*
@@ -2316,7 +2316,7 @@ dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx *ctx)
23162316
return ctx->u.rinfo.nhe.nh_grp;
23172317
}
23182318

2319-
uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx)
2319+
uint16_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx)
23202320
{
23212321
DPLANE_CTX_VALID(ctx);
23222322
return ctx->u.rinfo.nhe.nh_grp_count;

zebra/zebra_dplane.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ const struct nexthop_group *
597597
dplane_ctx_get_nhe_ng(const struct zebra_dplane_ctx *ctx);
598598
const struct nh_grp *
599599
dplane_ctx_get_nhe_nh_grp(const struct zebra_dplane_ctx *ctx);
600-
uint8_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx);
600+
uint16_t dplane_ctx_get_nhe_nh_grp_count(const struct zebra_dplane_ctx *ctx);
601601

602602
/* Accessors for LSP information */
603603

0 commit comments

Comments
 (0)