blob: 2567d7fd214e99644480a93787494e1916df1953 [file] [log] [blame]
From 36f46b1f60453bdbb8841bd86724ff868149594b 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 4e137d7b9e..2c97da60d3 100644
--- a/src/network/meson.build
+++ b/src/network/meson.build
@@ -129,6 +129,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 374d27bef3..5e53498711 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -38,6 +38,7 @@
#include "networkd-routing-policy-rule.h"
#include "networkd-speed-meter.h"
#include "networkd-state-file.h"
+#include "networkd-varlink.h"
#include "ordered-set.h"
#include "path-lookup.h"
#include "path-util.h"
@@ -509,6 +510,8 @@ Manager* manager_free(Manager *m) {
m->fw_ctx = fw_ctx_free(m->fw_ctx);
+ manager_varlink_done(m);
+
return mfree(m);
}
@@ -518,6 +521,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 4ee48f3468..f8d4d00db2 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;
@@ -99,6 +100,8 @@ struct Manager {
FirewallContext *fw_ctx;
OrderedSet *request_queue;
+
+ VarlinkServer *varlink_server;
};
int manager_new(Manager **ret);
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.33.0