summaryrefslogtreecommitdiffstats
path: root/src/osf.c
diff options
context:
space:
mode:
authorFernando Fernandez Mancera <ffmancera@riseup.net>2018-10-23 17:06:22 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-23 17:46:47 +0200
commit03eafe098d5eead786cbbe6f79348f05819cd99e (patch)
tree852498d1288759dafa8773c04fc24e3f54d4512a /src/osf.c
parentd7ef1e206bd9b36607dddcf337fada11d743b61f (diff)
osf: add ttl option support
Add support for ttl option in "osf" expression. Example: table ip foo { chain bar { type filter hook input priority filter; policy accept; osf ttl skip name "Linux" } } Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/osf.c')
-rw-r--r--src/osf.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/osf.c b/src/osf.c
index 85c95739..b98d1650 100644
--- a/src/osf.c
+++ b/src/osf.c
@@ -5,13 +5,31 @@
#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)
{
- nft_print(octx, "osf name");
+ 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 = {
@@ -19,10 +37,11 @@ static const struct expr_ops osf_expr_ops = {
.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)
+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;
@@ -30,6 +49,7 @@ struct expr *osf_expr_alloc(const struct location *loc)
expr = expr_alloc(loc, &osf_expr_ops, type,
BYTEORDER_HOST_ENDIAN, len);
+ expr->osf.ttl = ttl;
return expr;
}