Hi,
  here is a small patch that allows dnsmasq to assign IP addresses from subnet, that is not configured on listening interface.

Use case:
  - I've a server(s) with multiple virtual machines, with network settings configured via DHCP.   - Each VM has statically assigned private IPs from subnet range on the bridge, but some of them might have also public addresses from subnet range that is *only routed* on that bridge.   - With this patch I'm able to let dnsmasq assign this public addresses by defining a *virtual subnet*. This is not otherwise allowed, because dnsmasq is doing 'same net' checking on the incoming interface subnet and to-be-assigned IP address.

Usage is simple:

dhcp-range=wan,XXX.XXX.XXX.1,*virtual*,255.255.255.240,12h

It's a quick hack, but it works for me perfectly.

Kind regards
  Sam
diff --git a/src/dhcp.c b/src/dhcp.c
index fb2f650..b9a73d0 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -526,8 +526,9 @@ static int complete_context(struct in_addr local, int 
if_index, char *label,
       }
       
       if (context->netmask.s_addr != 0 &&
-         is_same_net(local, context->start, context->netmask) &&
-         is_same_net(local, context->end, context->netmask))
+         ((is_same_net(local, context->start, context->netmask) &&
+         is_same_net(local, context->end, context->netmask)) ||
+         context->flags & CONTEXT_VIRTUAL))
        {
          /* link it onto the current chain if we've not seen it before */
          if (if_index == param->ind && context->current == context)
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 4b55bb5..95eee82 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -872,6 +872,7 @@ struct dhcp_context {
 #define CONTEXT_OLD            (1u<<16)
 #define CONTEXT_V6             (1u<<17)
 #define CONTEXT_RA_OFF_LINK    (1u<<18)
+#define CONTEXT_VIRTUAL        (1u<<19)
 
 struct ping_result {
   struct in_addr addr;
diff --git a/src/option.c b/src/option.c
index 50d26ba..af69e0e 100644
--- a/src/option.c
+++ b/src/option.c
@@ -2775,6 +2775,8 @@ static int one_opt(int option, char *arg, char *errstr, 
char *gen_err, int comma
              new->flags |= CONTEXT_STATIC;
            else if (strcmp(a[1], "proxy") == 0)
              new->flags |= CONTEXT_PROXY;
+           else if (strcmp(a[1], "virtual") == 0)
+             new->flags |= CONTEXT_STATIC | CONTEXT_VIRTUAL;
            else if (!inet_pton(AF_INET, a[1], &new->end))
              ret_err(_("bad dhcp-range"));
            
_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

Reply via email to