]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add MACAddress= setting in [SR-IOV] section
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 22 Jun 2020 10:48:33 +0000 (19:48 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 1 Jul 2020 04:51:35 +0000 (13:51 +0900)
man/systemd.network.xml
src/network/networkd-network-gperf.gperf
src/network/networkd-sriov.c
src/network/networkd-sriov.h
test/fuzz/fuzz-network-parser/directives.network

index 7c31f345ab872579da46e1f872e4773b5708cf28..ea470be5b1e626128f547c8b3b4272e639441f87 100644 (file)
           </listitem>
         </varlistentry>
 
+        <varlistentry>
+          <term><varname>MACAddress=</varname></term>
+          <listitem>
+            <para>Specifies the MAC address for the virtual function.</para>
+          </listitem>
+        </varlistentry>
       </variablelist>
   </refsect1>
 
index f1937ac251f87bd4bfa5686b93bf687ead95ba1e..9bdd639831292d4f7fb4188fbfa1a2a57bf60aa2 100644 (file)
@@ -62,6 +62,7 @@ SR-IOV.MACSpoofCheck,                        config_parse_sr_iov_boolean,
 SR-IOV.QueryReceiveSideScaling,              config_parse_sr_iov_boolean,                              0,                             0
 SR-IOV.Trust,                                config_parse_sr_iov_boolean,                              0,                             0
 SR-IOV.LinkState,                            config_parse_sr_iov_link_state,                           0,                             0
+SR-IOV.MACAddress,                           config_parse_sr_iov_mac,                                  0,                             0
 Network.Description,                         config_parse_string,                                      0,                             offsetof(Network, description)
 Network.Bridge,                              config_parse_ifname,                                      0,                             offsetof(Network, bridge_name)
 Network.Bond,                                config_parse_ifname,                                      0,                             offsetof(Network, bond_name)
index 62a6fc9c225119cd3563e3625519994ea08dbc51..5ae751ed46f95efc3f6d40e17c081f2f287bd1b1 100644 (file)
@@ -131,6 +131,17 @@ int sr_iov_configure(Link *link, SRIOV *sr_iov) {
         if (r < 0)
                 return log_link_error_errno(link, r, "Could not open IFLA_VF_INFO container: %m");
 
+        if (!ether_addr_is_null(&sr_iov->mac)) {
+                struct ifla_vf_mac ivm = {
+                        .vf = sr_iov->vf,
+                };
+
+                memcpy(ivm.mac, &sr_iov->mac, ETH_ALEN);
+                r = sd_netlink_message_append_data(req, IFLA_VF_MAC, &ivm, sizeof(struct ifla_vf_mac));
+                if (r < 0)
+                        return log_link_error_errno(link, r, "Could not append IFLA_VF_MAC: %m");
+        }
+
         if (sr_iov->vf_spoof_check_setting >= 0) {
                 struct ifla_vf_spoofchk ivs = {
                         .vf = sr_iov->vf,
@@ -446,3 +457,45 @@ int config_parse_sr_iov_boolean(
         TAKE_PTR(sr_iov);
         return 0;
 }
+
+int config_parse_sr_iov_mac(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        _cleanup_(sr_iov_free_or_set_invalidp) SRIOV *sr_iov = NULL;
+        Network *network = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(data);
+
+        r = sr_iov_new_static(network, filename, section_line, &sr_iov);
+        if (r < 0)
+                return r;
+
+        if (isempty(rvalue)) {
+                sr_iov->mac = ETHER_ADDR_NULL;
+                TAKE_PTR(sr_iov);
+                return 0;
+        }
+
+        r = ether_addr_from_string(rvalue, &sr_iov->mac);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, 0,
+                           "Failed to parse SR-IOV '%s=', ignoring assignment: %s", lvalue, rvalue);
+                return 0;
+        }
+
+        TAKE_PTR(sr_iov);
+        return 0;
+}
index 65ad3266b3d7699afc411e2888566801f8a365fb..a545d1292ae0e5aec540964609a5ead866bf48c6 100644 (file)
@@ -29,6 +29,7 @@ typedef struct SRIOV {
         int query_rss;
         int trust;
         SRIOVLinkState link_state;
+        struct ether_addr mac;
 } SRIOV;
 
 SRIOV *sr_iov_free(SRIOV *sr_iov);
@@ -42,3 +43,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_uint32);
 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_boolean);
 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_link_state);
 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_vlan_proto);
+CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_mac);
index c5bab2abf8320e3cd2eb161f9ed97cd183db29a4..da4a9647ab30b6bec9078d7927e4adcf15a5f094 100644 (file)
@@ -47,6 +47,7 @@ QualityOfService=
 QueryReceiveSideScaling=
 Trust=
 LinkState=
+MACAddress=
 [BridgeFDB]
 VLANId=
 MACAddress=