mnl: revisit hook listing
Pablo Neira Ayuso
maintainerPATCH v3 1/1 mnl: revisit hook listing
Update this command to display the hook datapath for a packet depending on its family. This includes:
- Group existing hooks based on the hook location.
- Order hooks by priority, from INT_MIN to INT_MAX.
- Do not add sign to priority zero.
- Refresh include/linux/netfilter/nfnetlink_hook.h cache copy.
- Use NFNLA_CHAIN_* attributes to print the chain family, table and name. If NFNLA_CHAIN_* attributes are not available, display the hookfn name.
- Update syntax: remove optional hook parameter, promote the 'device' argument.
The following example shows the hook datapath for IPv4 packets coming in from netdevice 'eth0':
# nft list hooks ip device eth0
family ip {
hook ingress {
+0000000010 chain netdev x y [nf_tables]
+0000000300 chain inet m w [nf_tables]
}
hook input {
-0000000100 chain ip a b [nf_tables]
+0000000300 chain inet m z [nf_tables]
}
hook forward {
-0000000225 selinux_ipv4_forward
0000000000 chain ip a c [nf_tables]
}
hook output {
-0000000225 selinux_ipv4_output
}
hook postrouting {
+0000000225 selinux_ipv4_postroute
}
}Note that the listing above includes the existing netdev and inet hooks/chains which might interfer in the travel of an incoming IPv4 packet.
This allows users to debug the pipeline, basically, to understand in what order the hooks/chains are evaluated for the IPv4 packets.
If the netdevice is not specified, then the ingress hook is not shown.
--- include/linux/netfilter/nfnetlink_hook.h | 14 +- include/rule.h | 1 + src/mnl.c | 342 ++++++++++++++++------- src/parser_bison.y | 25 +- src/rule.c | 2 + 5 files changed, 264 insertions(+), 120 deletions(-)
include/linux/netfilter/nfnetlink_hook.h +12 -2
@@ -8,10 +8,10 @@ enum nfnl_hook_msg_types { };/** -* enum nfnl_hook_attributes - nf_tables netfilter hook netlink attributes +* enum nfnl_hook_attributes - netfilter hook netlink attributes * * @NFNLA_HOOK_HOOKNUM: netfilter hook number (NLA_U32) -* @NFNLAA_HOOK_PRIORITY: netfilter hook priority (NLA_U32) +* @NFNLA_HOOK_PRIORITY: netfilter hook priority (NLA_U32) * @NFNLA_HOOK_DEV: netdevice name (NLA_STRING) * @NFNLA_HOOK_FUNCTION_NAME: hook function name (NLA_STRING) * @NFNLA_HOOK_MODULE_NAME: kernel module that registered this hook (NLA_STRING)
@@ -43,6 +43,15 @@ enum nfnl_hook_chain_info_attributes { };#define NFNLA_HOOK_INFO_MAX (__NFNLA_HOOK_INFO_MAX - 1) +enum nfnl_hook_chain_desc_attributes { +NFNLA_CHAIN_UNSPEC , +NFNLA_CHAIN_TABLE , +NFNLA_CHAIN_FAMILY , +NFNLA_CHAIN_NAME , + __NFNLA_CHAIN_MAX, +}; +#define NFNLA_CHAIN_MAX (__NFNLA_CHAIN_MAX - 1) +/** * enum nfnl_hook_chaintype - chain type *
@@ -51,4 +60,5 @@ enum nfnl_hook_chain_info_attributes {enum nfnl_hook_chaintype {NFNL_HOOK_TYPE_NFTABLES =0x1 , }; +#endif /* _NFNL_HOOK_H */
include/rule.h +1 -0
@@ -270,6 +270,7 @@ extern struct chain *chain_binding_lookup(const struct table *table, const char *chain_name);extern const char *family2str (unsigned int family); +#define __NF_ARP_INGRESS 255extern const char *hooknum2str (unsigned int family,unsigned int hooknum);extern const char *chain_policy2str (uint32_t policy); extern void chain_print_plain(const struct chain *chain,
src/mnl.c +244 -98
448 lines not on this page · raw message
src/parser_bison.y +5 -20
@@ -1474,11 +1474,7 @@ list_cmd : TABLE table_spec } ; -basehook_device_name : /* NULL */ - { - $$ = NULL; - } - | DEVICE STRING +basehook_device_name : DEVICE STRING { $$ = $2; }
@@ -1488,22 +1484,11 @@ basehook_spec : ruleset_spec { $$ = $1; } - | ruleset_spec STRING basehook_device_name + | ruleset_spec basehook_device_name { - const char *name = chain_hookname_lookup($2); - - if (name == NULL) { - erec_queue(error(&@2, "unknown chain hook"), - state->msgs); - xfree($3); - YYERROR; - } - - $1.chain.name = $2; - $1.chain.location = @2; - if ($3) { - $1.obj.name = $3; - $1.obj.location = @3; + if ($2) { + $1.obj.name = $2; + $1.obj.location = @2; } $$ = $1; }
src/rule.c +2 -0
@@ -822,6 +822,8 @@ const char *hooknum2str(unsigned int family, unsigned int hooknum)return "forward" ;case NF_ARP_OUT :return "output" ; +case __NF_ARP_INGRESS: +return "ingress" ;default :break ; }
Signature · 1 line
2.20.1