-
Notifications
You must be signed in to change notification settings - Fork 1.4k
bfd: fix RFC 5880 compliance violations in packet reception #20324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SpadeMomo
wants to merge
1
commit into
FRRouting:master
Choose a base branch
from
SpadeMomo:bfd_rfc_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -852,6 +852,17 @@ static bool bfd_check_auth(const struct bfd_session *bfd, | |||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| static int match_ip_address(const struct sockaddr_any *a, const struct sockaddr_any *b) | ||||||
| { | ||||||
| if (a->sa_sin.sin_family != b->sa_sin.sin_family) | ||||||
| return 0; | ||||||
| if (a->sa_sin.sin_family == AF_INET) | ||||||
| return IPV4_ADDR_SAME(&a->sa_sin.sin_addr, &b->sa_sin.sin_addr); | ||||||
| else if (a->sa_sin.sin_family == AF_INET6) | ||||||
| return IPV6_ADDR_SAME(&a->sa_sin6.sin6_addr, &b->sa_sin6.sin6_addr); | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| void bfd_recv_cb(struct event *t) | ||||||
| { | ||||||
| int sd = EVENT_FD(t); | ||||||
|
|
@@ -954,7 +965,7 @@ void bfd_recv_cb(struct event *t) | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| if ((cp->len < BFD_PKT_LEN) || (cp->len > mlen)) { | ||||||
| if ((cp->len < (BFD_GETABIT(cp->flags) ? BFD_PKT_LEN + 2 : BFD_PKT_LEN)) || (cp->len > mlen)) { | ||||||
| frrtrace(8, frr_bfd, packet_validation_error, 5, is_mhop, &peer, &local, ifindex, | ||||||
| vrfid, cp->len, (uint32_t)mlen); | ||||||
| cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "too small"); | ||||||
|
|
@@ -999,12 +1010,27 @@ void bfd_recv_cb(struct event *t) | |||||
| } | ||||||
|
|
||||||
| /* Ensure that existing good sessions are not overridden. */ | ||||||
| if (!cp->discrs.remote_discr && bfd->ses_state != PTM_BFD_DOWN && | ||||||
| bfd->ses_state != PTM_BFD_ADM_DOWN) { | ||||||
| frrtrace(6, frr_bfd, packet_remote_discr_zero, is_mhop, &peer, &local, ifindex, | ||||||
| vrfid, bfd->ses_state); | ||||||
| /* Drop packet if address mismatch */ | ||||||
| if (!cp->discrs.remote_discr) { | ||||||
| if (bfd->ses_state == PTM_BFD_UP) { | ||||||
| /* If address mismatch, drop the packet */ | ||||||
| if (bfd->local_address.sa_sin.sin_family != AF_UNSPEC && | ||||||
| (match_ip_address(&bfd->local_address, &local) == 0)) { | ||||||
| frrtrace(6, frr_bfd, packet_remote_discr_zero, is_mhop, &peer, | ||||||
| &local, ifindex, vrfid, bfd->ses_state); | ||||||
| cp_debug(is_mhop, &peer, &local, ifindex, vrfid, | ||||||
| "local address mismatch"); | ||||||
| return; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /* Implement RFC 5880 6.8.6 */ | ||||||
| /* This is different from last check, because RFC requires checking of packet state too. */ | ||||||
| if (!cp->discrs.remote_discr && BFD_GETSTATE(cp->flags) != PTM_BFD_DOWN && | ||||||
| BFD_GETSTATE(cp->flags) != PTM_BFD_ADM_DOWN) { | ||||||
| cp_debug(is_mhop, &peer, &local, ifindex, vrfid, | ||||||
| "'remote discriminator' is zero, not overridden"); | ||||||
| "'remote discriminator' is zero in non-DOWN state"); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -1051,8 +1077,7 @@ void bfd_recv_cb(struct event *t) | |||||
| bfd->discrs.remote_discr, ntohl(cp->discrs.my_discr)); | ||||||
| } | ||||||
|
|
||||||
| bfd->discrs.remote_discr = ntohl(cp->discrs.my_discr); | ||||||
|
|
||||||
|
|
||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace on this line
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: bfdd/bfd_packet.c
Line: 1080:1080
Comment:
Trailing whitespace on this line
```suggestion
/* Check authentication. */
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| /* Check authentication. */ | ||||||
| if (!bfd_check_auth(bfd, cp)) { | ||||||
| /* Extract auth type from packet for tracing */ | ||||||
|
|
@@ -1073,6 +1098,9 @@ void bfd_recv_cb(struct event *t) | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| /* Update remote discriminator after authentication check. */ | ||||||
| bfd->discrs.remote_discr = ntohl(cp->discrs.my_discr); | ||||||
|
|
||||||
| /* Save remote diagnostics before state switch. */ | ||||||
| bfd->remote_diag = CHECK_FLAG(cp->diag, BFD_DIAGMASK); | ||||||
|
|
||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at end of file
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI