Skip to content

Commit

Permalink
zebra: add srv6 nexthop resolution given by sr policy
Browse files Browse the repository at this point in the history
Consider an srv6 policy active, when sr policy set is
received. The sr_policy_validate() function is however
called, the default state value is down, and immediately
sent to UP.

Signed-off-by: Philippe Guibert <[email protected]>
Signed-off-by: Dmytro Shytyi <[email protected]>
  • Loading branch information
dmytroshytyi-6WIND committed Aug 1, 2024
1 parent 9155c80 commit 6a7edd0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
33 changes: 23 additions & 10 deletions zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,7 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe,
if (nexthop->srte_color) {
struct ipaddr endpoint = {0};
struct zebra_sr_policy *policy;
struct nexthop *nexthop_resolved;

switch (afi) {
case AFI_IP:
Expand All @@ -2309,19 +2310,31 @@ static int nexthop_active(struct nexthop *nexthop, struct nhg_hash_entry *nhe,
policy = zebra_sr_policy_find(nexthop->srte_color, &endpoint);
if (policy && policy->status == ZEBRA_SR_POLICY_UP) {
resolved = 0;
frr_each_safe (nhlfe_list, &policy->lsp->nhlfe_list,
nhlfe) {
if (!CHECK_FLAG(nhlfe->flags,
NHLFE_FLAG_SELECTED)
|| CHECK_FLAG(nhlfe->flags,
NHLFE_FLAG_DELETED))
continue;
SET_FLAG(nexthop->flags,
NEXTHOP_FLAG_RECURSIVE);
nexthop_set_resolved(afi, nhlfe->nexthop,
if (policy->segment_list.label_num > 0) {
frr_each_safe (nhlfe_list,
&policy->lsp->nhlfe_list, nhlfe) {
if (!CHECK_FLAG(nhlfe->flags,
NHLFE_FLAG_SELECTED) ||
CHECK_FLAG(nhlfe->flags,
NHLFE_FLAG_DELETED))
continue;
SET_FLAG(nexthop->flags,
NEXTHOP_FLAG_RECURSIVE);
nexthop_set_resolved(afi, nhlfe->nexthop,
nexthop, policy);
resolved = 1;
}
} else if (policy->segment_list.nexthop_resolved_num) {
nexthop_resolved = nexthop_from_zapi_nexthop(
&policy->segment_list.nexthop_resolved[0]);

SET_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
nexthop_set_resolved(afi, nexthop_resolved,
nexthop, policy);
resolved = 1;
nexthop_free(nexthop_resolved);
}

if (resolved)
return 1;
}
Expand Down
17 changes: 13 additions & 4 deletions zebra/zebra_srte.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,24 @@ int zebra_sr_policy_validate(struct zebra_sr_policy *policy,
struct zapi_srte_tunnel *new_tunnel)
{
struct zapi_srte_tunnel old_tunnel = policy->segment_list;
struct zebra_lsp *lsp;
struct zebra_lsp *lsp = NULL;
bool srv6_sid_resolved = false;

if (new_tunnel)
policy->segment_list = *new_tunnel;

/* Try to resolve the Binding-SID nexthops. */
lsp = mpls_lsp_find(policy->zvrf, policy->segment_list.labels[0]);
if (!lsp || !lsp->best_nhlfe
|| lsp->addr_family != ipaddr_family(&policy->endpoint)) {
if (policy->segment_list.type == ZEBRA_SR_LSP_SRTE)
lsp = mpls_lsp_find(policy->zvrf,
policy->segment_list.labels[0]);

/* Check if there are resolved nexthops in the segment list. */
srv6_sid_resolved = policy->segment_list.nexthop_resolved_num ? true
: false;

if ((!lsp || !lsp->best_nhlfe ||
lsp->addr_family != ipaddr_family(&policy->endpoint)) &&
!srv6_sid_resolved) {
if (policy->status == ZEBRA_SR_POLICY_UP)
zebra_sr_policy_deactivate(policy);
return -1;
Expand Down
1 change: 1 addition & 0 deletions zebra/zebra_srv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zebra.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "zebra_srte.h"

#include "qobj.h"
#include "prefix.h"
Expand Down

0 comments on commit 6a7edd0

Please sign in to comment.