Skip to contentSkip to conversation

Various xfrm fixes and clean-ups

PATCH Applied Herbert Xu 5 participants 41 messages Oct 17, 2007 – Oct 25, 2007

Subsystems (4)
lore
Share & tools
lore

Herbert Xu

author maintainer
#0 lore raw

cover Various xfrm fixes and clean-ups

Hi Dave:

This series of patches completely replaces the ones I posted yesterday so you can delete the previous batch.

I'm still in the process of fixing up inter-family transforms so this is mostly the patches I posted yesterday with the offensive bits removed :)

I hadn't realised how broken inter-family transforms are on output until I started trying to fix them. As it is, it'll happily send IPv4 packets into the IPv6 ICMP stack or worse, IPv6 netfilter and vice versa.

The last patch in the series lays the foundation of my fix to this. My plan is to divide the work that's currently done by x->mode->output into two parts so that the first part can be done by the inner address family, i.e., x->inner_mode while the rest of it will be done by x->outer_mode->output. A similar scheme would operate on the inbound direction.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author maintainer
#1 lore raw

PATCH 1/11 : Fix pure tunnel modes involving IPv6

[IPSEC]: Fix pure tunnel modes involving IPv6

I noticed that my recent patch broke 6-on-4 pure IPsec tunnels (the ones that are only used for incompressible IPsec packets). Subsequent reviews show that I broke 6-on-6 pure tunnels more than three years ago and nobody ever noticed. I suppose every must be testing 6-on-6 IPComp with large pings which are very compressible :)

This patch fixes both cases.

---

 net/ipv4/xfrm4_tunnel.c |    2 +-
 net/ipv6/xfrm6_tunnel.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/xfrm4_tunnel.c +1 -1
index 1312417..83e9580 100644
@@ -18,7 +18,7 @@ static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
 
 static int ipip_xfrm_rcv(struct xfrm_state *x, struct sk_buff *skb)
 {
-	return IPPROTO_IP;
+	return ip_hdr(skb)->protocol;
 }
 
 static int ipip_init_state(struct xfrm_state *x)
net/ipv6/xfrm6_tunnel.c +1 -1
index 3f8a3ab..6c67ac1 100644
@@ -248,7 +248,7 @@ static int xfrm6_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
 
 static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
 {
-	return 0;
+	return skb_network_header(skb)[IP6CB(skb)->nhoff];
 }
 
 static int xfrm6_tunnel_rcv(struct sk_buff *skb)
maintainer Applied
#2 lore raw

Re: [PATCH 1/11] [IPSEC]: Fix pure tunnel modes involving IPv6

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:08 +0800

Quoted 11 lines

[IPSEC]: Fix pure tunnel modes involving IPv6

I noticed that my recent patch broke 6-on-4 pure IPsec tunnels (the ones that are only used for incompressible IPsec packets). Subsequent reviews show that I broke 6-on-6 pure tunnels more than three years ago and nobody ever noticed. I suppose every must be testing 6-on-6 IPComp with large pings which are very compressible :)

This patch fixes both cases.

Applied.

author maintainer
#3 lore raw

PATCH 2/11 : Move tunnel parsing for IPv4 out of xfrm4_input

In reply to Herbert Xu

[IPSEC]: Move tunnel parsing for IPv4 out of xfrm4_input

This patch moves the tunnel parsing for IPv4 out of xfrm4_input and into xfrm4_tunnel. This change is in line with what IPv6 does and will allow us to merge the two input functions.

---

 include/net/xfrm.h      |    8 ++++++++
 net/ipv4/xfrm4_input.c  |   36 +++++++++++-------------------------
 net/ipv4/xfrm4_tunnel.c |    9 +++++++--
 3 files changed, 26 insertions(+), 27 deletions(-)
include/net/xfrm.h +8 -0
index 0e84484..680739f 100644
@@ -1046,7 +1046,15 @@ extern void xfrm_replay_notify(struct xfrm_state *x, int event);
 extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
 extern int xfrm_init_state(struct xfrm_state *x);
 extern int xfrm_output(struct sk_buff *skb);
+extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
+			   int encap_type);
 extern int xfrm4_rcv(struct sk_buff *skb);
+
+static inline int xfrm4_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
+{
+	return xfrm4_rcv_encap(skb, nexthdr, spi, 0);
+}
+
 extern int xfrm4_output(struct sk_buff *skb);
 extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family);
 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family);
net/ipv4/xfrm4_input.c +11 -25
index e9bbfde..5cb0b59 100644
@@ -16,19 +16,6 @@
 #include <net/ip.h>
 #include <net/xfrm.h>
 
-static int xfrm4_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
-{
-	switch (nexthdr) {
-	case IPPROTO_IPIP:
-	case IPPROTO_IPV6:
-		*spi = ip_hdr(skb)->saddr;
-		*seq = 0;
-		return 0;
-	}
-
-	return xfrm_parse_spi(skb, nexthdr, spi, seq);
-}
-
 #ifdef CONFIG_NETFILTER
 static inline int xfrm4_rcv_encap_finish(struct sk_buff *skb)
 {
@@ -46,28 +33,29 @@ drop:
 }
 #endif
 
-static int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
+int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
+		    int encap_type)
 {
-	__be32 spi, seq;
+	int err;
+	__be32 seq;
 	struct xfrm_state *xfrm_vec[XFRM_MAX_DEPTH];
 	struct xfrm_state *x;
 	int xfrm_nr = 0;
 	int decaps = 0;
-	int err = xfrm4_parse_spi(skb, ip_hdr(skb)->protocol, &spi, &seq);
 	unsigned int nhoff = offsetof(struct iphdr, protocol);
 
-	if (err != 0)
+	seq = 0;
+	if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0)
 		goto drop;
 
 	do {
 		const struct iphdr *iph = ip_hdr(skb);
-		int nexthdr;
 
 		if (xfrm_nr == XFRM_MAX_DEPTH)
 			goto drop;
 
 		x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, spi,
-				iph->protocol != IPPROTO_IPV6 ? iph->protocol : IPPROTO_IPIP, AF_INET);
+				      nexthdr, AF_INET);
 		if (x == NULL)
 			goto drop;
 
@@ -111,7 +99,7 @@ static int xfrm4_rcv_encap(struct sk_buff *skb, __u16 encap_type)
 			break;
 		}
 
-		err = xfrm_parse_spi(skb, ip_hdr(skb)->protocol, &spi, &seq);
+		err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
 		if (err < 0)
 			goto drop;
 	} while (!err);
@@ -165,6 +153,7 @@ drop:
 	kfree_skb(skb);
 	return 0;
 }
+EXPORT_SYMBOL(xfrm4_rcv_encap);
 
 /* If it's a keepalive packet, then just eat it.
  * If it's an encapsulated packet, then pass it to the
@@ -252,11 +241,8 @@ int xfrm4_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
 	__skb_pull(skb, len);
 	skb_reset_transport_header(skb);
 
-	/* modify the protocol (it's ESP!) */
-	iph->protocol = IPPROTO_ESP;
-
 	/* process ESP */
-	ret = xfrm4_rcv_encap(skb, encap_type);
+	ret = xfrm4_rcv_encap(skb, IPPROTO_ESP, 0, encap_type);
 	return ret;
 
 drop:
@@ -266,7 +252,7 @@ drop:
 
 int xfrm4_rcv(struct sk_buff *skb)
 {
-	return xfrm4_rcv_encap(skb, 0);
+	return xfrm4_rcv_spi(skb, ip_hdr(skb)->protocol, 0);
 }
 
 EXPORT_SYMBOL(xfrm4_rcv);
net/ipv4/xfrm4_tunnel.c +7 -2
index 83e9580..3268451 100644
@@ -48,20 +48,25 @@ static struct xfrm_type ipip_type = {
 	.output		= ipip_output
 };
 
+static int xfrm_tunnel_rcv(struct sk_buff *skb)
+{
+	return xfrm4_rcv_spi(skb, IPPROTO_IP, ip_hdr(skb)->saddr);
+}
+
 static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
 {
 	return -ENOENT;
 }
 
 static struct xfrm_tunnel xfrm_tunnel_handler = {
-	.handler	=	xfrm4_rcv,
+	.handler	=	xfrm_tunnel_rcv,
 	.err_handler	=	xfrm_tunnel_err,
 	.priority	=	2,
 };
 
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
 static struct xfrm_tunnel xfrm64_tunnel_handler = {
-	.handler	=	xfrm4_rcv,
+	.handler	=	xfrm_tunnel_rcv,
 	.err_handler	=	xfrm_tunnel_err,
 	.priority	=	2,
 };
maintainer Applied
#4 lore raw

Re: [PATCH 2/11] [IPSEC]: Move tunnel parsing for IPv4 out of xfrm4_input

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:09 +0800

Quoted 7 lines

[IPSEC]: Move tunnel parsing for IPv4 out of xfrm4_input

This patch moves the tunnel parsing for IPv4 out of xfrm4_input and into xfrm4_tunnel. This change is in line with what IPv6 does and will allow us to merge the two input functions.

Applied.

author maintainer
#5 lore raw

PATCH 3/11 : Get nexthdr from caller in xfrm6_rcv_spi

In reply to Herbert Xu

[IPSEC]: Get nexthdr from caller in xfrm6_rcv_spi

Currently xfrm6_rcv_spi gets the nexthdr value itself from the packet. This means that we need to fix up the value in case we have a 4-on-6 tunnel. Moving this logic into the caller simplifies things and allows us to merge the code with IPv4.

---

 include/net/xfrm.h      |    2 +-
 net/ipv6/xfrm6_input.c  |    9 ++++-----
 net/ipv6/xfrm6_tunnel.c |    2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)
include/net/xfrm.h +1 -1
index 680739f..d8974ca 100644
@@ -1058,7 +1058,7 @@ static inline int xfrm4_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 extern int xfrm4_output(struct sk_buff *skb);
 extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family);
 extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family);
-extern int xfrm6_rcv_spi(struct sk_buff *skb, __be32 spi);
+extern int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi);
 extern int xfrm6_rcv(struct sk_buff *skb);
 extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
 			    xfrm_address_t *saddr, u8 proto);
net/ipv6/xfrm6_input.c +4 -5
index 02f69e5..596a730 100644
@@ -16,7 +16,7 @@
 #include <net/ipv6.h>
 #include <net/xfrm.h>
 
-int xfrm6_rcv_spi(struct sk_buff *skb, __be32 spi)
+int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 {
 	int err;
 	__be32 seq;
@@ -24,11 +24,9 @@ int xfrm6_rcv_spi(struct sk_buff *skb, __be32 spi)
 	struct xfrm_state *x;
 	int xfrm_nr = 0;
 	int decaps = 0;
-	int nexthdr;
 	unsigned int nhoff;
 
 	nhoff = IP6CB(skb)->nhoff;
-	nexthdr = skb_network_header(skb)[nhoff];
 
 	seq = 0;
 	if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0)
@@ -41,7 +39,7 @@ int xfrm6_rcv_spi(struct sk_buff *skb, __be32 spi)
 			goto drop;
 
 		x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, spi,
-				nexthdr != IPPROTO_IPIP ? nexthdr : IPPROTO_IPV6, AF_INET6);
+				      nexthdr, AF_INET6);
 		if (x == NULL)
 			goto drop;
 		spin_lock(&x->lock);
@@ -135,7 +133,8 @@ EXPORT_SYMBOL(xfrm6_rcv_spi);
 
 int xfrm6_rcv(struct sk_buff *skb)
 {
-	return xfrm6_rcv_spi(skb, 0);
+	return xfrm6_rcv_spi(skb, skb_network_header(skb)[IP6CB(skb)->nhoff],
+			     0);
 }
 
 EXPORT_SYMBOL(xfrm6_rcv);
net/ipv6/xfrm6_tunnel.c +1 -1
index 6c67ac1..fae90ff 100644
@@ -257,7 +257,7 @@ static int xfrm6_tunnel_rcv(struct sk_buff *skb)
 	__be32 spi;
 
 	spi = xfrm6_tunnel_spi_lookup((xfrm_address_t *)&iph->saddr);
-	return xfrm6_rcv_spi(skb, spi) > 0 ? : 0;
+	return xfrm6_rcv_spi(skb, IPPROTO_IPV6, spi) > 0 ? : 0;
 }
 
 static int xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
maintainer Applied
#6 lore raw

Re: [PATCH 3/11] [IPSEC]: Get nexthdr from caller in xfrm6_rcv_spi

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:10 +0800

Quoted 8 lines

[IPSEC]: Get nexthdr from caller in xfrm6_rcv_spi

Currently xfrm6_rcv_spi gets the nexthdr value itself from the packet. This means that we need to fix up the value in case we have a 4-on-6 tunnel. Moving this logic into the caller simplifies things and allows us to merge the code with IPv4.

Applied.

author maintainer
#7 lore raw

PATCH 4/11 : Move ip_summed zapping out of xfrm6_rcv_spi

In reply to Herbert Xu

[IPSEC]: Move ip_summed zapping out of xfrm6_rcv_spi

Not every transform needs to zap ip_summed. For example, a pure tunnel mode encapsulation does not affect the hardware checksum at all. In fact, every algorithm (that needs this) other than AH6 already does its own ip_summed zapping.

This patch moves the zapping into AH6 which is in line with what IPv4 does.

Possible future optimisation: Checksum the data as we copy them in IPComp.

---

 net/ipv6/ah6.c         |    2 ++
 net/ipv6/xfrm6_input.c |    1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
net/ipv6/ah6.c +2 -0
index f9f6891..a8221d1 100644
@@ -344,6 +344,8 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
 	    pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
 		goto out;
 
+	skb->ip_summed = CHECKSUM_NONE;
+
 	hdr_len = skb->data - skb_network_header(skb);
 	ah = (struct ip_auth_hdr *)skb->data;
 	ahp = x->data;
net/ipv6/xfrm6_input.c +0 -1
index 596a730..b1201c3 100644
@@ -97,7 +97,6 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 	memcpy(skb->sp->xvec + skb->sp->len, xfrm_vec,
 	       xfrm_nr * sizeof(xfrm_vec[0]));
 	skb->sp->len += xfrm_nr;
-	skb->ip_summed = CHECKSUM_NONE;
 
 	nf_reset(skb);
 
maintainer Applied
#8 lore raw

Re: [PATCH 4/11] [IPSEC]: Move ip_summed zapping out of xfrm6_rcv_spi

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:11 +0800

Quoted 7 lines

[IPSEC]: Move ip_summed zapping out of xfrm6_rcv_spi

Not every transform needs to zap ip_summed. For example, a pure tunnel mode encapsulation does not affect the hardware checksum at all. In fact, every algorithm (that needs this) other than AH6 already does its own ip_summed zapping.

Quoted 5 lines

This patch moves the zapping into AH6 which is in line with what IPv4 does.

Possible future optimisation: Checksum the data as we copy them in IPComp.

Applied.

author maintainer
#9 lore raw

PATCH 5/11 : Fix length check in xfrm_parse_spi

In reply to Herbert Xu

[IPSEC]: Fix length check in xfrm_parse_spi

Currently xfrm_parse_spi requires there to be 16 bytes for AH and ESP. In contrived cases there may not actually be 16 bytes there since the respective header sizes are less than that (8 and 12 currently).

This patch changes the test to use the actual header length instead of 16.

---

 net/xfrm/xfrm_input.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletion(-)
net/xfrm/xfrm_input.c +4 -1
index 113f444..cb97fda 100644
@@ -49,13 +49,16 @@ EXPORT_SYMBOL(secpath_dup);
 int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
 {
 	int offset, offset_seq;
+	int hlen;
 
 	switch (nexthdr) {
 	case IPPROTO_AH:
+		hlen = sizeof(struct ip_auth_hdr);
 		offset = offsetof(struct ip_auth_hdr, spi);
 		offset_seq = offsetof(struct ip_auth_hdr, seq_no);
 		break;
 	case IPPROTO_ESP:
+		hlen = sizeof(struct ip_esp_hdr);
 		offset = offsetof(struct ip_esp_hdr, spi);
 		offset_seq = offsetof(struct ip_esp_hdr, seq_no);
 		break;
@@ -69,7 +72,7 @@ int xfrm_parse_spi(struct sk_buff *skb, u8 nexthdr, __be32 *spi, __be32 *seq)
 		return 1;
 	}
 
-	if (!pskb_may_pull(skb, 16))
+	if (!pskb_may_pull(skb, hlen))
 		return -EINVAL;
 
 	*spi = *(__be32*)(skb_transport_header(skb) + offset);
maintainer Applied
#10 lore raw

Re: [PATCH 5/11] [IPSEC]: Fix length check in xfrm_parse_spi

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:13 +0800

Quoted 9 lines

[IPSEC]: Fix length check in xfrm_parse_spi

Currently xfrm_parse_spi requires there to be 16 bytes for AH and ESP. In contrived cases there may not actually be 16 bytes there since the respective header sizes are less than that (8 and 12 currently).

This patch changes the test to use the actual header length instead of 16.

Applied.

author maintainer
#11 lore raw

PATCH 6/11 : Move type and mode map into xfrm_state.c

In reply to Herbert Xu

[IPSEC]: Move type and mode map into xfrm_state.c

The type and mode maps are only used by SAs, not policies. So it makes sense to move them from xfrm_policy.c into xfrm_state.c. This alos allows us to mark xfrm_get_type/xfrm_put_type/xfrm_get_mode/xfrm_put_mode as static.

The only other change I've made in the move is to get rid of the casts on the request_module call for types. They're unnecessary because C will promote them to ints anyway.

---

 include/net/xfrm.h     |    8 --
 net/xfrm/xfrm_policy.c |  173 -------------------------------------------------
 net/xfrm/xfrm_state.c  |  170 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+), 179 deletions(-)
include/net/xfrm.h +2 -6
index d8974ca..7f156a0 100644
@@ -228,8 +228,6 @@ struct xfrm_type;
 struct xfrm_dst;
 struct xfrm_policy_afinfo {
 	unsigned short		family;
-	struct xfrm_type	*type_map[IPPROTO_MAX];
-	struct xfrm_mode	*mode_map[XFRM_MODE_MAX];
 	struct dst_ops		*dst_ops;
 	void			(*garbage_collect)(void);
 	int			(*dst_lookup)(struct xfrm_dst **dst, struct flowi *fl);
@@ -256,6 +254,8 @@ extern int __xfrm_state_delete(struct xfrm_state *x);
 
 struct xfrm_state_afinfo {
 	unsigned short		family;
+	struct xfrm_type	*type_map[IPPROTO_MAX];
+	struct xfrm_mode	*mode_map[XFRM_MODE_MAX];
 	int			(*init_flags)(struct xfrm_state *x);
 	void			(*init_tempsel)(struct xfrm_state *x, struct flowi *fl,
 						struct xfrm_tmpl *tmpl,
@@ -295,8 +295,6 @@ struct xfrm_type
 
 extern int xfrm_register_type(struct xfrm_type *type, unsigned short family);
 extern int xfrm_unregister_type(struct xfrm_type *type, unsigned short family);
-extern struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family);
-extern void xfrm_put_type(struct xfrm_type *type);
 
 struct xfrm_mode {
 	int (*input)(struct xfrm_state *x, struct sk_buff *skb);
@@ -320,8 +318,6 @@ struct xfrm_mode {
 
 extern int xfrm_register_mode(struct xfrm_mode *mode, int family);
 extern int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
-extern struct xfrm_mode *xfrm_get_mode(unsigned int encap, int family);
-extern void xfrm_put_mode(struct xfrm_mode *mode);
 
 struct xfrm_tmpl
 {
net/xfrm/xfrm_policy.c +0 -173

197 lines not on this page · raw message

net/xfrm/xfrm_state.c +170 -0

176 lines not on this page · raw message

maintainer Applied
#12 lore raw

Re: [PATCH 6/11] [IPSEC]: Move type and mode map into xfrm_state.c

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:14 +0800

Quoted 7 lines

[IPSEC]: Move type and mode map into xfrm_state.c

The type and mode maps are only used by SAs, not policies. So it makes sense to move them from xfrm_policy.c into xfrm_state.c. This alos allows us to mark xfrm_get_type/xfrm_put_type/xfrm_get_mode/xfrm_put_mode as static.

Quoted 5 lines

The only other change I've made in the move is to get rid of the casts on the request_module call for types. They're unnecessary because C will promote them to ints anyway.

Applied.

author maintainer
#13 lore raw

PATCH 7/11 : Add missing BEET checks

In reply to Herbert Xu

[IPSEC]: Add missing BEET checks

Currently BEET mode does not reinject the packet back into the stack like tunnel mode does. Since BEET should behave just like tunnel mode this is incorrect.

This patch fixes this by introducing a flags field to xfrm_mode that tells the IPsec code whether it should terminate and reinject the packet back into the stack.

It then sets the flag for BEET and tunnel mode.

I've also added a number of missing BEET checks elsewhere where we check whether a given mode is a tunnel or not.

---

 include/net/xfrm.h           |    6 ++++++
 net/ipv4/xfrm4_input.c       |    2 +-
 net/ipv4/xfrm4_mode_beet.c   |    1 +
 net/ipv4/xfrm4_mode_tunnel.c |    1 +
 net/ipv4/xfrm4_output.c      |    2 +-
 net/ipv4/xfrm4_policy.c      |    2 +-
 net/ipv6/xfrm6_input.c       |    2 +-
 net/ipv6/xfrm6_mode_beet.c   |    1 +
 net/ipv6/xfrm6_mode_tunnel.c |    1 +
 net/ipv6/xfrm6_output.c      |    2 +-
 net/ipv6/xfrm6_policy.c      |    3 +--
 net/ipv6/xfrm6_state.c       |    6 ++++--
 net/xfrm/xfrm_output.c       |    2 +-
 net/xfrm/xfrm_policy.c       |    6 ++++--
 14 files changed, 25 insertions(+), 12 deletions(-)
include/net/xfrm.h +6 -0
index 7f156a0..2143f29 100644
@@ -314,6 +314,12 @@ struct xfrm_mode {
 
 	struct module *owner;
 	unsigned int encap;
+	int flags;
+};
+
+/* Flags for xfrm_mode. */
+enum {
+	XFRM_MODE_FLAG_TUNNEL = 1,
 };
 
 extern int xfrm_register_mode(struct xfrm_mode *mode, int family);
net/ipv4/xfrm4_input.c +1 -1
index 5cb0b59..bc5dc07 100644
@@ -94,7 +94,7 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 		if (x->mode->input(x, skb))
 			goto drop;
 
-		if (x->props.mode == XFRM_MODE_TUNNEL) {
+		if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
 		}
net/ipv4/xfrm4_mode_beet.c +1 -0
index 73d2338..e42e122 100644
@@ -114,6 +114,7 @@ static struct xfrm_mode xfrm4_beet_mode = {
 	.output = xfrm4_beet_output,
 	.owner = THIS_MODULE,
 	.encap = XFRM_MODE_BEET,
+	.flags = XFRM_MODE_FLAG_TUNNEL,
 };
 
 static int __init xfrm4_beet_init(void)
net/ipv4/xfrm4_mode_tunnel.c +1 -0
index 1ae9d32..e4deecb 100644
@@ -139,6 +139,7 @@ static struct xfrm_mode xfrm4_tunnel_mode = {
 	.output = xfrm4_tunnel_output,
 	.owner = THIS_MODULE,
 	.encap = XFRM_MODE_TUNNEL,
+	.flags = XFRM_MODE_FLAG_TUNNEL,
 };
 
 static int __init xfrm4_tunnel_init(void)
net/ipv4/xfrm4_output.c +1 -1
index a4edd66..dcbc274 100644
@@ -47,7 +47,7 @@ static inline int xfrm4_output_one(struct sk_buff *skb)
 	struct iphdr *iph;
 	int err;
 
-	if (x->props.mode == XFRM_MODE_TUNNEL) {
+	if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 		err = xfrm4_tunnel_check_size(skb);
 		if (err)
 			goto error_nolock;
net/ipv4/xfrm4_policy.c +1 -1
index 329825c..2373d67 100644
@@ -117,7 +117,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		header_len += xfrm[i]->props.header_len;
 		trailer_len += xfrm[i]->props.trailer_len;
 
-		if (xfrm[i]->props.mode == XFRM_MODE_TUNNEL) {
+		if (xfrm[i]->props.mode != XFRM_MODE_TRANSPORT) {
 			unsigned short encap_family = xfrm[i]->props.family;
 			switch (encap_family) {
 			case AF_INET:
net/ipv6/xfrm6_input.c +1 -1
index b1201c3..c6ee1a3 100644
@@ -71,7 +71,7 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 		if (x->mode->input(x, skb))
 			goto drop;
 
-		if (x->props.mode == XFRM_MODE_TUNNEL) { /* XXX */
+		if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
 		}
net/ipv6/xfrm6_mode_beet.c +1 -0
index 13bb1e8..2bfb4f0 100644
@@ -79,6 +79,7 @@ static struct xfrm_mode xfrm6_beet_mode = {
 	.output = xfrm6_beet_output,
 	.owner = THIS_MODULE,
 	.encap = XFRM_MODE_BEET,
+	.flags = XFRM_MODE_FLAG_TUNNEL,
 };
 
 static int __init xfrm6_beet_init(void)
net/ipv6/xfrm6_mode_tunnel.c +1 -0
index ea22838..fd84e22 100644
@@ -118,6 +118,7 @@ static struct xfrm_mode xfrm6_tunnel_mode = {
 	.output = xfrm6_tunnel_output,
 	.owner = THIS_MODULE,
 	.encap = XFRM_MODE_TUNNEL,
+	.flags = XFRM_MODE_FLAG_TUNNEL,
 };
 
 static int __init xfrm6_tunnel_init(void)
net/ipv6/xfrm6_output.c +1 -1
index a5a32c1..c9f42d1 100644
@@ -50,7 +50,7 @@ static inline int xfrm6_output_one(struct sk_buff *skb)
 	struct ipv6hdr *iph;
 	int err;
 
-	if (x->props.mode == XFRM_MODE_TUNNEL) {
+	if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 		err = xfrm6_tunnel_check_size(skb);
 		if (err)
 			goto error_nolock;
net/ipv6/xfrm6_policy.c +1 -2
index 15aa4c5..dc4bdcb 100644
@@ -178,8 +178,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		__xfrm6_bundle_len_inc(&header_len, &nfheader_len, xfrm[i]);
 		trailer_len += xfrm[i]->props.trailer_len;
 
-		if (xfrm[i]->props.mode == XFRM_MODE_TUNNEL ||
-		    xfrm[i]->props.mode == XFRM_MODE_ROUTEOPTIMIZATION) {
+		if (xfrm[i]->props.mode != XFRM_MODE_TRANSPORT) {
 			unsigned short encap_family = xfrm[i]->props.family;
 			switch(encap_family) {
 			case AF_INET:
net/ipv6/xfrm6_state.c +4 -2
index cdadb48..e644c80 100644
@@ -93,7 +93,8 @@ __xfrm6_state_sort(struct xfrm_state **dst, struct xfrm_state **src, int n)
 	/* Rule 4: select IPsec tunnel */
 	for (i = 0; i < n; i++) {
 		if (src[i] &&
-		    src[i]->props.mode == XFRM_MODE_TUNNEL) {
+		    (src[i]->props.mode == XFRM_MODE_TUNNEL ||
+		     src[i]->props.mode == XFRM_MODE_BEET)) {
 			dst[j++] = src[i];
 			src[i] = NULL;
 		}
@@ -146,7 +147,8 @@ __xfrm6_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n)
 	/* Rule 3: select IPsec tunnel */
 	for (i = 0; i < n; i++) {
 		if (src[i] &&
-		    src[i]->mode == XFRM_MODE_TUNNEL) {
+		    (src[i]->mode == XFRM_MODE_TUNNEL ||
+		     src[i]->mode == XFRM_MODE_BEET)) {
 			dst[j++] = src[i];
 			src[i] = NULL;
 		}
net/xfrm/xfrm_output.c +1 -1
index 0eb3377..8bf71ba 100644
@@ -82,7 +82,7 @@ int xfrm_output(struct sk_buff *skb)
 		}
 		dst = skb->dst;
 		x = dst->xfrm;
-	} while (x && (x->props.mode != XFRM_MODE_TUNNEL));
+	} while (x && !(x->mode->flags & XFRM_MODE_FLAG_TUNNEL));
 
 	err = 0;
 
net/xfrm/xfrm_policy.c +4 -2
index ca24c90..1d66fb4 100644
@@ -1940,7 +1940,8 @@ int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first,
 		if (xdst->genid != dst->xfrm->genid)
 			return 0;
 
-		if (strict && fl && dst->xfrm->props.mode != XFRM_MODE_TUNNEL &&
+		if (strict && fl &&
+		    !(dst->xfrm->mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
 		    !xfrm_state_addr_flow_check(dst->xfrm, fl, family))
 			return 0;
 
@@ -2291,7 +2292,8 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
 			if (!migrate_tmpl_match(mp, &pol->xfrm_vec[i]))
 				continue;
 			n++;
-			if (pol->xfrm_vec[i].mode != XFRM_MODE_TUNNEL)
+			if (pol->xfrm_vec[i].mode != XFRM_MODE_TUNNEL &&
+			    pol->xfrm_vec[i].mode != XFRM_MODE_BEET)
 				continue;
 			/* update endpoints */
 			memcpy(&pol->xfrm_vec[i].id.daddr, &mp->new_daddr,
maintainer Applied
#14 lore raw

Re: [PATCH 7/11] [IPSEC]: Add missing BEET checks

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:15 +0800

Quoted 10 lines

[IPSEC]: Add missing BEET checks

Currently BEET mode does not reinject the packet back into the stack like tunnel mode does. Since BEET should behave just like tunnel mode this is incorrect.

This patch fixes this by introducing a flags field to xfrm_mode that tells the IPsec code whether it should terminate and reinject the packet back into the stack.

Quoted 6 lines

It then sets the flag for BEET and tunnel mode.

I've also added a number of missing BEET checks elsewhere where we check whether a given mode is a tunnel or not.

Applied.

author maintainer
#15 lore raw

PATCH 8/11 : Store afinfo pointer in xfrm_mode

In reply to Herbert Xu

[IPSEC]: Store afinfo pointer in xfrm_mode

It is convenient to have a pointer from xfrm_state to address-specific functions such as the output function for a family. Currently the address-specific policy code calls out to the xfrm state code to get those pointers when we could get it in an easier way via the state itself.

This patch adds an xfrm_state_afinfo to xfrm_mode (since they're address-specific) and changes the policy code to use it. I've also added an owner field to do reference counting on the module providing the afinfo even though it isn't strictly necessary today since IPv6 can't be unloaded yet.

---

 include/net/xfrm.h      |    6 +++---
 net/ipv4/xfrm4_policy.c |   13 +------------
 net/ipv4/xfrm4_state.c  |    1 +
 net/ipv6/xfrm6_policy.c |   14 +-------------
 net/ipv6/xfrm6_state.c  |    1 +
 net/xfrm/xfrm_state.c   |   26 +++++++++++++++++---------
 6 files changed, 24 insertions(+), 37 deletions(-)
include/net/xfrm.h +3 -3
index 2143f29..f0f3318 100644
@@ -253,7 +253,8 @@ extern void km_state_expired(struct xfrm_state *x, int hard, u32 pid);
 extern int __xfrm_state_delete(struct xfrm_state *x);
 
 struct xfrm_state_afinfo {
-	unsigned short		family;
+	unsigned int		family;
+	struct module		*owner;
 	struct xfrm_type	*type_map[IPPROTO_MAX];
 	struct xfrm_mode	*mode_map[XFRM_MODE_MAX];
 	int			(*init_flags)(struct xfrm_state *x);
@@ -267,8 +268,6 @@ struct xfrm_state_afinfo {
 
 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
-extern struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family);
-extern void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
 
 extern void xfrm_state_delete_tunnel(struct xfrm_state *x);
 
@@ -312,6 +311,7 @@ struct xfrm_mode {
 	 */
 	int (*output)(struct xfrm_state *x,struct sk_buff *skb);
 
+	struct xfrm_state_afinfo *afinfo;
 	struct module *owner;
 	unsigned int encap;
 	int flags;
net/ipv4/xfrm4_policy.c +1 -12
index 2373d67..c65b8e0 100644
@@ -151,7 +151,6 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 	i = 0;
 	for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
 		struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
-		struct xfrm_state_afinfo *afinfo;
 		x->u.rt.fl = *fl;
 
 		dst_prev->xfrm = xfrm[i++];
@@ -169,17 +168,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		/* Copy neighbout for reachability confirmation */
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
-		/* XXX: When IPv6 module can be unloaded, we should manage reference
-		 * to xfrm6_output in afinfo->output. Miyazawa
-		 * */
-		afinfo = xfrm_state_get_afinfo(dst_prev->xfrm->props.family);
-		if (!afinfo) {
-			dst = *dst_p;
-			err = -EAFNOSUPPORT;
-			goto error;
-		}
-		dst_prev->output = afinfo->output;
-		xfrm_state_put_afinfo(afinfo);
+		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
 		if (dst_prev->xfrm->props.family == AF_INET && rt->peer)
 			atomic_inc(&rt->peer->refcnt);
 		x->u.rt.peer = rt->peer;
net/ipv4/xfrm4_state.c +1 -0
index 93e2c06..13d54a1 100644
@@ -49,6 +49,7 @@ __xfrm4_init_tempsel(struct xfrm_state *x, struct flowi *fl,
 
 static struct xfrm_state_afinfo xfrm4_state_afinfo = {
 	.family			= AF_INET,
+	.owner			= THIS_MODULE,
 	.init_flags		= xfrm4_init_flags,
 	.init_tempsel		= __xfrm4_init_tempsel,
 	.output			= xfrm4_output,
net/ipv6/xfrm6_policy.c +1 -13
index dc4bdcb..3242683 100644
@@ -214,7 +214,6 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 	i = 0;
 	for (; dst_prev != &rt->u.dst; dst_prev = dst_prev->child) {
 		struct xfrm_dst *x = (struct xfrm_dst*)dst_prev;
-		struct xfrm_state_afinfo *afinfo;
 
 		dst_prev->xfrm = xfrm[i++];
 		dst_prev->dev = rt->u.dst.dev;
@@ -231,18 +230,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		/* Copy neighbour for reachability confirmation */
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
-		/* XXX: When IPv4 is implemented as module and can be unloaded,
-		 * we should manage reference to xfrm4_output in afinfo->output.
-		 * Miyazawa
-		 */
-		afinfo = xfrm_state_get_afinfo(dst_prev->xfrm->props.family);
-		if (!afinfo) {
-			dst = *dst_p;
-			goto error;
-		}
-
-		dst_prev->output = afinfo->output;
-		xfrm_state_put_afinfo(afinfo);
+		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
 		/* Sheit... I remember I did this right. Apparently,
 		 * it was magically lost, so this code needs audit */
 		x->u.rt6.rt6i_flags    = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
net/ipv6/xfrm6_state.c +1 -0
index e644c80..b392bee 100644
@@ -170,6 +170,7 @@ __xfrm6_tmpl_sort(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n)
 
 static struct xfrm_state_afinfo xfrm6_state_afinfo = {
 	.family			= AF_INET6,
+	.owner			= THIS_MODULE,
 	.init_tempsel		= __xfrm6_init_tempsel,
 	.tmpl_sort		= __xfrm6_tmpl_sort,
 	.state_sort		= __xfrm6_state_sort,
net/xfrm/xfrm_state.c +17 -9
index dc438f2..48b4a06 100644
@@ -57,6 +57,9 @@ static unsigned int xfrm_state_hashmax __read_mostly = 1 * 1024 * 1024;
 static unsigned int xfrm_state_num;
 static unsigned int xfrm_state_genid;
 
+static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family);
+static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
+
 static inline unsigned int xfrm_dst_hash(xfrm_address_t *daddr,
 					 xfrm_address_t *saddr,
 					 u32 reqid,
@@ -289,11 +292,18 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
 
 	err = -EEXIST;
 	modemap = afinfo->mode_map;
-	if (likely(modemap[mode->encap] == NULL)) {
-		modemap[mode->encap] = mode;
-		err = 0;
-	}
+	if (modemap[mode->encap])
+		goto out;
 
+	err = -ENOENT;
+	if (!try_module_get(afinfo->owner))
+		goto out;
+
+	mode->afinfo = afinfo;
+	modemap[mode->encap] = mode;
+	err = 0;
+
+out:
 	xfrm_state_unlock_afinfo(afinfo);
 	return err;
 }
@@ -316,6 +326,7 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
 	modemap = afinfo->mode_map;
 	if (likely(modemap[mode->encap] == mode)) {
 		modemap[mode->encap] = NULL;
+		module_put(mode->afinfo->owner);
 		err = 0;
 	}
 
@@ -1869,7 +1880,7 @@ int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo)
 }
 EXPORT_SYMBOL(xfrm_state_unregister_afinfo);
 
-struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family)
+static struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family)
 {
 	struct xfrm_state_afinfo *afinfo;
 	if (unlikely(family >= NPROTO))
@@ -1881,14 +1892,11 @@ struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned short family)
 	return afinfo;
 }
 
-void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo)
+static void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo)
 {
 	read_unlock(&xfrm_state_afinfo_lock);
 }
 
-EXPORT_SYMBOL(xfrm_state_get_afinfo);
-EXPORT_SYMBOL(xfrm_state_put_afinfo);
-
 /* Temporarily located here until net/xfrm/xfrm_tunnel.c is created */
 void xfrm_state_delete_tunnel(struct xfrm_state *x)
 {
maintainer Applied
#16 lore raw

Re: [PATCH 8/11] [IPSEC]: Store afinfo pointer in xfrm_mode

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:16 +0800

Quoted 8 lines

[IPSEC]: Store afinfo pointer in xfrm_mode

It is convenient to have a pointer from xfrm_state to address-specific functions such as the output function for a family. Currently the address-specific policy code calls out to the xfrm state code to get those pointers when we could get it in an easier way via the state itself.

Quoted 7 lines

This patch adds an xfrm_state_afinfo to xfrm_mode (since they're address-specific) and changes the policy code to use it. I've also added an owner field to do reference counting on the module providing the afinfo even though it isn't strictly necessary today since IPv6 can't be unloaded yet.

Applied.

Thanks for doing this, those afinfo get/put things all over the place really bugged me.

author maintainer
#17 lore raw

PATCH 9/11 : Use the top IPv4 route's peer instead of the bottom

In reply to Herbert Xu

[IPSEC]: Use the top IPv4 route's peer instead of the bottom

For IPv4 we were using the bottom route's peer instead of the top one. This is wrong because the peer is only used by TCP to keep track of information about the TCP destination address which certainly does not live in the bottom route.

This patch fixes that which allows us to get rid of the family check since the bottom route could be IPv6 while the top one must always be IPv4.

I've also changed the other fields which are IPv4-specific to get the info from the top route instead of potentially bogus data from the bottom route.

---

 net/ipv4/xfrm4_policy.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
net/ipv4/xfrm4_policy.c +6 -6
index c65b8e0..1f0ea0e 100644
@@ -169,16 +169,16 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
 		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
-		if (dst_prev->xfrm->props.family == AF_INET && rt->peer)
-			atomic_inc(&rt->peer->refcnt);
-		x->u.rt.peer = rt->peer;
+		if (rt0->peer)
+			atomic_inc(&rt0->peer->refcnt);
+		x->u.rt.peer = rt0->peer;
 		/* Sheit... I remember I did this right. Apparently,
 		 * it was magically lost, so this code needs audit */
 		x->u.rt.rt_flags = rt0->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
-		x->u.rt.rt_type = rt->rt_type;
+		x->u.rt.rt_type = rt0->rt_type;
 		x->u.rt.rt_src = rt0->rt_src;
 		x->u.rt.rt_dst = rt0->rt_dst;
-		x->u.rt.rt_gateway = rt->rt_gateway;
+		x->u.rt.rt_gateway = rt0->rt_gateway;
 		x->u.rt.rt_spec_dst = rt0->rt_spec_dst;
 		x->u.rt.idev = rt0->idev;
 		in_dev_hold(rt0->idev);
@@ -280,7 +280,7 @@ static void xfrm4_dst_destroy(struct dst_entry *dst)
 
 	if (likely(xdst->u.rt.idev))
 		in_dev_put(xdst->u.rt.idev);
-	if (dst->xfrm && dst->xfrm->props.family == AF_INET && likely(xdst->u.rt.peer))
+	if (likely(xdst->u.rt.peer))
 		inet_putpeer(xdst->u.rt.peer);
 	xfrm_dst_destroy(xdst);
 }
maintainer Applied
#18 lore raw

Re: [PATCH 9/11] [IPSEC]: Use the top IPv4 route's peer instead of the bottom

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:17 +0800

Quoted 11 lines

[IPSEC]: Use the top IPv4 route's peer instead of the bottom

For IPv4 we were using the bottom route's peer instead of the top one. This is wrong because the peer is only used by TCP to keep track of information about the TCP destination address which certainly does not live in the bottom route.

This patch fixes that which allows us to get rid of the family check since the bottom route could be IPv6 while the top one must always be IPv4.

Quoted 5 lines

I've also changed the other fields which are IPv4-specific to get the info from the top route instead of potentially bogus data from the bottom route.

Applied, thanks.

author maintainer
#19 lore raw

PATCH 10/11 : Disallow combinations of RO and AH/ESP/IPCOMP

In reply to Herbert Xu

[IPSEC]: Disallow combinations of RO and AH/ESP/IPCOMP

Combining RO and AH/ESP/IPCOMP does not make sense. So this patch adds a check in the state initialisation function to prevent this.

This allows us to safely remove the mode input function of RO since it can never be called anymore. Indeed, if somehow it does get called we'll know about it through an OOPS instead of it slipping past silently.

---

 net/ipv6/ah6.c           |    9 ++++++++-
 net/ipv6/esp6.c          |    9 ++++++++-
 net/ipv6/ipcomp6.c       |    9 ++++++++-
 net/ipv6/xfrm6_mode_ro.c |    9 ---------
 4 files changed, 24 insertions(+), 12 deletions(-)
net/ipv6/ah6.c +8 -1
index a8221d1..67cd066 100644
@@ -477,8 +477,15 @@ static int ah6_init_state(struct xfrm_state *x)
 
 	x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) +
 					  ahp->icv_trunc_len);
-	if (x->props.mode == XFRM_MODE_TUNNEL)
+	switch (x->props.mode) {
+	case XFRM_MODE_BEET:
+	case XFRM_MODE_TRANSPORT:
+		break;
+	case XFRM_MODE_TUNNEL:
 		x->props.header_len += sizeof(struct ipv6hdr);
+	default:
+		goto error;
+	}
 	x->data = ahp;
 
 	return 0;
net/ipv6/esp6.c +8 -1
index 9eb9285..b071543 100644
@@ -354,8 +354,15 @@ static int esp6_init_state(struct xfrm_state *x)
 				    (x->ealg->alg_key_len + 7) / 8))
 		goto error;
 	x->props.header_len = sizeof(struct ip_esp_hdr) + esp->conf.ivlen;
-	if (x->props.mode == XFRM_MODE_TUNNEL)
+	switch (x->props.mode) {
+	case XFRM_MODE_BEET:
+	case XFRM_MODE_TRANSPORT:
+		break;
+	case XFRM_MODE_TUNNEL:
 		x->props.header_len += sizeof(struct ipv6hdr);
+	default:
+		goto error;
+	}
 	x->data = esp;
 	return 0;
 
net/ipv6/ipcomp6.c +8 -1
index 28fc8ed..80ef2a1 100644
@@ -411,8 +411,15 @@ static int ipcomp6_init_state(struct xfrm_state *x)
 		goto out;
 
 	x->props.header_len = 0;
-	if (x->props.mode == XFRM_MODE_TUNNEL)
+	switch (x->props.mode) {
+	case XFRM_MODE_BEET:
+	case XFRM_MODE_TRANSPORT:
+		break;
+	case XFRM_MODE_TUNNEL:
 		x->props.header_len += sizeof(struct ipv6hdr);
+	default:
+		goto error;
+	}
 
 	mutex_lock(&ipcomp6_resource_mutex);
 	if (!ipcomp6_alloc_scratches())
net/ipv6/xfrm6_mode_ro.c +0 -9
index 957ae36..a7bc8c6 100644
@@ -58,16 +58,7 @@ static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
 	return 0;
 }
 
-/*
- * Do nothing about routing optimization header unlike IPsec.
- */
-static int xfrm6_ro_input(struct xfrm_state *x, struct sk_buff *skb)
-{
-	return 0;
-}
-
 static struct xfrm_mode xfrm6_ro_mode = {
-	.input = xfrm6_ro_input,
 	.output = xfrm6_ro_output,
 	.owner = THIS_MODULE,
 	.encap = XFRM_MODE_ROUTEOPTIMIZATION,
maintainer Applied
#20 lore raw

Re: [PATCH 10/11] [IPSEC]: Disallow combinations of RO and AH/ESP/IPCOMP

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 22:34:18 +0800

Quoted 10 lines

[IPSEC]: Disallow combinations of RO and AH/ESP/IPCOMP

Combining RO and AH/ESP/IPCOMP does not make sense. So this patch adds a check in the state initialisation function to prevent this.

This allows us to safely remove the mode input function of RO since it can never be called anymore. Indeed, if somehow it does get called we'll know about it through an OOPS instead of it slipping past silently.

Applied.

#21 lore raw

PATCH 1/1 IPV6: Fix to add tunnel mode SA correctly.

---
 net/ipv6/ah6.c  |    1 +
 net/ipv6/esp6.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
net/ipv6/ah6.c +1 -0
index 67cd066..66a9139 100644
@@ -483,6 +483,7 @@ static int ah6_init_state(struct xfrm_state *x)
 		break;
 	case XFRM_MODE_TUNNEL:
 		x->props.header_len += sizeof(struct ipv6hdr);
+		break;
 	default:
 		goto error;
 	}
net/ipv6/esp6.c +1 -0
index b071543..72a6598 100644
@@ -360,6 +360,7 @@ static int esp6_init_state(struct xfrm_state *x)
 		break;
 	case XFRM_MODE_TUNNEL:
 		x->props.header_len += sizeof(struct ipv6hdr);
+		break;
 	default:
 		goto error;
 	}
Signature · 1 line
1.4.4.2
author maintainer
#22 lore raw

Re: [PATCH] [IPSEC] IPV6: Fix to add tunnel mode SA correctly.

Quoted 1 line · Masahide NAKAMURA

Thanks for catching my silly bug!

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#24 lore raw

cover : Support packet processing error statistics.

In reply to David Miller

This patch introduces statistics about transformation error (or almost error) factor at packet processing for developer.
It is not a SNMP/MIB specification from IPsec/MIPv6 but a counter designed from current transformation source code.

Comment please.

author maintainer
#25 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 6 lines · Masahide NAKAMURA

This patch introduces statistics about transformation error (or almost error) factor at packet processing for developer.
It is not a SNMP/MIB specification from IPsec/MIPv6 but a counter designed from current transformation source code.

Comment please.

Looks fine to me. But could you hold onto this for a few days? I'm in the process of merging the input paths of IPv4 and IPv6. Once that's done you'll only need to count things once rather than once for IPv4 and again for IPv6.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#26 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 6 lines · Herbert Xu
Quoted 5 lines · Masahide NAKAMURA

This patch introduces statistics about transformation error (or almost error) factor at packet processing for developer.
It is not a SNMP/MIB specification from IPsec/MIPv6 but a counter designed from current transformation source code.

Quoted 6 lines
Quoted 1 line

Comment please.

Looks fine to me. But could you hold onto this for a few days? I'm in the process of merging the input paths of IPv4 and IPv6. Once that's done you'll only need to count things once rather than once for IPv4 and again for IPv6.

No problem, I'll fix my patches upon your work and resend them.

Regards,

Signature · 1 line
Masahide NAKAMURA
#27 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

In reply to Masahide NAKAMURA
Quoted 6 lines · Masahide NAKAMURA

This patch introduces statistics about transformation error (or almost error) factor at packet processing for developer.
It is not a SNMP/MIB specification from IPsec/MIPv6 but a counter designed from current transformation source code.

Comment please.

very nice - these stats make IPSEC a lot more usable (I will go look and see if theres anything that i have used for debug before that you dont have and send you mail). Two comments:

1) Since these are not MIB stats, it sounds like a good idea not to use _MIB_ extender in the naming. Maybe something like _NOTMIB_ ;-> or totaly leave it out. One other approach is to push these to be a MIB at IETF since they are sensible to have.

2) Why /proc? Are you going to make these available also via netlink?

cheers,
jamal

#28 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 11 lines · jamal
Quoted 6 lines · Masahide NAKAMURA

This patch introduces statistics about transformation error (or almost error) factor at packet processing for developer.
It is not a SNMP/MIB specification from IPsec/MIPv6 but a counter designed from current transformation source code.

Comment please.

very nice - these stats make IPSEC a lot more usable (I will go look and see if theres anything that i have used for debug before that you dont have and send you mail). Two comments:

Thanks. I would like you to find too much item at my patch for the statistics, too.

Quoted 4 lines

1) Since these are not MIB stats, it sounds like a good idea not to use _MIB_ extender in the naming. Maybe something like _NOTMIB_ ;-> or totaly leave it out. One other approach is to push these to be a MIB at IETF since they are sensible to have.

This point is one of what I want to hear comment.
My patch uses "XFRM_MIB_XXX" because I found "LINUX_MIB_XXX" definition at include/linux/snmp.h for TCP extended statistics at /proc/net/netstat and it does not seem to be defined by any RFC specification. Then I feel it is not so bad to use _MIB_ for them. Maybe we have another idea to merge them into LINUX_MIB.

Now we have the following candidates:

(1) my patch XFRM_MIB_INHDRERROR
(2) some extender XFRM_XXX_INHDRERROR (XXX is requested)
(3) not-mib extender XFRM_NOTMIB_INHDRERROR
(4) no extender XFRM_INHDRERROR
(5) merge linux-mib LINUX_MIB_XFRMINHDRERROR

Comments?

Quoted 1 line

2) Why /proc? Are you going to make these available also via netlink?

Because /proc is easy to see it without any modified application. If you want the netlink interface, I can do it as the next step. Do you want it?

Signature · 1 line
Masahide NAKAMURA
#29 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 2 lines · Masahide NAKAMURA

Thanks. I would like you to find too much item at my patch for the statistics, too.

I am not anywhere close to a machine where i can give you precise details to this; the one thing that sticks out in my brain cells is the SPI mismatch. This (in static setups) seemed to be the most common mistake i saw (other than a mismatched key). Your stats as you have them now and as is will catch both in one spot - which is a good start.

Quoted 4 lines

This point is one of what I want to hear comment.
My patch uses "XFRM_MIB_XXX" because I found "LINUX_MIB_XXX" definition at include/linux/snmp.h for TCP extended statistics at /proc/net/netstat and it does not seem to be defined by any RFC specification.

I thought those were part of some MIB somewhere. Doesnt RFC 4898 cover them?
In any case, it seems to me to be more accurate to not call them MIB stats if they are not. This doesnt qualify using the macros, utilities etc used for MIBs.

Quoted 5 lines

Then I feel it is not so bad to
use _MIB_ for them. Maybe we have another idea to merge them into LINUX_MIB.

Now we have the following candidates:

Quoted 7 lines

(1) my patch XFRM_MIB_INHDRERROR
(2) some extender XFRM_XXX_INHDRERROR (XXX is requested)
(3) not-mib extender XFRM_NOTMIB_INHDRERROR
(4) no extender XFRM_INHDRERROR
(5) merge linux-mib LINUX_MIB_XFRMINHDRERROR

Comments?

I am very tempted to say #4. And when you push this to be a real MIB stat then

Quoted 5 lines
Quoted 2 lines

2) Why /proc? Are you going to make these available also via netlink?

Because /proc is easy to see it without any modified application. If you want the netlink interface, I can do it as the next step. Do you want it?

Absolutely - it would be much appreciated. And if you dont have time, I will write and test the user space part extension.

cheers,
jamal

#30 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 10 lines · jamal
Quoted 2 lines · Masahide NAKAMURA

Thanks. I would like you to find too much item at my patch for the statistics, too.

I am not anywhere close to a machine where i can give you precise details to this; the one thing that sticks out in my brain cells is the SPI mismatch. This (in static setups) seemed to be the most common mistake i saw (other than a mismatched key). Your stats as you have them now and as is will catch both in one spot - which is a good start.

At IPsec point of view, actually "SPI mismatch" caused by user configuration cannot be identified easily since identify of SAD is consist of SPI, address and protocol(ESP/AH...) and linux SAD uses hash database. It is database identify mismatch. Then, SPI mismatch goes "NoStates" at my patch.
OTOH Key mismatch goes "ProtoError" since esp[46]_input returns error.

Quoted 7 lines
Quoted 4 lines

This point is one of what I want to hear comment.
My patch uses "XFRM_MIB_XXX" because I found "LINUX_MIB_XXX" definition at include/linux/snmp.h for TCP extended statistics at /proc/net/netstat and it does not seem to be defined by any RFC specification.

I thought those were part of some MIB somewhere. Doesnt RFC 4898 cover them?

Thanks for pointing the RFC. I've read it, however, I cannot find them at the RFC.

Quoted 3 lines

In any case, it seems to me to be more accurate to not call them MIB stats if they are not. This doesnt qualify using the macros, utilities etc used for MIBs.

How about assuming it as "private MIB" of linux?

Quoted 11 lines
Quoted 11 lines

Then I feel it is not so bad to
use _MIB_ for them. Maybe we have another idea to merge them into LINUX_MIB.

Now we have the following candidates:

(1) my patch XFRM_MIB_INHDRERROR
(2) some extender XFRM_XXX_INHDRERROR (XXX is requested)
(3) not-mib extender XFRM_NOTMIB_INHDRERROR
(4) no extender XFRM_INHDRERROR
(5) merge linux-mib LINUX_MIB_XFRMINHDRERROR

Quoted 4 lines
Quoted 1 line

Comments?

I am very tempted to say #4. And when you push this to be a real MIB stat then

Shouldn't we have something after XFRM_ to distinguish from other XFRM macros?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

2) Why /proc? Are you going to make these available also via netlink?

Because /proc is easy to see it without any modified application. If you want the netlink interface, I can do it as the next step. Do you want it?

Absolutely - it would be much appreciated. And if you dont have time, I will write and test the user space part extension.

Thanks. After my first step is completed, could you write the netlink part?

Signature · 1 line
Masahide NAKAMURA
#31 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 5 lines · Masahide NAKAMURA

At IPsec point of view, actually "SPI mismatch" caused by user configuration cannot be identified easily since identify of SAD is consist of SPI, address and protocol(ESP/AH...) and linux SAD uses hash database. It is database identify mismatch. Then, SPI mismatch goes "NoStates" at my patch.
OTOH Key mismatch goes "ProtoError" since esp[46]_input returns error.

Would be useful to just document what you said above so that user doesnt have to intepret it.

Quoted 1 line

Thanks for pointing the RFC. I've read it, however, I cannot find them at the RFC.

My bad.

Quoted 4 lines
Quoted 3 lines

In any case, it seems to me to be more accurate to not call them MIB stats if they are not. This doesnt qualify using the macros, utilities etc used for MIBs.

BTW, I meant "doesnt disqualify them" above;->

Quoted 1 line

How about assuming it as "private MIB" of linux?

Ok, makes sense to me now - that would be a good choice (i dont see any confusion with enteprise mib).

Quoted 3 lines

Shouldn't we have something after XFRM_ to distinguish from other XFRM macros?

It is not needed - I am sorry that i missed the "Linux MIB" part in your emails so far. That would be good enough.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

2) Why /proc? Are you going to make these available also via netlink?

Because /proc is easy to see it without any modified application. If you want the netlink interface, I can do it as the next step. Do you want it?

Absolutely - it would be much appreciated. And if you dont have time, I will write and test the user space part extension.

Thanks. After my first step is completed, could you write the netlink part?

Thanks.

cheers,
jamal

#32 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 10 lines · jamal
Quoted 5 lines · Masahide NAKAMURA

At IPsec point of view, actually "SPI mismatch" caused by user configuration cannot be identified easily since identify of SAD is consist of SPI, address and protocol(ESP/AH...) and linux SAD uses hash database. It is database identify mismatch. Then, SPI mismatch goes "NoStates" at my patch.
OTOH Key mismatch goes "ProtoError" since esp[46]_input returns error.

Would be useful to just document what you said above so that user doesnt have to intepret it.

OK, I write it to commit-log then. If anybody have another place where such information should be written, tell me.

[snip]

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

In any case, it seems to me to be more accurate to not call them MIB stats if they are not. This doesnt qualify using the macros, utilities etc used for MIBs.

BTW, I meant "doesnt disqualify them" above;->

OK ;-)

Jamal, thanks for many comments.

Signature · 1 line
Masahide NAKAMURA
#33 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

In reply to Masahide NAKAMURA

In article <[email protected]> (at Tue, 23 Oct 2007 16:08:34 +0900), Masahide NAKAMURA <[email protected]> says:

Quoted 2 lines
Quoted 1 line · jamal

On Mon, 2007-22-10 at 15:11 +0900, Masahide NAKAMURA wrote:

:

Quoted 8 lines

This point is one of what I want to hear comment.
My patch uses "XFRM_MIB_XXX" because I found "LINUX_MIB_XXX" definition at include/linux/snmp.h for TCP extended statistics at /proc/net/netstat and it does not seem to be defined by any RFC specification. Then I feel it is not so bad to use _MIB_ for them. Maybe we have another idea to merge them into LINUX_MIB.

Now we have the following candidates:

Quoted 7 lines

(1) my patch XFRM_MIB_INHDRERROR
(2) some extender XFRM_XXX_INHDRERROR (XXX is requested)
(3) not-mib extender XFRM_NOTMIB_INHDRERROR
(4) no extender XFRM_INHDRERROR
(5) merge linux-mib LINUX_MIB_XFRMINHDRERROR

Comments?

I would support (5) or (1).

--yoshfuji

#34 lore raw

Re: [RFC][PATCH 0/3][XFRM]: Support packet processing error statistics.

Quoted 11 lines · YOSHIFUJI Hideaki / 吉藤英明

In article <[email protected]> (at Tue, 23 Oct 2007 16:08:34 +0900), Masahide NAKAMURA <[email protected]> says:

Quoted 8 lines

Now we have the following candidates:

(1) my patch XFRM_MIB_INHDRERROR
(2) some extender XFRM_XXX_INHDRERROR (XXX is requested)
(3) not-mib extender XFRM_NOTMIB_INHDRERROR
(4) no extender XFRM_INHDRERROR
(5) merge linux-mib LINUX_MIB_XFRMINHDRERROR

Quoted 3 lines
Quoted 1 line

Comments?

I would support (5) or (1).

#5 it is then.

cheers,
jamal

#35 lore raw

RFC PATCH 1/3 : Define packet processing statistics.

In reply to David Miller

This statistics is shown as /proc/net/xfrm_stat about transformation error (or almost error) factor at packet processing for developer. It is not a SNMP/MIB specification but a counter designed from current transformation source code.

- Inbound errors

XfrmInError               - all errors which is not matched others
XfrmInBufferError         - no buffer is left
XfrmInHdrError            - header error
XfrmInNoStates            - no state is found
XfrmInStateProtoError     - error at transformation protocol
XfrmInStateModeError      - error at transformation mode
XfrmInSeqOutOfWindow      - sequence out of window
XfrmInStateExpired        - state is expired
XfrmInStateMismatch       - state has mismatch option
XfrmInStateInvalid        - state is invalid
XfrmInTmplMismatch        - no matching template for states
XfrmInNoPols              - no policy is found for states
XfrmInPolBlock            - policy discards
XfrmInPolError            - policy error

- Outbound errors

XfrmOutError              - all errors which is not matched others
XfrmOutLengthError        - length error
XfrmOutBundleError        - error at bundle
XfrmOutNoStates           - no state is found
XfrmOutStateProtoError    - error at transformation protocol
XfrmOutStateModeError     - error at transformation mode
XfrmOutStateExpired       - state expired
XfrmOutPolBlock           - policy discards
XfrmOutPolError           - policy error
---
 include/linux/snmp.h   |   30 +++++++++++++++
 include/net/snmp.h     |    5 ++
 include/net/xfrm.h     |   17 ++++++++
 net/xfrm/Makefile      |    1 +
 net/xfrm/xfrm_policy.c |   35 +++++++++++++++++
 net/xfrm/xfrm_proc.c   |   96 ++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 184 insertions(+), 0 deletions(-)
include/linux/snmp.h +30 -0
index 89f0c2b..3fc89f4 100644
@@ -217,4 +217,34 @@ enum
 	__LINUX_MIB_MAX
 };
 
+/* xfrm mib definitions */
+enum
+{
+	XFRM_MIB_NUM = 0,
+	XFRM_MIB_INERROR,		/* XfrmInError */
+	XFRM_MIB_INBUFFERERROR,		/* XfrmInBufferError */
+	XFRM_MIB_INHDRERROR,		/* XfrmInHdrError */
+	XFRM_MIB_INNOSTATES,		/* XfrmInNoStates */
+	XFRM_MIB_INSTATEPROTOERROR,	/* XfrmInStateProtoError */
+	XFRM_MIB_INSTATEMODEERROR,	/* XfrmInStateModeError */
+	XFRM_MIB_INSEQOUTOFWINDOW,	/* XfrmInSeqOutOfWindow */
+	XFRM_MIB_INSTATEEXPIRED,	/* XfrmInStateExpired */
+	XFRM_MIB_INSTATEMISMATCH,	/* XfrmInStateMismatch */
+	XFRM_MIB_INSTATEINVALID,	/* XfrmInStateInvalid */
+	XFRM_MIB_INTMPLMISMATCH,	/* XfrmInTmplMismatch */
+	XFRM_MIB_INNOPOLS,		/* XfrmInNoPols */
+	XFRM_MIB_INPOLBLOCK,		/* XfrmInPolBlock */
+	XFRM_MIB_INPOLERROR,		/* XfrmInPolError */
+	XFRM_MIB_OUTERROR,		/* XfrmOutError */
+	XFRM_MIB_OUTLENGTHERROR,	/* XfrmOutLengthError */
+	XFRM_MIB_OUTBUNDLEERROR,	/* XfrmOutBundleError */
+	XFRM_MIB_OUTNOSTATES,		/* XfrmOutNoStates */
+	XFRM_MIB_OUTSTATEPROTOERROR,	/* XfrmOutStateProtoError */
+	XFRM_MIB_OUTSTATEMODEERROR,	/* XfrmOutStateModeError */
+	XFRM_MIB_OUTSTATEEXPIRED,	/* XfrmOutStateExpired */
+	XFRM_MIB_OUTPOLBLOCK,		/* XfrmOutPolBlock */
+	XFRM_MIB_OUTPOLERROR,		/* XfrmOutPolError */
+	__XFRM_MIB_MAX
+};
+
 #endif	/* _LINUX_SNMP_H */
include/net/snmp.h +5 -0
index ea206bf..37bcf19 100644
@@ -117,6 +117,11 @@ struct linux_mib {
 	unsigned long	mibs[LINUX_MIB_MAX];
 };
 
+/* Xfrm */
+#define XFRM_MIB_MAX	__XFRM_MIB_MAX
+struct xfrm_mib {
+	unsigned long	mibs[XFRM_MIB_MAX];
+};
 
 /* 
  * FIXME: On x86 and some other CPUs the split into user and softirq parts
include/net/xfrm.h +17 -0
index 688f6f5..679d915 100644
@@ -19,6 +19,9 @@
 #include <net/route.h>
 #include <net/ipv6.h>
 #include <net/ip6_fib.h>
+#ifdef CONFIG_XFRM_STATISTICS
+#include <net/snmp.h>
+#endif
 
 #define XFRM_PROTO_ESP		50
 #define XFRM_PROTO_AH		51
@@ -34,6 +37,17 @@
 #define MODULE_ALIAS_XFRM_TYPE(family, proto) \
 	MODULE_ALIAS("xfrm-type-" __stringify(family) "-" __stringify(proto))
 
+#ifdef CONFIG_XFRM_STATISTICS
+DECLARE_SNMP_STAT(struct xfrm_mib, xfrm_statistics);
+#define XFRM_INC_STATS(field)		SNMP_INC_STATS(xfrm_statistics, field)
+#define XFRM_INC_STATS_BH(field)	SNMP_INC_STATS_BH(xfrm_statistics, field)
+#define XFRM_INC_STATS_USER(field) 	SNMP_INC_STATS_USER(xfrm_statistics, field)
+#else
+#define XFRM_INC_STATS(field)
+#define XFRM_INC_STATS_BH(field)
+#define XFRM_INC_STATS_USER(field)
+#endif
+
 extern struct sock *xfrm_nl;
 extern u32 sysctl_xfrm_aevent_etime;
 extern u32 sysctl_xfrm_aevent_rseqth;
@@ -985,6 +999,9 @@ extern void xfrm_state_init(void);
 extern void xfrm4_state_init(void);
 extern void xfrm6_state_init(void);
 extern void xfrm6_state_fini(void);
+#ifdef CONFIG_XFRM_STATISTICS
+extern int xfrm_proc_init(void);
+#endif
 
 extern int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), void *);
 extern struct xfrm_state *xfrm_state_alloc(void);
net/xfrm/Makefile +1 -0
index 45744a3..332cfb0 100644
@@ -4,5 +4,6 @@
 
 obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \
 		      xfrm_input.o xfrm_output.o xfrm_algo.o
+obj-$(CONFIG_XFRM_STATISTICS) += xfrm_proc.o
 obj-$(CONFIG_XFRM_USER) += xfrm_user.o
 
net/xfrm/xfrm_policy.c +35 -0
index b702bd8..e770998 100644
@@ -25,11 +25,19 @@
 #include <linux/cache.h>
 #include <net/xfrm.h>
 #include <net/ip.h>
+#ifdef CONFIG_XFRM_STATISTICS
+#include <net/snmp.h>
+#endif
 
 #include "xfrm_hash.h"
 
 int sysctl_xfrm_larval_drop __read_mostly;
 
+#ifdef CONFIG_XFRM_STATISTICS
+DEFINE_SNMP_STAT(struct xfrm_mib, xfrm_statistics) __read_mostly;
+EXPORT_SYMBOL(xfrm_statistics);
+#endif
+
 DEFINE_MUTEX(xfrm_cfg_mutex);
 EXPORT_SYMBOL(xfrm_cfg_mutex);
 
@@ -2078,6 +2086,27 @@ static struct notifier_block xfrm_dev_notifier = {
 	0
 };
 
+#ifdef CONFIG_XFRM_STATISTICS
+static int __init xfrm_statistics_init(void)
+{
+	xfrm_statistics[0] = alloc_percpu(struct xfrm_mib);
+	if (!xfrm_statistics[0])
+		goto err0;
+
+	xfrm_statistics[1] = alloc_percpu(struct xfrm_mib);
+	if (!xfrm_statistics[1])
+		goto err1;
+
+	return 0;
+
+err1:
+	free_percpu(xfrm_statistics[0]);
+	xfrm_statistics[0] = NULL;
+err0:
+	return -ENOMEM;
+}
+#endif
+
 static void __init xfrm_policy_init(void)
 {
 	unsigned int hmask, sz;
@@ -2114,9 +2143,15 @@ static void __init xfrm_policy_init(void)
 
 void __init xfrm_init(void)
 {
+#ifdef CONFIG_XFRM_STATISTICS
+	xfrm_statistics_init();
+#endif
 	xfrm_state_init();
 	xfrm_policy_init();
 	xfrm_input_init();
+#ifdef CONFIG_XFRM_STATISTICS
+	xfrm_proc_init();
+#endif
 }
 
 #ifdef CONFIG_AUDITSYSCALL
net/xfrm/xfrm_proc.c new file +96 -0

96 lines not on this page · raw message

Signature · 1 line
1.4.4.2
#36 lore raw

RFC PATCH 2/3 : Support to increment packet processing statistics.

In reply to David Miller
---
 net/ipv4/xfrm4_input.c  |   48 +++++++++++++++++++++++++++---------
 net/ipv4/xfrm4_output.c |    4 ++-
 net/ipv6/xfrm6_input.c  |   56 ++++++++++++++++++++++++++++++++----------
 net/ipv6/xfrm6_output.c |    4 ++-
 net/xfrm/xfrm_output.c  |   19 +++++++++++---
 net/xfrm/xfrm_policy.c  |   61 +++++++++++++++++++++++++++++++++++++---------
 6 files changed, 148 insertions(+), 44 deletions(-)
net/ipv4/xfrm4_input.c +36 -12
index 5e95c8a..956e093 100644
@@ -45,36 +45,52 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 	unsigned int nhoff = offsetof(struct iphdr, protocol);
 
 	seq = 0;
-	if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0)
+	if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0) {
+		XFRM_INC_STATS(XFRM_MIB_INHDRERROR);
 		goto drop;
+	}
 
 	do {
 		const struct iphdr *iph = ip_hdr(skb);
 
-		if (xfrm_nr == XFRM_MAX_DEPTH)
+		if (xfrm_nr == XFRM_MAX_DEPTH) {
+			XFRM_INC_STATS(XFRM_MIB_INBUFFERERROR);
 			goto drop;
+		}
 
 		x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, spi,
 				      nexthdr, AF_INET);
-		if (x == NULL)
+		if (x == NULL) {
+			XFRM_INC_STATS(XFRM_MIB_INNOSTATES);
 			goto drop;
+		}
 
 		spin_lock(&x->lock);
-		if (unlikely(x->km.state != XFRM_STATE_VALID))
+		if (unlikely(x->km.state != XFRM_STATE_VALID)) {
+			XFRM_INC_STATS(XFRM_MIB_INSTATEINVALID);
 			goto drop_unlock;
+		}
 
-		if ((x->encap ? x->encap->encap_type : 0) != encap_type)
+		if ((x->encap ? x->encap->encap_type : 0) != encap_type) {
+			XFRM_INC_STATS(XFRM_MIB_INSTATEMISMATCH);
 			goto drop_unlock;
+		}
 
-		if (x->props.replay_window && xfrm_replay_check(x, seq))
+		if (x->props.replay_window && xfrm_replay_check(x, seq)) {
+			XFRM_INC_STATS(XFRM_MIB_INSEQOUTOFWINDOW);
 			goto drop_unlock;
+		}
 
-		if (xfrm_state_check_expire(x))
+		if (xfrm_state_check_expire(x)) {
+			XFRM_INC_STATS(XFRM_MIB_INSTATEEXPIRED);
 			goto drop_unlock;
+		}
 
 		nexthdr = x->type->input(x, skb);
-		if (nexthdr <= 0)
+		if (nexthdr <= 0) {
+			XFRM_INC_STATS(XFRM_MIB_INSTATEPROTOERROR);
 			goto drop_unlock;
+		}
 
 		skb_network_header(skb)[nhoff] = nexthdr;
 
@@ -91,8 +107,10 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 
 		xfrm_vec[xfrm_nr++] = x;
 
-		if (x->outer_mode->input(x, skb))
+		if (x->outer_mode->input(x, skb)) {
+			XFRM_INC_STATS(XFRM_MIB_INSTATEMODEERROR);
 			goto drop;
+		}
 
 		if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
@@ -100,8 +118,10 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 		}
 
 		err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
-		if (err < 0)
+		if (err < 0) {
+			XFRM_INC_STATS(XFRM_MIB_INHDRERROR);
 			goto drop;
+		}
 	} while (!err);
 
 	/* Allocate new secpath or COW existing one. */
@@ -109,14 +129,18 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 	if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) {
 		struct sec_path *sp;
 		sp = secpath_dup(skb->sp);
-		if (!sp)
+		if (!sp) {
+			XFRM_INC_STATS(XFRM_MIB_INERROR);
 			goto drop;
+		}
 		if (skb->sp)
 			secpath_put(skb->sp);
 		skb->sp = sp;
 	}
-	if (xfrm_nr + skb->sp->len > XFRM_MAX_DEPTH)
+	if (xfrm_nr + skb->sp->len > XFRM_MAX_DEPTH) {
+		XFRM_INC_STATS(XFRM_MIB_INBUFFERERROR);
 		goto drop;
+	}
 
 	memcpy(skb->sp->xvec + skb->sp->len, xfrm_vec,
 	       xfrm_nr * sizeof(xfrm_vec[0]));
net/ipv4/xfrm4_output.c +3 -1
index c4a7156..9d1d7b9 100644
@@ -49,8 +49,10 @@ static inline int xfrm4_output_one(struct sk_buff *skb)
 
 	if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 		err = xfrm4_tunnel_check_size(skb);
-		if (err)
+		if (err) {
+			XFRM_INC_STATS(XFRM_MIB_OUTLENGTHERROR);
 			goto error_nolock;
+		}
 	}
 
 	err = xfrm_output(skb);
net/ipv6/xfrm6_input.c +42 -14

127 lines not on this page · raw message

net/ipv6/xfrm6_output.c +3 -1
index 6569767..6dfc74d 100644
@@ -52,8 +52,10 @@ static inline int xfrm6_output_one(struct sk_buff *skb)
 
 	if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 		err = xfrm6_tunnel_check_size(skb);
-		if (err)
+		if (err) {
+			XFRM_INC_STATS(XFRM_MIB_OUTLENGTHERROR);
 			goto error_nolock;
+		}
 	}
 
 	err = xfrm_output(skb);
net/xfrm/xfrm_output.c +15 -4
index f4bfd6c..39e40ac 100644
@@ -32,9 +32,13 @@ static int xfrm_state_check_space(struct xfrm_state *x, struct sk_buff *skb)
 static int xfrm_state_check(struct xfrm_state *x, struct sk_buff *skb)
 {
 	int err = xfrm_state_check_expire(x);
-	if (err < 0)
+	if (err < 0) {
+		XFRM_INC_STATS(XFRM_MIB_OUTSTATEEXPIRED);
 		goto err;
+	}
 	err = xfrm_state_check_space(x, skb);
+	if (err)
+		XFRM_INC_STATS(XFRM_MIB_OUTLENGTHERROR);
 err:
 	return err;
 }
@@ -47,8 +51,10 @@ int xfrm_output(struct sk_buff *skb)
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
 		err = skb_checksum_help(skb);
-		if (err)
+		if (err) {
+			XFRM_INC_STATS(XFRM_MIB_OUTERROR);
 			goto error_nolock;
+		}
 	}
 
 	do {
@@ -64,8 +70,10 @@ int xfrm_output(struct sk_buff *skb)
 		}
 
 		err = x->outer_mode->output(x, skb);
-		if (err)
+		if (err) {
+			XFRM_INC_STATS(XFRM_MIB_OUTSTATEMODEERROR);
 			goto error;
+		}
 
 		x->curlft.bytes += skb->len;
 		x->curlft.packets++;
@@ -73,10 +81,13 @@ int xfrm_output(struct sk_buff *skb)
 		spin_unlock_bh(&x->lock);
 
 		err = x->type->output(x, skb);
-		if (err)
+		if (err) {
+			XFRM_INC_STATS(XFRM_MIB_OUTSTATEPROTOERROR);
 			goto error_nolock;
+		}
 
 		if (!(skb->dst = dst_pop(dst))) {
+			XFRM_INC_STATS(XFRM_MIB_OUTERROR);
 			err = -EHOSTUNREACH;
 			goto error_nolock;
 		}
net/xfrm/xfrm_policy.c +49 -12

197 lines not on this page · raw message

Signature · 1 line
1.4.4.2
#37 lore raw

RFC PATCH 3/3 : Add packet processing statistics option.

In reply to David Miller
---
 net/xfrm/Kconfig |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
net/xfrm/Kconfig +10 -0
index 577a4f8..6b5b50f 100644
@@ -35,6 +35,16 @@ config XFRM_MIGRATE
 
 	  If unsure, say N.
 
+config XFRM_STATISTICS
+	bool "Transformation statistics (EXPERIMENTAL)"
+	depends on XFRM && PROC_FS && EXPERIMENTAL
+	---help---
+	  This statistics is not a SNMP/MIB specification but shows
+	  statistics about transformation error (or almost error) factor
+	  at packet processing for developer.
+
+	  If unsure, say N.
+
 config NET_KEY
 	tristate "PF_KEY sockets"
 	select XFRM
Signature · 1 line
1.4.4.2
author maintainer
#38 lore raw

PATCH 11/11 : Rename mode to outer_mode and add inner_mode

In reply to Herbert Xu

[IPSEC]: Rename mode to outer_mode and add inner_mode

This patch adds a new field to xfrm states called inner_mode. The existing mode object is renamed to outer_mode.

This is the first part of an attempt to fix inter-family transforms. As it is we always use the outer family when determining which mode to use. As a result we may end up shoving IPv4 packets into netfilter6 and vice versa.

What we really want is to use the inner family for the first part of outbound processing and the outer family for the second part. For inbound processing we'd use the opposite pairing.

I've also added a check to prevent silly combinations such as transport mode with inter-family transforms.

---

 include/net/xfrm.h      |    3 ++-
 net/core/pktgen.c       |    2 +-
 net/ipv4/xfrm4_input.c  |    4 ++--
 net/ipv4/xfrm4_policy.c |    2 +-
 net/ipv6/xfrm6_input.c  |    4 ++--
 net/ipv6/xfrm6_policy.c |    2 +-
 net/xfrm/xfrm_output.c  |    4 ++--
 net/xfrm/xfrm_policy.c  |    2 +-
 net/xfrm/xfrm_state.c   |   18 ++++++++++++++----
 9 files changed, 26 insertions(+), 15 deletions(-)
include/net/xfrm.h +2 -1
index f0f3318..688f6f5 100644
@@ -186,7 +186,8 @@ struct xfrm_state
 	/* Reference to data common to all the instances of this
 	 * transformer. */
 	struct xfrm_type	*type;
-	struct xfrm_mode	*mode;
+	struct xfrm_mode	*inner_mode;
+	struct xfrm_mode	*outer_mode;
 
 	/* Security context */
 	struct xfrm_sec_ctx	*security;
net/core/pktgen.c +1 -1
index 2100c73..8cae60c 100644
@@ -2454,7 +2454,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
 	spin_lock(&x->lock);
 	iph = ip_hdr(skb);
 
-	err = x->mode->output(x, skb);
+	err = x->outer_mode->output(x, skb);
 	if (err)
 		goto error;
 	err = x->type->output(x, skb);
net/ipv4/xfrm4_input.c +2 -2
index bc5dc07..5e95c8a 100644
@@ -91,10 +91,10 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 
 		xfrm_vec[xfrm_nr++] = x;
 
-		if (x->mode->input(x, skb))
+		if (x->outer_mode->input(x, skb))
 			goto drop;
 
-		if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
+		if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
 		}
net/ipv4/xfrm4_policy.c +1 -1
index 1f0ea0e..cc86fb1 100644
@@ -168,7 +168,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		/* Copy neighbout for reachability confirmation */
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
-		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
+		dst_prev->output = dst_prev->xfrm->outer_mode->afinfo->output;
 		if (rt0->peer)
 			atomic_inc(&rt0->peer->refcnt);
 		x->u.rt.peer = rt0->peer;
net/ipv6/xfrm6_input.c +2 -2
index c6ee1a3..5157837 100644
@@ -68,10 +68,10 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 
 		xfrm_vec[xfrm_nr++] = x;
 
-		if (x->mode->input(x, skb))
+		if (x->outer_mode->input(x, skb))
 			goto drop;
 
-		if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
+		if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
 		}
net/ipv6/xfrm6_policy.c +1 -1
index 3242683..82e27b8 100644
@@ -230,7 +230,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		/* Copy neighbour for reachability confirmation */
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
-		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
+		dst_prev->output = dst_prev->xfrm->outer_mode->afinfo->output;
 		/* Sheit... I remember I did this right. Apparently,
 		 * it was magically lost, so this code needs audit */
 		x->u.rt6.rt6i_flags    = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
net/xfrm/xfrm_output.c +2 -2
index 8bf71ba..f4bfd6c 100644
@@ -63,7 +63,7 @@ int xfrm_output(struct sk_buff *skb)
 				xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
 		}
 
-		err = x->mode->output(x, skb);
+		err = x->outer_mode->output(x, skb);
 		if (err)
 			goto error;
 
@@ -82,7 +82,7 @@ int xfrm_output(struct sk_buff *skb)
 		}
 		dst = skb->dst;
 		x = dst->xfrm;
-	} while (x && !(x->mode->flags & XFRM_MODE_FLAG_TUNNEL));
+	} while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL));
 
 	err = 0;
 
net/xfrm/xfrm_policy.c +1 -1
index 1d66fb4..b702bd8 100644
@@ -1941,7 +1941,7 @@ int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first,
 			return 0;
 
 		if (strict && fl &&
-		    !(dst->xfrm->mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
+		    !(dst->xfrm->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
 		    !xfrm_state_addr_flow_check(dst->xfrm, fl, family))
 			return 0;
 
net/xfrm/xfrm_state.c +14 -4
index 48b4a06..224b44e 100644
@@ -377,8 +377,10 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x)
 	kfree(x->calg);
 	kfree(x->encap);
 	kfree(x->coaddr);
-	if (x->mode)
-		xfrm_put_mode(x->mode);
+	if (x->inner_mode)
+		xfrm_put_mode(x->inner_mode);
+	if (x->outer_mode)
+		xfrm_put_mode(x->outer_mode);
 	if (x->type) {
 		x->type->destructor(x);
 		xfrm_put_type(x->type);
@@ -1947,6 +1949,14 @@ int xfrm_init_state(struct xfrm_state *x)
 		goto error;
 
 	err = -EPROTONOSUPPORT;
+	x->inner_mode = xfrm_get_mode(x->props.mode, x->sel.family);
+	if (x->inner_mode == NULL)
+		goto error;
+
+	if (!(x->inner_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
+	    family != x->sel.family)
+		goto error;
+
 	x->type = xfrm_get_type(x->id.proto, family);
 	if (x->type == NULL)
 		goto error;
@@ -1955,8 +1965,8 @@ int xfrm_init_state(struct xfrm_state *x)
 	if (err)
 		goto error;
 
-	x->mode = xfrm_get_mode(x->props.mode, family);
-	if (x->mode == NULL)
+	x->outer_mode = xfrm_get_mode(x->props.mode, family);
+	if (x->outer_mode == NULL)
 		goto error;
 
 	x->km.state = XFRM_STATE_VALID;
author maintainer
#39 lore raw

Re: [PATCH 11/11] [IPSEC]: Rename mode to outer_mode and add inner_mode

Quoted 1 line · Herbert Xu

[IPSEC]: Rename mode to outer_mode and add inner_mode

Oops. This patch is missing two files. Here is the correct version.

Cheers,

Signature · 36 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
[IPSEC]: Rename mode to outer_mode and add inner_mode

This patch adds a new field to xfrm states called inner_mode.  The existing
mode object is renamed to outer_mode.

This is the first part of an attempt to fix inter-family transforms.  As it
is we always use the outer family when determining which mode to use.  As a
result we may end up shoving IPv4 packets into netfilter6 and vice versa.

What we really want is to use the inner family for the first part of outbound
processing and the outer family for the second part.  For inbound processing
we'd use the opposite pairing.

I've also added a check to prevent silly combinations such as transport mode
with inter-family transforms.

Signed-off-by: Herbert Xu <[email protected]>
---

 include/net/xfrm.h      |    3 ++-
 net/core/pktgen.c       |    2 +-
 net/ipv4/xfrm4_input.c  |    4 ++--
 net/ipv4/xfrm4_output.c |    2 +-
 net/ipv4/xfrm4_policy.c |    2 +-
 net/ipv6/xfrm6_input.c  |    4 ++--
 net/ipv6/xfrm6_output.c |    2 +-
 net/ipv6/xfrm6_policy.c |    2 +-
 net/xfrm/xfrm_output.c  |    4 ++--
 net/xfrm/xfrm_policy.c  |    2 +-
 net/xfrm/xfrm_state.c   |   18 ++++++++++++++----
 11 files changed, 28 insertions(+), 17 deletions(-)
include/net/xfrm.h +2 -1
index f0f3318..688f6f5 100644
@@ -186,7 +186,8 @@ struct xfrm_state
 	/* Reference to data common to all the instances of this
 	 * transformer. */
 	struct xfrm_type	*type;
-	struct xfrm_mode	*mode;
+	struct xfrm_mode	*inner_mode;
+	struct xfrm_mode	*outer_mode;
 
 	/* Security context */
 	struct xfrm_sec_ctx	*security;
net/core/pktgen.c +1 -1
index 2100c73..8cae60c 100644
@@ -2454,7 +2454,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
 	spin_lock(&x->lock);
 	iph = ip_hdr(skb);
 
-	err = x->mode->output(x, skb);
+	err = x->outer_mode->output(x, skb);
 	if (err)
 		goto error;
 	err = x->type->output(x, skb);
net/ipv4/xfrm4_input.c +2 -2
index bc5dc07..5e95c8a 100644
@@ -91,10 +91,10 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 
 		xfrm_vec[xfrm_nr++] = x;
 
-		if (x->mode->input(x, skb))
+		if (x->outer_mode->input(x, skb))
 			goto drop;
 
-		if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
+		if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
 		}
net/ipv4/xfrm4_output.c +1 -1
index dcbc274..c4a7156 100644
@@ -47,7 +47,7 @@ static inline int xfrm4_output_one(struct sk_buff *skb)
 	struct iphdr *iph;
 	int err;
 
-	if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
+	if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 		err = xfrm4_tunnel_check_size(skb);
 		if (err)
 			goto error_nolock;
net/ipv4/xfrm4_policy.c +1 -1
index 1f0ea0e..cc86fb1 100644
@@ -168,7 +168,7 @@ __xfrm4_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		/* Copy neighbout for reachability confirmation */
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
-		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
+		dst_prev->output = dst_prev->xfrm->outer_mode->afinfo->output;
 		if (rt0->peer)
 			atomic_inc(&rt0->peer->refcnt);
 		x->u.rt.peer = rt0->peer;
net/ipv6/xfrm6_input.c +2 -2
index c6ee1a3..5157837 100644
@@ -68,10 +68,10 @@ int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 
 		xfrm_vec[xfrm_nr++] = x;
 
-		if (x->mode->input(x, skb))
+		if (x->outer_mode->input(x, skb))
 			goto drop;
 
-		if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
+		if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 			decaps = 1;
 			break;
 		}
net/ipv6/xfrm6_output.c +1 -1
index c9f42d1..6569767 100644
@@ -50,7 +50,7 @@ static inline int xfrm6_output_one(struct sk_buff *skb)
 	struct ipv6hdr *iph;
 	int err;
 
-	if (x->mode->flags & XFRM_MODE_FLAG_TUNNEL) {
+	if (x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) {
 		err = xfrm6_tunnel_check_size(skb);
 		if (err)
 			goto error_nolock;
net/ipv6/xfrm6_policy.c +1 -1
index 3242683..82e27b8 100644
@@ -230,7 +230,7 @@ __xfrm6_bundle_create(struct xfrm_policy *policy, struct xfrm_state **xfrm, int
 		/* Copy neighbour for reachability confirmation */
 		dst_prev->neighbour	= neigh_clone(rt->u.dst.neighbour);
 		dst_prev->input		= rt->u.dst.input;
-		dst_prev->output = dst_prev->xfrm->mode->afinfo->output;
+		dst_prev->output = dst_prev->xfrm->outer_mode->afinfo->output;
 		/* Sheit... I remember I did this right. Apparently,
 		 * it was magically lost, so this code needs audit */
 		x->u.rt6.rt6i_flags    = rt0->rt6i_flags&(RTCF_BROADCAST|RTCF_MULTICAST|RTCF_LOCAL);
net/xfrm/xfrm_output.c +2 -2
index 8bf71ba..f4bfd6c 100644
@@ -63,7 +63,7 @@ int xfrm_output(struct sk_buff *skb)
 				xfrm_replay_notify(x, XFRM_REPLAY_UPDATE);
 		}
 
-		err = x->mode->output(x, skb);
+		err = x->outer_mode->output(x, skb);
 		if (err)
 			goto error;
 
@@ -82,7 +82,7 @@ int xfrm_output(struct sk_buff *skb)
 		}
 		dst = skb->dst;
 		x = dst->xfrm;
-	} while (x && !(x->mode->flags & XFRM_MODE_FLAG_TUNNEL));
+	} while (x && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL));
 
 	err = 0;
 
net/xfrm/xfrm_policy.c +1 -1
index 1d66fb4..b702bd8 100644
@@ -1941,7 +1941,7 @@ int xfrm_bundle_ok(struct xfrm_policy *pol, struct xfrm_dst *first,
 			return 0;
 
 		if (strict && fl &&
-		    !(dst->xfrm->mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
+		    !(dst->xfrm->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
 		    !xfrm_state_addr_flow_check(dst->xfrm, fl, family))
 			return 0;
 
net/xfrm/xfrm_state.c +14 -4
index 48b4a06..224b44e 100644
@@ -377,8 +377,10 @@ static void xfrm_state_gc_destroy(struct xfrm_state *x)
 	kfree(x->calg);
 	kfree(x->encap);
 	kfree(x->coaddr);
-	if (x->mode)
-		xfrm_put_mode(x->mode);
+	if (x->inner_mode)
+		xfrm_put_mode(x->inner_mode);
+	if (x->outer_mode)
+		xfrm_put_mode(x->outer_mode);
 	if (x->type) {
 		x->type->destructor(x);
 		xfrm_put_type(x->type);
@@ -1947,6 +1949,14 @@ int xfrm_init_state(struct xfrm_state *x)
 		goto error;
 
 	err = -EPROTONOSUPPORT;
+	x->inner_mode = xfrm_get_mode(x->props.mode, x->sel.family);
+	if (x->inner_mode == NULL)
+		goto error;
+
+	if (!(x->inner_mode->flags & XFRM_MODE_FLAG_TUNNEL) &&
+	    family != x->sel.family)
+		goto error;
+
 	x->type = xfrm_get_type(x->id.proto, family);
 	if (x->type == NULL)
 		goto error;
@@ -1955,8 +1965,8 @@ int xfrm_init_state(struct xfrm_state *x)
 	if (err)
 		goto error;
 
-	x->mode = xfrm_get_mode(x->props.mode, family);
-	if (x->mode == NULL)
+	x->outer_mode = xfrm_get_mode(x->props.mode, family);
+	if (x->outer_mode == NULL)
 		goto error;
 
 	x->km.state = XFRM_STATE_VALID;
maintainer Applied
#40 lore raw

Re: [PATCH 11/11] [IPSEC]: Rename mode to outer_mode and add inner_mode

From: Herbert Xu <[email protected]>
Date: Wed, 17 Oct 2007 23:26:02 +0800

Quoted 30 lines · Herbert Xu
Quoted 1 line

[IPSEC]: Rename mode to outer_mode and add inner_mode

Oops. This patch is missing two files. Here is the correct version.

Cheers,

Signature · 22 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
[IPSEC]: Rename mode to outer_mode and add inner_mode

This patch adds a new field to xfrm states called inner_mode.  The existing
mode object is renamed to outer_mode.

This is the first part of an attempt to fix inter-family transforms.  As it
is we always use the outer family when determining which mode to use.  As a
result we may end up shoving IPv4 packets into netfilter6 and vice versa.

What we really want is to use the inner family for the first part of outbound
processing and the outer family for the second part.  For inbound processing
we'd use the opposite pairing.

I've also added a check to prevent silly combinations such as transport mode
with inter-family transforms.

Signed-off-by: Herbert Xu <[email protected]>

Applied, thanks Herbert.