summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-12 12:12:22 +0200
committerGitHub <noreply@github.com>2021-05-12 12:12:22 +0200
commit7a7e58ce443221ed09a9bb15dcef84fdbc5574a0 (patch)
treecc1e4df7b702d7130fd824310f7be58b4dc0bb2e /src/basic
parent8f7123731d2a269ee9985cc265b6e69af63c1b6b (diff)
parent932e157b5e0936a5f531b8bb559997830eb14739 (diff)
downloadsystemd-7a7e58ce443221ed09a9bb15dcef84fdbc5574a0.tar.gz
Merge pull request #19533 from yuwata/network-queue
network: introduce queue to configure address, route, etc
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/hashmap.h30
-rw-r--r--src/basic/in-addr-util.h13
-rw-r--r--src/basic/ordered-set.h11
-rw-r--r--src/basic/set.h13
4 files changed, 44 insertions, 23 deletions
diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h
index c20ee8eb4b..c855f39b1d 100644
--- a/src/basic/hashmap.h
+++ b/src/basic/hashmap.h
@@ -371,28 +371,26 @@ static inline void *ordered_hashmap_first_key(OrderedHashmap *h) {
return _hashmap_first_key(HASHMAP_BASE(h), false);
}
-#define hashmap_clear_with_destructor(_s, _f) \
+#define hashmap_clear_with_destructor(h, f) \
({ \
+ Hashmap *_h = (h); \
void *_item; \
- while ((_item = hashmap_steal_first(_s))) \
- _f(_item); \
+ while ((_item = hashmap_steal_first(_h))) \
+ f(_item); \
+ _h; \
})
-#define hashmap_free_with_destructor(_s, _f) \
- ({ \
- hashmap_clear_with_destructor(_s, _f); \
- hashmap_free(_s); \
- })
-#define ordered_hashmap_clear_with_destructor(_s, _f) \
+#define hashmap_free_with_destructor(h, f) \
+ hashmap_free(hashmap_clear_with_destructor(h, f))
+#define ordered_hashmap_clear_with_destructor(h, f) \
({ \
+ OrderedHashmap *_h = (h); \
void *_item; \
- while ((_item = ordered_hashmap_steal_first(_s))) \
- _f(_item); \
- })
-#define ordered_hashmap_free_with_destructor(_s, _f) \
- ({ \
- ordered_hashmap_clear_with_destructor(_s, _f); \
- ordered_hashmap_free(_s); \
+ while ((_item = ordered_hashmap_steal_first(_h))) \
+ f(_item); \
+ _h; \
})
+#define ordered_hashmap_free_with_destructor(h, f) \
+ ordered_hashmap_free(ordered_hashmap_clear_with_destructor(h, f))
/* no hashmap_next */
void* ordered_hashmap_next(OrderedHashmap *h, const void *key);
diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h
index d5caf662ab..906b3fe97e 100644
--- a/src/basic/in-addr-util.h
+++ b/src/basic/in-addr-util.h
@@ -73,7 +73,13 @@ int in_addr_prefix_range(
union in_addr_union *ret_start,
union in_addr_union *ret_end);
int in_addr_to_string(int family, const union in_addr_union *u, char **ret);
+static inline int in6_addr_to_string(const struct in6_addr *u, char **ret) {
+ return in_addr_to_string(AF_INET6, (const union in_addr_union*) u, ret);
+}
int in_addr_prefix_to_string(int family, const union in_addr_union *u, unsigned prefixlen, char **ret);
+static inline int in6_addr_prefix_to_string(const struct in6_addr *u, unsigned prefixlen, char **ret) {
+ return in_addr_prefix_to_string(AF_INET6, (const union in_addr_union*) u, prefixlen, ret);
+}
int in_addr_port_ifindex_name_to_string(int family, const union in_addr_union *u, uint16_t port, int ifindex, const char *server_name, char **ret);
static inline int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) {
return in_addr_port_ifindex_name_to_string(family, u, 0, ifindex, NULL, ret);
@@ -120,3 +126,10 @@ extern const struct hash_ops in_addr_data_hash_ops;
extern const struct hash_ops in_addr_prefix_hash_ops;
extern const struct hash_ops in_addr_prefix_hash_ops_free;
extern const struct hash_ops in6_addr_hash_ops;
+
+#define IPV4_ADDRESS_FMT_STR "%u.%u.%u.%u"
+#define IPV4_ADDRESS_FMT_VAL(address) \
+ be32toh((address).s_addr) >> 24, \
+ (be32toh((address).s_addr) >> 16) & 0xFFu, \
+ (be32toh((address).s_addr) >> 8) & 0xFFu, \
+ be32toh((address).s_addr) & 0xFFu
diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h
index a377f20b1f..64df41766f 100644
--- a/src/basic/ordered-set.h
+++ b/src/basic/ordered-set.h
@@ -75,6 +75,17 @@ void ordered_set_print(FILE *f, const char *field, OrderedSet *s);
#define ORDERED_SET_FOREACH(e, s) \
_ORDERED_SET_FOREACH(e, s, UNIQ_T(i, UNIQ))
+#define ordered_set_clear_with_destructor(s, f) \
+ ({ \
+ OrderedSet *_s = (s); \
+ void *_item; \
+ while ((_item = ordered_set_steal_first(_s))) \
+ f(_item); \
+ _s; \
+ })
+#define ordered_set_free_with_destructor(s, f) \
+ ordered_set_free(ordered_set_clear_with_destructor(s, f))
+
DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free_free);
diff --git a/src/basic/set.h b/src/basic/set.h
index 52b6f4984c..0f8673934f 100644
--- a/src/basic/set.h
+++ b/src/basic/set.h
@@ -95,17 +95,16 @@ static inline void *set_steal_first(Set *s) {
return _hashmap_first_key_and_value(HASHMAP_BASE(s), true, NULL);
}
-#define set_clear_with_destructor(_s, _f) \
+#define set_clear_with_destructor(s, f) \
({ \
+ Set *_s = (s); \
void *_item; \
while ((_item = set_steal_first(_s))) \
- _f(_item); \
- })
-#define set_free_with_destructor(_s, _f) \
- ({ \
- set_clear_with_destructor(_s, _f); \
- set_free(_s); \
+ f(_item); \
+ _s; \
})
+#define set_free_with_destructor(s, f) \
+ set_free(set_clear_with_destructor(s, f))
/* no set_steal_first_key */
/* no set_first_key */