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

NHG allow recursivity extension #15212

Closed
Closed
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
4 changes: 4 additions & 0 deletions lib/nexthop_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct nexthop_group {
struct nexthop *nexthop;

struct nhg_resilience nhgr;

/* nexthop group flags */
#define NEXTHOP_GROUP_ALLOW_RECURSION (1 << 1)
uint8_t flags;
};

struct nexthop_group *nexthop_group_new(void);
Expand Down
2 changes: 2 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,8 @@ static int zapi_nhg_encode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
stream_putl(s, api_nhg->resilience.idle_timer);
stream_putl(s, api_nhg->resilience.unbalanced_timer);

stream_putc(s, api_nhg->flags);

if (cmd == ZEBRA_NHG_ADD) {
/* Nexthops */
zapi_nexthop_group_sort(api_nhg->nexthops,
Expand Down
3 changes: 3 additions & 0 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ struct zapi_nhg {

uint16_t backup_nexthop_num;
struct zapi_nexthop backup_nexthops[MULTIPATH_NUM];

/* nexthop group flags */
uint8_t flags;
};

/*
Expand Down
1 change: 1 addition & 0 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg,

api_nhg.id = id;

api_nhg.flags = nhg->flags;
api_nhg.resilience = nhg->nhgr;

for (ALL_NEXTHOPS_PTR(nhg, nh)) {
Expand Down
3 changes: 3 additions & 0 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,8 @@ static int zapi_nhg_decode(struct stream *s, int cmd, struct zapi_nhg *api_nhg)
STREAM_GETL(s, api_nhg->resilience.idle_timer);
STREAM_GETL(s, api_nhg->resilience.unbalanced_timer);

STREAM_GETC(s, api_nhg->flags);

/* Nexthops */
STREAM_GETW(s, api_nhg->nexthop_num);

Expand Down Expand Up @@ -2013,6 +2015,7 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS)
nhe = zebra_nhg_alloc();
nhe->id = api_nhg.id;
nhe->type = api_nhg.proto;
nhe->nhg.flags = api_nhg.flags;
nhe->zapi_instance = client->instance;
nhe->zapi_session = client->session_id;

Expand Down
35 changes: 26 additions & 9 deletions zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2346,8 +2346,10 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe,
* if specified) - i.e., we cannot have a nexthop NH1 is
* resolved by a route NH1. The exception is if the route is a
* host route.
* This control will not work by using nexthop groups, and will
* have to be handled at protocol level
*/
if (prefix_same(&rn->p, top))
if (top && prefix_same(&rn->p, top))
if (((afi == AFI_IP)
&& (rn->p.prefixlen != IPV4_MAX_BITLEN))
|| ((afi == AFI_IP6)
Expand Down Expand Up @@ -3356,16 +3358,22 @@ bool zebra_nhg_proto_nexthops_only(void)
}

/* Add NHE from upper level proto */
struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type,
uint16_t instance, uint32_t session,
struct nhg_hash_entry *zebra_nhg_proto_add(struct nhg_hash_entry *nhe,
struct nexthop_group *nhg, afi_t afi)
{
struct nhg_hash_entry lookup;
struct nhg_hash_entry *new, *old;
struct nhg_connected *rb_node_dep = NULL;
struct nexthop *newhop;
bool replace = false;
int ret = 0;
int ret = 0, type;
uint32_t id, session, api_message = 0;
uint16_t instance;

id = nhe->id;
type = nhe->type;
session = nhe->zapi_session;
instance = nhe->zapi_instance;

if (!nhg->nexthop) {
if (IS_ZEBRA_DEBUG_NHG)
Expand Down Expand Up @@ -3407,14 +3415,23 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type,
return NULL;
}

if (!newhop->ifindex) {
if (!newhop->ifindex &&
!CHECK_FLAG(nhg->flags, NEXTHOP_GROUP_ALLOW_RECURSION)) {
if (IS_ZEBRA_DEBUG_NHG)
zlog_debug(
"%s: id %u, nexthop without ifindex is not supported",
__func__, id);
zlog_debug("%s: id %u, nexthop without ifindex and allow-recursion is not supported",
__func__, id);
return NULL;
}
SET_FLAG(newhop->flags, NEXTHOP_FLAG_ACTIVE);

/* Check that the route may be recursively resolved */
if (CHECK_FLAG(nhg->flags, NEXTHOP_GROUP_ALLOW_RECURSION))
api_message = ZEBRA_FLAG_ALLOW_RECURSION;

if (nexthop_active(newhop, nhe, NULL, type, api_message, NULL,
newhop->vrf_id))
SET_FLAG(newhop->flags, NEXTHOP_FLAG_ACTIVE);
else
UNSET_FLAG(newhop->flags, NEXTHOP_FLAG_ACTIVE);
}

zebra_nhe_init(&lookup, afi, nhg->nexthop);
Expand Down
6 changes: 2 additions & 4 deletions zebra/zebra_nhg.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,8 @@ zebra_nhg_rib_find_nhe(struct nhg_hash_entry *rt_nhe, afi_t rt_afi);
*
* Returns allocated NHE on success, otherwise NULL.
*/
struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type,
uint16_t instance, uint32_t session,
struct nexthop_group *nhg,
afi_t afi);
struct nhg_hash_entry *zebra_nhg_proto_add(struct nhg_hash_entry *nhe,
struct nexthop_group *nhg, afi_t afi);

/*
* Del NHE.
Expand Down
5 changes: 1 addition & 4 deletions zebra/zebra_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2580,10 +2580,7 @@ static void process_subq_nhg(struct listnode *lnode)
ZAPI_NHG_REMOVE_FAIL);

} else {
newnhe = zebra_nhg_proto_add(nhe->id, nhe->type,
nhe->zapi_instance,
nhe->zapi_session,
&nhe->nhg, 0);
newnhe = zebra_nhg_proto_add(nhe, &nhe->nhg, 0);

/* Report error to daemon via ZAPI */
if (newnhe == NULL)
Expand Down
Loading