summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iface.c15
-rw-r--r--iface.h5
-rw-r--r--llmnrd.c2
-rw-r--r--socket.c8
-rw-r--r--socket.h4
5 files changed, 21 insertions, 13 deletions
diff --git a/iface.c b/iface.c
index 9664a0c..8cb88fc 100644
--- a/iface.c
+++ b/iface.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2015-2016 Tobias Klauser <tklauser@distanz.ch>
*
* This file is part of llmnrd.
*
@@ -41,6 +41,7 @@
#include "iface.h"
static bool iface_running = true;
+static bool iface_ipv6 = false;
static pthread_t iface_thread;
static iface_event_handler_t iface_event_handler;
@@ -349,15 +350,17 @@ int iface_run(void)
return -1;
}
- sock = socket_open_rtnl();
+ sock = socket_open_rtnl(iface_ipv6);
if (sock < 0)
return -1;
/* send RTM_GETADDR request to initially populate the interface list */
if (iface_rtnl_enumerate(sock, RTM_GETADDR, AF_INET) < 0)
goto out;
- if (iface_rtnl_enumerate(sock, RTM_GETADDR, AF_INET6) < 0)
- goto out;
+ if (iface_ipv6) {
+ if (iface_rtnl_enumerate(sock, RTM_GETADDR, AF_INET6) < 0)
+ goto out;
+ }
while (iface_running) {
ssize_t recvlen;
@@ -385,8 +388,10 @@ static void* iface_run_wrapper(void *data __unused)
return ERR_PTR(iface_run());
}
-int iface_start_thread(void)
+int iface_start_thread(bool ipv6)
{
+ iface_ipv6 = ipv6;
+
if (pthread_create(&iface_thread, NULL, iface_run_wrapper, NULL) < 0) {
log_err("Failed to start interface monitoring thread\n");
return -1;
diff --git a/iface.h b/iface.h
index 47321d5..5032d87 100644
--- a/iface.h
+++ b/iface.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2015-2016 Tobias Klauser <tklauser@distanz.ch>
*
* This file is part of llmnrd.
*
@@ -19,6 +19,7 @@
#ifndef IFACE_H
#define IFACE_H
+#include <stdbool.h>
#include <sys/socket.h>
enum iface_event_type {
@@ -30,7 +31,7 @@ typedef void (*iface_event_handler_t)(enum iface_event_type, unsigned char af,
unsigned int ifindex);
void iface_register_event_handler(iface_event_handler_t event_handler);
-int iface_start_thread(void);
+int iface_start_thread(bool ipv6);
void iface_stop(void);
size_t iface_addr_lookup(unsigned int ifindex, unsigned char family,
diff --git a/llmnrd.c b/llmnrd.c
index 48e4030..866e919 100644
--- a/llmnrd.c
+++ b/llmnrd.c
@@ -167,7 +167,7 @@ int main(int argc, char **argv)
if (llmnr_init(hostname, port, ipv6) < 0)
goto out;
- if (iface_start_thread() < 0)
+ if (iface_start_thread(ipv6) < 0)
goto out;
ret = llmnr_run();
diff --git a/socket.c b/socket.c
index 872796d..21e715a 100644
--- a/socket.c
+++ b/socket.c
@@ -136,7 +136,7 @@ err:
return -1;
}
-int socket_open_rtnl(void)
+int socket_open_rtnl(bool ipv6)
{
int sock;
struct sockaddr_nl sa;
@@ -153,9 +153,11 @@ int socket_open_rtnl(void)
* listen for following events:
* - network interface create/delete/up/down
* - IPv4 address add/delete
- * - IPv6 address add/delete
+ * - IPv6 address add/delete (if enabled)
*/
- sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR;
+ sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
+ if (ipv6)
+ sa.nl_groups |= RTMGRP_IPV6_IFADDR;
if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
log_err("Failed to bind() netlink socket: %s\n", strerror(errno));
diff --git a/socket.h b/socket.h
index bb555c8..93c41a0 100644
--- a/socket.h
+++ b/socket.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014-2015 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2014-2016 Tobias Klauser <tklauser@distanz.ch>
*
* This file is part of llmnrd.
*
@@ -24,7 +24,7 @@
int socket_open_ipv4(uint16_t port);
int socket_open_ipv6(uint16_t port);
-int socket_open_rtnl(void);
+int socket_open_rtnl(bool ipv6);
int socket_mcast_group_ipv4(int sock, unsigned int ifindex, bool join);
int socket_mcast_group_ipv6(int sock, unsigned int ifindex, bool join);