diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-12 12:12:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 12:12:22 +0200 |
commit | 7a7e58ce443221ed09a9bb15dcef84fdbc5574a0 (patch) | |
tree | cc1e4df7b702d7130fd824310f7be58b4dc0bb2e /src/basic | |
parent | 8f7123731d2a269ee9985cc265b6e69af63c1b6b (diff) | |
parent | 932e157b5e0936a5f531b8bb559997830eb14739 (diff) | |
download | systemd-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.h | 30 | ||||
-rw-r--r-- | src/basic/in-addr-util.h | 13 | ||||
-rw-r--r-- | src/basic/ordered-set.h | 11 | ||||
-rw-r--r-- | src/basic/set.h | 13 |
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 */ |