All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Ludvig <mludvig@suse.cz>
To: netfilter-devel@lists.netfilter.org
Subject: NAT before IPsec with 2.6
Date: Wed, 21 Jan 2004 13:29:09 +0100	[thread overview]
Message-ID: <400E7095.9040709@suse.cz> (raw)

[-- Attachment #1: Type: text/plain, Size: 1069 bytes --]

Hi there,

with the native IPsec stack in 2.6.1 kernel it's impossible to do SNAT 
on outgoing packets that are leaving through an IPsec link. The problem 
is that the forwarded packets are encapsulated (with IPSec ESP/AH) yet 
before the POSTROUTING chain is reached.

So I hacked up this simple solution - I understand that it won't be 
accepted as-is, because now the POSTROUTING chain is reached twice (once 
from ip_forward and once from ip_output). But anyways - is this a 
correct approach and should I go this way with some cleanups?

Or is there another approach? I was thinking about extending the FORWARD 
chain and let it do SNAT/MASQUERADE. That would be cleaner, but more 
intrusive than my patch and would probably also require some changes in 
the userspace.

Comments, opinions, ...?

(Please Cc me on replies, thanks!)

Michal Ludvig
-- 
SUSE Labs                    mludvig@suse.cz | Cray is the only computer
(+420) 296.545.373        http://www.suse.cz | that runs an endless loop
Personal homepage http://www.logix.cz/michal | in just four hours.

[-- Attachment #2: kernel-nat-before-ipsec.diff --]
[-- Type: text/plain, Size: 1188 bytes --]

diff -rup linux-2.6.1.orig/net/ipv4/ip_forward.c linux-2.6.1.naga/net/ipv4/ip_forward.c
--- linux-2.6.1.orig/net/ipv4/ip_forward.c	2004-01-16 14:28:39.000000000 +0100
+++ linux-2.6.1.naga/net/ipv4/ip_forward.c	2004-01-20 16:11:09.904466001 +0100
@@ -46,12 +46,30 @@ static inline int ip_forward_finish(stru
 {
 	struct ip_options * opt	= &(IPCB(skb)->opt);
 
+	if (!xfrm4_route_forward(skb))
+		goto drop;
+
+#ifdef CONFIG_NETFILTER_DEBUG
+	skb->nf_debug &= ~(1 << NF_IP_POST_ROUTING);
+#endif
+
 	IP_INC_STATS_BH(IpForwDatagrams);
 
 	if (unlikely(opt->optlen))
 		ip_forward_options(skb);
 
 	return dst_output(skb);
+
+drop:
+	kfree_skb(skb);
+	return NET_RX_DROP;
+}
+
+static inline int ip_forward_postroute(struct sk_buff *skb)
+{
+	struct rtable *rt = (struct rtable*)skb->dst;
+
+	return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, skb->dev, rt->u.dst.dev, ip_forward_finish);
 }
 
 int ip_forward(struct sk_buff *skb)
@@ -109,7 +131,7 @@ int ip_forward(struct sk_buff *skb)
 	skb->priority = rt_tos2priority(iph->tos);
 
 	return NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, rt->u.dst.dev,
-		       ip_forward_finish);
+		       ip_forward_postroute);
 
 sr_failed:
         /*

             reply	other threads:[~2004-01-21 12:29 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-21 12:29 Michal Ludvig [this message]
2004-01-23  6:57 ` NAT before IPsec with 2.6 Willy Tarreau
2004-01-23 12:31 ` Henrik Nordstrom
2004-01-23 13:31   ` Michal Ludvig
2004-01-23 14:24     ` Henrik Nordstrom
2004-01-23 14:40       ` Michal Ludvig
2004-01-23 15:56         ` Henrik Nordstrom
2004-01-23 15:51       ` Tom Eastep
2004-01-24  8:22         ` Willy Tarreau
2004-01-24  9:21           ` Henrik Nordstrom
2004-01-24  9:27             ` Willy Tarreau
2004-01-27 10:39               ` Harald Welte
2004-01-27 11:57                 ` Henrik Nordstrom
2004-01-27 13:07                   ` Harald Welte
2004-01-27 13:22                     ` Henrik Nordstrom
2004-01-27 14:12                     ` Henrik Nordstrom
2004-01-27 20:51                       ` Harald Welte
2004-01-27 22:35                         ` Henrik Nordstrom
2004-01-28 13:48                           ` Harald Welte
2004-01-27 22:41                         ` Willy Tarreau
2004-01-27 23:55                     ` Harald Welte
2004-01-28  0:14                       ` Willy Tarreau
2004-01-28  0:09                     ` [PATCH]Re: " Harald Welte
2004-01-28  8:49                       ` Patrick McHardy
2004-01-28  9:37                         ` Patrick McHardy
2004-01-28 10:30                         ` Harald Welte
2004-01-28 11:24                           ` Willy Tarreau
2004-01-28 13:39                             ` Harald Welte
2004-01-28 15:58                             ` Tom Eastep
2004-01-28 13:22                           ` Patrick McHardy
2004-01-28 14:23                           ` Henrik Nordstrom
2004-02-01 14:52                           ` Patrick McHardy
2004-02-16  1:19                             ` Patrick McHardy
2004-02-18 14:57                               ` Patrick McHardy
     [not found]                                 ` <20040218220337.GA3193@alpha.home.local>
2004-02-20  1:43                                   ` Patrick McHardy
2004-03-04 22:30                                     ` [PATCH]: latest netfilter+ipsec patches Patrick McHardy
2004-03-04 23:11                                       ` Willy Tarreau
2004-03-04 23:42                                         ` Alexander Samad
2004-03-05  2:00                                           ` Patrick McHardy
2004-03-05  2:13                                             ` Alexander Samad
2004-03-10  2:45                                             ` Alexander Samad
2004-03-11 22:10                                               ` Patrick McHardy
2004-03-12  0:15                                                 ` Alexander Samad
2004-03-05  1:47                                         ` Patrick McHardy
2004-03-05 11:10                                           ` Willy Tarreau
2004-03-04 23:44                                       ` Patrick McHardy
2004-03-05 11:39                                       ` Harald Welte
2004-01-28 10:30                       ` [PATCH]Re: NAT before IPsec with 2.6 Andreas Jellinghaus
2004-01-29 19:05                         ` Harald Welte
2004-01-27 19:54                   ` Michael Richardson
2004-01-27 13:27                 ` Valentijn Sessink
2004-01-27 13:57                   ` Henrik Nordstrom
2004-01-27 21:13                   ` Andreas Jellinghaus
2004-01-28  8:58                     ` Harald Welte
2004-01-28 10:21                       ` Andreas Jellinghaus
2004-01-28 13:00                         ` Harald Welte
2004-01-28 13:43                           ` Andreas Jellinghaus
2004-01-28 14:24                       ` 2.6.2-rc2 and nf-log Wojciech 'Sas' Cieciwa
2004-01-28 19:38                       ` NAT before IPsec with 2.6 David S. Miller
2004-01-27 16:11                 ` Tom Eastep
2004-01-27 20:45                   ` Harald Welte
2004-01-28 15:36                     ` Tom Eastep
2004-01-27 19:51                 ` Michael Richardson

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=400E7095.9040709@suse.cz \
    --to=mludvig@suse.cz \
    --cc=netfilter-devel@lists.netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.