Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netlink: cleanup interfaces upon removal #229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ int netlink_get_device_addr_len(struct Interface *iface)
return addr_len;
}

void process_netlink_msg(int sock, struct Interface *ifaces)
void process_netlink_msg(int netlink_sock, struct Interface *ifaces, int icmp_sock)
{
char buf[4096];
struct iovec iov = {buf, sizeof(buf)};
struct sockaddr_nl sa;
struct msghdr msg = {.msg_name=(void *)&sa, .msg_namelen=sizeof(sa), .msg_iov=&iov, .msg_iovlen=1, .msg_control=NULL, .msg_controllen=0, .msg_flags=0};
int len = recvmsg(sock, &msg, 0);
int len = recvmsg(netlink_sock, &msg, 0);
if (len == -1) {
flog(LOG_ERR, "netlink: recvmsg failed: %s", strerror(errno));
}
Expand Down Expand Up @@ -259,7 +259,13 @@ void process_netlink_msg(int sock, struct Interface *ifaces)
break;
}
if (iface) {
touch_iface(iface);
if (nh->nlmsg_type == RTM_DELLINK) {
dlog(LOG_INFO, 4, "netlink: %s removed, cleaning up", iface->props.name);
cleanup_iface(icmp_sock, iface);
}
else {
touch_iface(iface);
}
}

} else if (nh->nlmsg_type == RTM_NEWADDR || nh->nlmsg_type == RTM_DELADDR) {
Expand Down
2 changes: 1 addition & 1 deletion netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

int netlink_get_address_lifetimes(struct AdvPrefix const *prefix, unsigned int *preferred_lft, unsigned int *valid_lft);
int netlink_get_device_addr_len(struct Interface *iface);
void process_netlink_msg(int sock, struct Interface *ifaces);
void process_netlink_msg(int netlink_sock, struct Interface *ifaces, int icmp_sock);
int netlink_socket(void);
int prefix_match (struct AdvPrefix const *prefix, struct in6_addr *addr);
2 changes: 1 addition & 1 deletion radvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ static struct Interface *main_loop(int sock, struct Interface *ifaces, char cons
if (rc > 0) {
#ifdef HAVE_NETLINK
if (fds[1].revents & POLLIN) {
process_netlink_msg(fds[1].fd, ifaces);
process_netlink_msg(fds[1].fd, ifaces, sock);
} else if (fds[1].revents & (POLLERR | POLLHUP | POLLNVAL)) {
flog(LOG_WARNING, "socket error on fds[1].fd");
}
Expand Down