]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
DHCP: Don't request an automatically requested option if not wanted
authorRoy Marples <roy@marples.name>
Thu, 19 Sep 2019 18:20:16 +0000 (19:20 +0100)
committerRoy Marples <roy@marples.name>
Thu, 19 Sep 2019 18:20:16 +0000 (19:20 +0100)
This handy macro also simplifies the logic a little.

src/dhcp-common.h
src/dhcp.c
src/dhcp6.c

index 2732823afd23cc84561526b9c7e04b1d6b269c85..a711a184a250c82d85cac1e9e0dc4e80f47dfebc 100644 (file)
 #define        OT_BITFLAG              (1 << 27)
 #define        OT_RESERVED             (1 << 28)
 
+#define DHC_REQOPT(o, r, n)                                              \
+       (!((o)->type & OT_NOREQ) &&                                       \
+        ((o)->type & OT_REQUEST || has_option_mask((r), (o)->option)) && \
+         !has_option_mask((n), (o)->option))
+
 struct dhcp_opt {
        uint32_t option; /* Also used for IANA Enterpise Number */
        int type;
index 75eb3f56f03a4518b9ca8fada8fe71d2a9c5a645..fc21904b3707b51bacc66050dc4ec6c3366e9119 100644 (file)
@@ -1032,10 +1032,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
                    i < ifp->ctx->dhcp_opts_len;
                    i++, opt++)
                {
-                       if (!(opt->type & OT_REQUEST ||
-                           has_option_mask(ifo->requestmask, opt->option)))
-                               continue;
-                       if (opt->type & OT_NOREQ)
+                       if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask))
                                continue;
                        if (type == DHCP_INFORM &&
                            (opt->option == DHO_RENEWALTIME ||
@@ -1054,10 +1051,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
                                        break;
                        if (lp < p)
                                continue;
-                       if (!(opt->type & OT_REQUEST ||
-                           has_option_mask(ifo->requestmask, opt->option)))
-                               continue;
-                       if (opt->type & OT_NOREQ)
+                       if (!DHC_REQOPT(opt, ifo->requestmask, ifo->nomask))
                                continue;
                        if (type == DHCP_INFORM &&
                            (opt->option == DHO_RENEWALTIME ||
index 3c22005c1a9b9eab244428f6ddc9a45c1b643b7c..08183370f8c9e204212cdff208980bba68678359 100644 (file)
@@ -680,27 +680,21 @@ dhcp6_makemessage(struct interface *ifp)
                                        break;
                        }
                        if (n < ifo->dhcp6_override_len)
-                           continue;
-                       if (!(opt->type & OT_NOREQ) &&
-                           (opt->type & OT_REQUEST ||
-                           has_option_mask(ifo->requestmask6, opt->option)))
-                       {
-                               n_options++;
-                               len += sizeof(o.len);
-                       }
+                               continue;
+                       if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
+                               continue;
+                       n_options++;
+                       len += sizeof(o.len);
                }
 #ifndef SMALL
                for (l = 0, opt = ifo->dhcp6_override;
                    l < ifo->dhcp6_override_len;
                    l++, opt++)
                {
-                       if (!(opt->type & OT_NOREQ) &&
-                           (opt->type & OT_REQUEST ||
-                           has_option_mask(ifo->requestmask6, opt->option)))
-                       {
-                               n_options++;
-                               len += sizeof(o.len);
-                       }
+                       if (!DHC_REQOPT(opt, ifo->requestmask6, ifo->nomask6))
+                               continue;
+                       n_options++;
+                       len += sizeof(o.len);
                }
                if (dhcp6_findselfsla(ifp)) {
                        n_options++;
@@ -1060,34 +1054,26 @@ dhcp6_makemessage(struct interface *ifp)
                                if (n < ifo->dhcp6_override_len)
                                    continue;
 #endif
-                               if (!(opt->type & OT_NOREQ) &&
-                                   (opt->type & OT_REQUEST ||
-                                   has_option_mask(ifo->requestmask6,
-                                       opt->option)))
-                               {
-                                       o.code = htons((uint16_t)opt->option);
-                                       memcpy(p, &o.code, sizeof(o.code));
-                                       p += sizeof(o.code);
-                                       o.len = (uint16_t)
-                                           (o.len + sizeof(o.code));
-                               }
+                               if (!DHC_REQOPT(opt, ifo->requestmask6,
+                                   ifo->nomask6))
+                                       continue;
+                               o.code = htons((uint16_t)opt->option);
+                               memcpy(p, &o.code, sizeof(o.code));
+                               p += sizeof(o.code);
+                               o.len = (uint16_t)(o.len + sizeof(o.code));
                        }
 #ifndef SMALL
                        for (l = 0, opt = ifo->dhcp6_override;
                            l < ifo->dhcp6_override_len;
                            l++, opt++)
                        {
-                               if (!(opt->type & OT_NOREQ) &&
-                                   (opt->type & OT_REQUEST ||
-                                   has_option_mask(ifo->requestmask6,
-                                       opt->option)))
-                               {
-                                       o.code = htons((uint16_t)opt->option);
-                                       memcpy(p, &o.code, sizeof(o.code));
-                                       p += sizeof(o.code);
-                                       o.len = (uint16_t)
-                                           (o.len + sizeof(o.code));
-                               }
+                               if (!DHC_REQOPT(opt, ifo->requestmask6,
+                                   ifo->nomask6))
+                                       continue;
+                               o.code = htons((uint16_t)opt->option);
+                               memcpy(p, &o.code, sizeof(o.code));
+                               p += sizeof(o.code);
+                               o.len = (uint16_t)(o.len + sizeof(o.code));
                        }
                        if (dhcp6_findselfsla(ifp)) {
                                o.code = htons(D6_OPTION_PD_EXCLUDE);