1 /* xfrm4_tunnel.c: Generic IP tunnel transformer.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
6 #include <linux/skbuff.h>
7 #include <linux/module.h>
8 #include <linux/mutex.h>
11 #include <net/protocol.h>
13 static int ipip_output(struct xfrm_state
*x
, struct sk_buff
*skb
)
15 skb_push(skb
, -skb_network_offset(skb
));
19 static int ipip_xfrm_rcv(struct xfrm_state
*x
, struct sk_buff
*skb
)
21 return ip_hdr(skb
)->protocol
;
24 static int ipip_init_state(struct xfrm_state
*x
)
26 if (x
->props
.mode
!= XFRM_MODE_TUNNEL
)
32 x
->props
.header_len
= sizeof(struct iphdr
);
37 static void ipip_destroy(struct xfrm_state
*x
)
41 static struct xfrm_type ipip_type
= {
42 .description
= "IPIP",
44 .proto
= IPPROTO_IPIP
,
45 .init_state
= ipip_init_state
,
46 .destructor
= ipip_destroy
,
47 .input
= ipip_xfrm_rcv
,
51 static int xfrm_tunnel_rcv(struct sk_buff
*skb
)
53 return xfrm4_rcv_spi(skb
, IPPROTO_IP
, ip_hdr(skb
)->saddr
);
56 static int xfrm_tunnel_err(struct sk_buff
*skb
, u32 info
)
61 static struct xfrm_tunnel xfrm_tunnel_handler
= {
62 .handler
= xfrm_tunnel_rcv
,
63 .err_handler
= xfrm_tunnel_err
,
67 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
68 static struct xfrm_tunnel xfrm64_tunnel_handler
= {
69 .handler
= xfrm_tunnel_rcv
,
70 .err_handler
= xfrm_tunnel_err
,
75 static int __init
ipip_init(void)
77 if (xfrm_register_type(&ipip_type
, AF_INET
) < 0) {
78 printk(KERN_INFO
"ipip init: can't add xfrm type\n");
82 if (xfrm4_tunnel_register(&xfrm_tunnel_handler
, AF_INET
)) {
83 printk(KERN_INFO
"ipip init: can't add xfrm handler for AF_INET\n");
84 xfrm_unregister_type(&ipip_type
, AF_INET
);
87 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
88 if (xfrm4_tunnel_register(&xfrm64_tunnel_handler
, AF_INET6
)) {
89 printk(KERN_INFO
"ipip init: can't add xfrm handler for AF_INET6\n");
90 xfrm4_tunnel_deregister(&xfrm_tunnel_handler
, AF_INET
);
91 xfrm_unregister_type(&ipip_type
, AF_INET
);
98 static void __exit
ipip_fini(void)
100 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
101 if (xfrm4_tunnel_deregister(&xfrm64_tunnel_handler
, AF_INET6
))
102 printk(KERN_INFO
"ipip close: can't remove xfrm handler for AF_INET6\n");
104 if (xfrm4_tunnel_deregister(&xfrm_tunnel_handler
, AF_INET
))
105 printk(KERN_INFO
"ipip close: can't remove xfrm handler for AF_INET\n");
106 if (xfrm_unregister_type(&ipip_type
, AF_INET
) < 0)
107 printk(KERN_INFO
"ipip close: can't remove xfrm type\n");
110 module_init(ipip_init
);
111 module_exit(ipip_fini
);
112 MODULE_LICENSE("GPL");
113 MODULE_ALIAS_XFRM_TYPE(AF_INET
, XFRM_PROTO_IPIP
);