Force socket error on iptables reject with icmp semantics?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Before I go bug the kernel people, I'd like to know if this seems
reasonable from a netfilter perspective.

>From e8b45cfd66ccc1be0bc406fc9662f0f1e7a94283 Mon Sep 17 00:00:00 2001
From: JP Abgrall <jpa@xxxxxxxxxx>
Date: Thu, 19 May 2011 19:30:02 -0700
Subject: [PATCH] netfilter: have ip*t REJECT set the sock err when an
icmp is to be sent

Allow the REJECT --reject-with icmp*blabla to also set the matching error
locally on the socket affected by the reject.
This allows the process to see an error as if it received it via ICMP.
It avoids the local process who's packet is rejected to have to wait
for a pseudo-eternity until some timeout kicks in.
---
 net/ipv4/netfilter/ipt_REJECT.c  |    6 ++++++
 net/ipv6/netfilter/ip6t_REJECT.c |    7 +++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/net/ipv4/netfilter/ipt_REJECT.c b/net/ipv4/netfilter/ipt_REJECT.c
index 43eec80..5b27d4b 100644
--- a/net/ipv4/netfilter/ipt_REJECT.c
+++ b/net/ipv4/netfilter/ipt_REJECT.c
@@ -134,6 +134,12 @@ static void send_reset(struct sk_buff *oldskb, int hook)
 static inline void send_unreach(struct sk_buff *skb_in, int code)
 {
        icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0);
+       if (skb_in->sk) {
+               skb_in->sk->sk_err = icmp_err_convert[code].errno;
+               skb_in->sk->sk_error_report(skb_in->sk);
+               pr_debug("ipt_REJECT: sk_err=%d for skb=%p sk=%p\n",
+                       skb_in->sk->sk_err, skb_in, skb_in->sk);
+       }
 }

 static unsigned int
diff --git a/net/ipv6/netfilter/ip6t_REJECT.c b/net/ipv6/netfilter/ip6t_REJECT.c
index 2933396..89a5512 100644
--- a/net/ipv6/netfilter/ip6t_REJECT.c
+++ b/net/ipv6/netfilter/ip6t_REJECT.c
@@ -174,6 +174,13 @@ send_unreach(struct net *net, struct sk_buff
*skb_in, unsigned char code,
                skb_in->dev = net->loopback_dev;

        icmpv6_send(skb_in, ICMPV6_DEST_UNREACH, code, 0);
+       if (skb_in->sk) {
+               icmpv6_err_convert(ICMP_DEST_UNREACH, code,
+                                  &skb_in->sk->sk_err);
+               skb_in->sk->sk_error_report(skb_in->sk);
+               pr_debug("ip6t_REJECT: sk_err=%d for skb=%p sk=%p\n",
+                       skb_in->sk->sk_err, skb_in, skb_in->sk);
+       }
 }

 static unsigned int
--
1.7.3.1
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux