blob: de6b7dbead8b24f35dd978abb517eee9e5b0a2f4 [file] [log] [blame]
From a99f62ee2c89b3631a23426eedfa477aa9d8dbd9 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/9] 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 | 3 +++
src/network/networkd-varlink.c | 34 ++++++++++++++++++++++++++++++++++
src/network/networkd-varlink.h | 7 +++++++
5 files changed, 53 insertions(+)
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 5857439c5a..430dadbf05 100644
--- a/src/network/meson.build
+++ b/src/network/meson.build
@@ -137,6 +137,8 @@ sources = files('''
networkd-sysctl.h
networkd-util.c
networkd-util.h
+ networkd-varlink.c
+ networkd-varlink.h
networkd-wifi.c
networkd-wifi.h
tc/cake.c
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 7e89366ae8..9f6a2553f6 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -41,6 +41,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 "ordered-set.h"
#include "path-lookup.h"
@@ -543,6 +544,8 @@ Manager* manager_free(Manager *m) {
m->fw_ctx = fw_ctx_free(m->fw_ctx);
+ manager_varlink_done(m);
+
return mfree(m);
}
@@ -552,6 +555,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 36313589a3..a0c0336ce5 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;
@@ -95,6 +96,8 @@ struct Manager {
FirewallContext *fw_ctx;
OrderedSet *request_queue;
+
+ VarlinkServer *varlink_server;
};
int manager_new(Manager **ret, bool test_mode);
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.34.1