xfrm4_tunnel.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. static int __init ipip_init(void)
  54. {
  55. if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
  56. printk(KERN_INFO "ipip init: can't add xfrm type\n");
  57. return -EAGAIN;
  58. }
  59. if (xfrm4_tunnel_register(&xfrm_tunnel_handler)) {
  60. printk(KERN_INFO "ipip init: can't add xfrm handler\n");
  61. xfrm_unregister_type(&ipip_type, AF_INET);
  62. return -EAGAIN;
  63. }
  64. return 0;
  65. }
  66. static void __exit ipip_fini(void)
  67. {
  68. if (xfrm4_tunnel_deregister(&xfrm_tunnel_handler))
  69. printk(KERN_INFO "ipip close: can't remove xfrm handler\n");
  70. if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
  71. printk(KERN_INFO "ipip close: can't remove xfrm type\n");
  72. }
  73. module_init(ipip_init);
  74. module_exit(ipip_fini);
  75. MODULE_LICENSE("GPL");