Skip to content

Commit

Permalink
Add a comment regarding the fix for "0.0.0.0/0" subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico Schiattarella committed Jan 23, 2017
1 parent 5e2c2b1 commit becb250
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/common/network/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ IpWhiteList::IpWhiteList(const Json::Object& config) {
throw EnvoyException(
fmt::format("invalid ipv4/mask combo '{}' (mask bits must be <= 32)", entry));
}
// "0.0.0.0/0" is a valid subnet that contains all possible IPv4 addresses, so mask can be equal to 0

Ipv4Entry white_list_entry;
white_list_entry.ipv4_address_ = ntohl(addr.s_addr);
// The 1ULL below makes sure that the RHS is computed as a 64-bit value, so that we do not over-shift
// to the left when mask = 0. The assignment to ipv4_mask_ then truncates the value back to 32 bits.
white_list_entry.ipv4_mask_ = ~((1ULL << (32 - mask)) - 1);

// Check to make sure applying the mask to the address equals the address. This can prevent
Expand Down

0 comments on commit becb250

Please sign in to comment.