xfrm4_mode_transport.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * xfrm4_mode_transport.c - Transport mode encapsulation for IPv4.
  3. *
  4. * Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
  5. */
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/stringify.h>
  11. #include <net/dst.h>
  12. #include <net/ip.h>
  13. #include <net/xfrm.h>
  14. /* Add encapsulation header.
  15. *
  16. * The IP header will be moved forward to make space for the encapsulation
  17. * header.
  18. *
  19. * On exit, skb->h will be set to the start of the payload to be processed
  20. * by x->type->output and skb->nh will be set to the top IP header.
  21. */
  22. static int xfrm4_transport_output(struct sk_buff *skb)
  23. {
  24. struct xfrm_state *x;
  25. struct iphdr *iph;
  26. int ihl;
  27. iph = skb->nh.iph;
  28. skb->h.ipiph = iph;
  29. ihl = iph->ihl * 4;
  30. skb->h.raw += ihl;
  31. x = skb->dst->xfrm;
  32. skb->nh.raw = memmove(skb_push(skb, x->props.header_len), iph, ihl);
  33. return 0;
  34. }
  35. static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
  36. {
  37. return 0;
  38. }
  39. static struct xfrm_mode xfrm4_transport_mode = {
  40. .input = xfrm4_transport_input,
  41. .output = xfrm4_transport_output,
  42. .owner = THIS_MODULE,
  43. .encap = XFRM_MODE_TRANSPORT,
  44. };
  45. static int __init xfrm4_transport_init(void)
  46. {
  47. return xfrm_register_mode(&xfrm4_transport_mode, AF_INET);
  48. }
  49. static void __exit xfrm4_transport_exit(void)
  50. {
  51. int err;
  52. err = xfrm_unregister_mode(&xfrm4_transport_mode, AF_INET);
  53. BUG_ON(err);
  54. }
  55. module_init(xfrm4_transport_init);
  56. module_exit(xfrm4_transport_exit);
  57. MODULE_LICENSE("GPL");
  58. MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TRANSPORT);