xfrm4_tunnel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* xfrm4_tunnel.c: Generic IP tunnel transformer.
  2. *
  3. * Copyright (C) 2003 David S. Miller (davem@redhat.com)
  4. */
  5. #include <linux/skbuff.h>
  6. #include <linux/module.h>
  7. #include <linux/mutex.h>
  8. #include <net/xfrm.h>
  9. #include <net/ip.h>
  10. #include <net/protocol.h>
  11. static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
  12. {
  13. skb_push(skb, -skb_network_offset(skb));
  14. return 0;
  15. }
  16. static int ipip_xfrm_rcv(struct xfrm_state *x, struct sk_buff *skb)
  17. {
  18. return IPPROTO_IP;
  19. }
  20. static int ipip_init_state(struct xfrm_state *x)
  21. {
  22. if (x->props.mode != XFRM_MODE_TUNNEL)
  23. return -EINVAL;
  24. if (x->encap)
  25. return -EINVAL;
  26. x->props.header_len = sizeof(struct iphdr);
  27. return 0;
  28. }
  29. static void ipip_destroy(struct xfrm_state *x)
  30. {
  31. }
  32. static struct xfrm_type ipip_type = {
  33. .description = "IPIP",
  34. .owner = THIS_MODULE,
  35. .proto = IPPROTO_IPIP,
  36. .init_state = ipip_init_state,
  37. .destructor = ipip_destroy,
  38. .input = ipip_xfrm_rcv,
  39. .output = ipip_output
  40. };
  41. static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
  42. {
  43. return -ENOENT;
  44. }
  45. static struct xfrm_tunnel xfrm_tunnel_handler = {
  46. .handler = xfrm4_rcv,
  47. .err_handler = xfrm_tunnel_err,
  48. .priority = 2,
  49. };
  50. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  51. static struct xfrm_tunnel xfrm64_tunnel_handler = {
  52. .handler = xfrm4_rcv,
  53. .err_handler = xfrm_tunnel_err,
  54. .priority = 2,
  55. };
  56. #endif
  57. static int __init ipip_init(void)
  58. {
  59. if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
  60. printk(KERN_INFO "ipip init: can't add xfrm type\n");
  61. return -EAGAIN;
  62. }
  63. if (xfrm4_tunnel_register(&xfrm_tunnel_handler, AF_INET)) {
  64. printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET\n");
  65. xfrm_unregister_type(&ipip_type, AF_INET);
  66. return -EAGAIN;
  67. }
  68. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  69. if (xfrm4_tunnel_register(&xfrm64_tunnel_handler, AF_INET6)) {
  70. printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET6\n");
  71. xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET);
  72. xfrm_unregister_type(&ipip_type, AF_INET);
  73. return -EAGAIN;
  74. }
  75. #endif
  76. return 0;
  77. }
  78. static void __exit ipip_fini(void)
  79. {
  80. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  81. if (xfrm4_tunnel_deregister(&xfrm64_tunnel_handler, AF_INET6))
  82. printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET6\n");
  83. #endif
  84. if (xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET))
  85. printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET\n");
  86. if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
  87. printk(KERN_INFO "ipip close: can't remove xfrm type\n");
  88. }
  89. module_init(ipip_init);
  90. module_exit(ipip_fini);
  91. MODULE_LICENSE("GPL");
  92. MODULE_ALIAS_XFRM_TYPE(AF_INET, XFRM_PROTO_IPIP);