[Dnsmasq-discuss] Patch to allow router other than local machine

Jared Stafford jspenguin42 at gmail.com
Mon Dec 19 02:33:36 GMT 2005


I've got an ADSL router from 2wire that does not do proper DNS
masqerading, so I installed Dnsmasq. However, I still wanted to use the
router as the gateway. Dnsmasq did not have an option to do this, so I
created one. Right now, it just uses a global option to set the real
router address, any suggestions on how to improve it?



-------------- next part --------------
diff -U 4 dnsmasq-2.24-old/src/dhcp.c dnsmasq-2.24/src/dhcp.c
--- dnsmasq-2.24-old/src/dhcp.c	2005-12-18 20:06:51.000000000 -0600
+++ dnsmasq-2.24/src/dhcp.c	2005-12-18 19:50:33.000000000 -0600
@@ -394,9 +394,13 @@
 	    {
 	      /* link it onto the current chain if we've not seen it before */
 	      if (context->current == context)
 		{
-		  context->router = local;
+		  if (daemon->dhcp_router.s_addr) 
+		    context->router = daemon->dhcp_router;
+		  else
+		    context->router = local;
+		    
 		  context->local = local;
 		  context->current = current;
 		  current = context;
 		}
diff -U 4 dnsmasq-2.24-old/src/dnsmasq.h dnsmasq-2.24/src/dnsmasq.h
--- dnsmasq-2.24-old/src/dnsmasq.h	2005-12-18 20:06:53.000000000 -0600
+++ dnsmasq-2.24/src/dnsmasq.h	2005-12-18 19:42:03.000000000 -0600
@@ -426,8 +426,9 @@
   struct dhcp_opt *dhcp_opts, *vendor_opts;
   struct dhcp_vendor *dhcp_vendors;
   struct dhcp_boot *boot_config;
   struct dhcp_netid_list *dhcp_ignore;
+  struct in_addr dhcp_router;
   int dhcp_max; 
   unsigned int min_leasetime;
   struct doctor *doctors;
   unsigned short edns_pktsz;
diff -U 4 dnsmasq-2.24-old/src/option.c dnsmasq-2.24/src/option.c
--- dnsmasq-2.24-old/src/option.c	2005-11-23 04:11:43.000000000 -0600
+++ dnsmasq-2.24/src/option.c	2005-12-18 20:08:06.000000000 -0600
@@ -20,9 +20,9 @@
   int *flag;
   int val;
 };
 
-#define OPTSTRING "31yZDNLERKzowefnbvhdkqr:m:p:c:l:s:i:t:u:g:a:x:S:C:A:T:H:Q:I:B:F:G:O:M:X:V:U:j:P:J:W:Y:2:"
+#define OPTSTRING "31yZDNLERKzowefnbvhdkqr:m:p:c:l:s:i:t:u:g:a:x:S:C:A:T:H:Q:I:B:F:G:O:M:X:V:U:j:P:J:W:Y:2:0:"
 
 static const struct myoption opts[] = { 
   {"version", 0, 0, 'v'},
   {"no-hosts", 0, 0, 'h'},
@@ -65,8 +65,9 @@
   {"addn-hosts", 1, 0, 'H'},
   {"query-port", 1, 0, 'Q'},
   {"except-interface", 1, 0, 'I'},
   {"no-dhcp-interface", 1, 0, '2'},
+  {"router", 1, 0, '0'},
   {"domain-needed", 0, 0, 'D'},
   {"dhcp-lease-max", 1, 0, 'X' },
   {"bind-interfaces", 0, 0, 'z'},
   {"read-ethers", 0, 0, 'Z' },
@@ -1072,8 +1073,21 @@
 		  daemon->min_leasetime = new->lease_time;
 		break;
 	      }
 
+	    case '0':
+	      {
+		struct in_addr addr;
+		unhide_metas(arg);
+		if (arg && (addr.s_addr = inet_addr(arg)) != (in_addr_t)-1)
+		  {
+		    daemon->dhcp_router=addr;
+		  }
+		else
+		  option = '?'; /* error */
+		break;	
+	      }
+
 	    case 'G':
 	      {
 		int j, k;
 		char *a[6] = { NULL, NULL, NULL, NULL, NULL, NULL };




More information about the Dnsmasq-discuss mailing list