1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

Merge pull request #31943 from yuwata/sd-ndisc-option-getter-remover

sd-ndisc: introduce option getter and remover
This commit is contained in:
Luca Boccassi 2024-03-26 13:55:46 +00:00 committed by GitHub
commit d1b08f2460
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

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;

View File

@ -109,12 +109,21 @@ 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);
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,

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;