Skip to content

Commit 426bdd1

Browse files
authored
Merge pull request FRRouting#18563 from pguibert6WIND/srv6_display
show ipv6 route [json] displays seg6local flavors
2 parents b18523e + 9d4ad7f commit 426bdd1

File tree

65 files changed

+413
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+413
-296
lines changed

lib/nexthop.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,9 +1324,10 @@ void nexthop_json_helper(json_object *json_nexthop,
13241324
if (nexthop->nh_srv6) {
13251325
json_seg6local = json_object_new_object();
13261326
json_object_string_add(json_seg6local, "action",
1327-
seg6local_action2str(
1328-
nexthop->nh_srv6
1329-
->seg6local_action));
1327+
seg6local_action2str_with_next_csid(
1328+
nexthop->nh_srv6->seg6local_action,
1329+
seg6local_has_next_csid(
1330+
&nexthop->nh_srv6->seg6local_ctx)));
13301331
json_seg6local_context = json_object_new_object();
13311332
json_object_object_add(json_nexthop, "seg6local",
13321333
json_seg6local);
@@ -1486,8 +1487,10 @@ void nexthop_vty_helper(struct vty *vty, const struct nexthop *nexthop,
14861487
if (nexthop->nh_srv6->seg6local_action !=
14871488
ZEBRA_SEG6_LOCAL_ACTION_UNSPEC)
14881489
vty_out(vty, ", seg6local %s %s",
1489-
seg6local_action2str(
1490-
nexthop->nh_srv6->seg6local_action),
1490+
seg6local_action2str_with_next_csid(nexthop->nh_srv6->seg6local_action,
1491+
seg6local_has_next_csid(
1492+
&nexthop->nh_srv6
1493+
->seg6local_ctx)),
14911494
buf);
14921495
if (nexthop->nh_srv6->seg6_segs &&
14931496
IPV6_ADDR_CMP(&nexthop->nh_srv6->seg6_segs->seg[0],

lib/srv6.c

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,51 @@ DEFINE_MTYPE_STATIC(LIB, SRV6_LOCATOR_CHUNK, "SRV6 locator chunk");
1616
DEFINE_MTYPE_STATIC(LIB, SRV6_SID_FORMAT, "SRv6 SID format");
1717
DEFINE_MTYPE_STATIC(LIB, SRV6_SID_CTX, "SRv6 SID context");
1818

19-
const char *seg6local_action2str(uint32_t action)
19+
const char *seg6local_action2str_with_next_csid(uint32_t action, bool has_next_csid)
2020
{
2121
switch (action) {
2222
case ZEBRA_SEG6_LOCAL_ACTION_END:
23-
return "End";
23+
return has_next_csid ? "uN" : "End";
2424
case ZEBRA_SEG6_LOCAL_ACTION_END_X:
25-
return "End.X";
25+
return has_next_csid ? "uA" : "End.X";
2626
case ZEBRA_SEG6_LOCAL_ACTION_END_T:
27-
return "End.T";
27+
return has_next_csid ? "uDT" : "End.T";
2828
case ZEBRA_SEG6_LOCAL_ACTION_END_DX2:
29-
return "End.DX2";
29+
return has_next_csid ? "uDX2" : "End.DX2";
3030
case ZEBRA_SEG6_LOCAL_ACTION_END_DX6:
31-
return "End.DX6";
31+
return has_next_csid ? "uDX6" : "End.DX6";
3232
case ZEBRA_SEG6_LOCAL_ACTION_END_DX4:
33-
return "End.DX4";
33+
return has_next_csid ? "uDX4" : "End.DX4";
3434
case ZEBRA_SEG6_LOCAL_ACTION_END_DT6:
35-
return "End.DT6";
35+
return has_next_csid ? "uDT6" : "End.DT6";
3636
case ZEBRA_SEG6_LOCAL_ACTION_END_DT4:
37-
return "End.DT4";
37+
return has_next_csid ? "uDT4" : "End.DT4";
3838
case ZEBRA_SEG6_LOCAL_ACTION_END_B6:
39-
return "End.B6";
39+
return has_next_csid ? "uB6" : "End.B6";
4040
case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP:
41-
return "End.B6.Encap";
41+
return has_next_csid ? "uB6.Encap" : "End.B6.Encap";
4242
case ZEBRA_SEG6_LOCAL_ACTION_END_BM:
43-
return "End.BM";
43+
return has_next_csid ? "uBM" : "End.BM";
4444
case ZEBRA_SEG6_LOCAL_ACTION_END_S:
4545
return "End.S";
4646
case ZEBRA_SEG6_LOCAL_ACTION_END_AS:
4747
return "End.AS";
4848
case ZEBRA_SEG6_LOCAL_ACTION_END_AM:
4949
return "End.AM";
5050
case ZEBRA_SEG6_LOCAL_ACTION_END_DT46:
51-
return "End.DT46";
51+
return has_next_csid ? "uDT46" : "End.DT46";
5252
case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC:
5353
return "unspec";
5454
default:
5555
return "unknown";
5656
}
5757
}
5858

59+
const char *seg6local_action2str(uint32_t action)
60+
{
61+
return seg6local_action2str_with_next_csid(action, false);
62+
}
63+
5964
int snprintf_seg6_segs(char *str,
6065
size_t size, const struct seg6_segs *segs)
6166
{
@@ -71,6 +76,21 @@ int snprintf_seg6_segs(char *str,
7176
return strlen(str);
7277
}
7378

79+
static void seg6local_flavors2json(json_object *json, const struct seg6local_flavors_info *flv_info)
80+
{
81+
json_object *json_flavors;
82+
83+
json_flavors = json_object_new_array();
84+
json_object_object_add(json, "flavors", json_flavors);
85+
86+
if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP))
87+
json_array_string_add(json_flavors, "psp");
88+
if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USP))
89+
json_array_string_add(json_flavors, "usp");
90+
if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USD))
91+
json_array_string_add(json_flavors, "usd");
92+
}
93+
7494
void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *json)
7595
{
7696
json_object_int_add(json, "blockLen", ctx->block_len);
@@ -82,6 +102,7 @@ void srv6_sid_structure2json(const struct seg6local_context *ctx, json_object *j
82102
void seg6local_context2json(const struct seg6local_context *ctx,
83103
uint32_t action, json_object *json)
84104
{
105+
seg6local_flavors2json(json, &ctx->flv);
85106
switch (action) {
86107
case ZEBRA_SEG6_LOCAL_ACTION_END:
87108
return;
@@ -116,35 +137,65 @@ void seg6local_context2json(const struct seg6local_context *ctx,
116137
}
117138
}
118139

140+
static char *seg6local_flavors2str(char *str, size_t size,
141+
const struct seg6local_flavors_info *flv_info)
142+
{
143+
size_t len = 0;
144+
bool first = true;
145+
146+
if (!CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP |
147+
ZEBRA_SEG6_LOCAL_FLV_OP_USP |
148+
ZEBRA_SEG6_LOCAL_FLV_OP_USD))
149+
return str;
150+
151+
len += snprintf(str + len, size - len, " (");
152+
if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_PSP)) {
153+
len += snprintf(str + len, size - len, "%sPSP", first ? "" : "/");
154+
first = false;
155+
}
156+
if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USP)) {
157+
len += snprintf(str + len, size - len, "%sUSP", first ? "" : "/");
158+
first = false;
159+
}
160+
if (CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_USD))
161+
len += snprintf(str + len, size - len, "%sUSD", first ? "" : "/");
162+
163+
snprintf(str + len, size - len, ")");
164+
165+
return str;
166+
}
119167
const char *seg6local_context2str(char *str, size_t size,
120168
const struct seg6local_context *ctx,
121169
uint32_t action)
122170
{
123-
switch (action) {
171+
char flavor[SRV6_FLAVORS_STRLEN], *p_flavor;
124172

173+
flavor[0] = '\0';
174+
p_flavor = seg6local_flavors2str(flavor, sizeof(flavor), &ctx->flv);
175+
switch (action) {
125176
case ZEBRA_SEG6_LOCAL_ACTION_END:
126-
snprintf(str, size, "-");
177+
snprintf(str, size, "%s", p_flavor);
127178
return str;
128179

129180
case ZEBRA_SEG6_LOCAL_ACTION_END_X:
130181
case ZEBRA_SEG6_LOCAL_ACTION_END_DX6:
131-
snprintfrr(str, size, "nh6 %pI6", &ctx->nh6);
182+
snprintfrr(str, size, "nh6 %pI6%s", &ctx->nh6, p_flavor);
132183
return str;
133184

134185
case ZEBRA_SEG6_LOCAL_ACTION_END_DX4:
135-
snprintfrr(str, size, "nh4 %pI4", &ctx->nh4);
186+
snprintfrr(str, size, "nh4 %pI4%s", &ctx->nh4, p_flavor);
136187
return str;
137188

138189
case ZEBRA_SEG6_LOCAL_ACTION_END_T:
139190
case ZEBRA_SEG6_LOCAL_ACTION_END_DT6:
140191
case ZEBRA_SEG6_LOCAL_ACTION_END_DT4:
141192
case ZEBRA_SEG6_LOCAL_ACTION_END_DT46:
142-
snprintf(str, size, "table %u", ctx->table);
193+
snprintf(str, size, "table %u%s", ctx->table, p_flavor);
143194
return str;
144195

145196
case ZEBRA_SEG6_LOCAL_ACTION_END_B6:
146197
case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP:
147-
snprintfrr(str, size, "nh6 %pI6", &ctx->nh6);
198+
snprintfrr(str, size, "nh6 %pI6%s", &ctx->nh6, p_flavor);
148199
return str;
149200
case ZEBRA_SEG6_LOCAL_ACTION_END_DX2:
150201
case ZEBRA_SEG6_LOCAL_ACTION_END_BM:

lib/srv6.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ struct seg6_segs {
9797
struct in6_addr segs[256];
9898
};
9999

100+
/* flavors psp, usd, usp, next-csid */
101+
#define SRV6_FLAVORS_STRLEN 50
102+
100103
struct seg6local_flavors_info {
101104
/* Flavor operations */
102105
uint32_t flv_ops;
@@ -210,6 +213,16 @@ enum srv6_endpoint_behavior_codepoint {
210213
SRV6_ENDPOINT_BEHAVIOR_OPAQUE = 0xFFFF,
211214
};
212215

216+
/*
217+
* Return true if next-csid behavior is used, false otherwise
218+
*/
219+
static inline bool seg6local_has_next_csid(const struct seg6local_context *ctx)
220+
{
221+
const struct seg6local_flavors_info *flv_info = &ctx->flv;
222+
223+
return CHECK_SRV6_FLV_OP(flv_info->flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
224+
}
225+
213226
/*
214227
* Convert SRv6 endpoint behavior codepoints to human-friendly string.
215228
*/
@@ -420,6 +433,8 @@ static inline void *sid_copy(struct in6_addr *dst,
420433
return memcpy(dst, src, sizeof(struct in6_addr));
421434
}
422435

436+
const char *seg6local_action2str_with_next_csid(uint32_t action, bool has_next_csid);
437+
423438
const char *
424439
seg6local_action2str(uint32_t action);
425440

staticd/static_zebra.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,23 @@ void static_zebra_srv6_sid_install(struct static_srv6_sid *sid)
662662
ctx.flv.lcnode_func_len = sid->locator->node_bits_length;
663663
break;
664664
case SRV6_ENDPOINT_BEHAVIOR_END_DT6:
665+
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT6;
666+
vrf = vrf_lookup_by_name(sid->attributes.vrf_name);
667+
if (!vrf_is_enabled(vrf)) {
668+
zlog_warn("Failed to install SID %pFX: VRF %s is inactive", &sid->addr,
669+
sid->attributes.vrf_name);
670+
return;
671+
}
672+
ctx.table = vrf->data.l.table_id;
673+
ifp = if_get_vrf_loopback(vrf->vrf_id);
674+
if (!ifp) {
675+
zlog_warn("Failed to install SID %pFX: failed to get loopback for vrf %s",
676+
&sid->addr, sid->attributes.vrf_name);
677+
return;
678+
}
679+
break;
665680
case SRV6_ENDPOINT_BEHAVIOR_END_DT6_USID:
681+
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
666682
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT6;
667683
vrf = vrf_lookup_by_name(sid->attributes.vrf_name);
668684
if (!vrf_is_enabled(vrf)) {
@@ -679,7 +695,23 @@ void static_zebra_srv6_sid_install(struct static_srv6_sid *sid)
679695
}
680696
break;
681697
case SRV6_ENDPOINT_BEHAVIOR_END_DT4:
698+
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT4;
699+
vrf = vrf_lookup_by_name(sid->attributes.vrf_name);
700+
if (!vrf_is_enabled(vrf)) {
701+
zlog_warn("Failed to install SID %pFX: VRF %s is inactive", &sid->addr,
702+
sid->attributes.vrf_name);
703+
return;
704+
}
705+
ctx.table = vrf->data.l.table_id;
706+
ifp = if_get_vrf_loopback(vrf->vrf_id);
707+
if (!ifp) {
708+
zlog_warn("Failed to install SID %pFX: failed to get loopback for vrf %s",
709+
&sid->addr, sid->attributes.vrf_name);
710+
return;
711+
}
712+
break;
682713
case SRV6_ENDPOINT_BEHAVIOR_END_DT4_USID:
714+
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
683715
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT4;
684716
vrf = vrf_lookup_by_name(sid->attributes.vrf_name);
685717
if (!vrf_is_enabled(vrf)) {
@@ -696,7 +728,23 @@ void static_zebra_srv6_sid_install(struct static_srv6_sid *sid)
696728
}
697729
break;
698730
case SRV6_ENDPOINT_BEHAVIOR_END_DT46:
731+
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT46;
732+
vrf = vrf_lookup_by_name(sid->attributes.vrf_name);
733+
if (!vrf_is_enabled(vrf)) {
734+
zlog_warn("Failed to install SID %pFX: VRF %s is inactive", &sid->addr,
735+
sid->attributes.vrf_name);
736+
return;
737+
}
738+
ctx.table = vrf->data.l.table_id;
739+
ifp = if_get_vrf_loopback(vrf->vrf_id);
740+
if (!ifp) {
741+
zlog_warn("Failed to install SID %pFX: failed to get loopback for vrf %s",
742+
&sid->addr, sid->attributes.vrf_name);
743+
return;
744+
}
745+
break;
699746
case SRV6_ENDPOINT_BEHAVIOR_END_DT46_USID:
747+
SET_SRV6_FLV_OP(ctx.flv.flv_ops, ZEBRA_SEG6_LOCAL_FLV_OP_NEXT_CSID);
700748
action = ZEBRA_SEG6_LOCAL_ACTION_END_DT46;
701749
vrf = vrf_lookup_by_name(sid->attributes.vrf_name);
702750
if (!vrf_is_enabled(vrf)) {

tests/topotests/isis_srv6_topo1/rt1/step1/show_ipv6_route.ref

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"interfaceName":"sr0",
218218
"active":true,
219219
"seg6local":{
220-
"action":"End"
220+
"action":"uN"
221221
}
222222
}
223223
]
@@ -239,7 +239,7 @@
239239
"interfaceName":"eth-sw1",
240240
"active":true,
241241
"seg6local":{
242-
"action":"End.X"
242+
"action":"uA"
243243
}
244244
}
245245
]
@@ -261,7 +261,7 @@
261261
"interfaceName":"eth-sw1",
262262
"active":true,
263263
"seg6local":{
264-
"action":"End.X"
264+
"action":"uA"
265265
}
266266
}
267267
]

tests/topotests/isis_srv6_topo1/rt1/step3/show_ipv6_route.ref

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"interfaceName":"sr0",
218218
"active":true,
219219
"seg6local":{
220-
"action":"End"
220+
"action":"uN"
221221
}
222222
}
223223
]
@@ -239,7 +239,7 @@
239239
"interfaceName":"eth-sw1",
240240
"active":true,
241241
"seg6local":{
242-
"action":"End.X"
242+
"action":"uA"
243243
}
244244
}
245245
]
@@ -261,7 +261,7 @@
261261
"interfaceName":"eth-sw1",
262262
"active":true,
263263
"seg6local":{
264-
"action":"End.X"
264+
"action":"uA"
265265
}
266266
}
267267
]

tests/topotests/isis_srv6_topo1/rt1/step5/show_ipv6_route.ref

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"interfaceName":"sr0",
218218
"active":true,
219219
"seg6local":{
220-
"action":"End"
220+
"action":"uN"
221221
}
222222
}
223223
]
@@ -239,7 +239,7 @@
239239
"interfaceName":"eth-sw1",
240240
"active":true,
241241
"seg6local":{
242-
"action":"End.X"
242+
"action":"uA"
243243
}
244244
}
245245
]
@@ -261,7 +261,7 @@
261261
"interfaceName":"eth-sw1",
262262
"active":true,
263263
"seg6local":{
264-
"action":"End.X"
264+
"action":"uA"
265265
}
266266
}
267267
]

0 commit comments

Comments
 (0)