netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: JP Abgrall <jpa@google.com>
To: netfilter-devel@vger.kernel.org
Subject: Force socket error on iptables reject with icmp semantics?
Date: Mon, 23 May 2011 16:16:33 -0700	[thread overview]
Message-ID: <BANLkTi=APDmR7c8eqVySKofXx_wMtgPGOw@mail.gmail.com> (raw)

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@google.com>
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

             reply	other threads:[~2011-05-23 23:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 23:16 JP Abgrall [this message]
2011-05-24  7:01 ` Force socket error on iptables reject with icmp semantics? Patrick McHardy
2011-05-25  1:57   ` JP Abgrall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=APDmR7c8eqVySKofXx_wMtgPGOw@mail.gmail.com' \
    --to=jpa@google.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).