bgpd: BGP-LS: add Prefix SID (TLV 1158)#21076
bgpd: BGP-LS: add Prefix SID (TLV 1158)#21076hedrok wants to merge 1 commit intoFRRouting:masterfrom
Conversation
Greptile SummaryThis PR implements BGP-LS Prefix SID (TLV 1158) as defined in RFC 9085 Section 2.3.1, adding parsing, encoding, hashing, comparison, and VTY display support across Key changes:
Minor issues found: the parse function comment in Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant IGP as IGP (IS-IS/OSPF)
participant TED as bgp_ls_ted.c
participant ATTR as bgp_ls_attr
participant ENC as bgp_ls_nlri.c (encode)
participant PEER as BGP Peer
IGP->>TED: ls_prefix (sr.sid, sr.sid_flag, sr.algo)
TED->>ATTR: populate prefix_sid {sid, sid_flag, algo, sid_len}
TED->>ATTR: set BGP_LS_ATTR_PREFIX_SID_BIT in present_tlvs
PEER->>ENC: BGP UPDATE with TLV 1158
ENC->>ATTR: parse_prefix_sid(stream, length=7or8)
ATTR-->>ENC: prefix_sid populated
ENC->>PEER: bgp_ls_encode_attr → stream TLV 1158
Note over ENC,PEER: flags(1) + algo(1) + reserved(2) + SID(3or4)
Last reviewed commit: 9eac2ad |
| /* IS-IS (RFC 8667, 2.1.1.1); OSPF (RFC 8665, 5); OSPFv3 (RFC 8666, 6) */ | ||
| /* All protocols have same logic: V-Flag and L-Flag are at same positions, | ||
| * both can be 1 or 0, when 1 - length is 3, when 0 - length is 4 | ||
| */ | ||
| if (CHECK_FLAG((*attr)->prefix_sid.sid_flag, BGP_LS_PREFIX_SID_FLAG_VALUE)) |
There was a problem hiding this comment.
Misleading comment about V-Flag and L-Flag positions
The comment "V-Flag and L-Flag are at same positions, both can be 1 or 0, when 1 – length is 3, when 0 – length is 4" is misleading in two ways:
- The V-flag and L-flag are not at the same bit position across all protocols. In IS-IS (RFC 8667), V=
0x08and L=0x04; in OSPFv2 (as implemented in FRR'sospfd/ospf_sr.h), the flag bits happen to shift. The assertion "same positions" can confuse future maintainers. - The code only checks
BGP_LS_PREFIX_SID_FLAG_VALUE(the V-flag,0x08), not both V and L together, which doesn't match the "both can be 1 or 0" phrasing.
Consider clarifying the comment to reflect that only the V-flag (BGP_LS_PREFIX_SID_FLAG_VALUE) is checked, and that a set V-flag means the SID is an MPLS label (3 bytes) rather than an index (4 bytes), consistent with RFC 8667 and RFC 8665.
Also, for consistency with the rest of the file, consider using the BGP_LS_TLV_SET macro on line 276 instead of the open-coded bit manipulation:
| /* IS-IS (RFC 8667, 2.1.1.1); OSPF (RFC 8665, 5); OSPFv3 (RFC 8666, 6) */ | |
| /* All protocols have same logic: V-Flag and L-Flag are at same positions, | |
| * both can be 1 or 0, when 1 - length is 3, when 0 - length is 4 | |
| */ | |
| if (CHECK_FLAG((*attr)->prefix_sid.sid_flag, BGP_LS_PREFIX_SID_FLAG_VALUE)) | |
| /* IS-IS (RFC 8667, 2.1.1.1); OSPF (RFC 8665, 5); OSPFv3 (RFC 8666, 6) | |
| * When the V-Flag (Value flag) is set, the SID carries an absolute MPLS | |
| * label value (20-bit, encoded in 3 bytes). When clear, it is an index (4 bytes). | |
| */ | |
| if (CHECK_FLAG((*attr)->prefix_sid.sid_flag, BGP_LS_PREFIX_SID_FLAG_VALUE)) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_ls_ted.c
Line: 268-272
Comment:
**Misleading comment about V-Flag and L-Flag positions**
The comment "V-Flag and L-Flag are at same positions, both can be 1 or 0, when 1 – length is 3, when 0 – length is 4" is misleading in two ways:
1. The V-flag and L-flag are **not at the same bit position** across all protocols. In IS-IS (RFC 8667), V=`0x08` and L=`0x04`; in OSPFv2 (as implemented in FRR's `ospfd/ospf_sr.h`), the flag bits happen to shift. The assertion "same positions" can confuse future maintainers.
2. The code only checks `BGP_LS_PREFIX_SID_FLAG_VALUE` (the V-flag, `0x08`), not both V and L together, which doesn't match the "both can be 1 or 0" phrasing.
Consider clarifying the comment to reflect that only the V-flag (`BGP_LS_PREFIX_SID_FLAG_VALUE`) is checked, and that a set V-flag means the SID is an MPLS label (3 bytes) rather than an index (4 bytes), consistent with RFC 8667 and RFC 8665.
Also, for consistency with the rest of the file, consider using the `BGP_LS_TLV_SET` macro on line 276 instead of the open-coded bit manipulation:
```suggestion
/* IS-IS (RFC 8667, 2.1.1.1); OSPF (RFC 8665, 5); OSPFv3 (RFC 8666, 6)
* When the V-Flag (Value flag) is set, the SID carries an absolute MPLS
* label value (20-bit, encoded in 3 bytes). When clear, it is an index (4 bytes).
*/
if (CHECK_FLAG((*attr)->prefix_sid.sid_flag, BGP_LS_PREFIX_SID_FLAG_VALUE))
```
How can I resolve this? If you propose a fix, please make it concise.| (*attr)->prefix_sid.sid_len = 3; | ||
| else | ||
| (*attr)->prefix_sid.sid_len = 4; | ||
| (*attr)->present_tlvs |= (1ULL << BGP_LS_ATTR_PREFIX_SID_BIT); |
There was a problem hiding this comment.
Inconsistent use of present_tlvs setter
All other callers in bgp_ls_ted.c set bits in present_tlvs using the BGP_LS_TLV_SET macro (e.g. lines 248, 252, 259), but here raw bit-shift arithmetic is used. Using the macro keeps the code consistent and avoids the risk of accidentally missing the ULL suffix on larger bit numbers.
| (*attr)->present_tlvs |= (1ULL << BGP_LS_ATTR_PREFIX_SID_BIT); | |
| BGP_LS_TLV_SET((*attr)->present_tlvs, BGP_LS_ATTR_PREFIX_SID_BIT); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_ls_ted.c
Line: 276
Comment:
**Inconsistent use of `present_tlvs` setter**
All other callers in `bgp_ls_ted.c` set bits in `present_tlvs` using the `BGP_LS_TLV_SET` macro (e.g. lines 248, 252, 259), but here raw bit-shift arithmetic is used. Using the macro keeps the code consistent and avoids the risk of accidentally missing the `ULL` suffix on larger bit numbers.
```suggestion
BGP_LS_TLV_SET((*attr)->present_tlvs, BGP_LS_ATTR_PREFIX_SID_BIT);
```
How can I resolve this? If you propose a fix, please make it concise.ADD TLV 1158 Prefix SID to BGP-LS: RFC 9085 Section 2.3.1 Signed-off-by: Kyrylo Yatsenko <hedrok@gmail.com>
9eac2ad to
38d38cd
Compare
|
we need a topotest |
|
|
Just to let you know. We've gotten a rash of people using AI to find buffer exploits/underflow/overflow situations recently. I just ran it on your commit and found issues. From your comments above this is the first of many new nlri parsing changes. My expectation is that you are going to go through and fix any problems before the rest are submitted. |
|
I will. My plan for each item:
After all that work I'll add topotest coverage for this TLV. But I'll do it all tomorrow (or at least will start tomorrow). 🫡 |
|
Summary:
@cscarpitta I would really appreciate advises. While waiting for advises I'll add checks in test for this TLV... 1.
It is just wrong in many aspects.
Well, it will give -1 for this Same can be written about Apart from that the function is used only as 2.
Well, Should it be fixed?.. I have very shallow understanding of how streams work here, but as I understand after each Options: Update: in #21092 3.
Totally wrong, there is: at the beginning of function, so it is impossible. 4. At last something specific to this PR. Well... Probably there is some merit in this, but I'm not sure. A lot of other parts of FRR just check V-flag. I expect that state in a. Ignore. 5. I don't see where RFC 9085 specifies at most one Prefix SID per prefix and what to do if it is not. I would expect it is. If there is policy I don't see why it can't be confused by last TLV instead of first one if FRR uses first one instead... I'll appreciate advise: a. Should I ignore this?.. Update: in #21092 even more strict option is chosen: ignore whole NLRI. |
|
About topotest for this, @cscarpitta I see as proper way to add Should I add json output as separate PR? Or do you have such plans/other suggestion how to test this?.. Thanks. |
ADD TLV 1158 Prefix SID to BGP-LS: RFC 9805 Section 2.3.1
@cscarpitta Please review.
I've got commits for TLVs:
And plan to create separate PR for each. If it is more convenient for you to review them all together, I can add them to this PR.
Thanks.