X Tutup
Skip to content

Commit fbdda4b

Browse files
committed
network: ndisc: split out prefix option handling into ndsic_router_process_prefix()
1 parent 5c12ee3 commit fbdda4b

File tree

1 file changed

+65
-44
lines changed

1 file changed

+65
-44
lines changed

src/network/networkd-ndisc.c

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,12 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
390390
int r;
391391

392392
assert(link);
393+
assert(link->network);
393394
assert(rt);
394395

396+
if (!link->network->ipv6_accept_ra_use_autonomous_prefix)
397+
return 0;
398+
395399
r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), &timestamp_usec);
396400
if (r < 0)
397401
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) {
479483
int r;
480484

481485
assert(link);
486+
assert(link->network);
482487
assert(rt);
483488

489+
if (!link->network->ipv6_accept_ra_use_onlink_prefix)
490+
return 0;
491+
484492
r = sd_ndisc_router_prefix_get_valid_lifetime(rt, &lifetime_sec);
485493
if (r < 0)
486494
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) {
516524
return 0;
517525
}
518526

527+
static int ndisc_router_process_prefix(Link *link, sd_ndisc_router *rt) {
528+
unsigned prefixlen;
529+
struct in6_addr a;
530+
uint8_t flags;
531+
int r;
532+
533+
assert(link);
534+
assert(link->network);
535+
assert(rt);
536+
537+
r = sd_ndisc_router_prefix_get_address(rt, &a);
538+
if (r < 0)
539+
return log_link_error_errno(link, r, "Failed to get prefix address: %m");
540+
541+
r = sd_ndisc_router_prefix_get_prefixlen(rt, &prefixlen);
542+
if (r < 0)
543+
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
544+
545+
if (in6_prefix_is_filtered(&a, prefixlen, link->network->ndisc_allow_listed_prefix, link->network->ndisc_deny_listed_prefix)) {
546+
if (DEBUG_LOGGING) {
547+
_cleanup_free_ char *b = NULL;
548+
549+
(void) in6_addr_prefix_to_string(&a, prefixlen, &b);
550+
if (!set_isempty(link->network->ndisc_allow_listed_prefix))
551+
log_link_debug(link, "Prefix '%s' is not in allow list, ignoring", strna(b));
552+
else
553+
log_link_debug(link, "Prefix '%s' is in deny list, ignoring", strna(b));
554+
}
555+
return 0;
556+
}
557+
558+
r = sd_ndisc_router_prefix_get_flags(rt, &flags);
559+
if (r < 0)
560+
return log_link_error_errno(link, r, "Failed to get RA prefix flags: %m");
561+
562+
if (FLAGS_SET(flags, ND_OPT_PI_FLAG_ONLINK)) {
563+
r = ndisc_router_process_onlink_prefix(link, rt);
564+
if (r < 0)
565+
return r;
566+
}
567+
568+
if (FLAGS_SET(flags, ND_OPT_PI_FLAG_AUTO)) {
569+
r = ndisc_router_process_autonomous_prefix(link, rt);
570+
if (r < 0)
571+
return r;
572+
}
573+
574+
return 0;
575+
}
576+
519577
static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
520578
_cleanup_(route_freep) Route *route = NULL;
521579
unsigned preference, prefixlen;
@@ -775,11 +833,13 @@ static int ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) {
775833
}
776834

777835
static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) {
836+
int r;
837+
778838
assert(link);
779839
assert(link->network);
780840
assert(rt);
781841

782-
for (int r = sd_ndisc_router_option_rewind(rt); ; r = sd_ndisc_router_option_next(rt)) {
842+
for (r = sd_ndisc_router_option_rewind(rt); ; r = sd_ndisc_router_option_next(rt)) {
783843
uint8_t type;
784844

785845
if (r < 0)
@@ -793,51 +853,11 @@ static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) {
793853

794854
switch (type) {
795855

796-
case SD_NDISC_OPTION_PREFIX_INFORMATION: {
797-
unsigned prefixlen;
798-
struct in6_addr a;
799-
uint8_t flags;
800-
801-
r = sd_ndisc_router_prefix_get_address(rt, &a);
802-
if (r < 0)
803-
return log_link_error_errno(link, r, "Failed to get prefix address: %m");
804-
805-
r = sd_ndisc_router_prefix_get_prefixlen(rt, &prefixlen);
856+
case SD_NDISC_OPTION_PREFIX_INFORMATION:
857+
r = ndisc_router_process_prefix(link, rt);
806858
if (r < 0)
807-
return log_link_error_errno(link, r, "Failed to get prefix length: %m");
808-
809-
if (in6_prefix_is_filtered(&a, prefixlen, link->network->ndisc_allow_listed_prefix, link->network->ndisc_deny_listed_prefix)) {
810-
if (DEBUG_LOGGING) {
811-
_cleanup_free_ char *b = NULL;
812-
813-
(void) in6_addr_prefix_to_string(&a, prefixlen, &b);
814-
if (!set_isempty(link->network->ndisc_allow_listed_prefix))
815-
log_link_debug(link, "Prefix '%s' is not in allow list, ignoring", strna(b));
816-
else
817-
log_link_debug(link, "Prefix '%s' is in deny list, ignoring", strna(b));
818-
}
819-
break;
820-
}
821-
822-
r = sd_ndisc_router_prefix_get_flags(rt, &flags);
823-
if (r < 0)
824-
return log_link_error_errno(link, r, "Failed to get RA prefix flags: %m");
825-
826-
if (link->network->ipv6_accept_ra_use_onlink_prefix &&
827-
FLAGS_SET(flags, ND_OPT_PI_FLAG_ONLINK)) {
828-
r = ndisc_router_process_onlink_prefix(link, rt);
829-
if (r < 0)
830-
return r;
831-
}
832-
833-
if (link->network->ipv6_accept_ra_use_autonomous_prefix &&
834-
FLAGS_SET(flags, ND_OPT_PI_FLAG_AUTO)) {
835-
r = ndisc_router_process_autonomous_prefix(link, rt);
836-
if (r < 0)
837-
return r;
838-
}
859+
return r;
839860
break;
840-
}
841861

842862
case SD_NDISC_OPTION_ROUTE_INFORMATION:
843863
r = ndisc_router_process_route(link, rt);
@@ -961,6 +981,7 @@ static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) {
961981
r = ndisc_router_process_default(link, rt);
962982
if (r < 0)
963983
return r;
984+
964985
r = ndisc_router_process_options(link, rt);
965986
if (r < 0)
966987
return r;

0 commit comments

Comments
 (0)
X Tutup