Skip to content

Commit 66f552c

Browse files
committed
lib: Add nexthop_same_no_ifindex comparison function
Add a nexthop_same_no_ifindex comparison function to allow nexthops to be compared without looking at the outgoing ifindex. This is because sometimes it is not possible to resolve a nh to a ifindex when zebra receives it and we need the ability to compare them then. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
1 parent 7307cdd commit 66f552c

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/nexthop.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int _nexthop_source_cmp(const struct nexthop *nh1,
145145
}
146146

147147
static int _nexthop_cmp_no_labels(const struct nexthop *next1,
148-
const struct nexthop *next2, bool use_weight)
148+
const struct nexthop *next2, bool use_weight, bool use_ifindex)
149149
{
150150
int ret = 0;
151151

@@ -181,6 +181,8 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1,
181181
ret = _nexthop_gateway_cmp(next1, next2);
182182
if (ret != 0)
183183
return ret;
184+
if (!use_ifindex)
185+
break;
184186
fallthrough;
185187
case NEXTHOP_TYPE_IFINDEX:
186188
if (next1->ifindex < next2->ifindex)
@@ -236,11 +238,11 @@ static int _nexthop_cmp_no_labels(const struct nexthop *next1,
236238
}
237239

238240
static int nexthop_cmp_internal(const struct nexthop *next1,
239-
const struct nexthop *next2, bool use_weight)
241+
const struct nexthop *next2, bool use_weight, bool use_ifindex)
240242
{
241243
int ret = 0;
242244

243-
ret = _nexthop_cmp_no_labels(next1, next2, use_weight);
245+
ret = _nexthop_cmp_no_labels(next1, next2, use_weight, use_ifindex);
244246
if (ret != 0)
245247
return ret;
246248

@@ -255,13 +257,13 @@ static int nexthop_cmp_internal(const struct nexthop *next1,
255257

256258
int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2)
257259
{
258-
return nexthop_cmp_internal(next1, next2, true);
260+
return nexthop_cmp_internal(next1, next2, true, true);
259261
}
260262

261263
int nexthop_cmp_no_weight(const struct nexthop *next1,
262264
const struct nexthop *next2)
263265
{
264-
return nexthop_cmp_internal(next1, next2, false);
266+
return nexthop_cmp_internal(next1, next2, false, true);
265267
}
266268

267269
/*
@@ -432,6 +434,20 @@ void nexthops_free(struct nexthop *nexthop)
432434
}
433435
}
434436

437+
bool nexthop_same_no_ifindex(const struct nexthop *nh1, const struct nexthop *nh2)
438+
{
439+
if (nh1 && !nh2)
440+
return false;
441+
442+
if (!nh1 && nh2)
443+
return false;
444+
445+
if (nh1 == nh2)
446+
return true;
447+
448+
return nexthop_cmp_internal(nh1, nh2, true, false);
449+
}
450+
435451
bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2)
436452
{
437453
if (nh1 && !nh2)
@@ -461,7 +477,7 @@ bool nexthop_same_no_labels(const struct nexthop *nh1,
461477
if (nh1 == nh2)
462478
return true;
463479

464-
if (_nexthop_cmp_no_labels(nh1, nh2, true) != 0)
480+
if (_nexthop_cmp_no_labels(nh1, nh2, true, true) != 0)
465481
return false;
466482

467483
return true;

lib/nexthop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ struct nexthop *nexthop_from_blackhole(enum blackhole_type bh_type,
238238
uint32_t nexthop_hash(const struct nexthop *nexthop);
239239

240240
extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2);
241+
extern bool nexthop_same_no_ifindex(const struct nexthop *nh1, const struct nexthop *nh2);
241242
extern bool nexthop_same_no_labels(const struct nexthop *nh1,
242243
const struct nexthop *nh2);
243244
extern int nexthop_cmp(const struct nexthop *nh1, const struct nexthop *nh2);

0 commit comments

Comments
 (0)