]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util:netlink: Enable virNetlinkNewLink to support veth
authorShi Lei <shi_lei@massclouds.com>
Wed, 16 Dec 2020 06:01:04 +0000 (14:01 +0800)
committerLaine Stump <laine@redhat.com>
Wed, 16 Dec 2020 19:42:46 +0000 (14:42 -0500)
Signed-off-by: Shi Lei <shi_lei@massclouds.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/util/virnetlink.c
src/util/virnetlink.h

index fdd3a6a4d0b3e2df11b63f0a2828d8b99a50ec03..ca735bb880a8defd99e7eae694fa3d157800e734 100644 (file)
@@ -41,6 +41,9 @@ VIR_LOG_INIT("util.netlink");
 #define NETLINK_ACK_TIMEOUT_S  (2*1000)
 
 #if defined(WITH_LIBNL)
+
+# include <linux/veth.h>
+
 /* State for a single netlink event handle */
 struct virNetlinkEventHandle {
     int watch;
@@ -535,6 +538,19 @@ virNetlinkNewLink(const char *ifname,
         NETLINK_MSG_NEST_END(nl_msg, infodata);
     }
 
+    if (STREQ(type, "veth") && extra_args && extra_args->veth_peer) {
+        struct nlattr *infoveth = NULL;
+
+        NETLINK_MSG_NEST_START(nl_msg, infodata, IFLA_INFO_DATA);
+        NETLINK_MSG_NEST_START(nl_msg, infoveth, VETH_INFO_PEER);
+        nlmsg_reserve(nl_msg, sizeof(struct ifinfomsg), 0);
+        NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME,
+                        (strlen(extra_args->veth_peer) + 1),
+                        extra_args->veth_peer);
+        NETLINK_MSG_NEST_END(nl_msg, infoveth);
+        NETLINK_MSG_NEST_END(nl_msg, infodata);
+    }
+
     NETLINK_MSG_NEST_END(nl_msg, linkinfo);
 
     if (extra_args) {
index 7121eac43e540c9a0806bb15ea3d75565672f8c6..7c4ed202b9cfe485a6be5eaf8f7fed7bf85eaf04 100644 (file)
@@ -84,6 +84,7 @@ struct _virNetlinkNewLinkData {
     const int *ifindex;             /* The index for the 'link' device */
     const virMacAddr *mac;          /* The MAC address of the device */
     const uint32_t *macvlan_mode;   /* The mode of macvlan */
+    const char *veth_peer;          /* The peer name for veth */
 };
 
 int virNetlinkNewLink(const char *ifname,