mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Convert failure of setsockopt(..., SOL_NETLINK, NETLINK_NO_ENOBUFS, ...) into warning.
We call this, which avoids POLLERR returns from netlink on a loaded system, if the kernel is new enough to support it. Sadly, qemu-user doesn't support the socket option, so if it fails despite the kernel being new enough to support it, we just emit a warning, rather than failing hard.
This commit is contained in:
@@ -58,6 +58,7 @@ int main (int argc, char **argv)
|
|||||||
char *bound_device = NULL;
|
char *bound_device = NULL;
|
||||||
int did_bind = 0;
|
int did_bind = 0;
|
||||||
struct server *serv;
|
struct server *serv;
|
||||||
|
char *netlink_warn;
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_DHCP) || defined(HAVE_DHCP6)
|
#if defined(HAVE_DHCP) || defined(HAVE_DHCP6)
|
||||||
struct dhcp_context *context;
|
struct dhcp_context *context;
|
||||||
@@ -327,7 +328,7 @@ int main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LINUX_NETWORK)
|
#if defined(HAVE_LINUX_NETWORK)
|
||||||
netlink_init();
|
netlink_warn = netlink_init();
|
||||||
#elif defined(HAVE_BSD_NETWORK)
|
#elif defined(HAVE_BSD_NETWORK)
|
||||||
route_init();
|
route_init();
|
||||||
#endif
|
#endif
|
||||||
@@ -946,6 +947,9 @@ int main (int argc, char **argv)
|
|||||||
# ifdef HAVE_LINUX_NETWORK
|
# ifdef HAVE_LINUX_NETWORK
|
||||||
if (did_bind)
|
if (did_bind)
|
||||||
my_syslog(MS_DHCP | LOG_INFO, _("DHCP, sockets bound exclusively to interface %s"), bound_device);
|
my_syslog(MS_DHCP | LOG_INFO, _("DHCP, sockets bound exclusively to interface %s"), bound_device);
|
||||||
|
|
||||||
|
if (netlink_warn)
|
||||||
|
my_syslog(LOG_WARNING, netlink_warn);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
/* after dhcp_construct_contexts */
|
/* after dhcp_construct_contexts */
|
||||||
|
|||||||
@@ -1450,7 +1450,7 @@ void clear_cache_and_reload(time_t now);
|
|||||||
|
|
||||||
/* netlink.c */
|
/* netlink.c */
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
void netlink_init(void);
|
char *netlink_init(void);
|
||||||
void netlink_multicast(void);
|
void netlink_multicast(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ static u32 netlink_pid;
|
|||||||
|
|
||||||
static void nl_async(struct nlmsghdr *h);
|
static void nl_async(struct nlmsghdr *h);
|
||||||
|
|
||||||
void netlink_init(void)
|
char *netlink_init(void)
|
||||||
{
|
{
|
||||||
struct sockaddr_nl addr;
|
struct sockaddr_nl addr;
|
||||||
socklen_t slen = sizeof(addr);
|
socklen_t slen = sizeof(addr);
|
||||||
@@ -82,16 +82,21 @@ void netlink_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (daemon->netlinkfd == -1 ||
|
if (daemon->netlinkfd == -1 ||
|
||||||
(daemon->kernel_version >= KERNEL_VERSION(2,6,30) &&
|
|
||||||
setsockopt(daemon->netlinkfd, SOL_NETLINK, NETLINK_NO_ENOBUFS, &opt, sizeof(opt)) == -1) ||
|
|
||||||
getsockname(daemon->netlinkfd, (struct sockaddr *)&addr, &slen) == -1)
|
getsockname(daemon->netlinkfd, (struct sockaddr *)&addr, &slen) == -1)
|
||||||
die(_("cannot create netlink socket: %s"), NULL, EC_MISC);
|
die(_("cannot create netlink socket: %s"), NULL, EC_MISC);
|
||||||
|
|
||||||
|
|
||||||
/* save pid assigned by bind() and retrieved by getsockname() */
|
/* save pid assigned by bind() and retrieved by getsockname() */
|
||||||
netlink_pid = addr.nl_pid;
|
netlink_pid = addr.nl_pid;
|
||||||
|
|
||||||
iov.iov_len = 100;
|
iov.iov_len = 100;
|
||||||
iov.iov_base = safe_malloc(iov.iov_len);
|
iov.iov_base = safe_malloc(iov.iov_len);
|
||||||
|
|
||||||
|
if (daemon->kernel_version >= KERNEL_VERSION(2,6,30) &&
|
||||||
|
setsockopt(daemon->netlinkfd, SOL_NETLINK, NETLINK_NO_ENOBUFS, &opt, sizeof(opt)) == -1)
|
||||||
|
return _("warning: failed to set NETLINK_NO_ENOBUFS on netlink socket");
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t netlink_recv(void)
|
static ssize_t netlink_recv(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user