From 9ff636a5c75c7dacce0fe915163b994d2a484002 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sat, 18 Jan 2014 14:49:29 +0000 Subject: [PATCH] IAID must be used within an interface block. IA_PD must be used within an interface block. You cannot assign a delegated prefix to the requesting interface. --- dhcpcd.c | 6 +++--- dhcpcd.conf.5.in | 13 ++++++++++--- if-options.c | 40 ++++++++++++++++++++++++++++++++-------- if-options.h | 2 +- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/dhcpcd.c b/dhcpcd.c index 4fedb6dc..d67873d6 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -495,7 +495,7 @@ configure_interface(struct interface *ifp, int argc, char **argv) { select_profile(ifp, NULL); - add_options(ifp->options, argc, argv); + add_options(ifp->name, ifp->options, argc, argv); configure_interface1(ifp); } @@ -839,7 +839,7 @@ sig_reboot(void *arg) ifdv = NULL; ifo = read_config(cffile, NULL, NULL, NULL); - add_options(ifo, margc, margv); + add_options(NULL, ifo, margc, margv); /* We need to preserve these two options. */ if (options & DHCPCD_MASTER) ifo->options |= DHCPCD_MASTER; @@ -1167,7 +1167,7 @@ main(int argc, char **argv) margv = argv; margc = argc; if_options = read_config(cffile, NULL, NULL, NULL); - opt = add_options(if_options, argc, argv); + opt = add_options(NULL, if_options, argc, argv); if (opt != 1) { if (opt == 0) usage(); diff --git a/dhcpcd.conf.5.in b/dhcpcd.conf.5.in index 9dacbb9b..3dc79d5b 100644 --- a/dhcpcd.conf.5.in +++ b/dhcpcd.conf.5.in @@ -1,4 +1,4 @@ -.\" Copyright (c) 2006-2013 Roy Marples +.\" Copyright (c) 2006-2014 Roy Marples .\" All rights reserved .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd December 6, 2013 +.Dd January 18, 2014 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -146,6 +146,9 @@ and should not be copied to other hosts. .It Ic iaid Ar iaid Set the Interface Association Identifier to .Ar iaid . +This option must be used in an +.Ic interface +block. This defaults to the last 4 bytes of the hardware address assigned to the interface. Each instance of this should be unique within the scope of the client and @@ -200,6 +203,9 @@ for each one. .It Ic ia_pd Op Ar iaid Op Ar interface Op / Ar sla_id Op / Ar prefix_len Request a DHCPv6 Delegated Prefix for .Ar iaid . +This option must be used in an +.Ic interface +block. If no .Ar interface is given then we will assign a prefix to every other interface with a unique @@ -208,7 +214,8 @@ for each, starting from 0. Otherwise addresses are only assigned for each .Ar interface and -.Ar sla_id +.Ar sla_id . +You cannot assign a prefix to the requesting interface. A default .Ar prefix_len of 64 is assumed. diff --git a/if-options.c b/if-options.c index 06a17a6b..2ec5778e 100644 --- a/if-options.c +++ b/if-options.c @@ -550,7 +550,8 @@ strskipwhite(const char *s) } static int -parse_option(struct if_options *ifo, int opt, const char *arg) +parse_option(const char *ifname, struct if_options *ifo, + int opt, const char *arg) { int i, l, t; unsigned int u; @@ -1081,6 +1082,11 @@ parse_option(struct if_options *ifo, int opt, const char *arg) break; #endif case O_IAID: + if (ifname == NULL) { + syslog(LOG_ERR, + "IAID must belong in an interface block"); + return -1; + } if (parse_iaid(ifo->iaid, arg, sizeof(ifo->iaid)) == -1) return -1; ifo->options |= DHCPCD_IAID; @@ -1112,8 +1118,19 @@ parse_option(struct if_options *ifo, int opt, const char *arg) i = D6_OPTION_IA_TA; /* FALLTHROUGH */ case O_IA_PD: - if (i == 0) + if (i == 0) { + if (ifname == NULL) { + syslog(LOG_ERR, + "IA PD must belong in an interface block"); + return -1; + } i = D6_OPTION_IA_PD; + } + if (arg != NULL && ifname == NULL) { + syslog(LOG_ERR, + "IA with IAID must belong in an interface block"); + return -1; + } ifo->options |= DHCPCD_IA_FORCED; if (ifo->ia_type != 0 && ifo->ia_type != i) { syslog(LOG_ERR, "cannot specify a different IA type"); @@ -1173,6 +1190,12 @@ parse_option(struct if_options *ifo, int opt, const char *arg) np = strchr(p, '/'); if (np) *np++ = '\0'; + if (strcmp(ifname, p) == 0) { + syslog(LOG_ERR, + "%s: cannot assign IA_PD to itself", + ifname); + return -1; + } if (strlcpy(sla->ifname, p, sizeof(sla->ifname)) >= sizeof(sla->ifname)) { @@ -1506,7 +1529,8 @@ parse_option(struct if_options *ifo, int opt, const char *arg) } static int -parse_config_line(struct if_options *ifo, const char *opt, char *line) +parse_config_line(const char *ifname, struct if_options *ifo, + const char *opt, char *line) { unsigned int i; @@ -1522,7 +1546,7 @@ parse_config_line(struct if_options *ifo, const char *opt, char *line) return -1; } - return parse_option(ifo, cf_options[i].val, line); + return parse_option(ifname, ifo, cf_options[i].val, line); } fprintf(stderr, PACKAGE ": unknown option -- %s\n", opt); @@ -1648,7 +1672,7 @@ read_config(const char *file, *(p - 1) != '\\') *p-- = '\0'; } - parse_config_line(ifo, option, line); + parse_config_line(NULL, ifo, option, line); } @@ -1737,7 +1761,7 @@ read_config(const char *file, } if (skip) continue; - parse_config_line(ifo, option, line); + parse_config_line(ifname, ifo, option, line); } fclose(f); @@ -1752,7 +1776,7 @@ read_config(const char *file, } int -add_options(struct if_options *ifo, int argc, char **argv) +add_options(const char *ifname, struct if_options *ifo, int argc, char **argv) { int oi, opt, r; @@ -1763,7 +1787,7 @@ add_options(struct if_options *ifo, int argc, char **argv) r = 1; while ((opt = getopt_long(argc, argv, IF_OPTS, cf_options, &oi)) != -1) { - r = parse_option(ifo, opt, optarg); + r = parse_option(ifname, ifo, opt, optarg); if (r != 1) break; } diff --git a/if-options.h b/if-options.h index ad594e5c..e50f9867 100644 --- a/if-options.h +++ b/if-options.h @@ -182,7 +182,7 @@ extern char *dev_load; struct if_options *read_config(const char *, const char *, const char *, const char *); -int add_options(struct if_options *, int, char **); +int add_options(const char *, struct if_options *, int, char **); void free_dhcp_opt_embenc(struct dhcp_opt *); void free_options(struct if_options *); -- 2.47.3