blob: bb16f0cc164448d81c8f17cd106199e69ae264f9 [file] [log] [blame]
From 00b203ad445b40faf5836a3ca9a6c1ec89165c23 Mon Sep 17 00:00:00 2001
From: Tomas Pecka <peckato1@users.noreply.github.com>
Date: Tue, 24 Aug 2021 14:59:40 +0200
Subject: [PATCH 2/7] network: Add varlink server
Add a varlink server. In the next commits, we will implement a method
that queries the LLDP neighbors.
---
src/network/meson.build | 2 ++
src/network/networkd-manager.c | 7 +++++++
src/network/networkd-manager.h | 11 +++++++----
src/network/networkd-varlink.c | 34 ++++++++++++++++++++++++++++++++++
src/network/networkd-varlink.h | 7 +++++++
5 files changed, 57 insertions(+), 4 deletions(-)
create mode 100644 src/network/networkd-varlink.c
create mode 100644 src/network/networkd-varlink.h
diff --git a/src/network/meson.build b/src/network/meson.build
index b09c18dbbd..90ae4ed238 100644
--- a/src/network/meson.build
+++ b/src/network/meson.build
@@ -145,6 +145,8 @@ sources = files(
'networkd-sysctl.h',
'networkd-util.c',
'networkd-util.h',
+ 'networkd-varlink.c',
+ 'networkd-varlink.h',
'networkd-wifi.c',
'networkd-wifi.h',
'networkd-wiphy.c',
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index cdfd29bc0e..9f859408a1 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -44,6 +44,7 @@
#include "networkd-routing-policy-rule.h"
#include "networkd-speed-meter.h"
#include "networkd-state-file.h"
+#include "networkd-varlink.h"
#include "networkd-wifi.h"
#include "networkd-wiphy.h"
#include "ordered-set.h"
@@ -667,6 +668,8 @@ Manager* manager_free(Manager *m) {
m->fw_ctx = fw_ctx_free(m->fw_ctx);
+ manager_varlink_done(m);
+
return mfree(m);
}
@@ -676,6 +679,10 @@ int manager_start(Manager *m) {
assert(m);
+ r = manager_varlink_init(m);
+ if (r < 0)
+ return r;
+
r = manager_start_speed_meter(m);
if (r < 0)
return log_error_errno(r, "Failed to initialize speed meter: %m");
diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h
index 40e6092f85..dfdd44baf8 100644
--- a/src/network/networkd-manager.h
+++ b/src/network/networkd-manager.h
@@ -16,6 +16,7 @@
#include "ordered-set.h"
#include "set.h"
#include "time-util.h"
+#include "varlink.h"
struct Manager {
sd_netlink *rtnl;
@@ -62,8 +63,8 @@ struct Manager {
bool has_product_uuid;
bool product_uuid_requested;
- char* dynamic_hostname;
- char* dynamic_timezone;
+ char *dynamic_hostname;
+ char *dynamic_timezone;
Set *rules;
@@ -100,10 +101,12 @@ struct Manager {
OrderedSet *request_queue;
Hashmap *tuntap_fds_by_name;
+
+ VarlinkServer *varlink_server;
};
int manager_new(Manager **ret, bool test_mode);
-Manager* manager_free(Manager *m);
+Manager *manager_free(Manager *m);
int manager_setup(Manager *m);
int manager_start(Manager *m);
@@ -115,4 +118,4 @@ int manager_enumerate(Manager *m);
int manager_set_hostname(Manager *m, const char *hostname);
int manager_set_timezone(Manager *m, const char *timezone);
-DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Manager *, manager_free);
diff --git a/src/network/networkd-varlink.c b/src/network/networkd-varlink.c
new file mode 100644
index 0000000000..57d8acb967
--- /dev/null
+++ b/src/network/networkd-varlink.c
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "networkd-varlink.h"
+
+int manager_varlink_init(Manager *m) {
+ _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL;
+ int r;
+
+ assert(m);
+
+ if (m->varlink_server)
+ return 0;
+
+ r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID);
+ if (r < 0)
+ return log_error_errno(r, "Failed to allocate varlink server object: %m");
+
+ r = varlink_server_listen_address(s, "/run/systemd/netif/io.systemd.Network", 0666);
+ if (r < 0)
+ return log_error_errno(r, "Failed to bind to varlink socket: %m");
+
+ r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to attach varlink connection to event loop: %m");
+
+ m->varlink_server = TAKE_PTR(s);
+ return 0;
+}
+
+void manager_varlink_done(Manager *m) {
+ assert(m);
+
+ m->varlink_server = varlink_server_unref(m->varlink_server);
+}
diff --git a/src/network/networkd-varlink.h b/src/network/networkd-varlink.h
new file mode 100644
index 0000000000..657e054a51
--- /dev/null
+++ b/src/network/networkd-varlink.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "networkd-manager.h"
+
+int manager_varlink_init(Manager *m);
+void manager_varlink_done(Manager *m);
--
2.41.0