mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-20 02:38:32 +00:00
Log SO_BINDTODEVICE use at startup.
This commit is contained in:
@@ -444,7 +444,7 @@ void dhcp_update_configs(struct dhcp_config *configs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
void bindtodevice(int fd)
|
char *whichdevice(void)
|
||||||
{
|
{
|
||||||
/* If we are doing DHCP on exactly one interface, and running linux, do SO_BINDTODEVICE
|
/* If we are doing DHCP on exactly one interface, and running linux, do SO_BINDTODEVICE
|
||||||
to that device. This is for the use case of (eg) OpenStack, which runs a new
|
to that device. This is for the use case of (eg) OpenStack, which runs a new
|
||||||
@@ -461,11 +461,11 @@ void bindtodevice(int fd)
|
|||||||
struct iname *if_tmp;
|
struct iname *if_tmp;
|
||||||
|
|
||||||
if (!daemon->if_names)
|
if (!daemon->if_names)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
for (if_tmp = daemon->if_names; if_tmp; if_tmp = if_tmp->next)
|
for (if_tmp = daemon->if_names; if_tmp; if_tmp = if_tmp->next)
|
||||||
if (if_tmp->name && (!if_tmp->used || strchr(if_tmp->name, '*')))
|
if (if_tmp->name && (!if_tmp->used || strchr(if_tmp->name, '*')))
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
for (found = NULL, iface = daemon->interfaces; iface; iface = iface->next)
|
for (found = NULL, iface = daemon->interfaces; iface; iface = iface->next)
|
||||||
if (iface->dhcp_ok)
|
if (iface->dhcp_ok)
|
||||||
@@ -473,18 +473,24 @@ void bindtodevice(int fd)
|
|||||||
if (!found)
|
if (!found)
|
||||||
found = iface;
|
found = iface;
|
||||||
else if (strcmp(found->name, iface->name) != 0)
|
else if (strcmp(found->name, iface->name) != 0)
|
||||||
return; /* more than one. */
|
return NULL; /* more than one. */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
{
|
return found->name;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bindtodevice(char *device, int fd)
|
||||||
|
{
|
||||||
struct ifreq ifr;
|
struct ifreq ifr;
|
||||||
strcpy(ifr.ifr_name, found->name);
|
|
||||||
|
strcpy(ifr.ifr_name, device);
|
||||||
/* only allowed by root. */
|
/* only allowed by root. */
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) == -1 &&
|
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) == -1 &&
|
||||||
errno != EPERM)
|
errno != EPERM)
|
||||||
die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, EC_BADNET);
|
die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, EC_BADNET);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ int main (int argc, char **argv)
|
|||||||
#if defined(HAVE_LINUX_NETWORK)
|
#if defined(HAVE_LINUX_NETWORK)
|
||||||
cap_user_header_t hdr = NULL;
|
cap_user_header_t hdr = NULL;
|
||||||
cap_user_data_t data = NULL;
|
cap_user_data_t data = NULL;
|
||||||
|
char *bound_device = NULL;
|
||||||
|
int did_bind = 0;
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_DHCP) || defined(HAVE_DHCP6)
|
#if defined(HAVE_DHCP) || defined(HAVE_DHCP6)
|
||||||
struct dhcp_context *context;
|
struct dhcp_context *context;
|
||||||
@@ -239,18 +241,29 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
#if defined(HAVE_LINUX_NETWORK) && defined(HAVE_DHCP)
|
#if defined(HAVE_LINUX_NETWORK) && defined(HAVE_DHCP)
|
||||||
/* after enumerate_interfaces() */
|
/* after enumerate_interfaces() */
|
||||||
|
bound_device = whichdevice();
|
||||||
|
|
||||||
if (daemon->dhcp)
|
if (daemon->dhcp)
|
||||||
{
|
{
|
||||||
if (!daemon->relay4)
|
if (!daemon->relay4 && bound_device)
|
||||||
bindtodevice(daemon->dhcpfd);
|
{
|
||||||
if (daemon->enable_pxe)
|
bindtodevice(bound_device, daemon->dhcpfd);
|
||||||
bindtodevice(daemon->pxefd);
|
did_bind = 1;
|
||||||
|
}
|
||||||
|
if (daemon->enable_pxe && bound_device)
|
||||||
|
{
|
||||||
|
bindtodevice(bound_device, daemon->pxefd);
|
||||||
|
did_bind = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LINUX_NETWORK) && defined(HAVE_DHCP6)
|
#if defined(HAVE_LINUX_NETWORK) && defined(HAVE_DHCP6)
|
||||||
if (daemon->doing_dhcp6 && !daemon->relay6)
|
if (daemon->doing_dhcp6 && !daemon->relay6 && bound_device)
|
||||||
bindtodevice(daemon->dhcp6fd);
|
{
|
||||||
|
bindtodevice(bound_device, daemon->dhcp6fd);
|
||||||
|
did_bind = 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -659,6 +672,11 @@ int main (int argc, char **argv)
|
|||||||
my_syslog(MS_DHCP | LOG_INFO, _("IPv6 router advertisement enabled"));
|
my_syslog(MS_DHCP | LOG_INFO, _("IPv6 router advertisement enabled"));
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifdef HAVE_LINUX_NETWORK
|
||||||
|
if (did_bind)
|
||||||
|
my_syslog(MS_DHCP | LOG_INFO, _("DHCP, sockets bound exclusively to interface %s"), bound_device);
|
||||||
|
# endif
|
||||||
|
|
||||||
/* after dhcp_contruct_contexts */
|
/* after dhcp_contruct_contexts */
|
||||||
if (daemon->dhcp || daemon->doing_dhcp6)
|
if (daemon->dhcp || daemon->doing_dhcp6)
|
||||||
lease_find_interfaces(now);
|
lease_find_interfaces(now);
|
||||||
|
|||||||
@@ -1268,7 +1268,8 @@ struct dhcp_config *find_config(struct dhcp_config *configs,
|
|||||||
int hw_type, char *hostname);
|
int hw_type, char *hostname);
|
||||||
int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
|
int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
|
||||||
#ifdef HAVE_LINUX_NETWORK
|
#ifdef HAVE_LINUX_NETWORK
|
||||||
void bindtodevice(int fd);
|
char *whichdevice(void);
|
||||||
|
void bindtodevice(char *device, int fd);
|
||||||
#endif
|
#endif
|
||||||
# ifdef HAVE_DHCP6
|
# ifdef HAVE_DHCP6
|
||||||
void display_opts6(void);
|
void display_opts6(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user