network,udev: make .network and .link file can match with hardware address longer...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Nov 2021 17:59:11 +0000 (02:59 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 25 Nov 2021 19:14:46 +0000 (20:14 +0100)
man/systemd.link.xml
src/network/networkd-link.c
src/network/networkd-network-bus.c
src/network/networkd-network-gperf.gperf
src/shared/net-condition.c
src/shared/net-condition.h
src/udev/net/link-config-gperf.gperf
src/udev/net/link-config.c

index 487f314396c3f6453962f5b744216a3c52beffa9..45cabbccf70c1c0d5aa8a2843a500ca2cb5edfbd 100644 (file)
       <varlistentry id='mac-address'>
         <term><varname>MACAddress=</varname></term>
         <listitem>
-          <para>A whitespace-separated list of hardware addresses. Use full colon-, hyphen- or dot-delimited hexadecimal. See the example below.
-          This option may appear more than once, in which case the lists are merged. If the empty string is assigned to this option, the list
-          of hardware addresses defined prior to this is reset.</para>
+          <para>A whitespace-separated list of hardware addresses. The acceptable formats are:</para>
 
-          <para>Example:
-          <programlisting>MACAddress=01:23:45:67:89:ab 00-11-22-33-44-55 AABB.CCDD.EEFF</programlisting></para>
+          <variablelist>
+            <varlistentry>
+              <term><option>colon-delimited hexadecimal</option></term>
+              <listitem><para>
+                Each field must be one byte.
+                E.g. <literal>12:34:56:78:90:ab</literal> or <literal>AA:BB:CC:DD:EE:FF</literal>.
+              </para></listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>hyphen-delimited hexadecimal</option></term>
+              <listitem><para>
+                Each field must be one byte.
+                E.g. <literal>12-34-56-78-90-ab</literal> or <literal>AA-BB-CC-DD-EE-FF</literal>.
+              </para></listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>dot-delimited hexadecimal</option></term>
+              <listitem><para>
+                Each field must be two bytes.
+                E.g. <literal>1234.5678.90ab</literal> or <literal>AABB.CCDD.EEFF</literal>.
+              </para></listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>IPv4 address format</option></term>
+              <listitem><para>
+                E.g. <literal>127.0.0.1</literal> or <literal>192.168.0.1</literal>.
+              </para></listitem>
+            </varlistentry>
+            <varlistentry>
+              <term><option>IPv6 address format</option></term>
+              <listitem><para>
+                E.g. <literal>2001:0db8:85a3::8a2e:0370:7334</literal> or <literal>::1</literal>.
+              </para></listitem>
+            </varlistentry>
+          </variablelist>
+
+          <para>The total length of each MAC address must be 4 (for IPv4 tunnel), 6 (for Ethernet), 16
+          (for IPv6 tunnel), or 20 (for InfiniBand). This option may appear more than once, in which
+          case the lists are merged. If the empty string is assigned to this option, the list of
+          hardware addresses defined prior to this is reset. Defaults to unset.</para>
         </listitem>
       </varlistentry>
 
           <para>A whitespace-separated list of hardware's permanent addresses. While
           <varname>MACAddress=</varname> matches the device's current MAC address, this matches the
           device's permanent MAC address, which may be different from the current one. Use full
-          colon-, hyphen- or dot-delimited hexadecimal. This option may appear more than once, in
-          which case the lists are merged. If the empty string is assigned to this option, the list
-          of hardware addresses defined prior to this is reset.</para>
+          colon-, hyphen- or dot-delimited hexadecimal, or IPv4 or IPv6 address format. This option may
+          appear more than once, in which case the lists are merged. If the empty string is assigned to
+          this option, the list of hardware addresses defined prior to this is reset. Defaults to
+          unset.</para>
         </listitem>
       </varlistentry>
 
index a63b1704c1ae4f41e2108dd6cdef65897effd4cd..174e695c37930051849cf0f579ec8a7d3ccdcc4a 100644 (file)
@@ -1201,8 +1201,8 @@ static int link_get_network(Link *link, Network **ret) {
                 r = net_match_config(
                                 &network->match,
                                 link->sd_device,
-                                link->hw_addr.length == ETH_ALEN ? &link->hw_addr.ether : NULL,
-                                link->permanent_hw_addr.length == ETH_ALEN ? &link->permanent_hw_addr.ether : NULL,
+                                &link->hw_addr,
+                                &link->permanent_hw_addr,
                                 link->driver,
                                 link->iftype,
                                 link->ifname,
index 4f141c3c2967e94e364b48f90e2130b9909bffdf..5b3e4eee3035725da0324c8e53032288394d3c34 100644 (file)
@@ -7,7 +7,7 @@
 #include "string-util.h"
 #include "strv.h"
 
-static int property_get_ether_addrs(
+static int property_get_hw_addrs(
                 sd_bus *bus,
                 const char *path,
                 const char *interface,
@@ -16,7 +16,7 @@ static int property_get_ether_addrs(
                 void *userdata,
                 sd_bus_error *error) {
 
-        const struct ether_addr *p;
+        const struct hw_addr_data *p;
         Set *s;
         int r;
 
@@ -31,7 +31,7 @@ static int property_get_ether_addrs(
                 return r;
 
         SET_FOREACH(p, s) {
-                r = sd_bus_message_append(reply, "s", ETHER_ADDR_TO_STR(p));
+                r = sd_bus_message_append(reply, "s", HW_ADDR_TO_STR(p));
                 if (r < 0)
                         return r;
         }
@@ -44,7 +44,7 @@ static const sd_bus_vtable network_vtable[] = {
 
         SD_BUS_PROPERTY("Description", "s", NULL, offsetof(Network, description), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("SourcePath", "s", NULL, offsetof(Network, filename), SD_BUS_VTABLE_PROPERTY_CONST),
-        SD_BUS_PROPERTY("MatchMAC", "as", property_get_ether_addrs, offsetof(Network, match.mac), SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("MatchMAC", "as", property_get_hw_addrs, offsetof(Network, match.hw_addr), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("MatchPath", "as", NULL, offsetof(Network, match.path), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("MatchDriver", "as", NULL, offsetof(Network, match.driver), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("MatchType", "as", NULL, offsetof(Network, match.iftype), SD_BUS_VTABLE_PROPERTY_CONST),
index 2fdfb1668949eaaeca7e9b21b55136f3647cd9f6..ac44083b4541ee079b5cd6bf8ef3ba702b92a014 100644 (file)
@@ -45,8 +45,8 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-Match.MACAddress,                            config_parse_ether_addrs,                                 0,                             offsetof(Network, match.mac)
-Match.PermanentMACAddress,                   config_parse_ether_addrs,                                 0,                             offsetof(Network, match.permanent_mac)
+Match.MACAddress,                            config_parse_hw_addrs,                                    0,                             offsetof(Network, match.hw_addr)
+Match.PermanentMACAddress,                   config_parse_hw_addrs,                                    0,                             offsetof(Network, match.permanent_hw_addr)
 Match.Path,                                  config_parse_match_strv,                                  0,                             offsetof(Network, match.path)
 Match.Driver,                                config_parse_match_strv,                                  0,                             offsetof(Network, match.driver)
 Match.Type,                                  config_parse_match_strv,                                  0,                             offsetof(Network, match.iftype)
index 6be8f1cbcea460c391e922a08dbaae6ee26f75d0..fbd7bd0784bcd1b435468ed3ee78a832e19a9965 100644 (file)
@@ -17,8 +17,8 @@ void net_match_clear(NetMatch *match) {
         if (!match)
                 return;
 
-        match->mac = set_free(match->mac);
-        match->permanent_mac = set_free(match->permanent_mac);
+        match->hw_addr = set_free(match->hw_addr);
+        match->permanent_hw_addr = set_free(match->permanent_hw_addr);
         match->path = strv_free(match->path);
         match->driver = strv_free(match->driver);
         match->iftype = strv_free(match->iftype);
@@ -33,8 +33,8 @@ bool net_match_is_empty(const NetMatch *match) {
         assert(match);
 
         return
-                set_isempty(match->mac) &&
-                set_isempty(match->permanent_mac) &&
+                set_isempty(match->hw_addr) &&
+                set_isempty(match->permanent_hw_addr) &&
                 strv_isempty(match->path) &&
                 strv_isempty(match->driver) &&
                 strv_isempty(match->iftype) &&
@@ -122,8 +122,8 @@ static int net_condition_test_property(char * const *match_property, sd_device *
 int net_match_config(
                 const NetMatch *match,
                 sd_device *device,
-                const struct ether_addr *mac,
-                const struct ether_addr *permanent_mac,
+                const struct hw_addr_data *hw_addr,
+                const struct hw_addr_data *permanent_hw_addr,
                 const char *driver,
                 unsigned short iftype,
                 const char *ifname,
@@ -150,13 +150,12 @@ int net_match_config(
                         (void) sd_device_get_sysname(device, &ifname);
         }
 
-        if (match->mac && (!mac || !set_contains(match->mac, mac)))
+        if (match->hw_addr && (!hw_addr || !set_contains(match->hw_addr, hw_addr)))
                 return false;
 
-        if (match->permanent_mac &&
-            (!permanent_mac ||
-             ether_addr_is_null(permanent_mac) ||
-             !set_contains(match->permanent_mac, permanent_mac)))
+        if (match->permanent_hw_addr &&
+            (!permanent_hw_addr ||
+             !set_contains(match->permanent_hw_addr, permanent_hw_addr)))
                 return false;
 
         if (!net_condition_test_strv(match->path, path))
index 4f8e30a27164bb2649435a1196bfaf6c77348a36..e767439335d532bc522cc62508622d7892b4780d 100644 (file)
@@ -11,8 +11,8 @@
 #include "set.h"
 
 typedef struct NetMatch {
-        Set *mac;
-        Set *permanent_mac;
+        Set *hw_addr;
+        Set *permanent_hw_addr;
         char **path;
         char **driver;
         char **iftype;
@@ -29,8 +29,8 @@ bool net_match_is_empty(const NetMatch *match);
 int net_match_config(
                 const NetMatch *match,
                 sd_device *device,
-                const struct ether_addr *mac,
-                const struct ether_addr *permanent_mac,
+                const struct hw_addr_data *hw_addr,
+                const struct hw_addr_data *permanent_hw_addr,
                 const char *driver,
                 unsigned short iftype,
                 const char *ifname,
index a3efb4e6c7727e16e55bc78582e1226c9f05be52..5e570f00fb9f7d82f2f38f739c1472e118243202 100644 (file)
@@ -21,8 +21,8 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-Match.MACAddress,                          config_parse_ether_addrs,              0,                             offsetof(LinkConfig, match.mac)
-Match.PermanentMACAddress,                 config_parse_ether_addrs,              0,                             offsetof(LinkConfig, match.permanent_mac)
+Match.MACAddress,                          config_parse_hw_addrs,                 0,                             offsetof(LinkConfig, match.hw_addr)
+Match.PermanentMACAddress,                 config_parse_hw_addrs,                 0,                             offsetof(LinkConfig, match.permanent_hw_addr)
 Match.OriginalName,                        config_parse_match_ifnames,            0,                             offsetof(LinkConfig, match.ifname)
 Match.Path,                                config_parse_match_strv,               0,                             offsetof(LinkConfig, match.path)
 Match.Driver,                              config_parse_match_strv,               0,                             offsetof(LinkConfig, match.driver)
index 95450772b14067fb5b326ee200f823715abe2d7e..fb108b7551e8ee2316e0964cff855e5110f84377 100644 (file)
@@ -386,9 +386,7 @@ int link_config_get(LinkConfigContext *ctx, sd_netlink **rtnl, sd_device *device
         (void) link_unsigned_attribute(device, "name_assign_type", &name_assign_type);
 
         LIST_FOREACH(links, link, ctx->links) {
-                r = net_match_config(&link->match, device,
-                                     hw_addr.length == ETH_ALEN ? &hw_addr.ether : NULL,
-                                     permanent_hw_addr.length == ETH_ALEN ? &permanent_hw_addr.ether : NULL,
+                r = net_match_config(&link->match, device, &hw_addr, &permanent_hw_addr,
                                      NULL, iftype, NULL, NULL, 0, NULL, NULL);
                 if (r < 0)
                         return r;