Blame view

net/ipv4/xfrm4_tunnel.c 2.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
  /* xfrm4_tunnel.c: Generic IP tunnel transformer.
   *
   * Copyright (C) 2003 David S. Miller (davem@redhat.com)
   */
  
  #include <linux/skbuff.h>
  #include <linux/module.h>
4a3e2f711   Arjan van de Ven   [NET] sem2mutex: ...
8
  #include <linux/mutex.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
  #include <net/xfrm.h>
  #include <net/ip.h>
  #include <net/protocol.h>
  
  static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
  {
7b277b1a5   Herbert Xu   [IPSEC]: Set skb-...
15
  	skb_push(skb, -skb_network_offset(skb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
  	return 0;
  }
e695633e2   Herbert Xu   [IPSEC]: Kill unu...
18
  static int ipip_xfrm_rcv(struct xfrm_state *x, struct sk_buff *skb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  {
04663d0b8   Herbert Xu   [IPSEC]: Fix pure...
20
  	return ip_hdr(skb)->protocol;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  }
72cb6962a   Herbert Xu   [IPSEC]: Add xfrm...
22
  static int ipip_init_state(struct xfrm_state *x)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
  {
7e49e6de3   Masahide NAKAMURA   [XFRM]: Add XFRM_...
24
  	if (x->props.mode != XFRM_MODE_TUNNEL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
29
30
31
32
33
34
35
36
37
  		return -EINVAL;
  
  	if (x->encap)
  		return -EINVAL;
  
  	x->props.header_len = sizeof(struct iphdr);
  
  	return 0;
  }
  
  static void ipip_destroy(struct xfrm_state *x)
  {
  }
533cb5b0a   Eric Dumazet   [XFRM]: constify ...
38
  static const struct xfrm_type ipip_type = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
41
42
43
44
45
46
  	.description	= "IPIP",
  	.owner		= THIS_MODULE,
  	.proto	     	= IPPROTO_IPIP,
  	.init_state	= ipip_init_state,
  	.destructor	= ipip_destroy,
  	.input		= ipip_xfrm_rcv,
  	.output		= ipip_output
  };
c4541b41c   Herbert Xu   [IPSEC]: Move tun...
47
48
  static int xfrm_tunnel_rcv(struct sk_buff *skb)
  {
b1641064a   Herbert Xu   [IPCOMP]: Fix rec...
49
  	return xfrm4_rcv_spi(skb, IPPROTO_IPIP, ip_hdr(skb)->saddr);
c4541b41c   Herbert Xu   [IPSEC]: Move tun...
50
  }
d2acc3479   Herbert Xu   [INET]: Introduce...
51
52
53
54
  static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
  {
  	return -ENOENT;
  }
6dcd814bd   Eric Dumazet   net: struct xfrm_...
55
  static struct xfrm_tunnel xfrm_tunnel_handler __read_mostly = {
c4541b41c   Herbert Xu   [IPSEC]: Move tun...
56
  	.handler	=	xfrm_tunnel_rcv,
d2acc3479   Herbert Xu   [INET]: Introduce...
57
58
  	.err_handler	=	xfrm_tunnel_err,
  	.priority	=	2,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  };
dfd56b8b3   Eric Dumazet   net: use IS_ENABL...
60
  #if IS_ENABLED(CONFIG_IPV6)
6dcd814bd   Eric Dumazet   net: struct xfrm_...
61
  static struct xfrm_tunnel xfrm64_tunnel_handler __read_mostly = {
c4541b41c   Herbert Xu   [IPSEC]: Move tun...
62
  	.handler	=	xfrm_tunnel_rcv,
c0d56408e   Kazunori MIYAZAWA   [IPSEC]: Changing...
63
64
65
66
  	.err_handler	=	xfrm_tunnel_err,
  	.priority	=	2,
  };
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
69
70
71
72
73
  static int __init ipip_init(void)
  {
  	if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
  		printk(KERN_INFO "ipip init: can't add xfrm type
  ");
  		return -EAGAIN;
  	}
c0d56408e   Kazunori MIYAZAWA   [IPSEC]: Changing...
74
75
76
77
78
79
80
  
  	if (xfrm4_tunnel_register(&xfrm_tunnel_handler, AF_INET)) {
  		printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET
  ");
  		xfrm_unregister_type(&ipip_type, AF_INET);
  		return -EAGAIN;
  	}
dfd56b8b3   Eric Dumazet   net: use IS_ENABL...
81
  #if IS_ENABLED(CONFIG_IPV6)
c0d56408e   Kazunori MIYAZAWA   [IPSEC]: Changing...
82
83
84
85
  	if (xfrm4_tunnel_register(&xfrm64_tunnel_handler, AF_INET6)) {
  		printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET6
  ");
  		xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
87
88
  		xfrm_unregister_type(&ipip_type, AF_INET);
  		return -EAGAIN;
  	}
c0d56408e   Kazunori MIYAZAWA   [IPSEC]: Changing...
89
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
93
94
  	return 0;
  }
  
  static void __exit ipip_fini(void)
  {
dfd56b8b3   Eric Dumazet   net: use IS_ENABL...
95
  #if IS_ENABLED(CONFIG_IPV6)
c0d56408e   Kazunori MIYAZAWA   [IPSEC]: Changing...
96
97
98
99
100
101
102
  	if (xfrm4_tunnel_deregister(&xfrm64_tunnel_handler, AF_INET6))
  		printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET6
  ");
  #endif
  	if (xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET))
  		printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
104
105
106
107
108
109
110
  	if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
  		printk(KERN_INFO "ipip close: can't remove xfrm type
  ");
  }
  
  module_init(ipip_init);
  module_exit(ipip_fini);
  MODULE_LICENSE("GPL");
d3d6dd3ad   Masahide NAKAMURA   [XFRM]: Add modul...
111
  MODULE_ALIAS_XFRM_TYPE(AF_INET, XFRM_PROTO_IPIP);