network,udev: make MACAddress= in [Match] section take multiple MAC addresses

This commit is contained in:
Yu Watanabe 2018-05-09 11:59:18 +09:00
parent a7533e3e48
commit e90d037411
9 changed files with 22 additions and 19 deletions

View file

@ -97,7 +97,7 @@ static bool net_condition_test_strv(char * const *raw_patterns,
return string && strv_fnmatch(raw_patterns, string, 0);
}
bool net_match_config(const struct ether_addr *match_mac,
bool net_match_config(Set *match_mac,
char * const *match_paths,
char * const *match_drivers,
char * const *match_types,
@ -129,7 +129,7 @@ bool net_match_config(const struct ether_addr *match_mac,
if (match_arch && condition_test(match_arch) <= 0)
return false;
if (match_mac && (!dev_mac || memcmp(match_mac, dev_mac, ETH_ALEN)))
if (match_mac && dev_mac && !set_contains(match_mac, dev_mac))
return false;
if (!net_condition_test_strv(match_paths, dev_path))
@ -329,7 +329,7 @@ int config_parse_hwaddrs(const char *unit,
if (isempty(rvalue)) {
/* Empty assignment resets the list */
set_free_free(*hwaddrs);
*hwaddrs = set_free_free(*hwaddrs);
return 0;
}
@ -351,7 +351,7 @@ int config_parse_hwaddrs(const char *unit,
return 0;
}
n = new0(struct ether_addr, 1);
n = new(struct ether_addr, 1);
if (!n)
return log_oom();

View file

@ -18,7 +18,7 @@
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
bool net_match_config(const struct ether_addr *match_mac,
bool net_match_config(Set *match_mac,
char * const *match_path,
char * const *match_driver,
char * const *match_type,

View file

@ -6,6 +6,7 @@
***/
#include "alloc-util.h"
#include "ether-addr-util.h"
#include "networkd-manager.h"
#include "string-util.h"
#include "strv.h"
@ -19,23 +20,24 @@ static int property_get_ether_addrs(
void *userdata,
sd_bus_error *error) {
Network *n = userdata;
const char *ether = NULL;
char buf[ETHER_ADDR_TO_STRING_MAX];
const struct ether_addr *p;
Iterator i;
Set *s;
int r;
assert(bus);
assert(reply);
assert(n);
assert(userdata);
if (n->match_mac)
ether = ether_ntoa(n->match_mac);
s = *(Set **) userdata;
r = sd_bus_message_open_container(reply, 'a', "s");
if (r < 0)
return r;
if (ether) {
r = sd_bus_message_append(reply, "s", strempty(ether));
SET_FOREACH(p, s, i) {
r = sd_bus_message_append(reply, "s", ether_addr_to_string(p, buf));
if (r < 0)
return r;
}
@ -48,7 +50,7 @@ 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, 0, 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("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_type), SD_BUS_VTABLE_PROPERTY_CONST),

View file

@ -20,7 +20,7 @@ struct ConfigPerfItem;
%struct-type
%includes
%%
Match.MACAddress, config_parse_hwaddr, 0, offsetof(Network, match_mac)
Match.MACAddress, config_parse_hwaddrs, 0, offsetof(Network, match_mac)
Match.Path, config_parse_strv, 0, offsetof(Network, match_path)
Match.Driver, config_parse_strv, 0, offsetof(Network, match_driver)
Match.Type, config_parse_strv, 0, offsetof(Network, match_type)

View file

@ -353,7 +353,7 @@ void network_free(Network *network) {
free(network->filename);
free(network->match_mac);
set_free_free(network->match_mac);
strv_free(network->match_path);
strv_free(network->match_driver);
strv_free(network->match_type);

View file

@ -103,7 +103,7 @@ struct Network {
char *filename;
char *name;
struct ether_addr *match_mac;
Set *match_mac;
char **match_path;
char **match_driver;
char **match_type;

View file

@ -19,7 +19,7 @@ struct ConfigPerfItem;
%struct-type
%includes
%%
Match.MACAddress, config_parse_hwaddr, 0, offsetof(link_config, match_mac)
Match.MACAddress, config_parse_hwaddrs, 0, offsetof(link_config, match_mac)
Match.OriginalName, config_parse_ifnames, 0, offsetof(link_config, match_name)
Match.Path, config_parse_strv, 0, offsetof(link_config, match_path)
Match.Driver, config_parse_strv, 0, offsetof(link_config, match_driver)

View file

@ -57,7 +57,7 @@ static void link_config_free(link_config *link) {
free(link->filename);
free(link->match_mac);
set_free_free(link->match_mac);
strv_free(link->match_path);
strv_free(link->match_driver);
strv_free(link->match_type);

View file

@ -12,6 +12,7 @@
#include "condition.h"
#include "ethtool-util.h"
#include "list.h"
#include "set.h"
typedef struct link_config_ctx link_config_ctx;
typedef struct link_config link_config;
@ -38,7 +39,7 @@ typedef enum NamePolicy {
struct link_config {
char *filename;
struct ether_addr *match_mac;
Set *match_mac;
char **match_path;
char **match_driver;
char **match_type;