1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

network: ndisc: split out prefix option handling into ndsic_router_process_prefix()

This commit is contained in:
Yu Watanabe 2021-11-09 06:26:29 +09:00
parent 5c12ee3656
commit fbdda4bb53

View File

@ -390,8 +390,12 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
int r; int r;
assert(link); assert(link);
assert(link->network);
assert(rt); assert(rt);
if (!link->network->ipv6_accept_ra_use_autonomous_prefix)
return 0;
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &timestamp_usec); r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &timestamp_usec);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); return log_link_error_errno(link, r, "Failed to get RA timestamp: %m");
@ -479,8 +483,12 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
int r; int r;
assert(link); assert(link);
assert(link->network);
assert(rt); assert(rt);
if (!link->network->ipv6_accept_ra_use_onlink_prefix)
return 0;
r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime_sec); r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime_sec);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix lifetime: %m"); return log_link_error_errno(link, r, "Failed to get prefix lifetime: %m");
@ -516,6 +524,56 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
return 0; return 0;
} }
static int ndisc_router_process_prefix(Link *link, sd_ndisc_router *rt) {
unsigned prefixlen;
struct in6_addr a;
uint8_t flags;
int r;
assert(link);
assert(link->network);
assert(rt);
r = sd_ndisc_router_prefix_get_address(rt, &a);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix address: %m");
r = sd_ndisc_router_prefix_get_prefixlen(rt, &prefixlen);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
if (in6_prefix_is_filtered(&a, prefixlen, link->network->ndisc_allow_listed_prefix, link->network->ndisc_deny_listed_prefix)) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *b = NULL;
(void) in6_addr_prefix_to_string(&a, prefixlen, &b);
if (!set_isempty(link->network->ndisc_allow_listed_prefix))
log_link_debug(link, "Prefix '%s' is not in allow list, ignoring", strna(b));
else
log_link_debug(link, "Prefix '%s' is in deny list, ignoring", strna(b));
}
return 0;
}
r = sd_ndisc_router_prefix_get_flags(rt, &flags);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA prefix flags: %m");
if (FLAGS_SET(flags, ND_OPT_PI_FLAG_ONLINK)) {
r = ndisc_router_process_onlink_prefix(link, rt);
if (r < 0)
return r;
}
if (FLAGS_SET(flags, ND_OPT_PI_FLAG_AUTO)) {
r = ndisc_router_process_autonomous_prefix(link, rt);
if (r < 0)
return r;
}
return 0;
}
static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) { static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
_cleanup_(route_freep) Route *route = NULL; _cleanup_(route_freep) Route *route = NULL;
unsigned preference, prefixlen; unsigned preference, prefixlen;
@ -775,11 +833,13 @@ static int ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) {
} }
static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) { static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) {
int r;
assert(link); assert(link);
assert(link->network); assert(link->network);
assert(rt); assert(rt);
for (int r = sd_ndisc_router_option_rewind(rt); ; r = sd_ndisc_router_option_next(rt)) { for (r = sd_ndisc_router_option_rewind(rt); ; r = sd_ndisc_router_option_next(rt)) {
uint8_t type; uint8_t type;
if (r < 0) if (r < 0)
@ -793,51 +853,11 @@ static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) {
switch (type) { switch (type) {
case SD_NDISC_OPTION_PREFIX_INFORMATION: { case SD_NDISC_OPTION_PREFIX_INFORMATION:
unsigned prefixlen; r = ndisc_router_process_prefix(link, rt);
struct in6_addr a;
uint8_t flags;
r = sd_ndisc_router_prefix_get_address(rt, &a);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix address: %m"); return r;
r = sd_ndisc_router_prefix_get_prefixlen(rt, &prefixlen);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
if (in6_prefix_is_filtered(&a, prefixlen, link->network->ndisc_allow_listed_prefix, link->network->ndisc_deny_listed_prefix)) {
if (DEBUG_LOGGING) {
_cleanup_free_ char *b = NULL;
(void) in6_addr_prefix_to_string(&a, prefixlen, &b);
if (!set_isempty(link->network->ndisc_allow_listed_prefix))
log_link_debug(link, "Prefix '%s' is not in allow list, ignoring", strna(b));
else
log_link_debug(link, "Prefix '%s' is in deny list, ignoring", strna(b));
}
break;
}
r = sd_ndisc_router_prefix_get_flags(rt, &flags);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get RA prefix flags: %m");
if (link->network->ipv6_accept_ra_use_onlink_prefix &&
FLAGS_SET(flags, ND_OPT_PI_FLAG_ONLINK)) {
r = ndisc_router_process_onlink_prefix(link, rt);
if (r < 0)
return r;
}
if (link->network->ipv6_accept_ra_use_autonomous_prefix &&
FLAGS_SET(flags, ND_OPT_PI_FLAG_AUTO)) {
r = ndisc_router_process_autonomous_prefix(link, rt);
if (r < 0)
return r;
}
break; break;
}
case SD_NDISC_OPTION_ROUTE_INFORMATION: case SD_NDISC_OPTION_ROUTE_INFORMATION:
r = ndisc_router_process_route(link, rt); r = ndisc_router_process_route(link, rt);
@ -961,6 +981,7 @@ static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
r = ndisc_router_process_default(link, rt); r = ndisc_router_process_default(link, rt);
if (r < 0) if (r < 0)
return r; return r;
r = ndisc_router_process_options(link, rt); r = ndisc_router_process_options(link, rt);
if (r < 0) if (r < 0)
return r; return r;