From 10b06d88f0bd5d14fb2e90fab8df8f680543c321 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Thu, 18 Feb 2016 22:35:56 +0000 Subject: [PATCH] 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 Signed-off-by: Sami Kerola --- THANKS | 1 + src/getdata.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/THANKS b/THANKS index 8c8f80b..1302c03 100644 --- a/THANKS +++ b/THANKS @@ -37,3 +37,4 @@ Tim Cantin Martijn van Brummelen Anton Tkachev Derrick Lin +Ivanov Ivan diff --git a/src/getdata.c b/src/getdata.c index 03a0b13..3e3be1f 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -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;