2 * xfrm6_mode_transport.c - Transport mode encapsulation for IPv6.
4 * Copyright (C) 2002 USAGI/WIDE Project
5 * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/stringify.h>
16 #include <net/protocol.h>
18 /* Add encapsulation header.
20 * The IP header and mutable extension headers will be moved forward to make
21 * space for the encapsulation header.
23 static int xfrm6_transport_output(struct xfrm_state
*x
, struct sk_buff
*skb
)
30 skb_set_inner_transport_header(skb
, skb_transport_offset(skb
));
32 hdr_len
= x
->type
->hdr_offset(x
, skb
, &prevhdr
);
35 skb_set_mac_header(skb
, (prevhdr
- x
->props
.header_len
) - skb
->data
);
36 skb_set_network_header(skb
, -x
->props
.header_len
);
37 skb
->transport_header
= skb
->network_header
+ hdr_len
;
38 __skb_pull(skb
, hdr_len
);
39 memmove(ipv6_hdr(skb
), iph
, hdr_len
);
43 /* Remove encapsulation header.
45 * The IP header will be moved over the top of the encapsulation header.
47 * On entry, skb->h shall point to where the IP header should be and skb->nh
48 * shall be set to where the IP header currently is. skb->data shall point
49 * to the start of the payload.
51 static int xfrm6_transport_input(struct xfrm_state
*x
, struct sk_buff
*skb
)
53 int ihl
= skb
->data
- skb_transport_header(skb
);
54 struct xfrm_offload
*xo
= xfrm_offload(skb
);
56 if (skb
->transport_header
!= skb
->network_header
) {
57 memmove(skb_transport_header(skb
),
58 skb_network_header(skb
), ihl
);
59 skb
->network_header
= skb
->transport_header
;
61 ipv6_hdr(skb
)->payload_len
= htons(skb
->len
+ ihl
-
62 sizeof(struct ipv6hdr
));
63 if (!xo
|| !(xo
->flags
& XFRM_GRO
))
64 skb_reset_transport_header(skb
);
68 static struct sk_buff
*xfrm4_transport_gso_segment(struct xfrm_state
*x
,
70 netdev_features_t features
)
72 const struct net_offload
*ops
;
73 struct sk_buff
*segs
= ERR_PTR(-EINVAL
);
74 struct xfrm_offload
*xo
= xfrm_offload(skb
);
76 skb
->transport_header
+= x
->props
.header_len
;
77 ops
= rcu_dereference(inet6_offloads
[xo
->proto
]);
78 if (likely(ops
&& ops
->callbacks
.gso_segment
))
79 segs
= ops
->callbacks
.gso_segment(skb
, features
);
84 static void xfrm6_transport_xmit(struct xfrm_state
*x
, struct sk_buff
*skb
)
86 struct xfrm_offload
*xo
= xfrm_offload(skb
);
88 skb_reset_mac_len(skb
);
89 pskb_pull(skb
, skb
->mac_len
+ sizeof(struct ipv6hdr
) + x
->props
.header_len
);
91 if (xo
->flags
& XFRM_GSO_SEGMENT
) {
92 skb_reset_transport_header(skb
);
93 skb
->transport_header
-= x
->props
.header_len
;
98 static struct xfrm_mode xfrm6_transport_mode
= {
99 .input
= xfrm6_transport_input
,
100 .output
= xfrm6_transport_output
,
101 .gso_segment
= xfrm4_transport_gso_segment
,
102 .xmit
= xfrm6_transport_xmit
,
103 .owner
= THIS_MODULE
,
104 .encap
= XFRM_MODE_TRANSPORT
,
107 static int __init
xfrm6_transport_init(void)
109 return xfrm_register_mode(&xfrm6_transport_mode
, AF_INET6
);
112 static void __exit
xfrm6_transport_exit(void)
116 err
= xfrm_unregister_mode(&xfrm6_transport_mode
, AF_INET6
);
120 module_init(xfrm6_transport_init
);
121 module_exit(xfrm6_transport_exit
);
122 MODULE_LICENSE("GPL");
123 MODULE_ALIAS_XFRM_MODE(AF_INET6
, XFRM_MODE_TRANSPORT
);