]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: openvswitch: don't call pad_packet if not necessary
authorTonghao Zhang <xiangxia.m.yue@gmail.com>
Thu, 14 Nov 2019 15:51:08 +0000 (23:51 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 15 Nov 2019 20:43:27 +0000 (12:43 -0800)
The nla_put_u16/nla_put_u32 makes sure that
*attrlen is align. The call tree is that:

nla_put_u16/nla_put_u32
  -> nla_put attrlen = sizeof(u16) or sizeof(u32)
  -> __nla_put attrlen
  -> __nla_reserve attrlen
  -> skb_put(skb, nla_total_size(attrlen))

nla_total_size returns the total length of attribute
including padding.

Cc: Joe Stringer <joe@ovn.org>
Cc: William Tu <u9012063@gmail.com>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/openvswitch/datapath.c

index 8ce1f773378dcc44b657ca0588b2bf63361e9fa2..93d4991ddc1fed197413c557c45fd756b5c6a22a 100644 (file)
@@ -487,23 +487,17 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,
        }
 
        /* Add OVS_PACKET_ATTR_MRU */
-       if (upcall_info->mru) {
-               if (nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU,
-                               upcall_info->mru)) {
-                       err = -ENOBUFS;
-                       goto out;
-               }
-               pad_packet(dp, user_skb);
+       if (upcall_info->mru &&
+           nla_put_u16(user_skb, OVS_PACKET_ATTR_MRU, upcall_info->mru)) {
+               err = -ENOBUFS;
+               goto out;
        }
 
        /* Add OVS_PACKET_ATTR_LEN when packet is truncated */
-       if (cutlen > 0) {
-               if (nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN,
-                               skb->len)) {
-                       err = -ENOBUFS;
-                       goto out;
-               }
-               pad_packet(dp, user_skb);
+       if (cutlen > 0 &&
+           nla_put_u32(user_skb, OVS_PACKET_ATTR_LEN, skb->len)) {
+               err = -ENOBUFS;
+               goto out;
        }
 
        /* Add OVS_PACKET_ATTR_HASH */