Skip to content

Commit

Permalink
Added check for existing addresses
Browse files Browse the repository at this point in the history
Added a check for an address before adding Single Port addresses.
This was added because in case the `DirAddress` is set BEFORE `DirPort` in the config file, the process would go on and assign an extra IPV6 address, which should not be the case. The `DirAddress` is supposed to be the only address reachable. In this case only the V4 address is setup which overall just changes the listening port.
  • Loading branch information
alaaeddineelamri committed Sep 23, 2021
1 parent abce51c commit 8282ab7
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions core/src/lib/res.cc
Expand Up @@ -1315,6 +1315,7 @@ void ConfigurationParser::StoreAddressesAddress(LEX* lc,
|| token == BCT_IDENTIFIER)) {
scan_err1(lc, _("Expected an IP number or a hostname, got: %s"), lc->str);
}

if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_SINGLE_ADDR, htons(port), AF_INET, lc->str, 0,
Expand All @@ -1338,28 +1339,45 @@ void ConfigurationParser::StoreAddressesPort(LEX* lc,
scan_err1(lc, _("Expected a port number or string, got: %s"), lc->str);
}

#ifdef HAVE_IPV6
if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_MULTIPLE, htons(port), AF_INET, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
bool has_address = false;
IPADDR* iaddr;
dlist<IPADDR>* addrs
= (dlist<IPADDR>*)(*(GetItemVariablePointer<dlist<IPADDR>**>(*item)));
foreach_dlist (iaddr, addrs) {
if (iaddr->GetType() == IPADDR::R_SINGLE) { has_address = true; }
}

if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_MULTIPLE, htons(port), AF_INET6, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
}
if (has_address) {
if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_SINGLE_PORT, htons(port), AF_INET, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
}
} else {
#ifdef HAVE_IPV6
if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_SINGLE, htons(port), AF_INET, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
}

if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_SINGLE, htons(port), AF_INET6, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
}
#else
if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_SINGLE_PORT, htons(port), AF_INET, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
}
if (pass == 1
&& !AddAddress(GetItemVariablePointer<dlist<IPADDR>**>(*item),
IPADDR::R_SINGLE_PORT, htons(port), AF_INET, 0, lc->str,
errmsg, sizeof(errmsg))) {
scan_err2(lc, _("can't add port (%s) to (%s)"), lc->str, errmsg);
}
#endif
}
}

// Generic store resource dispatcher.
Expand Down

0 comments on commit 8282ab7

Please sign in to comment.