From: Roy Marples Date: Mon, 19 Oct 2015 09:19:45 +0000 (+0000) Subject: Introduce the optional option type, which allows embedded options to be X-Git-Tag: v6.9.4~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecdbb919fa4d05a8b1303848ec99a67c16b063dd;p=thirdparty%2Fdhcpcd.git Introduce the optional option type, which allows embedded options to be optional. A good example of this is the Client FQDN string in the DHCP Client FQDN option as a NULL value indicates the server has no idea what the FQDN should be. --- diff --git a/dhcp-common.c b/dhcp-common.c index 47bf47d9..285e29c0 100644 --- a/dhcp-common.c +++ b/dhcp-common.c @@ -898,9 +898,10 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix, if (eo == -1) { if (env == NULL) logger(ctx, LOG_ERR, - "%s: %s: malformed embedded option %d:%d", + "%s: %s: malformed embedded option" + " %d:%d/%zu", ifname, __func__, opt->option, - eopt->option); + eopt->option, i); goto out; } if (eo == 0) { @@ -908,15 +909,13 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix, * data for it. * This may not be an error as some options like * DHCP FQDN in RFC4702 have a string as the last - * option which is optional. - * FIXME: Add an flag to the options to indicate - * wether this is allowable or not. */ + * option which is optional. */ if (env == NULL && - (ol != 0 || i + 1 < opt->embopts_len)) + (ol != 0 || !(eopt->type & OPTIONAL))) logger(ctx, LOG_ERR, - "%s: %s: malformed embedded option %d:%d", + "%s: %s: missing embedded option %d:%d/%zu", ifname, __func__, opt->option, - eopt->option); + eopt->option, i); goto out; } /* Use the option prefix if the embedded option diff --git a/dhcp-common.h b/dhcp-common.h index 3899fc7f..37451b06 100644 --- a/dhcp-common.h +++ b/dhcp-common.h @@ -52,7 +52,7 @@ #define RFC3361 (1 << 9) #define RFC1035 (1 << 10) #define RFC3442 (1 << 11) -/* unassigned (1 << 12) */ +#define OPTIONAL (1 << 12) #define ADDRIPV6 (1 << 13) #define BINHEX (1 << 14) #define FLAG (1 << 15) diff --git a/dhcpcd-definitions.conf b/dhcpcd-definitions.conf index 5c8b6225..21552b8e 100644 --- a/dhcpcd-definitions.conf +++ b/dhcpcd-definitions.conf @@ -114,7 +114,7 @@ embed byte rcode2 # RFC1035 encoded. # The server MUST use the encoding as specified by the client as noted # in RFC4702 Section 2.1. -embed domain fqdn +embed optional domain fqdn # Option 82 is for Relay Agents and DHCP servers diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 5ef1e3c3..a7f0acd5 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 15, 2015 +.Dd October 19, 2015 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -735,6 +735,10 @@ Requests the option by default without having to be specified in user configuration .It Ic norequest This option cannot be requested, regardless of user configuration +.It Ic optional +This option is optional. +Only makes sense for embedded options where like the client FQDN option where +the FQDN string itself is optional. .It Ic index The option can appear more than once and will be indexed. .It Ic array diff --git a/if-options.c b/if-options.c index 40753fc4..71d2cb47 100644 --- a/if-options.c +++ b/if-options.c @@ -1599,6 +1599,17 @@ err_sla: } *fp++ = '\0'; } + if (strcasecmp(arg, "optional") == 0) { + t |= OPTIONAL; + arg = strskipwhite(fp); + fp = strwhite(arg); + if (fp == NULL) { + logger(ctx, LOG_ERR, + "incomplete optional type"); + return -1; + } + *fp++ = '\0'; + } if (strcasecmp(arg, "index") == 0) { t |= INDEX; arg = strskipwhite(fp);