History

netfilter: nf_tables: extend tracing infrastructure

nft monitor mode can then decode and display this trace data. Parts of LL/Network/Transport headers are provided as separate attributes. Otherwise, printing IP address data becomes virtually impossible for userspace since in the case of the netdev family we really don't want userspace to have to know all the possible link layer types and/or sizes just to display/print an ip address. We also don't want userspace to have to follow ipv6 header chains to get the s/dport info, the kernel already did this work for us. To avoid bloating nft_do_chain all data required for tracing is encapsulated in nft_traceinfo. The structure is initialized unconditionally(!) for each nft_do_chain invocation. This unconditionall call will be moved under a static key in a followup patch. With lots of help from Patrick McHardy and Pablo Neira.

Florian Westphal committed 10 years ago

Commit 33d5a7b1 parent 7ec3f7b8 files · +398 −19Browse files

Showing the changes to include/uapi (2 of 8 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/netfilter/nf_tables.h +52 −0
  2. include/uapi/linux/netfilter/nfnetlink.h +2 −0
include/uapi/linux/netfilter/nf_tables.h+52−0
@@ -83,6 +83,7 @@ enum nft_verdicts { · 82 unmodified lines
8383 * @NFT_MSG_DELSETELEM: delete a set element (enum nft_set_elem_attributes)
8484 * @NFT_MSG_NEWGEN: announce a new generation, only for events (enum nft_gen_attributes)
8585 * @NFT_MSG_GETGEN: get the rule-set generation (enum nft_gen_attributes)
86+ * @NFT_MSG_TRACE: trace event (enum nft_trace_attributes)
8687 */
8788 enum nf_tables_msg_types {
8889 NFT_MSG_NEWTABLE,
@@ -102,6 +103,7 @@ enum nf_tables_msg_types { · 13 unmodified lines
102103 NFT_MSG_DELSETELEM,
103104 NFT_MSG_NEWGEN,
104105 NFT_MSG_GETGEN,
106+ NFT_MSG_TRACE,
105107 NFT_MSG_MAX,
106108 };
107109
@@ -987,4 +989,54 @@ enum nft_gen_attributes { · 879 unmodified lines
987989 };
988990 #define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1)
989991
992+/**
993+ * enum nft_trace_attributes - nf_tables trace netlink attributes
994+ *
995+ * @NFTA_TRACE_TABLE: name of the table (NLA_STRING)
996+ * @NFTA_TRACE_CHAIN: name of the chain (NLA_STRING)
997+ * @NFTA_TRACE_RULE_HANDLE: numeric handle of the rule (NLA_U64)
998+ * @NFTA_TRACE_TYPE: type of the event (NLA_U32: nft_trace_types)
999+ * @NFTA_TRACE_VERDICT: verdict returned by hook (NLA_NESTED: nft_verdicts)
1000+ * @NFTA_TRACE_ID: pseudo-id, same for each skb traced (NLA_U32)
1001+ * @NFTA_TRACE_LL_HEADER: linklayer header (NLA_BINARY)
1002+ * @NFTA_TRACE_NETWORK_HEADER: network header (NLA_BINARY)
1003+ * @NFTA_TRACE_TRANSPORT_HEADER: transport header (NLA_BINARY)
1004+ * @NFTA_TRACE_IIF: indev ifindex (NLA_U32)
1005+ * @NFTA_TRACE_IIFTYPE: netdev->type of indev (NLA_U16)
1006+ * @NFTA_TRACE_OIF: outdev ifindex (NLA_U32)
1007+ * @NFTA_TRACE_OIFTYPE: netdev->type of outdev (NLA_U16)
1008+ * @NFTA_TRACE_MARK: nfmark (NLA_U32)
1009+ * @NFTA_TRACE_NFPROTO: nf protocol processed (NLA_U32)
1010+ * @NFTA_TRACE_POLICY: policy that decided fate of packet (NLA_U32)
1011+ */
1012+enum nft_trace_attibutes {
1013+ NFTA_TRACE_UNSPEC,
1014+ NFTA_TRACE_TABLE,
1015+ NFTA_TRACE_CHAIN,
1016+ NFTA_TRACE_RULE_HANDLE,
1017+ NFTA_TRACE_TYPE,
1018+ NFTA_TRACE_VERDICT,
1019+ NFTA_TRACE_ID,
1020+ NFTA_TRACE_LL_HEADER,
1021+ NFTA_TRACE_NETWORK_HEADER,
1022+ NFTA_TRACE_TRANSPORT_HEADER,
1023+ NFTA_TRACE_IIF,
1024+ NFTA_TRACE_IIFTYPE,
1025+ NFTA_TRACE_OIF,
1026+ NFTA_TRACE_OIFTYPE,
1027+ NFTA_TRACE_MARK,
1028+ NFTA_TRACE_NFPROTO,
1029+ NFTA_TRACE_POLICY,
1030+ __NFTA_TRACE_MAX
1031+};
1032+#define NFTA_TRACE_MAX (__NFTA_TRACE_MAX - 1)
1033+
1034+enum nft_trace_types {
1035+ NFT_TRACETYPE_UNSPEC,
1036+ NFT_TRACETYPE_POLICY,
1037+ NFT_TRACETYPE_RETURN,
1038+ NFT_TRACETYPE_RULE,
1039+ __NFT_TRACETYPE_MAX
1040+};
1041+#define NFT_TRACETYPE_MAX (__NFT_TRACETYPE_MAX - 1)
9901042 #endif /* _LINUX_NF_TABLES_H */
include/uapi/linux/netfilter/nfnetlink.h+2−0
@@ -22,6 +22,8 @@ enum nfnetlink_groups { · 21 unmodified lines
2222 #define NFNLGRP_NFTABLES NFNLGRP_NFTABLES
2323 NFNLGRP_ACCT_QUOTA,
2424 #define NFNLGRP_ACCT_QUOTA NFNLGRP_ACCT_QUOTA
25+ NFNLGRP_NFTRACE,
26+#define NFNLGRP_NFTRACE NFNLGRP_NFTRACE
2527 __NFNLGRP_MAX,
2628 };
2729 #define NFNLGRP_MAX (__NFNLGRP_MAX - 1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t