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
|
#include <nftables.h>
#include <expression.h>
#include <utils.h>
#include <string.h>
#include <osf.h>
#include <json.h>
static const char *osf_ttl_int_to_str(const uint8_t ttl)
{
if (ttl == 1)
return "ttl loose ";
else if (ttl == 2)
return "ttl skip ";
return "";
}
static void osf_expr_print(const struct expr *expr, struct output_ctx *octx)
{
const char *ttl_str = osf_ttl_int_to_str(expr->osf.ttl);
nft_print(octx, "osf %sname", ttl_str);
}
static void osf_expr_clone(struct expr *new, const struct expr *expr)
{
new->osf.ttl = expr->osf.ttl;
}
static bool osf_expr_cmp(const struct expr *e1, const struct expr *e2)
{
return e1->osf.ttl == e2->osf.ttl;
}
static const struct expr_ops osf_expr_ops = {
.type = EXPR_OSF,
.name = "osf",
.print = osf_expr_print,
.clone = osf_expr_clone,
.cmp = osf_expr_cmp,
.json = osf_expr_json,
};
struct expr *osf_expr_alloc(const struct location *loc, const uint8_t ttl)
{
unsigned int len = NFT_OSF_MAXGENRELEN * BITS_PER_BYTE;
const struct datatype *type = &string_type;
struct expr *expr;
expr = expr_alloc(loc, &osf_expr_ops, type,
BYTEORDER_HOST_ENDIAN, len);
expr->osf.ttl = ttl;
return expr;
}
|