[PATCH 1/2] util:netlink: Enable virNetlinkNewLink to support veth
Shi Lei
shi_lei at massclouds.com
Mon Nov 23 01:53:03 UTC 2020
>On 11/17/20 1:48 AM, Shi Lei wrote:
>> Signed-off-by: Shi Lei <shi_lei at massclouds.com>
>> ---
>> src/util/virnetlink.c | 25 +++++++++++++++++++++++++
>> src/util/virnetlink.h | 1 +
>> 2 files changed, 26 insertions(+)
>>
>> diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
>> index fdd3a6a4..e191f63b 100644
>> --- a/src/util/virnetlink.c
>> +++ b/src/util/virnetlink.c
>> @@ -41,6 +41,18 @@ VIR_LOG_INIT("util.netlink");
>> #define NETLINK_ACK_TIMEOUT_S (2*1000)
>>
>> #if defined(WITH_LIBNL)
>> +
>> +/*
>> + * VETH_INFO_PEER is defined in libnl, but it isn't exposed.
>> + * We include it just like what iproute2 has done.
>
>This is actually defined as a part of the basic netlink .h files, and is
>available in /usr/include/linux/veth.h. The file in iproute2 is just a
>copy of that file (in include/uapi/linux/veth.h). I'm not sure why they
>did that, possibly so they could build an ip binary containing the "new"
>(at the time) veth support on a machine that was still lacking support
>in the kernel header files?.
>
>
>Anyway, I replaced this open-coded definition of VETH_INFO_* with
>
>#include <linux/veth.h> and everything built with no problem. And I've
>checked and that file is present in the kernel headers at least as far
>back as kernel-3.18 (and we don't support anything older than that).
>
>
>So, when you send V2 with the change I outlined in my review of Patch
>2/2, could you replace this enum with the proper #include?
>
>
>Thanks!
Okay. I also don't like introducing that enum.
Thanks for letting me know :-)
Shi Lei
>
>> + */
>> +enum {
>> + VETH_INFO_UNSPEC,
>> + VETH_INFO_PEER,
>> +
>> + __VETH_INFO_MAX
>> +};
>> +
>> /* State for a single netlink event handle */
>> struct virNetlinkEventHandle {
>> int watch;
>> @@ -535,6 +547,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) {
>> diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
>> index 7121eac4..7c4ed202 100644
>> --- a/src/util/virnetlink.h
>> +++ b/src/util/virnetlink.h
>> @@ -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,
>
>
More information about the libvir-list
mailing list