network,udev: make MACAddress= in [Match] section take multiple MAC addresses
This commit is contained in:
@@ -97,7 +97,7 @@ static bool net_condition_test_strv(char * const *raw_patterns,
|
|||||||
return string && strv_fnmatch(raw_patterns, string, 0);
|
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_paths,
|
||||||
char * const *match_drivers,
|
char * const *match_drivers,
|
||||||
char * const *match_types,
|
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)
|
if (match_arch && condition_test(match_arch) <= 0)
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
if (!net_condition_test_strv(match_paths, dev_path))
|
if (!net_condition_test_strv(match_paths, dev_path))
|
||||||
@@ -329,7 +329,7 @@ int config_parse_hwaddrs(const char *unit,
|
|||||||
|
|
||||||
if (isempty(rvalue)) {
|
if (isempty(rvalue)) {
|
||||||
/* Empty assignment resets the list */
|
/* Empty assignment resets the list */
|
||||||
set_free_free(*hwaddrs);
|
*hwaddrs = set_free_free(*hwaddrs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ int config_parse_hwaddrs(const char *unit,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = new0(struct ether_addr, 1);
|
n = new(struct ether_addr, 1);
|
||||||
if (!n)
|
if (!n)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
|
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
|
||||||
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
|
#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_path,
|
||||||
char * const *match_driver,
|
char * const *match_driver,
|
||||||
char * const *match_type,
|
char * const *match_type,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
|
#include "ether-addr-util.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
@@ -19,23 +20,24 @@ static int property_get_ether_addrs(
|
|||||||
void *userdata,
|
void *userdata,
|
||||||
sd_bus_error *error) {
|
sd_bus_error *error) {
|
||||||
|
|
||||||
Network *n = userdata;
|
char buf[ETHER_ADDR_TO_STRING_MAX];
|
||||||
const char *ether = NULL;
|
const struct ether_addr *p;
|
||||||
|
Iterator i;
|
||||||
|
Set *s;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(bus);
|
assert(bus);
|
||||||
assert(reply);
|
assert(reply);
|
||||||
assert(n);
|
assert(userdata);
|
||||||
|
|
||||||
if (n->match_mac)
|
s = *(Set **) userdata;
|
||||||
ether = ether_ntoa(n->match_mac);
|
|
||||||
|
|
||||||
r = sd_bus_message_open_container(reply, 'a', "s");
|
r = sd_bus_message_open_container(reply, 'a', "s");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (ether) {
|
SET_FOREACH(p, s, i) {
|
||||||
r = sd_bus_message_append(reply, "s", strempty(ether));
|
r = sd_bus_message_append(reply, "s", ether_addr_to_string(p, buf));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
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("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("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("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("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),
|
SD_BUS_PROPERTY("MatchType", "as", NULL, offsetof(Network, match_type), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ struct ConfigPerfItem;
|
|||||||
%struct-type
|
%struct-type
|
||||||
%includes
|
%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.Path, config_parse_strv, 0, offsetof(Network, match_path)
|
||||||
Match.Driver, config_parse_strv, 0, offsetof(Network, match_driver)
|
Match.Driver, config_parse_strv, 0, offsetof(Network, match_driver)
|
||||||
Match.Type, config_parse_strv, 0, offsetof(Network, match_type)
|
Match.Type, config_parse_strv, 0, offsetof(Network, match_type)
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ void network_free(Network *network) {
|
|||||||
|
|
||||||
free(network->filename);
|
free(network->filename);
|
||||||
|
|
||||||
free(network->match_mac);
|
set_free_free(network->match_mac);
|
||||||
strv_free(network->match_path);
|
strv_free(network->match_path);
|
||||||
strv_free(network->match_driver);
|
strv_free(network->match_driver);
|
||||||
strv_free(network->match_type);
|
strv_free(network->match_type);
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ struct Network {
|
|||||||
char *filename;
|
char *filename;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
struct ether_addr *match_mac;
|
Set *match_mac;
|
||||||
char **match_path;
|
char **match_path;
|
||||||
char **match_driver;
|
char **match_driver;
|
||||||
char **match_type;
|
char **match_type;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ struct ConfigPerfItem;
|
|||||||
%struct-type
|
%struct-type
|
||||||
%includes
|
%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.OriginalName, config_parse_ifnames, 0, offsetof(link_config, match_name)
|
||||||
Match.Path, config_parse_strv, 0, offsetof(link_config, match_path)
|
Match.Path, config_parse_strv, 0, offsetof(link_config, match_path)
|
||||||
Match.Driver, config_parse_strv, 0, offsetof(link_config, match_driver)
|
Match.Driver, config_parse_strv, 0, offsetof(link_config, match_driver)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ static void link_config_free(link_config *link) {
|
|||||||
|
|
||||||
free(link->filename);
|
free(link->filename);
|
||||||
|
|
||||||
free(link->match_mac);
|
set_free_free(link->match_mac);
|
||||||
strv_free(link->match_path);
|
strv_free(link->match_path);
|
||||||
strv_free(link->match_driver);
|
strv_free(link->match_driver);
|
||||||
strv_free(link->match_type);
|
strv_free(link->match_type);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "condition.h"
|
#include "condition.h"
|
||||||
#include "ethtool-util.h"
|
#include "ethtool-util.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "set.h"
|
||||||
|
|
||||||
typedef struct link_config_ctx link_config_ctx;
|
typedef struct link_config_ctx link_config_ctx;
|
||||||
typedef struct link_config link_config;
|
typedef struct link_config link_config;
|
||||||
@@ -38,7 +39,7 @@ typedef enum NamePolicy {
|
|||||||
struct link_config {
|
struct link_config {
|
||||||
char *filename;
|
char *filename;
|
||||||
|
|
||||||
struct ether_addr *match_mac;
|
Set *match_mac;
|
||||||
char **match_path;
|
char **match_path;
|
||||||
char **match_driver;
|
char **match_driver;
|
||||||
char **match_type;
|
char **match_type;
|
||||||
|
|||||||
Reference in New Issue
Block a user