• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 23518499972

24 Mar 2026 09:45PM UTC coverage: 72.567% (-0.01%) from 72.581%
23518499972

push

github

web-flow
resolved: add "static RRs" concept (#41213)

split out of #40980

301 of 337 new or added lines in 9 files covered. (89.32%)

3451 existing lines in 67 files now uncovered.

316989 of 436822 relevant lines covered (72.57%)

1153112.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.21
/src/network/networkctl-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <sys/stat.h>
4
#include <unistd.h>
5

6
#include "ansi-color.h"
7
#include "bus-util.h"
8
#include "log.h"
9
#include "networkctl.h"
10
#include "networkctl-util.h"
11
#include "polkit-agent.h"
12
#include "string-util.h"
13
#include "strv.h"
14
#include "varlink-util.h"
15

16
int varlink_connect_networkd(sd_varlink **ret_varlink) {
2,638✔
17
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
2,638✔
18
        sd_json_variant *reply;
2,638✔
19
        uint64_t id;
2,638✔
20
        int r;
2,638✔
21

22
        r = sd_varlink_connect_address(&vl, "/run/systemd/netif/io.systemd.Network");
2,638✔
23
        if (r < 0)
2,638✔
UNCOV
24
                return log_error_errno(r, "Failed to connect to network service /run/systemd/netif/io.systemd.Network: %m");
×
25

26
        (void) sd_varlink_set_description(vl, "varlink-network");
2,638✔
27

28
        r = sd_varlink_set_allow_fd_passing_output(vl, true);
2,638✔
29
        if (r < 0)
2,638✔
UNCOV
30
                return log_error_errno(r, "Failed to allow passing file descriptor through varlink: %m");
×
31

32
        r = varlink_call_and_log(vl, "io.systemd.Network.GetNamespaceId", /* parameters= */ NULL, &reply);
2,638✔
33
        if (r < 0)
2,638✔
34
                return r;
35

36
        static const sd_json_dispatch_field dispatch_table[] = {
2,638✔
37
                { "NamespaceId", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint64, 0, SD_JSON_MANDATORY },
38
                {},
39
        };
40

41
        r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &id);
2,638✔
42
        if (r < 0)
2,638✔
43
                return r;
44

45
        if (id == 0)
2,638✔
UNCOV
46
                log_debug("systemd-networkd.service not running in a network namespace (?), skipping netns check.");
×
47
        else {
48
                struct stat st;
2,638✔
49

50
                if (stat("/proc/self/ns/net", &st) < 0)
2,638✔
UNCOV
51
                        return log_error_errno(errno, "Failed to determine our own network namespace ID: %m");
×
52

53
                if (id != st.st_ino)
2,638✔
UNCOV
54
                        return log_error_errno(SYNTHETIC_ERRNO(EREMOTE),
×
55
                                               "networkctl must be invoked in same network namespace as systemd-networkd.service.");
56
        }
57

58
        if (ret_varlink)
2,638✔
59
                *ret_varlink = TAKE_PTR(vl);
2,638✔
60
        return 0;
61
}
62

63
int reload_networkd(void) {
153✔
64
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
153✔
65
        int r;
153✔
66

67
        r = varlink_connect_networkd(&vl);
153✔
68
        if (r < 0)
153✔
69
                return r;
70

71
        (void) polkit_agent_open_if_enabled(BUS_TRANSPORT_LOCAL, arg_ask_password);
153✔
72

73
        return varlink_callbo_and_log(
153✔
74
                        vl,
75
                        "io.systemd.service.Reload",
76
                        /* reply= */ NULL,
77
                        SD_JSON_BUILD_PAIR_BOOLEAN("allowInteractiveAuthentication", arg_ask_password));
78
}
79

80
int reload_udevd(void) {
1✔
81
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
1✔
82
        int r;
1✔
83

84
        r = sd_varlink_connect_address(&vl, "/run/udev/io.systemd.Udev");
1✔
85
        if (r == -ENOENT) {
1✔
86
                log_debug("systemd-udevd is not running, skipping reload.");
1✔
87
                return 0;
1✔
88
        }
UNCOV
89
        if (r < 0)
×
UNCOV
90
                return log_error_errno(r, "Failed to connect to udev: %m");
×
91

92
        (void) sd_varlink_set_description(vl, "udev");
×
93

UNCOV
94
        return varlink_call_and_log(vl, "io.systemd.service.Reload", /* parameters= */ NULL, /* reply= */ NULL);
×
95
}
96

97
bool networkd_is_running(void) {
20✔
98
        static int cached = -1;
20✔
99
        int r;
20✔
100

101
        if (cached < 0) {
20✔
102
                r = access("/run/systemd/netif/state", F_OK);
17✔
103
                if (r < 0) {
17✔
UNCOV
104
                        if (errno != ENOENT)
×
UNCOV
105
                                log_debug_errno(errno,
×
106
                                                "Failed to determine whether networkd is running, assuming it's not: %m");
107

UNCOV
108
                        cached = false;
×
109
                } else
110
                        cached = true;
17✔
111
        }
112

113
        return cached;
20✔
114
}
115

116
void operational_state_to_color(const char *name, const char *state, const char **on, const char **off) {
1,473✔
117
        if (STRPTR_IN_SET(state, "routable", "enslaved") ||
1,473✔
118
            (streq_ptr(name, "lo") && streq_ptr(state, "carrier"))) {
628✔
119
                if (on)
850✔
120
                        *on = ansi_highlight_green();
1,700✔
121
                if (off)
850✔
122
                        *off = ansi_normal();
1,694✔
123
        } else if (streq_ptr(state, "degraded")) {
623✔
124
                if (on)
372✔
125
                        *on = ansi_highlight_yellow();
372✔
126
                if (off)
372✔
127
                        *off = ansi_normal();
738✔
128
        } else {
129
                if (on)
251✔
130
                        *on = "";
251✔
131
                if (off)
251✔
132
                        *off = "";
229✔
133
        }
134
}
1,473✔
135

136
void setup_state_to_color(const char *state, const char **on, const char **off) {
1,471✔
137
        if (streq_ptr(state, "configured")) {
1,471✔
138
                if (on)
1,351✔
139
                        *on = ansi_highlight_green();
2,702✔
140
                if (off)
1,351✔
141
                        *off = ansi_normal();
2,690✔
142
        } else if (streq_ptr(state, "configuring")) {
120✔
143
                if (on)
42✔
144
                        *on = ansi_highlight_yellow();
42✔
145
                if (off)
42✔
146
                        *off = ansi_normal();
84✔
147
        } else if (STRPTR_IN_SET(state, "failed", "linger")) {
78✔
UNCOV
148
                if (on)
×
UNCOV
149
                        *on = ansi_highlight_red();
×
UNCOV
150
                if (off)
×
UNCOV
151
                        *off = ansi_normal();
×
152
        } else {
153
                if (on)
78✔
154
                        *on = "";
78✔
155
                if (off)
78✔
156
                        *off = "";
56✔
157
        }
158
}
1,471✔
159

160
void online_state_to_color(const char *state, const char **on, const char **off) {
1,445✔
161
        if (streq_ptr(state, "online")) {
1,445✔
162
                if (on)
1,202✔
163
                        *on = ansi_highlight_green();
2,404✔
164
                if (off)
1,202✔
UNCOV
165
                        *off = ansi_normal();
×
166
        } else if (streq_ptr(state, "partial")) {
243✔
UNCOV
167
                if (on)
×
UNCOV
168
                        *on = ansi_highlight_yellow();
×
169
                if (off)
×
170
                        *off = ansi_normal();
×
171
        } else {
172
                if (on)
243✔
173
                        *on = "";
243✔
174
                if (off)
243✔
UNCOV
175
                        *off = "";
×
176
        }
177
}
1,445✔
178

179
int acquire_link_description(sd_varlink *vl, int ifindex, sd_json_variant **ret) {
1,443✔
180
        int r;
1,443✔
181

182
        assert(vl);
1,443✔
183
        assert(ifindex > 0);
1,443✔
184
        assert(ret);
1,443✔
185

186
        sd_json_variant *v; /* borrowed from vl, do not unref */
1,443✔
187
        r = varlink_callbo_and_log(
1,443✔
188
                        vl,
189
                        "io.systemd.Network.Link.Describe",
190
                        &v,
191
                        SD_JSON_BUILD_PAIR_INTEGER("InterfaceIndex", ifindex));
192
        if (r < 0)
1,443✔
193
                return r;
1,443✔
194

195
        *ret = sd_json_variant_ref(v);
1,443✔
196
        return 0;
1,443✔
197
}
198

199
int json_variant_find_object(sd_json_variant *v, char * const *object_names, sd_json_variant **ret) {
2,914✔
200
        assert(object_names);
2,914✔
201
        assert(ret);
2,914✔
202

203
        if (!v || sd_json_variant_is_null(v))
2,914✔
204
                return -ENODATA;
28✔
205

206
        STRV_FOREACH(name, object_names) {
5,837✔
207
                v = sd_json_variant_by_key(v, *name);
5,807✔
208
                if (!v || sd_json_variant_is_null(v))
5,807✔
209
                        return -ENODATA;
2,856✔
210
        }
211

212
        *ret = v;
30✔
213
        return 0;
30✔
214
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc