configure: Avoid addition assignment operators
[iptables-mirror.git] / iptables / nft-chain.c
blobc24e6c9b346d114149a243510125f80bc2623875
1 /*
2 * Copyright (c) 2020 Red Hat GmbH. Author: Phil Sutter <phil@nwl.cc>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
10 #include <stdlib.h>
11 #include <xtables.h>
13 #include "nft-chain.h"
15 struct nft_chain *nft_chain_alloc(struct nftnl_chain *nftnl, bool fake)
17 struct nft_chain *c = xtables_malloc(sizeof(*c));
19 INIT_LIST_HEAD(&c->head);
20 c->nftnl = nftnl;
21 c->fake = fake;
23 return c;
26 void nft_chain_free(struct nft_chain *c)
28 if (c->nftnl)
29 nftnl_chain_free(c->nftnl);
30 free(c);
33 struct nft_chain_list *nft_chain_list_alloc(void)
35 struct nft_chain_list *list = xtables_malloc(sizeof(*list));
36 int i;
38 INIT_LIST_HEAD(&list->list);
39 for (i = 0; i < CHAIN_NAME_HSIZE; i++)
40 INIT_HLIST_HEAD(&list->names[i]);
42 return list;
45 void nft_chain_list_del(struct nft_chain *c)
47 list_del(&c->head);
48 hlist_del(&c->hnode);
51 void nft_chain_list_free(struct nft_chain_list *list)
53 struct nft_chain *c, *c2;
55 list_for_each_entry_safe(c, c2, &list->list, head) {
56 nft_chain_list_del(c);
57 nft_chain_free(c);
59 free(list);