From: Roy Marples Date: Mon, 2 Dec 2013 14:34:04 +0000 (+0000) Subject: If an embedded or encapsulated option variable differs from the parent X-Git-Tag: v6.2.0~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63bdd2c247ee3eb37f35e1113bd6d82459f6bca2;p=thirdparty%2Fdhcpcd.git If an embedded or encapsulated option variable differs from the parent variable, prefix it with the parent varaible and an underscore. Document request, norequest and array. Ignore string arrays. --- diff --git a/dhcp-common.c b/dhcp-common.c index 0f5aec45..694949bb 100644 --- a/dhcp-common.c +++ b/dhcp-common.c @@ -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; } diff --git a/dhcpcd-embedded.conf b/dhcpcd-embedded.conf index ee6ab6e5..c4134227 100644 --- a/dhcpcd-embedded.conf +++ b/dhcpcd-embedded.conf @@ -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 diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 0309d612..3ff2dea2 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 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 , diff --git a/if-options.c b/if-options.c index f0975737..b665cfea 100644 --- a/if-options.c +++ b/if-options.c @@ -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);