--- zzzz-none-000/linux-5.4.213/net/ipv4/ip_tunnel_core.c 2022-09-15 10:04:56.000000000 +0000 +++ miami-7690-761/linux-5.4.213/net/ipv4/ip_tunnel_core.c 2024-05-29 11:20:02.000000000 +0000 @@ -34,6 +34,7 @@ #include #include #include +#include const struct ip_tunnel_encap_ops __rcu * iptun_encaps[MAX_IPTUN_ENCAP_OPS] __read_mostly; @@ -51,7 +52,12 @@ struct net *net = dev_net(rt->dst.dev); struct net_device *dev = skb->dev; struct iphdr *iph; + struct net_device *in_dev = NULL; int err; + int skb_iif; + + /* Save input interface index */ + skb_iif = skb->skb_iif; skb_scrub_packet(skb, xnet); @@ -75,6 +81,15 @@ iph->ttl = ttl; __ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1); + /* Get input interface */ + if (skb_iif) { + in_dev = __dev_get_by_index(&init_net, skb_iif); + } + + if (proto == IPPROTO_IPV6 || proto == IPPROTO_GRE || (in_dev && netif_is_vxlan(in_dev))) { + skb->skb_iif = skb_iif; + } + err = ip_local_out(net, sk, skb); if (dev) {