Skip to content

Commit e417c2f

Browse files
committed
isisd: Unpack Node MSD Sub-TLV with SRv6 MSDs
The Router Capabilities TLV unpack function already unpacks the Node MSD Sub-TLV. This commit extends Router Capabilities TLV unpack function to extract SRv6 MSDs from the Node MSD Sub-TLV (RFC 9352 section sonic-net#4). Signed-off-by: Carmine Scarpitta <[email protected]>
1 parent 15abfb1 commit e417c2f

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

isisd/isis_tlvs.c

+57-9
Original file line numberDiff line numberDiff line change
@@ -4464,6 +4464,7 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context,
44644464
uint8_t length;
44654465
uint8_t subtlv_len;
44664466
uint8_t size;
4467+
int num_msd;
44674468

44684469
sbuf_push(log, indent, "Unpacking Router Capability TLV...\n");
44694470
if (tlv_len < ISIS_ROUTER_CAP_SIZE) {
@@ -4632,19 +4633,66 @@ static int unpack_tlv_router_cap(enum isis_tlv_context context,
46324633

46334634
break;
46344635
case ISIS_SUBTLV_NODE_MSD:
4636+
sbuf_push(log, indent,
4637+
"Unpacking Node MSD sub-TLV...\n");
4638+
46354639
/* Check that MSD is correctly formated */
4636-
if (length < MSD_TLV_SIZE) {
4640+
if (length % 2) {
4641+
sbuf_push(
4642+
log, indent,
4643+
"WARNING: Unexpected MSD sub-TLV length\n");
46374644
stream_forward_getp(s, length);
46384645
break;
46394646
}
4640-
msd_type = stream_getc(s);
4641-
rcap->msd = stream_getc(s);
4642-
/* Only BMI-MSD type has been defined in RFC 8491 */
4643-
if (msd_type != MSD_TYPE_BASE_MPLS_IMPOSITION)
4644-
rcap->msd = 0;
4645-
/* Only one MSD is standardized. Skip others */
4646-
if (length > MSD_TLV_SIZE)
4647-
stream_forward_getp(s, length - MSD_TLV_SIZE);
4647+
4648+
/* Get the number of MSDs carried in the value field of
4649+
* the Node MSD sub-TLV. The value field consists of one
4650+
* or more pairs of a 1-octet MSD-Type and 1-octet
4651+
* MSD-Value */
4652+
num_msd = length / 2;
4653+
4654+
/* Unpack MSDs */
4655+
for (int i = 0; i < num_msd; i++) {
4656+
msd_type = stream_getc(s);
4657+
4658+
switch (msd_type) {
4659+
case MSD_TYPE_BASE_MPLS_IMPOSITION:
4660+
/* BMI-MSD type as per RFC 8491 */
4661+
rcap->msd = stream_getc(s);
4662+
break;
4663+
case ISIS_SUBTLV_SRV6_MAX_SL_MSD:
4664+
/* SRv6 Maximum Segments Left MSD Type
4665+
* as per RFC 9352 section #4.1 */
4666+
rcap->srv6_msd.max_seg_left_msd =
4667+
stream_getc(s);
4668+
break;
4669+
case ISIS_SUBTLV_SRV6_MAX_END_POP_MSD:
4670+
/* SRv6 Maximum End Pop MSD Type as per
4671+
* RFC 9352 section #4.2 */
4672+
rcap->srv6_msd.max_end_pop_msd =
4673+
stream_getc(s);
4674+
break;
4675+
case ISIS_SUBTLV_SRV6_MAX_H_ENCAPS_MSD:
4676+
/* SRv6 Maximum H.Encaps MSD Type as per
4677+
* RFC 9352 section #4.3 */
4678+
rcap->srv6_msd.max_h_encaps_msd =
4679+
stream_getc(s);
4680+
break;
4681+
case ISIS_SUBTLV_SRV6_MAX_END_D_MSD:
4682+
/* SRv6 Maximum End D MSD Type as per
4683+
* RFC 9352 section #4.4 */
4684+
rcap->srv6_msd.max_end_d_msd =
4685+
stream_getc(s);
4686+
break;
4687+
default:
4688+
/* Unknown MSD, let's skip it */
4689+
sbuf_push(
4690+
log, indent,
4691+
"WARNING: Skipping unknown MSD Type %hhu (1 byte)\n",
4692+
msd_type);
4693+
stream_forward_getp(s, 1);
4694+
}
4695+
}
46484696
break;
46494697
#ifndef FABRICD
46504698
case ISIS_SUBTLV_FAD:

0 commit comments

Comments
 (0)