[OpenWrt-Devel] [PATCH relayd] Add command line argument to disable DHCP options parsing

Alejandro Enrique alejandro.enrique at fon.com
Tue Feb 17 06:06:30 EST 2015


Default routes added when parsing DHCP options are problematic on
setups where there are more interfaces than those being managed by
relayd. A default route on the routing table used for locally
generated traffic makes the traffic addressed to not managed local
networks to be sent out using that default route instead of being
properly routed.

Disabling DHCP options parsing prevents the introduction of a default
route, that way the traffic addressed to not managed local networks is
routed using the main routing table.

Signed-off-by: Alejandro Enrique <alejandro.enrique at fon.com>
---
 dhcp.c   |    4 ++--
 main.c   |   10 ++++++++--
 relayd.h |    2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/dhcp.c b/dhcp.c
index 5f7744a..aefe34f 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -115,7 +115,7 @@ parse_dhcp_options(struct relayd_host *host, struct dhcp_header *dhcp, int len)
 	}
 }
 
-bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int len, bool forward)
+bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int len, bool forward, bool parse)
 {
 	struct ip_packet *pkt = data;
 	struct udphdr *udp;
@@ -151,7 +151,7 @@ bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int len
 
 	if (dhcp->op == 2) {
 		host = relayd_refresh_host(rif, pkt->eth.ether_shost, (void *) &pkt->iph.saddr);
-		if (host)
+		if (host && parse)
 			parse_dhcp_options(host, dhcp, udplen - sizeof(struct udphdr));
 	}
 
diff --git a/main.c b/main.c
index 24435b4..edd10b8 100644
--- a/main.c
+++ b/main.c
@@ -40,6 +40,7 @@ static int host_ping_tries;
 static int inet_sock;
 static int forward_bcast;
 static int forward_dhcp;
+static int parse_dhcp;
 
 uint8_t local_addr[4];
 int local_route_table;
@@ -507,7 +508,7 @@ static void recv_bcast_packet(struct uloop_fd *fd, unsigned int events)
 		if (!forward_bcast && !forward_dhcp)
 			continue;
 
-		if (relayd_handle_dhcp_packet(rif, pktbuf, pktlen, forward_dhcp))
+		if (relayd_handle_dhcp_packet(rif, pktbuf, pktlen, forward_dhcp, parse_dhcp))
 			continue;
 
 		if (forward_bcast)
@@ -690,6 +691,7 @@ static int usage(const char *progname)
 			"	-T <table>	Set routing table number for automatically added routes\n"
 			"	-B		Enable broadcast forwarding\n"
 			"	-D		Enable DHCP forwarding\n"
+			"	-P		Disable DHCP options parsing\n"
 			"	-L <ipaddr>	Enable local access using <ipaddr> as source address\n"
 			"\n",
 		progname);
@@ -718,9 +720,10 @@ int main(int argc, char **argv)
 	host_ping_tries = 5;
 	forward_bcast = 0;
 	local_route_table = 0;
+	parse_dhcp = 1;
 	uloop_init();
 
-	while ((ch = getopt(argc, argv, "I:i:t:p:BDdT:G:R:L:")) != -1) {
+	while ((ch = getopt(argc, argv, "I:i:t:p:BDPdT:G:R:L:")) != -1) {
 		switch(ch) {
 		case 'I':
 			managed = true;
@@ -752,6 +755,9 @@ int main(int argc, char **argv)
 		case 'D':
 			forward_dhcp = 1;
 			break;
+		case 'P':
+			parse_dhcp = 0;
+			break;
 		case 'T':
 			route_table = atoi(optarg);
 			if (route_table <= 0)
diff --git a/relayd.h b/relayd.h
index ff30b67..d7ad212 100644
--- a/relayd.h
+++ b/relayd.h
@@ -127,6 +127,6 @@ void relayd_add_host_route(struct relayd_host *host, const uint8_t *ipaddr, uint
 void relayd_add_pending_route(const uint8_t *gateway, const uint8_t *dest, uint8_t mask, int timeout);
 
 void relayd_forward_bcast_packet(struct relayd_interface *from_rif, void *packet, int len);
-bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int len, bool forward);
+bool relayd_handle_dhcp_packet(struct relayd_interface *rif, void *data, int len, bool forward, bool parse);
 
 #endif
-- 
1.7.10.4
_______________________________________________
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