[Dnsmasq-discuss] Re: negated network-ids (Re: dhcp: mac address as "range selector"?)

Simon Kelley simon at thekelleys.org.uk
Sat Feb 18 16:17:42 GMT 2006


Lutz Pressler wrote:
> Hello again,
> 
> I wrote:
> 
>>I read that, tested - and then interpreted "#" as being only relevant
>>in dhcp-option (btw, there is a typo --dhcp=option=#purple...).
>>I have not tried dhcp-boot and dhcp-ignore, but
>>
>>>dhcp-range=net:#tel,192.168.169.80,192.168.169.99,255.255.255.0,12h
>>
>>has the consequence that tel devices don't get those addresses -
>>but non-tel (no network-id) ones don't either (like # is interpreted
>>literally). 
>>
> The problem only occurs when the requesting device has no network-id
> at all associated. Debugging shows that then match_netid is not
> called at all.
> dhcp.c:address_allocate is incorrect, I think.
> 
>   for (c = context; c; c = c->current)
>     if (c->flags & CONTEXT_STATIC)
>       continue;
>     else if (netids && !(c->flags & CONTEXT_FILTER))
>       continue;
>     else if (!netids && (c->flags & CONTEXT_FILTER))
>       continue;
>     else if (netids && (c->flags & CONTEXT_FILTER) && !match_netid(&c->netid, netids))
>       continue;
>     else
> ...
> 
> Why is !netids and netids differentiated in the case of CONTEXT_FILTER set?
> Maybe this can simply be changed to
> 
>   for (c = context; c; c = c->current)
>     if (c->flags & CONTEXT_STATIC)
>       continue;
>     else if (netids && !(c->flags & CONTEXT_FILTER))
>       continue;
>     else if ((c->flags & CONTEXT_FILTER) && !match_netid(&c->netid, netids))
>       continue;
>     else
> ...
> 
> ? The logic within match_netid seems to be correct - and a first test
> worked out fine for me.
> 

It took me head-scratching to understand this, and I wrote it! A perfect
example of why it's impossible to have too many comments.

The behaviour is fine for the case it was originally written for, a
combination of tagged and non-tagged dhcp-ranges (context)

The logic is:

	If (tag set)
	    attempt to allocate address in tagged range
            if (failed)
	        allocate address in non-tagged range.
        else
            allocate address in non-tagged range.

Note the code at the bottom of the routine, where it calls itself again
without a tag if it fails to get an address when it has a tag.

This is broken for NOT-tag, which was added later, with match_netid
updated, but not this code.

the logic should be
        If (tag not set ||
	    failure of attempt to allocate address in range where all
            positive tags match and no negative tags match
  	then
            allocate address in range with no postive tags and no
            matching negtive tags.

the existing code only looks for matches in untagged ranges, and ignores
matches in negative-tagged ranges where the tags don't match.

I've sent you private mail with updated code, please let me know if that
works for you.


Cheers,

Simon.




More information about the Dnsmasq-discuss mailing list