network,udev: make .network and .link file can match with hardware address longer or shorter than ETH_ALEN
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
81e1590e2d
commit
5213507113
@@ -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)
|
||||
|
||||
+10
-11
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user