summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-12-04 21:57:13 +0100
committerTom Gundersen <teg@jklm.no>2014-12-05 00:38:10 +0100
commitc106cc36b9b8e8998eb95299b02f1db9c1209122 (patch)
treef60a30744029dd69fb0ba47e5bc21c79d516b162
parentc18c2a0ea15820c49226aa05f294f5d5c1417263 (diff)
networkd: add basic [Link] settings to .network files
This allows the default link settings (set in .link files) to be overridden per Network. Only MTU and MACAddress is supported for now.
-rw-r--r--man/systemd.network.xml24
-rw-r--r--src/network/networkd-link.c17
-rw-r--r--src/network/networkd-network-gperf.gperf2
-rw-r--r--src/network/networkd-network.c11
-rw-r--r--src/network/networkd.h3
5 files changed, 56 insertions, 1 deletions
diff --git a/man/systemd.network.xml b/man/systemd.network.xml
index a913fdfc5e..11b4370a6e 100644
--- a/man/systemd.network.xml
+++ b/man/systemd.network.xml
@@ -180,6 +180,30 @@
</refsect1>
<refsect1>
+ <title>[Link] Section Options</title>
+
+ <para> The <literal>[Link]</literal> section accepts the following keys:</para>
+
+ <variablelist class='network-directives'>
+ <varlistentry>
+ <term><varname>MACAddress=</varname></term>
+ <listitem>
+ <para>The hardware address.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><varname>MTUBytes=</varname></term>
+ <listitem>
+ <para>The maximum transmission unit in bytes to
+ set for the device. The usual suffixes K, M, G,
+ are supported and are understood to the base of
+ 1024.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
<title>[Network] Section Options</title>
<para>The <literal>[Network]</literal> section accepts the following keys:</para>
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 7cffcb48d0..d59a8192b0 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1074,6 +1074,7 @@ static int link_up(Link *link) {
int r;
assert(link);
+ assert(link->network);
assert(link->manager);
assert(link->manager->rtnl);
@@ -1093,6 +1094,22 @@ static int link_up(Link *link) {
return r;
}
+ if (link->network->mac) {
+ r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, link->network->mac);
+ if (r < 0) {
+ log_link_error(link, "Could not set MAC address: %s", strerror(-r));
+ return r;
+ }
+ }
+
+ if (link->network->mtu) {
+ r = sd_rtnl_message_append_u32(req, IFLA_MTU, link->network->mtu);
+ if (r < 0) {
+ log_link_error(link, "Could not set MTU: %s", strerror(-r));
+ return r;
+ }
+ }
+
r = sd_rtnl_call_async(link->manager->rtnl, req, link_up_handler, link,
0, NULL);
if (r < 0) {
diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
index 4f0e05aeb6..bd422e3e0b 100644
--- a/src/network/networkd-network-gperf.gperf
+++ b/src/network/networkd-network-gperf.gperf
@@ -24,6 +24,8 @@ Match.Host, config_parse_net_condition, CONDITION_HOST,
Match.Virtualization, config_parse_net_condition, CONDITION_VIRTUALIZATION, offsetof(Network, match_virt)
Match.KernelCommandLine, config_parse_net_condition, CONDITION_KERNEL_COMMAND_LINE, offsetof(Network, match_kernel)
Match.Architecture, config_parse_net_condition, CONDITION_ARCHITECTURE, offsetof(Network, match_arch)
+Link.MACAddress, config_parse_hwaddr, 0, offsetof(Network, mac)
+Link.MTUBytes, config_parse_iec_size, 0, offsetof(Network, mtu)
Network.Description, config_parse_string, 0, offsetof(Network, description)
Network.Bridge, config_parse_netdev, 0, offsetof(Network, bridge)
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index cb111382f5..b014a6b649 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -90,7 +90,14 @@ static int network_load_one(Manager *manager, const char *filename) {
network->llmnr = LLMNR_SUPPORT_YES;
r = config_parse(NULL, filename, file,
- "Match\0Network\0Address\0Route\0DHCP\0DHCPv4\0BridgePort\0",
+ "Match\0"
+ "Link\0"
+ "Network\0"
+ "Address\0"
+ "Route\0"
+ "DHCP\0"
+ "DHCPv4\0"
+ "BridgePort\0",
config_item_perf_lookup, network_network_gperf_lookup,
false, false, true, network);
if (r < 0)
@@ -163,6 +170,8 @@ void network_free(Network *network) {
free(network->description);
free(network->dhcp_vendor_class_identifier);
+ free(network->mac);
+
strv_free(network->ntp);
strv_free(network->dns);
strv_free(network->domains);
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 07917f0ef4..5f553fb3b9 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -108,6 +108,9 @@ struct Network {
unsigned cost;
+ struct ether_addr *mac;
+ unsigned mtu;
+
LIST_HEAD(Address, static_addresses);
LIST_HEAD(Route, static_routes);