1 /* 2 * Copyright (c) 2020 Red Hat GmbH. Author: Phil Sutter <phil@nwl.cc> 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 as published 6 * by the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 */ 9 10 #include <stdlib.h> 11 #include <xtables.h> 12 13 #include "nft-chain.h" 14 nft_chain_alloc(struct nftnl_chain * nftnl)15struct nft_chain *nft_chain_alloc(struct nftnl_chain *nftnl) 16 { 17 struct nft_chain *c = xtables_malloc(sizeof(*c)); 18 19 INIT_LIST_HEAD(&c->head); 20 c->nftnl = nftnl; 21 22 return c; 23 } 24 nft_chain_free(struct nft_chain * c)25void nft_chain_free(struct nft_chain *c) 26 { 27 if (c->nftnl) 28 nftnl_chain_free(c->nftnl); 29 free(c); 30 } 31 nft_chain_list_alloc(void)32struct nft_chain_list *nft_chain_list_alloc(void) 33 { 34 struct nft_chain_list *list = xtables_malloc(sizeof(*list)); 35 int i; 36 37 INIT_LIST_HEAD(&list->list); 38 for (i = 0; i < CHAIN_NAME_HSIZE; i++) 39 INIT_HLIST_HEAD(&list->names[i]); 40 41 return list; 42 } 43 nft_chain_list_del(struct nft_chain * c)44void nft_chain_list_del(struct nft_chain *c) 45 { 46 list_del(&c->head); 47 hlist_del(&c->hnode); 48 } 49 nft_chain_list_free(struct nft_chain_list * list)50void nft_chain_list_free(struct nft_chain_list *list) 51 { 52 struct nft_chain *c, *c2; 53 54 list_for_each_entry_safe(c, c2, &list->list, head) { 55 nft_chain_list_del(c); 56 nft_chain_free(c); 57 } 58 free(list); 59 } 60