All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
Cc: Harald Welte <laforge@netfilter.org>,
	Henrik Nordstrom <hno@marasystems.com>,
	Willy Tarreau <willy@w.ods.org>,
	Tom Eastep <teastep@shorewall.net>,
	Michal Ludvig <mludvig@suse.cz>,
	netfilter-devel@lists.netfilter.org
Subject: Re: [PATCH]Re: NAT before IPsec with 2.6
Date: Wed, 18 Feb 2004 15:57:39 +0100	[thread overview]
Message-ID: <40337D63.6080602@trash.net> (raw)
In-Reply-To: <40301AB2.2030103@trash.net>

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

Here is another patch on top of the last ones, it makes
incoming packets from transport mode SAs visible to
netfilter hooks and emulates normal behaviour. With this
patch you can share a transport-mode SA between an entire
network using MASQUERADE, but also do weird stuff like
DNAT packets coming from a transport mode SA to remote
hosts ;)

The patch is not exactly nice, but with it, everything should
be working fine except for nested tunnels. I would really
appreciate if I can get some comments for this part and the
other ones so I can prepare some final patches to discuss
with davem.

Regards
Patrick

Patrick McHardy wrote:

> There are 4 patches:
> 
> 01-nf_reset.diff
>     Move common nf_conntrack_put/nfct=NULL/nf_debug=0 code to
>     new inline function nf_reset.
> 
> 02-hooks.diff
>     Make packets to be encrypted visible on POST_ROUTING hook
>     and encrypted packets on LOCAL_OUT. Reset nfct etc. before
>     reposting the packet into the stack on reception.
> 
> 03-nat-policy-lookup.diff
>     Add policy lookups to ip_route_me_harder and change NAT to
>     reroute for any change that affects routing or policy lookups
> 
> 04-nat-policy-checks.diff
>     Make xfrm_policy_check find correct policy for NATed packets

[-- Attachment #2: 05-transport-mode-hooks.diff --]
[-- Type: text/plain, Size: 2092 bytes --]

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/02/18 15:42:49+01:00 kaber@trash.net 
#   Emulate netfilter hooks for transport mode packets
# 
# net/ipv4/xfrm4_input.c
#   2004/02/18 15:42:42+01:00 kaber@trash.net +46 -1
#   Emulate netfilter hooks for transport mode packets
# 
diff -Nru a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c
--- a/net/ipv4/xfrm4_input.c	Wed Feb 18 15:45:17 2004
+++ b/net/ipv4/xfrm4_input.c	Wed Feb 18 15:45:17 2004
@@ -9,10 +9,53 @@
  * 	
  */
 
+#include <linux/config.h>
+#include <linux/skbuff.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter_ipv4.h>
 #include <net/inet_ecn.h>
 #include <net/ip.h>
 #include <net/xfrm.h>
 
+#ifdef CONFIG_NETFILTER
+static inline int emulate_nf_done(struct sk_buff *skb)
+{
+	return 0;
+}
+
+static inline int emulate_nf_hooks2(struct sk_buff *skb)
+{
+	if (inet_addr_type(skb->nh.iph->daddr) != RTN_LOCAL) {
+		if (ip_route_me_harder(&skb) == 0)
+			dst_input(skb);
+		else
+			kfree_skb(skb);
+		return -1;
+	}
+		
+	return NF_HOOK(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
+	               emulate_nf_done);
+}
+
+static inline int emulate_nf_hooks(struct sk_buff *skb)
+{
+	int off = skb->data - skb->nh.raw;
+		
+	skb_push(skb, off);
+	skb->nh.iph->tot_len = htons(skb->len);
+	ip_send_check(skb->nh.iph);
+
+	if (NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
+	            emulate_nf_hooks2) != 0)
+		return -1;
+
+	skb_pull(skb, off);
+	return 0;
+}
+#else /* CONFIG_NETFILTER */
+static inline int emulate_nf_hooks(struct sk_buff *skb) {}
+#endif /* CONFIG_NETFILTER */
+
 int xfrm4_rcv(struct sk_buff *skb)
 {
 	return xfrm4_rcv_encap(skb, 0);
@@ -125,15 +168,17 @@
 	memcpy(skb->sp->x+skb->sp->len, xfrm_vec, xfrm_nr*sizeof(struct sec_decap_state));
 	skb->sp->len += xfrm_nr;
 
+	nf_reset(skb);
 	if (decaps) {
 		if (!(skb->dev->flags&IFF_LOOPBACK)) {
 			dst_release(skb->dst);
 			skb->dst = NULL;
 		}
-		nf_reset(skb);
 		netif_rx(skb);
 		return 0;
 	} else {
+		if (emulate_nf_hooks(skb) != 0)
+			return 0;
 		return -skb->nh.iph->protocol;
 	}
 

  reply	other threads:[~2004-02-18 14:57 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-21 12:29 NAT before IPsec with 2.6 Michal Ludvig
2004-01-23  6:57 ` 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 [this message]
     [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=40337D63.6080602@trash.net \
    --to=kaber@trash.net \
    --cc=hno@marasystems.com \
    --cc=laforge@netfilter.org \
    --cc=mludvig@suse.cz \
    --cc=netfilter-devel@lists.netfilter.org \
    --cc=teastep@shorewall.net \
    --cc=willy@w.ods.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.