]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If an embedded or encapsulated option variable differs from the parent
authorRoy Marples <roy@marples.name>
Mon, 2 Dec 2013 14:34:04 +0000 (14:34 +0000)
committerRoy Marples <roy@marples.name>
Mon, 2 Dec 2013 14:34:04 +0000 (14:34 +0000)
variable, prefix it with the parent varaible and an underscore.

Document request, norequest and array.

Ignore string arrays.

dhcp-common.c
dhcpcd-embedded.conf
dhcpcd.conf.5.in
if-options.c

index 0f5aec4526f09c1c1d9edab37083101150bc41fc..694949bbcd8c22c2aa605b090d87155413b13a6a 100644 (file)
@@ -539,6 +539,8 @@ dhcp_envoption(char **env, const char *prefix, const char *famprefix,
        const uint8_t *ed;
        int el;
        const struct dhcp_opt *eopt;
+       char *eprefix;
+       const char *p;
 
        /* If no embedded or encapsulated options, it's easy */
        if (opt->embopts_len == 0 && opt->encopts_len == 0) {
@@ -548,6 +550,20 @@ dhcp_envoption(char **env, const char *prefix, const char *famprefix,
                return 1;
        }
 
+       /* Create a new prefix based on the option */
+       if (env) {
+               e = strlen(famprefix) + strlen(opt->v.var) + 2;
+               eprefix = malloc(e);
+               if (eprefix == NULL) {
+                       syslog(LOG_ERR, "%s: %m", __func__);
+                       return 0;
+               }
+               snprintf(eprefix, e, "%s_%s", famprefix, opt->v.var);
+       }
+       /* Silence bogus gcc warning */
+       else
+               eprefix = NULL;
+
        /* Embedded options are always processed first as that
         * is a fixed layout */
        n = 0;
@@ -557,9 +573,17 @@ dhcp_envoption(char **env, const char *prefix, const char *famprefix,
                if (e == 0)
                        /* Report error? */
                        return 0;
-               if (env)
-                       dhcp_envoption1(&env[n], prefix, famprefix, ifname,
+               if (env) {
+                       /* Use the option prefix if the embedded option
+                        * name is different.
+                        * This avoids new_fqdn_fqdn which would be silly. */
+                       if (strcmp(opt->v.var, eopt->v.var) == 0)
+                               p = famprefix;
+                       else
+                               p = eprefix;
+                       dhcp_envoption1(&env[n], prefix, p, ifname,
                            eopt, od, e);
+               }
                n++;
                od += e;
                ol -= e;
@@ -569,13 +593,21 @@ dhcp_envoption(char **env, const char *prefix, const char *famprefix,
        for (i = 0; i < opt->encopts_len; i++) {
                eopt = &opt->encopts[i];
                if ((ed = dgetopt(&el, eopt->option, od, ol))) {
-                       if (env)
-                               dhcp_envoption1(&env[n], prefix,
-                                   famprefix, ifname, eopt, ed, el);
+                       if (env) {
+                               if (strcmp(opt->v.var, eopt->v.var) == 0)
+                                       p = famprefix;
+                               else
+                                       p = eprefix;
+                               dhcp_envoption1(&env[n], prefix, p,
+                                   ifname, eopt, ed, el);
+                       }
                        n++;
                }
        }
 
+       if (env)
+               free(eprefix);
+
        /* Return number of options found */
        return n;
 }
index ee6ab6e5bc63588e05159e3a1e770618df432cc3..c413422767b23a49f0e0e3df1426aca6e91911fd 100644 (file)
@@ -1,19 +1,19 @@
 # Embedded option definitions for dhcpcd(8)
 
-# DHCP option 81, Fully Qualified Domain Name, RFC4702
-define 81 embed
-embed byte fqdn_flags
-embed byte fqdn_rcode1
-embed byte fqdn_rcode2
-embed domain fqdn
+# DHCP Fully Qualified Domain Name, RFC4702
+define 81      embed                   fqdn
+embed          byte                    flags
+embed          byte                    rcode1
+embed          byte                    rcode2
+embed          domain                  fqdn
 
-# DHCPv6 option 39, Fully Qualified Domain Name, RFC4704
-define6 39 embed
-embed byte fqdn_flags
-embed domain fqdn
+# DHCPv6 Fully Qualified Domain Name, RFC4704
+define6 39     embed                   fqdn
+embed          byte                    flags
+embed          domain                  fqdn
 
-# DHCPv6 option 56 NTP Server, RFC5908
-define6 56 encap
-encap 1 ip6address ntp_server_addr
-encap 2 ip6address ntp_mcast_addr
-encap 3 ip6address ntp_server_fqdn
+# DHCPv6 Network Time Protocol Server, RFC5908
+define6 56     encap                   ntp_server
+encap 1                ip6address              addr
+encap 2                ip6address              mcast_addr
+encap 3                ip6address              fqdn
index 0309d61222d98a5f2917d92c4a1f29cde2a28940..3ff2dea2de0a594abc25decdf9ad16d90632c31a 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd December 1, 2013
+.Dd December 2, 2013
 .Dt DHCPCD.CONF 5
 .Os
 .Sh NAME
@@ -509,10 +509,35 @@ with a prefix of
 Defines an embedded variable within the defined option.
 The length is determined by the
 .Ar type .
+If the
+.Ar variable
+is not the same as defined in the parent option,
+it is prefixed with the parent
+.Ar variable
+first with an underscore.
 .It Ic encap Ar code Ar type Ar variable
 Defines an encapsulated variable within the defined option.
 The length is determined by the
 .Ar type .
+If the
+.Ar variable
+is not the same as defined in the parent option,
+it is prefixed with the parent
+.Ar variable
+first with an underscore.
+.El
+.Ss Type prefix
+These keywords come before the type itself, to describe it more fully.
+You can use more than one, but they must appear in the order listed below.
+.Bl -tag -width -indent
+.It Ic request
+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 array
+The option data is split into a space seperated array, each element being
+the same type.
 .El
 .Ss Types to define
 The type directly affects the length of data consumed inside the option.
@@ -549,17 +574,17 @@ Contains encapsulated options (implies embed as well)
 .El
 .Ss Example definition
 .D1 # DHCP option 81, Fully Qualified Domain Name, RFC4702
-.D1 define 81 embed
-.D1 embed byte fqdn_flags
-.D1 embed byte fqdn_rcode1
-.D1 embed byte fqdn_rcode2
+.D1 define 81 embed fqdn
+.D1 embed byte flags
+.D1 embed byte rcode1
+.D1 embed byte rcode2
 .D1 embed domain fqdn
 .Pp
 .D1 # DHCP option 125, Vendor Specific Information Option, RFC3925
-.D1 define 125 encap
-.D1 embed uint32 vsio_enterprise_number
+.D1 define 125 encap vsio
+.D1 embed uint32 enterprise_number
 .D1 # Options defined for the enterprise number
-.D1 encap 1 ipaddress vsio_ipaddress
+.D1 encap 1 ipaddress ipaddress
 .Sh SEE ALSO
 .Xr fnmatch 3 ,
 .Xr if_nametoindex 3 ,
index f097573766a940f700404636394a3825b3008b44..b665cfeafe8a33c8ccb2326afbc24a05bdd09f27 100644 (file)
@@ -1325,6 +1325,10 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                            "ignoring length for type `%s'", arg);
                        l = 0;
                }
+               if (t & ARRAY && t & (STRING | BINHEX)) {
+                       syslog(LOG_WARNING, "ignoring array for strings");
+                       t &= ~ARRAY;
+               }
                /* variable */
                if (fp) {
                        arg = strskipwhite(fp);