bgpd: Allow overriding "remote-as" per-neighbor - #21450
Conversation
Greptile SummaryThis PR allows BGP peer-group members to override Key changes:
Confidence Score: 4/5Safe to merge with two minor style issues; core logic, flag tracking, and config write ordering are all correct. The main logic is sound: PEER_FLAG_REMOTE_AS correctly gates peer->as in peer_group2peer_config_copy, peer_group_remote_as and peer_group_remote_as_delete correctly skip override peers, and the VTY config write is fixed to the proper ordering for reload. Two P2 items remain: a dead *as = peer->as assignment in peer_group_bind (the return it fed was removed), and a missing comment explaining why as_type does not need guarding alongside as. Neither blocks correctness or merge. bgpd/bgpd.c β specifically peer_group_bind (dead output param) and peer_group2peer_config_copy (undocumented as_type behavior) Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: bgpd/bgpd.c
Line: 3536-3539
Comment:
**Dead output parameter assignment after error return removal**
After the `return BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT` was removed, the `if (as) *as = peer->as;` assignment on the preceding line is now effectively dead code. In the type-mismatch path (`gtype != BGP_PEER_INTERNAL && gtype != ptype`), the assignment was only meaningful as context for the caller to surface an error message β but without the error return the caller never inspects `*as` for this purpose. The function continues to bind the peer successfully regardless.
Consider removing the dead assignment or adding a comment explaining why it's retained:
```suggestion
if ((gtype != BGP_PEER_INTERNAL) && (gtype != ptype)) {
}
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: bgpd/bgpd.c
Line: 3124-3126
Comment:
**`as_type` is not guarded alongside `as` β worth a comment**
The new guard correctly prevents the group's `conf->as` from overwriting the peer's AS when `PEER_FLAG_REMOTE_AS` is set. However, `peer->as_type` is not explicitly copied anywhere in `peer_group2peer_config_copy`, so it's implicitly protected already (the peer's `as_type` set by `peer_as_change()` in `peer_remote_as()` is preserved naturally). This is correct but non-obvious. A brief comment noting that `as_type` is intentionally not propagated here would help future readers:
```suggestion
/* remote-as: propagate group AS to peer unless the peer has an
* explicit per-peer override. Note: as_type is not copied here
* (peer_as_change owns it), so no guard is needed for it.
*/
if (conf->as && !CHECK_FLAG(peer->flags_override, PEER_FLAG_REMOTE_AS))
peer->as = conf->as;
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (4): Last reviewed commit: "bgpd: Always print peer-group first for ..." | Re-trigger Greptile |
b017878 to
0c4d42a
Compare
Since we have a way to specify "remote-as auto", it makes sense to relax this behavior to allow overriding remote-as for an arbitrary neighbor too. E.g. Arista allows this behavior. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Avoid such a case like below where neighbor X does not have remote-as 1, but gets the remote-as from peer-group G. neighbor G peer-group neighbor G remote-as 2 neighbor X remote-as 1 neighbor X peer-group G Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
14e40f3 to
d4a8cb4
Compare
Related: #21397