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

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

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

82.88
/src/network/netdev/vlan.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <errno.h>
4
#include <linux/if_arp.h>
5
#include <linux/if_vlan.h>
6
#include <net/if.h>
7

8
#include "alloc-util.h"
9
#include "parse-util.h"
10
#include "vlan.h"
11
#include "vlan-util.h"
12

13
static int netdev_vlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
11✔
14
        assert(link);
11✔
15
        assert(req);
11✔
16

17
        struct ifla_vlan_flags flags = {};
11✔
18
        VLan *v = VLAN(netdev);
11✔
19
        int r;
11✔
20

21
        r = sd_netlink_message_append_u16(req, IFLA_VLAN_ID, v->id);
11✔
22
        if (r < 0)
11✔
23
                return r;
11✔
24

25
        if (v->protocol >= 0) {
11✔
26
                r = sd_netlink_message_append_u16(req, IFLA_VLAN_PROTOCOL, htobe16(v->protocol));
×
UNCOV
27
                if (r < 0)
×
28
                        return r;
29
        }
30

31
        if (v->gvrp != -1) {
11✔
32
                flags.mask |= VLAN_FLAG_GVRP;
10✔
33
                SET_FLAG(flags.flags, VLAN_FLAG_GVRP, v->gvrp);
10✔
34
        }
35

36
        if (v->mvrp != -1) {
11✔
37
                flags.mask |= VLAN_FLAG_MVRP;
10✔
38
                SET_FLAG(flags.flags, VLAN_FLAG_MVRP, v->mvrp);
10✔
39
        }
40

41
        if (v->reorder_hdr != -1) {
11✔
42
                flags.mask |= VLAN_FLAG_REORDER_HDR;
10✔
43
                SET_FLAG(flags.flags, VLAN_FLAG_REORDER_HDR, v->reorder_hdr);
10✔
44
        }
45

46
        if (v->loose_binding != -1) {
11✔
47
                flags.mask |= VLAN_FLAG_LOOSE_BINDING;
10✔
48
                SET_FLAG(flags.flags, VLAN_FLAG_LOOSE_BINDING, v->loose_binding);
10✔
49
        }
50

51
        r = sd_netlink_message_append_data(req, IFLA_VLAN_FLAGS, &flags, sizeof(struct ifla_vlan_flags));
11✔
52
        if (r < 0)
11✔
53
                return r;
54

55
        if (!set_isempty(v->egress_qos_maps)) {
11✔
56
                struct ifla_vlan_qos_mapping *m;
10✔
57

58
                r = sd_netlink_message_open_container(req, IFLA_VLAN_EGRESS_QOS);
10✔
59
                if (r < 0)
10✔
UNCOV
60
                        return r;
×
61

62
                SET_FOREACH(m, v->egress_qos_maps) {
60✔
63
                        r = sd_netlink_message_append_data(req, IFLA_VLAN_QOS_MAPPING, m, sizeof(struct ifla_vlan_qos_mapping));
50✔
64
                        if (r < 0)
50✔
UNCOV
65
                                return r;
×
66
                }
67

68
                r = sd_netlink_message_close_container(req);
10✔
69
                if (r < 0)
10✔
70
                        return r;
71
        }
72

73
        if (!set_isempty(v->ingress_qos_maps)) {
11✔
74
                struct ifla_vlan_qos_mapping *m;
10✔
75

76
                r = sd_netlink_message_open_container(req, IFLA_VLAN_INGRESS_QOS);
10✔
77
                if (r < 0)
10✔
UNCOV
78
                        return r;
×
79

80
                SET_FOREACH(m, v->ingress_qos_maps) {
30✔
81
                        r = sd_netlink_message_append_data(req, IFLA_VLAN_QOS_MAPPING, m, sizeof(struct ifla_vlan_qos_mapping));
20✔
82
                        if (r < 0)
20✔
UNCOV
83
                                return r;
×
84
                }
85

86
                r = sd_netlink_message_close_container(req);
10✔
87
                if (r < 0)
10✔
88
                        return r;
89
        }
90

91
        return 0;
92
}
93

94
static void vlan_qos_maps_hash_func(const struct ifla_vlan_qos_mapping *x, struct siphash *state) {
120✔
95
        siphash24_compress_typesafe(x->from, state);
120✔
96
        siphash24_compress_typesafe(x->to, state);
120✔
97
}
120✔
98

99
static int vlan_qos_maps_compare_func(const struct ifla_vlan_qos_mapping *a, const struct ifla_vlan_qos_mapping *b) {
33✔
100
        int r;
33✔
101

102
        r = CMP(a->from, b->from);
33✔
103
        if (r != 0)
9✔
104
                return r;
33✔
105

UNCOV
106
        return CMP(a->to, b->to);
×
107
}
108

109
DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
70✔
110
                vlan_qos_maps_hash_ops,
111
                struct ifla_vlan_qos_mapping,
112
                vlan_qos_maps_hash_func,
113
                vlan_qos_maps_compare_func,
114
                free);
115

116
int config_parse_vlan_qos_maps(
20✔
117
                const char *unit,
118
                const char *filename,
119
                unsigned line,
120
                const char *section,
121
                unsigned section_line,
122
                const char *lvalue,
123
                int ltype,
124
                const char *rvalue,
125
                void *data,
126
                void *userdata) {
127

128
        Set **s = ASSERT_PTR(data);
20✔
129
        int r;
20✔
130

131
        assert(filename);
20✔
132
        assert(lvalue);
20✔
133
        assert(rvalue);
20✔
134

135
        if (isempty(rvalue)) {
20✔
136
                *s = set_free(*s);
×
UNCOV
137
                return 0;
×
138
        }
139

140
        for (const char *p = rvalue;;) {
20✔
141
                _cleanup_free_ struct ifla_vlan_qos_mapping *m = NULL;
180✔
142
                _cleanup_free_ char *w = NULL;
90✔
143
                unsigned from, to;
90✔
144

145
                r = extract_first_word(&p, &w, NULL, EXTRACT_CUNESCAPE|EXTRACT_UNQUOTE);
90✔
146
                if (r == -ENOMEM)
90✔
UNCOV
147
                        return log_oom();
×
148
                if (r < 0) {
90✔
149
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, rvalue);
×
UNCOV
150
                        return 0;
×
151
                }
152
                if (r == 0)
90✔
153
                        return 0;
154

155
                r = parse_range(w, &from, &to);
70✔
156
                if (r < 0) {
70✔
157
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s, ignoring: %s", lvalue, w);
×
UNCOV
158
                        continue;
×
159
                }
160

161
                m = new(struct ifla_vlan_qos_mapping, 1);
70✔
162
                if (!m)
70✔
UNCOV
163
                        return log_oom();
×
164

165
                *m = (struct ifla_vlan_qos_mapping) {
70✔
166
                        .from = from,
167
                        .to = to,
168
                };
169

170
                r = set_ensure_consume(s, &vlan_qos_maps_hash_ops, TAKE_PTR(m));
70✔
171
                if (r < 0) {
70✔
172
                        log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to store %s, ignoring: %s", lvalue, w);
×
UNCOV
173
                        continue;
×
174
                }
175
        }
176
}
177

178
static int netdev_vlan_verify(NetDev *netdev, const char *filename) {
12✔
179
        assert(filename);
12✔
180

181
        VLan *v = VLAN(netdev);
12✔
182

183
        if (v->id == VLANID_INVALID) {
12✔
184
                log_netdev_warning(netdev, "VLAN without valid Id (%"PRIu16") configured in %s.", v->id, filename);
×
UNCOV
185
                return -EINVAL;
×
186
        }
187

188
        return 0;
189
}
190

191
static void vlan_done(NetDev *netdev) {
12✔
192
        VLan *v = VLAN(netdev);
12✔
193

194
        set_free(v->egress_qos_maps);
12✔
195
        set_free(v->ingress_qos_maps);
12✔
196
}
12✔
197

198
static void vlan_init(NetDev *netdev) {
12✔
199
        VLan *v = VLAN(netdev);
12✔
200

201
        v->id = VLANID_INVALID;
12✔
202
        v->protocol = -1;
12✔
203
        v->gvrp = -1;
12✔
204
        v->mvrp = -1;
12✔
205
        v->loose_binding = -1;
12✔
206
        v->reorder_hdr = -1;
12✔
207
}
12✔
208

209
const NetDevVTable vlan_vtable = {
210
        .object_size = sizeof(VLan),
211
        .init = vlan_init,
212
        .sections = NETDEV_COMMON_SECTIONS "VLAN\0",
213
        .fill_message_create = netdev_vlan_fill_message_create,
214
        .create_type = NETDEV_CREATE_STACKED,
215
        .config_verify = netdev_vlan_verify,
216
        .done = vlan_done,
217
        .iftype = ARPHRD_ETHER,
218
};
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