xfrm4_output.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * xfrm4_output.c - Common IPsec encapsulation code for IPv4.
  4. * Copyright (c) 2004 Herbert Xu <[email protected]>
  5. */
  6. #include <linux/if_ether.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/netfilter_ipv4.h>
  11. #include <net/dst.h>
  12. #include <net/ip.h>
  13. #include <net/xfrm.h>
  14. #include <net/icmp.h>
  15. static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
  16. {
  17. #ifdef CONFIG_NETFILTER
  18. struct xfrm_state *x = skb_dst(skb)->xfrm;
  19. if (!x) {
  20. IPCB(skb)->flags |= IPSKB_REROUTED;
  21. return dst_output(net, sk, skb);
  22. }
  23. #endif
  24. return xfrm_output(sk, skb);
  25. }
  26. int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
  27. {
  28. return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING,
  29. net, sk, skb, skb->dev, skb_dst(skb)->dev,
  30. __xfrm4_output,
  31. !(IPCB(skb)->flags & IPSKB_REROUTED));
  32. }
  33. void xfrm4_local_error(struct sk_buff *skb, u32 mtu)
  34. {
  35. struct iphdr *hdr;
  36. hdr = skb->encapsulation ? inner_ip_hdr(skb) : ip_hdr(skb);
  37. ip_local_error(skb->sk, EMSGSIZE, hdr->daddr,
  38. inet_sk(skb->sk)->inet_dport, mtu);
  39. }