1 #include <linux/errno.h>
3 #include <linux/kernel.h>
4 #include <linux/module.h>
5 #include <linux/skbuff.h>
6 #include <linux/socket.h>
7 #include <linux/types.h>
8 #include <net/checksum.h>
10 #include <net/ip6_fib.h>
11 #include <net/lwtunnel.h>
12 #include <net/protocol.h>
13 #include <uapi/linux/ila.h>
16 static __wsum
get_csum_diff(struct ipv6hdr
*ip6h
, struct ila_params
*p
)
18 if (*(__be64
*)&ip6h
->daddr
== p
->locator_match
)
21 return compute_csum_diff8((__be32
*)&ip6h
->daddr
,
22 (__be32
*)&p
->locator
);
25 void update_ipv6_locator(struct sk_buff
*skb
, struct ila_params
*p
)
28 struct ipv6hdr
*ip6h
= ipv6_hdr(skb
);
29 size_t nhoff
= sizeof(struct ipv6hdr
);
31 /* First update checksum */
32 switch (ip6h
->nexthdr
) {
34 if (likely(pskb_may_pull(skb
, nhoff
+ sizeof(struct tcphdr
)))) {
35 struct tcphdr
*th
= (struct tcphdr
*)
36 (skb_network_header(skb
) + nhoff
);
38 diff
= get_csum_diff(ip6h
, p
);
39 inet_proto_csum_replace_by_diff(&th
->check
, skb
,
44 if (likely(pskb_may_pull(skb
, nhoff
+ sizeof(struct udphdr
)))) {
45 struct udphdr
*uh
= (struct udphdr
*)
46 (skb_network_header(skb
) + nhoff
);
48 if (uh
->check
|| skb
->ip_summed
== CHECKSUM_PARTIAL
) {
49 diff
= get_csum_diff(ip6h
, p
);
50 inet_proto_csum_replace_by_diff(&uh
->check
, skb
,
53 uh
->check
= CSUM_MANGLED_0
;
58 if (likely(pskb_may_pull(skb
,
59 nhoff
+ sizeof(struct icmp6hdr
)))) {
60 struct icmp6hdr
*ih
= (struct icmp6hdr
*)
61 (skb_network_header(skb
) + nhoff
);
63 diff
= get_csum_diff(ip6h
, p
);
64 inet_proto_csum_replace_by_diff(&ih
->icmp6_cksum
, skb
,
70 /* Now change destination address */
71 *(__be64
*)&ip6h
->daddr
= p
->locator
;
74 static int __init
ila_init(void)
83 ret
= ila_xlat_init();
94 static void __exit
ila_fini(void)
100 module_init(ila_init
);
101 module_exit(ila_fini
);
102 MODULE_ALIAS_RTNL_LWT(ILA
);
103 MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>");
104 MODULE_LICENSE("GPL");