add support for reject verdict in netdev
Subsystems (3)
cover add support for reject verdict in netdev
This patch series comprises changes in kernel space and user space to enable the reject verdict for the netdev family.
In addition, some code refactor has been made to the nft_reject infrastructure in kernel, adding two new functions to create the icmp or tcp reset skbuffs to avoid using ip_local_out. Also, reject init and dump functions has been unified into nft_reject.c
This follows previous work from Laura García.
nf-next
-------
Jose M. Guisado Gomez (3):
net: netfilter: add reject skbuff creation helpers
net: netfilter: unify reject init and dump into nft_reject
net: netfilter: add reject verdict support for netdev
include/net/netfilter/ipv4/nf_reject.h | 10 + include/net/netfilter/ipv6/nf_reject.h | 9 + net/bridge/netfilter/Kconfig | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 255 +---------------------- net/ipv4/netfilter/nf_reject_ipv4.c | 122 +++++++++++ net/ipv6/netfilter/nf_reject_ipv6.c | 134 ++++++++++++ net/netfilter/Kconfig | 10 + net/netfilter/Makefile | 1 + net/netfilter/nft_reject.c | 12 +- net/netfilter/nft_reject_inet.c | 60 +----- net/netfilter/nft_reject_netdev.c | 189 +++++++++++++++++ 11 files changed, 495 insertions(+), 309 deletions(-) create mode 100644 net/netfilter/nft_reject_netdev.c
nftables
--------
Jose M. Guisado Gomez (2):
evaluate: add netdev support for reject default
tests: py: add netdev folder and reject.t icmp cases
src/evaluate.c | 1 + tests/py/netdev/reject.t | 20 +++++++++++ tests/py/netdev/reject.t.payload | 60 ++++++++++++++++++++++++++++++++ tests/py/nft-test.py | 2 +- 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/py/netdev/reject.t create mode 100644 tests/py/netdev/reject.t.payload
Signature · 1 line
2.28.0
PATCH 1/5 net: netfilter: add reject skbuff creation helpers
Adds reject skbuff creation helper functions to ipv4/6 nf_reject infrastructure. Use these functions for reject verdict in bridge family.
Can be reused by all different families that support reject and will not inject the reject packet through ip local out.
--- include/net/netfilter/ipv4/nf_reject.h | 10 ++ include/net/netfilter/ipv6/nf_reject.h | 9 ++ net/bridge/netfilter/Kconfig | 2 +- net/bridge/netfilter/nft_reject_bridge.c | 195 +---------------------- net/ipv4/netfilter/nf_reject_ipv4.c | 122 ++++++++++++++ net/ipv6/netfilter/nf_reject_ipv6.c | 134 ++++++++++++++++ 6 files changed, 280 insertions(+), 192 deletions(-)
include/net/netfilter/ipv4/nf_reject.h +10 -0
@@ -18,4 +18,14 @@ struct iphdr *nf_reject_iphdr_put(struct sk_buff *nskb,void nf_reject_ip_tcphdr_put (struct sk_buff *nskb,const struct sk_buff *oldskb,const struct tcphdr *oth); +struct sk_buff *nf_reject_skb_v4_unreach (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook,u8 code); +struct sk_buff *nf_reject_skb_v4_tcp_reset (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook); + +#endif /* _IPV4_NF_REJECT_H */
include/net/netfilter/ipv6/nf_reject.h +9 -0
@@ -20,4 +20,13 @@ void nf_reject_ip6_tcphdr_put(struct sk_buff *nskb,const struct sk_buff *oldskb, const struct tcphdr *oth, unsigned int otcplen); +struct sk_buff *nf_reject_skb_v6_tcp_reset (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook); +struct sk_buff *nf_reject_skb_v6_unreach (struct net *net, +struct sk_buff *oldskb, +const struct net_device *dev, +int hook,u8 code); +#endif /* _IPV6_NF_REJECT_H */
net/bridge/netfilter/Kconfig +1 -1
@@ -17,7 +17,7 @@ config NFT_BRIDGE_META config NFT_BRIDGE_REJECT tristate "Netfilter nf_tables bridge reject support" - depends on NFT_REJECT && NFT_REJECT_IPV4 && NFT_REJECT_IPV6 + depends on NFT_REJECT help Add support to reject packets.
net/bridge/netfilter/nft_reject_bridge.c +4 -191
251 lines not on this page · raw message
net/ipv4/netfilter/nf_reject_ipv4.c +122 -0
128 lines not on this page · raw message
net/ipv6/netfilter/nf_reject_ipv6.c +134 -0
140 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 2/5 net: netfilter: unify reject init and dump into nft_reject
In reply to Jose M. Guisado GomezBridge family is using the same static init and dump function as inet.
This patch removes duplicate code unifying these functions body into nft_reject.c so they can be reused in the rest of families supporting reject verdict.
--- net/bridge/netfilter/nft_reject_bridge.c | 60 +----------------------- net/netfilter/nft_reject.c | 12 ++++- net/netfilter/nft_reject_inet.c | 60 +----------------------- 3 files changed, 15 insertions(+), 117 deletions(-)
net/bridge/netfilter/nft_reject_bridge.c +2 -58
@@ -177,69 +177,13 @@ static int nft_reject_bridge_validate(const struct nft_ctx *ctx, (1 << NF_BR_LOCAL_IN)); } -static int nft_reject_bridge_init (const struct nft_ctx *ctx, -const struct nft_expr *expr, -const struct nlattr *const tb[]) -{ -struct nft_reject *priv =nft_expr_priv (expr); -int icmp_code; - -if (tb[NFTA_REJECT_TYPE ] ==NULL ) -return -EINVAL ; - - priv->type =ntohl (nla_get_be32 (tb[NFTA_REJECT_TYPE ])); -switch (priv->type) { -case NFT_REJECT_ICMP_UNREACH : -case NFT_REJECT_ICMPX_UNREACH : -if (tb[NFTA_REJECT_ICMP_CODE ] ==NULL ) -return -EINVAL ; - - icmp_code =nla_get_u8 (tb[NFTA_REJECT_ICMP_CODE ]); -if (priv->type ==NFT_REJECT_ICMPX_UNREACH && - icmp_code >NFT_REJECT_ICMPX_MAX ) -return -EINVAL ; - - priv->icmp_code = icmp_code; -break ; -case NFT_REJECT_TCP_RST : -break ; -default : -return -EINVAL ; - } -return 0 ; -} - -static int nft_reject_bridge_dump (struct sk_buff *skb, -const struct nft_expr *expr) -{ -const struct nft_reject *priv =nft_expr_priv (expr); - -if (nla_put_be32 (skb,NFTA_REJECT_TYPE ,htonl (priv->type))) - goto nla_put_failure; - -switch (priv->type) { -case NFT_REJECT_ICMP_UNREACH : -case NFT_REJECT_ICMPX_UNREACH : -if (nla_put_u8 (skb,NFTA_REJECT_ICMP_CODE , priv->icmp_code)) - goto nla_put_failure; -break ; -default : -break ; - } - -return 0 ; - -nla_put_failure: -return -1 ; -} -static struct nft_expr_type nft_reject_bridge_type;static const struct nft_expr_ops nft_reject_bridge_ops = { .type = &nft_reject_bridge_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_reject )), .eval = nft_reject_bridge_eval, - .init = nft_reject_bridge_init, - .dump = nft_reject_bridge_dump, + .init = nft_reject_init, + .dump = nft_reject_dump, .validate = nft_reject_bridge_validate, };
net/netfilter/nft_reject.c +11 -1
@@ -40,6 +40,7 @@ int nft_reject_init(const struct nft_ctx *ctx, const struct nlattr * const tb[]) {struct nft_reject *priv =nft_expr_priv (expr); +int icmp_code;if (tb[NFTA_REJECT_TYPE ] ==NULL )return -EINVAL ;
@@ -47,9 +48,17 @@ int nft_reject_init(const struct nft_ctx *ctx, priv->type =ntohl (nla_get_be32 (tb[NFTA_REJECT_TYPE ]));switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : +case NFT_REJECT_ICMPX_UNREACH :if (tb[NFTA_REJECT_ICMP_CODE ] ==NULL )return -EINVAL ; - priv->icmp_code =nla_get_u8 (tb[NFTA_REJECT_ICMP_CODE ]); + + icmp_code =nla_get_u8 (tb[NFTA_REJECT_ICMP_CODE ]); +if (priv->type ==NFT_REJECT_ICMPX_UNREACH && + icmp_code >NFT_REJECT_ICMPX_MAX ) +return -EINVAL ; + + priv->icmp_code = icmp_code; +break ;case NFT_REJECT_TCP_RST :break ;default :
@@ -69,6 +78,7 @@ int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)switch (priv->type) {case NFT_REJECT_ICMP_UNREACH : +case NFT_REJECT_ICMPX_UNREACH :if (nla_put_u8 (skb,NFTA_REJECT_ICMP_CODE , priv->icmp_code)) goto nla_put_failure;break ;
net/netfilter/nft_reject_inet.c +2 -58
71 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 3/5 net: netfilter: add reject verdict support for netdev
In reply to Jose M. Guisado GomezAdds support for reject from ingress hook in netdev family. Both stacks ipv4 and ipv6. With reject packets supporting ICMP and TCP RST.
This ability is required in devices that need to REJECT legitimate clients which traffic is forwarded from the ingress hook.
Joint work with Laura Garcia.
--- net/netfilter/Kconfig | 10 ++ net/netfilter/Makefile | 1 + net/netfilter/nft_reject_netdev.c | 189 ++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 net/netfilter/nft_reject_netdev.c
net/netfilter/Kconfig +10 -0
@@ -681,6 +681,16 @@ config NFT_FIB_NETDEV The lookup will be delegated to the IPv4 or IPv6 FIB depending on the protocol of the packet. +config NFT_REJECT_NETDEV + depends on NFT_REJECT_IPV4 + depends on NFT_REJECT_IPV6 + tristate "Netfilter nf_tables netdev REJECT support" + help + This option enables the REJECT support from the netdev table. + The return packet generation will be delegated to the IPv4 + or IPv6 ICMP or TCP RST implementation depending on the + protocol of the packet. + endif # NF_TABLES_NETDEV endif # NF_TABLES
net/netfilter/Makefile +1 -0
@@ -101,6 +101,7 @@ obj-$(CONFIG_NFT_QUEUE) += nft_queue.o obj-$(CONFIG_NFT_QUOTA) += nft_quota.o obj-$(CONFIG_NFT_REJECT) += nft_reject.o obj-$(CONFIG_NFT_REJECT_INET) += nft_reject_inet.o +obj-$(CONFIG_NFT_REJECT_NETDEV) += nft_reject_netdev.o obj-$(CONFIG_NFT_TUNNEL) += nft_tunnel.o obj-$(CONFIG_NFT_COUNTER) += nft_counter.o obj-$(CONFIG_NFT_LOG) += nft_log.o
net/netfilter/nft_reject_netdev.c new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.28.0
PATCH 4/5 evaluate: add netdev support for reject default
In reply to Jose M. Guisado GomezEnables not specifying any icmp type and code when using reject inside netdev.
This patch completely enables using reject for the netdev family.
--- src/evaluate.c | 1 + 1 file changed, 1 insertion(+)
src/evaluate.c +1 -0
@@ -2745,6 +2745,7 @@ static int stmt_evaluate_reject_default(struct eval_ctx *ctx, }break ;case NFPROTO_BRIDGE : +case NFPROTO_NETDEV : desc = ctx->pctx.protocol[PROTO_BASE_NETWORK_HDR ].desc;if (desc ==NULL ) { stmt->reject.type =NFT_REJECT_ICMPX_UNREACH ;
Signature · 1 line
2.28.0
Re: [PATCH nftables 4/5] evaluate: add netdev support for reject default
Quoted 4 lines · Jose M. Guisado Gomez
Enables not specifying any icmp type and code when using reject inside netdev.
This patch completely enables using reject for the netdev family.
Applied, thanks.
PATCH 5/5 tests: py: add netdev folder and reject.t icmp cases
In reply to Jose M. Guisado GomezAdd unit tests for the use of reject with icmp inside netdev family.
reject.t from inet family couldn't be reused because it was using meta nfproto which is not supported inside netdev.
--- tests/py/netdev/reject.t | 20 +++++++++++ tests/py/netdev/reject.t.payload | 60 ++++++++++++++++++++++++++++++++ tests/py/nft-test.py | 2 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/py/netdev/reject.t create mode 100644 tests/py/netdev/reject.t.payload
tests/py/netdev/reject.t new file +20 -0
@@ -0,0 +1,20 @@ +:ingress;type filter hook ingress device lo priority 0 + +*netdev;test-netdev;ingress + +reject with icmp type host-unreachable;ok;reject +reject with icmp type net-unreachable;ok;reject +reject with icmp type prot-unreachable;ok;reject +reject with icmp type port-unreachable;ok;reject +reject with icmp type net-prohibited;ok;reject +reject with icmp type host-prohibited;ok;reject +reject with icmp type admin-prohibited;ok;reject + +reject with icmpv6 type no-route;ok;reject +reject with icmpv6 type admin-prohibited;ok;reject +reject with icmpv6 type addr-unreachable;ok;reject +reject with icmpv6 type port-unreachable;ok;reject +reject with icmpv6 type policy-fail;ok;reject +reject with icmpv6 type reject-route;ok;reject + +reject;ok
tests/py/netdev/reject.t.payload new file +60 -0
60 lines not on this page · raw message
tests/py/nft-test.py +1 -1
@@ -28,7 +28,7 @@ os.environ['TZ'] = 'UTC-2' from nftables import Nftables -TESTS_DIRECTORY = ["any", "arp", "bridge", "inet", "ip", "ip6"] +TESTS_DIRECTORY = ["any", "arp", "bridge", "inet", "ip", "ip6", "netdev"] LOGFILE = "/tmp/nftables-test.log" log_file = None table_list = []
Signature · 1 line
2.28.0
Pablo Neira Ayuso
maintainerRe: [PATCH nftables 5/5] tests: py: add netdev folder and reject.t icmp cases
Quoted 4 lines · Jose M. Guisado Gomez
Add unit tests for the use of reject with icmp inside netdev family.
reject.t from inet family couldn't be reused because it was using meta nfproto which is not supported inside netdev.
Also applied, thanks.
Quoted 10 lines · Jose M. Guisado Gomez
This patch series comprises changes in kernel space and user space to enable the reject verdict for the netdev family.
In addition, some code refactor has been made to the
nft_rejectinfrastructure in kernel, adding two new functions to create the icmp or tcp reset skbuffs to avoid usingip_local_out. Also, reject init and dump functions has been unified intonft_reject.cThis follows previous work from Laura García.
Quoted 7 lines
nf-next
-------Jose M. Guisado Gomez (3):
net: netfilter: add reject skbuff creation helpers
net: netfilter: unify reject init and dump intonft_reject
net: netfilter: add reject verdict support for netdev
Applied these three patches to nf-next, thanks.