• 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

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

3
#include "sd-netlink.h"
4

5
#include "bus-util.h"
6
#include "errno-util.h"
7
#include "fd-util.h"
8
#include "format-ifname.h"
9
#include "log.h"
10
#include "netlink-util.h"
11
#include "networkctl.h"
12
#include "networkctl-misc.h"
13
#include "networkctl-util.h"
14
#include "ordered-set.h"
15
#include "parse-util.h"
16
#include "polkit-agent.h"
17
#include "string-util.h"
18
#include "strv.h"
19
#include "varlink-util.h"
20

21
static int parse_interfaces(sd_netlink **rtnl, char *argv[], OrderedSet **ret) {
48✔
22
        _cleanup_(sd_netlink_unrefp) sd_netlink *our_rtnl = NULL;
48✔
23
        _cleanup_ordered_set_free_ OrderedSet *indexes = NULL;
48✔
24
        int r;
48✔
25

26
        assert(ret);
48✔
27

28
        if (!rtnl)
48✔
29
                rtnl = &our_rtnl;
47✔
30

31
        STRV_FOREACH(s, strv_skip(argv, 1)) {
107✔
32
                int index = rtnl_resolve_interface_or_warn(rtnl, *s);
59✔
33
                if (index < 0)
59✔
34
                        return index;
35
                assert(index > 0);
59✔
36

37
                r = ordered_set_ensure_put(&indexes, /* ops= */ NULL, INT_TO_PTR(index));
59✔
38
                if (r < 0)
59✔
UNCOV
39
                        return log_oom();
×
40
        }
41

42
        *ret = TAKE_PTR(indexes);
48✔
43
        return 0;
48✔
44
}
45

46
int verb_link_delete(int argc, char *argv[], uintptr_t _data, void *userdata) {
1✔
47
        int r, ret = 0;
1✔
48

49
        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
1✔
50
        _cleanup_ordered_set_free_ OrderedSet *indexes = NULL;
1✔
51
        r = parse_interfaces(&rtnl, argv, &indexes);
1✔
52
        if (r < 0)
1✔
53
                return r;
54

55
        void *p;
1✔
56
        ORDERED_SET_FOREACH(p, indexes) {
3✔
57
                _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
2✔
58
                int index = PTR_TO_INT(p);
2✔
59

60
                r = sd_rtnl_message_new_link(rtnl, &req, RTM_DELLINK, index);
2✔
61
                if (r < 0)
2✔
UNCOV
62
                        return rtnl_log_create_error(r);
×
63

64
                r = sd_netlink_call(rtnl, req, /* timeout= */ 0, /* ret= */ NULL);
2✔
65
                if (r < 0) {
2✔
UNCOV
66
                        RET_GATHER(ret, r);
×
UNCOV
67
                        log_error_errno(r, "Failed to delete interface %s: %m",
×
68
                                        FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX));
69
                }
70
        }
71

72
        return ret;
1✔
73
}
74

75
int verb_link_varlink_simple_method(int argc, char *argv[], uintptr_t _data, void *userdata) {
47✔
76
        int r, ret = 0;
47✔
77

78
        typedef struct LinkVarlinkAction {
47✔
79
                const char *verb;
80
                const char *method;
81
        } LinkVarlinkAction;
82

83
        static const LinkVarlinkAction link_varlink_action_table[] = {
47✔
84
                { "up",          "io.systemd.Network.Link.Up",          },
85
                { "down",        "io.systemd.Network.Link.Down",        },
86
                { "renew",       "io.systemd.Network.Link.Renew",       },
87
                { "forcerenew",  "io.systemd.Network.Link.ForceRenew",  },
88
                { "reconfigure", "io.systemd.Network.Link.Reconfigure", },
89
        };
90

91
        /* Common implementation for 'simple' method calls that just take an ifindex, and nothing else. */
92

93
        const LinkVarlinkAction *a = NULL;
47✔
94
        FOREACH_ELEMENT(i, link_varlink_action_table)
206✔
95
                if (streq(argv[0], i->verb)) {
206✔
96
                        a = i;
97
                        break;
98
                }
99
        assert(a);
47✔
100

UNCOV
101
        _cleanup_ordered_set_free_ OrderedSet *indexes = NULL;
×
102
        r = parse_interfaces(/* rtnl= */ NULL, argv, &indexes);
47✔
103
        if (r < 0)
47✔
104
                return r;
105

106
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
47✔
107
        r = varlink_connect_networkd(&vl);
47✔
108
        if (r < 0)
47✔
109
                return r;
110

111
        (void) polkit_agent_open_if_enabled(BUS_TRANSPORT_LOCAL, arg_ask_password);
47✔
112

113
        void *p;
47✔
114
        ORDERED_SET_FOREACH(p, indexes)
96✔
115
                RET_GATHER(ret, varlink_callbo_and_log(
49✔
116
                                           vl,
117
                                           a->method,
118
                                           /* reply= */ NULL,
119
                                           SD_JSON_BUILD_PAIR_INTEGER("InterfaceIndex", PTR_TO_INT(p)),
120
                                           SD_JSON_BUILD_PAIR_BOOLEAN("allowInteractiveAuthentication", arg_ask_password)));
121

122
        return ret;
47✔
123
}
124

125
int verb_reload(int argc, char *argv[], uintptr_t _data, void *userdata) {
144✔
126
        return reload_networkd();
144✔
127
}
128

129
int verb_persistent_storage(int argc, char *argv[], uintptr_t _data, void *userdata) {
898✔
130
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
898✔
131
        bool ready;
898✔
132
        int r;
898✔
133

134
        r = parse_boolean(argv[1]);
898✔
135
        if (r < 0)
898✔
UNCOV
136
                return log_error_errno(r, "Failed to parse argument: %s", argv[1]);
×
137
        ready = r;
898✔
138

139
        r = varlink_connect_networkd(&vl);
898✔
140
        if (r < 0)
898✔
141
                return r;
142

143
        if (ready) {
898✔
144
                _cleanup_close_ int fd = -EBADF;
898✔
145

146
                fd = open("/var/lib/systemd/network/", O_CLOEXEC | O_DIRECTORY);
449✔
147
                if (fd < 0)
449✔
UNCOV
148
                        return log_error_errno(errno, "Failed to open %s: %m", "/var/lib/systemd/network/");
×
149

150
                r = sd_varlink_push_fd(vl, fd);
449✔
151
                if (r < 0)
449✔
152
                        return log_error_errno(r, "Failed to push file descriptor of /var/lib/systemd/network/ into varlink: %m");
×
153

154
                TAKE_FD(fd);
449✔
155
        }
156

157
        return varlink_callbo_and_log(
898✔
158
                        vl,
159
                        "io.systemd.Network.SetPersistentStorage",
160
                        /* reply= */ NULL,
161
                        SD_JSON_BUILD_PAIR_BOOLEAN("Ready", ready));
162
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc