getdata: flip ranges if they are in greater smaller order

Apparently ISC dhcpd allows marking ranges in order from greater IP to
smaller.  In these cases first and last IPs are fliped, so that the rest of
the processing can be done without alterations.

Reported-by: Ivanov Ivan <mgfnv9@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2016-02-18 22:35:56 +00:00
parent 3d0c510475
commit 10b06d88f0
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
2 changed files with 15 additions and 0 deletions

1
THANKS
View file

@ -37,3 +37,4 @@ Tim Cantin
Martijn van Brummelen
Anton Tkachev
Derrick Lin
Ivanov Ivan

View file

@ -163,6 +163,19 @@ static int is_interesting_config_clause(char const *restrict s)
return ITS_NOTHING_INTERESTING;
}
/*! \brief Flip first and last IP in range if they are in unusual order.
*/
void reorder_last_first(struct range_t *range_p)
{
if (ipcomp(&range_p->first_ip, &range_p->last_ip) > 0) {
union ipaddr_t tmp;
tmp = range_p->first_ip;
range_p->first_ip = range_p->last_ip;
range_p->last_ip = tmp;
}
}
/*! \brief The dhcpd.conf file parser.
* FIXME: This spaghetti monster function need to be rewrote at least
* ones.
@ -334,6 +347,7 @@ void parse_config(int is_include, const char *restrict config_file,
copy_ipaddr(&range_p->first_ip, &addr);
}
copy_ipaddr(&range_p->last_ip, &addr);
reorder_last_first(range_p);
newrange:
range_p->count = 0;
range_p->touched = 0;