xfrm4_tunnel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. struct iphdr *iph;
  14. iph = skb->nh.iph;
  15. iph->tot_len = htons(skb->len);
  16. ip_send_check(iph);
  17. return 0;
  18. }
  19. static int ipip_xfrm_rcv(struct xfrm_state *x, struct sk_buff *skb)
  20. {
  21. return 0;
  22. }
  23. static int ipip_init_state(struct xfrm_state *x)
  24. {
  25. if (x->props.mode != XFRM_MODE_TUNNEL)
  26. return -EINVAL;
  27. if (x->encap)
  28. return -EINVAL;
  29. x->props.header_len = sizeof(struct iphdr);
  30. return 0;
  31. }
  32. static void ipip_destroy(struct xfrm_state *x)
  33. {
  34. }
  35. static struct xfrm_type ipip_type = {
  36. .description = "IPIP",
  37. .owner = THIS_MODULE,
  38. .proto = IPPROTO_IPIP,
  39. .init_state = ipip_init_state,
  40. .destructor = ipip_destroy,
  41. .input = ipip_xfrm_rcv,
  42. .output = ipip_output
  43. };
  44. static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
  45. {
  46. return -ENOENT;
  47. }
  48. static struct xfrm_tunnel xfrm_tunnel_handler = {
  49. .handler = xfrm4_rcv,
  50. .err_handler = xfrm_tunnel_err,
  51. .priority = 2,
  52. };
  53. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  54. static struct xfrm_tunnel xfrm64_tunnel_handler = {
  55. .handler = xfrm4_rcv,
  56. .err_handler = xfrm_tunnel_err,
  57. .priority = 2,
  58. };
  59. #endif
  60. static int __init ipip_init(void)
  61. {
  62. if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
  63. printk(KERN_INFO "ipip init: can't add xfrm type\n");
  64. return -EAGAIN;
  65. }
  66. if (xfrm4_tunnel_register(&xfrm_tunnel_handler, AF_INET)) {
  67. printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET\n");
  68. xfrm_unregister_type(&ipip_type, AF_INET);
  69. return -EAGAIN;
  70. }
  71. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  72. if (xfrm4_tunnel_register(&xfrm64_tunnel_handler, AF_INET6)) {
  73. printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET6\n");
  74. xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET);
  75. xfrm_unregister_type(&ipip_type, AF_INET);
  76. return -EAGAIN;
  77. }
  78. #endif
  79. return 0;
  80. }
  81. static void __exit ipip_fini(void)
  82. {
  83. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  84. if (xfrm4_tunnel_deregister(&xfrm64_tunnel_handler, AF_INET6))
  85. printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET6\n");
  86. #endif
  87. if (xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET))
  88. printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET\n");
  89. if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
  90. printk(KERN_INFO "ipip close: can't remove xfrm type\n");
  91. }
  92. module_init(ipip_init);
  93. module_exit(ipip_fini);
  94. MODULE_LICENSE("GPL");