]> granicus.if.org Git - libnl/commitdiff
route/vlan: fix cloning vlan link in vlan_clone()
authorThomas Haller <thaller@redhat.com>
Mon, 23 Oct 2017 09:35:32 +0000 (11:35 +0200)
committerThomas Haller <thaller@redhat.com>
Mon, 23 Oct 2017 10:09:16 +0000 (12:09 +0200)
We need to copy the entire source struct over
from source to destination.

The only thing that needs special handling is
to deep-clone the vi_egress_qos buffer.

Fixes: a7469ce758fac3631df6ce72eb3f89150070e7f8
lib/route/link/vlan.c

index 477c9af2a8710259ac4bf36344f66e92da966048..23fdf662bcd45397865a6317b17e554a3966e143 100644 (file)
@@ -264,19 +264,28 @@ static int vlan_clone(struct rtnl_link *dst, struct rtnl_link *src)
 {
        struct vlan_info *vdst, *vsrc = src->l_info;
        int err;
+       struct vlan_map *p = NULL;
 
        dst->l_info = NULL;
        if ((err = rtnl_link_set_type(dst, "vlan")) < 0)
                return err;
        vdst = dst->l_info;
 
-       vdst->vi_egress_qos = calloc(vsrc->vi_egress_size,
-                                    sizeof(struct vlan_map));
-       if (!vdst->vi_egress_qos)
-               return -NLE_NOMEM;
+       if (vsrc->vi_negress) {
+               p = calloc(vsrc->vi_negress,
+                          sizeof(struct vlan_map));
+               if (!p)
+                       return -NLE_NOMEM;
+       }
 
-       memcpy(vdst->vi_egress_qos, vsrc->vi_egress_qos,
-              vsrc->vi_egress_size * sizeof(struct vlan_map));
+       *vdst = *vsrc;
+
+       if (vsrc->vi_negress) {
+               vdst->vi_egress_size = vsrc->vi_negress;
+               vdst->vi_egress_qos = p;
+               memcpy(vdst->vi_egress_qos, vsrc->vi_egress_qos,
+                      vsrc->vi_negress * sizeof(struct vlan_map));
+       }
 
        return 0;
 }