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 | 27 ++++++++++++++++++++++----- proto/radv/radv.c | 14 ++++++-------- proto/radv/radv.h | 1 + 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/doc/bird.sgml b/doc/bird.sgml index a79c842cc..2a7b39154 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -6137,6 +6137,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 + and has to be specified above any prefix options (and at most once in the + instance). + <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, @@ -6426,6 +6431,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 @@ -6442,6 +6452,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 ee1e273c1..6c928a39d 100644 --- a/proto/radv/config.Y +++ b/proto/radv/config.Y @@ -24,6 +24,7 @@ static struct radv_rdnss_config this_radv_rdnss; static struct radv_dnssl_config this_radv_dnssl; static list radv_dns_list; /* Used by radv_rdnss and radv_dnssl */ static u8 radv_mult_val; /* Used by radv_mult for second return value */ +static bool radv_default_forbidden; static inline void radv_add_to_custom_list(list *l, int type, const struct adata *payload) @@ -63,6 +64,14 @@ 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_default_forbidden = false; }; radv_proto_item: @@ -70,6 +79,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); } @@ -208,13 +218,10 @@ CF_CLI(SHOW RADV INTERFACES, optproto opttext, [<name>] [\"<interfaces>\"], [[Sh radv_prefix_start: net_ip6 { + radv_default_forbidden = true; 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: @@ -254,6 +261,16 @@ radv_prefix_opt_list: radv_prefix: radv_prefix_start radv_prefix_opt_list radv_prefix_finish; +radv_default_prefix_start: +{ + if (radv_default_forbidden) + cf_error("Re-defining default options for prefixes or declaring them after prefix blocks is not supported"); + radv_default_forbidden = true; + 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 499aeaea5..cd6cfd218 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 69b5f9f86..a0c46220d 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