summaryrefslogtreecommitdiffstats
path: root/include/payload.h
blob: 08e45f7f79e243ddb52fb0ce6d405183b1ecae05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef NFTABLES_PAYLOAD_H
#define NFTABLES_PAYLOAD_H

#include <nftables.h>
#include <proto.h>

extern struct expr *payload_expr_alloc(const struct location *loc,
				       const struct proto_desc *desc,
				       unsigned int type);
extern void payload_init_raw(struct expr *expr, enum proto_bases base,
			     unsigned int offset, unsigned int len);
extern unsigned int payload_hdr_field(const struct expr *expr);

struct eval_ctx;
struct stmt;
extern int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr,
				  struct stmt **res);
int payload_gen_inner_dependency(struct eval_ctx *ctx, const struct expr *expr,
				 struct stmt **res);
extern int payload_gen_icmp_dependency(struct eval_ctx *ctx,
				       const struct expr *expr,
				       struct stmt **res);
extern int exthdr_gen_dependency(struct eval_ctx *ctx, const struct expr *expr,
				 const struct proto_desc *dependency,
				 enum proto_bases pb, struct stmt **res);

/**
 * struct payload_dep_ctx - payload protocol dependency tracking
 *
 * @icmp_type: extra info for icmp(6) decoding
 * @prev: previous statement
 * @pdeps: last dependency match per protocol layer
 */
struct payload_dep_ctx {
	uint8_t		icmp_type;
	struct stmt	*prev;
	struct stmt	*pdeps[PROTO_BASE_MAX + 1];
};

extern bool payload_is_known(const struct expr *expr);
extern bool payload_is_stacked(const struct proto_desc *desc,
			       const struct expr *expr);

void payload_dependency_reset(struct payload_dep_ctx *ctx);
extern void payload_dependency_store(struct payload_dep_ctx *ctx,
				     struct stmt *stmt,
				     enum proto_bases base);
extern bool payload_dependency_exists(const struct payload_dep_ctx *ctx,
				      enum proto_bases base);
extern struct expr *payload_dependency_get(struct payload_dep_ctx *ctx,
					   enum proto_bases base);
extern void payload_dependency_release(struct payload_dep_ctx *ctx,
				       enum proto_bases base);
extern void payload_dependency_kill(struct payload_dep_ctx *ctx,
				    struct expr *expr, unsigned int family);
extern void exthdr_dependency_kill(struct payload_dep_ctx *ctx,
				   struct expr *expr, unsigned int family);

extern bool payload_can_merge(const struct expr *e1, const struct expr *e2);
extern struct expr *payload_expr_join(const struct expr *e1,
				      const struct expr *e2);

bool payload_expr_trim(struct expr *expr, struct expr *mask,
		       const struct proto_ctx *ctx, unsigned int *shift);
extern void payload_expr_expand(struct list_head *list, struct expr *expr,
				const struct proto_ctx *ctx);
extern void payload_expr_complete(struct expr *expr,
				  const struct proto_ctx *ctx);

bool payload_expr_cmp(const struct expr *e1, const struct expr *e2);

const struct proto_desc *find_proto_desc(const struct nftnl_udata *ud);

#endif /* NFTABLES_PAYLOAD_H */