systemd: dhcp: move filtering of bogus DNS/NTP addresses out of DHCP client

Imported from systemd:

    The DHCP client should not pre-filter addresses beyond what RFC
    requires. If a client's user (like networkd) wishes to skip/filter
    certain addresses, it's their responsibility.

    The point of this is that the DHCP library does not hide/abstract
    information that might be relevant for certain users. For example,
    NetworkManager exposes DHCP options in its API. When doing that, the
    options should be close to the actual lease.

    This is related to commit d9ec2e632df4905201facf76d6a205edc952116a
    (dhcp4: filter bogus DNS/NTP server addresses silently).

072320eab0
This commit is contained in:
Thomas Haller
2018-12-14 16:25:01 +01:00
parent 39ac79c55d
commit 19c3d1f58b
5 changed files with 43 additions and 34 deletions

View File

@@ -70,6 +70,14 @@ bool in4_addr_is_localhost(const struct in_addr *a) {
return (be32toh(a->s_addr) & UINT32_C(0xFF000000)) == UINT32_C(127) << 24;
}
bool in4_addr_is_non_local(const struct in_addr *a) {
/* Whether the address is not null and not localhost.
*
* As such, it is suitable to configure as DNS/NTP server from DHCP. */
return !in4_addr_is_null(a) &&
!in4_addr_is_localhost(a);
}
int in_addr_is_localhost(int family, const union in_addr_union *u) {
assert(u);

View File

@@ -30,6 +30,8 @@ int in_addr_is_link_local(int family, const union in_addr_union *u);
bool in4_addr_is_localhost(const struct in_addr *a);
int in_addr_is_localhost(int family, const union in_addr_union *u);
bool in4_addr_is_non_local(const struct in_addr *a);
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b);
int in_addr_prefix_intersect(int family, const union in_addr_union *a, unsigned aprefixlen, const union in_addr_union *b, unsigned bprefixlen);
int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);