Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 1 | From a99f62ee2c89b3631a23426eedfa477aa9d8dbd9 Mon Sep 17 00:00:00 2001 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 2 | From: Tomas Pecka <peckato1@users.noreply.github.com> |
| 3 | Date: Tue, 24 Aug 2021 14:59:40 +0200 |
| 4 | Subject: [PATCH 2/9] network: Add varlink server |
| 5 | |
| 6 | Add a varlink server. In the next commits, we will implement a method |
| 7 | that queries the LLDP neighbors. |
| 8 | --- |
| 9 | src/network/meson.build | 2 ++ |
| 10 | src/network/networkd-manager.c | 7 +++++++ |
| 11 | src/network/networkd-manager.h | 3 +++ |
| 12 | src/network/networkd-varlink.c | 34 ++++++++++++++++++++++++++++++++++ |
| 13 | src/network/networkd-varlink.h | 7 +++++++ |
| 14 | 5 files changed, 53 insertions(+) |
| 15 | create mode 100644 src/network/networkd-varlink.c |
| 16 | create mode 100644 src/network/networkd-varlink.h |
| 17 | |
| 18 | diff --git a/src/network/meson.build b/src/network/meson.build |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 19 | index 5857439c5a..430dadbf05 100644 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 20 | --- a/src/network/meson.build |
| 21 | +++ b/src/network/meson.build |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 22 | @@ -137,6 +137,8 @@ sources = files(''' |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 23 | networkd-sysctl.h |
| 24 | networkd-util.c |
| 25 | networkd-util.h |
| 26 | + networkd-varlink.c |
| 27 | + networkd-varlink.h |
| 28 | networkd-wifi.c |
| 29 | networkd-wifi.h |
| 30 | tc/cake.c |
| 31 | diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 32 | index 7e89366ae8..9f6a2553f6 100644 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 33 | --- a/src/network/networkd-manager.c |
| 34 | +++ b/src/network/networkd-manager.c |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 35 | @@ -41,6 +41,7 @@ |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 36 | #include "networkd-routing-policy-rule.h" |
| 37 | #include "networkd-speed-meter.h" |
| 38 | #include "networkd-state-file.h" |
| 39 | +#include "networkd-varlink.h" |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 40 | #include "networkd-wifi.h" |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 41 | #include "ordered-set.h" |
| 42 | #include "path-lookup.h" |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 43 | @@ -543,6 +544,8 @@ Manager* manager_free(Manager *m) { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 44 | |
| 45 | m->fw_ctx = fw_ctx_free(m->fw_ctx); |
| 46 | |
| 47 | + manager_varlink_done(m); |
| 48 | + |
| 49 | return mfree(m); |
| 50 | } |
| 51 | |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 52 | @@ -552,6 +555,10 @@ int manager_start(Manager *m) { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 53 | |
| 54 | assert(m); |
| 55 | |
| 56 | + r = manager_varlink_init(m); |
| 57 | + if (r < 0) |
| 58 | + return r; |
| 59 | + |
| 60 | r = manager_start_speed_meter(m); |
| 61 | if (r < 0) |
| 62 | return log_error_errno(r, "Failed to initialize speed meter: %m"); |
| 63 | diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 64 | index 36313589a3..a0c0336ce5 100644 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 65 | --- a/src/network/networkd-manager.h |
| 66 | +++ b/src/network/networkd-manager.h |
| 67 | @@ -16,6 +16,7 @@ |
| 68 | #include "ordered-set.h" |
| 69 | #include "set.h" |
| 70 | #include "time-util.h" |
| 71 | +#include "varlink.h" |
| 72 | |
| 73 | struct Manager { |
| 74 | sd_netlink *rtnl; |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 75 | @@ -95,6 +96,8 @@ struct Manager { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 76 | FirewallContext *fw_ctx; |
| 77 | |
| 78 | OrderedSet *request_queue; |
| 79 | + |
| 80 | + VarlinkServer *varlink_server; |
| 81 | }; |
| 82 | |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 83 | int manager_new(Manager **ret, bool test_mode); |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 84 | diff --git a/src/network/networkd-varlink.c b/src/network/networkd-varlink.c |
| 85 | new file mode 100644 |
| 86 | index 0000000000..57d8acb967 |
| 87 | --- /dev/null |
| 88 | +++ b/src/network/networkd-varlink.c |
| 89 | @@ -0,0 +1,34 @@ |
| 90 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 91 | + |
| 92 | +#include "networkd-varlink.h" |
| 93 | + |
| 94 | +int manager_varlink_init(Manager *m) { |
| 95 | + _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; |
| 96 | + int r; |
| 97 | + |
| 98 | + assert(m); |
| 99 | + |
| 100 | + if (m->varlink_server) |
| 101 | + return 0; |
| 102 | + |
| 103 | + r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID); |
| 104 | + if (r < 0) |
| 105 | + return log_error_errno(r, "Failed to allocate varlink server object: %m"); |
| 106 | + |
| 107 | + r = varlink_server_listen_address(s, "/run/systemd/netif/io.systemd.Network", 0666); |
| 108 | + if (r < 0) |
| 109 | + return log_error_errno(r, "Failed to bind to varlink socket: %m"); |
| 110 | + |
| 111 | + r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); |
| 112 | + if (r < 0) |
| 113 | + return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); |
| 114 | + |
| 115 | + m->varlink_server = TAKE_PTR(s); |
| 116 | + return 0; |
| 117 | +} |
| 118 | + |
| 119 | +void manager_varlink_done(Manager *m) { |
| 120 | + assert(m); |
| 121 | + |
| 122 | + m->varlink_server = varlink_server_unref(m->varlink_server); |
| 123 | +} |
| 124 | diff --git a/src/network/networkd-varlink.h b/src/network/networkd-varlink.h |
| 125 | new file mode 100644 |
| 126 | index 0000000000..657e054a51 |
| 127 | --- /dev/null |
| 128 | +++ b/src/network/networkd-varlink.h |
| 129 | @@ -0,0 +1,7 @@ |
| 130 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 131 | +#pragma once |
| 132 | + |
| 133 | +#include "networkd-manager.h" |
| 134 | + |
| 135 | +int manager_varlink_init(Manager *m); |
| 136 | +void manager_varlink_done(Manager *m); |
| 137 | -- |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame^] | 138 | 2.34.1 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 139 | |