Skip to content

Commit 922fcad

Browse files
rachidttfxlb
authored andcommitted
OSPF: Add SR-Algo, Local Block, and SRMS Preference TLV parsers.
Display additional TLVs and their sub-TLVs from RFC8665: - SR-Algorithm TLV - SR Local Block TLV and its sub-TLVs - SRMS Preference TLV It also uses the SR-Algorithm names when printing the Prefix-SID Sub-TLV.
1 parent 419bdb1 commit 922fcad

File tree

8 files changed

+82
-12
lines changed

8 files changed

+82
-12
lines changed

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ Additional people who have contributed patches (in alphabetical order):
265265
Phil Wood <cpw at lanl dot gov>
266266
Pier Carlo Chiodi <pierky at pierky dot com>
267267
Quentin Armitage <quentin at armitage dot org dot uk>
268+
Rachid Tak Tak <rachidtt at arista dot com>
268269
Rafal Maszkowski <rzm at icm dot edu dot pl>
269270
Randy Sofia <rsofia at users dot sourceforge dot net>
270271
Raphael Raimbault <raphael dot raimbault at netasq dot com>

ospf.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@
7171

7272
#define LS_OPAQUE_TYPE_TE 1 /* rfc3630 */
7373
#define LS_OPAQUE_TYPE_GRACE 3 /* rfc3623 */
74-
#define LS_OPAQUE_TYPE_RI 4 /* draft-ietf-ospf-cap-03 */
74+
#define LS_OPAQUE_TYPE_RI 4 /* rfc7770 */
7575
#define LS_OPAQUE_TYPE_EP 7 /* rfc7684 */
76+
#define LS_OPAQUE_TYPE_EL 8 /* rfc7684 */
7677

7778
#define LS_OPAQUE_TE_TLV_ROUTER 1 /* rfc3630 */
7879
#define LS_OPAQUE_TE_TLV_LINK 2 /* rfc3630 */
@@ -110,9 +111,12 @@
110111
#define LS_OPAQUE_GRACE_TLV_REASON_SW_UPGRADE 2 /* rfc3623 */
111112
#define LS_OPAQUE_GRACE_TLV_REASON_CP_SWITCH 3 /* rfc3623 */
112113

113-
#define LS_OPAQUE_RI_TLV_CAP 1 /* draft-ietf-ospf-cap-03 */
114-
#define LS_OPAQUE_RI_TLV_HOSTNAME 7 /* rfc5642 */
115-
#define LS_OPAQUE_RI_TLV_SID_LABEL_RANGE 9 /* rfc8665 */
114+
#define LS_OPAQUE_RI_TLV_CAP 1 /* rfc7770 */
115+
#define LS_OPAQUE_RI_TLV_HOSTNAME 7 /* rfc5642 */
116+
#define LS_OPAQUE_RI_TLV_SR_ALGO 8 /* rfc8865 */
117+
#define LS_OPAQUE_RI_TLV_SID_LABEL_RANGE 9 /* rfc8865 */
118+
#define LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK 14 /* rfc8865 */
119+
#define LS_OPAQUE_RI_TLV_SRMS_PREFERENCE 15 /* rfc8865 */
116120

117121
/* rla_link.link_type */
118122
#define RLA_TYPE_ROUTER 1 /* point-to-point to another router */

print-ospf.c

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static const struct tok lsa_opaque_values[] = {
102102
{ LS_OPAQUE_TYPE_GRACE, "Graceful restart" },
103103
{ LS_OPAQUE_TYPE_RI, "Router Information" },
104104
{ LS_OPAQUE_TYPE_EP, "Extended Prefix" },
105+
{ LS_OPAQUE_TYPE_EL, "Extended Link" },
105106
{ 0, NULL }
106107
};
107108

@@ -192,8 +193,11 @@ static const struct tok lsa_opaque_te_tlv_link_type_sub_tlv_values[] = {
192193

193194
static const struct tok lsa_opaque_ri_tlv_values[] = {
194195
{ LS_OPAQUE_RI_TLV_CAP, "Router Capabilities" },
196+
{ LS_OPAQUE_RI_TLV_SR_ALGO, "SR-Algorithm" },
195197
{ LS_OPAQUE_RI_TLV_HOSTNAME, "Hostname" },
196198
{ LS_OPAQUE_RI_TLV_SID_LABEL_RANGE, "SID/Label Range" },
199+
{ LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK, "SR Local Block" },
200+
{ LS_OPAQUE_RI_TLV_SRMS_PREFERENCE, "SRMS Preference" },
197201
{ 0, NULL }
198202
};
199203

@@ -211,6 +215,12 @@ static const struct tok lsa_opaque_ri_tlv_cap_values[] = {
211215
{ 0, NULL }
212216
};
213217

218+
static const struct tok lsa_opaque_ri_tlv_sr_algos[] = {
219+
{ 0, "Shortest Path First" },
220+
{ 1, "Strict Shortest Path First" },
221+
{ 0, NULL }
222+
};
223+
214224
static const struct tok ospf_lls_tlv_values[] = {
215225
{ OSPF_LLS_EO, "Extended Options" },
216226
{ OSPF_LLS_MD5, "MD5 Authentication" },
@@ -656,6 +666,14 @@ ospf_print_tos_metrics(netdissect_options *ndo,
656666
}
657667
}
658668

669+
/*
670+
* The SID/Label Range TLV
671+
* https://datatracker.ietf.org/doc/html/rfc8665#section-3.2
672+
* and the SR Local Block TLV
673+
* https://datatracker.ietf.org/doc/html/rfc8665#section-3.3
674+
* have the same contents, so this function is used to
675+
* print both.
676+
*/
659677
static int
660678
ospf_print_ri_lsa_sid_label_range_tlv(netdissect_options *ndo, const uint8_t *tptr,
661679
u_int tlv_length)
@@ -739,15 +757,16 @@ ospf_print_ep_lsa_extd_prefix_tlv(netdissect_options *ndo, const uint8_t *tptr,
739757
algo = GET_U_1(tptr+3);
740758

741759
if (subtlv_length == 7) {
742-
ND_PRINT("\n\t\t Label: %u, MT-ID: %u, Algorithm: %u",
743-
GET_BE_U_3(tptr+4), mt_id, algo);
760+
ND_PRINT("\n\t\t Label: %u", GET_BE_U_3(tptr+4));
744761
} else if (subtlv_length == 8) {
745-
ND_PRINT("\n\t\t Index: %u, MT-ID: %u, Algorithm: %u, Flags [%s]",
746-
GET_BE_U_4(tptr+4), mt_id, algo,
747-
bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values, "none", flags));
762+
ND_PRINT("\n\t\t Index: %u", GET_BE_U_4(tptr+4));
748763
} else {
749764
ND_PRINT("\n\t\tBogus subTLV length %u", subtlv_length);
765+
break;
750766
}
767+
ND_PRINT( ", MT-ID: %u, Algorithm: %s (%u), Flags [%s]",
768+
mt_id, tok2str(lsa_opaque_ri_tlv_sr_algos, "Unknown", algo), algo,
769+
bittok2str(ep_range_tlv_prefix_sid_subtlv_flag_values, "none", flags));
751770
break;
752771

753772
default:
@@ -883,7 +902,7 @@ ospf_print_lsa(netdissect_options *ndo,
883902
const struct aslametric *almp;
884903
const struct mcla *mcp;
885904
const uint8_t *lp;
886-
u_int tlv_type, tlv_length, rla_count, topology;
905+
u_int tlv_type, tlv_length, rla_count, topology, num_tlv;
887906
int ospf_print_lshdr_ret;
888907
u_int ls_length;
889908
const uint8_t *tptr;
@@ -1099,14 +1118,32 @@ ospf_print_lsa(netdissect_options *ndo,
10991118
nd_printjnp(ndo, tptr, tlv_length);
11001119
break;
11011120

1121+
case LS_OPAQUE_RI_TLV_SR_ALGO:
1122+
num_tlv = tlv_length;
1123+
while (num_tlv >= 1) {
1124+
ND_PRINT("\n\t %s (%u)",
1125+
tok2str(lsa_opaque_ri_tlv_sr_algos, "Unknown", GET_U_1(tptr+tlv_length-num_tlv)), GET_U_1(tptr+tlv_length-num_tlv));
1126+
num_tlv--;
1127+
}
1128+
break;
1129+
11021130
case LS_OPAQUE_RI_TLV_SID_LABEL_RANGE:
1131+
case LS_OPAQUE_RI_TLV_SR_LOCAL_BLOCK:
11031132
ND_TCHECK_4(tptr);
11041133
ND_PRINT("\n\t Range size: %u", GET_BE_U_3(tptr));
11051134
if (ospf_print_ri_lsa_sid_label_range_tlv(ndo, tptr+4, tlv_length-4) == -1) {
11061135
return(ls_end);
11071136
}
11081137
break;
11091138

1139+
case LS_OPAQUE_RI_TLV_SRMS_PREFERENCE:
1140+
if (tlv_length != 4) {
1141+
ND_PRINT("\n\t Bogus SRMS Preference TLV length %u != 4", tlv_length);
1142+
return(ls_end);
1143+
}
1144+
ND_PRINT("\n\t SRMS Preference: %u", GET_U_1(tptr));
1145+
break;
1146+
11101147
default:
11111148
if (ndo->ndo_vflag <= 1) {
11121149
if (!print_unknown_data(ndo, tptr, "\n\t ", tlv_length))

tests/TESTLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ ospf-nssa-bitnt ospf-nssa-bitnt.pcap ospf-nssa-bitnt.out -v
134134
ospf-ack ospf-ack.pcap ospf-ack.out -v
135135
ospf-sr ospf-sr.pcapng ospf-sr-v.out -v
136136
ospf-sr2 ospf-sr2.pcapng ospf-sr2-v.out -v
137+
ospf-sr-ri-sid ospf-sr-ri-sid.pcap ospf-sr-ri-sid-v.out -v
137138
ospf3_ah-vv OSPFv3_with_AH.pcap ospf3_ah-vv.out -v -v
138139
ospf3_auth-vv ospf3_auth.pcapng ospf3_auth-vv.out -v -v
139140
ospf3_bc-vv OSPFv3_broadcast_adjacency.pcap ospf3_bc-vv.out -v -v

tests/ospf-sr-ri-sid-v.out

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
1 22:11:10.755260 IP (tos 0x0, ttl 1, id 1, offset 0, flags [none], proto OSPF (89), length 148, bad cksum d831 (->d809)!)
2+
1.0.0.2 > 224.0.0.5: OSPFv2, LS-Update, length 128
3+
Router-ID 2.2.2.2, Backbone Area, Authentication Type: none (0), 1 LSA
4+
LSA #1
5+
Advertising Router 2.2.2.2, seq 0x80000001, age 3600s, length 80
6+
Area Local Opaque LSA (10), Opaque-Type Router Information LSA (4), Opaque-ID 0
7+
Options: [none]
8+
SR-Algorithm TLV (8), length: 1, value:
9+
Shortest Path First (0)
10+
SID/Label Range TLV (9), length: 12, value:
11+
Range size: 100
12+
SID/Label subTLV (1), length: 3, value:
13+
Label: 100
14+
SID/Label Range TLV (9), length: 12, value:
15+
Range size: 100
16+
SID/Label subTLV (1), length: 3, value:
17+
Label: 1000
18+
SR Local Block TLV (14), length: 12, value:
19+
Range size: 4242
20+
SID/Label subTLV (1), length: 3, value:
21+
Label: 4321
22+
SR Local Block TLV (14), length: 12, value:
23+
Range size: 4242
24+
SID/Label subTLV (1), length: 4, value:
25+
SID: 24680
26+
SRMS Preference TLV (15), length: 4, value:
27+
SRMS Preference: 99

tests/ospf-sr-ri-sid.pcap

202 Bytes
Binary file not shown.

tests/ospf-sr-v.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Extended Prefix Range TLV (2), length: 24, value:
1919
IPv4 prefix: 192.168.0.0/32, Range size: 1, Flags [none]
2020
Prefix-SID subTLV (2), length: 8, value:
21-
Index: 4, MT-ID: 0, Algorithm: 0, Flags [none]
21+
Index: 4, MT-ID: 0, Algorithm: Shortest Path First (0), Flags [none]
2222
LSA #3
2323
Advertising Router 192.168.0.4, seq 0x8000001e, age 1s, length 112
2424
Router LSA (1), LSA-ID: 192.168.0.4

tests/ospf-sr2-v.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Extended Prefix TLV (1), length: 20, value:
1919
IPv4 prefix: 192.168.0.0/32, Route Type: Intra-Area, Flags [none]
2020
Prefix-SID subTLV (2), length: 8, value:
21-
Index: 0, MT-ID: 0, Algorithm: 0, Flags [none]
21+
Index: 0, MT-ID: 0, Algorithm: Shortest Path First (0), Flags [none]
2222
LSA #3
2323
Advertising Router 192.168.0.0, seq 0x80000009, age 1s, length 112
2424
Router LSA (1), LSA-ID: 192.168.0.0

0 commit comments

Comments
 (0)