Browse Source

Add command line argument to disable DHCP options parsing

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@fon.com>
Alejandro Enrique 9 years ago
parent
commit
2970ff60ba
3 changed files with 11 additions and 5 deletions
  1. 2 2
      dhcp.c
  2. 8 2
      main.c
  3. 1 1
      relayd.h

+ 2 - 2
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));
 	}
 

+ 8 - 2
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)

+ 1 - 1
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