Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More nh groups #1863

Merged
merged 3 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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