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