#include <net/if.h>
#include <sys/wait.h>
#include <sys/syscall.h>
+#include <arpa/inet.h>
#include "odhcp6c.h"
#include "ra.h"
char *optpos;
uint16_t opttype;
enum odhcp6c_ia_mode ia_na_mode = IA_MODE_TRY;
+ static struct in6_addr ifid = IN6ADDR_ANY_INIT;
bool help = false, daemonize = false;
int logopt = LOG_PID;
int c, request_pd = 0;
- while ((c = getopt(argc, argv, "S::N:P:c:r:s:khedp:")) != -1) {
+ while ((c = getopt(argc, argv, "S::N:P:c:i:r:s:khedp:")) != -1) {
switch (c) {
case 'S':
allow_slaac_only = (optarg) ? atoi(optarg) : -1;
}
break;
+ case 'i':
+ if (inet_pton(AF_INET6, optarg, &ifid) != 1)
+ help = true;
+ break;
+
case 'r':
optpos = optarg;
while (optpos[0]) {
signal(SIGUSR2, sighandler);
if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 ||
- init_dhcpv6(ifname, request_pd) || ra_init(ifname) ||
+ init_dhcpv6(ifname, request_pd) || ra_init(ifname, &ifid) ||
script_init(script, ifname)) {
syslog(LOG_ERR, "failed to initialize: %s", strerror(errno));
return 3;
" -N <mode> Mode for requesting addresses [try|force|none]\n"
" -P <length> Request IPv6-Prefix (0 = auto)\n"
" -c <clientid> Override client-ID (base-16 encoded)\n"
+ " -i <iface-id> Use a custom interface identifier for RA handling\n"
" -r <options> Options to be requested (comma-separated)\n"
" -s <script> Status update script (/usr/sbin/odhcp6c-update)\n"
" -k Don't send a RELEASE when stopping\n"
static void ra_send_rs(int signal __attribute__((unused)));
-int ra_init(const char *ifname)
+int ra_init(const char *ifname, const struct in6_addr *ifid)
{
sock = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
if_index = if_nametoindex(ifname);
strncpy(if_name, ifname, sizeof(if_name) - 1);
+ lladdr = *ifid;
// Filter ICMPv6 package types
struct icmp6_filter filt;
fcntl(sock, F_SETOWN, ourpid);
fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_ASYNC);
- // Get LL-addr
- FILE *fp = fopen("/proc/net/if_inet6", "r");
- if (fp) {
- char addrbuf[33], ifbuf[16];
- while (fscanf(fp, "%32s %*x %*x %*x %*x %15s", addrbuf, ifbuf) == 2) {
- if (!strcmp(ifbuf, if_name)) {
- script_unhexlify((uint8_t*)&lladdr, sizeof(lladdr), addrbuf);
- break;
+ if (IN6_IS_ADDR_UNSPECIFIED(&lladdr)) {
+ // Autodetect interface-id if not specified
+ FILE *fp = fopen("/proc/net/if_inet6", "r");
+ if (fp) {
+ char addrbuf[33], ifbuf[16];
+ while (fscanf(fp, "%32s %*x %*x %*x %*x %15s", addrbuf, ifbuf) == 2) {
+ if (!strcmp(ifbuf, if_name)) {
+ script_unhexlify((uint8_t*)&lladdr, sizeof(lladdr), addrbuf);
+ break;
+ }
}
+ fclose(fp);
}
- fclose(fp);
}
// Open rtnetlink socket