]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
options: use DHCPCD_MASTER to guard global options
authorRoy Marples <roy@marples.name>
Sat, 27 Jun 2020 12:46:25 +0000 (13:46 +0100)
committerRoy Marples <roy@marples.name>
Sat, 27 Jun 2020 12:46:25 +0000 (13:46 +0100)
As ifname generally always set.

src/if-options.c

index 4c4ca90f06d45c6fab794917d47a8efe67f3e475..0f146e7b4444995c28232658218dc4fa3d9a2e28 100644 (file)
@@ -674,7 +674,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                break;
        case 'c':
                ARG_REQUIRED;
-               if (ifname != NULL) {
+               if (!(ifo->options & DHCPCD_MASTER)) {
                        logerrx("%s: per interface scripts"
                            " are no longer supported",
                            ifname);
@@ -744,7 +744,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                ARG_REQUIRED;
                /* per interface logging is not supported
                 * don't want to overide the commandline */
-               if (ifname == NULL && ctx->logfile == NULL) {
+               if (ifo->options & DHCPCD_MASTER && ctx->logfile == NULL) {
                        logclose();
                        ctx->logfile = strdup(arg);
                        logopen(ctx->logfile);
@@ -947,7 +947,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                break;
        case 'z':
                ARG_REQUIRED;
-               if (ifname == NULL)
+               if (ifo->options & DHCPCD_MASTER)
                        ctx->ifav = splitv(&ctx->ifac, ctx->ifav, arg);
                break;
        case 'A':
@@ -1193,7 +1193,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                break;
        case 'Z':
                ARG_REQUIRED;
-               if (ifname == NULL)
+               if (ifo->options & DHCPCD_MASTER)
                        ctx->ifdv = splitv(&ctx->ifdc, ctx->ifdv, arg);
                break;
        case '1':
@@ -1297,7 +1297,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
 #endif
        case O_IAID:
                ARG_REQUIRED;
-               if (ifname == NULL) {
+               if (ifo->options & DHCPCD_MASTER) {
                        logerrx("IAID must belong in an interface block");
                        return -1;
                }
@@ -1339,7 +1339,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                        logwarnx("%s: IA_PD not compiled in", ifname);
                        return -1;
 #else
-                       if (ifname == NULL) {
+                       if (ifo->options & DHCPCD_MASTER) {
                                logerrx("IA PD must belong in an "
                                    "interface block");
                                return -1;
@@ -1347,7 +1347,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                        i = D6_OPTION_IA_PD;
 #endif
                }
-               if (ifname == NULL && arg) {
+               if (ifo->options & DHCPCD_MASTER && arg) {
                        logerrx("IA with IAID must belong in an "
                            "interface block");
                        return -1;
@@ -2335,6 +2335,9 @@ read_config(struct dhcpcd_ctx *ctx,
        ifo->options |= DHCPCD_DHCP6;
 #endif
 
+       /* Set master to indicate global options */
+       ifo->options |= DHCPCD_MASTER;
+
        vlen = strlcpy((char *)ifo->vendorclassid + 1, ctx->vendor,
            sizeof(ifo->vendorclassid) - 1);
        ifo->vendorclassid[0] = (uint8_t)(vlen > 255 ? 0 : vlen);
@@ -2487,7 +2490,11 @@ read_config(struct dhcpcd_ctx *ctx,
                        had_block = 1;
                        new_block = 0;
                        ifo->options &= ~DHCPCD_WAITOPTS;
+
+                       /* Unset master to indicate non-global options */
+                       ifo->options &= ~DHCPCD_MASTER;
                }
+
                /* Start of an interface block, skip if not ours */
                if (strcmp(option, "interface") == 0) {
                        char **n;