Merge tag 'regulator-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[linux-2.6-microblaze.git] / net / ipv4 / ip_input.c
index c59a78a..aa438c6 100644 (file)
@@ -302,16 +302,31 @@ drop:
        return true;
 }
 
+static bool ip_can_use_hint(const struct sk_buff *skb, const struct iphdr *iph,
+                           const struct sk_buff *hint)
+{
+       return hint && !skb_dst(skb) && ip_hdr(hint)->daddr == iph->daddr &&
+              ip_hdr(hint)->tos == iph->tos;
+}
+
 INDIRECT_CALLABLE_DECLARE(int udp_v4_early_demux(struct sk_buff *));
 INDIRECT_CALLABLE_DECLARE(int tcp_v4_early_demux(struct sk_buff *));
 static int ip_rcv_finish_core(struct net *net, struct sock *sk,
-                             struct sk_buff *skb, struct net_device *dev)
+                             struct sk_buff *skb, struct net_device *dev,
+                             const struct sk_buff *hint)
 {
        const struct iphdr *iph = ip_hdr(skb);
        int (*edemux)(struct sk_buff *skb);
        struct rtable *rt;
        int err;
 
+       if (ip_can_use_hint(skb, iph, hint)) {
+               err = ip_route_use_hint(skb, iph->daddr, iph->saddr, iph->tos,
+                                       dev, hint);
+               if (unlikely(err))
+                       goto drop_error;
+       }
+
        if (net->ipv4.sysctl_ip_early_demux &&
            !skb_dst(skb) &&
            !skb->sk &&
@@ -408,7 +423,7 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
        if (!skb)
                return NET_RX_SUCCESS;
 
-       ret = ip_rcv_finish_core(net, sk, skb, dev);
+       ret = ip_rcv_finish_core(net, sk, skb, dev, NULL);
        if (ret != NET_RX_DROP)
                ret = dst_input(skb);
        return ret;
@@ -535,11 +550,20 @@ static void ip_sublist_rcv_finish(struct list_head *head)
        }
 }
 
+static struct sk_buff *ip_extract_route_hint(const struct net *net,
+                                            struct sk_buff *skb, int rt_type)
+{
+       if (fib4_has_custom_rules(net) || rt_type == RTN_BROADCAST)
+               return NULL;
+
+       return skb;
+}
+
 static void ip_list_rcv_finish(struct net *net, struct sock *sk,
                               struct list_head *head)
 {
+       struct sk_buff *skb, *next, *hint = NULL;
        struct dst_entry *curr_dst = NULL;
-       struct sk_buff *skb, *next;
        struct list_head sublist;
 
        INIT_LIST_HEAD(&sublist);
@@ -554,11 +578,14 @@ static void ip_list_rcv_finish(struct net *net, struct sock *sk,
                skb = l3mdev_ip_rcv(skb);
                if (!skb)
                        continue;
-               if (ip_rcv_finish_core(net, sk, skb, dev) == NET_RX_DROP)
+               if (ip_rcv_finish_core(net, sk, skb, dev, hint) == NET_RX_DROP)
                        continue;
 
                dst = skb_dst(skb);
                if (curr_dst != dst) {
+                       hint = ip_extract_route_hint(net, skb,
+                                              ((struct rtable *)dst)->rt_type);
+
                        /* dispatch old sublist */
                        if (!list_empty(&sublist))
                                ip_sublist_rcv_finish(&sublist);
@@ -611,5 +638,6 @@ void ip_list_rcv(struct list_head *head, struct packet_type *pt,
                list_add_tail(&skb->list, &sublist);
        }
        /* dispatch final sublist */
-       ip_sublist_rcv(&sublist, curr_dev, curr_net);
+       if (!list_empty(&sublist))
+               ip_sublist_rcv(&sublist, curr_dev, curr_net);
 }