veth: use nl_object_clone() to deep copy rtnl_link object
Currently we use memcpy() to copy the peer rtnl_link for veth device, this is wrong, we should do deep copy by calling nl_object_clone() recursively. We should be careful and need to make sure we only call it once. Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
6c8f67b87a
commit
3700bf56fa
1 changed files with 11 additions and 11 deletions
|
@ -98,19 +98,19 @@ static void veth_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
|
|||
|
||||
static int veth_clone(struct rtnl_link *dst, struct rtnl_link *src)
|
||||
{
|
||||
struct rtnl_link *dst_peer , *src_peer = src->l_info;
|
||||
int err;
|
||||
struct rtnl_link *dst_peer = NULL, *src_peer = src->l_info;
|
||||
|
||||
dst_peer = dst->l_info = rtnl_link_alloc();
|
||||
if (!dst_peer || !src_peer)
|
||||
return -NLE_NOMEM;
|
||||
if ((err = rtnl_link_set_type(dst, "veth")) < 0) {
|
||||
rtnl_link_put(dst_peer);
|
||||
return err;
|
||||
/* we are calling nl_object_clone() recursively, this should
|
||||
* happen only once */
|
||||
if (src_peer) {
|
||||
src_peer->l_info = NULL;
|
||||
dst_peer = (struct rtnl_link *)nl_object_clone(OBJ_CAST(src_peer));
|
||||
if (!dst_peer)
|
||||
return -NLE_NOMEM;
|
||||
src_peer->l_info = src;
|
||||
dst_peer->l_info = dst;
|
||||
}
|
||||
|
||||
memcpy(dst_peer, src_peer, sizeof(struct rtnl_link));
|
||||
|
||||
dst->l_info = dst_peer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue