summaryrefslogtreecommitdiff
path: root/iface.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-02-18 16:49:51 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-02-18 16:49:51 +0100
commit069060cad6d9a21d9ec287a7ae9a22deb87f4abc (patch)
tree93846e5638c08a6bd3e1f38e79bae78dcbba01df /iface.c
parent8868bebeee5aad1247bd93a031a7fa30138da13d (diff)
llmnrd: Join IP multicast group on each new interface
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'iface.c')
-rw-r--r--iface.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/iface.c b/iface.c
index 510a0c4..5d0117e 100644
--- a/iface.c
+++ b/iface.c
@@ -41,6 +41,7 @@
static bool iface_running = true;
static pthread_t iface_thread;
+static iface_event_handler_t iface_event_handler;
struct iface_record {
struct list_head list;
@@ -198,7 +199,7 @@ static void iface_nlmsg_change_addr(const struct nlmsghdr *nlh)
rta = (const struct rtattr *)((const uint8_t *)nlh + NLMSG_SPACE(sizeof(*ifa)));
for ( ; RTA_OK(rta, rtalen); rta = RTA_NEXT(rta, rtalen)) {
char ifname[IF_NAMESIZE];
- const char *action;
+ enum iface_event_type type;
switch (rta->rta_type) {
case IFA_ADDRESS:
@@ -207,17 +208,21 @@ static void iface_nlmsg_change_addr(const struct nlmsghdr *nlh)
if (nlh->nlmsg_type == RTM_NEWADDR) {
iface_addr_add(index, ifa->ifa_family, RTA_DATA(rta));
- action = "Added";
+ type = IFACE_ADD;
} else if (nlh->nlmsg_type == RTM_DELADDR) {
iface_addr_del(index, ifa->ifa_family, RTA_DATA(rta));
- action = "Deleted";
+ type = IFACE_DEL;
} else {
/* This case shouldn't occur */
continue;
}
+ if (iface_event_handler)
+ (*iface_event_handler)(type, ifa->ifa_family, ifa->ifa_index);
+
log_info("%s IPv%c address %s on interface %s\n",
- action, ifa->ifa_family == AF_INET ? '4' : '6', addr,
+ type == IFACE_ADD ? "Added" : "Deleted",
+ ifa->ifa_family == AF_INET ? '4' : '6', addr,
if_indextoname(ifa->ifa_index, ifname));
}
}
@@ -290,6 +295,11 @@ static int iface_rtnl_enumerate(int sock, int type, int family)
return iface_nlmsg_process((const struct nlmsghdr *)pktbuf, recvlen);
}
+void iface_register_event_handler(iface_event_handler_t event_handler)
+{
+ iface_event_handler = event_handler;
+}
+
int iface_run(void)
{
int ret = -1;