summaryrefslogtreecommitdiff
path: root/src/basic/in-addr-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-01-31 19:26:51 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-02-01 11:30:37 +0900
commitb69bfa43052586cd6894c32d7d3d447195539ec5 (patch)
treeddee51c4d9b080e766237c999373072a3d429a7c /src/basic/in-addr-util.c
parent259c65f36c02a740ba2fa2791c421dada4db441c (diff)
downloadsystemd-b69bfa43052586cd6894c32d7d3d447195539ec5.tar.gz
network: do not remove localhost address
Managing loopback interfaces by networkd is not recommended, but supporeted. Even such spurious situation, do not drop the localhost addresses.
Diffstat (limited to 'src/basic/in-addr-util.c')
-rw-r--r--src/basic/in-addr-util.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c
index a43a831991..660c1f1824 100644
--- a/src/basic/in-addr-util.c
+++ b/src/basic/in-addr-util.c
@@ -121,6 +121,19 @@ int in_addr_is_localhost(int family, const union in_addr_union *u) {
return -EAFNOSUPPORT;
}
+int in_addr_is_localhost_one(int family, const union in_addr_union *u) {
+ assert(u);
+
+ if (family == AF_INET)
+ /* 127.0.0.1 */
+ return be32toh(u->in.s_addr) == UINT32_C(0x7F000001);
+
+ if (family == AF_INET6)
+ return IN6_IS_ADDR_LOOPBACK(&u->in6); /* lgtm [cpp/potentially-dangerous-function] */
+
+ return -EAFNOSUPPORT;
+}
+
bool in6_addr_is_ipv4_mapped_address(const struct in6_addr *a) {
return a->s6_addr32[0] == 0 &&
a->s6_addr32[1] == 0 &&