GCC Code Coverage Report


Directory: ./
File: src/cmd.c
Date: 2026-01-20 23:48:36
Exec Total Coverage
Lines: 209 276 75.7%
Functions: 14 14 100.0%
Branches: 101 163 62.0%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2020 Pablo Neira Ayuso <pablo@netfilter.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 (or any
6 * later) as published by the Free Software Foundation.
7 */
8
9 #include <nft.h>
10
11 #include <erec.h>
12 #include <mnl.h>
13 #include <cmd.h>
14 #include <parser.h>
15 #include <utils.h>
16 #include <iface.h>
17 #include <errno.h>
18 #include <cache.h>
19
20 1896636 void cmd_add_loc(struct cmd *cmd, const struct nlmsghdr *nlh, const struct location *loc)
21 {
22
2/2
✓ Branch 0 (2→3) taken 1611 times.
✓ Branch 1 (2→5) taken 1895025 times.
1896636 if (cmd->num_attrs >= cmd->attr_array_len) {
23 1611 cmd->attr_array_len *= 2;
24 1611 cmd->attr = xrealloc(cmd->attr, sizeof(struct nlerr_loc) * cmd->attr_array_len);
25 }
26
27 1896636 cmd->attr[cmd->num_attrs].seqnum = nlh->nlmsg_seq;
28 1896636 cmd->attr[cmd->num_attrs].offset = nlh->nlmsg_len;
29 1896636 cmd->attr[cmd->num_attrs].location = loc;
30 1896636 cmd->num_attrs++;
31 1896636 }
32
33 5 static int nft_cmd_enoent_table(struct netlink_ctx *ctx, const struct cmd *cmd,
34 const struct location *loc)
35 {
36 struct table *table;
37
38
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→4) taken 3 times.
5 if (!cmd->handle.table.name)
39 2 return 0;
40
41 3 table = table_lookup_fuzzy(&cmd->handle, &ctx->nft->cache);
42
1/2
✓ Branch 0 (5→6) taken 3 times.
✗ Branch 1 (5→7) not taken.
3 if (!table)
43 3 return 0;
44
45 ✗ netlink_io_error(ctx, loc, "%s; did you mean table '%s' in family %s?",
46 strerror(ENOENT), table->handle.table.name,
47 ✗ family2str(table->handle.family));
48 ✗ return 1;
49 }
50
51 4 static int table_fuzzy_check(struct netlink_ctx *ctx, const struct cmd *cmd,
52 const struct table *table)
53 {
54
2/2
✓ Branch 0 (3→4) taken 3 times.
✓ Branch 1 (3→5) taken 1 times.
4 if (table_cache_find(&ctx->nft->cache.table_cache,
55 4 cmd->handle.table.name, cmd->handle.family))
56 3 return 0;
57
58
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→7) taken 1 times.
1 if (strcmp(cmd->handle.table.name, table->handle.table.name) ||
59 ✗ cmd->handle.family != table->handle.family) {
60 1 netlink_io_error(ctx, &cmd->handle.table.location,
61 "%s; did you mean table '%s' in family %s?",
62 1 strerror(ENOENT), table->handle.table.name,
63 1 family2str(table->handle.family));
64 1 return 1;
65 }
66
67 ✗ return 0;
68 }
69
70 6 static int nft_cmd_enoent_chain(struct netlink_ctx *ctx, const struct cmd *cmd,
71 const struct location *loc)
72 {
73 6 const struct table *table = NULL;
74 struct chain *chain;
75
76
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→4) taken 4 times.
6 if (!cmd->handle.chain.name)
77 2 return 0;
78
79
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→7) taken 4 times.
4 if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_CHAIN,
80 ctx->msgs, NULL) < 0)
81 ✗ return 0;
82
83 4 chain = chain_lookup_fuzzy(&cmd->handle, &ctx->nft->cache, &table);
84 /* check table first. */
85
1/2
✓ Branch 0 (8→9) taken 4 times.
✗ Branch 1 (8→10) not taken.
4 if (!table)
86 4 return 0;
87
88 ✗ if (table_fuzzy_check(ctx, cmd, table))
89 ✗ return 1;
90
91 ✗ if (!chain)
92 ✗ return 0;
93
94 ✗ netlink_io_error(ctx, loc, "%s; did you mean chain '%s' in table %s '%s'?",
95 strerror(ENOENT), chain->handle.chain.name,
96 ✗ family2str(table->handle.family),
97 ✗ table->handle.table.name);
98 ✗ return 1;
99 }
100
101 13 static int nft_cmd_enoent_rule(struct netlink_ctx *ctx, const struct cmd *cmd,
102 const struct location *loc)
103 {
104 13 unsigned int flags = NFT_CACHE_TABLE |
105 NFT_CACHE_CHAIN;
106 13 const struct table *table = NULL;
107 struct chain *chain;
108
109
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 13 times.
13 if (nft_cache_update(ctx->nft, flags, ctx->msgs, NULL) < 0)
110 ✗ return 0;
111
112 13 chain = chain_lookup_fuzzy(&cmd->handle, &ctx->nft->cache, &table);
113 /* check table first. */
114
2/2
✓ Branch 0 (6→7) taken 9 times.
✓ Branch 1 (6→8) taken 4 times.
13 if (!table)
115 9 return 0;
116
117
2/2
✓ Branch 0 (9→10) taken 1 times.
✓ Branch 1 (9→11) taken 3 times.
4 if (table_fuzzy_check(ctx, cmd, table))
118 1 return 1;
119
120
1/2
✗ Branch 0 (11→12) not taken.
✓ Branch 1 (11→13) taken 3 times.
3 if (!chain)
121 ✗ return 0;
122
123
1/2
✗ Branch 0 (13→14) not taken.
✓ Branch 1 (13→18) taken 3 times.
3 if (strcmp(cmd->handle.chain.name, chain->handle.chain.name)) {
124 ✗ netlink_io_error(ctx, loc, "%s; did you mean chain '%s' in table %s '%s'?",
125 strerror(ENOENT),
126 chain->handle.chain.name,
127 ✗ family2str(table->handle.family),
128 ✗ table->handle.table.name);
129 ✗ return 1;
130 }
131
132 3 return 0;
133 }
134
135 10 static int nft_cmd_enoent_set(struct netlink_ctx *ctx, const struct cmd *cmd,
136 const struct location *loc)
137 {
138 10 const struct table *table = NULL;
139 struct set *set;
140
141
2/2
✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→4) taken 8 times.
10 if (!cmd->handle.set.name)
142 2 return 0;
143
144
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→7) taken 8 times.
8 if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_SET,
145 ctx->msgs, NULL) < 0)
146 ✗ return 0;
147
148 8 set = set_lookup_fuzzy(cmd->handle.set.name, &ctx->nft->cache, &table);
149 /* check table first. */
150
1/2
✓ Branch 0 (8→9) taken 8 times.
✗ Branch 1 (8→10) not taken.
8 if (!table)
151 8 return 0;
152
153 ✗ if (table_fuzzy_check(ctx, cmd, table))
154 ✗ return 1;
155
156 ✗ if (!set)
157 ✗ return 0;
158
159 ✗ netlink_io_error(ctx, loc, "%s; did you mean %s '%s' in table %s '%s'?",
160 strerror(ENOENT),
161 ✗ set_is_map(set->flags) ? "map" : "set",
162 set->handle.set.name,
163 ✗ family2str(set->handle.family),
164 ✗ table->handle.table.name);
165 ✗ return 1;
166 }
167
168 2 static int nft_cmd_enoent_obj(struct netlink_ctx *ctx, const struct cmd *cmd,
169 const struct location *loc)
170 {
171 2 const struct table *table = NULL;
172 struct obj *obj;
173
174
2/2
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→4) taken 1 times.
2 if (!cmd->handle.obj.name)
175 1 return 0;
176
177
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→7) taken 1 times.
1 if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_OBJECT,
178 ctx->msgs, NULL) < 0)
179 ✗ return 0;
180
181 1 obj = obj_lookup_fuzzy(cmd->handle.obj.name, &ctx->nft->cache, &table);
182 /* check table first. */
183
1/2
✓ Branch 0 (8→9) taken 1 times.
✗ Branch 1 (8→10) not taken.
1 if (!table)
184 1 return 0;
185
186 ✗ if (table_fuzzy_check(ctx, cmd, table))
187 ✗ return 1;
188
189 ✗ if (!obj)
190 ✗ return 0;
191
192 ✗ netlink_io_error(ctx, loc, "%s; did you mean obj '%s' in table %s '%s'?",
193 strerror(ENOENT), obj->handle.obj.name,
194 ✗ family2str(obj->handle.family),
195 ✗ table->handle.table.name);
196 ✗ return 1;
197 }
198
199 3 static int nft_cmd_enoent_flowtable(struct netlink_ctx *ctx,
200 const struct cmd *cmd,
201 const struct location *loc)
202 {
203 3 const struct table *table = NULL;
204 struct flowtable *ft;
205
206
2/2
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→4) taken 2 times.
3 if (!cmd->handle.flowtable.name)
207 1 return 0;
208
209
1/2
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→7) taken 2 times.
2 if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_FLOWTABLE,
210 ctx->msgs, NULL) < 0)
211 ✗ return 0;
212
213 2 ft = flowtable_lookup_fuzzy(cmd->handle.flowtable.name,
214 2 &ctx->nft->cache, &table);
215 /* check table first. */
216
1/2
✓ Branch 0 (8→9) taken 2 times.
✗ Branch 1 (8→10) not taken.
2 if (!table)
217 2 return 0;
218
219 ✗ if (table_fuzzy_check(ctx, cmd, table))
220 ✗ return 1;
221
222 ✗ if (!ft)
223 ✗ return 0;
224
225 ✗ netlink_io_error(ctx, loc, "%s; did you mean flowtable '%s' in table %s '%s'?",
226 strerror(ENOENT), ft->handle.flowtable.name,
227 ✗ family2str(ft->handle.family),
228 ✗ table->handle.table.name);
229 ✗ return 1;
230 }
231
232 809 static void nft_cmd_enoent(struct netlink_ctx *ctx, const struct cmd *cmd,
233 const struct location *loc, int err)
234 {
235 809 int ret = 0;
236
237
7/7
✓ Branch 0 (2→3) taken 5 times.
✓ Branch 1 (2→5) taken 6 times.
✓ Branch 2 (2→7) taken 10 times.
✓ Branch 3 (2→9) taken 13 times.
✓ Branch 4 (2→11) taken 2 times.
✓ Branch 5 (2→13) taken 3 times.
✓ Branch 6 (2→15) taken 770 times.
809 switch (cmd->obj) {
238 5 case CMD_OBJ_TABLE:
239 5 ret = nft_cmd_enoent_table(ctx, cmd, loc);
240 5 break;
241 6 case CMD_OBJ_CHAIN:
242 6 ret = nft_cmd_enoent_chain(ctx, cmd, loc);
243 6 break;
244 10 case CMD_OBJ_SET:
245 10 ret = nft_cmd_enoent_set(ctx, cmd, loc);
246 10 break;
247 13 case CMD_OBJ_RULE:
248 13 ret = nft_cmd_enoent_rule(ctx, cmd, loc);
249 13 break;
250 2 case CMD_OBJ_COUNTER:
251 case CMD_OBJ_QUOTA:
252 case CMD_OBJ_CT_HELPER:
253 case CMD_OBJ_CT_TIMEOUT:
254 case CMD_OBJ_LIMIT:
255 case CMD_OBJ_SECMARK:
256 case CMD_OBJ_CT_EXPECT:
257 case CMD_OBJ_SYNPROXY:
258 2 ret = nft_cmd_enoent_obj(ctx, cmd, loc);
259 2 break;
260 3 case CMD_OBJ_FLOWTABLE:
261 3 ret = nft_cmd_enoent_flowtable(ctx, cmd, loc);
262 3 break;
263 770 default:
264 770 break;
265 }
266
267
2/2
✓ Branch 0 (16→17) taken 1 times.
✓ Branch 1 (16→18) taken 808 times.
809 if (ret)
268 1 return;
269
270 808 netlink_io_error(ctx, loc, "Could not process rule: %s", strerror(err));
271 }
272
273 6 static int nft_cmd_chain_error(struct netlink_ctx *ctx, struct cmd *cmd,
274 struct mnl_err *err)
275 {
276 6 struct chain *chain = cmd->chain, *existing_chain;
277 const struct table *table;
278 int priority;
279
280
2/2
✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→26) taken 5 times.
6 switch (err->err) {
281 1 case EOPNOTSUPP:
282
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→5) taken 1 times.
1 if (!(chain->flags & CHAIN_F_BASECHAIN))
283 ✗ break;
284
285
1/4
✗ Branch 0 (5→6) not taken.
✓ Branch 1 (5→27) taken 1 times.
✗ Branch 2 (6→7) not taken.
✗ Branch 3 (6→27) not taken.
1 if (!chain->priority.expr || !chain->type.str)
286 break;
287
288 ✗ mpz_export_data(&priority, chain->priority.expr->value,
289 BYTEORDER_HOST_ENDIAN, sizeof(int));
290 ✗ if (priority <= -200 && !strcmp(chain->type.str, "nat"))
291 ✗ return netlink_io_error(ctx, &chain->priority.loc,
292 "Chains of type \"nat\" must have a priority value above -200");
293
294 ✗ if (nft_cache_update(ctx->nft, NFT_CACHE_TABLE | NFT_CACHE_CHAIN,
295 ctx->msgs, NULL) < 0) {
296 ✗ return netlink_io_error(ctx, &chain->loc,
297 "Chain of type \"%s\" is not supported, perhaps kernel support is missing?",
298 chain->type.str);
299 }
300
301 ✗ table = table_cache_find(&ctx->nft->cache.table_cache,
302 cmd->handle.table.name, cmd->handle.family);
303 ✗ if (table) {
304 ✗ existing_chain = chain_cache_find(table, cmd->handle.chain.name);
305 ✗ if (existing_chain && existing_chain != chain &&
306 ✗ !strcmp(existing_chain->handle.chain.name, chain->handle.chain.name))
307 ✗ return netlink_io_error(ctx, &chain->loc,
308 "Chain \"%s\" already exists in table %s '%s' with different declaration",
309 chain->handle.chain.name,
310 ✗ family2str(table->handle.family), table->handle.table.name);
311 }
312
313 ✗ return netlink_io_error(ctx, &chain->loc,
314 "Chain of type \"%s\" is not supported, perhaps kernel support is missing?",
315 chain->type.str);
316 5 default:
317 5 break;
318 }
319
320 6 return 0;
321 }
322
323 940 void nft_cmd_error(struct netlink_ctx *ctx, struct cmd *cmd,
324 struct mnl_err *err)
325 {
326 940 const struct location *loc = NULL;
327 uint32_t i;
328
329
2/2
✓ Branch 0 (7→3) taken 9521 times.
✓ Branch 1 (7→8) taken 940 times.
10461 for (i = 0; i < cmd->num_attrs; i++) {
330
1/2
✓ Branch 0 (3→4) taken 9521 times.
✗ Branch 1 (3→6) not taken.
9521 if (cmd->attr[i].seqnum == err->seqnum &&
331
2/2
✓ Branch 0 (4→5) taken 889 times.
✓ Branch 1 (4→6) taken 8632 times.
9521 cmd->attr[i].offset == err->offset)
332 889 loc = cmd->attr[i].location;
333 }
334
335
2/2
✓ Branch 0 (8→9) taken 889 times.
✓ Branch 1 (8→12) taken 51 times.
940 if (loc) {
336
2/2
✓ Branch 0 (9→10) taken 809 times.
✓ Branch 1 (9→13) taken 80 times.
889 if (err->err == ENOENT) {
337 809 nft_cmd_enoent(ctx, cmd, loc, err->err);
338 809 return;
339 }
340 } else {
341 51 loc = &cmd->location;
342 }
343
344
2/2
✓ Branch 0 (13→14) taken 6 times.
✓ Branch 1 (13→18) taken 125 times.
131 switch (cmd->obj) {
345 6 case CMD_OBJ_CHAIN:
346
1/2
✗ Branch 0 (15→16) not taken.
✓ Branch 1 (15→17) taken 6 times.
6 if (nft_cmd_chain_error(ctx, cmd, err) < 0)
347 ✗ return;
348 6 break;
349 125 default:
350 125 break;
351 }
352
353
1/4
✗ Branch 0 (19→20) not taken.
✓ Branch 1 (19→23) taken 131 times.
✗ Branch 2 (20→21) not taken.
✗ Branch 3 (20→23) not taken.
131 if (cmd->op == CMD_DESTROY && err->err == EINVAL) {
354 ✗ netlink_io_error(ctx, loc,
355 "\"destroy\" command is not supported, perhaps kernel support is missing?");
356 ✗ return;
357 }
358
359 131 netlink_io_error(ctx, loc, "Could not process rule: %s",
360 strerror(err->err));
361 }
362
363 2526 static void nft_cmd_expand_chain(struct chain *chain, struct list_head *new_cmds)
364 {
365 struct rule *rule, *next;
366 struct handle h;
367 struct cmd *new;
368
369
2/2
✓ Branch 0 (11→3) taken 43107 times.
✓ Branch 1 (11→12) taken 2526 times.
45633 list_for_each_entry_safe(rule, next, &chain->rules, list) {
370 43107 list_del(&rule->list);
371 43107 handle_merge(&rule->handle, &chain->handle);
372 43107 memset(&h, 0, sizeof(h));
373 43107 handle_merge(&h, &chain->handle);
374
1/2
✗ Branch 0 (6→7) not taken.
✓ Branch 1 (6→8) taken 43107 times.
43107 if (chain->flags & CHAIN_F_BINDING) {
375 ✗ rule->handle.chain_id = chain->handle.chain_id;
376 ✗ rule->handle.chain.location = chain->location;
377 }
378 43107 new = cmd_alloc(CMD_ADD, CMD_OBJ_RULE, &h,
379 43107 &rule->location, rule);
380 43107 list_add_tail(&new->list, new_cmds);
381 }
382 2526 }
383
384 23415 bool nft_cmd_collapse_elems(enum cmd_ops op, struct list_head *cmds,
385 struct handle *handle, struct expr *init)
386 {
387 struct cmd *last_cmd;
388
389
2/2
✓ Branch 0 (3→4) taken 2124 times.
✓ Branch 1 (3→5) taken 21291 times.
23415 if (list_empty(cmds))
390 2124 return false;
391
392
2/2
✓ Branch 0 (5→6) taken 4 times.
✓ Branch 1 (5→7) taken 21287 times.
21291 if (init->etype == EXPR_VARIABLE)
393 4 return false;
394
395 21287 last_cmd = list_last_entry(cmds, struct cmd, list);
396
2/2
✓ Branch 0 (7→8) taken 21092 times.
✓ Branch 1 (7→13) taken 195 times.
21287 if (last_cmd->op != op ||
397
2/2
✓ Branch 0 (8→9) taken 21032 times.
✓ Branch 1 (8→13) taken 60 times.
21092 last_cmd->obj != CMD_OBJ_ELEMENTS ||
398
2/2
✓ Branch 0 (9→10) taken 21031 times.
✓ Branch 1 (9→13) taken 1 times.
21032 last_cmd->expr->etype == EXPR_VARIABLE ||
399
2/2
✓ Branch 0 (10→11) taken 21030 times.
✓ Branch 1 (10→13) taken 1 times.
21031 last_cmd->handle.family != handle->family ||
400
1/2
✓ Branch 0 (11→12) taken 21030 times.
✗ Branch 1 (11→13) not taken.
21030 strcmp(last_cmd->handle.table.name, handle->table.name) ||
401
2/2
✓ Branch 0 (12→13) taken 20972 times.
✓ Branch 1 (12→14) taken 58 times.
21030 strcmp(last_cmd->handle.set.name, handle->set.name))
402 21229 return false;
403
404 58 list_splice_tail_init(&expr_set(init)->expressions,
405
2/4
✗ Branch 0 (14→15) not taken.
✓ Branch 1 (14→16) taken 58 times.
✗ Branch 2 (16→17) not taken.
✓ Branch 3 (16→18) taken 58 times.
58 &expr_set(last_cmd->expr)->expressions);
406
2/4
✗ Branch 0 (19→20) not taken.
✓ Branch 1 (19→21) taken 58 times.
✗ Branch 2 (21→22) not taken.
✓ Branch 3 (21→23) taken 58 times.
58 expr_set(last_cmd->expr)->size += expr_set(init)->size;
407
408 58 return true;
409 }
410
411 147551 void nft_cmd_expand(struct cmd *cmd)
412 {
413 struct list_head new_cmds;
414 struct flowtable *ft;
415 struct table *table;
416 struct chain *chain;
417 struct set *set;
418 struct obj *obj;
419 struct cmd *new;
420 struct handle h;
421
422 147551 init_list_head(&new_cmds);
423
424
4/4
✓ Branch 0 (3→4) taken 3524 times.
✓ Branch 1 (3→45) taken 7503 times.
✓ Branch 2 (3→51) taken 2929 times.
✓ Branch 3 (3→58) taken 133595 times.
147551 switch (cmd->obj) {
425 3524 case CMD_OBJ_TABLE:
426 3524 table = cmd->table;
427
2/2
✓ Branch 0 (4→5) taken 2073 times.
✓ Branch 1 (4→6) taken 1451 times.
3524 if (!table)
428 2073 return;
429
430
2/2
✓ Branch 0 (13→7) taken 2521 times.
✓ Branch 1 (13→14) taken 1451 times.
3972 list_for_each_entry(chain, &table->chains, list) {
431 2521 handle_merge(&chain->handle, &table->handle);
432 2521 memset(&h, 0, sizeof(h));
433 2521 handle_merge(&h, &chain->handle);
434 2521 h.chain_id = chain->handle.chain_id;
435 2521 new = cmd_alloc(CMD_ADD, CMD_OBJ_CHAIN, &h,
436 2521 &chain->location, chain_get(chain));
437 2521 list_add_tail(&new->list, &new_cmds);
438 }
439
2/2
✓ Branch 0 (22→15) taken 276 times.
✓ Branch 1 (22→23) taken 1451 times.
1727 list_for_each_entry(obj, &table->objs, list) {
440 276 handle_merge(&obj->handle, &table->handle);
441 276 memset(&h, 0, sizeof(h));
442 276 handle_merge(&h, &obj->handle);
443 276 new = cmd_alloc(CMD_ADD, obj_type_to_cmd(obj->type), &h,
444 276 &obj->location, obj_get(obj));
445 276 list_add_tail(&new->list, &new_cmds);
446 }
447
2/2
✓ Branch 0 (30→24) taken 875 times.
✓ Branch 1 (30→31) taken 1451 times.
2326 list_for_each_entry(set, &table->sets, list) {
448 875 handle_merge(&set->handle, &table->handle);
449 875 memset(&h, 0, sizeof(h));
450 875 handle_merge(&h, &set->handle);
451 875 new = cmd_alloc(CMD_ADD, CMD_OBJ_SET, &h,
452 875 &set->location, set_get(set));
453 875 list_add_tail(&new->list, &new_cmds);
454 }
455
2/2
✓ Branch 0 (38→32) taken 37 times.
✓ Branch 1 (38→39) taken 1451 times.
1488 list_for_each_entry(ft, &table->flowtables, list) {
456 37 handle_merge(&ft->handle, &table->handle);
457 37 memset(&h, 0, sizeof(h));
458 37 handle_merge(&h, &ft->handle);
459 37 new = cmd_alloc(CMD_ADD, CMD_OBJ_FLOWTABLE, &h,
460 37 &ft->location, flowtable_get(ft));
461 37 list_add_tail(&new->list, &new_cmds);
462 }
463
2/2
✓ Branch 0 (42→40) taken 2521 times.
✓ Branch 1 (42→43) taken 1451 times.
3972 list_for_each_entry(chain, &table->chains, list)
464 2521 nft_cmd_expand_chain(chain, &new_cmds);
465
466 1451 list_splice(&new_cmds, &cmd->list);
467 1451 break;
468 7503 case CMD_OBJ_CHAIN:
469 7503 chain = cmd->chain;
470
4/4
✓ Branch 0 (45→46) taken 5443 times.
✓ Branch 1 (45→59) taken 2060 times.
✓ Branch 2 (47→48) taken 5 times.
✓ Branch 3 (47→59) taken 5438 times.
7503 if (!chain || list_empty(&chain->rules))
471 break;
472
473 5 nft_cmd_expand_chain(chain, &new_cmds);
474 5 list_splice(&new_cmds, &cmd->list);
475 5 break;
476 2929 case CMD_OBJ_SET:
477 case CMD_OBJ_MAP:
478 2929 set = cmd->set;
479
2/2
✓ Branch 0 (51→52) taken 1847 times.
✓ Branch 1 (51→53) taken 1082 times.
2929 if (!set->init)
480 1847 break;
481
482 1082 memset(&h, 0, sizeof(h));
483 1082 handle_merge(&h, &set->handle);
484 1082 new = cmd_alloc(CMD_ADD, CMD_OBJ_SETELEMS, &h,
485 1082 &set->location, set_get(set));
486 1082 list_add(&new->list, &cmd->list);
487 1082 break;
488 133595 default:
489 133595 break;
490 }
491 }
492