Browse Source

[IPSEC]: Use the correct family for input state lookup

When merging the input paths of IPsec I accidentally left a hard-coded
AF_INET for the state lookup call.  This broke IPv6 obviously.  This
patch fixes by getting the input callers to specify the family through
skb->cb.

Credit goes to Kazunori Miyazawa for diagnosing this and providing an
initial patch.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Herbert Xu 17 years ago
parent
commit
2fcb45b6b8
4 changed files with 7 additions and 1 deletions
  1. 1 0
      include/net/xfrm.h
  2. 1 0
      net/ipv4/xfrm4_input.c
  3. 1 0
      net/ipv6/xfrm6_input.c
  4. 4 1
      net/xfrm/xfrm_input.c

+ 1 - 0
include/net/xfrm.h

@@ -534,6 +534,7 @@ struct xfrm_spi_skb_cb {
 	} header;
 	} header;
 
 
 	unsigned int daddroff;
 	unsigned int daddroff;
+	unsigned int family;
 };
 };
 
 
 #define XFRM_SPI_SKB_CB(__skb) ((struct xfrm_spi_skb_cb *)&((__skb)->cb[0]))
 #define XFRM_SPI_SKB_CB(__skb) ((struct xfrm_spi_skb_cb *)&((__skb)->cb[0]))

+ 1 - 0
net/ipv4/xfrm4_input.c

@@ -39,6 +39,7 @@ drop:
 int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
 		    int encap_type)
 		    int encap_type)
 {
 {
+	XFRM_SPI_SKB_CB(skb)->family = AF_INET;
 	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
 	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
 	return xfrm_input(skb, nexthdr, spi, encap_type);
 	return xfrm_input(skb, nexthdr, spi, encap_type);
 }
 }

+ 1 - 0
net/ipv6/xfrm6_input.c

@@ -23,6 +23,7 @@ int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb)
 
 
 int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
 {
 {
+	XFRM_SPI_SKB_CB(skb)->family = AF_INET6;
 	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct ipv6hdr, daddr);
 	XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct ipv6hdr, daddr);
 	return xfrm_input(skb, nexthdr, spi, 0);
 	return xfrm_input(skb, nexthdr, spi, 0);
 }
 }

+ 4 - 1
net/xfrm/xfrm_input.c

@@ -102,6 +102,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 	__be32 seq;
 	__be32 seq;
 	struct xfrm_state *x;
 	struct xfrm_state *x;
 	xfrm_address_t *daddr;
 	xfrm_address_t *daddr;
+	unsigned int family;
 	int decaps = 0;
 	int decaps = 0;
 	int async = 0;
 	int async = 0;
 
 
@@ -127,6 +128,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 
 	daddr = (xfrm_address_t *)(skb_network_header(skb) +
 	daddr = (xfrm_address_t *)(skb_network_header(skb) +
 				   XFRM_SPI_SKB_CB(skb)->daddroff);
 				   XFRM_SPI_SKB_CB(skb)->daddroff);
+	family = XFRM_SPI_SKB_CB(skb)->family;
 
 
 	seq = 0;
 	seq = 0;
 	if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0)
 	if (!spi && (err = xfrm_parse_spi(skb, nexthdr, &spi, &seq)) != 0)
@@ -136,7 +138,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 		if (skb->sp->len == XFRM_MAX_DEPTH)
 		if (skb->sp->len == XFRM_MAX_DEPTH)
 			goto drop;
 			goto drop;
 
 
-		x = xfrm_state_lookup(daddr, spi, nexthdr, AF_INET);
+		x = xfrm_state_lookup(daddr, spi, nexthdr, family);
 		if (x == NULL)
 		if (x == NULL)
 			goto drop;
 			goto drop;
 
 
@@ -198,6 +200,7 @@ resume:
 		 * transport mode so the outer address is identical.
 		 * transport mode so the outer address is identical.
 		 */
 		 */
 		daddr = &x->id.daddr;
 		daddr = &x->id.daddr;
+		family = x->outer_mode->afinfo->family;
 
 
 		err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
 		err = xfrm_parse_spi(skb, nexthdr, &spi, &seq);
 		if (err < 0)
 		if (err < 0)