blob: a778650ac133af33549104248469ef98d57f961a (
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*
* Copyright (c) 2019 Pablo Neira Ayuso <pablo@netfilter.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 (or any
* later) as published by the Free Software Foundation.
*/
#include <expression.h>
#include <statement.h>
#include <rule.h>
#include <erec.h>
#include <utils.h>
#include <cache.h>
static unsigned int evaluate_cache_add(struct cmd *cmd, unsigned int flags)
{
switch (cmd->obj) {
case CMD_OBJ_CHAIN:
case CMD_OBJ_SET:
case CMD_OBJ_COUNTER:
case CMD_OBJ_QUOTA:
case CMD_OBJ_LIMIT:
case CMD_OBJ_SECMARK:
case CMD_OBJ_FLOWTABLE:
flags |= NFT_CACHE_TABLE;
break;
case CMD_OBJ_SETELEM:
flags |= NFT_CACHE_TABLE |
NFT_CACHE_CHAIN |
NFT_CACHE_SET |
NFT_CACHE_OBJECT |
NFT_CACHE_SETELEM;
break;
case CMD_OBJ_RULE:
flags |= NFT_CACHE_TABLE |
NFT_CACHE_CHAIN |
NFT_CACHE_SET |
NFT_CACHE_OBJECT |
NFT_CACHE_FLOWTABLE;
if (cmd->handle.index.id ||
cmd->handle.position.id)
flags |= NFT_CACHE_RULE | NFT_CACHE_UPDATE;
break;
default:
break;
}
return flags;
}
static unsigned int evaluate_cache_del(struct cmd *cmd, unsigned int flags)
{
switch (cmd->obj) {
case CMD_OBJ_SETELEM:
flags |= NFT_CACHE_SETELEM;
break;
default:
break;
}
return flags;
}
static unsigned int evaluate_cache_flush(struct cmd *cmd, unsigned int flags)
{
switch (cmd->obj) {
case CMD_OBJ_SET:
case CMD_OBJ_MAP:
case CMD_OBJ_METER:
flags |= NFT_CACHE_SET;
break;
case CMD_OBJ_RULESET:
flags |= NFT_CACHE_FLUSHED;
break;
default:
break;
}
return flags;
}
static unsigned int evaluate_cache_rename(struct cmd *cmd, unsigned int flags)
{
switch (cmd->obj) {
case CMD_OBJ_CHAIN:
flags |= NFT_CACHE_CHAIN;
break;
default:
break;
}
return flags;
}
unsigned int cache_evaluate(struct nft_ctx *nft, struct list_head *cmds)
{
unsigned int flags = NFT_CACHE_EMPTY;
struct cmd *cmd;
list_for_each_entry(cmd, cmds, list) {
switch (cmd->op) {
case CMD_ADD:
case CMD_INSERT:
case CMD_CREATE:
flags = evaluate_cache_add(cmd, flags);
if (nft_output_echo(&nft->output))
flags |= NFT_CACHE_FULL;
break;
case CMD_REPLACE:
flags = NFT_CACHE_FULL;
break;
case CMD_DELETE:
flags |= NFT_CACHE_TABLE |
NFT_CACHE_CHAIN |
NFT_CACHE_SET |
NFT_CACHE_FLOWTABLE |
NFT_CACHE_OBJECT;
flags = evaluate_cache_del(cmd, flags);
break;
case CMD_GET:
case CMD_LIST:
case CMD_RESET:
case CMD_EXPORT:
case CMD_MONITOR:
flags |= NFT_CACHE_FULL;
break;
case CMD_FLUSH:
flags = evaluate_cache_flush(cmd, flags);
break;
case CMD_RENAME:
flags = evaluate_cache_rename(cmd, flags);
break;
case CMD_DESCRIBE:
case CMD_IMPORT:
break;
default:
break;
}
}
return flags;
}
|