]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
net: add dst_pending_confirm flag to skbuff
authorJulian Anastasov <ja@ssi.bg>
Fri, 8 Sep 2017 07:00:00 +0000 (09:00 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 15 Sep 2017 13:49:14 +0000 (15:49 +0200)
BugLink: https://bugs.launchpad.net/bugs/1715812
Add new skbuff flag to allow protocols to confirm neighbour.
When same struct dst_entry can be used for many different
neighbours we can not use it for pending confirmations.

Add sock_confirm_neigh() helper to confirm the neighbour and
use it for IPv4, IPv6 and VRF before dst_neigh_output.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 4ff0620354f2b39b9fe2a91c22c4de9d1fba0c8e)
Signed-off-by: Daniel Axtens <daniel.axtens@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Colin King <colin.king@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/net/vrf.c
include/linux/skbuff.h
include/net/sock.h
net/ipv4/ip_output.c
net/ipv6/ip6_output.c

index f2fd52e71a5ed58f6e238578a08bb7902d6b8595..82232897c994540c719e092b31c1cbf6a10d28a0 100644 (file)
@@ -380,6 +380,7 @@ static int vrf_finish_output6(struct net *net, struct sock *sk,
        if (unlikely(!neigh))
                neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
        if (!IS_ERR(neigh)) {
+               sock_confirm_neigh(skb, neigh);
                ret = dst_neigh_output(dst, neigh, skb);
                rcu_read_unlock_bh();
                return ret;
@@ -578,8 +579,10 @@ static int vrf_finish_output(struct net *net, struct sock *sk, struct sk_buff *s
        neigh = __ipv4_neigh_lookup_noref(dev, nexthop);
        if (unlikely(!neigh))
                neigh = __neigh_create(&arp_tbl, &nexthop, dev, false);
-       if (!IS_ERR(neigh))
+       if (!IS_ERR(neigh)) {
+               sock_confirm_neigh(skb, neigh);
                ret = dst_neigh_output(dst, neigh, skb);
+       }
 
        rcu_read_unlock_bh();
 err:
index a410715bbef8889d148a6b3f8dbd6afc4ae6f4d0..ee060e8c6ff164ca8b41d5691121735a6c1cc796 100644 (file)
@@ -610,6 +610,7 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,
  *     @wifi_acked_valid: wifi_acked was set
  *     @wifi_acked: whether frame was acked on wifi or not
  *     @no_fcs:  Request NIC to treat last 4 bytes as Ethernet FCS
+ *     @dst_pending_confirm: need to confirm neighbour
   *    @napi_id: id of the NAPI struct this skb came from
  *     @secmark: security marking
  *     @mark: Generic packet mark
@@ -740,6 +741,7 @@ struct sk_buff {
        __u8                    csum_level:2;
        __u8                    csum_bad:1;
 
+       __u8                    dst_pending_confirm:1;
 #ifdef CONFIG_IPV6_NDISC_NODETYPE
        __u8                    ndisc_nodetype:2;
 #endif
@@ -3689,6 +3691,16 @@ static inline bool skb_rx_queue_recorded(const struct sk_buff *skb)
        return skb->queue_mapping != 0;
 }
 
+static inline void skb_set_dst_pending_confirm(struct sk_buff *skb, u32 val)
+{
+       skb->dst_pending_confirm = val;
+}
+
+static inline bool skb_get_dst_pending_confirm(const struct sk_buff *skb)
+{
+       return skb->dst_pending_confirm != 0;
+}
+
 static inline struct sec_path *skb_sec_path(struct sk_buff *skb)
 {
 #ifdef CONFIG_XFRM
index 7e4ca83a6815a740c231212baddcd7743e9fcd33..dfe020eea2ae64dc1275d0bbde984474a5234056 100644 (file)
@@ -1818,6 +1818,20 @@ static inline void sk_dst_confirm(struct sock *sk)
                sk->sk_dst_pending_confirm = 1;
 }
 
+static inline void sock_confirm_neigh(struct sk_buff *skb, struct neighbour *n)
+{
+       if (skb_get_dst_pending_confirm(skb)) {
+               struct sock *sk = skb->sk;
+               unsigned long now = jiffies;
+
+               /* avoid dirtying neighbour */
+               if (n->confirmed != now)
+                       n->confirmed = now;
+               if (sk && sk->sk_dst_pending_confirm)
+                       sk->sk_dst_pending_confirm = 0;
+       }
+}
+
 bool sk_mc_loop(struct sock *sk);
 
 static inline bool sk_can_gso(const struct sock *sk)
index 49e9b2bc6e3329b263cb97a16e7ed5869506be6a..8c85cad2b2afe24c6bd9d75c391340df53c6eacb 100644 (file)
@@ -222,7 +222,10 @@ static int ip_finish_output2(struct net *net, struct sock *sk, struct sk_buff *s
        if (unlikely(!neigh))
                neigh = __neigh_create(&arp_tbl, &nexthop, dev, false);
        if (!IS_ERR(neigh)) {
-               int res = dst_neigh_output(dst, neigh, skb);
+               int res;
+
+               sock_confirm_neigh(skb, neigh);
+               res = dst_neigh_output(dst, neigh, skb);
 
                rcu_read_unlock_bh();
                return res;
index b65ce893f1cb88eaf7272c40550d9d0c10108ef6..7ceac3b8694a81775870d8604b81f9acc2bb09f7 100644 (file)
@@ -119,6 +119,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *
        if (unlikely(!neigh))
                neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
        if (!IS_ERR(neigh)) {
+               sock_confirm_neigh(skb, neigh);
                ret = dst_neigh_output(dst, neigh, skb);
                rcu_read_unlock_bh();
                return ret;