Skip to content

Commit

Permalink
Merge pull request #1863 from donaldsharp/more_nh_groups
Browse files Browse the repository at this point in the history
More nh groups
  • Loading branch information
pguibert6WIND authored Mar 14, 2018
2 parents 2b9a295 + 1b7bce0 commit 2f9fca6
Show file tree
Hide file tree
Showing 4 changed files with 400 additions and 8 deletions.
51 changes: 51 additions & 0 deletions lib/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,57 @@ void nexthops_free(struct nexthop *nexthop)
}
}

bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2)
{
if (nh1 && !nh2)
return false;

if (!nh1 && nh2)
return false;

if (nh1 == nh2)
return true;

if (nh1->vrf_id != nh2->vrf_id)
return false;

if (nh1->type != nh2->type)
return false;

switch (nh1->type) {
case NEXTHOP_TYPE_IFINDEX:
if (nh1->ifindex != nh2->ifindex)
return false;
break;
case NEXTHOP_TYPE_IPV4:
if (nh1->gate.ipv4.s_addr != nh2->gate.ipv4.s_addr)
return false;
break;
case NEXTHOP_TYPE_IPV4_IFINDEX:
if (nh1->gate.ipv4.s_addr != nh2->gate.ipv4.s_addr)
return false;
if (nh1->ifindex != nh2->ifindex)
return false;
break;
case NEXTHOP_TYPE_IPV6:
if (memcmp(&nh1->gate.ipv6, &nh2->gate.ipv6, 16))
return false;
break;
case NEXTHOP_TYPE_IPV6_IFINDEX:
if (memcmp(&nh1->gate.ipv6, &nh2->gate.ipv6, 16))
return false;
if (nh1->ifindex != nh2->ifindex)
return false;
break;
case NEXTHOP_TYPE_BLACKHOLE:
if (nh1->bh_type != nh2->bh_type)
return false;
break;
}

return true;
}

/* Update nexthop with label information. */
void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t type,
u_int8_t num_labels, mpls_label_t *label)
Expand Down
2 changes: 2 additions & 0 deletions lib/nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void nexthop_add_labels(struct nexthop *, enum lsp_types_t, u_int8_t,
mpls_label_t *);
void nexthop_del_labels(struct nexthop *);

extern bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2);

extern const char *nexthop_type_to_str(enum nexthop_types_t nh_type);
extern int nexthop_same_no_recurse(const struct nexthop *next1,
const struct nexthop *next2);
Expand Down
Loading

0 comments on commit 2f9fca6

Please sign in to comment.