networkd:add support to configure ipv6 acceprt ra

This patch support to configure the ipv6 acceprt ra option.

for more information see
http://www.tldp.org/HOWTO/Linux+IPv6-HOWTO/proc-sys-net-ipv6..html
This commit is contained in:
Susant Sahani 2015-09-12 08:18:06 +05:30
parent f24aa148ab
commit 4f2e437ad7
4 changed files with 131 additions and 84 deletions

View file

@ -1789,6 +1789,45 @@ static int link_set_ipv6_privacy_extensions(Link *link) {
return 0;
}
static int link_set_ipv6_accept_ra(Link *link) {
const char *p = NULL, *v = NULL;
bool b;
int r;
/* Make this a NOP if IPv6 is not available */
if (!socket_ipv6_is_supported())
return 0;
if (link->flags & IFF_LOOPBACK)
return 0;
/* if unset check the ip forwarding setting maintained for the interface
* and then set it to depending on that. enabled if local forwarding
* is disabled. disabled if local forwarding is enabled.
*/
if (link->network->ipv6_accept_ra < 0) {
if (IN_SET(link->network->ip_forward, ADDRESS_FAMILY_YES, ADDRESS_FAMILY_IPV6))
b = false;
else
b = true;
} else
b = link->network->ipv6_accept_ra;
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/accept_ra");
v = one_zero(b);
r = write_string_file(p, v, 0);
if (r < 0) {
/* If the right value is set anyway, don't complain */
if (verify_one_line_file(p, v) > 0)
return 0;
log_link_warning_errno(link, r, "Cannot configure IPv6 accept_ra for interface: %m");
}
return 0;
}
static int link_configure(Link *link) {
int r;
@ -1812,6 +1851,10 @@ static int link_configure(Link *link) {
if (r < 0)
return r;
r = link_set_ipv6_accept_ra(link);
if (r < 0)
return r;
if (link_ipv4ll_enabled(link)) {
r = ipv4ll_configure(link);
if (r < 0)

View file

@ -50,6 +50,7 @@ Network.NTP, config_parse_strv, 0
Network.IPForward, config_parse_address_family_boolean_with_kernel,0, offsetof(Network, ip_forward)
Network.IPMasquerade, config_parse_bool, 0, offsetof(Network, ip_masquerade)
Network.IPv6PrivacyExtensions, config_parse_ipv6_privacy_extensions, 0, offsetof(Network, ipv6_privacy_extensions)
Network.IPv6AcceptRouterAdvertisements, config_parse_tristate, 0, offsetof(Network, ipv6_accept_ra)
Network.BindCarrier, config_parse_strv, 0, offsetof(Network, bind_carrier)
Address.Address, config_parse_address, 0, 0
Address.Peer, config_parse_address, 0, 0
@ -75,7 +76,7 @@ DHCP.VendorClassIdentifier, config_parse_string, 0
DHCP.RouteMetric, config_parse_unsigned, 0, offsetof(Network, dhcp_route_metric)
DHCP.UseTimezone, config_parse_bool, 0, offsetof(Network, dhcp_timezone)
DHCPServer.MaxLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_max_lease_time_usec)
DHCPServer.DefaultLeaseTimeSec,config_parse_sec, 0, offsetof(Network, dhcp_server_default_lease_time_usec)
DHCPServer.DefaultLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_default_lease_time_usec)
DHCPServer.EmitDNS, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_dns)
DHCPServer.DNS, config_parse_dhcp_server_dns, 0, 0
DHCPServer.EmitNTP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_ntp)

View file

@ -120,6 +120,7 @@ static int network_load_one(Manager *manager, const char *filename) {
network->link_local = ADDRESS_FAMILY_IPV6;
network->ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO;
network->ipv6_accept_ra = -1;
r = config_parse(NULL, filename, file,
"Match\0"

View file

@ -120,6 +120,8 @@ struct Network {
AddressFamilyBoolean ip_forward;
bool ip_masquerade;
int ipv6_accept_ra;
union in_addr_union ipv6_token;
IPv6PrivacyExtensions ipv6_privacy_extensions;