xfrm_output.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * xfrm_output.c - Common IPsec encapsulation code.
  3. *
  4. * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/module.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/time.h>
  17. #include <net/dst.h>
  18. #include <net/xfrm.h>
  19. int xfrm_output(struct sk_buff *skb)
  20. {
  21. struct dst_entry *dst = skb->dst;
  22. struct xfrm_state *x = dst->xfrm;
  23. int err;
  24. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  25. err = skb_checksum_help(skb);
  26. if (err)
  27. goto error_nolock;
  28. }
  29. do {
  30. spin_lock_bh(&x->lock);
  31. err = xfrm_state_check(x, skb);
  32. if (err)
  33. goto error;
  34. err = x->mode->output(x, skb);
  35. if (err)
  36. goto error;
  37. err = x->type->output(x, skb);
  38. if (err)
  39. goto error;
  40. x->curlft.bytes += skb->len;
  41. x->curlft.packets++;
  42. if (x->props.mode == XFRM_MODE_ROUTEOPTIMIZATION)
  43. x->lastused = get_seconds();
  44. spin_unlock_bh(&x->lock);
  45. skb_reset_network_header(skb);
  46. if (!(skb->dst = dst_pop(dst))) {
  47. err = -EHOSTUNREACH;
  48. goto error_nolock;
  49. }
  50. dst = skb->dst;
  51. x = dst->xfrm;
  52. } while (x && (x->props.mode != XFRM_MODE_TUNNEL));
  53. err = 0;
  54. error_nolock:
  55. return err;
  56. error:
  57. spin_unlock_bh(&x->lock);
  58. goto error_nolock;
  59. }
  60. EXPORT_SYMBOL_GPL(xfrm_output);