[OpenWrt-Devel] [EXPERIMENTAL] [PATCH] package/network/services/odhcpd: Allow per-interface leasefiles to work with multiple instance dnsmasq

openwrt at daniel.thecshore.com openwrt at daniel.thecshore.com
Tue Feb 16 05:40:46 EST 2016


From: Daniel Dickinson <openwrt at daniel.thecshore.com>

When using multiple instance dnsmasq different instances can use different hosts files
and have different domains.  To make this work with odhcpd we modify odhcpd to support
per-interface leasefiles so that the host files generated from dhcpdv6 can be associated
with the appropriate dnsmasq instance.

This patch has only been compile not verified in operation at this time.  It is
for the previous dnsmaq patch series I submitted and will allow me to reintroduce
ipv6 in my network (ipv6 caused issues because I have some multi-homed hosts for
which it matters which interface you arrive on but localise_queries doesn't work
with dnsmasq on ipv6 (known limitation of dnsmasq); by allowing to have
multiple-instance dnsmasq and per-interface odhcpd leasefiles it becomes possible
to serve different DNS to different interfaces and still have DNS-from-DHCP work.

Signed-off-by: Daniel Dickinson <openwrt at daniel.thecshore.com>
---
 .../odhcpd/patches/100-enable-separated-dns.patch  | 116 +++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 package/network/services/odhcpd/patches/100-enable-separated-dns.patch

diff --git a/package/network/services/odhcpd/patches/100-enable-separated-dns.patch b/package/network/services/odhcpd/patches/100-enable-separated-dns.patch
new file mode 100644
index 0000000..8bdb500
--- /dev/null
+++ b/package/network/services/odhcpd/patches/100-enable-separated-dns.patch
@@ -0,0 +1,116 @@
+Index: odhcpd-2015-11-19/src/config.c
+===================================================================
+--- odhcpd-2015-11-19.orig/src/config.c
++++ odhcpd-2015-11-19/src/config.c
+@@ -22,6 +22,7 @@ enum {
+ 	IFACE_ATTR_DYNAMICDHCP,
+ 	IFACE_ATTR_IGNORE,
+ 	IFACE_ATTR_LEASETIME,
++	IFACE_ATTR_LEASEFILE,
+ 	IFACE_ATTR_LIMIT,
+ 	IFACE_ATTR_START,
+ 	IFACE_ATTR_MASTER,
+@@ -55,6 +56,7 @@ static const struct blobmsg_policy iface
+ 	[IFACE_ATTR_DYNAMICDHCP] = { .name = "dynamicdhcp", .type = BLOBMSG_TYPE_BOOL },
+ 	[IFACE_ATTR_IGNORE] = { .name = "ignore", .type = BLOBMSG_TYPE_BOOL },
+ 	[IFACE_ATTR_LEASETIME] = { .name = "leasetime", .type = BLOBMSG_TYPE_STRING },
++	[IFACE_ATTR_LEASEFILE] = { .name = "leasefile", .type = BLOBMSG_TYPE_STRING },
+ 	[IFACE_ATTR_START] = { .name = "start", .type = BLOBMSG_TYPE_INT32 },
+ 	[IFACE_ATTR_LIMIT] = { .name = "limit", .type = BLOBMSG_TYPE_INT32 },
+ 	[IFACE_ATTR_MASTER] = { .name = "master", .type = BLOBMSG_TYPE_BOOL },
+@@ -351,6 +353,9 @@ int config_parse_interface(void *data, s
+ 			iface->dhcpv4_leasetime = time;
+ 	}
+ 
++	if (tb[IFACE_ATTR_LEASEFILE])
++		iface->leasefile = blobmsg_get_string(tb[IFACE_ATTR_LEASEFILE]);
++
+ 	if ((c = tb[IFACE_ATTR_START])) {
+ 		iface->dhcpv4_start.s_addr = htonl(blobmsg_get_u32(c));
+ 
+Index: odhcpd-2015-11-19/src/dhcpv6-ia.c
+===================================================================
+--- odhcpd-2015-11-19.orig/src/dhcpv6-ia.c
++++ odhcpd-2015-11-19/src/dhcpv6-ia.c
+@@ -202,6 +202,20 @@ static int send_reconf(struct interface
+ 	return odhcpd_send(iface->dhcpv6_event.uloop.fd, &assign->peer, &iov, 1, iface);
+ }
+ 
++FILE *dhcpv6_open_statefile(char *statefile) {
++	int fd = open(statefile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
++	if (fd < 0)
++		return NULL;
++
++	lockf(fd, F_LOCK, 0);
++	if (ftruncate(fd, 0) < 0) {}
++
++	FILE *fp = fdopen(fd, "w");
++	if (!fp)
++		close(fd);
++	return fp;
++}
++
+ 
+ void dhcpv6_write_statefile(void)
+ {
+@@ -210,21 +224,24 @@ void dhcpv6_write_statefile(void)
+ 
+ 	if (config.dhcp_statefile) {
+ 		time_t now = odhcpd_time(), wall_time = time(NULL);
+-		int fd = open(config.dhcp_statefile, O_CREAT | O_WRONLY | O_CLOEXEC, 0644);
+-		if (fd < 0)
+-			return;
+-
+-		lockf(fd, F_LOCK, 0);
+-		if (ftruncate(fd, 0) < 0) {}
+ 
+-		FILE *fp = fdopen(fd, "w");
+-		if (!fp) {
+-			close(fd);
++		FILE *lp = dhcpv6_open_statefile(config.dhcp_statefile);
++		if (!lp) {
+ 			return;
+ 		}
+ 
+ 		struct interface *iface;
+ 		list_for_each_entry(iface, &interfaces, head) {
++			FILE *fp;
++
++			if (iface->leasefile) {
++				fp = dhcpv6_open_statefile(iface->leasefile);
++				if (!fp) {
++					continue;
++				}
++			} else {
++				fp = lp;
++			}
+ 			if (iface->dhcpv6 != RELAYD_SERVER && iface->dhcpv4 != RELAYD_SERVER)
+ 				continue;
+ 
+@@ -330,9 +347,13 @@ void dhcpv6_write_statefile(void)
+ 					fwrite(leasebuf, 1, l, fp);
+ 				}
+ 			}
++			if (lp != fp) {
++				fclose(fp);
++				fp = NULL;
++			}
+ 		}
+ 
+-		fclose(fp);
++		fclose(lp);
+ 	}
+ 
+ 	uint8_t newmd5[16];
+Index: odhcpd-2015-11-19/src/odhcpd.h
+===================================================================
+--- odhcpd-2015-11-19.orig/src/odhcpd.h
++++ odhcpd-2015-11-19/src/odhcpd.h
+@@ -139,6 +139,7 @@ struct interface {
+ 	bool ra_not_onlink;
+ 	bool ra_advrouter;
+ 	bool no_dynamic_dhcp;
++	char *leasefile;
+ 
+ 	int learn_routes;
+ 	int default_router;
-- 
2.4.3
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list