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

systemd / systemd / 13042844938

29 Jan 2025 04:17PM UTC coverage: 71.718% (+0.2%) from 71.53%
13042844938

push

github

bluca
tree-wide: remove some spurious newlines

Specifically, remove double newlines, and newlines before '}'.

292558 of 407928 relevant lines covered (71.72%)

710701.19 hits per line

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

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

3
/* Make sure the net/if.h header is included before any linux/ one */
4
#include <net/if.h>
5
#include <linux/if_arp.h>
6
#include <linux/if_bridge.h>
7
#include <netinet/in.h>
8

9
#include "bridge.h"
10
#include "netlink-util.h"
11
#include "networkd-manager.h"
12
#include "string-table.h"
13
#include "vlan-util.h"
14

15
assert_cc((int) MULTICAST_ROUTER_NONE            == (int) MDB_RTR_TYPE_DISABLED);
16
assert_cc((int) MULTICAST_ROUTER_TEMPORARY_QUERY == (int) MDB_RTR_TYPE_TEMP_QUERY);
17
assert_cc((int) MULTICAST_ROUTER_PERMANENT       == (int) MDB_RTR_TYPE_PERM);
18
assert_cc((int) MULTICAST_ROUTER_TEMPORARY       == (int) MDB_RTR_TYPE_TEMP);
19

20
static const char* const multicast_router_table[_MULTICAST_ROUTER_MAX] = {
21
        [MULTICAST_ROUTER_NONE]            = "no",
22
        [MULTICAST_ROUTER_TEMPORARY_QUERY] = "query",
23
        [MULTICAST_ROUTER_PERMANENT]       = "permanent",
24
        [MULTICAST_ROUTER_TEMPORARY]       = "temporary",
25
};
26

27
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(multicast_router, MulticastRouter, _MULTICAST_ROUTER_INVALID);
2✔
28
DEFINE_CONFIG_PARSE_ENUM(config_parse_multicast_router, multicast_router, MulticastRouter);
2✔
29

30
/* callback for bridge netdev's parameter set */
31
static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {
16✔
32
        int r;
16✔
33

34
        assert(netdev);
16✔
35
        assert(m);
16✔
36

37
        r = sd_netlink_message_get_errno(m);
16✔
38
        if (r < 0) {
16✔
39
                log_netdev_warning_errno(netdev, r, "Bridge parameters could not be set: %m");
×
40
                return 1;
×
41
        }
42

43
        log_netdev_debug(netdev, "Bridge parameters set success");
16✔
44

45
        return 1;
46
}
47

48
static int netdev_bridge_post_create_message(NetDev *netdev, sd_netlink_message *req) {
16✔
49
        Bridge *b = BRIDGE(netdev);
16✔
50
        struct br_boolopt_multi bm = {};
16✔
51
        int r;
16✔
52

53
        r = sd_netlink_message_open_container(req, IFLA_LINKINFO);
16✔
54
        if (r < 0)
16✔
55
                return r;
16✔
56

57
        r = sd_netlink_message_open_container_union(req, IFLA_INFO_DATA, netdev_kind_to_string(netdev->kind));
16✔
58
        if (r < 0)
16✔
59
                return r;
60

61
        /* convert to jiffes */
62
        if (b->forward_delay != USEC_INFINITY) {
16✔
63
                r = sd_netlink_message_append_u32(req, IFLA_BR_FORWARD_DELAY, usec_to_jiffies(b->forward_delay));
3✔
64
                if (r < 0)
3✔
65
                        return r;
66
        }
67

68
        if (b->hello_time > 0) {
16✔
69
                r = sd_netlink_message_append_u32(req, IFLA_BR_HELLO_TIME, usec_to_jiffies(b->hello_time));
2✔
70
                if (r < 0)
2✔
71
                        return r;
72
        }
73

74
        if (b->max_age > 0) {
16✔
75
                r = sd_netlink_message_append_u32(req, IFLA_BR_MAX_AGE, usec_to_jiffies(b->max_age));
2✔
76
                if (r < 0)
2✔
77
                        return r;
78
        }
79

80
        if (b->ageing_time != USEC_INFINITY) {
16✔
81
                r = sd_netlink_message_append_u32(req, IFLA_BR_AGEING_TIME, usec_to_jiffies(b->ageing_time));
2✔
82
                if (r < 0)
2✔
83
                        return r;
84
        }
85

86
        if (b->priority > 0) {
16✔
87
                r = sd_netlink_message_append_u16(req, IFLA_BR_PRIORITY, b->priority);
3✔
88
                if (r < 0)
3✔
89
                        return r;
90
        }
91

92
        if (b->group_fwd_mask > 0) {
16✔
93
                r = sd_netlink_message_append_u16(req, IFLA_BR_GROUP_FWD_MASK, b->group_fwd_mask);
×
94
                if (r < 0)
×
95
                        return r;
96
        }
97

98
        if (b->default_pvid != VLANID_INVALID) {
16✔
99
                r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_DEFAULT_PVID, b->default_pvid);
2✔
100
                if (r < 0)
2✔
101
                        return r;
102
        }
103

104
        if (b->mcast_querier >= 0) {
16✔
105
                r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_QUERIER, b->mcast_querier);
3✔
106
                if (r < 0)
3✔
107
                        return r;
108
        }
109

110
        if (b->mcast_snooping >= 0) {
16✔
111
                r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_SNOOPING, b->mcast_snooping);
3✔
112
                if (r < 0)
3✔
113
                        return r;
114
        }
115

116
        if (b->vlan_filtering >= 0) {
16✔
117
                r = sd_netlink_message_append_u8(req, IFLA_BR_VLAN_FILTERING, b->vlan_filtering);
3✔
118
                if (r < 0)
3✔
119
                        return r;
120
        }
121

122
        if (b->vlan_protocol >= 0) {
16✔
123
                r = sd_netlink_message_append_u16(req, IFLA_BR_VLAN_PROTOCOL, htobe16(b->vlan_protocol));
2✔
124
                if (r < 0)
2✔
125
                        return r;
126
        }
127

128
        if (b->stp >= 0) {
16✔
129
                r = sd_netlink_message_append_u32(req, IFLA_BR_STP_STATE, b->stp);
3✔
130
                if (r < 0)
3✔
131
                        return r;
132
        }
133

134
        if (b->igmp_version > 0) {
16✔
135
                r = sd_netlink_message_append_u8(req, IFLA_BR_MCAST_IGMP_VERSION, b->igmp_version);
3✔
136
                if (r < 0)
3✔
137
                        return r;
138
        }
139

140
        if (b->fdb_max_learned_set) {
16✔
141
                r = sd_netlink_message_append_u32(req, IFLA_BR_FDB_MAX_LEARNED, b->fdb_max_learned);
2✔
142
                if (r < 0)
2✔
143
                        return r;
144
        }
145

146
        if (b->linklocal_learn >= 0) {
16✔
147
                bm.optmask |= 1 << BR_BOOLOPT_NO_LL_LEARN;
2✔
148
                SET_FLAG(bm.optval, 1 << BR_BOOLOPT_NO_LL_LEARN, !b->linklocal_learn);
2✔
149
        }
150

151
        if (bm.optmask != 0) {
16✔
152
                r = sd_netlink_message_append_data(req, IFLA_BR_MULTI_BOOLOPT, &bm, sizeof(bm));
2✔
153
                if (r < 0)
2✔
154
                        return r;
155
        }
156

157
        r = sd_netlink_message_close_container(req);
16✔
158
        if (r < 0)
16✔
159
                return r;
160

161
        r = sd_netlink_message_close_container(req);
16✔
162
        if (r < 0)
16✔
163
                return r;
×
164

165
        return 0;
166
}
167

168
static int netdev_bridge_post_create(NetDev *netdev, Link *link) {
16✔
169
        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
16✔
170
        int r;
16✔
171

172
        assert(netdev);
16✔
173

174
        if (!netdev_is_managed(netdev))
16✔
175
                return 0; /* Already detached, due to e.g. reloading .netdev files. */
176

177
        r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, netdev->ifindex);
16✔
178
        if (r < 0)
16✔
179
                return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m");
×
180

181
        r = netdev_bridge_post_create_message(netdev, req);
16✔
182
        if (r < 0)
16✔
183
                return log_netdev_error_errno(netdev, r, "Could not create netlink message: %m");
×
184

185
        r = netlink_call_async(netdev->manager->rtnl, NULL, req, netdev_bridge_set_handler,
16✔
186
                               netdev_destroy_callback, netdev);
187
        if (r < 0)
16✔
188
                return log_netdev_error_errno(netdev, r, "Could not send netlink message: %m");
×
189

190
        netdev_ref(netdev);
16✔
191

192
        return r;
193
}
194

195
int config_parse_bridge_igmp_version(
×
196
                const char *unit,
197
                const char *filename,
198
                unsigned line,
199
                const char *section,
200
                unsigned section_line,
201
                const char *lvalue,
202
                int ltype,
203
                const char *rvalue,
204
                void *data,
205
                void *userdata) {
206

207
        assert(filename);
×
208
        assert(lvalue);
×
209
        assert(rvalue);
×
210
        assert(data);
×
211

212
        Bridge *b = ASSERT_PTR(userdata);
×
213

214
        if (isempty(rvalue)) {
×
215
                b->igmp_version = 0; /* 0 means unset. */
×
216
                return 0;
×
217
        }
218

219
        return config_parse_uint8_bounded(
×
220
                        unit, filename, line, section, section_line, lvalue, rvalue,
221
                        2, 3, true,
222
                        &b->igmp_version);
223
}
224

225
int config_parse_bridge_port_priority(
9✔
226
                const char *unit,
227
                const char *filename,
228
                unsigned line,
229
                const char *section,
230
                unsigned section_line,
231
                const char *lvalue,
232
                int ltype,
233
                const char *rvalue,
234
                void *data,
235
                void *userdata) {
236

237
        assert(filename);
9✔
238
        assert(lvalue);
9✔
239
        assert(rvalue);
9✔
240

241
        uint16_t *prio = ASSERT_PTR(data);
9✔
242

243
        return config_parse_uint16_bounded(
9✔
244
                        unit, filename, line, section, section_line, lvalue, rvalue,
245
                        0, LINK_BRIDGE_PORT_PRIORITY_MAX, true,
246
                        prio);
247
}
248

249
int config_parse_bridge_fdb_max_learned(
2✔
250
                const char *unit,
251
                const char *filename,
252
                unsigned line,
253
                const char *section,
254
                unsigned section_line,
255
                const char *lvalue,
256
                int ltype,
257
                const char *rvalue,
258
                void *data,
259
                void *userdata) {
260

261
        Bridge *b = ASSERT_PTR(userdata);
2✔
262
        int r;
2✔
263

264
        assert(filename);
2✔
265
        assert(lvalue);
2✔
266
        assert(rvalue);
2✔
267
        assert(data);
2✔
268

269
        if (isempty(rvalue)) {
2✔
270
                b->fdb_max_learned_set = false;
×
271
                return 0;
×
272
        }
273

274
        r = config_parse_uint32_bounded(unit, filename, line, section, section_line, lvalue, rvalue,
2✔
275
                                        0, UINT32_MAX, true, &b->fdb_max_learned);
276
        if (r <= 0)
2✔
277
                return r;
278

279
        b->fdb_max_learned_set = true;
2✔
280
        return 1;
2✔
281
}
282

283
static void bridge_init(NetDev *netdev) {
27✔
284
        Bridge *b = BRIDGE(netdev);
27✔
285

286
        b->mcast_querier = -1;
27✔
287
        b->mcast_snooping = -1;
27✔
288
        b->vlan_filtering = -1;
27✔
289
        b->vlan_protocol = -1;
27✔
290
        b->stp = -1;
27✔
291
        b->default_pvid = VLANID_INVALID;
27✔
292
        b->forward_delay = USEC_INFINITY;
27✔
293
        b->ageing_time = USEC_INFINITY;
27✔
294
        b->linklocal_learn = -1;
27✔
295
}
27✔
296

297
static bool bridge_can_set_mac(NetDev *netdev, const struct hw_addr_data *hw_addr) {
×
298
        return true;
×
299
}
300

301
const NetDevVTable bridge_vtable = {
302
        .object_size = sizeof(Bridge),
303
        .init = bridge_init,
304
        .sections = NETDEV_COMMON_SECTIONS "Bridge\0",
305
        .post_create = netdev_bridge_post_create,
306
        .create_type = NETDEV_CREATE_INDEPENDENT,
307
        .can_set_mac = bridge_can_set_mac,
308
        .iftype = ARPHRD_ETHER,
309
        .generate_mac = true,
310
};
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