ndisc-option: rename ndisc_option_get() -> ndisc_option_get_by_type()

Then, introduce more generic ndisc_option_get().
This commit is contained in:
Yu Watanabe
2024-03-26 03:30:41 +09:00
parent 4651e1428d
commit 697c3693b3
3 changed files with 9 additions and 7 deletions
+1 -1
View 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;
+5 -3
View 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(
+3 -3
View 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;