mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-02 09:47:03 +03:00
network,udev: make .network and .link file can match with hardware address longer or shorter than ETH_ALEN
This commit is contained in:
parent
81e1590e2d
commit
5213507113
@ -89,12 +89,48 @@
|
||||
<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>
|
||||
|
||||
@ -104,9 +140,10 @@
|
||||
<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>
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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),
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user