Before this, it was necessary to include all the differences from the hardcoded defaults for each prefix, as there was no inheritance. That could be an issue for deployments that don't use the BIRD's defaults (e.g. not using SLAAC or using different lifetimes). The new option `default prefix` allows overriding BIRD's default in the instance's config. This also made it possible to only have BIRD's defaults in a single place – the copy in `radv.c` is no longer useful. --- doc/bird.sgml | 12 ++++++++++++ proto/radv/config.Y | 20 +++++++++++++++----- proto/radv/radv.c | 14 ++++++-------- proto/radv/radv.h | 1 + 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/doc/bird.sgml b/doc/bird.sgml index ee5d3039d..392f95b97 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -6098,6 +6098,11 @@ definitions, prefix definitions and DNS definitions: prefix definition is matching if the network prefix is a subnet of the prefix in prefix definition. + <tag><label id="radv-default-prefix">default prefix { <m/options/ }</tag> + This allows to alter the default prefix options for this instance of RAdv. + The changed values apply for subsequent <cf/prefix/ blocks and can be + overwritten inbetween blocks. + <tag><label id="radv-rdnss">rdnss { <m/options/ }</tag> RDNSS definitions allow to specify a list of advertised recursive DNS servers together with their options. As options are seldom necessary, @@ -6387,6 +6392,11 @@ protocol radv { propagate routes yes; # Propagate the routes from the radv_routes table ipv6 { table radv_routes; export all; }; + default prefix { + preferred lifetime 3600; # use shorter lifetimes for all networks + valid lifetime 14400; + }; + interface "eth2" { max ra interval 5; # Fast failover with more routers managed yes; # Using DHCPv6 on eth2 @@ -6403,6 +6413,8 @@ protocol radv { prefix 2001:0DB8:2000::/48 { autonomous off; # Do not autoconfigure + preferred lifetime 14400; # use conventional lifetimes + valid lifetime 86400; }; rdnss 2001:0DB8:1234::10; # Short form of RDNSS diff --git a/proto/radv/config.Y b/proto/radv/config.Y index 463b79532..731a0ef38 100644 --- a/proto/radv/config.Y +++ b/proto/radv/config.Y @@ -63,6 +63,12 @@ radv_proto_start: proto_start RADV init_list(&RADV_CFG->rdnss_list); init_list(&RADV_CFG->dnssl_list); init_list(&RADV_CFG->custom_list); + + RADV_CFG->default_prefix_config = cfg_allocz(sizeof(struct radv_prefix_config)); + RADV_CFG->default_prefix_config->onlink = 1; + RADV_CFG->default_prefix_config->autonomous = 1; + RADV_CFG->default_prefix_config->valid_lifetime = DEFAULT_VALID_LIFETIME; + RADV_CFG->default_prefix_config->preferred_lifetime = DEFAULT_PREFERRED_LIFETIME; }; radv_proto_item: @@ -70,6 +76,7 @@ radv_proto_item: | proto_channel | nbrs_channel | INTERFACE radv_iface + | DEFAULT PREFIX radv_default_prefix | PREFIX radv_prefix { add_tail(&RADV_CFG->pref_list, NODE this_radv_prefix); } | RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_CFG->rdnss_list, &radv_dns_list); } | DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_CFG->dnssl_list, &radv_dns_list); } @@ -206,12 +213,8 @@ radv_iface: radv_prefix_start: net_ip6 { this_radv_prefix = cfg_allocz(sizeof(struct radv_prefix_config)); + memcpy(RADV_PREFIX, RADV_CFG->default_prefix_config, sizeof(struct radv_prefix_config)); RADV_PREFIX->prefix = *(net_addr_ip6 *) &($1); - - RADV_PREFIX->onlink = 1; - RADV_PREFIX->autonomous = 1; - RADV_PREFIX->valid_lifetime = DEFAULT_VALID_LIFETIME; - RADV_PREFIX->preferred_lifetime = DEFAULT_PREFERRED_LIFETIME; }; radv_prefix_item: @@ -251,6 +254,13 @@ radv_prefix_opt_list: radv_prefix: radv_prefix_start radv_prefix_opt_list radv_prefix_finish; +radv_default_prefix_start: +{ + this_radv_prefix = RADV_CFG->default_prefix_config; +}; + +radv_default_prefix: + radv_default_prefix_start radv_prefix_opt_list radv_prefix_finish; radv_rdnss_node: ipa diff --git a/proto/radv/radv.c b/proto/radv/radv.c index 7c2e89535..da40765af 100644 --- a/proto/radv/radv.c +++ b/proto/radv/radv.c @@ -88,13 +88,6 @@ radv_nbr_timer(timer *tm) radv_prune_neighbors(p); } -static struct radv_prefix_config default_prefix = { - .onlink = 1, - .autonomous = 1, - .valid_lifetime = DEFAULT_VALID_LIFETIME, - .preferred_lifetime = DEFAULT_PREFERRED_LIFETIME -}; - static struct radv_prefix_config dead_prefix = { }; @@ -114,7 +107,12 @@ radv_prefix_match(struct radv_iface *ifa, net_addr_ip6 *px) if (net_in_net_ip6(px, &pc->prefix)) return pc; - return &default_prefix; + struct radv_prefix_config *ret = cf->default_prefix_config; + if (!ret) { + log(L_BUG "RAdv: default config for prefixes was not allocated"); + return &dead_prefix; + } + return ret; } /* diff --git a/proto/radv/radv.h b/proto/radv/radv.h index d3f6eceef..868e2566f 100644 --- a/proto/radv/radv.h +++ b/proto/radv/radv.h @@ -56,6 +56,7 @@ struct radv_config net_addr trigger; /* Prefix of a trigger route, if defined */ u8 propagate_routes; /* Do we propagate more specific routes (RFC 4191)? */ u32 max_linger_time; /* Maximum of interface route_linger_time */ + struct radv_prefix_config *default_prefix_config; /* base config for prefixes */ }; struct radv_iface_config -- 2.55.0