Compare commits

...
20 Commits
Author SHA1 Message Date
Simon Kelley ed4c0767b1 --add-subnet option. 2013-10-08 20:46:34 +01:00
Vic 043c271f8a Update Spanish translation. 2013-10-04 15:09:13 +01:00
Simon Kelley d4da20f064 Unset environment variables to script when we have no value for them. 2013-10-04 10:12:49 +01:00
Simon Kelley 903650af67 Further fixes to DHCP logging. 2013-10-03 11:43:09 +01:00
Tanguy Bouzeloc ef1d7425e3 Fix problem in DHCPv6 vendorclass/userclass matching code. 2013-10-03 11:06:31 +01:00
Simon Kelley 1d1c795601 Tweak tag->debian package version code so rc tags are later than test ones. 2013-10-02 14:52:23 +01:00
Simon Kelley 889d8a156f Update Polish translation. 2013-10-02 13:12:09 +01:00
Simon Kelley b7f666ff09 Add *.po target to cannonicalise .po files received from translators. 2013-10-02 11:48:43 +01:00
Simon Kelley e4e9b342a7 Cosmetic change to start-up logging of DHCPv6 configuration. 2013-10-02 11:03:39 +01:00
Simon Kelley d5c35a59b0 Merge new messages into .po files. 2013-10-01 20:28:22 +01:00
Simon Kelley 2f9fd1dcc5 Fix FTBFS when NO_IPV6 defined. 2013-10-01 09:54:41 +01:00
Simon Kelley 8f3194f7ac Do multicast interface selection portably for router advertisements. 2013-09-30 15:04:58 +01:00
Simon Kelley 10bd29265b macscript: create file if it doesn't exist. 2013-09-27 21:07:30 +01:00
Simon Kelley 42b44a591b Add contrib/mactable 2013-09-27 14:38:45 +01:00
Simon Kelley a810559b24 daemon->icmp6fd is always valid when doing DHCPv6 now. 2013-09-25 15:36:00 +01:00
Simon Kelley 861c89141a Change rules for constructing DHCPv6 ranges. 2013-09-25 15:30:30 +01:00
Simon Kelley 8939c95fd6 Don't extract MAC address from ND table when DHCPv6 request is from a relay. 2013-09-25 11:49:34 +01:00
Vladislav Grishenko 408c368fa5 Remove unused variable warnings when omitting stuff at compile-time. 2013-09-24 16:18:49 +01:00
Simon Kelley b5d9a362b4 Fix TFTP script action, broken a few commits ago. 2013-09-24 09:44:33 +01:00
Simon Kelley f1af2bb485 Big ugly refactor in rfc3315.c should be no behaviour changes. 2013-09-24 09:16:28 +01:00
30 changed files with 5776 additions and 5009 deletions

No files matched your search

+15
View File
@@ -120,6 +120,21 @@ version 2.67
connected clients. Thanks to Vladislav Grishenko connected clients. Thanks to Vladislav Grishenko
for prompting this feature. for prompting this feature.
Remove the rule for constructed DHCP ranges that the local
address must be either the first or last address in the
range. This was originally to avoid SLAAC addresses, but
we now explicitly autoconfig and privacy addresses instead.
Update Polish translation. Thanks to Jan Psota.
Fix problem in DHCPv6 vendorclass/userclass matching
code. Thanks to Tanguy Bouzeloc for the patch.
Update Spanish transalation. Thanks to Vicente Soriano.
Add --add-subnet configuration, to tell upstream DNS
servers where the original client is.
version 2.66 version 2.66
Add the ability to act as an authoritative DNS Add the ability to act as an authoritative DNS
+5
View File
@@ -114,6 +114,11 @@ merge :
echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \ echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \
done done
# Cannonicalise .po file.
%.po :
@cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
mv $(PO)/$*.po $(PO)/$*.po.orig && $(MSGMERGE) --no-wrap $(PO)/$*.po.orig $(BUILDDIR)/dnsmasq.pot >$(PO)/$*.po;
$(BUILDDIR): $(BUILDDIR):
mkdir -p $(BUILDDIR) mkdir -p $(BUILDDIR)
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
STATUS_FILE="/tmp/dnsmasq-ip-mac.status"
# Script for dnsmasq lease-change hook.
# Maintains the above file with a IP address/MAC address pairs,
# one lease per line. Works with IPv4 and IPv6 leases, file is
# atomically updated, so no races for users of the data.
action="$1"
mac="$2" # IPv4
ip="$3"
# ensure it always exists.
if [ ! -f "$STATUS_FILE" ]; then
touch "$STATUS_FILE"
fi
if [ -n "$DNSMASQ_IAID" ]; then
mac="$DNSMASQ_MAC" # IPv6
fi
# worry about an add or old action when the MAC address is not known:
# leave any old one in place in that case.
if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
if [ -n "$mac" -o "$action" = "del" ]; then
sed "/^${ip//./\.} / d" "$STATUS_FILE" > "$STATUS_FILE".new
if [ "$action" = "add" -o "$action" = "old" ]; then
echo "$ip $mac" >> "$STATUS_FILE".new
fi
mv "$STATUS_FILE".new "$STATUS_FILE" # atomic update.
fi
fi
+1 -1
View File
@@ -25,7 +25,7 @@ DEB_BUILD_ARCH_OS := $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
# Force package version based on git tags. # Force package version based on git tags.
ifneq (,$(filter gitversion,$(DEB_BUILD_OPTIONS))) ifneq (,$(filter gitversion,$(DEB_BUILD_OPTIONS)))
PACKAGE_VERSION = $(shell bld/get-version `pwd` | sed 's/[a-z]/~&/; s/-/./g; s/$$/-1/; s/^/-v/';) PACKAGE_VERSION = $(shell bld/get-version `pwd` | sed 's/test/~&/; s/[a-z]/~&/; s/-/./g; s/$$/-1/; s/^/-v/';)
endif endif
ifeq (,$(filter nodbus,$(DEB_BUILD_OPTIONS))) ifeq (,$(filter nodbus,$(DEB_BUILD_OPTIONS)))
+17 -8
View File
@@ -543,7 +543,20 @@ server. The MAC address can only be added if the requestor is on the same
subnet as the dnsmasq server. Note that the mechanism used to achieve this (an EDNS0 option) subnet as the dnsmasq server. Note that the mechanism used to achieve this (an EDNS0 option)
is not yet standardised, so this should be considered is not yet standardised, so this should be considered
experimental. Also note that exposing MAC addresses in this way may experimental. Also note that exposing MAC addresses in this way may
have security and privacy implications. have security and privacy implications. The warning about caching
given for --add-subnet applies to --add-mac too.
.TP
.B --add-subnet[[=<IPv4 prefix length>],<IPv6 prefix length>]
Add the subnet address of the requestor to the DNS queries which are
forwarded upstream. The amount of the address forwarded depends on the
prefix length parameter: 32 (128 for IPv6) forwards the whole address,
zero forwards none of it but still marks the request so that no
upstream nameserver will add client address information either. The
default is zero for both IPv4 and IPv6. Note that upstream nameservers
may be configured to return different results based on this
information, but the dnsmasq cache does not take account. If a dnsmasq
instance is configured such that different results may be encountered,
caching should be disabled.
.TP .TP
.B \-c, --cache-size=<cachesize> .B \-c, --cache-size=<cachesize>
Set the size of dnsmasq's cache. The default is 150 names. Setting the cache size to zero disables caching. Set the size of dnsmasq's cache. The default is 150 names. Setting the cache size to zero disables caching.
@@ -652,24 +665,20 @@ This forms a template which describes how to create ranges, based on the address
.B --dhcp-range=::1,::400,constructor:eth0 .B --dhcp-range=::1,::400,constructor:eth0
will look for addresses of the form <network>::1 or <network>:400 on will look for addresses on
eth0 and then create a range from <network>::1 to <network>::400. If eth0 and then create a range from <network>::1 to <network>::400. If
the interface is assigned more than one network, then the the interface is assigned more than one network, then the
corresponding ranges will be automatically created, and then corresponding ranges will be automatically created, and then
deprecated and finally removed again as the address is deprecated and deprecated and finally removed again as the address is deprecated and
then deleted. The interface name may have a final "*" wildcard. Note then deleted. The interface name may have a final "*" wildcard. Note
that just any address on eth0 will not do: the non-prefix part must be that just any address on eth0 will not do: it must not be an
equal either the start or end address given in the dhcp-range. This is autoconfigured or privacy address, or be deprecated.
to prevent prefixes becoming perpetual if the interface
gains a SLAAC address for the prefix when it is advertised by dnsmasq.
If a dhcp-range is only being used for stateless DHCP and/or SLAAC, If a dhcp-range is only being used for stateless DHCP and/or SLAAC,
then the address can be simply :: then the address can be simply ::
.B --dhcp-range=::,constructor:eth0 .B --dhcp-range=::,constructor:eth0
This removes the condition above, and will pick up the prefix from any address on eth0 which is NOT
autoconfigured, slaac, temporary or deprecated.
There is a variant of the constructor: syntax using the keyword There is a variant of the constructor: syntax using the keyword
.B constructor-noauth. .B constructor-noauth.
+465 -413
View File
File diff suppressed because it is too large. Load diff
+633 -583
View File
File diff suppressed because it is too large. Load diff
+516 -467
View File
File diff suppressed because it is too large. Load diff
+464 -410
View File
File diff suppressed because it is too large. Load diff
+490 -441
View File
File diff suppressed because it is too large. Load diff
+516 -467
View File
File diff suppressed because it is too large. Load diff
+479 -432
View File
File diff suppressed because it is too large. Load diff
+469 -420
View File
File diff suppressed because it is too large. Load diff
+516 -467
View File
File diff suppressed because it is too large. Load diff
+479 -432
View File
File diff suppressed because it is too large. Load diff
-1
View File
@@ -39,7 +39,6 @@
#define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */ #define TFTP_MAX_CONNECTIONS 50 /* max simultaneous connections */
#define LOG_MAX 5 /* log-queue length */ #define LOG_MAX 5 /* log-queue length */
#define RANDFILE "/dev/urandom" #define RANDFILE "/dev/urandom"
#define EDNS0_OPTION_MAC 5 /* dyndns.org temporary assignment */
#define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */ #define DNSMASQ_SERVICE "uk.org.thekelleys.dnsmasq" /* Default - may be overridden by config */
#define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq" #define DNSMASQ_PATH "/uk/org/thekelleys/dnsmasq"
#define AUTH_TTL 600 /* default TTL for auth DNS */ #define AUTH_TTL 600 /* default TTL for auth DNS */
+31 -11
View File
@@ -627,6 +627,8 @@ int lookup_dhcp_opt(int prot, char *name)
const struct opttab_t *t; const struct opttab_t *t;
int i; int i;
(void)prot;
#ifdef HAVE_DHCP6 #ifdef HAVE_DHCP6
if (prot == AF_INET6) if (prot == AF_INET6)
t = opttab6; t = opttab6;
@@ -646,6 +648,8 @@ int lookup_dhcp_len(int prot, int val)
const struct opttab_t *t; const struct opttab_t *t;
int i; int i;
(void)prot;
#ifdef HAVE_DHCP6 #ifdef HAVE_DHCP6
if (prot == AF_INET6) if (prot == AF_INET6)
t = opttab6; t = opttab6;
@@ -823,10 +827,10 @@ void log_context(int family, struct dhcp_context *context)
template = p; template = p;
p += sprintf(p, ", "); p += sprintf(p, ", ");
if (indextoname(daemon->doing_dhcp6 ? daemon->dhcp6fd : daemon->icmp6fd, context->if_index, ifrn_name)) if (indextoname(daemon->icmp6fd, context->if_index, ifrn_name))
sprintf(p, "%s for %s", (context->flags & CONTEXT_OLD) ? "old prefix" : "constructed", ifrn_name); sprintf(p, "%s for %s", (context->flags & CONTEXT_OLD) ? "old prefix" : "constructed", ifrn_name);
} }
else if (context->flags & CONTEXT_TEMPLATE) else if (context->flags & CONTEXT_TEMPLATE && !(context->flags & CONTEXT_RA_STATELESS))
{ {
template = p; template = p;
p += sprintf(p, ", "); p += sprintf(p, ", ");
@@ -838,21 +842,37 @@ void log_context(int family, struct dhcp_context *context)
if (!(context->flags & CONTEXT_OLD) && if (!(context->flags & CONTEXT_OLD) &&
((context->flags & CONTEXT_DHCP) || family == AF_INET)) ((context->flags & CONTEXT_DHCP) || family == AF_INET))
{ {
inet_ntop(family, start, daemon->dhcp_buff, 256); #ifdef HAVE_DHCP6
if (context->flags & CONTEXT_RA_STATELESS)
{
if (context->flags & CONTEXT_TEMPLATE)
strncpy(daemon->dhcp_buff, context->template_interface, 256);
else
strcpy(daemon->dhcp_buff, daemon->addrbuff);
}
else
#endif
inet_ntop(family, start, daemon->dhcp_buff, 256);
inet_ntop(family, end, daemon->dhcp_buff3, 256); inet_ntop(family, end, daemon->dhcp_buff3, 256);
my_syslog(MS_DHCP | LOG_INFO, my_syslog(MS_DHCP | LOG_INFO,
(context->flags & CONTEXT_RA_STATELESS) ? (context->flags & CONTEXT_RA_STATELESS) ?
_("%s stateless on %s%.0s%.0s%s") : _("%s stateless on %s%.0s%.0s%s") :
(context->flags & CONTEXT_STATIC) ? (context->flags & CONTEXT_STATIC) ?
_("%s, static leases only on %.0s%s%s%.0s") : _("%s, static leases only on %.0s%s%s%.0s") :
(context->flags & CONTEXT_PROXY) ? (context->flags & CONTEXT_PROXY) ?
_("%s, proxy on subnet %.0s%s%.0s%.0s") : _("%s, proxy on subnet %.0s%s%.0s%.0s") :
_("%s, IP range %s -- %s%s%.0s"), _("%s, IP range %s -- %s%s%.0s"),
(family != AF_INET) ? "DHCPv6" : "DHCP", (family != AF_INET) ? "DHCPv6" : "DHCP",
daemon->dhcp_buff, daemon->dhcp_buff3, daemon->namebuff, template); daemon->dhcp_buff, daemon->dhcp_buff3, daemon->namebuff, template);
} }
#ifdef HAVE_DHCP6 #ifdef HAVE_DHCP6
if (context->flags & CONTEXT_TEMPLATE)
{
strcpy(daemon->addrbuff, context->template_interface);
template = "";
}
if ((context->flags & CONTEXT_RA_NAME) && !(context->flags & CONTEXT_OLD)) if ((context->flags & CONTEXT_RA_NAME) && !(context->flags & CONTEXT_OLD))
my_syslog(MS_DHCP | LOG_INFO, _("DHCPv4-derived IPv6 names on %s%s"), daemon->addrbuff, template); my_syslog(MS_DHCP | LOG_INFO, _("DHCPv4-derived IPv6 names on %s%s"), daemon->addrbuff, template);
+61 -56
View File
@@ -29,7 +29,7 @@ struct iface_param {
struct mac_param { struct mac_param {
struct in6_addr *target; struct in6_addr *target;
unsigned char mac[DHCP_CHADDR_MAX]; unsigned char *mac;
unsigned int maclen; unsigned int maclen;
}; };
@@ -99,7 +99,6 @@ void dhcp6_packet(time_t now)
struct dhcp_context *context; struct dhcp_context *context;
struct dhcp_relay *relay; struct dhcp_relay *relay;
struct iface_param parm; struct iface_param parm;
struct mac_param mac_param;
struct cmsghdr *cmptr; struct cmsghdr *cmptr;
struct msghdr msg; struct msghdr msg;
int if_index = 0; int if_index = 0;
@@ -145,8 +144,6 @@ void dhcp6_packet(time_t now)
if ((port = relay_reply6(&from, sz, ifr.ifr_name)) == 0) if ((port = relay_reply6(&from, sz, ifr.ifr_name)) == 0)
{ {
int i;
for (tmp = daemon->if_except; tmp; tmp = tmp->next) for (tmp = daemon->if_except; tmp; tmp = tmp->next)
if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name)) if (tmp->name && wildcard_match(tmp->name, ifr.ifr_name))
return; return;
@@ -182,48 +179,6 @@ void dhcp6_packet(time_t now)
if (!iface_enumerate(AF_INET6, &parm, complete_context6)) if (!iface_enumerate(AF_INET6, &parm, complete_context6))
return; return;
/* Recieving a packet from a host does not populate the neighbour
cache, so we send a neighbour discovery request if we can't
find the sender. Repeat a few times in case of packet loss. */
for (i = 0; i < 5; i++)
{
struct timespec ts;
struct neigh_packet *neigh;
struct sockaddr_in6 addr;
mac_param.target = &from.sin6_addr;
mac_param.maclen = 0;
iface_enumerate(AF_UNSPEC, &mac_param, find_mac);
if (mac_param.maclen != 0)
break;
save_counter(0);
neigh = expand(sizeof(struct neigh_packet));
neigh->type = ND_NEIGHBOR_SOLICIT;
neigh->code = 0;
neigh->reserved = 0;
neigh->target = from.sin6_addr;
memset(&addr, 0, sizeof(addr));
#ifdef HAVE_SOCKADDR_SA_LEN
addr.sin6_len = sizeof(struct sockaddr_in6);
#endif
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(IPPROTO_ICMPV6);
addr.sin6_addr = from.sin6_addr;
addr.sin6_scope_id = from.sin6_scope_id;
sendto(daemon->icmp6fd, daemon->outpacket.iov_base, save_counter(0), 0,
(struct sockaddr *)&addr, sizeof(addr));
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 100ms */
nanosleep(&ts, NULL);
}
if (daemon->if_names || daemon->if_addrs) if (daemon->if_names || daemon->if_addrs)
{ {
@@ -244,8 +199,7 @@ void dhcp6_packet(time_t now)
inet_pton(AF_INET6, ALL_SERVERS, &all_servers); inet_pton(AF_INET6, ALL_SERVERS, &all_servers);
if (!IN6_ARE_ADDR_EQUAL(&dst_addr, &all_servers)) if (!IN6_ARE_ADDR_EQUAL(&dst_addr, &all_servers))
relay_upstream6(parm.relay, sz, &from.sin6_addr, from.sin6_scope_id, relay_upstream6(parm.relay, sz, &from.sin6_addr, from.sin6_scope_id);
mac_param.maclen == 0 ? NULL : &mac_param.mac[0], mac_param.maclen, ARPHRD_ETHER);
return; return;
} }
@@ -256,8 +210,7 @@ void dhcp6_packet(time_t now)
lease_prune(NULL, now); /* lose any expired leases */ lease_prune(NULL, now); /* lose any expired leases */
port = dhcp6_reply(parm.current, if_index, ifr.ifr_name, &parm.fallback, port = dhcp6_reply(parm.current, if_index, ifr.ifr_name, &parm.fallback,
sz, IN6_IS_ADDR_MULTICAST(&from.sin6_addr), now, sz, &from.sin6_addr, now);
mac_param.maclen == 0 ? NULL : &mac_param.mac[0], mac_param.maclen, ARPHRD_ETHER);
lease_update_file(now); lease_update_file(now);
lease_update_dns(0); lease_update_dns(0);
@@ -276,6 +229,55 @@ void dhcp6_packet(time_t now)
} }
} }
void get_client_mac(struct in6_addr *client, int iface, unsigned char *mac, unsigned int *maclenp, unsigned int *mactypep)
{
/* Recieving a packet from a host does not populate the neighbour
cache, so we send a neighbour discovery request if we can't
find the sender. Repeat a few times in case of packet loss. */
struct neigh_packet neigh;
struct sockaddr_in6 addr;
struct mac_param mac_param;
int i;
neigh.type = ND_NEIGHBOR_SOLICIT;
neigh.code = 0;
neigh.reserved = 0;
neigh.target = *client;
memset(&addr, 0, sizeof(addr));
#ifdef HAVE_SOCKADDR_SA_LEN
addr.sin6_len = sizeof(struct sockaddr_in6);
#endif
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(IPPROTO_ICMPV6);
addr.sin6_addr = *client;
addr.sin6_scope_id = iface;
mac_param.target = client;
mac_param.maclen = 0;
mac_param.mac = mac;
for (i = 0; i < 5; i++)
{
struct timespec ts;
iface_enumerate(AF_UNSPEC, &mac_param, find_mac);
if (mac_param.maclen != 0)
break;
sendto(daemon->icmp6fd, &neigh, sizeof(neigh), 0, (struct sockaddr *)&addr, sizeof(addr));
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 100ms */
nanosleep(&ts, NULL);
}
*maclenp = mac_param.maclen;
*mactypep = ARPHRD_ETHER;
}
static int find_mac(int family, char *addrp, char *mac, size_t maclen, void *parmv) static int find_mac(int family, char *addrp, char *mac, size_t maclen, void *parmv)
{ {
struct mac_param *parm = parmv; struct mac_param *parm = parmv;
@@ -552,6 +554,7 @@ static int make_duid1(int index, unsigned int type, char *mac, size_t maclen, vo
unsigned char *p; unsigned char *p;
(void)index; (void)index;
(void)parm;
if (type >= 256) if (type >= 256)
return 1; return 1;
@@ -599,7 +602,13 @@ static int construct_worker(struct in6_addr *local, int prefix,
IN6_IS_ADDR_MULTICAST(local)) IN6_IS_ADDR_MULTICAST(local))
return 1; return 1;
if (!indextoname(daemon->doing_dhcp6 ? daemon->dhcp6fd : daemon->icmp6fd, if_index, ifrn_name)) if (!(flags & IFACE_PERMANENT))
return 1;
if (flags & IFACE_DEPRECATED)
return 1;
if (!indextoname(daemon->icmp6fd, if_index, ifrn_name))
return 0; return 0;
for (template = daemon->dhcp6; template; template = template->next) for (template = daemon->dhcp6; template; template = template->next)
@@ -615,11 +624,7 @@ static int construct_worker(struct in6_addr *local, int prefix,
} }
} }
else if ((addr6part(local) == addr6part(&template->start6) || else if (wildcard_match(template->template_interface, ifrn_name))
addr6part(local) == addr6part(&template->end6) ||
(IN6_IS_ADDR_UNSPECIFIED(&template->start6) &&
IFACE_PERMANENT == (flags & (IFACE_PERMANENT | IFACE_DEPRECATED)))) &&
wildcard_match(template->template_interface, ifrn_name))
{ {
start6 = *local; start6 = *local;
setaddr6part(&start6, addr6part(&template->start6)); setaddr6part(&start6, addr6part(&template->start6));
+4
View File
@@ -56,6 +56,10 @@
#define T_MAILB 253 #define T_MAILB 253
#define T_ANY 255 #define T_ANY 255
#define EDNS0_OPTION_MAC 65001 /* dyndns.org temporary assignment */
#define EDNS0_OPTION_CLIENT_SUBNET 5 /* IANA */
struct dns_header { struct dns_header {
u16 id; u16 id;
u8 hb3,hb4; u8 hb3,hb4;
+4
View File
@@ -51,8 +51,10 @@ int main (int argc, char **argv)
cap_user_header_t hdr = NULL; cap_user_header_t hdr = NULL;
cap_user_data_t data = NULL; cap_user_data_t data = NULL;
#endif #endif
#if defined(HAVE_DHCP) || defined(HAVE_DHCP6)
struct dhcp_context *context; struct dhcp_context *context;
struct dhcp_relay *relay; struct dhcp_relay *relay;
#endif
#ifdef LOCALEDIR #ifdef LOCALEDIR
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@@ -1231,6 +1233,8 @@ void poll_resolv(int force, int do_reload, time_t now)
void clear_cache_and_reload(time_t now) void clear_cache_and_reload(time_t now)
{ {
(void)now;
if (daemon->port != 0) if (daemon->port != 0)
cache_reload(); cache_reload();
+11 -5
View File
@@ -222,7 +222,8 @@ struct event_desc {
#define OPT_CLEVERBIND 39 #define OPT_CLEVERBIND 39
#define OPT_TFTP 40 #define OPT_TFTP 40
#define OPT_FAST_RA 41 #define OPT_FAST_RA 41
#define OPT_LAST 42 #define OPT_CLIENT_SUBNET 42
#define OPT_LAST 43
/* extra flags for my_syslog, we use a couple of facilities since they are known /* extra flags for my_syslog, we use a couple of facilities since they are known
not to occupy the same bits as priorities, no matter how syslog.h is set up. */ not to occupy the same bits as priorities, no matter how syslog.h is set up. */
@@ -487,6 +488,7 @@ struct hostsfile {
#define FREC_NOREBIND 1 #define FREC_NOREBIND 1
#define FREC_CHECKING_DISABLED 2 #define FREC_CHECKING_DISABLED 2
#define FREC_HAS_SUBNET 4
struct frec { struct frec {
union mysockaddr source; union mysockaddr source;
@@ -802,6 +804,8 @@ extern struct daemon {
struct auth_zone *auth_zones; struct auth_zone *auth_zones;
struct interface_name *int_names; struct interface_name *int_names;
char *mxtarget; char *mxtarget;
int addr4_netmask;
int addr6_netmask;
char *lease_file; char *lease_file;
char *username, *groupname, *scriptuser; char *username, *groupname, *scriptuser;
char *luascript; char *luascript;
@@ -962,6 +966,8 @@ unsigned int questions_crc(struct dns_header *header, size_t plen, char *buff);
size_t resize_packet(struct dns_header *header, size_t plen, size_t resize_packet(struct dns_header *header, size_t plen,
unsigned char *pheader, size_t hlen); unsigned char *pheader, size_t hlen);
size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3); size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3);
size_t add_source_addr(struct dns_header *header, size_t plen, char *limit, union mysockaddr *source);
int check_source(struct dns_header *header, size_t plen, unsigned char *pseudoheader, union mysockaddr *peer);
int add_resource_record(struct dns_header *header, char *limit, int *truncp, int add_resource_record(struct dns_header *header, char *limit, int *truncp,
int nameoffset, unsigned char **pp, unsigned long ttl, int nameoffset, unsigned char **pp, unsigned long ttl,
int *offset, unsigned short type, unsigned short class, char *format, ...); int *offset, unsigned short type, unsigned short class, char *format, ...);
@@ -1212,15 +1218,15 @@ struct dhcp_config *config_find_by_address6(struct dhcp_config *configs, struct
int prefix, u64 addr); int prefix, u64 addr);
void make_duid(time_t now); void make_duid(time_t now);
void dhcp_construct_contexts(time_t now); void dhcp_construct_contexts(time_t now);
void get_client_mac(struct in6_addr *client, int iface, unsigned char *mac,
unsigned int *maclenp, unsigned int *mactypep);
#endif #endif
/* rfc3315.c */ /* rfc3315.c */
#ifdef HAVE_DHCP6 #ifdef HAVE_DHCP6
unsigned short dhcp6_reply(struct dhcp_context *context, int interface, char *iface_name, unsigned short dhcp6_reply(struct dhcp_context *context, int interface, char *iface_name,
struct in6_addr *fallback, size_t sz, int is_multicast, time_t now, struct in6_addr *fallback, size_t sz, struct in6_addr *client_addr, time_t now);
unsigned char *mac, unsigned int mac_len, unsigned int mac_type); void relay_upstream6(struct dhcp_relay *relay, ssize_t sz, struct in6_addr *peer_address, u32 scope_id);
void relay_upstream6(struct dhcp_relay *relay, ssize_t sz, struct in6_addr *peer_address, u32 scope_id,
unsigned char *mac, unsigned int mac_len, unsigned int mac_type);
unsigned short relay_reply6( struct sockaddr_in6 *peer, ssize_t sz, char *arrival_interface); unsigned short relay_reply6( struct sockaddr_in6 *peer, ssize_t sz, char *arrival_interface);
#endif #endif
+47 -12
View File
@@ -284,6 +284,7 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
forward->fd = udpfd; forward->fd = udpfd;
forward->crc = crc; forward->crc = crc;
forward->forwardall = 0; forward->forwardall = 0;
forward->flags = 0;
if (norebind) if (norebind)
forward->flags |= FREC_NOREBIND; forward->flags |= FREC_NOREBIND;
if (header->hb4 & HB4_CD) if (header->hb4 & HB4_CD)
@@ -331,6 +332,16 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
if (option_bool(OPT_ADD_MAC)) if (option_bool(OPT_ADD_MAC))
plen = add_mac(header, plen, ((char *) header) + PACKETSZ, &forward->source); plen = add_mac(header, plen, ((char *) header) + PACKETSZ, &forward->source);
if (option_bool(OPT_CLIENT_SUBNET))
{
size_t new = add_source_addr(header, plen, ((char *) header) + PACKETSZ, &forward->source);
if (new != plen)
{
plen = new;
forward->flags |= FREC_HAS_SUBNET;
}
}
while (1) while (1)
{ {
/* only send to servers dealing with our domain. /* only send to servers dealing with our domain.
@@ -435,8 +446,8 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
return 0; return 0;
} }
static size_t process_reply(struct dns_header *header, time_t now, static size_t process_reply(struct dns_header *header, time_t now, struct server *server, size_t n, int check_rebind,
struct server *server, size_t n, int check_rebind, int checking_disabled) int checking_disabled, int check_subnet, union mysockaddr *query_source)
{ {
unsigned char *pheader, *sizep; unsigned char *pheader, *sizep;
char **sets = 0; char **sets = 0;
@@ -465,19 +476,29 @@ static size_t process_reply(struct dns_header *header, time_t now,
than we allow, trim it so that we don't get overlarge than we allow, trim it so that we don't get overlarge
requests for the client. We can't do this for signed packets. */ requests for the client. We can't do this for signed packets. */
if ((pheader = find_pseudoheader(header, n, &plen, &sizep, &is_sign)) && !is_sign) if ((pheader = find_pseudoheader(header, n, &plen, &sizep, &is_sign)))
{ {
unsigned short udpsz; if (!is_sign)
unsigned char *psave = sizep; {
unsigned short udpsz;
unsigned char *psave = sizep;
GETSHORT(udpsz, sizep); GETSHORT(udpsz, sizep);
if (udpsz > daemon->edns_pktsz) if (udpsz > daemon->edns_pktsz)
PUTSHORT(daemon->edns_pktsz, psave); PUTSHORT(daemon->edns_pktsz, psave);
}
if (check_subnet && !check_source(header, plen, pheader, query_source))
{
my_syslog(LOG_WARNING, _("discarding DNS reply: subnet option mismatch"));
return 0;
}
} }
/* RFC 4035 sect 4.6 para 3 */ /* RFC 4035 sect 4.6 para 3 */
if (!is_sign && !option_bool(OPT_DNSSEC)) if (!is_sign && !option_bool(OPT_DNSSEC))
header->hb4 &= ~HB4_AD; header->hb4 &= ~HB4_AD;
if (OPCODE(header) != QUERY || (RCODE(header) != NOERROR && RCODE(header) != NXDOMAIN)) if (OPCODE(header) != QUERY || (RCODE(header) != NOERROR && RCODE(header) != NXDOMAIN))
return n; return n;
@@ -632,7 +653,8 @@ void reply_query(int fd, int family, time_t now)
if (!option_bool(OPT_NO_REBIND)) if (!option_bool(OPT_NO_REBIND))
check_rebind = 0; check_rebind = 0;
if ((nn = process_reply(header, now, server, (size_t)n, check_rebind, forward->flags & FREC_CHECKING_DISABLED))) if ((nn = process_reply(header, now, server, (size_t)n, check_rebind, forward->flags & FREC_CHECKING_DISABLED,
forward->flags & FREC_HAS_SUBNET, &forward->source)))
{ {
header->id = htons(forward->orig_id); header->id = htons(forward->orig_id);
header->hb4 |= HB4_RA; /* recursion if available */ header->hb4 |= HB4_RA; /* recursion if available */
@@ -876,7 +898,7 @@ unsigned char *tcp_request(int confd, time_t now,
{ {
size_t size = 0; size_t size = 0;
int norebind = 0; int norebind = 0;
int checking_disabled; int checking_disabled, check_subnet;
size_t m; size_t m;
unsigned short qtype; unsigned short qtype;
unsigned int gotname; unsigned int gotname;
@@ -906,6 +928,8 @@ unsigned char *tcp_request(int confd, time_t now,
if (size < (int)sizeof(struct dns_header)) if (size < (int)sizeof(struct dns_header))
continue; continue;
check_subnet = 0;
/* save state of "cd" flag in query */ /* save state of "cd" flag in query */
checking_disabled = header->hb4 & HB4_CD; checking_disabled = header->hb4 & HB4_CD;
@@ -956,6 +980,16 @@ unsigned char *tcp_request(int confd, time_t now,
if (option_bool(OPT_ADD_MAC)) if (option_bool(OPT_ADD_MAC))
size = add_mac(header, size, ((char *) header) + 65536, &peer_addr); size = add_mac(header, size, ((char *) header) + 65536, &peer_addr);
if (option_bool(OPT_CLIENT_SUBNET))
{
size_t new = add_source_addr(header, size, ((char *) header) + 65536, &peer_addr);
if (size != new)
{
size = new;
check_subnet = 1;
}
}
if (gotname) if (gotname)
flags = search_servers(now, &addrp, gotname, daemon->namebuff, &type, &domain, &norebind); flags = search_servers(now, &addrp, gotname, daemon->namebuff, &type, &domain, &norebind);
@@ -1056,7 +1090,8 @@ unsigned char *tcp_request(int confd, time_t now,
sending replies containing questions and bogus answers. */ sending replies containing questions and bogus answers. */
if (crc == questions_crc(header, (unsigned int)m, daemon->namebuff)) if (crc == questions_crc(header, (unsigned int)m, daemon->namebuff))
m = process_reply(header, now, last_server, (unsigned int)m, m = process_reply(header, now, last_server, (unsigned int)m,
option_bool(OPT_NO_REBIND) && !norebind, checking_disabled); option_bool(OPT_NO_REBIND) && !norebind, checking_disabled,
check_subnet, &peer_addr);
break; break;
} }
+56 -50
View File
@@ -61,8 +61,13 @@ struct script_data
#else #else
time_t expires; time_t expires;
#endif #endif
#ifdef HAVE_DHCP6 #ifdef HAVE_TFTP
off_t file_len;
#endif
#ifdef HAVE_IPV6
struct in6_addr addr6; struct in6_addr addr6;
#endif
#ifdef HAVE_DHCP6
int iaid, vendorclass_count; int iaid, vendorclass_count;
#endif #endif
unsigned char hwaddr[DHCP_CHADDR_MAX]; unsigned char hwaddr[DHCP_CHADDR_MAX];
@@ -289,9 +294,11 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
inet_ntop(AF_INET6, &data.addr6, daemon->addrbuff, ADDRSTRLEN); inet_ntop(AF_INET6, &data.addr6, daemon->addrbuff, ADDRSTRLEN);
#endif #endif
#ifdef HAVE_TFTP
/* file length */ /* file length */
if (data.action == ACTION_TFTP) if (data.action == ACTION_TFTP)
sprintf(daemon->dhcp_buff, "%u", data.hwaddr_len); sprintf(is6 ? daemon->packet : daemon->dhcp_buff, "%lu", (unsigned long)data.file_len);
#endif
#ifdef HAVE_LUASCRIPT #ifdef HAVE_LUASCRIPT
if (daemon->luascript) if (daemon->luascript)
@@ -309,7 +316,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
lua_setfield(lua, -2, "destination_address"); lua_setfield(lua, -2, "destination_address");
lua_pushstring(lua, hostname); lua_pushstring(lua, hostname);
lua_setfield(lua, -2, "file_name"); lua_setfield(lua, -2, "file_name");
lua_pushstring(lua, daemon->dhcp_buff); lua_pushstring(lua, is6 ? daemon->packet : daemon->dhcp_buff);
lua_setfield(lua, -2, "file_size"); lua_setfield(lua, -2, "file_size");
lua_call(lua, 2, 0); /* pass 2 values, expect 0 */ lua_call(lua, 2, 0); /* pass 2 values, expect 0 */
} }
@@ -474,20 +481,13 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
if (data.action != ACTION_TFTP) if (data.action != ACTION_TFTP)
{ {
#ifdef HAVE_DHCP6 #ifdef HAVE_DHCP6
if (is6) my_setenv("DNSMASQ_IAID", is6 ? daemon->dhcp_buff3 : NULL, &err);
{ my_setenv("DNSMASQ_SERVER_DUID", is6 ? daemon->dhcp_packet.iov_base : NULL, &err);
my_setenv("DNSMASQ_IAID", daemon->dhcp_buff3, &err); my_setenv("DNSMASQ_MAC", is6 && data.hwaddr_len != 0 ? daemon->dhcp_buff : NULL, &err);
my_setenv("DNSMASQ_SERVER_DUID", daemon->dhcp_packet.iov_base, &err);
if (data.hwaddr_len != 0)
my_setenv("DNSMASQ_MAC", daemon->dhcp_buff, &err);
}
#endif #endif
if (!is6 && data.clid_len != 0) my_setenv("DNSMASQ_CLIENT_ID", !is6 && data.clid_len != 0 ? daemon->packet : NULL, &err);
my_setenv("DNSMASQ_CLIENT_ID", daemon->packet, &err); my_setenv("DNSMASQ_INTERFACE", strlen(data.interface) != 0 ? data.interface : NULL, &err);
if (strlen(data.interface) != 0)
my_setenv("DNSMASQ_INTERFACE", data.interface, &err);
#ifdef HAVE_BROKEN_RTC #ifdef HAVE_BROKEN_RTC
sprintf(daemon->dhcp_buff2, "%u", data.length); sprintf(daemon->dhcp_buff2, "%u", data.length);
@@ -497,8 +497,7 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
my_setenv("DNSMASQ_LEASE_EXPIRES", daemon->dhcp_buff2, &err); my_setenv("DNSMASQ_LEASE_EXPIRES", daemon->dhcp_buff2, &err);
#endif #endif
if (domain) my_setenv("DNSMASQ_DOMAIN", domain, &err);
my_setenv("DNSMASQ_DOMAIN", domain, &err);
end = extradata + data.ed_len; end = extradata + data.ed_len;
buf = extradata; buf = extradata;
@@ -536,8 +535,8 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
if (is6) if (is6)
buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err); buf = grab_extradata(buf, end, "DNSMASQ_RELAY_ADDRESS", &err);
else if (data.giaddr.s_addr != 0) else
my_setenv("DNSMASQ_RELAY_ADDRESS", inet_ntoa(data.giaddr), &err); my_setenv("DNSMASQ_RELAY_ADDRESS", data.giaddr.s_addr != 0 ? inet_ntoa(data.giaddr) : NULL, &err);
for (i = 0; buf; i++) for (i = 0; buf; i++)
{ {
@@ -545,21 +544,15 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err); buf = grab_extradata(buf, end, daemon->dhcp_buff2, &err);
} }
if (data.action != ACTION_DEL && data.remaining_time != 0) sprintf(daemon->dhcp_buff2, "%u", data.remaining_time);
{ my_setenv("DNSMASQ_TIME_REMAINING", data.action != ACTION_DEL && data.remaining_time != 0 ? daemon->dhcp_buff2 : NULL, &err);
sprintf(daemon->dhcp_buff2, "%u", data.remaining_time);
my_setenv("DNSMASQ_TIME_REMAINING", daemon->dhcp_buff2, &err);
}
if (data.action == ACTION_OLD_HOSTNAME && hostname) my_setenv("DNSMASQ_OLD_HOSTNAME", data.action == ACTION_OLD_HOSTNAME ? hostname : NULL, &err);
{ if (data.action == ACTION_OLD_HOSTNAME)
my_setenv("DNSMASQ_OLD_HOSTNAME", hostname, &err); hostname = NULL;
hostname = NULL;
}
} }
if (option_bool(OPT_LOG_OPTS)) my_setenv("DNSMASQ_LOG_DHCP", option_bool(OPT_LOG_OPTS) ? "1" : NULL, &err);
my_setenv("DNSMASQ_LOG_DHCP", "1", &err);
/* we need to have the event_fd around if exec fails */ /* we need to have the event_fd around if exec fails */
if ((i = fcntl(event_fd, F_GETFD)) != -1) if ((i = fcntl(event_fd, F_GETFD)) != -1)
@@ -583,31 +576,44 @@ int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd)
static void my_setenv(const char *name, const char *value, int *error) static void my_setenv(const char *name, const char *value, int *error)
{ {
if (*error == 0 && setenv(name, value, 1) != 0) if (*error == 0)
*error = errno; {
if (!value)
unsetenv(name);
else if (setenv(name, value, 1) != 0)
*error = errno;
}
} }
static unsigned char *grab_extradata(unsigned char *buf, unsigned char *end, char *env, int *err) static unsigned char *grab_extradata(unsigned char *buf, unsigned char *end, char *env, int *err)
{ {
unsigned char *next; unsigned char *next = NULL;
char *val = NULL;
if (!buf || (buf == end)) if (buf && (buf != end))
return NULL;
for (next = buf; *next != 0; next++)
if (next == end)
return NULL;
if (next != buf)
{ {
char *p; for (next = buf; ; next++)
/* No "=" in value */ if (next == end)
if ((p = strchr((char *)buf, '='))) {
*p = 0; next = NULL;
my_setenv(env, (char *)buf, err); break;
}
else if (*next == 0)
break;
if (next && (next != buf))
{
char *p;
/* No "=" in value */
if ((p = strchr((char *)buf, '=')))
*p = 0;
val = (char *)buf;
}
} }
return next + 1; my_setenv(env, val, err);
return next ? next + 1 : NULL;
} }
#ifdef HAVE_LUASCRIPT #ifdef HAVE_LUASCRIPT
@@ -739,13 +745,13 @@ void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer)
buf->action = ACTION_TFTP; buf->action = ACTION_TFTP;
buf->hostname_len = filename_len; buf->hostname_len = filename_len;
buf->hwaddr_len = file_len; buf->file_len = file_len;
if ((buf->flags = peer->sa.sa_family) == AF_INET) if ((buf->flags = peer->sa.sa_family) == AF_INET)
buf->addr = peer->in.sin_addr; buf->addr = peer->in.sin_addr;
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
else else
memcpy(buf->hwaddr, &peer->in6.sin6_addr, IN6ADDRSZ); buf->addr6 = peer->in6.sin6_addr;
#endif #endif
memcpy((unsigned char *)(buf+1), filename, filename_len); memcpy((unsigned char *)(buf+1), filename, filename_len);
+5
View File
@@ -788,6 +788,7 @@ void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
#endif #endif
(void)force; (void)force;
(void)now;
if (hw_len != lease->hwaddr_len || if (hw_len != lease->hwaddr_len ||
hw_type != lease->hwaddr_type || hw_type != lease->hwaddr_type ||
@@ -956,6 +957,8 @@ void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth, char *do
void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now) void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now)
{ {
(void)now;
if (lease->last_interface == interface) if (lease->last_interface == interface)
return; return;
@@ -984,6 +987,8 @@ int do_script_run(time_t now)
{ {
struct dhcp_lease *lease; struct dhcp_lease *lease;
(void)now;
#ifdef HAVE_DBUS #ifdef HAVE_DBUS
/* If we're going to be sending DBus signals, but the connection is not yet up, /* If we're going to be sending DBus signals, but the connection is not yet up,
delay everything until it is. */ delay everything until it is. */
+2
View File
@@ -402,6 +402,8 @@ static int nl_async(struct nlmsghdr *h)
static void nl_newaddress(time_t now) static void nl_newaddress(time_t now)
{ {
(void)now;
if (option_bool(OPT_CLEVERBIND) || daemon->doing_dhcp6 || daemon->relay6 || daemon->doing_ra) if (option_bool(OPT_CLEVERBIND) || daemon->doing_dhcp6 || daemon->relay6 || daemon->doing_ra)
enumerate_interfaces(0); enumerate_interfaces(0);
+2
View File
@@ -709,6 +709,8 @@ static struct listener *create_listeners(union mysockaddr *addr, int do_tftp, in
struct listener *l = NULL; struct listener *l = NULL;
int fd = -1, tcpfd = -1, tftpfd = -1; int fd = -1, tcpfd = -1, tftpfd = -1;
(void)do_tftp;
if (daemon->port != 0) if (daemon->port != 0)
{ {
fd = make_sock(addr, SOCK_DGRAM, dienow); fd = make_sock(addr, SOCK_DGRAM, dienow);
+14
View File
@@ -134,6 +134,7 @@ struct myoption {
#endif #endif
#define LOPT_FAST_RA 322 #define LOPT_FAST_RA 322
#define LOPT_RELAY 323 #define LOPT_RELAY 323
#define LOPT_ADD_SBNET 324
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
static const struct option opts[] = static const struct option opts[] =
@@ -251,6 +252,7 @@ static const struct myoption opts[] =
{ "dhcp-generate-names", 2, 0, LOPT_GEN_NAMES }, { "dhcp-generate-names", 2, 0, LOPT_GEN_NAMES },
{ "rebind-localhost-ok", 0, 0, LOPT_LOC_REBND }, { "rebind-localhost-ok", 0, 0, LOPT_LOC_REBND },
{ "add-mac", 0, 0, LOPT_ADD_MAC }, { "add-mac", 0, 0, LOPT_ADD_MAC },
{ "add-subnet", 2, 0, LOPT_ADD_SBNET },
{ "proxy-dnssec", 0, 0, LOPT_DNSSEC }, { "proxy-dnssec", 0, 0, LOPT_DNSSEC },
{ "dhcp-sequential-ip", 0, 0, LOPT_INCR_ADDR }, { "dhcp-sequential-ip", 0, 0, LOPT_INCR_ADDR },
{ "conntrack", 0, 0, LOPT_CONNTRACK }, { "conntrack", 0, 0, LOPT_CONNTRACK },
@@ -397,6 +399,7 @@ static struct {
{ LOPT_PXE_SERV, ARG_DUP, "<service>", gettext_noop("Boot service for PXE menu."), NULL }, { LOPT_PXE_SERV, ARG_DUP, "<service>", gettext_noop("Boot service for PXE menu."), NULL },
{ LOPT_TEST, 0, NULL, gettext_noop("Check configuration syntax."), NULL }, { LOPT_TEST, 0, NULL, gettext_noop("Check configuration syntax."), NULL },
{ LOPT_ADD_MAC, OPT_ADD_MAC, NULL, gettext_noop("Add requestor's MAC address to forwarded DNS queries."), NULL }, { LOPT_ADD_MAC, OPT_ADD_MAC, NULL, gettext_noop("Add requestor's MAC address to forwarded DNS queries."), NULL },
{ LOPT_ADD_SBNET, ARG_ONE, "<v4 pref>[,<v6 pref>]", gettext_noop("Add requestor's IP subnet to forwarded DNS queries."), NULL },
{ LOPT_DNSSEC, OPT_DNSSEC, NULL, gettext_noop("Proxy DNSSEC validation results from upstream nameservers."), NULL }, { LOPT_DNSSEC, OPT_DNSSEC, NULL, gettext_noop("Proxy DNSSEC validation results from upstream nameservers."), NULL },
{ LOPT_INCR_ADDR, OPT_CONSEC_ADDR, NULL, gettext_noop("Attempt to allocate sequential IP addresses to DHCP clients."), NULL }, { LOPT_INCR_ADDR, OPT_CONSEC_ADDR, NULL, gettext_noop("Attempt to allocate sequential IP addresses to DHCP clients."), NULL },
{ LOPT_CONNTRACK, OPT_CONNTRACK, NULL, gettext_noop("Copy connection-track mark from queries to upstream connections."), NULL }, { LOPT_CONNTRACK, OPT_CONNTRACK, NULL, gettext_noop("Copy connection-track mark from queries to upstream connections."), NULL },
@@ -1424,6 +1427,17 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
break; break;
} }
case LOPT_ADD_SBNET: /* --add-subnet */
set_option_bool(OPT_CLIENT_SUBNET);
if (arg)
{
comma = split(arg);
if (!atoi_check(arg, &daemon->addr4_netmask) ||
(comma && !atoi_check(comma, &daemon->addr6_netmask)))
ret_err(gen_err);
}
break;
case '1': /* --enable-dbus */ case '1': /* --enable-dbus */
set_option_bool(OPT_DBUS); set_option_bool(OPT_DBUS);
if (arg) if (arg)
+6 -3
View File
@@ -391,10 +391,13 @@ static void send_ra(time_t now, int iface, char *iface_name, struct in6_addr *de
addr.sin6_scope_id = iface; addr.sin6_scope_id = iface;
} }
else else
inet_pton(AF_INET6, ALL_NODES, &addr.sin6_addr); {
inet_pton(AF_INET6, ALL_NODES, &addr.sin6_addr);
setsockopt(daemon->icmp6fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &iface, sizeof(iface));
}
send_from(daemon->icmp6fd, 0, daemon->outpacket.iov_base, save_counter(0), while (sendto(daemon->icmp6fd, daemon->outpacket.iov_base, save_counter(0), 0,
(union mysockaddr *)&addr, (struct all_addr *)&parm.link_local, iface); (struct sockaddr *)&addr, sizeof(addr)) == -1 && retry_send());
} }
+165 -64
View File
@@ -514,13 +514,79 @@ struct macparm {
union mysockaddr *l3; union mysockaddr *l3;
}; };
static size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *limit,
int optno, unsigned char *opt, size_t optlen)
{
unsigned char *lenp, *datap, *p;
int rdlen;
if (ntohs(header->arcount) == 0)
{
/* We are adding the pseudoheader */
if (!(p = skip_questions(header, plen)) ||
!(p = skip_section(p,
ntohs(header->ancount) + ntohs(header->nscount),
header, plen)))
return plen;
*p++ = 0; /* empty name */
PUTSHORT(T_OPT, p);
PUTSHORT(daemon->edns_pktsz, p); /* max packet length */
PUTLONG(0, p); /* extended RCODE */
lenp = p;
PUTSHORT(0, p); /* RDLEN */
rdlen = 0;
if (((ssize_t)optlen) > (limit - (p + 4)))
return plen; /* Too big */
header->arcount = htons(1);
datap = p;
}
else
{
int i, is_sign;
unsigned short code, len;
if (ntohs(header->arcount) != 1 ||
!(p = find_pseudoheader(header, plen, NULL, NULL, &is_sign)) ||
is_sign ||
(!(p = skip_name(p, header, plen, 10))))
return plen;
p += 8; /* skip UDP length and RCODE */
lenp = p;
GETSHORT(rdlen, p);
if (!CHECK_LEN(header, p, plen, rdlen))
return plen; /* bad packet */
datap = p;
/* check if option already there */
for (i = 0; i + 4 < rdlen; i += len + 4)
{
GETSHORT(code, p);
GETSHORT(len, p);
if (code == optno)
return plen;
p += len;
}
if (((ssize_t)optlen) > (limit - (p + 4)))
return plen; /* Too big */
}
PUTSHORT(optno, p);
PUTSHORT(optlen, p);
memcpy(p, opt, optlen);
p += optlen;
PUTSHORT(p - datap, lenp);
return p - (unsigned char *)header;
}
static int filter_mac(int family, char *addrp, char *mac, size_t maclen, void *parmv) static int filter_mac(int family, char *addrp, char *mac, size_t maclen, void *parmv)
{ {
struct macparm *parm = parmv; struct macparm *parm = parmv;
int match = 0; int match = 0;
unsigned short rdlen;
struct dns_header *header = parm->header;
unsigned char *lenp, *datap, *p;
if (family == parm->l3->sa.sa_family) if (family == parm->l3->sa.sa_family)
{ {
@@ -536,71 +602,11 @@ static int filter_mac(int family, char *addrp, char *mac, size_t maclen, void *p
if (!match) if (!match)
return 1; /* continue */ return 1; /* continue */
if (ntohs(header->arcount) == 0) parm->plen = add_pseudoheader(parm->header, parm->plen, parm->limit, EDNS0_OPTION_MAC, (unsigned char *)mac, maclen);
{
/* We are adding the pseudoheader */
if (!(p = skip_questions(header, parm->plen)) ||
!(p = skip_section(p,
ntohs(header->ancount) + ntohs(header->nscount),
header, parm->plen)))
return 0;
*p++ = 0; /* empty name */
PUTSHORT(T_OPT, p);
PUTSHORT(PACKETSZ, p); /* max packet length - is 512 suitable default for non-EDNS0 resolvers? */
PUTLONG(0, p); /* extended RCODE */
lenp = p;
PUTSHORT(0, p); /* RDLEN */
rdlen = 0;
if (((ssize_t)maclen) > (parm->limit - (p + 4)))
return 0; /* Too big */
header->arcount = htons(1);
datap = p;
}
else
{
int i, is_sign;
unsigned short code, len;
if (ntohs(header->arcount) != 1 ||
!(p = find_pseudoheader(header, parm->plen, NULL, NULL, &is_sign)) ||
is_sign ||
(!(p = skip_name(p, header, parm->plen, 10))))
return 0;
p += 8; /* skip UDP length and RCODE */
lenp = p;
GETSHORT(rdlen, p);
if (!CHECK_LEN(header, p, parm->plen, rdlen))
return 0; /* bad packet */
datap = p;
/* check if option already there */
for (i = 0; i + 4 < rdlen; i += len + 4)
{
GETSHORT(code, p);
GETSHORT(len, p);
if (code == EDNS0_OPTION_MAC)
return 0;
p += len;
}
if (((ssize_t)maclen) > (parm->limit - (p + 4)))
return 0; /* Too big */
}
PUTSHORT(EDNS0_OPTION_MAC, p);
PUTSHORT(maclen, p);
memcpy(p, mac, maclen);
p += maclen;
PUTSHORT(p - datap, lenp);
parm->plen = p - (unsigned char *)header;
return 0; /* done */ return 0; /* done */
} }
size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3) size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3)
{ {
struct macparm parm; struct macparm parm;
@@ -621,6 +627,101 @@ size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysock
return parm.plen; return parm.plen;
} }
struct subnet_opt {
u16 family;
u8 source_netmask, scope_netmask;
#ifdef HAVE_IPV6
u8 addr[IN6ADDRSZ];
#else
u8 addr[INADDRSZ];
#endif
};
size_t calc_subnet_opt(struct subnet_opt *opt, union mysockaddr *source)
{
/* http://tools.ietf.org/html/draft-vandergaast-edns-client-subnet-02 */
int len;
void *addrp;
if (source->sa.sa_family == AF_INET)
{
opt->family = htons(1);
opt->source_netmask = daemon->addr4_netmask;
addrp = &source->in.sin_addr;
}
#ifdef HAVE_IPV6
else
{
opt->family = htons(2);
opt->source_netmask = daemon->addr6_netmask;
addrp = &source->in6.sin6_addr;
}
#endif
opt->scope_netmask = 0;
len = 0;
if (opt->source_netmask != 0)
{
len = ((opt->source_netmask - 1) >> 3) + 1;
memcpy(opt->addr, addrp, len);
if (opt->source_netmask & 7)
opt->addr[len-1] &= 0xff << (8 - (opt->source_netmask & 7));
}
return len + 4;
}
size_t add_source_addr(struct dns_header *header, size_t plen, char *limit, union mysockaddr *source)
{
/* http://tools.ietf.org/html/draft-vandergaast-edns-client-subnet-02 */
int len;
struct subnet_opt opt;
len = calc_subnet_opt(&opt, source);
return add_pseudoheader(header, plen, (unsigned char *)limit, EDNS0_OPTION_CLIENT_SUBNET, (unsigned char *)&opt, len);
}
int check_source(struct dns_header *header, size_t plen, unsigned char *pseudoheader, union mysockaddr *peer)
{
/* Section 9.2, Check that subnet option in reply matches. */
int len, calc_len;
struct subnet_opt opt;
unsigned char *p;
int code, i, rdlen;
calc_len = calc_subnet_opt(&opt, peer);
if (!(p = skip_name(pseudoheader, header, plen, 10)))
return 1;
p += 8; /* skip UDP length and RCODE */
GETSHORT(rdlen, p);
if (!CHECK_LEN(header, p, plen, rdlen))
return 1; /* bad packet */
/* check if option there */
for (i = 0; i + 4 < rdlen; i += len + 4)
{
GETSHORT(code, p);
GETSHORT(len, p);
if (code == EDNS0_OPTION_CLIENT_SUBNET)
{
/* make sure this doesn't mismatch. */
opt.scope_netmask = p[3];
if (len != calc_len || memcmp(p, &opt, len) != 0)
return 0;
}
p += len;
}
return 1;
}
/* is addr in the non-globally-routed IP space? */ /* is addr in the non-globally-routed IP space? */
static int private_net(struct in_addr addr, int ban_localhost) static int private_net(struct in_addr addr, int ban_localhost)
+267 -266
View File
File diff suppressed because it is too large. Load diff