| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef _NFT_CACHE_H_ | ||
| 2 | #define _NFT_CACHE_H_ | ||
| 3 | |||
| 4 | #include <list.h> | ||
| 5 | |||
| 6 | struct handle; | ||
| 7 | |||
| 8 | enum cache_level_bits { | ||
| 9 | NFT_CACHE_TABLE_BIT = (1 << 0), | ||
| 10 | NFT_CACHE_CHAIN_BIT = (1 << 1), | ||
| 11 | NFT_CACHE_SET_BIT = (1 << 2), | ||
| 12 | NFT_CACHE_FLOWTABLE_BIT = (1 << 3), | ||
| 13 | NFT_CACHE_OBJECT_BIT = (1 << 4), | ||
| 14 | NFT_CACHE_SETELEM_BIT = (1 << 5), | ||
| 15 | NFT_CACHE_RULE_BIT = (1 << 6), | ||
| 16 | __NFT_CACHE_MAX_BIT = (1 << 7), | ||
| 17 | }; | ||
| 18 | |||
| 19 | enum cache_level_flags { | ||
| 20 | NFT_CACHE_EMPTY = 0, | ||
| 21 | NFT_CACHE_TABLE = NFT_CACHE_TABLE_BIT, | ||
| 22 | NFT_CACHE_CHAIN = NFT_CACHE_TABLE_BIT | | ||
| 23 | NFT_CACHE_CHAIN_BIT, | ||
| 24 | NFT_CACHE_SET = NFT_CACHE_TABLE_BIT | | ||
| 25 | NFT_CACHE_SET_BIT, | ||
| 26 | NFT_CACHE_FLOWTABLE = NFT_CACHE_TABLE_BIT | | ||
| 27 | NFT_CACHE_FLOWTABLE_BIT, | ||
| 28 | NFT_CACHE_OBJECT = NFT_CACHE_TABLE_BIT | | ||
| 29 | NFT_CACHE_OBJECT_BIT, | ||
| 30 | NFT_CACHE_SETELEM = NFT_CACHE_TABLE_BIT | | ||
| 31 | NFT_CACHE_SET_BIT | | ||
| 32 | NFT_CACHE_SETELEM_BIT, | ||
| 33 | NFT_CACHE_RULE = NFT_CACHE_TABLE_BIT | | ||
| 34 | NFT_CACHE_RULE_BIT, | ||
| 35 | NFT_CACHE_FULL = __NFT_CACHE_MAX_BIT - 1, | ||
| 36 | NFT_CACHE_TERSE = (1 << 27), | ||
| 37 | NFT_CACHE_SETELEM_MAYBE = (1 << 28), | ||
| 38 | NFT_CACHE_REFRESH = (1 << 29), | ||
| 39 | NFT_CACHE_UPDATE = (1 << 30), | ||
| 40 | NFT_CACHE_FLUSHED = (1 << 31), | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct nft_filter_obj { | ||
| 44 | struct list_head list; | ||
| 45 | uint32_t family; | ||
| 46 | const char *table; | ||
| 47 | const char *set; | ||
| 48 | }; | ||
| 49 | |||
| 50 | #define NFT_CACHE_HSIZE 8192 | ||
| 51 | |||
| 52 | struct nft_cache_filter { | ||
| 53 | struct { | ||
| 54 | uint32_t family; | ||
| 55 | const char *table; | ||
| 56 | const char *chain; | ||
| 57 | const char *obj; | ||
| 58 | const char *set; | ||
| 59 | const char *ft; | ||
| 60 | int obj_type; | ||
| 61 | uint64_t rule_handle; | ||
| 62 | } list; | ||
| 63 | |||
| 64 | struct { | ||
| 65 | struct list_head head; | ||
| 66 | } obj[NFT_CACHE_HSIZE]; | ||
| 67 | |||
| 68 | struct { | ||
| 69 | bool obj; | ||
| 70 | bool rule; | ||
| 71 | bool elem; | ||
| 72 | } reset; | ||
| 73 | }; | ||
| 74 | |||
| 75 | struct nft_cache; | ||
| 76 | struct nft_ctx; | ||
| 77 | enum cmd_ops; | ||
| 78 | |||
| 79 | int nft_cache_evaluate(struct nft_ctx *nft, struct list_head *cmds, | ||
| 80 | struct list_head *msgs, struct nft_cache_filter *filter, | ||
| 81 | unsigned int *flags); | ||
| 82 | int nft_cache_update(struct nft_ctx *ctx, unsigned int flags, | ||
| 83 | struct list_head *msgs, | ||
| 84 | const struct nft_cache_filter *filter); | ||
| 85 | bool nft_cache_needs_update(struct nft_cache *cache); | ||
| 86 | void nft_cache_release(struct nft_cache *cache); | ||
| 87 | |||
| 88 | 601840 | static inline uint32_t djb_hash(const char *key) | |
| 89 | { | ||
| 90 | 601840 | uint32_t i, hash = 5381; | |
| 91 | |||
| 92 |
2/2✓ Branch 0 (4→3) taken 3043265 times.
✓ Branch 1 (4→5) taken 601840 times.
|
3645105 | for (i = 0; i < strlen(key); i++) |
| 93 | 3043265 | hash = ((hash << 5) + hash) + key[i]; | |
| 94 | |||
| 95 | 601840 | return hash; | |
| 96 | } | ||
| 97 | |||
| 98 | struct nft_cache_filter *nft_cache_filter_init(void); | ||
| 99 | void nft_cache_filter_fini(struct nft_cache_filter *filter); | ||
| 100 | |||
| 101 | struct table; | ||
| 102 | struct chain; | ||
| 103 | |||
| 104 | void chain_cache_add(struct chain *chain, struct table *table); | ||
| 105 | void chain_cache_del(struct chain *chain); | ||
| 106 | struct chain *chain_cache_find(const struct table *table, const char *name); | ||
| 107 | |||
| 108 | struct set; | ||
| 109 | |||
| 110 | void set_cache_add(struct set *set, struct table *table); | ||
| 111 | void set_cache_del(struct set *set); | ||
| 112 | struct set *set_cache_find(const struct table *table, const char *name); | ||
| 113 | |||
| 114 | struct cache { | ||
| 115 | struct list_head *ht; | ||
| 116 | struct list_head list; | ||
| 117 | }; | ||
| 118 | |||
| 119 | struct cache_item { | ||
| 120 | struct list_head hlist; | ||
| 121 | struct list_head list; | ||
| 122 | }; | ||
| 123 | |||
| 124 | void cache_init(struct cache *cache); | ||
| 125 | void cache_free(struct cache *cache); | ||
| 126 | void cache_add(struct cache_item *item, struct cache *cache, const char *name); | ||
| 127 | void cache_del(struct cache_item *item); | ||
| 128 | |||
| 129 | void table_cache_add(struct table *table, struct nft_cache *cache); | ||
| 130 | void table_cache_del(struct table *table); | ||
| 131 | struct table *table_cache_find(const struct cache *cache, const char *name, | ||
| 132 | uint32_t family); | ||
| 133 | |||
| 134 | struct obj; | ||
| 135 | |||
| 136 | void obj_cache_add(struct obj *obj, struct table *table); | ||
| 137 | void obj_cache_del(struct obj *obj); | ||
| 138 | struct obj *obj_cache_find(const struct table *table, const char *name, | ||
| 139 | uint32_t obj_type); | ||
| 140 | |||
| 141 | struct flowtable; | ||
| 142 | void ft_cache_add(struct flowtable *ft, struct table *table); | ||
| 143 | void ft_cache_del(struct flowtable *ft); | ||
| 144 | struct flowtable *ft_cache_find(const struct table *table, const char *name); | ||
| 145 | |||
| 146 | struct nft_cache { | ||
| 147 | uint32_t genid; | ||
| 148 | struct cache table_cache; | ||
| 149 | uint32_t seqnum; | ||
| 150 | uint32_t flags; | ||
| 151 | }; | ||
| 152 | |||
| 153 | struct netlink_ctx; | ||
| 154 | |||
| 155 | void nft_chain_cache_update(struct netlink_ctx *ctx, struct table *table, | ||
| 156 | const char *chain); | ||
| 157 | |||
| 158 | #endif /* _NFT_CACHE_H_ */ | ||
| 159 |