Add command line argument to disable DHCP options parsing
authorAlejandro Enrique <alejandro.enrique@fon.com>
Tue, 17 Feb 2015 11:06:30 +0000 (12:06 +0100)
committerJohn Crispin <blogic@openwrt.org>
Thu, 12 Mar 2015 23:23:14 +0000 (00:23 +0100)
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>
dhcp.c
main.c
relayd.h

diff --git a/dhcp.c b/dhcp.c
index 5f7744ac02ae34c80e39e19b3046fcf1f283d24d..aefe34fd80e6c5ab8fe5bc19581e12954e0e782a 100644 (file)
--- 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 24435b49b459e0de7e97365ad5088de6944f0583..edd10b8b064f26fc0d6e175de09f5617d24d5cac 100644 (file)
--- 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)
index ff30b67f7822a5201161953a6155497b09e9f37d..d7ad212edb6848cfe9fd9fe3a73f215cae7cb3c9 100644 (file)
--- 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