Skip to contentSkip to conversation

netfilter: nft: add support of reject verdict from ingress

PATCH In review Laura Garcia Liebana 2 participants 3 messages Jun 8, 2020 – Jun 12, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 netfilter: nft: add support of reject verdict from ingress

This patch adds the REJECT support from ingress for both stacks ipv4 and ipv6, but also, both types ICMP and TCP RESET.

This ability is required in devices that need to REJECT legitimate clients which traffic are forwarded from the ingress hook.

---
 net/netfilter/Kconfig             | 10 +++++
 net/netfilter/Makefile            |  1 +
 net/netfilter/nft_reject_netdev.c | 65 +++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)
 create mode 100644 net/netfilter/nft_reject_netdev.c
net/netfilter/Kconfig +10 -0
index 468fea1aebba..25200f249778 100644
@@ -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
index 0e0ded87e27b..33da7bf1b68e 100644
@@ -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 +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw

Hi Laura,

Quoted 5 lines · Laura Garcia Liebana
net/netfilter/nft_reject_netdev.c new file +0 -0
new file mode 100644
index 000000000000..64123d80210d

[...]

net/netfilter/nft_reject_netdev.c line 28

Quoted 12 lines
net/netfilter/nft_reject_netdev.c new file +12 -0
+static void nft_reject_netdev_eval(const struct nft_expr *expr,
+				   struct nft_regs *regs,
+				   const struct nft_pktinfo *pkt)
+{
+	switch (ntohs(pkt->skb->protocol)) {
+	case ETH_P_IP:
+		nft_reject_ipv4_eval(expr, regs, pkt);
+		break;
+	case ETH_P_IPV6:
+		nft_reject_ipv6_eval(expr, regs, pkt);
+		break;
+	}

We should reuse nft_reject_br_send_v4_tcp_reset() and nft_reject_br_send_v4_unreach() and call dev_queue_xmit() to send the reject packet.

No need to inject this from LOCAL_OUT, given this packet is being rejects from the ingress path.

The reject action for netdev is more similar to the one that bridge supports than what we have for inet actually.

You can probably move the bridge functions to net/netfilter/nf_reject.c so this code can be shared between bridge reject and netdev.

I like your code refactoring in patch 1 though.

#2 lore raw

Hi Pablo,

Quoted 30 lines · Pablo Neira Ayuso

Hi Laura,

Quoted 5 lines · Laura Garcia Liebana
net/netfilter/nft_reject_netdev.c new file +0 -0
new file mode 100644
index 000000000000..64123d80210d

[...]

net/netfilter/nft_reject_netdev.c line 28

Quoted 12 lines
net/netfilter/nft_reject_netdev.c new file +12 -0
+static void nft_reject_netdev_eval(const struct nft_expr *expr,
+                                struct nft_regs *regs,
+                                const struct nft_pktinfo *pkt)
+{
+     switch (ntohs(pkt->skb->protocol)) {
+     case ETH_P_IP:
+             nft_reject_ipv4_eval(expr, regs, pkt);
+             break;
+     case ETH_P_IPV6:
+             nft_reject_ipv6_eval(expr, regs, pkt);
+             break;
+     }

We should reuse nft_reject_br_send_v4_tcp_reset() and nft_reject_br_send_v4_unreach() and call dev_queue_xmit() to send the reject packet.

No need to inject this from LOCAL_OUT, given this packet is being rejects from the ingress path.

Quoted 7 lines

The reject action for netdev is more similar to the one that bridge supports than what we have for inet actually.

You can probably move the bridge functions to net/netfilter/nf_reject.c so this code can be shared between bridge reject and netdev.

Thank you for your review, I'll apply the changes.

Quoted 1 line

I like your code refactoring in patch 1 though.