summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/netdev/netdev.c20
-rw-r--r--src/network/netdev/netdev.h2
2 files changed, 11 insertions, 11 deletions
diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c
index 5530760e19..7afe30f7fb 100644
--- a/src/network/netdev/netdev.c
+++ b/src/network/netdev/netdev.c
@@ -138,7 +138,7 @@ static void netdev_free(NetDev *netdev) {
netdev_cancel_callbacks(netdev);
- if (netdev->ifname)
+ if (netdev->ifname && netdev->manager)
hashmap_remove(netdev->manager->netdevs, netdev->ifname);
free(netdev->filename);
@@ -601,8 +601,7 @@ int netdev_join(NetDev *netdev, Link *link, sd_netlink_message_handler_t callbac
}
static int netdev_load_one(Manager *manager, const char *filename) {
- _cleanup_netdev_unref_ NetDev *netdev = NULL;
- _cleanup_free_ NetDev *netdev_raw = NULL;
+ _cleanup_netdev_unref_ NetDev *netdev_raw = NULL, *netdev = NULL;
_cleanup_fclose_ FILE *file = NULL;
const char *dropin_dirname;
bool independent = false;
@@ -628,9 +627,11 @@ static int netdev_load_one(Manager *manager, const char *filename) {
if (!netdev_raw)
return log_oom();
+ netdev_raw->n_ref = 1;
netdev_raw->kind = _NETDEV_KIND_INVALID;
- dropin_dirname = strjoina(basename(filename), ".d");
+ netdev_raw->state = _NETDEV_STATE_INVALID;
+ dropin_dirname = strjoina(basename(filename), ".d");
r = config_parse_many(filename, network_dirs, dropin_dirname,
"Match\0NetDev\0",
config_item_perf_lookup, network_netdev_gperf_lookup,
@@ -638,10 +639,6 @@ static int netdev_load_one(Manager *manager, const char *filename) {
if (r < 0)
return r;
- r = fseek(file, 0, SEEK_SET);
- if (r < 0)
- return -errno;
-
/* skip out early if configuration does not match the environment */
if (net_match_config(NULL, NULL, NULL, NULL, NULL,
netdev_raw->match_host, netdev_raw->match_virt,
@@ -659,15 +656,18 @@ static int netdev_load_one(Manager *manager, const char *filename) {
return 0;
}
+ r = fseek(file, 0, SEEK_SET);
+ if (r < 0)
+ return -errno;
+
netdev = malloc0(NETDEV_VTABLE(netdev_raw)->object_size);
if (!netdev)
return log_oom();
netdev->n_ref = 1;
netdev->manager = manager;
- netdev->state = _NETDEV_STATE_INVALID;
netdev->kind = netdev_raw->kind;
- netdev->ifname = netdev_raw->ifname;
+ netdev->state = _NETDEV_STATE_INVALID;
if (NETDEV_VTABLE(netdev)->init)
NETDEV_VTABLE(netdev)->init(netdev);
diff --git a/src/network/netdev/netdev.h b/src/network/netdev/netdev.h
index ec65251464..24915b2b04 100644
--- a/src/network/netdev/netdev.h
+++ b/src/network/netdev/netdev.h
@@ -143,7 +143,7 @@ typedef struct NetDevVTable {
extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
-#define NETDEV_VTABLE(n) netdev_vtable[(n)->kind]
+#define NETDEV_VTABLE(n) ((n)->kind != _NETDEV_KIND_INVALID ? netdev_vtable[(n)->kind] : NULL)
/* For casting a netdev into the various netdev kinds */
#define DEFINE_NETDEV_CAST(UPPERCASE, MixedCase) \