Skip to content

Commit

Permalink
isis, lib: add isis srv6 end sid to ls_prefix
Browse files Browse the repository at this point in the history
According to draft-ietf-lsr-isis-srv6-extensions draft,
the End SID should be available in link state prefix
information. Add the SID information in the link state
prefix.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Apr 19, 2024
1 parent 8e7fb95 commit 90f5312
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
31 changes: 31 additions & 0 deletions isisd/isis_te.c
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,37 @@ static int lsp_to_subnet_cb(const struct prefix *prefix, uint32_t metric,
}
}

/* Update SRv6 SID and locator if any */
if (subtlvs && subtlvs->srv6_end_sids.count != 0) {
struct isis_srv6_sid *psid;
struct ls_srv6_sid sr = {};

psid = (struct isis_srv6_sid *)subtlvs->prefix_sids.head;
sr.behavior = psid->behavior;
sr.flags = psid->flags;
memcpy(&sr.sid, &psid->sid, sizeof(struct in6_addr));

if (!CHECK_FLAG(ls_pref->flags, LS_PREF_SRV6) ||
!memcmp(&ls_pref->srv6, &sr, sizeof(struct ls_srv6_sid))) {
memcpy(&ls_pref->srv6, &sr, sizeof(struct ls_srv6_sid));
SET_FLAG(ls_pref->flags, LS_PREF_SRV6);
if (subnet->status != NEW)
subnet->status = UPDATE;
} else {
if (subnet->status == ORPHAN)
subnet->status = SYNC;
}
} else {
if (CHECK_FLAG(ls_pref->flags, LS_PREF_SRV6)) {
UNSET_FLAG(ls_pref->flags, LS_PREF_SRV6);
if (subnet->status != NEW)
subnet->status = UPDATE;
} else {
if (subnet->status == ORPHAN)
subnet->status = SYNC;
}
}

/* Update status and Export Link State Edge if needed */
if (subnet->status != SYNC) {
if (args->export)
Expand Down
36 changes: 35 additions & 1 deletion lib/link_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ int ls_prefix_same(struct ls_prefix *p1, struct ls_prefix *p2)
|| (p1->sr.sid_flag != p2->sr.sid_flag))
return 0;
}
if (CHECK_FLAG(p1->flags, LS_PREF_SRV6)) {
if (memcmp(&p1->srv6.sid, &p2->srv6.sid,
sizeof(struct in6_addr)) ||
(p1->srv6.flags != p2->srv6.flags) ||
(p1->srv6.behavior != p2->srv6.behavior))
return 0;
}

/* OK, p1 & p2 are equal */
return 1;
Expand Down Expand Up @@ -1345,6 +1352,11 @@ static struct ls_prefix *ls_parse_prefix(struct stream *s)
STREAM_GETC(s, ls_pref->sr.sid_flag);
STREAM_GETC(s, ls_pref->sr.algo);
}
if (CHECK_FLAG(ls_pref->flags, LS_PREF_SRV6)) {
STREAM_GET(&ls_pref->srv6.sid, s, sizeof(struct in6_addr));
STREAM_GETW(s, ls_pref->srv6.behavior);
STREAM_GETC(s, ls_pref->srv6.flags);
}

return ls_pref;

Expand Down Expand Up @@ -1567,6 +1579,11 @@ static int ls_format_prefix(struct stream *s, struct ls_prefix *ls_pref)
stream_putc(s, ls_pref->sr.sid_flag);
stream_putc(s, ls_pref->sr.algo);
}
if (CHECK_FLAG(ls_pref->flags, LS_PREF_SRV6)) {
stream_put(s, &ls_pref->srv6.sid, sizeof(struct in6_addr));
stream_putw(s, ls_pref->srv6.behavior);
stream_putc(s, ls_pref->srv6.flags);
}

return 0;
}
Expand Down Expand Up @@ -2626,6 +2643,13 @@ static void ls_show_subnet_vty(struct ls_subnet *subnet, struct vty *vty,
sbuf_push(&sbuf, 4, "SID: %d\tAlgorithm: %d\tFlags: 0x%x\n",
pref->sr.sid, pref->sr.algo, pref->sr.sid_flag);

if (CHECK_FLAG(pref->flags, LS_PREF_SRV6))
sbuf_push(&sbuf, 4,
"SIDv6: %pI6\tEndpoint behavior: %s\tFlags: 0x%x\n",
&pref->srv6.sid,
seg6local_action2str(pref->srv6.behavior),
pref->srv6.flags);

end:
vty_out(vty, "%s\n", sbuf_buf(&sbuf));
sbuf_free(&sbuf);
Expand All @@ -2635,7 +2659,7 @@ static void ls_show_subnet_json(struct ls_subnet *subnet,
struct json_object *json)
{
struct ls_prefix *pref;
json_object *jsr;
json_object *jsr, *jsrv6;
char buf[INET6_BUFSIZ];

pref = subnet->ls_pref;
Expand Down Expand Up @@ -2665,6 +2689,16 @@ static void ls_show_subnet_json(struct ls_subnet *subnet,
snprintfrr(buf, INET6_BUFSIZ, "0x%x", pref->sr.sid_flag);
json_object_string_add(jsr, "flags", buf);
}
if (CHECK_FLAG(pref->flags, LS_PREF_SRV6)) {
jsrv6 = json_object_new_object();
json_object_object_add(json, "segment-routing-ipv6", jsrv6);
snprintfrr(buf, INET6_BUFSIZ, "%pI6", &pref->srv6.sid);
json_object_string_add(jsrv6, "sid", buf);
json_object_string_add(jsrv6, "sid",
seg6local_action2str(pref->srv6.behavior));
snprintfrr(buf, INET6_BUFSIZ, "0x%x", pref->srv6.flags);
json_object_string_add(jsrv6, "flags", buf);
}
}

void ls_show_subnet(struct ls_subnet *subnet, struct vty *vty,
Expand Down
6 changes: 6 additions & 0 deletions lib/link_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ struct ls_attributes {
#define LS_PREF_EXTENDED_TAG 0x04
#define LS_PREF_METRIC 0x08
#define LS_PREF_SR 0x10
#define LS_PREF_SRV6 0x20

/* Link State Prefix */
struct ls_prefix {
Expand All @@ -235,6 +236,11 @@ struct ls_prefix {
uint8_t sid_flag; /* Segment Routing Flags */
uint8_t algo; /* Algorithm for Segment Routing */
} sr;
struct ls_srv6_sid {
struct in6_addr sid; /* Segment Routing ID */
uint16_t behavior; /* Endpoint behavior bound to the SID */
uint8_t flags; /* Flags */
} srv6;
};

/**
Expand Down

0 comments on commit 90f5312

Please sign in to comment.