diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2018-09-30 21:54:33 +0200 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2018-10-07 14:48:40 +0200 |
commit | 57f639e3b0288c2ec12cdfb8598a182293746a0a (patch) | |
tree | 067c8e852e34af060b2cbe5e2b4c6116f63db2c9 /src/odhcpd.c | |
parent | 402c2749f04852f84e90682cf6acca09f304efb0 (diff) |
odhcpd: make DHCPv6/RA/NDP support optional
In case IPv6 is not enabled don't try to init DHCPv6/RA and NDP but only
init DHCPv4. This allows odhcpd to start up in absence of IPv6 support.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/odhcpd.c')
-rw-r--r-- | src/odhcpd.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/odhcpd.c b/src/odhcpd.c index c1d51e7..bb7aba6 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -53,7 +53,6 @@ static void sighandler(_unused int signal) uloop_end(); } - static void print_usage(const char *app) { printf( @@ -64,6 +63,17 @@ static void print_usage(const char *app) ); } +static bool ipv6_enabled(void) +{ + int fd = socket(AF_INET6, SOCK_DGRAM, 0); + + if (fd < 0) + return false; + + close(fd); + + return true; +} int main(int argc, char **argv) { @@ -104,16 +114,20 @@ int main(int argc, char **argv) if (netlink_init()) return 4; - if (router_init()) - return 4; + if (ipv6_enabled()) { + if (router_init()) + return 4; - if (dhcpv6_init()) - return 4; + if (dhcpv6_init()) + return 4; - if (ndp_init()) + if (ndp_init()) + return 4; + } +#ifndef DHCPV4_SUPPORT + else return 4; - -#ifdef DHCPV4_SUPPORT +#else if (dhcpv4_init()) return 4; #endif |