Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 1 | From 00b203ad445b40faf5836a3ca9a6c1ec89165c23 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 |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 4 | Subject: [PATCH 2/7] network: Add varlink server |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 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 +++++++ |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 11 | src/network/networkd-manager.h | 11 +++++++---- |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 12 | src/network/networkd-varlink.c | 34 ++++++++++++++++++++++++++++++++++ |
| 13 | src/network/networkd-varlink.h | 7 +++++++ |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 14 | 5 files changed, 57 insertions(+), 4 deletions(-) |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 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 |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 19 | index b09c18dbbd..90ae4ed238 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 |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 22 | @@ -145,6 +145,8 @@ sources = files( |
Tomáš Pecka | 5e07025 | 2022-05-20 20:41:21 +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', |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 30 | 'networkd-wiphy.c', |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 31 | diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 32 | index cdfd29bc0e..9f859408a1 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 |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 35 | @@ -44,6 +44,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 | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 41 | #include "networkd-wiphy.h" |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 42 | #include "ordered-set.h" |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 43 | @@ -667,6 +668,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 | |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 52 | @@ -676,6 +679,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 |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 64 | index 40e6092f85..dfdd44baf8 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; |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 75 | @@ -62,8 +63,8 @@ struct Manager { |
| 76 | bool has_product_uuid; |
| 77 | bool product_uuid_requested; |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 78 | |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 79 | - char* dynamic_hostname; |
| 80 | - char* dynamic_timezone; |
| 81 | + char *dynamic_hostname; |
| 82 | + char *dynamic_timezone; |
| 83 | |
| 84 | Set *rules; |
| 85 | |
| 86 | @@ -100,10 +101,12 @@ struct Manager { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 87 | OrderedSet *request_queue; |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 88 | |
| 89 | Hashmap *tuntap_fds_by_name; |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 90 | + |
| 91 | + VarlinkServer *varlink_server; |
| 92 | }; |
| 93 | |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 94 | int manager_new(Manager **ret, bool test_mode); |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 95 | -Manager* manager_free(Manager *m); |
| 96 | +Manager *manager_free(Manager *m); |
| 97 | |
| 98 | int manager_setup(Manager *m); |
| 99 | int manager_start(Manager *m); |
| 100 | @@ -115,4 +118,4 @@ int manager_enumerate(Manager *m); |
| 101 | int manager_set_hostname(Manager *m, const char *hostname); |
| 102 | int manager_set_timezone(Manager *m, const char *timezone); |
| 103 | |
| 104 | -DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |
| 105 | +DEFINE_TRIVIAL_CLEANUP_FUNC(Manager *, manager_free); |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 106 | diff --git a/src/network/networkd-varlink.c b/src/network/networkd-varlink.c |
| 107 | new file mode 100644 |
| 108 | index 0000000000..57d8acb967 |
| 109 | --- /dev/null |
| 110 | +++ b/src/network/networkd-varlink.c |
| 111 | @@ -0,0 +1,34 @@ |
| 112 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 113 | + |
| 114 | +#include "networkd-varlink.h" |
| 115 | + |
| 116 | +int manager_varlink_init(Manager *m) { |
| 117 | + _cleanup_(varlink_server_unrefp) VarlinkServer *s = NULL; |
| 118 | + int r; |
| 119 | + |
| 120 | + assert(m); |
| 121 | + |
| 122 | + if (m->varlink_server) |
| 123 | + return 0; |
| 124 | + |
| 125 | + r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID); |
| 126 | + if (r < 0) |
| 127 | + return log_error_errno(r, "Failed to allocate varlink server object: %m"); |
| 128 | + |
| 129 | + r = varlink_server_listen_address(s, "/run/systemd/netif/io.systemd.Network", 0666); |
| 130 | + if (r < 0) |
| 131 | + return log_error_errno(r, "Failed to bind to varlink socket: %m"); |
| 132 | + |
| 133 | + r = varlink_server_attach_event(s, m->event, SD_EVENT_PRIORITY_NORMAL); |
| 134 | + if (r < 0) |
| 135 | + return log_error_errno(r, "Failed to attach varlink connection to event loop: %m"); |
| 136 | + |
| 137 | + m->varlink_server = TAKE_PTR(s); |
| 138 | + return 0; |
| 139 | +} |
| 140 | + |
| 141 | +void manager_varlink_done(Manager *m) { |
| 142 | + assert(m); |
| 143 | + |
| 144 | + m->varlink_server = varlink_server_unref(m->varlink_server); |
| 145 | +} |
| 146 | diff --git a/src/network/networkd-varlink.h b/src/network/networkd-varlink.h |
| 147 | new file mode 100644 |
| 148 | index 0000000000..657e054a51 |
| 149 | --- /dev/null |
| 150 | +++ b/src/network/networkd-varlink.h |
| 151 | @@ -0,0 +1,7 @@ |
| 152 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 153 | +#pragma once |
| 154 | + |
| 155 | +#include "networkd-manager.h" |
| 156 | + |
| 157 | +int manager_varlink_init(Manager *m); |
| 158 | +void manager_varlink_done(Manager *m); |
| 159 | -- |
Tomáš Pecka | 6936b91 | 2023-06-12 11:30:36 +0200 | [diff] [blame^] | 160 | 2.41.0 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 161 | |