-
Notifications
You must be signed in to change notification settings - Fork 137
manager: Fix loosing iface options on CARRIER #548
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -694,7 +694,10 @@ static void | |
| dhcpcd_initstate(struct interface *ifp, unsigned long long options) | ||
| { | ||
|
|
||
| dhcpcd_initstate1(ifp, ifp->ctx->argc, ifp->ctx->argv, options); | ||
| dhcpcd_initstate1(ifp, | ||
| ifp->argc ?: ifp->ctx->argc, | ||
| ifp->argv ?: ifp->ctx->argv, | ||
| options); | ||
| } | ||
|
|
||
| static void | ||
|
|
@@ -1315,7 +1318,7 @@ if_reboot(struct interface *ifp, int argc, char **argv) | |
| oldopts = ifp->options->options; | ||
| #endif | ||
| script_runreason(ifp, "RECONFIGURE"); | ||
| dhcpcd_initstate1(ifp, argc, argv, 0); | ||
| dhcpcd_initstate1(ifp, argc, argv, 0); // control or main argv | ||
| #ifdef INET | ||
| if (ifp->options->options & DHCPCD_DHCP) | ||
| dhcp_reboot_newopts(ifp, oldopts); | ||
|
|
@@ -1370,8 +1373,16 @@ reconf_reboot(struct dhcpcd_ctx *ctx, int action, int argc, char **argv, int oi) | |
| ipv4_applyaddr(ifp); | ||
| #endif | ||
| } else if (i != argc) { | ||
| /* iface wasnt found above -> it's new. start it. */ | ||
|
Member
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. This comment is misleading as the interface is not new, it's already been allocated. |
||
| ifp->active = IF_ACTIVE_USER; | ||
| dhcpcd_initstate1(ifp, argc, argv, 0); | ||
| dhcpcd_initstate1(ifp, argc, argv, 0); // control cmd args | ||
|
|
||
| if (ifp->argv) | ||
| free_argv_copy(ifp->argv); | ||
| ifp->argv = copy_argv(argc, argv); | ||
| if (ifp->argv) | ||
| ifp->argc = argc; | ||
|
|
||
| run_preinit(ifp); | ||
| dhcpcd_prestartinterface(ifp); | ||
| } | ||
|
|
@@ -1715,7 +1726,7 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, | |
| } | ||
|
|
||
| reload_config(ctx); | ||
| /* XXX: Respect initial commandline options? */ | ||
| /* Respect control cmd options! */ | ||
| reconf_reboot(ctx, do_reboot, argc, argv, oifind); | ||
| return 0; | ||
| } | ||
|
|
@@ -2605,7 +2616,7 @@ main(int argc, char **argv, char **envp) | |
|
|
||
| TAILQ_FOREACH(ifp, ctx.ifaces, next) { | ||
| if (ifp->active) | ||
| dhcpcd_initstate1(ifp, argc, argv, 0); | ||
| dhcpcd_initstate1(ifp, argc, argv, 0); // main argv | ||
| } | ||
| if_learnaddrs(&ctx, ctx.ifaces, &ifaddrs); | ||
| if_freeifaddrs(&ctx, &ifaddrs); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| #include <string.h> | ||
| #include <unistd.h> | ||
| #include <time.h> | ||
| #include <assert.h> | ||
|
|
||
| #include "config.h" | ||
| #include "common.h" | ||
|
|
@@ -2986,6 +2987,65 @@ add_options(struct dhcpcd_ctx *ctx, const char *ifname, | |
| return r; | ||
| } | ||
|
|
||
| #define ARGV_COPY_MAGIC ((char *)0x5a54292d273f3d34) | ||
| /*^ intentional truncation on 32bit arches */ | ||
|
Member
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. This comment is scary. |
||
|
|
||
| char **copy_argv(int argc, char **argv) | ||
| { | ||
| int i; | ||
| size_t strslen = 0; | ||
| for (i = 0; i < argc; i++) { | ||
|
Member
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. Whitespace between declaration and code please. |
||
| strslen += strlen(argv[i]) + 1; | ||
| } | ||
| if (strslen == 0) // also handles argc < 0 | ||
| return NULL; | ||
|
|
||
| unsigned nptrs = 1 + (unsigned)argc + 1; | ||
| size_t ptrslen = nptrs * sizeof(char *); | ||
| void *buf = malloc(ptrslen + strslen); | ||
| char **ptrs = buf; | ||
| if (!buf) | ||
| return NULL; | ||
|
|
||
| ptrs[0] = ARGV_COPY_MAGIC; | ||
| ptrs[nptrs - 1] = NULL; | ||
|
|
||
| if (argc == 0) | ||
| goto out; | ||
|
|
||
| char *strsp = (char *)&ptrs[nptrs]; | ||
| for (i = 0; i < argc; i++) { | ||
| size_t len = strlcpy(strsp, argv[i], strslen); | ||
| if (len >= strslen) // truncated | ||
| goto err; | ||
|
|
||
| ptrs[1 + i] = strsp; | ||
|
|
||
| strsp += len + 1; | ||
| if (strslen < len + 1) | ||
| goto err; | ||
| strslen -= len + 1; | ||
| } | ||
|
|
||
| assert(strslen == 0); | ||
|
Member
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. I find it interesting that you assert this error but allow impossible errors to pass with a failure in the loop. |
||
| assert(ptrs[nptrs - 1] == NULL); | ||
| out: | ||
| return &ptrs[1]; | ||
|
|
||
| err: | ||
| free(buf); | ||
| return NULL; | ||
| } | ||
|
|
||
| void free_argv_copy(char **argv) | ||
| { | ||
| assert(argv[-1] == ARGV_COPY_MAGIC); | ||
| if (argv[-1] != ARGV_COPY_MAGIC) { | ||
| logerrx("%s: invalid argv", __func__); | ||
| } else | ||
| free(&argv[-1]); | ||
| } | ||
|
|
||
| void | ||
| free_options(struct dhcpcd_ctx *ctx, struct if_options *ifo) | ||
| { | ||
|
|
||
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.
Is
?:a valid ternary operator in standard C?