[FRR]: Fix a BGP check that verifies if the nexthop is invalid#22910
[FRR]: Fix a BGP check that verifies if the nexthop is invalid#22910yejianquan merged 2 commits intosonic-net:masterfrom
Conversation
Currently, in `bgp_update_martian_nexthop` we do a check to evaluate whether a nexthop is valid or not. But then the result of this check is not saved and therefore it gets lost. ``` if (!ipv4_unicast_valid(&attr->nexthop) || bgp_nexthop_self(bgp, afi, type, stype, attr, dest)); ``` This commit fixes the issue by saving the result of the check in the `nh_invalid` variable that already exists. Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azpw run Azure.sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azpw run Azure.sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azpw run Azure.sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Commenter does not have sufficient privileges for PR 22910 in repo sonic-net/sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Commenter does not have sufficient privileges for PR 22910 in repo sonic-net/sonic-buildimage |
|
/azpw run Azure.sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azpw run Azure.sonic-buildimage |
|
/AzurePipelines run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) | ||
| - nh_invalid = (attr->nexthop.s_addr == INADDR_ANY || | ||
| - !ipv4_unicast_valid(&attr->nexthop) || | ||
| + if (!ipv4_unicast_valid(&attr->nexthop) || |
There was a problem hiding this comment.
Why do we remove the if here?
There was a problem hiding this comment.
@cscarpitta, can you please explain this change?
There was a problem hiding this comment.
Hi @BYGX-wcr I'm fixing an issue in the bgp_update_martian_nexthop() function.
Before my fix:
/* Check if received nexthop is valid or not. */
bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
uint8_t type, uint8_t stype, struct attr *attr,
struct bgp_dest *dest)
{
bool nh_invalid = false;
...
/* If NEXT_HOP is present, validate it:
* The route can have both nexthop + mp_nexthop encoded as multiple NLRIs,
* and we MUST check if at least one of them is valid.
* E.g.: IPv6 prefix can be with nexthop: 0.0.0.0, and mp_nexthop: fc00::1.
*/
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
if (!ipv4_unicast_valid(&attr->nexthop) ||
bgp_nexthop_self(bgp, afi, type, stype, attr, dest));
/* If MP_NEXTHOP is present, validate it. */
...
return nh_invalid;
}
After my fix:
/* Check if received nexthop is valid or not. */
bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi,
uint8_t type, uint8_t stype, struct attr *attr,
struct bgp_dest *dest)
{
bool nh_invalid = false;
...
/* If NEXT_HOP is present, validate it:
* The route can have both nexthop + mp_nexthop encoded as multiple NLRIs,
* and we MUST check if at least one of them is valid.
* E.g.: IPv6 prefix can be with nexthop: 0.0.0.0, and mp_nexthop: fc00::1.
*/
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
nh_invalid = !ipv4_unicast_valid(&attr->nexthop) ||
bgp_nexthop_self(bgp, afi, type, stype, attr, dest);
/* If MP_NEXTHOP is present, validate it. */
...
return nh_invalid;
}
As you can see, before my fix, the if statement was having no effect, because we were doing the check to evaluate whether the nexthop is valid or not, but then we did not take any action - we ignored the result of the check.
In other words, I am replacing this:
if (!ipv4_unicast_valid(&attr->nexthop) ||
bgp_nexthop_self(bgp, afi, type, stype, attr, dest));
with this:
nh_invalid = !ipv4_unicast_valid(&attr->nexthop) ||
bgp_nexthop_self(bgp, afi, type, stype, attr, dest);
The function then returns nh_invalid.
|
Cherry-pick PR to 202505: #23180 |
Currently, in
bgp_update_martian_nexthopwe do a check to evaluate whether a nexthop is valid or not. But then the result of this check is not saved and therefore it gets lost.This commit fixes the issue by saving the result of the check in the
nh_invalidvariable that already exists.