]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ndisc-option: rename ndisc_option_get() -> ndisc_option_get_by_type()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 16 Mar 2024 07:44:49 +0000 (16:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 25 Mar 2024 18:30:41 +0000 (03:30 +0900)
Then, introduce more generic ndisc_option_get().

src/libsystemd-network/ndisc-option.c
src/libsystemd-network/ndisc-option.h
src/libsystemd-network/sd-ndisc-router.c

index 9b4f48700d30faa3cfd4fd5628a202ae715890a3..7de83bcb12ec05b58b0425d8c58fd2fafcb17341 100644 (file)
@@ -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;
 
index 2669d5d5c91157ca8c3a5837892aa788c1e119b7..46783ebb3e8a1e26f2e946082da04964bbe3e75a 100644 (file)
@@ -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(
index bf7e185ee68df610818afcdd64f5e2541687e683..4b4cc530a69021ad1c61b9f41c7327b906539b23 100644 (file)
@@ -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;