mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
network: use sysctl_write_ip_property() and friends
This commit is contained in:
parent
3decde0226
commit
62e021a95d
@ -10,8 +10,9 @@
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-network.h"
|
||||
#include "string-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "string-util.h"
|
||||
#include "sysctl-util.h"
|
||||
|
||||
static bool ipv6_proxy_ndp_is_needed(Link *link) {
|
||||
assert(link);
|
||||
@ -32,8 +33,8 @@ static bool ipv6_proxy_ndp_is_needed(Link *link) {
|
||||
}
|
||||
|
||||
static int ipv6_proxy_ndp_set(Link *link) {
|
||||
const char *p = NULL;
|
||||
int r, v;
|
||||
bool v;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
||||
@ -41,9 +42,8 @@ static int ipv6_proxy_ndp_set(Link *link) {
|
||||
return 0;
|
||||
|
||||
v = ipv6_proxy_ndp_is_needed(link);
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/proxy_ndp");
|
||||
|
||||
r = write_string_file(p, one_zero(v), WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_boolean(AF_INET6, link->ifname, "proxy_ndp", v);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure proxy NDP for interface: %m");
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "stdio-util.h"
|
||||
#include "string-table.h"
|
||||
#include "strv.h"
|
||||
#include "sysctl-util.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "util.h"
|
||||
#include "virt.h"
|
||||
@ -297,7 +298,6 @@ static IPv6PrivacyExtensions link_ipv6_privacy_extensions(Link *link) {
|
||||
}
|
||||
|
||||
static int link_enable_ipv6(Link *link) {
|
||||
const char *p = NULL;
|
||||
bool disabled;
|
||||
int r;
|
||||
|
||||
@ -306,9 +306,7 @@ static int link_enable_ipv6(Link *link) {
|
||||
|
||||
disabled = !link_ipv6_enabled(link);
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/disable_ipv6");
|
||||
|
||||
r = write_string_file(p, one_zero(disabled), WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_boolean(AF_INET6, link->ifname, "disable_ipv6", disabled);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot %s IPv6 for interface %s: %m",
|
||||
enable_disable(!disabled), link->ifname);
|
||||
@ -1330,15 +1328,12 @@ static int link_set_bridge_vlan(Link *link) {
|
||||
}
|
||||
|
||||
static int link_set_proxy_arp(Link *link) {
|
||||
const char *p = NULL;
|
||||
int r;
|
||||
|
||||
if (!link_proxy_arp_enabled(link))
|
||||
return 0;
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv4/conf/", link->ifname, "/proxy_arp");
|
||||
|
||||
r = write_string_file(p, one_zero(link->network->proxy_arp), WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_boolean(AF_INET, link->ifname, "proxy_arp", link->network->proxy_arp > 0);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure proxy ARP for interface: %m");
|
||||
|
||||
@ -2653,7 +2648,7 @@ static int link_set_ipv4_forward(Link *link) {
|
||||
* primarily to keep IPv4 and IPv6 packet forwarding behaviour
|
||||
* somewhat in sync (see below). */
|
||||
|
||||
r = write_string_file("/proc/sys/net/ipv4/ip_forward", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property(AF_INET, NULL, "ip_forward", "1");
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot turn on IPv4 packet forwarding, ignoring: %m");
|
||||
|
||||
@ -2675,7 +2670,7 @@ static int link_set_ipv6_forward(Link *link) {
|
||||
* same behaviour there and also propagate the setting from
|
||||
* one to all, to keep things simple (see above). */
|
||||
|
||||
r = write_string_file("/proc/sys/net/ipv6/conf/all/forwarding", "1", WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property(AF_INET6, "all", "forwarding", "1");
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure IPv6 packet forwarding, ignoring: %m");
|
||||
|
||||
@ -2683,19 +2678,14 @@ static int link_set_ipv6_forward(Link *link) {
|
||||
}
|
||||
|
||||
static int link_set_ipv6_privacy_extensions(Link *link) {
|
||||
char buf[DECIMAL_STR_MAX(unsigned) + 1];
|
||||
IPv6PrivacyExtensions s;
|
||||
const char *p = NULL;
|
||||
int r;
|
||||
|
||||
s = link_ipv6_privacy_extensions(link);
|
||||
if (s < 0)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/use_tempaddr");
|
||||
xsprintf(buf, "%u", (unsigned) link->network->ipv6_privacy_extensions);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_int(AF_INET6, link->ifname, "use_tempaddr", (int) link->network->ipv6_privacy_extensions);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot configure IPv6 privacy extension for interface: %m");
|
||||
|
||||
@ -2703,7 +2693,6 @@ static int link_set_ipv6_privacy_extensions(Link *link) {
|
||||
}
|
||||
|
||||
static int link_set_ipv6_accept_ra(Link *link) {
|
||||
const char *p = NULL;
|
||||
int r;
|
||||
|
||||
/* Make this a NOP if IPv6 is not available */
|
||||
@ -2716,10 +2705,7 @@ static int link_set_ipv6_accept_ra(Link *link) {
|
||||
if (!link->network)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/accept_ra");
|
||||
|
||||
/* We handle router advertisements ourselves, tell the kernel to GTFO */
|
||||
r = write_string_file(p, "0", WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property(AF_INET6, link->ifname, "accept_ra", "0");
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot disable kernel IPv6 accept_ra for interface: %m");
|
||||
|
||||
@ -2727,8 +2713,6 @@ static int link_set_ipv6_accept_ra(Link *link) {
|
||||
}
|
||||
|
||||
static int link_set_ipv6_dad_transmits(Link *link) {
|
||||
char buf[DECIMAL_STR_MAX(int) + 1];
|
||||
const char *p = NULL;
|
||||
int r;
|
||||
|
||||
/* Make this a NOP if IPv6 is not available */
|
||||
@ -2744,10 +2728,7 @@ static int link_set_ipv6_dad_transmits(Link *link) {
|
||||
if (link->network->ipv6_dad_transmits < 0)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/dad_transmits");
|
||||
xsprintf(buf, "%i", link->network->ipv6_dad_transmits);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_int(AF_INET6, link->ifname, "dad_transmits", link->network->ipv6_dad_transmits);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot set IPv6 dad transmits for interface: %m");
|
||||
|
||||
@ -2755,8 +2736,6 @@ static int link_set_ipv6_dad_transmits(Link *link) {
|
||||
}
|
||||
|
||||
static int link_set_ipv6_hop_limit(Link *link) {
|
||||
char buf[DECIMAL_STR_MAX(int) + 1];
|
||||
const char *p = NULL;
|
||||
int r;
|
||||
|
||||
/* Make this a NOP if IPv6 is not available */
|
||||
@ -2772,10 +2751,7 @@ static int link_set_ipv6_hop_limit(Link *link) {
|
||||
if (link->network->ipv6_hop_limit < 0)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/hop_limit");
|
||||
xsprintf(buf, "%i", link->network->ipv6_hop_limit);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_int(AF_INET6, link->ifname, "hop_limit", link->network->ipv6_hop_limit);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot set IPv6 hop limit for interface: %m");
|
||||
|
||||
@ -2783,8 +2759,6 @@ static int link_set_ipv6_hop_limit(Link *link) {
|
||||
}
|
||||
|
||||
static int link_set_ipv6_mtu(Link *link) {
|
||||
char buf[DECIMAL_STR_MAX(unsigned) + 1];
|
||||
const char *p = NULL;
|
||||
int r;
|
||||
|
||||
/* Make this a NOP if IPv6 is not available */
|
||||
@ -2797,11 +2771,7 @@ static int link_set_ipv6_mtu(Link *link) {
|
||||
if (link->network->ipv6_mtu == 0)
|
||||
return 0;
|
||||
|
||||
p = strjoina("/proc/sys/net/ipv6/conf/", link->ifname, "/mtu");
|
||||
|
||||
xsprintf(buf, "%" PRIu32, link->network->ipv6_mtu);
|
||||
|
||||
r = write_string_file(p, buf, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
r = sysctl_write_ip_property_uint32(AF_INET6, link->ifname, "mtu", link->network->ipv6_mtu);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Cannot set IPv6 MTU for interface: %m");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user