From 441b06bc38676163fff3b6f6e97a59906759b662 Mon Sep 17 00:00:00 2001 From: "roy@uberlaptop.marples.name" Date: Sat, 4 Feb 2012 15:15:25 +0000 Subject: [PATCH] If the kernel is not configured to accept IPv6 or RA's then don't needless attempt to solicit an IPv6 RA. --- dhcpcd.c | 3 +++ ipv6rs.c | 2 +- platform-bsd.c | 37 ++++++++++++++++++++++++++++++++++++- platform-linux.c | 10 +++++++++- platform.h | 3 ++- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/dhcpcd.c b/dhcpcd.c index 621b83ac..bc2b4854 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -69,6 +69,7 @@ const char copyright[] = "Copyright (c) 2006-2012 Roy Marples"; #include "ipv4ll.h" #include "ipv6rs.h" #include "net.h" +#include "platform.h" #include "signals.h" /* We should define a maximum for the NAK exponential backoff */ @@ -1991,6 +1992,8 @@ main(int argc, char **argv) } #endif + if (options & DHCPCD_IPV6RS && !check_ipv6()) + options &= ~DHCPCD_IPV6RS; if (options & DHCPCD_IPV6RS) { ipv6rsfd = ipv6rs_open(); if (ipv6rsfd == -1) { diff --git a/ipv6rs.c b/ipv6rs.c index b9e7c9d6..69838e9d 100644 --- a/ipv6rs.c +++ b/ipv6rs.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2011 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without diff --git a/platform-bsd.c b/platform-bsd.c index dd5791ca..ff7379a2 100644 --- a/platform-bsd.c +++ b/platform-bsd.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2010 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -26,8 +26,12 @@ */ #include +#include #include #include +#include + +#include #include "platform.h" @@ -48,3 +52,34 @@ hardware_platform(void) return NULL; return march; } + +static int +inet6_sysctl(int code) +{ + int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 }; + int val; + size_t size; + + mib[3] = code; + size = sizeof(val); + if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &val, &size, NULL, 0) == -1) + return -1; + return val; +} + +int +check_ipv6(void) +{ + + if (!inet6_sysctl(IPV6CTL_ACCEPT_RTADV)) { + syslog(LOG_WARNING, + "Kernel is not configured to accept IPv6 RAs"); + return 0; + } + if (inet6_sysctl(IPV6CTL_FORWARDING)) { + syslog(LOG_WARNING, + "Kernel is configured as a router, not a host"); + return 0; + } + return 1; +} diff --git a/platform-linux.c b/platform-linux.c index 79562c84..923c9746 100644 --- a/platform-linux.c +++ b/platform-linux.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2010 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -102,3 +102,11 @@ hardware_platform(void) errno = ESRCH; return p; } + +int +check_ipv6(void) +{ + + // FIXME: Add IPv6 detection here + return 1; +} diff --git a/platform.h b/platform.h index 24731ace..1286fe62 100644 --- a/platform.h +++ b/platform.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2006-2010 Roy Marples + * Copyright (c) 2006-2012 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -29,5 +29,6 @@ #define PLATFORM_H char * hardware_platform(void); +int check_ipv6(void); #endif -- 2.47.2