From: Roy Marples Date: Thu, 19 Sep 2019 18:20:16 +0000 (+0100) Subject: DHCP: Don't request an automatically requested option if not wanted X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=793289f66fa6f4f6d1462fad249d1cc3ae90faf2;p=thirdparty%2Fdhcpcd.git DHCP: Don't request an automatically requested option if not wanted This handy macro also simplifies the logic a little. --- diff --git a/src/dhcp-common.h b/src/dhcp-common.h index 2732823a..a711a184 100644 --- a/src/dhcp-common.h +++ b/src/dhcp-common.h @@ -81,6 +81,11 @@ #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; diff --git a/src/dhcp.c b/src/dhcp.c index 75eb3f56..fc21904b 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -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 || diff --git a/src/dhcp6.c b/src/dhcp6.c index 3c22005c..08183370 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -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);