variable, prefix it with the parent varaible and an underscore.
Document request, norequest and array.
Ignore string arrays.
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) {
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;
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;
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;
}
# 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
.\" 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
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.
.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 ,
"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);