From: Daan De Meyer Date: Tue, 29 Apr 2025 13:20:02 +0000 (+0200) Subject: basic: Add our own and headers X-Git-Tag: v258-rc1~718^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d559f463849a7f178d2fb88f1aa482a809286672;p=thirdparty%2Fsystemd.git basic: Add our own and headers These glibc headers conflicts with the corresponding linux headers ( and ) and impose an include order (the glibc one has to be included before any linux header is included). This makes sorting includes a royal pain so let's define our own versions of these headers using various linux headers to do all the work and filling in the missing bits ourselves. --- diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index f1f3a195c08..4e39985e275 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -13,6 +13,7 @@ #include "in-addr-util.h" #include "logarithm.h" #include "macro.h" +#include "memory-util.h" #include "parse-util.h" #include "random-util.h" #include "stdio-util.h" @@ -28,7 +29,7 @@ bool in4_addr_is_null(const struct in_addr *a) { bool in6_addr_is_null(const struct in6_addr *a) { assert(a); - return IN6_IS_ADDR_UNSPECIFIED(a); + return eqzero(a->in6_u.u6_addr32); } int in_addr_is_null(int family, const union in_addr_union *u) { @@ -66,7 +67,7 @@ bool in4_addr_is_link_local_dynamic(const struct in_addr *a) { bool in6_addr_is_link_local(const struct in6_addr *a) { assert(a); - return IN6_IS_ADDR_LINKLOCAL(a); + return (a->in6_u.u6_addr32[0] & htobe32(0xffc00000)) == htobe32(0xfe800000); } int in_addr_is_link_local(int family, const union in_addr_union *u) { @@ -100,7 +101,7 @@ bool in4_addr_is_multicast(const struct in_addr *a) { bool in6_addr_is_multicast(const struct in6_addr *a) { assert(a); - return IN6_IS_ADDR_MULTICAST(a); + return a->in6_u.u6_addr8[0] == 0xff; } int in_addr_is_multicast(int family, const union in_addr_union *u) { @@ -136,6 +137,10 @@ bool in4_addr_is_non_local(const struct in_addr *a) { !in4_addr_is_localhost(a); } +static bool in6_addr_is_loopback(const struct in6_addr *a) { + return memcmp(a, &(struct in6_addr) IN6ADDR_LOOPBACK_INIT, sizeof(struct in6_addr)) == 0; +} + int in_addr_is_localhost(int family, const union in_addr_union *u) { assert(u); @@ -143,7 +148,7 @@ int in_addr_is_localhost(int family, const union in_addr_union *u) { return in4_addr_is_localhost(&u->in); if (family == AF_INET6) - return IN6_IS_ADDR_LOOPBACK(&u->in6); + return in6_addr_is_loopback(&u->in6); return -EAFNOSUPPORT; } @@ -156,7 +161,7 @@ int in_addr_is_localhost_one(int family, const union in_addr_union *u) { return be32toh(u->in.s_addr) == UINT32_C(0x7F000001); if (family == AF_INET6) - return IN6_IS_ADDR_LOOPBACK(&u->in6); + return in6_addr_is_loopback(&u->in6); return -EAFNOSUPPORT; } @@ -178,7 +183,7 @@ bool in6_addr_equal(const struct in6_addr *a, const struct in6_addr *b) { assert(a); assert(b); - return IN6_ARE_ADDR_EQUAL(a, b); + return memcmp(a, b, sizeof(struct in6_addr)) == 0; } int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) { diff --git a/src/basic/include/net/if.h b/src/basic/include/net/if.h new file mode 100644 index 00000000000..7d5b61ba061 --- /dev/null +++ b/src/basic/include/net/if.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include + +#define IF_NAMESIZE 16 + +extern unsigned int if_nametoindex(const char *__ifname) __THROW; +extern char *if_indextoname(unsigned int __ifindex, char __ifname[IF_NAMESIZE]) __THROW; diff --git a/src/basic/include/netinet/in.h b/src/basic/include/netinet/in.h new file mode 100644 index 00000000000..97475ac8821 --- /dev/null +++ b/src/basic/include/netinet/in.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include +#include +#include +#include +#include +#include + +#define INET_ADDRSTRLEN 16 +#define INET6_ADDRSTRLEN 46 + +extern const struct in6_addr in6addr_any; /* :: */ +extern const struct in6_addr in6addr_loopback; /* ::1 */ +#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } +#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } + +typedef uint32_t in_addr_t; diff --git a/src/libsystemd-network/icmp6-util.c b/src/libsystemd-network/icmp6-util.c index b3e3adfee0e..70190164c4f 100644 --- a/src/libsystemd-network/icmp6-util.c +++ b/src/libsystemd-network/icmp6-util.c @@ -34,13 +34,13 @@ int icmp6_bind(int ifindex, bool is_router) { if (is_router) { mreq = (struct ipv6_mreq) { .ipv6mr_multiaddr = IN6_ADDR_ALL_ROUTERS_MULTICAST, - .ipv6mr_interface = ifindex, + .ipv6mr_ifindex = ifindex, }; ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter); } else { mreq = (struct ipv6_mreq) { .ipv6mr_multiaddr = IN6_ADDR_ALL_NODES_MULTICAST, - .ipv6mr_interface = ifindex, + .ipv6mr_ifindex = ifindex, }; ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter); ICMP6_FILTER_SETPASS(ND_NEIGHBOR_ADVERT, &filter); @@ -76,7 +76,7 @@ int icmp6_bind(int ifindex, bool is_router) { if (r < 0) return r; - r = setsockopt_int(s, SOL_IPV6, IPV6_RECVHOPLIMIT, true); + r = setsockopt_int(s, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, true); if (r < 0) return r; @@ -149,7 +149,7 @@ int icmp6_receive( assert(!(msg.msg_flags & MSG_TRUNC)); - int *hops = CMSG_FIND_DATA(&msg, SOL_IPV6, IPV6_HOPLIMIT, int); + int *hops = CMSG_FIND_DATA(&msg, IPPROTO_IPV6, IPV6_HOPLIMIT, int); if (hops && *hops != 255) return -EMULTIHOP; diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index c9ea2d31d54..b76bc710fa8 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -929,7 +929,7 @@ static int dns_scope_multicast_membership(DnsScope *s, bool b, struct in_addr in } else if (s->family == AF_INET6) { struct ipv6_mreq mreq = { .ipv6mr_multiaddr = in6, - .ipv6mr_interface = s->link->ifindex, + .ipv6mr_ifindex = s->link->ifindex, }; if (s->protocol == DNS_PROTOCOL_LLMNR)