| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef NFTABLES_NFTABLES_H | ||
| 2 | #define NFTABLES_NFTABLES_H | ||
| 3 | |||
| 4 | #include <stdarg.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <utils.h> | ||
| 7 | #include <cache.h> | ||
| 8 | #include <nftables/libnftables.h> | ||
| 9 | |||
| 10 | struct cookie { | ||
| 11 | FILE *fp; | ||
| 12 | FILE *orig_fp; | ||
| 13 | char *buf; | ||
| 14 | size_t buflen; | ||
| 15 | size_t pos; | ||
| 16 | }; | ||
| 17 | |||
| 18 | struct symbol_tables { | ||
| 19 | const struct symbol_table *mark; | ||
| 20 | const struct symbol_table *devgroup; | ||
| 21 | const struct symbol_table *ct_label; | ||
| 22 | const struct symbol_table *realm; | ||
| 23 | }; | ||
| 24 | |||
| 25 | struct input_ctx { | ||
| 26 | unsigned int flags; | ||
| 27 | }; | ||
| 28 | |||
| 29 | 1195581 | static inline bool nft_input_no_dns(const struct input_ctx *ictx) | |
| 30 | { | ||
| 31 | 1195581 | return ictx->flags & NFT_CTX_INPUT_NO_DNS; | |
| 32 | } | ||
| 33 | |||
| 34 | 43079 | static inline bool nft_input_json(const struct input_ctx *ictx) | |
| 35 | { | ||
| 36 | 43079 | return ictx->flags & NFT_CTX_INPUT_JSON; | |
| 37 | } | ||
| 38 | |||
| 39 | struct output_ctx { | ||
| 40 | unsigned int flags; | ||
| 41 | bool force_newline; | ||
| 42 | union { | ||
| 43 | FILE *output_fp; | ||
| 44 | struct cookie output_cookie; | ||
| 45 | }; | ||
| 46 | union { | ||
| 47 | FILE *error_fp; | ||
| 48 | struct cookie error_cookie; | ||
| 49 | }; | ||
| 50 | struct symbol_tables tbl; | ||
| 51 | }; | ||
| 52 | |||
| 53 | 454945 | static inline bool nft_output_reversedns(const struct output_ctx *octx) | |
| 54 | { | ||
| 55 | 454945 | return octx->flags & NFT_CTX_OUTPUT_REVERSEDNS; | |
| 56 | } | ||
| 57 | |||
| 58 | 71494 | static inline bool nft_output_service(const struct output_ctx *octx) | |
| 59 | { | ||
| 60 | 71494 | return octx->flags & NFT_CTX_OUTPUT_SERVICE; | |
| 61 | } | ||
| 62 | |||
| 63 | 265534 | static inline bool nft_output_stateless(const struct output_ctx *octx) | |
| 64 | { | ||
| 65 | 265534 | return octx->flags & NFT_CTX_OUTPUT_STATELESS; | |
| 66 | } | ||
| 67 | |||
| 68 | 60188 | static inline bool nft_output_handle(const struct output_ctx *octx) | |
| 69 | { | ||
| 70 | 60188 | return octx->flags & NFT_CTX_OUTPUT_HANDLE; | |
| 71 | } | ||
| 72 | |||
| 73 | 131929 | static inline bool nft_output_json(const struct output_ctx *octx) | |
| 74 | { | ||
| 75 | 131929 | return octx->flags & NFT_CTX_OUTPUT_JSON; | |
| 76 | } | ||
| 77 | |||
| 78 | 273475 | static inline bool nft_output_echo(const struct output_ctx *octx) | |
| 79 | { | ||
| 80 | 273475 | return octx->flags & NFT_CTX_OUTPUT_ECHO; | |
| 81 | } | ||
| 82 | |||
| 83 | 560 | static inline bool nft_output_guid(const struct output_ctx *octx) | |
| 84 | { | ||
| 85 | 560 | return octx->flags & NFT_CTX_OUTPUT_GUID; | |
| 86 | } | ||
| 87 | |||
| 88 | 1058 | static inline bool nft_output_seconds(const struct output_ctx *octx) | |
| 89 | { | ||
| 90 | 1058 | return octx->flags & NFT_CTX_OUTPUT_NUMERIC_TIME; | |
| 91 | } | ||
| 92 | |||
| 93 | 2617 | static inline bool nft_output_numeric_proto(const struct output_ctx *octx) | |
| 94 | { | ||
| 95 | 2617 | return octx->flags & NFT_CTX_OUTPUT_NUMERIC_PROTO; | |
| 96 | } | ||
| 97 | |||
| 98 | 8795 | static inline bool nft_output_numeric_prio(const struct output_ctx *octx) | |
| 99 | { | ||
| 100 | 8795 | return octx->flags & NFT_CTX_OUTPUT_NUMERIC_PRIO; | |
| 101 | } | ||
| 102 | |||
| 103 | 7650 | static inline bool nft_output_numeric_symbol(const struct output_ctx *octx) | |
| 104 | { | ||
| 105 | 7650 | return octx->flags & NFT_CTX_OUTPUT_NUMERIC_SYMBOL; | |
| 106 | } | ||
| 107 | |||
| 108 | 22669 | static inline bool nft_output_terse(const struct output_ctx *octx) | |
| 109 | { | ||
| 110 | 22669 | return octx->flags & NFT_CTX_OUTPUT_TERSE; | |
| 111 | } | ||
| 112 | |||
| 113 | struct mnl_socket; | ||
| 114 | struct parser_state; | ||
| 115 | struct scope; | ||
| 116 | |||
| 117 | struct nft_vars { | ||
| 118 | const char *key; | ||
| 119 | const char *value; | ||
| 120 | }; | ||
| 121 | |||
| 122 | #define MAX_INCLUDE_DEPTH 16 | ||
| 123 | |||
| 124 | struct nft_ctx { | ||
| 125 | struct mnl_socket *nf_sock; | ||
| 126 | char **include_paths; | ||
| 127 | unsigned int num_include_paths; | ||
| 128 | struct nft_vars *vars; | ||
| 129 | struct { | ||
| 130 | const char *buf; | ||
| 131 | struct list_head indesc_list; | ||
| 132 | } vars_ctx; | ||
| 133 | unsigned int num_vars; | ||
| 134 | unsigned int parser_max_errors; | ||
| 135 | unsigned int debug_mask; | ||
| 136 | struct input_ctx input; | ||
| 137 | struct output_ctx output; | ||
| 138 | bool check; | ||
| 139 | struct nft_cache cache; | ||
| 140 | uint32_t flags; | ||
| 141 | uint32_t optimize_flags; | ||
| 142 | struct parser_state *state; | ||
| 143 | void *scanner; | ||
| 144 | struct scope *top_scope; | ||
| 145 | void *json_root; | ||
| 146 | json_t *json_echo; | ||
| 147 | const char *stdin_buf; | ||
| 148 | #if HAVE_FUZZER_BUILD | ||
| 149 | int afl_ctx_stage; | ||
| 150 | #endif | ||
| 151 | }; | ||
| 152 | |||
| 153 | enum nftables_exit_codes { | ||
| 154 | NFT_EXIT_SUCCESS = 0, | ||
| 155 | NFT_EXIT_FAILURE = 1, | ||
| 156 | NFT_EXIT_NOMEM = 2, | ||
| 157 | NFT_EXIT_NONL = 3, | ||
| 158 | }; | ||
| 159 | |||
| 160 | struct input_descriptor; | ||
| 161 | struct location { | ||
| 162 | const struct input_descriptor *indesc; | ||
| 163 | union { | ||
| 164 | struct { | ||
| 165 | unsigned int line_offset; | ||
| 166 | unsigned int first_line; | ||
| 167 | unsigned int first_column; | ||
| 168 | unsigned int last_column; | ||
| 169 | }; | ||
| 170 | struct { | ||
| 171 | const void *nle; | ||
| 172 | }; | ||
| 173 | }; | ||
| 174 | }; | ||
| 175 | |||
| 176 | extern const struct location internal_location; | ||
| 177 | |||
| 178 | /** | ||
| 179 | * enum input_descriptor_types | ||
| 180 | * | ||
| 181 | * @INDESC_INVALID: invalid | ||
| 182 | * @INDESC_INTERNAL: dummy type for internally generated messages | ||
| 183 | * @INDESC_BUFFER: buffer (command line arguments) | ||
| 184 | * @INDESC_FILE: file | ||
| 185 | * @INDESC_CLI: command line interface | ||
| 186 | * @INDESC_NETLINK: received from netlink | ||
| 187 | */ | ||
| 188 | enum input_descriptor_types { | ||
| 189 | INDESC_INVALID, | ||
| 190 | INDESC_INTERNAL, | ||
| 191 | INDESC_BUFFER, | ||
| 192 | INDESC_FILE, | ||
| 193 | INDESC_CLI, | ||
| 194 | INDESC_NETLINK, | ||
| 195 | INDESC_STDIN, | ||
| 196 | }; | ||
| 197 | |||
| 198 | /** | ||
| 199 | * struct input_descriptor | ||
| 200 | * | ||
| 201 | * @location: location, used for include statements | ||
| 202 | * @f: file descriptor | ||
| 203 | * @depth: include depth of the descriptor | ||
| 204 | * @type: input descriptor type | ||
| 205 | * @name: name describing the input | ||
| 206 | * @union: buffer or file descriptor, depending on type | ||
| 207 | * @lineno: current line number in the input | ||
| 208 | * @column: current column in the input | ||
| 209 | * @token_offset: offset of the current token to the beginning | ||
| 210 | * @line_offset: offset of the current line to the beginning | ||
| 211 | */ | ||
| 212 | struct input_descriptor { | ||
| 213 | struct list_head list; | ||
| 214 | FILE *f; | ||
| 215 | unsigned int depth; | ||
| 216 | struct location location; | ||
| 217 | enum input_descriptor_types type; | ||
| 218 | const char *name; | ||
| 219 | const char *data; | ||
| 220 | unsigned int lineno; | ||
| 221 | unsigned int column; | ||
| 222 | off_t token_offset; | ||
| 223 | off_t line_offset; | ||
| 224 | }; | ||
| 225 | |||
| 226 | void ct_label_table_init(struct nft_ctx *ctx); | ||
| 227 | void mark_table_init(struct nft_ctx *ctx); | ||
| 228 | void realm_table_rt_init(struct nft_ctx *ctx); | ||
| 229 | void devgroup_table_init(struct nft_ctx *ctx); | ||
| 230 | void xt_init(void); | ||
| 231 | |||
| 232 | void ct_label_table_exit(struct nft_ctx *ctx); | ||
| 233 | void mark_table_exit(struct nft_ctx *ctx); | ||
| 234 | void devgroup_table_exit(struct nft_ctx *ctx); | ||
| 235 | void realm_table_rt_exit(struct nft_ctx *ctx); | ||
| 236 | |||
| 237 | int nft_print(struct output_ctx *octx, const char *fmt, ...) | ||
| 238 | __attribute__((format(printf, 2, 3))); | ||
| 239 | int nft_gmp_print(struct output_ctx *octx, const char *fmt, ...); | ||
| 240 | |||
| 241 | int nft_optimize(struct nft_ctx *nft, struct list_head *cmds); | ||
| 242 | |||
| 243 | #define __NFT_OUTPUT_NOTSUPP UINT_MAX | ||
| 244 | |||
| 245 | /* internal marker, not used by the kernel. */ | ||
| 246 | #define NFT_NEVER_TIMEOUT UINT64_MAX | ||
| 247 | |||
| 248 | #endif /* NFTABLES_NFTABLES_H */ | ||
| 249 |