udev/net: split out udev property assignment logic
No functional change, just refactoring.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "creds-util.h"
|
||||
#include "device-private.h"
|
||||
#include "device-util.h"
|
||||
#include "escape.h"
|
||||
#include "ethtool-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
@@ -34,6 +35,7 @@
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "udev-builtin.h"
|
||||
#include "utf8.h"
|
||||
|
||||
struct LinkConfigContext {
|
||||
@@ -921,7 +923,38 @@ static int link_apply_sr_iov_config(Link *link, sd_netlink **rtnl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link) {
|
||||
static int link_apply_udev_properties(Link *link, bool test) {
|
||||
LinkConfig *config;
|
||||
sd_device *device;
|
||||
|
||||
assert(link);
|
||||
|
||||
config = ASSERT_PTR(link->config);
|
||||
device = ASSERT_PTR(link->device);
|
||||
|
||||
(void) udev_builtin_add_property(device, test, "ID_NET_LINK_FILE", config->filename);
|
||||
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
STRV_FOREACH(d, config->dropins) {
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
|
||||
escaped = xescape(*d, ":");
|
||||
if (!escaped)
|
||||
return log_oom();
|
||||
|
||||
if (!strextend_with_separator(&joined, ":", escaped))
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
(void) udev_builtin_add_property(device, test, "ID_NET_LINK_FILE_DROPINS", joined);
|
||||
|
||||
if (link->new_name)
|
||||
(void) udev_builtin_add_property(device, test, "ID_NET_NAME", link->new_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link, bool test) {
|
||||
int r;
|
||||
|
||||
assert(ctx);
|
||||
@@ -948,6 +981,10 @@ int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = link_apply_udev_properties(link, test);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ Link *link_free(Link *link);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_free);
|
||||
|
||||
int link_get_config(LinkConfigContext *ctx, Link *link);
|
||||
int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link);
|
||||
int link_apply_config(LinkConfigContext *ctx, sd_netlink **rtnl, Link *link, bool test);
|
||||
|
||||
const char *mac_address_policy_to_string(MACAddressPolicy p) _const_;
|
||||
MACAddressPolicy mac_address_policy_from_string(const char *p) _pure_;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "alloc-util.h"
|
||||
#include "device-private.h"
|
||||
#include "device-util.h"
|
||||
#include "escape.h"
|
||||
#include "errno-util.h"
|
||||
#include "link-config.h"
|
||||
#include "log.h"
|
||||
@@ -16,7 +15,6 @@ static LinkConfigContext *ctx = NULL;
|
||||
static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv, bool test) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
_cleanup_(link_freep) Link *link = NULL;
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
int r;
|
||||
|
||||
if (argc > 1)
|
||||
@@ -61,31 +59,14 @@ static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv, bool
|
||||
return log_device_error_errno(dev, r, "Failed to get link config: %m");
|
||||
}
|
||||
|
||||
r = link_apply_config(ctx, &event->rtnl, link);
|
||||
r = link_apply_config(ctx, &event->rtnl, link, test);
|
||||
if (r == -ENODEV)
|
||||
log_device_debug_errno(dev, r, "Link vanished while applying configuration, ignoring.");
|
||||
else if (r < 0)
|
||||
log_device_warning_errno(dev, r, "Could not apply link configuration, ignoring: %m");
|
||||
|
||||
udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->config->filename);
|
||||
if (link->new_name)
|
||||
udev_builtin_add_property(dev, test, "ID_NET_NAME", link->new_name);
|
||||
|
||||
event->altnames = TAKE_PTR(link->altnames);
|
||||
|
||||
STRV_FOREACH(d, link->config->dropins) {
|
||||
_cleanup_free_ char *escaped = NULL;
|
||||
|
||||
escaped = xescape(*d, ":");
|
||||
if (!escaped)
|
||||
return log_oom();
|
||||
|
||||
if (!strextend_with_separator(&joined, ":", escaped))
|
||||
return log_oom();
|
||||
}
|
||||
|
||||
udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE_DROPINS", joined);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user