diff options
| -rw-r--r-- | include/linux/in.h | 1 | ||||
| -rw-r--r-- | include/linux/ip.h | 9 | ||||
| -rw-r--r-- | include/linux/ipsec.h | 3 | ||||
| -rw-r--r-- | include/linux/xfrm.h | 3 | ||||
| -rw-r--r-- | net/ipv4/Kconfig | 9 | ||||
| -rw-r--r-- | net/ipv4/Makefile | 1 | ||||
| -rw-r--r-- | net/ipv4/esp4.c | 26 | ||||
| -rw-r--r-- | net/ipv4/ipcomp.c | 5 | ||||
| -rw-r--r-- | net/ipv4/xfrm4_mode_beet.c | 139 | ||||
| -rw-r--r-- | net/ipv6/Kconfig | 10 | ||||
| -rw-r--r-- | net/ipv6/Makefile | 1 | ||||
| -rw-r--r-- | net/ipv6/ipcomp6.c | 5 | ||||
| -rw-r--r-- | net/ipv6/xfrm6_mode_beet.c | 107 | ||||
| -rw-r--r-- | net/xfrm/xfrm_user.c | 1 |
14 files changed, 309 insertions, 11 deletions
diff --git a/include/linux/in.h b/include/linux/in.h index d79fc75fa7c2..2619859f6e1b 100644 --- a/include/linux/in.h +++ b/include/linux/in.h | |||
| @@ -40,6 +40,7 @@ enum { | |||
| 40 | 40 | ||
| 41 | IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */ | 41 | IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */ |
| 42 | IPPROTO_AH = 51, /* Authentication Header protocol */ | 42 | IPPROTO_AH = 51, /* Authentication Header protocol */ |
| 43 | IPPROTO_BEETPH = 94, /* IP option pseudo header for BEET */ | ||
| 43 | IPPROTO_PIM = 103, /* Protocol Independent Multicast */ | 44 | IPPROTO_PIM = 103, /* Protocol Independent Multicast */ |
| 44 | 45 | ||
| 45 | IPPROTO_COMP = 108, /* Compression Header protocol */ | 46 | IPPROTO_COMP = 108, /* Compression Header protocol */ |
diff --git a/include/linux/ip.h b/include/linux/ip.h index 6b25d36fc54c..ecee9bb27d0e 100644 --- a/include/linux/ip.h +++ b/include/linux/ip.h | |||
| @@ -80,6 +80,8 @@ | |||
| 80 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ | 80 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ |
| 81 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ | 81 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ |
| 82 | 82 | ||
| 83 | #define IPV4_BEET_PHMAXLEN 8 | ||
| 84 | |||
| 83 | struct iphdr { | 85 | struct iphdr { |
| 84 | #if defined(__LITTLE_ENDIAN_BITFIELD) | 86 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
| 85 | __u8 ihl:4, | 87 | __u8 ihl:4, |
| @@ -123,4 +125,11 @@ struct ip_comp_hdr { | |||
| 123 | __be16 cpi; | 125 | __be16 cpi; |
| 124 | }; | 126 | }; |
| 125 | 127 | ||
| 128 | struct ip_beet_phdr { | ||
| 129 | __u8 nexthdr; | ||
| 130 | __u8 hdrlen; | ||
| 131 | __u8 padlen; | ||
| 132 | __u8 reserved; | ||
| 133 | }; | ||
| 134 | |||
| 126 | #endif /* _LINUX_IP_H */ | 135 | #endif /* _LINUX_IP_H */ |
diff --git a/include/linux/ipsec.h b/include/linux/ipsec.h index d3c527616b5e..d17a6302a0e9 100644 --- a/include/linux/ipsec.h +++ b/include/linux/ipsec.h | |||
| @@ -12,7 +12,8 @@ | |||
| 12 | enum { | 12 | enum { |
| 13 | IPSEC_MODE_ANY = 0, /* We do not support this for SA */ | 13 | IPSEC_MODE_ANY = 0, /* We do not support this for SA */ |
| 14 | IPSEC_MODE_TRANSPORT = 1, | 14 | IPSEC_MODE_TRANSPORT = 1, |
| 15 | IPSEC_MODE_TUNNEL = 2 | 15 | IPSEC_MODE_TUNNEL = 2, |
| 16 | IPSEC_MODE_BEET = 3 | ||
| 16 | }; | 17 | }; |
| 17 | 18 | ||
| 18 | enum { | 19 | enum { |
diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h index 430afd058269..8ae7f744917b 100644 --- a/include/linux/xfrm.h +++ b/include/linux/xfrm.h | |||
| @@ -129,7 +129,8 @@ enum | |||
| 129 | #define XFRM_MODE_TUNNEL 1 | 129 | #define XFRM_MODE_TUNNEL 1 |
| 130 | #define XFRM_MODE_ROUTEOPTIMIZATION 2 | 130 | #define XFRM_MODE_ROUTEOPTIMIZATION 2 |
| 131 | #define XFRM_MODE_IN_TRIGGER 3 | 131 | #define XFRM_MODE_IN_TRIGGER 3 |
| 132 | #define XFRM_MODE_MAX 4 | 132 | #define XFRM_MODE_BEET 4 |
| 133 | #define XFRM_MODE_MAX 5 | ||
| 133 | 134 | ||
| 134 | /* Netlink configuration messages. */ | 135 | /* Netlink configuration messages. */ |
| 135 | enum { | 136 | enum { |
diff --git a/net/ipv4/Kconfig b/net/ipv4/Kconfig index d172a9804448..5572071af735 100644 --- a/net/ipv4/Kconfig +++ b/net/ipv4/Kconfig | |||
| @@ -434,6 +434,15 @@ config INET_XFRM_MODE_TUNNEL | |||
| 434 | 434 | ||
| 435 | If unsure, say Y. | 435 | If unsure, say Y. |
| 436 | 436 | ||
| 437 | config INET_XFRM_MODE_BEET | ||
| 438 | tristate "IP: IPsec BEET mode" | ||
| 439 | default y | ||
| 440 | select XFRM | ||
| 441 | ---help--- | ||
| 442 | Support for IPsec BEET mode. | ||
| 443 | |||
| 444 | If unsure, say Y. | ||
| 445 | |||
| 437 | config INET_DIAG | 446 | config INET_DIAG |
| 438 | tristate "INET: socket monitoring interface" | 447 | tristate "INET: socket monitoring interface" |
| 439 | default y | 448 | default y |
diff --git a/net/ipv4/Makefile b/net/ipv4/Makefile index f66049e28aeb..15645c51520c 100644 --- a/net/ipv4/Makefile +++ b/net/ipv4/Makefile | |||
| @@ -23,6 +23,7 @@ obj-$(CONFIG_INET_AH) += ah4.o | |||
| 23 | obj-$(CONFIG_INET_ESP) += esp4.o | 23 | obj-$(CONFIG_INET_ESP) += esp4.o |
| 24 | obj-$(CONFIG_INET_IPCOMP) += ipcomp.o | 24 | obj-$(CONFIG_INET_IPCOMP) += ipcomp.o |
| 25 | obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o | 25 | obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o |
| 26 | obj-$(CONFIG_INET_XFRM_MODE_BEET) += xfrm4_mode_beet.o | ||
| 26 | obj-$(CONFIG_INET_TUNNEL) += tunnel4.o | 27 | obj-$(CONFIG_INET_TUNNEL) += tunnel4.o |
| 27 | obj-$(CONFIG_INET_XFRM_MODE_TRANSPORT) += xfrm4_mode_transport.o | 28 | obj-$(CONFIG_INET_XFRM_MODE_TRANSPORT) += xfrm4_mode_transport.o |
| 28 | obj-$(CONFIG_INET_XFRM_MODE_TUNNEL) += xfrm4_mode_tunnel.o | 29 | obj-$(CONFIG_INET_XFRM_MODE_TUNNEL) += xfrm4_mode_tunnel.o |
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 13b29360d102..b5c205b57669 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c | |||
| @@ -253,7 +253,8 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb) | |||
| 253 | * as per draft-ietf-ipsec-udp-encaps-06, | 253 | * as per draft-ietf-ipsec-udp-encaps-06, |
| 254 | * section 3.1.2 | 254 | * section 3.1.2 |
| 255 | */ | 255 | */ |
| 256 | if (x->props.mode == XFRM_MODE_TRANSPORT) | 256 | if (x->props.mode == XFRM_MODE_TRANSPORT || |
| 257 | x->props.mode == XFRM_MODE_BEET) | ||
| 257 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 258 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 258 | } | 259 | } |
| 259 | 260 | ||
| @@ -271,17 +272,28 @@ static u32 esp4_get_max_size(struct xfrm_state *x, int mtu) | |||
| 271 | { | 272 | { |
| 272 | struct esp_data *esp = x->data; | 273 | struct esp_data *esp = x->data; |
| 273 | u32 blksize = ALIGN(crypto_blkcipher_blocksize(esp->conf.tfm), 4); | 274 | u32 blksize = ALIGN(crypto_blkcipher_blocksize(esp->conf.tfm), 4); |
| 274 | 275 | int enclen = 0; | |
| 275 | if (x->props.mode == XFRM_MODE_TUNNEL) { | 276 | |
| 276 | mtu = ALIGN(mtu + 2, blksize); | 277 | switch (x->props.mode) { |
| 277 | } else { | 278 | case XFRM_MODE_TUNNEL: |
| 278 | /* The worst case. */ | 279 | mtu = ALIGN(mtu +2, blksize); |
| 280 | break; | ||
| 281 | default: | ||
| 282 | case XFRM_MODE_TRANSPORT: | ||
| 283 | /* The worst case */ | ||
| 279 | mtu = ALIGN(mtu + 2, 4) + blksize - 4; | 284 | mtu = ALIGN(mtu + 2, 4) + blksize - 4; |
| 285 | break; | ||
| 286 | case XFRM_MODE_BEET: | ||
| 287 | /* The worst case. */ | ||
| 288 | enclen = IPV4_BEET_PHMAXLEN; | ||
| 289 | mtu = ALIGN(mtu + enclen + 2, blksize); | ||
| 290 | break; | ||
| 280 | } | 291 | } |
| 292 | |||
| 281 | if (esp->conf.padlen) | 293 | if (esp->conf.padlen) |
| 282 | mtu = ALIGN(mtu, esp->conf.padlen); | 294 | mtu = ALIGN(mtu, esp->conf.padlen); |
| 283 | 295 | ||
| 284 | return mtu + x->props.header_len + esp->auth.icv_trunc_len; | 296 | return mtu + x->props.header_len + esp->auth.icv_trunc_len - enclen; |
| 285 | } | 297 | } |
| 286 | 298 | ||
| 287 | static void esp4_err(struct sk_buff *skb, u32 info) | 299 | static void esp4_err(struct sk_buff *skb, u32 info) |
diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c index 2017d36024d4..3839b706142e 100644 --- a/net/ipv4/ipcomp.c +++ b/net/ipv4/ipcomp.c | |||
| @@ -206,6 +206,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info) | |||
| 206 | static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) | 206 | static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) |
| 207 | { | 207 | { |
| 208 | struct xfrm_state *t; | 208 | struct xfrm_state *t; |
| 209 | u8 mode = XFRM_MODE_TUNNEL; | ||
| 209 | 210 | ||
| 210 | t = xfrm_state_alloc(); | 211 | t = xfrm_state_alloc(); |
| 211 | if (t == NULL) | 212 | if (t == NULL) |
| @@ -216,7 +217,9 @@ static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x) | |||
| 216 | t->id.daddr.a4 = x->id.daddr.a4; | 217 | t->id.daddr.a4 = x->id.daddr.a4; |
| 217 | memcpy(&t->sel, &x->sel, sizeof(t->sel)); | 218 | memcpy(&t->sel, &x->sel, sizeof(t->sel)); |
| 218 | t->props.family = AF_INET; | 219 | t->props.family = AF_INET; |
| 219 | t->props.mode = XFRM_MODE_TUNNEL; | 220 | if (x->props.mode == XFRM_MODE_BEET) |
| 221 | mode = x->props.mode; | ||
| 222 | t->props.mode = mode; | ||
| 220 | t->props.saddr.a4 = x->props.saddr.a4; | 223 | t->props.saddr.a4 = x->props.saddr.a4; |
| 221 | t->props.flags = x->props.flags; | 224 | t->props.flags = x->props.flags; |
| 222 | 225 | ||
diff --git a/net/ipv4/xfrm4_mode_beet.c b/net/ipv4/xfrm4_mode_beet.c new file mode 100644 index 000000000000..89cf59ea7bbe --- /dev/null +++ b/net/ipv4/xfrm4_mode_beet.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* | ||
| 2 | * xfrm4_mode_beet.c - BEET mode encapsulation for IPv4. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com> | ||
| 5 | * Miika Komu <miika@iki.fi> | ||
| 6 | * Herbert Xu <herbert@gondor.apana.org.au> | ||
| 7 | * Abhinav Pathak <abhinav.pathak@hiit.fi> | ||
| 8 | * Jeff Ahrenholz <ahrenholz@gmail.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/init.h> | ||
| 12 | #include <linux/kernel.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/skbuff.h> | ||
| 15 | #include <linux/stringify.h> | ||
| 16 | #include <net/dst.h> | ||
| 17 | #include <net/ip.h> | ||
| 18 | #include <net/xfrm.h> | ||
| 19 | |||
| 20 | /* Add encapsulation header. | ||
| 21 | * | ||
| 22 | * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt. | ||
| 23 | * The following fields in it shall be filled in by x->type->output: | ||
| 24 | * tot_len | ||
| 25 | * check | ||
| 26 | * | ||
| 27 | * On exit, skb->h will be set to the start of the payload to be processed | ||
| 28 | * by x->type->output and skb->nh will be set to the top IP header. | ||
| 29 | */ | ||
| 30 | static int xfrm4_beet_output(struct xfrm_state *x, struct sk_buff *skb) | ||
| 31 | { | ||
| 32 | struct iphdr *iph, *top_iph = NULL; | ||
| 33 | int hdrlen, optlen; | ||
| 34 | |||
| 35 | iph = skb->nh.iph; | ||
| 36 | skb->h.ipiph = iph; | ||
| 37 | |||
| 38 | hdrlen = 0; | ||
| 39 | optlen = iph->ihl * 4 - sizeof(*iph); | ||
| 40 | if (unlikely(optlen)) | ||
| 41 | hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4); | ||
| 42 | |||
| 43 | skb->nh.raw = skb_push(skb, x->props.header_len + hdrlen); | ||
| 44 | top_iph = skb->nh.iph; | ||
| 45 | hdrlen = iph->ihl * 4 - optlen; | ||
| 46 | skb->h.raw += hdrlen; | ||
| 47 | |||
| 48 | memmove(top_iph, iph, hdrlen); | ||
| 49 | if (unlikely(optlen)) { | ||
| 50 | struct ip_beet_phdr *ph; | ||
| 51 | |||
| 52 | BUG_ON(optlen < 0); | ||
| 53 | |||
| 54 | ph = (struct ip_beet_phdr *)skb->h.raw; | ||
| 55 | ph->padlen = 4 - (optlen & 4); | ||
| 56 | ph->hdrlen = (optlen + ph->padlen + sizeof(*ph)) / 8; | ||
| 57 | ph->nexthdr = top_iph->protocol; | ||
| 58 | |||
| 59 | top_iph->protocol = IPPROTO_BEETPH; | ||
| 60 | top_iph->ihl = sizeof(struct iphdr) / 4; | ||
| 61 | } | ||
| 62 | |||
| 63 | top_iph->saddr = x->props.saddr.a4; | ||
| 64 | top_iph->daddr = x->id.daddr.a4; | ||
| 65 | |||
| 66 | return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | static int xfrm4_beet_input(struct xfrm_state *x, struct sk_buff *skb) | ||
| 70 | { | ||
| 71 | struct iphdr *iph = skb->nh.iph; | ||
| 72 | int phlen = 0; | ||
| 73 | int optlen = 0; | ||
| 74 | __u8 ph_nexthdr = 0, protocol = 0; | ||
| 75 | int err = -EINVAL; | ||
| 76 | |||
| 77 | protocol = iph->protocol; | ||
| 78 | |||
| 79 | if (unlikely(iph->protocol == IPPROTO_BEETPH)) { | ||
| 80 | struct ip_beet_phdr *ph = (struct ip_beet_phdr*)(iph + 1); | ||
| 81 | |||
| 82 | if (!pskb_may_pull(skb, sizeof(*ph))) | ||
| 83 | goto out; | ||
| 84 | |||
| 85 | phlen = ph->hdrlen * 8; | ||
| 86 | optlen = phlen - ph->padlen - sizeof(*ph); | ||
| 87 | if (optlen < 0 || optlen & 3 || optlen > 250) | ||
| 88 | goto out; | ||
| 89 | |||
| 90 | if (!pskb_may_pull(skb, phlen)) | ||
| 91 | goto out; | ||
| 92 | |||
| 93 | ph_nexthdr = ph->nexthdr; | ||
| 94 | } | ||
| 95 | |||
| 96 | skb_push(skb, sizeof(*iph) - phlen + optlen); | ||
| 97 | memmove(skb->data, skb->nh.raw, sizeof(*iph)); | ||
| 98 | skb->nh.raw = skb->data; | ||
| 99 | |||
| 100 | iph = skb->nh.iph; | ||
| 101 | iph->ihl = (sizeof(*iph) + optlen) / 4; | ||
| 102 | iph->tot_len = htons(skb->len); | ||
| 103 | iph->daddr = x->sel.daddr.a4; | ||
| 104 | iph->saddr = x->sel.saddr.a4; | ||
| 105 | if (ph_nexthdr) | ||
| 106 | iph->protocol = ph_nexthdr; | ||
| 107 | else | ||
| 108 | iph->protocol = protocol; | ||
| 109 | iph->check = 0; | ||
| 110 | iph->check = ip_fast_csum(skb->nh.raw, iph->ihl); | ||
| 111 | err = 0; | ||
| 112 | out: | ||
| 113 | return err; | ||
| 114 | } | ||
| 115 | |||
| 116 | static struct xfrm_mode xfrm4_beet_mode = { | ||
| 117 | .input = xfrm4_beet_input, | ||
| 118 | .output = xfrm4_beet_output, | ||
| 119 | .owner = THIS_MODULE, | ||
| 120 | .encap = XFRM_MODE_BEET, | ||
| 121 | }; | ||
| 122 | |||
| 123 | static int __init xfrm4_beet_init(void) | ||
| 124 | { | ||
| 125 | return xfrm_register_mode(&xfrm4_beet_mode, AF_INET); | ||
| 126 | } | ||
| 127 | |||
| 128 | static void __exit xfrm4_beet_exit(void) | ||
| 129 | { | ||
| 130 | int err; | ||
| 131 | |||
| 132 | err = xfrm_unregister_mode(&xfrm4_beet_mode, AF_INET); | ||
| 133 | BUG_ON(err); | ||
| 134 | } | ||
| 135 | |||
| 136 | module_init(xfrm4_beet_init); | ||
| 137 | module_exit(xfrm4_beet_exit); | ||
| 138 | MODULE_LICENSE("GPL"); | ||
| 139 | MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_BEET); | ||
diff --git a/net/ipv6/Kconfig b/net/ipv6/Kconfig index a2d211da2aba..a460e8132b4d 100644 --- a/net/ipv6/Kconfig +++ b/net/ipv6/Kconfig | |||
| @@ -136,6 +136,16 @@ config INET6_XFRM_MODE_TUNNEL | |||
| 136 | 136 | ||
| 137 | If unsure, say Y. | 137 | If unsure, say Y. |
| 138 | 138 | ||
| 139 | config INET6_XFRM_MODE_BEET | ||
| 140 | tristate "IPv6: IPsec BEET mode" | ||
| 141 | depends on IPV6 | ||
| 142 | default IPV6 | ||
| 143 | select XFRM | ||
| 144 | ---help--- | ||
| 145 | Support for IPsec BEET mode. | ||
| 146 | |||
| 147 | If unsure, say Y. | ||
| 148 | |||
| 139 | config INET6_XFRM_MODE_ROUTEOPTIMIZATION | 149 | config INET6_XFRM_MODE_ROUTEOPTIMIZATION |
| 140 | tristate "IPv6: MIPv6 route optimization mode (EXPERIMENTAL)" | 150 | tristate "IPv6: MIPv6 route optimization mode (EXPERIMENTAL)" |
| 141 | depends on IPV6 && EXPERIMENTAL | 151 | depends on IPV6 && EXPERIMENTAL |
diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile index 0213c6612b58..87274e47fe32 100644 --- a/net/ipv6/Makefile +++ b/net/ipv6/Makefile | |||
| @@ -26,6 +26,7 @@ obj-$(CONFIG_INET6_TUNNEL) += tunnel6.o | |||
| 26 | obj-$(CONFIG_INET6_XFRM_MODE_TRANSPORT) += xfrm6_mode_transport.o | 26 | obj-$(CONFIG_INET6_XFRM_MODE_TRANSPORT) += xfrm6_mode_transport.o |
| 27 | obj-$(CONFIG_INET6_XFRM_MODE_TUNNEL) += xfrm6_mode_tunnel.o | 27 | obj-$(CONFIG_INET6_XFRM_MODE_TUNNEL) += xfrm6_mode_tunnel.o |
| 28 | obj-$(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION) += xfrm6_mode_ro.o | 28 | obj-$(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION) += xfrm6_mode_ro.o |
| 29 | obj-$(CONFIG_INET6_XFRM_MODE_BEET) += xfrm6_mode_beet.o | ||
| 29 | obj-$(CONFIG_NETFILTER) += netfilter/ | 30 | obj-$(CONFIG_NETFILTER) += netfilter/ |
| 30 | 31 | ||
| 31 | obj-$(CONFIG_IPV6_TUNNEL) += ip6_tunnel.o | 32 | obj-$(CONFIG_IPV6_TUNNEL) += ip6_tunnel.o |
diff --git a/net/ipv6/ipcomp6.c b/net/ipv6/ipcomp6.c index a2860e35efd7..71f59f18ede8 100644 --- a/net/ipv6/ipcomp6.c +++ b/net/ipv6/ipcomp6.c | |||
| @@ -199,6 +199,7 @@ static void ipcomp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | |||
| 199 | static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) | 199 | static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) |
| 200 | { | 200 | { |
| 201 | struct xfrm_state *t = NULL; | 201 | struct xfrm_state *t = NULL; |
| 202 | u8 mode = XFRM_MODE_TUNNEL; | ||
| 202 | 203 | ||
| 203 | t = xfrm_state_alloc(); | 204 | t = xfrm_state_alloc(); |
| 204 | if (!t) | 205 | if (!t) |
| @@ -212,7 +213,9 @@ static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x) | |||
| 212 | memcpy(t->id.daddr.a6, x->id.daddr.a6, sizeof(struct in6_addr)); | 213 | memcpy(t->id.daddr.a6, x->id.daddr.a6, sizeof(struct in6_addr)); |
| 213 | memcpy(&t->sel, &x->sel, sizeof(t->sel)); | 214 | memcpy(&t->sel, &x->sel, sizeof(t->sel)); |
| 214 | t->props.family = AF_INET6; | 215 | t->props.family = AF_INET6; |
| 215 | t->props.mode = XFRM_MODE_TUNNEL; | 216 | if (x->props.mode == XFRM_MODE_BEET) |
| 217 | mode = x->props.mode; | ||
| 218 | t->props.mode = mode; | ||
| 216 | memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr)); | 219 | memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr)); |
| 217 | 220 | ||
| 218 | if (xfrm_init_state(t)) | 221 | if (xfrm_init_state(t)) |
diff --git a/net/ipv6/xfrm6_mode_beet.c b/net/ipv6/xfrm6_mode_beet.c new file mode 100644 index 000000000000..edcfffa9e87b --- /dev/null +++ b/net/ipv6/xfrm6_mode_beet.c | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* | ||
| 2 | * xfrm6_mode_beet.c - BEET mode encapsulation for IPv6. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com> | ||
| 5 | * Miika Komu <miika@iki.fi> | ||
| 6 | * Herbert Xu <herbert@gondor.apana.org.au> | ||
| 7 | * Abhinav Pathak <abhinav.pathak@hiit.fi> | ||
| 8 | * Jeff Ahrenholz <ahrenholz@gmail.com> | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/init.h> | ||
| 12 | #include <linux/kernel.h> | ||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/skbuff.h> | ||
| 15 | #include <linux/stringify.h> | ||
| 16 | #include <net/dsfield.h> | ||
| 17 | #include <net/dst.h> | ||
| 18 | #include <net/inet_ecn.h> | ||
| 19 | #include <net/ipv6.h> | ||
| 20 | #include <net/xfrm.h> | ||
| 21 | |||
| 22 | /* Add encapsulation header. | ||
| 23 | * | ||
| 24 | * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt. | ||
| 25 | * The following fields in it shall be filled in by x->type->output: | ||
| 26 | * payload_len | ||
| 27 | * | ||
| 28 | * On exit, skb->h will be set to the start of the encapsulation header to be | ||
| 29 | * filled in by x->type->output and skb->nh will be set to the nextheader field | ||
| 30 | * of the extension header directly preceding the encapsulation header, or in | ||
| 31 | * its absence, that of the top IP header. The value of skb->data will always | ||
| 32 | * point to the top IP header. | ||
| 33 | */ | ||
| 34 | static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb) | ||
| 35 | { | ||
| 36 | struct ipv6hdr *iph, *top_iph; | ||
| 37 | u8 *prevhdr; | ||
| 38 | int hdr_len; | ||
| 39 | |||
| 40 | skb_push(skb, x->props.header_len); | ||
| 41 | iph = skb->nh.ipv6h; | ||
| 42 | |||
| 43 | hdr_len = ip6_find_1stfragopt(skb, &prevhdr); | ||
| 44 | skb->nh.raw = prevhdr - x->props.header_len; | ||
| 45 | skb->h.raw = skb->data + hdr_len; | ||
| 46 | memmove(skb->data, iph, hdr_len); | ||
| 47 | |||
| 48 | skb->nh.raw = skb->data; | ||
| 49 | top_iph = skb->nh.ipv6h; | ||
| 50 | skb->nh.raw = &top_iph->nexthdr; | ||
| 51 | skb->h.ipv6h = top_iph + 1; | ||
| 52 | |||
| 53 | ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr); | ||
| 54 | ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr); | ||
| 55 | |||
| 56 | return 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb) | ||
| 60 | { | ||
| 61 | struct ipv6hdr *ip6h; | ||
| 62 | int size = sizeof(struct ipv6hdr); | ||
| 63 | int err = -EINVAL; | ||
| 64 | |||
| 65 | if (!pskb_may_pull(skb, sizeof(struct ipv6hdr))) | ||
| 66 | goto out; | ||
| 67 | |||
| 68 | skb_push(skb, size); | ||
| 69 | memmove(skb->data, skb->nh.raw, size); | ||
| 70 | skb->nh.raw = skb->data; | ||
| 71 | |||
| 72 | skb->mac.raw = memmove(skb->data - skb->mac_len, | ||
| 73 | skb->mac.raw, skb->mac_len); | ||
| 74 | |||
| 75 | ip6h = skb->nh.ipv6h; | ||
| 76 | ip6h->payload_len = htons(skb->len - size); | ||
| 77 | ipv6_addr_copy(&ip6h->daddr, (struct in6_addr *) &x->sel.daddr.a6); | ||
| 78 | ipv6_addr_copy(&ip6h->saddr, (struct in6_addr *) &x->sel.saddr.a6); | ||
| 79 | err = 0; | ||
| 80 | out: | ||
| 81 | return err; | ||
| 82 | } | ||
| 83 | |||
| 84 | static struct xfrm_mode xfrm6_beet_mode = { | ||
| 85 | .input = xfrm6_beet_input, | ||
| 86 | .output = xfrm6_beet_output, | ||
| 87 | .owner = THIS_MODULE, | ||
| 88 | .encap = XFRM_MODE_BEET, | ||
| 89 | }; | ||
| 90 | |||
| 91 | static int __init xfrm6_beet_init(void) | ||
| 92 | { | ||
| 93 | return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6); | ||
| 94 | } | ||
| 95 | |||
| 96 | static void __exit xfrm6_beet_exit(void) | ||
| 97 | { | ||
| 98 | int err; | ||
| 99 | |||
| 100 | err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6); | ||
| 101 | BUG_ON(err); | ||
| 102 | } | ||
| 103 | |||
| 104 | module_init(xfrm6_beet_init); | ||
| 105 | module_exit(xfrm6_beet_exit); | ||
| 106 | MODULE_LICENSE("GPL"); | ||
| 107 | MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET); | ||
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index c59a78d2923a..d54b3a70d5df 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c | |||
| @@ -211,6 +211,7 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, | |||
| 211 | case XFRM_MODE_TRANSPORT: | 211 | case XFRM_MODE_TRANSPORT: |
| 212 | case XFRM_MODE_TUNNEL: | 212 | case XFRM_MODE_TUNNEL: |
| 213 | case XFRM_MODE_ROUTEOPTIMIZATION: | 213 | case XFRM_MODE_ROUTEOPTIMIZATION: |
| 214 | case XFRM_MODE_BEET: | ||
| 214 | break; | 215 | break; |
| 215 | 216 | ||
| 216 | default: | 217 | default: |
