From 697c3693b3660c2938aa4d75a1439533280f3470 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 16 Mar 2024 16:44:49 +0900 Subject: [PATCH 1/2] ndisc-option: rename ndisc_option_get() -> ndisc_option_get_by_type() Then, introduce more generic ndisc_option_get(). --- src/libsystemd-network/ndisc-option.c | 2 +- src/libsystemd-network/ndisc-option.h | 8 +++++--- src/libsystemd-network/sd-ndisc-router.c | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libsystemd-network/ndisc-option.c b/src/libsystemd-network/ndisc-option.c index 9b4f48700d3..7de83bcb12e 100644 --- a/src/libsystemd-network/ndisc-option.c +++ b/src/libsystemd-network/ndisc-option.c @@ -1161,7 +1161,7 @@ int ndisc_parse_options(ICMP6Packet *packet, Set **ret_options) { int ndisc_option_get_mac(Set *options, uint8_t type, struct ether_addr *ret) { assert(IN_SET(type, SD_NDISC_OPTION_SOURCE_LL_ADDRESS, SD_NDISC_OPTION_TARGET_LL_ADDRESS)); - sd_ndisc_option *p = ndisc_option_get(options, type); + sd_ndisc_option *p = ndisc_option_get_by_type(options, type); if (!p) return -ENODATA; diff --git a/src/libsystemd-network/ndisc-option.h b/src/libsystemd-network/ndisc-option.h index 2669d5d5c91..46783ebb3e8 100644 --- a/src/libsystemd-network/ndisc-option.h +++ b/src/libsystemd-network/ndisc-option.h @@ -109,10 +109,12 @@ int ndisc_option_parse( int ndisc_parse_options(ICMP6Packet *p, Set **ret_options); -static inline sd_ndisc_option* ndisc_option_get(Set *options, uint8_t type) { - return set_get(options, &(sd_ndisc_option) { .type = type, }); +static inline sd_ndisc_option* ndisc_option_get(Set *options, const sd_ndisc_option *p) { + return set_get(options, ASSERT_PTR(p)); +} +static inline sd_ndisc_option* ndisc_option_get_by_type(Set *options, uint8_t type) { + return ndisc_option_get(options, &(const sd_ndisc_option) { .type = type }); } - int ndisc_option_get_mac(Set *options, uint8_t type, struct ether_addr *ret); int ndisc_option_add_raw( diff --git a/src/libsystemd-network/sd-ndisc-router.c b/src/libsystemd-network/sd-ndisc-router.c index bf7e185ee68..4b4cc530a69 100644 --- a/src/libsystemd-network/sd-ndisc-router.c +++ b/src/libsystemd-network/sd-ndisc-router.c @@ -151,7 +151,7 @@ int sd_ndisc_router_get_flags(sd_ndisc_router *rt, uint64_t *ret) { assert_return(rt, -EINVAL); assert_return(ret, -EINVAL); - sd_ndisc_option *p = ndisc_option_get(rt->options, SD_NDISC_OPTION_FLAGS_EXTENSION); + sd_ndisc_option *p = ndisc_option_get_by_type(rt->options, SD_NDISC_OPTION_FLAGS_EXTENSION); *ret = rt->flags | (p ? p->extended_flags : 0); return 0; @@ -184,7 +184,7 @@ int sd_ndisc_router_get_mtu(sd_ndisc_router *rt, uint32_t *ret) { assert_return(rt, -EINVAL); assert_return(ret, -EINVAL); - sd_ndisc_option *p = ndisc_option_get(rt->options, SD_NDISC_OPTION_MTU); + sd_ndisc_option *p = ndisc_option_get_by_type(rt->options, SD_NDISC_OPTION_MTU); if (!p) return -ENODATA; @@ -196,7 +196,7 @@ int sd_ndisc_router_get_captive_portal(sd_ndisc_router *rt, const char **ret) { assert_return(rt, -EINVAL); assert_return(ret, -EINVAL); - sd_ndisc_option *p = ndisc_option_get(rt->options, SD_NDISC_OPTION_CAPTIVE_PORTAL); + sd_ndisc_option *p = ndisc_option_get_by_type(rt->options, SD_NDISC_OPTION_CAPTIVE_PORTAL); if (!p) return -ENODATA; From 24578ce63aac951124fcde2b88c37cf4018a7e43 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 17 Mar 2024 13:27:08 +0900 Subject: [PATCH 2/2] ndisc-option: introduce ndisc_option_remove() --- src/libsystemd-network/ndisc-option.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libsystemd-network/ndisc-option.h b/src/libsystemd-network/ndisc-option.h index 46783ebb3e8..7e7a702b809 100644 --- a/src/libsystemd-network/ndisc-option.h +++ b/src/libsystemd-network/ndisc-option.h @@ -117,6 +117,13 @@ static inline sd_ndisc_option* ndisc_option_get_by_type(Set *options, uint8_t ty } int ndisc_option_get_mac(Set *options, uint8_t type, struct ether_addr *ret); +static inline void ndisc_option_remove(Set *options, const sd_ndisc_option *p) { + ndisc_option_free(set_remove(options, ASSERT_PTR(p))); +} +static inline void ndisc_option_remove_by_type(Set *options, uint8_t type) { + ndisc_option_remove(options, &(const sd_ndisc_option) { .type = type }); +} + int ndisc_option_add_raw( Set **options, size_t offset,