]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Introduce the optional option type, which allows embedded options to be
authorRoy Marples <roy@marples.name>
Mon, 19 Oct 2015 09:19:45 +0000 (09:19 +0000)
committerRoy Marples <roy@marples.name>
Mon, 19 Oct 2015 09:19:45 +0000 (09:19 +0000)
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.

dhcp-common.c
dhcp-common.h
dhcpcd-definitions.conf
dhcpcd.conf.5.in
if-options.c

index 47bf47d985cde03f135be3a82ce4d1fd28c5ab12..285e29c0d519e4aae7fdbff24536ffef18cbfefe 100644 (file)
@@ -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
index 3899fc7f3fbf5c6ba002f71139788a7fb10657de..37451b06172e8783101ddc4a88b2d1ac9d1cc425 100644 (file)
@@ -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)
index 5c8b6225ec35470b3ee3cd3a63dd8c2e13e033fd..21552b8ece4726fa375b61e8f50450e0fa90114e 100644 (file)
@@ -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
 
index 5ef1e3c32c20645ba58639f1b6a4c40185180ffc..a7f0acd58e53ae75eb6a191be6d8ebb48adcceb3 100644 (file)
@@ -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
index 40753fc4790b223b51b62dd40262b60d37520137..71d2cb478059446d47416f39f1e90610e749e8cd 100644 (file)
@@ -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);