From 1a3c075be1cf57dc248f38a974a8a01457e6b6e2 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 11 Nov 2015 01:54:01 +0100 Subject: src: add trace infrastructure support parses trace monitor netlink messages from the kernel and builds nftnl_trace struct that contains the dissected information. Provides getters to access these attributes. Signed-off-by: Florian Westphal --- include/libnftnl/Makefile.am | 1 + include/libnftnl/trace.h | 55 +++++++++++++++++++++++++++++++++++++ include/linux/netfilter/nf_tables.h | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 include/libnftnl/trace.h (limited to 'include') diff --git a/include/libnftnl/Makefile.am b/include/libnftnl/Makefile.am index a20aaee..84f01b6 100644 --- a/include/libnftnl/Makefile.am +++ b/include/libnftnl/Makefile.am @@ -1,5 +1,6 @@ pkginclude_HEADERS = batch.h \ table.h \ + trace.h \ chain.h \ rule.h \ expr.h \ diff --git a/include/libnftnl/trace.h b/include/libnftnl/trace.h new file mode 100644 index 0000000..674bc16 --- /dev/null +++ b/include/libnftnl/trace.h @@ -0,0 +1,55 @@ +#ifndef _LIBNFTNL_TRACE_H_ +#define _LIBNFTNL_TRACE_H_ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum nftnl_trace_attr { + NFTNL_TRACE_CHAIN = 0, + NFTNL_TRACE_FAMILY, + NFTNL_TRACE_ID, + NFTNL_TRACE_IIF, + NFTNL_TRACE_IIFTYPE, + NFTNL_TRACE_JUMP_TARGET, + NFTNL_TRACE_OIF, + NFTNL_TRACE_OIFTYPE, + NFTNL_TRACE_MARK, + NFTNL_TRACE_LL_HEADER, + NFTNL_TRACE_NETWORK_HEADER, + NFTNL_TRACE_TRANSPORT_HEADER, + NFTNL_TRACE_TABLE, + NFTNL_TRACE_TYPE, + NFTNL_TRACE_RULE_HANDLE, + NFTNL_TRACE_VERDICT, + NFTNL_TRACE_NFPROTO, + NFTNL_TRACE_POLICY, + __NFTNL_TRACE_MAX, +}; +#define NFTNL_TRACE_MAX (__NFTNL_TRACE_MAX - 1) + +struct nftnl_trace; + +struct nftnl_trace *nftnl_trace_alloc(void); +void nftnl_trace_free(struct nftnl_trace *trace); + +bool nftnl_trace_is_set(const struct nftnl_trace *trace, uint16_t type); + +const void *nftnl_trace_get_data(const struct nftnl_trace *trace, + uint16_t type, uint32_t *data_len); + +uint16_t nftnl_trace_get_u16(const struct nftnl_trace *trace, uint16_t type); +uint32_t nftnl_trace_get_u32(const struct nftnl_trace *trace, uint16_t type); +uint64_t nftnl_trace_get_u64(const struct nftnl_trace *trace, uint16_t type); +const char *nftnl_trace_get_str(const struct nftnl_trace *trace, uint16_t type); + +int nftnl_trace_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_trace *t); +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* _LIBNFTNL_TRACE_H_ */ diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h index 5420c8c..f77693b 100644 --- a/include/linux/netfilter/nf_tables.h +++ b/include/linux/netfilter/nf_tables.h @@ -83,6 +83,7 @@ enum nft_verdicts { * @NFT_MSG_DELSETELEM: delete a set element (enum nft_set_elem_attributes) * @NFT_MSG_NEWGEN: announce a new generation, only for events (enum nft_gen_attributes) * @NFT_MSG_GETGEN: get the rule-set generation (enum nft_gen_attributes) + * @NFT_MSG_TRACE: trace event (enum nft_trace_attributes) */ enum nf_tables_msg_types { NFT_MSG_NEWTABLE, @@ -102,6 +103,7 @@ enum nf_tables_msg_types { NFT_MSG_DELSETELEM, NFT_MSG_NEWGEN, NFT_MSG_GETGEN, + NFT_MSG_TRACE, NFT_MSG_MAX, }; @@ -987,4 +989,54 @@ enum nft_gen_attributes { }; #define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1) +/** + * enum nft_trace_attributes - nf_tables trace netlink attributes + * + * @NFTA_TRACE_TABLE: name of the table (NLA_STRING) + * @NFTA_TRACE_CHAIN: name of the chain (NLA_STRING) + * @NFTA_TRACE_RULE_HANDLE: numeric handle of the rule (NLA_U64) + * @NFTA_TRACE_TYPE: type of the event (NLA_U32: nft_trace_types) + * @NFTA_TRACE_VERDICT: verdict returned by hook (NLA_NESTED: nft_verdicts) + * @NFTA_TRACE_ID: pseudo-id, same for each skb traced (NLA_U32) + * @NFTA_TRACE_LL_HEADER: linklayer header (NLA_BINARY) + * @NFTA_TRACE_NETWORK_HEADER: network header (NLA_BINARY) + * @NFTA_TRACE_TRANSPORT_HEADER: transport header (NLA_BINARY) + * @NFTA_TRACE_IIF: indev ifindex (NLA_U32) + * @NFTA_TRACE_IIFTYPE: netdev->type of indev (NLA_U16) + * @NFTA_TRACE_OIF: outdev ifindex (NLA_U32) + * @NFTA_TRACE_OIFTYPE: netdev->type of outdev (NLA_U16) + * @NFTA_TRACE_MARK: nfmark (NLA_U32) + * @NFTA_TRACE_NFPROTO: nf protocol processed (NLA_U32) + * @NFTA_TRACE_POLICY: policy that decided fate of packet (NLA_U32) + */ +enum nft_trace_attibutes { + NFTA_TRACE_UNSPEC, + NFTA_TRACE_TABLE, + NFTA_TRACE_CHAIN, + NFTA_TRACE_RULE_HANDLE, + NFTA_TRACE_TYPE, + NFTA_TRACE_VERDICT, + NFTA_TRACE_ID, + NFTA_TRACE_LL_HEADER, + NFTA_TRACE_NETWORK_HEADER, + NFTA_TRACE_TRANSPORT_HEADER, + NFTA_TRACE_IIF, + NFTA_TRACE_IIFTYPE, + NFTA_TRACE_OIF, + NFTA_TRACE_OIFTYPE, + NFTA_TRACE_MARK, + NFTA_TRACE_NFPROTO, + NFTA_TRACE_POLICY, + __NFTA_TRACE_MAX +}; +#define NFTA_TRACE_MAX (__NFTA_TRACE_MAX - 1) + +enum nft_trace_types { + NFT_TRACETYPE_UNSPEC, + NFT_TRACETYPE_POLICY, + NFT_TRACETYPE_RETURN, + NFT_TRACETYPE_RULE, + __NFT_TRACETYPE_MAX +}; +#define NFT_TRACETYPE_MAX (__NFT_TRACETYPE_MAX - 1) #endif /* _LINUX_NF_TABLES_H */ -- cgit v1.2.3