summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2025-08-21 11:17:17 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2025-08-28 00:09:48 +0200
commite3b58fe8fcd876ceccef60f7784bb90267f36085 (patch)
tree0482b21ea863f9139f90f3cd4fea394c21608609 /include
parentd36691a4ac486857fd437d3a9aa3701a073a9539 (diff)
tunnel: rework options
Only vxlan gbp can work before this patch because NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR is off by one in the internal object flags. Replace them by NFTNL_OBJ_TUNNEL_OPTS and add two new opaque nftnl_tunnel_opts and nftnl_tunnel_opt structs to represent tunnel options. - nftnl_tunnel_opt_alloc() allocates one tunnel option. - nftnl_tunnel_opt_set() to sets it up. - nftnl_tunnel_opt_get() to get the option attribute. Then, to manage the list of options: - nftnl_tunnel_opts_alloc() allocates a list of tunnel options. - nftnl_tunnel_opts_add() adds a option to the list. Although vxlan and erspan support for a single tunnel option at this stage, this API prepares for supporting gevene which allows for more tunnel options. Joint work with Fernando. Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include')
-rw-r--r--include/libnftnl/object.h51
-rw-r--r--include/obj.h16
2 files changed, 47 insertions, 20 deletions
diff --git a/include/libnftnl/object.h b/include/libnftnl/object.h
index 9930355..6d0aab0 100644
--- a/include/libnftnl/object.h
+++ b/include/libnftnl/object.h
@@ -112,14 +112,52 @@ enum {
NFTNL_OBJ_TUNNEL_FLAGS,
NFTNL_OBJ_TUNNEL_TOS,
NFTNL_OBJ_TUNNEL_TTL,
- NFTNL_OBJ_TUNNEL_VXLAN_GBP,
- NFTNL_OBJ_TUNNEL_ERSPAN_VERSION,
- NFTNL_OBJ_TUNNEL_ERSPAN_V1_INDEX,
- NFTNL_OBJ_TUNNEL_ERSPAN_V2_HWID,
- NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR,
+ NFTNL_OBJ_TUNNEL_OPTS,
__NFTNL_OBJ_TUNNEL_MAX,
};
+#define NFTNL_TUNNEL_TYPE 0
+#define NFTNL_TUNNEL_BASE 4
+
+enum nftnl_tunnel_type {
+ NFTNL_TUNNEL_TYPE_VXLAN,
+ NFTNL_TUNNEL_TYPE_ERSPAN,
+};
+
+enum {
+ NFTNL_TUNNEL_VXLAN_GBP = NFTNL_TUNNEL_BASE,
+ __NFTNL_TUNNEL_VXLAN_MAX,
+};
+
+enum {
+ NFTNL_TUNNEL_ERSPAN_VERSION = NFTNL_TUNNEL_BASE,
+ NFTNL_TUNNEL_ERSPAN_V1_INDEX,
+ NFTNL_TUNNEL_ERSPAN_V2_HWID,
+ NFTNL_TUNNEL_ERSPAN_V2_DIR,
+ __NFTNL_TUNNEL_ERSPAN_MAX,
+};
+
+struct nftnl_tunnel_opt;
+struct nftnl_tunnel_opts;
+
+struct nftnl_tunnel_opts *nftnl_tunnel_opts_alloc(enum nftnl_tunnel_type type);
+int nftnl_tunnel_opts_add(struct nftnl_tunnel_opts *opts,
+ struct nftnl_tunnel_opt *opt);
+void nftnl_tunnel_opts_free(struct nftnl_tunnel_opts *opts);
+
+struct nftnl_tunnel_opt *nftnl_tunnel_opt_alloc(enum nftnl_tunnel_type type);
+int nftnl_tunnel_opt_set(struct nftnl_tunnel_opt *opt, uint16_t type,
+ const void *data, uint32_t data_len);
+const void *nftnl_tunnel_opt_get(const struct nftnl_tunnel_opt *ne, uint16_t attr);
+const void *nftnl_tunnel_opt_get_data(const struct nftnl_tunnel_opt *ne,
+ uint16_t attr,
+ uint32_t *data_len);
+uint8_t nftnl_tunnel_opt_get_u8(const struct nftnl_tunnel_opt *ne, uint16_t attr);
+uint16_t nftnl_tunnel_opt_get_u16(const struct nftnl_tunnel_opt *ne, uint16_t attr);
+uint32_t nftnl_tunnel_opt_get_u32(const struct nftnl_tunnel_opt *ne, uint16_t attr);
+enum nftnl_tunnel_type nftnl_tunnel_opt_get_type(const struct nftnl_tunnel_opt *ne);
+uint32_t nftnl_tunnel_opt_get_flags(const struct nftnl_tunnel_opt *ne);
+
enum {
NFTNL_OBJ_SECMARK_CTX = NFTNL_OBJ_BASE,
__NFTNL_OBJ_SECMARK_MAX,
@@ -148,6 +186,9 @@ uint16_t nftnl_obj_get_u16(const struct nftnl_obj *obj, uint16_t attr);
uint32_t nftnl_obj_get_u32(const struct nftnl_obj *ne, uint16_t attr);
uint64_t nftnl_obj_get_u64(const struct nftnl_obj *obj, uint16_t attr);
const char *nftnl_obj_get_str(const struct nftnl_obj *ne, uint16_t attr);
+int nftnl_obj_tunnel_opts_foreach(const struct nftnl_obj *ne,
+ int (*cb)(struct nftnl_tunnel_opt *ne, void *data),
+ void *data);
void nftnl_obj_nlmsg_build_payload(struct nlmsghdr *nlh,
const struct nftnl_obj *ne);
diff --git a/include/obj.h b/include/obj.h
index d217737..5d3c4ec 100644
--- a/include/obj.h
+++ b/include/obj.h
@@ -78,21 +78,7 @@ struct nftnl_obj {
uint32_t tun_flags;
uint8_t tun_tos;
uint8_t tun_ttl;
- union {
- struct {
- uint32_t gbp;
- } tun_vxlan;
- struct {
- uint32_t version;
- union {
- uint32_t v1_index;
- struct {
- uint8_t hwid;
- uint8_t dir;
- } v2;
- } u;
- } tun_erspan;
- } u;
+ struct nftnl_tunnel_opts *tun_opts;
} tunnel;
struct nftnl_obj_secmark {
char ctx[NFT_SECMARK_CTX_MAXLEN];