Re: [Dnsmasq-discuss] [PATCH] Allow specifying a 0.0.0.0 netmask in dhcp-range for relays.

2018-03-12 Thread Yuki Nisiwaki
Hello Nicolas

I missed this point.Thanks.
> dhcp-option=option:netmask,255.255.0.0 anyway.

But as you already mentioned, still I have to specify at least 2 dhcp-range
with /1 to cover all subnets since dnsmasq doesn't consider netmask 0 we
intentionally specified.
your patch seems good to me. I hope your patch will be in upstream before
long.

Yuki Nishiwaki


On 12 March 2018 at 18:26, Nicolas Cavallari <
nicolas.cavall...@green-communications.fr> wrote:

> When using a DHCP relay, the netmask in dhcp-range is matched against
> giaddr (or the link selection suboption) to determine on which range the
> address should be allocated.
>
> However, in some cases, you want to ignore this mechanism, because your
> relay, clients and your DHCP server are not in the same subnet, the
> relay do not have addresses on their client interfaces and/or you have
> more complicated matching in place (e.g.  other relay agent information
> suboptions).
>
> The link selection suboption would be a good candidate but this requires
> a duplicate policy/configuration in every relay that matches what the
> DHCP server would select.
>
> Specifying 0.0.0.0 as a netmask is accepted by the parser but is
> rejected by a condition in rfc2131.c, that only checks if
> netmask.s_addr = 0, which can happen if the guessing failed, but can
> also happen if 0.0.0.0 was explicitly specified.
>
> This fixes the condition so that netmask.s_addr = 0 is acceptable
> if it was specified in the configuration.  i.e.  if the
> dhcp context (the considered dhcp range) has the CONTEXT_NETMASK
> flag.
>
> The netmask to be sent to the client can be set with
> dhcp-option=option:netmask,255.255.0.0 anyway.
> ---
> Yuki Nisiwaki's message reminded me of this patch that I use but forgot
> about.
>
>  src/rfc2131.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/rfc2131.c b/src/rfc2131.c
> index c08a8ab..6b2df35 100644
> --- a/src/rfc2131.c
> +++ b/src/rfc2131.c
> @@ -319,7 +319,7 @@ size_t dhcp_reply(struct dhcp_context *context, char
> *iface_name, int int_index,
>
> /* This section fills in context mainly when a client which is
> on a remote (relayed)
>network renews a lease without using the relay, after
> dnsmasq has restarted. */
> -   if (netmask.s_addr != 0  &&
> +   if ((netmask.s_addr != 0 || context_tmp->flags &
> CONTEXT_NETMASK) &&
> is_same_net(addr, context_tmp->start, netmask) &&
> is_same_net(addr, context_tmp->end, netmask))
>   {
> --
> 2.16.2
>
>
> ___
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss@lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
>
___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


[Dnsmasq-discuss] [PATCH] Allow specifying a 0.0.0.0 netmask in dhcp-range for relays.

2018-03-12 Thread Nicolas Cavallari
When using a DHCP relay, the netmask in dhcp-range is matched against
giaddr (or the link selection suboption) to determine on which range the
address should be allocated.

However, in some cases, you want to ignore this mechanism, because your
relay, clients and your DHCP server are not in the same subnet, the
relay do not have addresses on their client interfaces and/or you have
more complicated matching in place (e.g.  other relay agent information
suboptions).

The link selection suboption would be a good candidate but this requires
a duplicate policy/configuration in every relay that matches what the
DHCP server would select.

Specifying 0.0.0.0 as a netmask is accepted by the parser but is
rejected by a condition in rfc2131.c, that only checks if
netmask.s_addr = 0, which can happen if the guessing failed, but can
also happen if 0.0.0.0 was explicitly specified.

This fixes the condition so that netmask.s_addr = 0 is acceptable
if it was specified in the configuration.  i.e.  if the
dhcp context (the considered dhcp range) has the CONTEXT_NETMASK
flag.

The netmask to be sent to the client can be set with
dhcp-option=option:netmask,255.255.0.0 anyway.
---
Yuki Nisiwaki's message reminded me of this patch that I use but forgot
about.

 src/rfc2131.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/rfc2131.c b/src/rfc2131.c
index c08a8ab..6b2df35 100644
--- a/src/rfc2131.c
+++ b/src/rfc2131.c
@@ -319,7 +319,7 @@ size_t dhcp_reply(struct dhcp_context *context, char 
*iface_name, int int_index,

/* This section fills in context mainly when a client which is on a 
remote (relayed)
   network renews a lease without using the relay, after dnsmasq 
has restarted. */
-   if (netmask.s_addr != 0  && 
+   if ((netmask.s_addr != 0 || context_tmp->flags & CONTEXT_NETMASK) &&
is_same_net(addr, context_tmp->start, netmask) &&
is_same_net(addr, context_tmp->end, netmask))
  {
-- 
2.16.2


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss