Skip to content
Permalink
Browse files

Add ia_pd_suffix option

First pass of adding an option to allow customization of the suffix used on an
address when configuring a new delegated prefix.
  • Loading branch information
bldewolf committed Nov 28, 2013
1 parent eed570f commit c6ab85de3954c019a9cec2ea32c155f4a6f64b2b
Showing with 40 additions and 6 deletions.
  1. +11 −0 dhcpcd.conf.5.in
  2. +16 −1 if-options.c
  3. +1 −0 if-options.h
  4. +12 −5 ipv6.c
@@ -229,6 +229,17 @@ IPv6RS should be disabled globally when requesting a Prefix Delegation like so:
.Pp
.D1 interface eth0
.D1 ia_pd 1 eth1/0 eth2/1
.It Ic ia_pd_suffix Ar address Ns
The second half of
.Ar address
will be used as the IPv6 suffix for any delegations.
Defaults to the suffix of the link-local address on the interface.
Can be set globally or per interface.
Example:
.Pp
.D1 ia_pd_suffix ::1
.D1 interface eth0
.D1 ia_pd_suffix ::cafe:babe
.It Ic ipv4only
Only configure IPv4.
.It Ic ipv6only
@@ -73,6 +73,7 @@ unsigned long long options = 0;
#define O_NOIPV4 O_BASE + 16
#define O_NOIPV6 O_BASE + 17
#define O_IAID O_BASE + 18
#define O_IA_PD_SUFFIX O_BASE + 19

char *dev_load;

@@ -142,6 +143,7 @@ const struct option cf_options[] = {
{"hostname_short", no_argument, NULL, O_HOSTNAME_SHORT},
{"dev", required_argument, NULL, O_DEV},
{"nodev", no_argument, NULL, O_NODEV},
{"ia_pd_suffix", required_argument, NULL, O_IA_PD_SUFFIX},
{NULL, 0, NULL, '\0'}
};

@@ -1122,8 +1124,19 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
}
}
}
#endif
break;
case O_IA_PD_SUFFIX:
free(ifo->ia_suffix);
ifo->ia_suffix = malloc(sizeof(*ifo->ia_suffix));

This comment has been minimized.

Copy link
@rsmarples

rsmarples Dec 1, 2013

You need to check malloc worked here.

if (inet_pton(AF_INET6, arg, ifo->ia_suffix) != 1) {
syslog(LOG_WARNING, "%s is not a valid IPv6 address",
arg);
free(ifo->ia_suffix);
ifo->ia_suffix = NULL;
return -1;
}
break;
#endif
case O_HOSTNAME_SHORT:
ifo->options |= DHCPCD_HOSTNAME | DHCPCD_HOSTNAME_SHORT;
break;
@@ -1321,6 +1334,8 @@ free_options(struct if_options *ifo)
#ifdef INET6
for (i = 0; i < ifo->ia_len; i++)
free(ifo->ia[i].sla);

free(ifo->ia_suffix);
#endif
free(ifo->ia);

@@ -157,6 +157,7 @@ struct if_options {
uint16_t ia_type;
struct if_ia *ia;
size_t ia_len;
struct in6_addr *ia_suffix;
#ifdef INET6
int dadtransmits;
#endif
17 ipv6.c
@@ -154,12 +154,19 @@ ipv6_makeaddr(struct in6_addr *addr, const struct interface *ifp,

memcpy(addr, prefix, sizeof(*prefix));

/* Try and make the address from the first local-link address */
ap = ipv6_linklocal(ifp);
if (ap) {
addr->s6_addr32[2] = ap->addr.s6_addr32[2];
addr->s6_addr32[3] = ap->addr.s6_addr32[3];
/* Use the user-provided suffix, otherwise try and make the address
* from the first local-link address */
if(ifp->options->ia_suffix) {
addr->s6_addr32[2] = ifp->options->ia_suffix->s6_addr32[2];
addr->s6_addr32[3] = ifp->options->ia_suffix->s6_addr32[3];
return 0;
} else {
ap = ipv6_linklocal(ifp);
if (ap) {
addr->s6_addr32[2] = ap->addr.s6_addr32[2];
addr->s6_addr32[3] = ap->addr.s6_addr32[3];
return 0;
}
}

/* Because we delay a few functions until we get a local-link address

1 comment on commit c6ab85d

@rsmarples

This comment has been minimized.

Copy link

@rsmarples rsmarples commented on c6ab85d Dec 1, 2013

While I'm happy with the idea, I dislike the approach because this would also affect creating SLAAC addresses from the RA.

Please sign in to comment.