Skip to content

Commit

Permalink
Merge pull request #229 from xdbob/fix-leak
Browse files Browse the repository at this point in the history
netlink: cleanup interfaces upon removal
  • Loading branch information
stappersg authored Dec 5, 2024
2 parents 3c9d491 + d83414f commit d845e3a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
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

0 comments on commit d845e3a

Please sign in to comment.