-
Notifications
You must be signed in to change notification settings - Fork 150
Accept Force Renew messages with zero xid #719
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
ColinMcInnes
wants to merge
2
commits into
NetworkConfiguration:master
Choose a base branch
from
ColinMcInnes:fix/615-support-reconfigure
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.
+76
−41
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3091,6 +3091,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | |
| bool bootp_copied; | ||
| uint32_t v6only_time = 0; | ||
| bool use_v6only = false, has_auto_conf = false; | ||
| bool bootp_must_reject_dhcp = false; | ||
| struct dhcp_policy dp = { | ||
| .ctx = ifp->ctx, | ||
| .bootp = bootp, | ||
|
|
@@ -3128,13 +3129,53 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | |
| return; | ||
| } | ||
|
|
||
| /* We may have found a BOOTP server */ | ||
| if (get_option_uint8(ifp->ctx, &type, bootp, bootp_len, | ||
| DHO_MESSAGETYPE) == -1) | ||
| type = 0; | ||
| else | ||
| bootp_must_reject_dhcp = (ifo->options & DHCPCD_BOOTP) != 0; | ||
|
|
||
| #ifdef AUTH | ||
| if (type == DHCP_FORCERENEW) { | ||
| auth = get_option(ifp->ctx, bootp, bootp_len, | ||
| DHO_AUTHENTICATION, &auth_len); | ||
| if (auth == NULL) { | ||
| LOGDHCP(LOG_ERR, "unauthenticated Force Renew"); | ||
| return; | ||
| } | ||
| if (dhcp_auth_validate(&state->auth, &ifo->auth, | ||
| (uint8_t *)bootp, bootp_len, 4, type, auth, | ||
| auth_len) == NULL) { | ||
| LOGDHCP0(LOG_ERR, "authentication failed"); | ||
| return; | ||
| } | ||
| if (state->auth.token) | ||
| logdebugx("%s: validated using 0x%08" PRIu32, ifp->name, | ||
| state->auth.token->secretid); | ||
| else | ||
| loginfox("%s: accepted reconfigure key", ifp->name); | ||
| } | ||
| #endif | ||
|
|
||
| if (state->xid != ntohl(bootp->xid)) { | ||
| if (IS_STATE_ACTIVE(state)) | ||
| logdebugx("%s: wrong xid 0x%x (expecting 0x%x) from %s", | ||
| ifp->name, ntohl(bootp->xid), state->xid, | ||
| inet_ntoa(*from)); | ||
| dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); | ||
| return; | ||
| /* AUTH has already run; this only skips redirect for | ||
| * MikroTik xid 0 FORCERENEW. Non-FORCERENEW xid | ||
| * mismatches still redirect. */ | ||
| if (bootp->xid == 0 && type == DHCP_FORCERENEW) { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if (IS_STATE_ACTIVE(state)) | ||
| logdebugx( | ||
| "%s: xid 0 in a BOOTP reply FORCERENEW from %s", | ||
| ifp->name, inet_ntoa(*from)); | ||
| } else { | ||
| if (IS_STATE_ACTIVE(state)) | ||
| logdebugx( | ||
| "%s: wrong xid 0x%x (expecting 0x%x) from %s", | ||
| ifp->name, ntohl(bootp->xid), state->xid, | ||
| inet_ntoa(*from)); | ||
| dhcp_redirect_dhcp(ifp, bootp, bootp_len, from); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (ifp->hwlen <= sizeof(bootp->chaddr) && | ||
|
|
@@ -3170,38 +3211,31 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | |
| } | ||
| } | ||
|
|
||
| /* We may have found a BOOTP server */ | ||
| if (get_option_uint8(ifp->ctx, &type, bootp, bootp_len, | ||
| DHO_MESSAGETYPE) == -1) | ||
| type = 0; | ||
| else if (ifo->options & DHCPCD_BOOTP) { | ||
| logdebugx("%s: ignoring DHCP reply (expecting BOOTP)", | ||
| ifp->name); | ||
| return; | ||
| } | ||
|
|
||
| #ifdef AUTH | ||
| /* Authenticate the message */ | ||
| auth = get_option(ifp->ctx, bootp, bootp_len, DHO_AUTHENTICATION, | ||
| &auth_len); | ||
| if (auth) { | ||
| if (dhcp_auth_validate(&state->auth, &ifo->auth, | ||
| (uint8_t *)bootp, bootp_len, 4, type, auth, | ||
| auth_len) == NULL) { | ||
| LOGDHCP0(LOG_ERR, "authentication failed"); | ||
| return; | ||
| } | ||
| if (state->auth.token) | ||
| logdebugx("%s: validated using 0x%08" PRIu32, ifp->name, | ||
| state->auth.token->secretid); | ||
| else | ||
| loginfox("%s: accepted reconfigure key", ifp->name); | ||
| } else if (ifo->auth.options & DHCPCD_AUTH_SEND) { | ||
| if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) { | ||
| LOGDHCP0(LOG_ERR, "no authentication"); | ||
| return; | ||
| if (type != DHCP_FORCERENEW) { | ||
| /* Authenticate the message */ | ||
| auth = get_option(ifp->ctx, bootp, bootp_len, | ||
| DHO_AUTHENTICATION, &auth_len); | ||
| if (auth) { | ||
| if (dhcp_auth_validate(&state->auth, &ifo->auth, | ||
| (uint8_t *)bootp, bootp_len, 4, type, auth, | ||
| auth_len) == NULL) { | ||
| LOGDHCP0(LOG_ERR, "authentication failed"); | ||
| return; | ||
| } | ||
| if (state->auth.token) | ||
| logdebugx("%s: validated using 0x%08" PRIu32, | ||
| ifp->name, state->auth.token->secretid); | ||
| else | ||
| loginfox("%s: accepted reconfigure key", | ||
|
Contributor
Author
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. same, renew msgs are debug level, so consider dropping the log level here too |
||
| ifp->name); | ||
| } else if (ifo->auth.options & DHCPCD_AUTH_SEND) { | ||
| if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) { | ||
| LOGDHCP0(LOG_ERR, "no authentication"); | ||
| return; | ||
| } | ||
| LOGDHCP0(LOG_WARNING, "no authentication"); | ||
| } | ||
| LOGDHCP0(LOG_WARNING, "no authentication"); | ||
| } | ||
| #endif | ||
|
|
||
|
|
@@ -3213,11 +3247,6 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | |
| return; | ||
| } | ||
| #ifdef AUTH | ||
| if (auth == NULL) { | ||
| LOGDHCP(LOG_ERR, "unauthenticated Force Renew"); | ||
| if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) | ||
| return; | ||
| } | ||
| if (state->state != DHS_BOUND && state->state != DHS_INFORM) { | ||
| LOGDHCP(LOG_DEBUG, "not bound, ignoring Force Renew"); | ||
| return; | ||
|
|
@@ -3237,6 +3266,12 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | |
| return; | ||
| } | ||
|
|
||
| if (bootp_must_reject_dhcp) { | ||
| logdebugx("%s: ignoring DHCP reply (expecting BOOTP)", | ||
| ifp->name); | ||
| return; | ||
| } | ||
|
|
||
| if (state->state == DHS_BOUND) { | ||
| LOGDHCP(LOG_DEBUG, "bound, ignoring"); | ||
| return; | ||
|
|
||
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.
drop this to debug as renew is now debug