virnetdevmacvlan.c 43.4 KB
Newer Older
1
/*
2
 * Copyright (C) 2010-2017 Red Hat, Inc.
3
 * Copyright (C) 2010-2012 IBM Corporation
4 5 6 7 8 9 10 11 12 13 14 15
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library.  If not, see
O
Osier Yang 已提交
17
 * <http://www.gnu.org/licenses/>.
18 19 20 21 22 23 24 25 26 27
 *
 * Notes:
 * netlink: http://lovezutto.googlepages.com/netlink.pdf
 *          iproute2 package
 *
 */

#include <config.h>

#include "virnetdevmacvlan.h"
28
#include "virmacaddr.h"
29
#include "virerror.h"
30
#include "virthread.h"
31
#include "virstring.h"
32 33 34

#define VIR_FROM_THIS VIR_FROM_NET

35 36
VIR_ENUM_IMPL(virNetDevMacVLanMode,
              VIR_NETDEV_MACVLAN_MODE_LAST,
37 38 39
              "vepa",
              "private",
              "bridge",
40 41
              "passthrough",
);
42 43 44 45 46 47

#if WITH_MACVTAP
# include <fcntl.h>
# include <sys/socket.h>
# include <sys/ioctl.h>

48
# include <net/if.h>
49 50 51 52 53 54 55
# include <linux/if_tun.h>

/* Older kernels lacked this enum value.  */
# if !HAVE_DECL_MACVLAN_MODE_PASSTHRU
#  define MACVLAN_MODE_PASSTHRU 8
# endif

56
# include "viralloc.h"
57
# include "virlog.h"
58
# include "viruuid.h"
59
# include "virfile.h"
60
# include "virnetlink.h"
61
# include "virnetdev.h"
62
# include "virpidfile.h"
63
# include "virbitmap.h"
64

65
VIR_LOG_INIT("util.netdevmacvlan");
66

67 68 69 70 71
# define VIR_NET_GENERATED_MACVTAP_PATTERN VIR_NET_GENERATED_MACVTAP_PREFIX "%d"
# define VIR_NET_GENERATED_MACVLAN_PATTERN VIR_NET_GENERATED_MACVLAN_PREFIX "%d"
# define VIR_NET_GENERATED_PREFIX \
    ((flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ? \
     VIR_NET_GENERATED_MACVTAP_PREFIX : VIR_NET_GENERATED_MACVLAN_PREFIX)
72

73 74
# define MACVLAN_MAX_ID 8191

75
virMutex virNetDevMacVLanCreateMutex = VIR_MUTEX_INITIALIZER;
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
virBitmapPtr macvtapIDs = NULL;
virBitmapPtr macvlanIDs = NULL;

static int
virNetDevMacVLanOnceInit(void)
{
    if (!macvtapIDs &&
        !(macvtapIDs = virBitmapNew(MACVLAN_MAX_ID + 1)))
        return -1;
    if (!macvlanIDs &&
        !(macvlanIDs = virBitmapNew(MACVLAN_MAX_ID + 1)))
        return -1;
    return 0;
}

VIR_ONCE_GLOBAL_INIT(virNetDevMacVLan);


/**
 * virNetDevMacVLanReserveID:
 *
 *  @id: id 0 - MACVLAN_MAX_ID+1 to reserve (or -1 for "first free")
 *  @flags: set VIR_NETDEV_MACVLAN_CREATE_WITH_TAP for macvtapN else macvlanN
 *  @quietFail: don't log an error if this name is already in-use
 *  @nextFree: reserve the next free ID *after* @id rather than @id itself
 *
 *  Reserve the indicated ID in the appropriate bitmap, or find the
 *  first free ID if @id is -1.
 *
 *  Returns newly reserved ID# on success, or -1 to indicate failure.
 */
static int
virNetDevMacVLanReserveID(int id, unsigned int flags,
                          bool quietFail, bool nextFree)
{
    virBitmapPtr bitmap;

    if (virNetDevMacVLanInitialize() < 0)
       return -1;

    bitmap = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
        macvtapIDs :  macvlanIDs;

    if (id > MACVLAN_MAX_ID) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("can't use name %s%d - out of range 0-%d"),
122
                       VIR_NET_GENERATED_PREFIX, id, MACVLAN_MAX_ID);
123 124 125 126
        return -1;
    }

    if ((id < 0 || nextFree) &&
127
        (id = virBitmapNextClearBit(bitmap, id)) < 0) {
128 129
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("no unused %s names available"),
130
                       VIR_NET_GENERATED_PREFIX);
131 132 133 134 135 136
        return -1;
    }

    if (virBitmapIsBitSet(bitmap, id)) {
        if (quietFail) {
            VIR_INFO("couldn't reserve name %s%d - already in use",
137
                     VIR_NET_GENERATED_PREFIX, id);
138 139 140
        } else {
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("couldn't reserve name %s%d - already in use"),
141
                           VIR_NET_GENERATED_PREFIX, id);
142 143 144 145 146 147 148
        }
        return -1;
    }

    if (virBitmapSetBit(bitmap, id) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("couldn't mark %s%d as used"),
149
                       VIR_NET_GENERATED_PREFIX, id);
150 151 152
        return -1;
    }

153
    VIR_INFO("reserving device %s%d", VIR_NET_GENERATED_PREFIX, id);
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    return id;
}


/**
 * virNetDevMacVLanReleaseID:
 *  @id: id 0 - MACVLAN_MAX_ID+1 to release
 *
 *  Returns 0 for success or -1 for failure.
 */
static int
virNetDevMacVLanReleaseID(int id, unsigned int flags)
{
    virBitmapPtr bitmap;

    if (virNetDevMacVLanInitialize() < 0)
        return 0;

    bitmap = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
        macvtapIDs :  macvlanIDs;

    if (id > MACVLAN_MAX_ID) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("can't free name %s%d - out of range 0-%d"),
178
                       VIR_NET_GENERATED_PREFIX, id, MACVLAN_MAX_ID);
179 180 181 182 183 184 185 186
        return -1;
    }

    if (id < 0)
        return 0;

    VIR_INFO("releasing %sdevice %s%d",
             virBitmapIsBitSet(bitmap, id) ? "" : "unreserved",
187
             VIR_NET_GENERATED_PREFIX, id);
188 189 190 191

    if (virBitmapClearBit(bitmap, id) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("couldn't mark %s%d as unused"),
192
                       VIR_NET_GENERATED_PREFIX, id);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
        return -1;
    }
    return 0;
}


/**
 * virNetDevMacVLanReserveName:
 *
 *  @name: already-known name of device
 *  @quietFail: don't log an error if this name is already in-use
 *
 *  Extract the device type and id from a macvtap/macvlan device name
 *  and mark the appropriate position as in-use in the appropriate
 *  bitmap.
 *
 *  Returns reserved ID# on success, -1 on failure, -2 if the name
 *  doesn't fit the auto-pattern (so not reserveable).
 */
int
virNetDevMacVLanReserveName(const char *name, bool quietFail)
{
    unsigned int id;
    unsigned int flags = 0;
    const char *idstr = NULL;

    if (virNetDevMacVLanInitialize() < 0)
       return -1;

222 223
    if (STRPREFIX(name, VIR_NET_GENERATED_MACVTAP_PREFIX)) {
        idstr = name + strlen(VIR_NET_GENERATED_MACVTAP_PREFIX);
224
        flags |= VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
225 226
    } else if (STRPREFIX(name, VIR_NET_GENERATED_MACVLAN_PREFIX)) {
        idstr = name + strlen(VIR_NET_GENERATED_MACVLAN_PREFIX);
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
    } else {
        return -2;
    }

    if (virStrToLong_ui(idstr, NULL, 10, &id) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("couldn't get id value from macvtap device name %s"),
                       name);
        return -1;
    }
    return virNetDevMacVLanReserveID(id, flags, quietFail, false);
}


/**
 * virNetDevMacVLanReleaseName:
 *
 *  @name: already-known name of device
 *
 *  Extract the device type and id from a macvtap/macvlan device name
 *  and mark the appropriate position as in-use in the appropriate
 *  bitmap.
 *
 *  returns 0 on success, -1 on failure
 */
int
virNetDevMacVLanReleaseName(const char *name)
{
    unsigned int id;
    unsigned int flags = 0;
    const char *idstr = NULL;

    if (virNetDevMacVLanInitialize() < 0)
       return -1;

262 263
    if (STRPREFIX(name, VIR_NET_GENERATED_MACVTAP_PREFIX)) {
        idstr = name + strlen(VIR_NET_GENERATED_MACVTAP_PREFIX);
264
        flags |= VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
265 266
    } else if (STRPREFIX(name, VIR_NET_GENERATED_MACVLAN_PREFIX)) {
        idstr = name + strlen(VIR_NET_GENERATED_MACVLAN_PREFIX);
267 268 269 270 271 272 273 274 275 276 277 278 279
    } else {
        return 0;
    }

    if (virStrToLong_ui(idstr, NULL, 10, &id) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("couldn't get id value from macvtap device name %s"),
                       name);
        return -1;
    }
    return virNetDevMacVLanReleaseID(id, flags);
}

280

281 282 283 284 285 286 287 288 289 290 291
/**
 * virNetDevMacVLanIsMacvtap:
 * @ifname: Name of the interface
 *
 * Return T if the named netdev exists and is a macvtap device
 * F in all other cases.
 */
bool
virNetDevMacVLanIsMacvtap(const char *ifname)
{
    int ifindex;
292
    g_autofree char *tapname = NULL;
293 294 295 296 297 298 299 300 301 302 303

    if (virNetDevGetIndex(ifname, &ifindex) < 0)
        return false;

    if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
        return false;

    return virFileExists(tapname);
}


304 305 306 307
/**
 * virNetDevMacVLanCreate:
 *
 * @ifname: The name the interface is supposed to have; optional parameter
308
 * @type: The type of device, i.e., "macvtap", "macvlan"
309 310 311 312 313 314 315 316 317 318 319 320 321 322
 * @macaddress: The MAC address of the device
 * @srcdev: The name of the 'link' device
 * @macvlan_mode: The macvlan mode to use
 * @retry: Pointer to integer that will be '1' upon return if an interface
 *         with the same name already exists and it is worth to try
 *         again with a different name
 *
 * Create a macvtap device with the given properties.
 *
 * Returns 0 on success, -1 on fatal error.
 */
int
virNetDevMacVLanCreate(const char *ifname,
                       const char *type,
323
                       const virMacAddr *macaddress,
324 325 326 327
                       const char *srcdev,
                       uint32_t macvlan_mode,
                       int *retry)
{
328 329 330 331 332 333
    int error = 0;
    int ifindex = 0;
    virNetlinkNewLinkData data = {
        .macvlan_mode = &macvlan_mode,
        .mac = macaddress,
    };
334 335 336

    *retry = 0;

337
    if (virNetDevGetIndex(srcdev, &ifindex) < 0)
338 339
        return -1;

340 341 342 343
    data.ifindex = &ifindex;
    if (virNetlinkNewLink(ifname, type, &data, &error) < 0) {
        char macstr[VIR_MAC_STRING_BUFLEN];
        if (error == -EEXIST)
344
            *retry = 1;
345 346
        else if (error < 0)
            virReportSystemError(-error,
347 348 349
                                 _("error creating %s interface %s@%s (%s)"),
                                 type, ifname, srcdev,
                                 virMacAddrFormat(macaddress, macstr));
350

351
        return -1;
352 353
    }

354
    return 0;
355 356 357 358 359 360 361 362 363 364 365 366 367
}

/**
 * virNetDevMacVLanDelete:
 *
 * @ifname: Name of the interface
 *
 * Tear down an interface with the given name.
 *
 * Returns 0 on success, -1 on fatal error.
 */
int virNetDevMacVLanDelete(const char *ifname)
{
368
    return virNetlinkDelLink(ifname, NULL);
369 370 371
}


372 373 374
/**
 * virNetDevMacVLanTapOpen:
 * @ifname: Name of the macvtap interface
375 376 377 378 379 380
 * @tapfd: array of file descriptor return value for the new macvtap device
 * @tapfdSize: number of file descriptors in @tapfd
 *
 * Open the macvtap's tap device, possibly multiple times if @tapfdSize > 1.
 *
 * Returns 0 on success, -1 otherwise.
381
 */
382
int
383 384
virNetDevMacVLanTapOpen(const char *ifname,
                        int *tapfd,
385
                        size_t tapfdSize)
386
{
387
    int retries = 10;
388
    int ret = -1;
389
    int ifindex;
390
    size_t i = 0;
391
    g_autofree char *tapname = NULL;
392

393
    if (virNetDevGetIndex(ifname, &ifindex) < 0)
394 395
        return -1;

396
    if (virAsprintf(&tapname, "/dev/tap%d", ifindex) < 0)
397
        goto cleanup;
398

399 400 401 402 403 404 405 406
    for (i = 0; i < tapfdSize; i++) {
        int fd = -1;

        while (fd < 0) {
            if ((fd = open(tapname, O_RDWR)) >= 0) {
                tapfd[i] = fd;
            } else if (retries-- > 0) {
                /* may need to wait for udev to be done */
407
                g_usleep(20000);
408 409 410 411 412 413 414
            } else {
                /* However, if haven't succeeded, quit. */
                virReportSystemError(errno,
                                     _("cannot open macvtap tap device %s"),
                                     tapname);
                goto cleanup;
            }
415 416 417
        }
    }

418 419
    ret = 0;

420
 cleanup:
421 422 423 424
    if (ret < 0) {
        while (i--)
            VIR_FORCE_CLOSE(tapfd[i]);
    }
425
    return ret;
426 427 428 429 430
}


/**
 * virNetDevMacVLanTapSetup:
431 432 433
 * @tapfd: array of file descriptors of the macvtap tap
 * @tapfdSize: number of file descriptors in @tapfd
 * @vnet_hdr: whether to enable or disable IFF_VNET_HDR
434
 *
435 436 437 438
 * Turn on the IFF_VNET_HDR flag if requested and available, but make sure
 * it's off otherwise. Similarly, turn on IFF_MULTI_QUEUE if @tapfdSize is
 * greater than one, but if it can't be set, consider it a fatal error
 * (rather than ignoring as with @vnet_hdr).
439 440 441 442 443
 *
 * A fatal error is defined as the VNET_HDR flag being set but it cannot
 * be turned off for some reason. This is reported with -1. Other fatal
 * error is not being able to read the interface flags. In that case the
 * macvtap device should not be used.
444
 *
445
 * Returns 0 on success, -1 in case of fatal error.
446
 */
447
int
448
virNetDevMacVLanTapSetup(int *tapfd, size_t tapfdSize, bool vnet_hdr)
449 450 451 452
{
    unsigned int features;
    struct ifreq ifreq;
    short new_flags = 0;
453
    size_t i;
454

455 456
    for (i = 0; i < tapfdSize; i++) {
        memset(&ifreq, 0, sizeof(ifreq));
457

458
        if (ioctl(tapfd[i], TUNGETIFF, &ifreq) < 0) {
459
            virReportSystemError(errno, "%s",
460
                                 _("cannot get interface flags on macvtap tap"));
461 462
            return -1;
        }
463 464 465

        new_flags = ifreq.ifr_flags;

466
        if (vnet_hdr) {
467 468 469 470 471
            if (ioctl(tapfd[i], TUNGETFEATURES, &features) < 0) {
                virReportSystemError(errno, "%s",
                                     _("cannot get feature flags on macvtap tap"));
                return -1;
            }
472 473 474 475
            if (features & IFF_VNET_HDR)
                new_flags |= IFF_VNET_HDR;
        } else {
            new_flags &= ~IFF_VNET_HDR;
476 477
        }

478
# ifdef IFF_MULTI_QUEUE
479
        if (tapfdSize > 1)
480 481 482
            new_flags |= IFF_MULTI_QUEUE;
        else
            new_flags &= ~IFF_MULTI_QUEUE;
483
# else
484
        if (tapfdSize > 1) {
485 486 487 488 489
            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                           _("Multiqueue devices are not supported on this system"));
            return -1;
        }
# endif
490

491 492 493
        if (new_flags != ifreq.ifr_flags) {
            ifreq.ifr_flags = new_flags;
            if (ioctl(tapfd[i], TUNSETIFF, &ifreq) < 0) {
494 495 496
                virReportSystemError(errno, "%s",
                                     _("unable to set vnet or multiqueue flags on macvtap"));
                return -1;
497
            }
498 499 500 501 502 503 504 505 506 507 508 509 510 511
        }
    }

    return 0;
}


static const uint32_t modeMap[VIR_NETDEV_MACVLAN_MODE_LAST] = {
    [VIR_NETDEV_MACVLAN_MODE_VEPA] = MACVLAN_MODE_VEPA,
    [VIR_NETDEV_MACVLAN_MODE_PRIVATE] = MACVLAN_MODE_PRIVATE,
    [VIR_NETDEV_MACVLAN_MODE_BRIDGE] = MACVLAN_MODE_BRIDGE,
    [VIR_NETDEV_MACVLAN_MODE_PASSTHRU] = MACVLAN_MODE_PASSTHRU,
};

512 513 514 515
/* Struct to hold the state and configuration of a 802.1qbg port */
struct virNetlinkCallbackData {
    char *cr_ifname;
    virNetDevVPortProfilePtr virtPortProfile;
516
    virMacAddr macaddress;
517
    char *linkdev;
518
    int vf;
S
Stefan Berger 已提交
519
    unsigned char vmuuid[VIR_UUID_BUFLEN];
520
    virNetDevVPortProfileOp vmOp;
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
    unsigned int linkState;
};

typedef struct virNetlinkCallbackData *virNetlinkCallbackDataPtr;

# define INSTANCE_STRLEN 36

static int instance2str(const unsigned char *p, char *dst, size_t size)
{
    if (dst && size > INSTANCE_STRLEN) {
        snprintf(dst, size, "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
                 "%02x%02x-%02x%02x%02x%02x%02x%02x",
                 p[0], p[1], p[2], p[3],
                 p[4], p[5], p[6], p[7],
                 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
        return 0;
    }
    return -1;
}

# define LLDPAD_PID_FILE  "/var/run/lldpad.pid"
# define VIRIP_PID_FILE   "/var/run/virip.pid"

/**
 * virNetDevMacVLanVPortProfileCallback:
 *
547
 * @hdr: The buffer containing the received netlink header + payload
548 549 550 551 552 553 554 555 556 557 558
 * @length: The length of the received netlink message.
 * @peer: The netling sockaddr containing the peer information
 * @handled: Contains information if the message has been replied to yet
 * @opaque: Contains vital information regarding the associated vm an interface
 *
 * This function is called when a netlink message is received. The function
 * reads the message and responds if it is pertinent to the running VMs
 * network interface.
 */

static void
559 560
virNetDevMacVLanVPortProfileCallback(struct nlmsghdr *hdr,
                                     unsigned int length,
561 562 563 564
                                     struct sockaddr_nl *peer,
                                     bool *handled,
                                     void *opaque)
{
565 566 567 568 569
    struct nla_policy ifla_vf_policy[IFLA_VF_MAX + 1] = {
        [IFLA_VF_MAC] = {.minlen = sizeof(struct ifla_vf_mac),
                         .maxlen = sizeof(struct ifla_vf_mac)},
        [IFLA_VF_VLAN] = {.minlen = sizeof(struct ifla_vf_vlan),
                          .maxlen = sizeof(struct ifla_vf_vlan)},
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
    };

    struct nla_policy ifla_port_policy[IFLA_PORT_MAX + 1] = {
        [IFLA_PORT_RESPONSE] = {.type = NLA_U16},
    };

    struct nlattr *tb[IFLA_MAX + 1], *tb3[IFLA_PORT_MAX + 1],
        *tb_vfinfo[IFLA_VF_MAX + 1], *tb_vfinfo_list;

    struct ifinfomsg ifinfo;
    void *data;
    int rem;
    char *ifname;
    bool indicate = false;
    virNetlinkCallbackDataPtr calld = opaque;
    pid_t lldpad_pid = 0;
    pid_t virip_pid = 0;
587
    char macaddr[VIR_MAC_STRING_BUFLEN];
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619

    data = nlmsg_data(hdr);

    /* Quickly decide if we want this or not */

    if (virPidFileReadPath(LLDPAD_PID_FILE, &lldpad_pid) < 0)
        return;

    ignore_value(virPidFileReadPath(VIRIP_PID_FILE, &virip_pid));

    if (hdr->nlmsg_pid != lldpad_pid && hdr->nlmsg_pid != virip_pid)
        return; /* we only care for lldpad and virip messages */
    if (hdr->nlmsg_type != RTM_SETLINK)
        return; /* we only care for RTM_SETLINK */
    if (*handled)
        return; /* if it has been handled - dont handle again */

    /* DEBUG start */
    VIR_INFO("netlink message nl_sockaddr: %p len: %d", peer, length);
    VIR_DEBUG("nlmsg_type  = 0x%02x", hdr->nlmsg_type);
    VIR_DEBUG("nlmsg_len   = 0x%04x", hdr->nlmsg_len);
    VIR_DEBUG("nlmsg_pid   = %d", hdr->nlmsg_pid);
    VIR_DEBUG("nlmsg_seq   = 0x%08x", hdr->nlmsg_seq);
    VIR_DEBUG("nlmsg_flags = 0x%04x", hdr->nlmsg_flags);

    VIR_DEBUG("lldpad pid  = %d", lldpad_pid);

    switch (hdr->nlmsg_type) {
    case RTM_NEWLINK:
    case RTM_DELLINK:
    case RTM_SETLINK:
    case RTM_GETLINK:
J
Jiri Denemark 已提交
620 621
        VIR_DEBUG(" IFINFOMSG");
        VIR_DEBUG("        ifi_family = 0x%02x",
622
                  ((struct ifinfomsg *)data)->ifi_family);
J
Jiri Denemark 已提交
623
        VIR_DEBUG("        ifi_type   = 0x%x",
624
                  ((struct ifinfomsg *)data)->ifi_type);
J
Jiri Denemark 已提交
625
        VIR_DEBUG("        ifi_index  = %i",
626
                  ((struct ifinfomsg *)data)->ifi_index);
J
Jiri Denemark 已提交
627
        VIR_DEBUG("        ifi_flags  = 0x%04x",
628
                  ((struct ifinfomsg *)data)->ifi_flags);
J
Jiri Denemark 已提交
629
        VIR_DEBUG("        ifi_change = 0x%04x",
630
                  ((struct ifinfomsg *)data)->ifi_change);
631 632 633 634
    }
    /* DEBUG end */

    /* Parse netlink message assume a setlink with vfports */
635
    memcpy(&ifinfo, NLMSG_DATA(hdr), sizeof(ifinfo));
636
    VIR_DEBUG("family:%#x type:%#x index:%d flags:%#x change:%#x",
637 638
              ifinfo.ifi_family, ifinfo.ifi_type, ifinfo.ifi_index,
              ifinfo.ifi_flags, ifinfo.ifi_change);
639
    if (nlmsg_parse(hdr, sizeof(ifinfo),
640
                    (struct nlattr **)&tb, IFLA_MAX, NULL)) {
641 642 643 644 645 646 647 648 649 650
        VIR_DEBUG("error parsing request...");
        return;
    }

    if (tb[IFLA_VFINFO_LIST]) {
        VIR_DEBUG("FOUND IFLA_VFINFO_LIST!");

        nla_for_each_nested(tb_vfinfo_list, tb[IFLA_VFINFO_LIST], rem) {
            if (nla_type(tb_vfinfo_list) != IFLA_VF_INFO) {
                VIR_DEBUG("nested parsing of"
651
                          "IFLA_VFINFO_LIST failed.");
652 653 654
                return;
            }
            if (nla_parse_nested(tb_vfinfo, IFLA_VF_MAX,
655
                                 tb_vfinfo_list, ifla_vf_policy)) {
656
                VIR_DEBUG("nested parsing of "
657
                          "IFLA_VF_INFO failed.");
658 659 660 661 662 663 664 665 666 667 668
                return;
            }
        }

        if (tb_vfinfo[IFLA_VF_MAC]) {
            struct ifla_vf_mac *mac = RTA_DATA(tb_vfinfo[IFLA_VF_MAC]);
            unsigned char *m = mac->mac;

            VIR_DEBUG("IFLA_VF_MAC = %2x:%2x:%2x:%2x:%2x:%2x",
                      m[0], m[1], m[2], m[3], m[4], m[5]);

E
Eric Blake 已提交
669
            if (virMacAddrCmpRaw(&calld->macaddress, mac->mac)) {
670
                /* Repeat the same check for a broadcast mac */
671
                size_t i;
672

673 674
                for (i = 0; i < VIR_MAC_BUFLEN; i++) {
                    if (calld->macaddress.addr[i] != 0xff) {
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
                        VIR_DEBUG("MAC address match failed (wasn't broadcast)");
                        return;
                    }
                }
            }
        }

        if (tb_vfinfo[IFLA_VF_VLAN]) {
            struct ifla_vf_vlan *vlan = RTA_DATA(tb_vfinfo[IFLA_VF_VLAN]);

            VIR_DEBUG("IFLA_VF_VLAN = %d", vlan->vlan);
        }
    }

    if (tb[IFLA_IFNAME]) {
        ifname = (char *)RTA_DATA(tb[IFLA_IFNAME]);
J
Jiri Denemark 已提交
691
        VIR_DEBUG("IFLA_IFNAME = %s", ifname);
692 693 694 695
    }

    if (tb[IFLA_OPERSTATE]) {
        rem = *(unsigned short *)RTA_DATA(tb[IFLA_OPERSTATE]);
J
Jiri Denemark 已提交
696
        VIR_DEBUG("IFLA_OPERSTATE = %d", rem);
697 698 699 700 701
    }

    if (tb[IFLA_VF_PORTS]) {
        struct nlattr *tb_vf_ports;

J
Jiri Denemark 已提交
702
        VIR_DEBUG("found IFLA_VF_PORTS");
703 704
        nla_for_each_nested(tb_vf_ports, tb[IFLA_VF_PORTS], rem) {

J
Jiri Denemark 已提交
705
            VIR_DEBUG("iterating");
706
            if (nla_type(tb_vf_ports) != IFLA_VF_PORT) {
J
Jiri Denemark 已提交
707
                VIR_DEBUG("not a IFLA_VF_PORT. skipping");
708 709 710
                continue;
            }
            if (nla_parse_nested(tb3, IFLA_PORT_MAX, tb_vf_ports,
711
                                 ifla_port_policy)) {
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
                VIR_DEBUG("nested parsing on level 2"
                          " failed.");
            }
            if (tb3[IFLA_PORT_VF]) {
                VIR_DEBUG("IFLA_PORT_VF = %d",
                          *(uint32_t *) (RTA_DATA(tb3[IFLA_PORT_VF])));
            }
            if (tb3[IFLA_PORT_PROFILE]) {
                VIR_DEBUG("IFLA_PORT_PROFILE = %s",
                          (char *) RTA_DATA(tb3[IFLA_PORT_PROFILE]));
            }

            if (tb3[IFLA_PORT_VSI_TYPE]) {
                struct ifla_port_vsi *pvsi;
                int tid = 0;

                pvsi = (struct ifla_port_vsi *)
                    RTA_DATA(tb3[IFLA_PORT_VSI_TYPE]);
                tid = ((pvsi->vsi_type_id[2] << 16) |
                       (pvsi->vsi_type_id[1] << 8) |
                       pvsi->vsi_type_id[0]);

                VIR_DEBUG("mgr_id: %d", pvsi->vsi_mgr_id);
                VIR_DEBUG("type_id: %d", tid);
                VIR_DEBUG("type_version: %d",
                          pvsi->vsi_type_version);
            }

            if (tb3[IFLA_PORT_INSTANCE_UUID]) {
                char instance[INSTANCE_STRLEN + 2];
                unsigned char *uuid;

                uuid = (unsigned char *)
                    RTA_DATA(tb3[IFLA_PORT_INSTANCE_UUID]);
                instance2str(uuid, instance, sizeof(instance));
J
Jiri Denemark 已提交
747
                VIR_DEBUG("IFLA_PORT_INSTANCE_UUID = %s",
748 749 750 751 752 753 754 755
                          instance);
            }

            if (tb3[IFLA_PORT_REQUEST]) {
                uint8_t req = *(uint8_t *) RTA_DATA(tb3[IFLA_PORT_REQUEST]);
                VIR_DEBUG("IFLA_PORT_REQUEST = %d", req);

                if (req == PORT_REQUEST_DISASSOCIATE) {
756
                    VIR_DEBUG("Set disassociated.");
757 758 759 760 761
                    indicate = true;
                }
            }

            if (tb3[IFLA_PORT_RESPONSE]) {
762 763
                VIR_DEBUG("IFLA_PORT_RESPONSE = %d",
                          *(uint16_t *) RTA_DATA(tb3[IFLA_PORT_RESPONSE]));
764 765 766 767
            }
        }
    }

768
    if (!indicate)
769 770 771 772 773
        return;

    VIR_INFO("Re-send 802.1qbg associate request:");
    VIR_INFO("  if: %s", calld->cr_ifname);
    VIR_INFO("  lf: %s", calld->linkdev);
774
    VIR_INFO(" mac: %s", virMacAddrFormat(&calld->macaddress, macaddr));
775 776
    ignore_value(virNetDevVPortProfileAssociate(calld->cr_ifname,
                                                calld->virtPortProfile,
777
                                                &calld->macaddress,
778
                                                calld->linkdev,
779
                                                calld->vf,
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
                                                calld->vmuuid,
                                                calld->vmOp, true));
    *handled = true;
    return;
}

/**
 * virNetlinkCallbackDataFree
 *
 * @calld: pointer to a virNetlinkCallbackData object to free
 *
 * This function frees all the data associated with a virNetlinkCallbackData object
 * as well as the object itself. If called with NULL, it does nothing.
 *
 * Returns nothing.
 */
static void
virNetlinkCallbackDataFree(virNetlinkCallbackDataPtr calld)
{
    if (calld) {
        VIR_FREE(calld->cr_ifname);
        VIR_FREE(calld->virtPortProfile);
        VIR_FREE(calld->linkdev);
    }
    VIR_FREE(calld);
}

/**
 * virNetDevMacVLanVPortProfileDestroyCallback:
 *
 * @watch: watch whose handle to remove
 * @macaddr: macaddr whose handle to remove
 * @opaque: Contains vital information regarding the associated vm
 *
 * This function is called when a netlink message handler is terminated.
 * The function frees locally allocated data referenced in the opaque
 * data, and the opaque object itself.
 */
static void
J
Ján Tomko 已提交
819 820
virNetDevMacVLanVPortProfileDestroyCallback(int watch G_GNUC_UNUSED,
                                            const virMacAddr *macaddr G_GNUC_UNUSED,
821 822 823 824 825
                                            void *opaque)
{
    virNetlinkCallbackDataFree((virNetlinkCallbackDataPtr)opaque);
}

826
int
827
virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
828
                                             const virMacAddr *macaddress,
829 830 831
                                             const char *linkdev,
                                             const unsigned char *vmuuid,
                                             virNetDevVPortProfilePtr virtPortProfile,
832
                                             virNetDevVPortProfileOp vmOp)
833 834 835
{
    virNetlinkCallbackDataPtr calld = NULL;

836
    if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
837
        if (VIR_ALLOC(calld) < 0)
838
            goto error;
839
        calld->cr_ifname = g_strdup(ifname);
840
        if (VIR_ALLOC(calld->virtPortProfile) < 0)
841
            goto error;
842
        memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
843
        virMacAddrSet(&calld->macaddress, macaddress);
844
        calld->linkdev = g_strdup(linkdev);
S
Stefan Berger 已提交
845
        memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid));
846 847 848 849 850

        calld->vmOp = vmOp;

        if (virNetlinkEventAddClient(virNetDevMacVLanVPortProfileCallback,
                                     virNetDevMacVLanVPortProfileDestroyCallback,
851
                                     calld, macaddress, NETLINK_ROUTE) < 0)
852 853 854 855 856
            goto error;
    }

    return 0;

857
 error:
858 859 860 861
    virNetlinkCallbackDataFree(calld);
    return -1;
}

862

863
/**
864
 * virNetDevMacVLanCreateWithVPortProfile:
865 866
 * Create an instance of a macvtap device and open its tap character
 * device.
867 868 869 870 871 872 873 874

 * @ifnameRequested: Interface name that the caller wants the macvtap
 *    device to have, or NULL to pick the first available name
 *    appropriate for the type (macvlan%d or macvtap%d). If the
 *    suggested name fits one of those patterns, but is already in
 *    use, we will fallback to finding the first available. If the
 *    suggested name *doesn't* fit a pattern and the name is in use,
 *    we will fail.
875 876
 * @macaddress: The MAC address for the macvtap device
 * @linkdev: The interface name of the NIC to connect to the external bridge
877
 * @mode: macvtap mode (VIR_NETDEV_MACVLAN_MODE_(BRIDGE|VEPA|PRIVATE|PASSTHRU)
878 879
 * @vmuuid: The UUID of the VM the macvtap belongs to
 * @virtPortProfile: pointer to object holding the virtual port profile data
880
 * @ifnameResult: Pointer to a string pointer where the actual name of the
881 882
 *     interface will be stored into if everything succeeded. It is up
 *     to the caller to free the string.
883 884
 * @tapfd: array of file descriptor return value for the new tap device
 * @tapfdSize: number of file descriptors in @tapfd
885
 * @flags: OR of virNetDevMacVLanCreateFlags.
886
 *
887 888 889 890 891
 * Creates a macvlan device. Optionally, if flags &
 * VIR_NETDEV_MACVLAN_CREATE_WITH_TAP is set, @tapfd is populated with FDs of
 * tap devices up to @tapfdSize.
 *
 * Return 0 on success, -1 on error.
892
 */
893 894 895 896 897
int
virNetDevMacVLanCreateWithVPortProfile(const char *ifnameRequested,
                                       const virMacAddr *macaddress,
                                       const char *linkdev,
                                       virNetDevMacVLanMode mode,
898
                                       virNetDevVlanPtr vlan,
899 900 901 902 903 904 905 906
                                       const unsigned char *vmuuid,
                                       virNetDevVPortProfilePtr virtPortProfile,
                                       char **ifnameResult,
                                       virNetDevVPortProfileOp vmOp,
                                       char *stateDir,
                                       int *tapfd,
                                       size_t tapfdSize,
                                       unsigned int flags)
907
{
908
    const char *type = VIR_NET_GENERATED_PREFIX;
909
    const char *pattern = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
910
        VIR_NET_GENERATED_MACVTAP_PATTERN : VIR_NET_GENERATED_MACVLAN_PATTERN;
911
    int reservedID = -1;
912 913 914
    char ifname[IFNAMSIZ];
    int retries, do_retry = 0;
    uint32_t macvtapMode;
915
    const char *ifnameCreated = NULL;
916
    int vf = -1;
917
    bool vnet_hdr = flags & VIR_NETDEV_MACVLAN_VNET_HDR;
918 919 920

    macvtapMode = modeMap[mode];

921
    *ifnameResult = NULL;
922 923 924 925 926 927 928 929

    /** Note: When using PASSTHROUGH mode with MACVTAP devices the link
     * device's MAC address must be set to the VMs MAC address. In
     * order to not confuse the first switch or bridge in line this MAC
     * address must be reset when the VM is shut down.
     * This is especially important when using SRIOV capable cards that
     * emulate their switch in firmware.
     */
930

931
    if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
932 933
        bool setVlan = true;

934 935
        if (virtPortProfile &&
            virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_8021QBH) {
936 937 938
            /* The Cisco enic driver (the only SRIOV-capable card that
             * uses 802.1Qbh) doesn't support IFLA_VFINFO_LIST, which
             * is required to get/set the vlan tag of a VF.
939
             */
940
            setVlan = false;
941
        }
942 943 944 945 946 947

        if (virNetDevSaveNetConfig(linkdev, -1, stateDir, setVlan) < 0)
           return -1;

        if (virNetDevSetNetConfig(linkdev, -1, NULL, vlan, macaddress, setVlan) < 0)
           return -1;
948 949
    }

950
    if (ifnameRequested) {
951
        int rc;
952
        bool isAutoName
953 954
            = (STRPREFIX(ifnameRequested, VIR_NET_GENERATED_MACVTAP_PREFIX) ||
               STRPREFIX(ifnameRequested, VIR_NET_GENERATED_MACVLAN_PREFIX));
955

956 957 958
        VIR_INFO("Requested macvtap device name: %s", ifnameRequested);
        virMutexLock(&virNetDevMacVLanCreateMutex);

959
        if ((rc = virNetDevExists(ifnameRequested)) < 0) {
960 961 962
            virMutexUnlock(&virNetDevMacVLanCreateMutex);
            return -1;
        }
963
        if (rc) {
964
            if (isAutoName)
965
                goto create_name;
966
            virReportSystemError(EEXIST,
967 968 969
                                 _("Unable to create %s device %s"),
                                 type, ifnameRequested);
            virMutexUnlock(&virNetDevMacVLanCreateMutex);
970 971
            return -1;
        }
972 973 974 975 976 977 978 979 980 981 982 983 984 985
        if (isAutoName &&
            (reservedID = virNetDevMacVLanReserveName(ifnameRequested, true)) < 0) {
            reservedID = -1;
            goto create_name;
        }

        if (virNetDevMacVLanCreate(ifnameRequested, type, macaddress,
                                   linkdev, macvtapMode, &do_retry) < 0) {
            if (isAutoName) {
                virNetDevMacVLanReleaseName(ifnameRequested);
                reservedID = -1;
                goto create_name;
            }
            virMutexUnlock(&virNetDevMacVLanCreateMutex);
986
            return -1;
987 988 989
        }
        /* virNetDevMacVLanCreate() was successful - use this name */
        ifnameCreated = ifnameRequested;
990
 create_name:
991 992 993 994 995
        virMutexUnlock(&virNetDevMacVLanCreateMutex);
    }

    retries = MACVLAN_MAX_ID;
    while (!ifnameCreated && retries) {
996
        virMutexLock(&virNetDevMacVLanCreateMutex);
997 998 999 1000 1001 1002
        reservedID = virNetDevMacVLanReserveID(reservedID, flags, false, true);
        if (reservedID < 0) {
            virMutexUnlock(&virNetDevMacVLanCreateMutex);
            return -1;
        }
        snprintf(ifname, sizeof(ifname), pattern, reservedID);
1003 1004
        if (virNetDevMacVLanCreate(ifname, type, macaddress, linkdev,
                                   macvtapMode, &do_retry) < 0) {
1005 1006 1007
            virNetDevMacVLanReleaseID(reservedID, flags);
            virMutexUnlock(&virNetDevMacVLanCreateMutex);
            if (!do_retry)
1008
                return -1;
1009 1010 1011 1012
            VIR_INFO("Device %s wasn't reserved but already existed, skipping",
                     ifname);
            retries--;
            continue;
1013
        }
1014
        ifnameCreated = ifname;
1015
        virMutexUnlock(&virNetDevMacVLanCreateMutex);
1016 1017
    }

1018 1019 1020 1021 1022 1023 1024 1025
    if (!ifnameCreated) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("Too many unreserved %s devices in use"),
                       type);
        return -1;
    }

    if (virNetDevVPortProfileAssociate(ifnameCreated,
1026 1027 1028
                                       virtPortProfile,
                                       macaddress,
                                       linkdev,
1029
                                       vf,
1030
                                       vmuuid, vmOp, false) < 0)
1031 1032
        goto link_del_exit;

1033
    if (flags & VIR_NETDEV_MACVLAN_CREATE_IFUP) {
1034
        if (virNetDevSetOnline(ifnameCreated, true) < 0)
1035
            goto disassociate_exit;
1036 1037
    }

1038
    if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) {
1039
        if (virNetDevMacVLanTapOpen(ifnameCreated, tapfd, tapfdSize) < 0)
1040 1041
            goto disassociate_exit;

1042
        if (virNetDevMacVLanTapSetup(tapfd, tapfdSize, vnet_hdr) < 0)
1043
            goto disassociate_exit;
1044

1045
        *ifnameResult = g_strdup(ifnameCreated);
1046
    } else {
1047
        *ifnameResult = g_strdup(ifnameCreated);
1048
    }
1049

1050 1051 1052 1053 1054 1055
    if (vmOp == VIR_NETDEV_VPORT_PROFILE_OP_CREATE ||
        vmOp == VIR_NETDEV_VPORT_PROFILE_OP_RESTORE) {
        /* Only directly register upon a create or restore (restarting
         * a saved image) - migration and libvirtd restart are handled
         * elsewhere.
         */
1056
        if (virNetDevMacVLanVPortProfileRegisterCallback(ifnameCreated, macaddress,
1057 1058
                                                         linkdev, vmuuid,
                                                         virtPortProfile,
1059
                                                         vmOp) < 0)
1060
            goto disassociate_exit;
1061
    }
1062

1063
    return 0;
1064

1065
 disassociate_exit:
1066
    ignore_value(virNetDevVPortProfileDisassociate(ifnameCreated,
1067 1068 1069
                                                   virtPortProfile,
                                                   macaddress,
                                                   linkdev,
1070
                                                   vf,
1071
                                                   vmOp));
1072 1073
    while (tapfdSize--)
        VIR_FORCE_CLOSE(tapfd[tapfdSize]);
1074

1075
 link_del_exit:
1076 1077
    ignore_value(virNetDevMacVLanDelete(ifnameCreated));
    virNetDevMacVLanReleaseName(ifnameCreated);
1078

1079
    return -1;
1080 1081 1082 1083
}


/**
1084
 * virNetDevMacVLanDeleteWithVPortProfile:
1085 1086 1087 1088 1089 1090 1091 1092
 * @ifname : The name of the macvtap interface
 * @linkdev: The interface name of the NIC to connect to the external bridge
 * @virtPortProfile: pointer to object holding the virtual port profile data
 *
 * Delete an interface given its name. Disassociate
 * it with the switch if port profile parameters
 * were provided.
 */
1093
int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
1094
                                           const virMacAddr *macaddr,
1095 1096 1097 1098
                                           const char *linkdev,
                                           int mode,
                                           virNetDevVPortProfilePtr virtPortProfile,
                                           char *stateDir)
1099 1100
{
    int ret = 0;
1101

1102 1103 1104 1105 1106
    if (ifname) {
        if (virNetDevVPortProfileDisassociate(ifname,
                                              virtPortProfile,
                                              macaddr,
                                              linkdev,
1107
                                              -1,
1108 1109
                                              VIR_NETDEV_VPORT_PROFILE_OP_DESTROY) < 0)
            ret = -1;
1110
        if (virNetDevMacVLanDelete(ifname) < 0)
1111
            ret = -1;
1112
        virNetDevMacVLanReleaseName(ifname);
1113
    }
1114

1115
    if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
J
Ján Tomko 已提交
1116 1117 1118
        g_autoptr(virMacAddr) MAC = NULL;
        g_autoptr(virMacAddr) adminMAC = NULL;
        g_autoptr(virNetDevVlan) vlan = NULL;
1119

1120 1121
        if ((virNetDevReadNetConfig(linkdev, -1, stateDir,
                                    &adminMAC, &vlan, &MAC) == 0) &&
1122
            (adminMAC || vlan || MAC)) {
1123 1124 1125 1126

            ignore_value(virNetDevSetNetConfig(linkdev, -1,
                                               adminMAC, vlan, MAC, !!vlan));
        }
1127 1128
    }

1129
    virNetlinkEventRemoveClient(0, macaddr, NETLINK_ROUTE);
1130

1131 1132 1133
    return ret;
}

1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
/**
 * virNetDevMacVLanRestartWithVPortProfile:
 * Register a port profile callback handler for a VM that
 * is already running
 * .
 * @cr_ifname: Interface name that the macvtap has.
 * @macaddress: The MAC address for the macvtap device
 * @linkdev: The interface name of the NIC to connect to the external bridge
 * @vmuuid: The UUID of the VM the macvtap belongs to
 * @virtPortProfile: pointer to object holding the virtual port profile data
 * @vmOp: Operation to use during setup of the association
 *
 * Returns 0; returns -1 on error.
 */
int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname,
1149 1150 1151 1152 1153
                                            const virMacAddr *macaddress,
                                            const char *linkdev,
                                            const unsigned char *vmuuid,
                                            virNetDevVPortProfilePtr virtPortProfile,
                                            virNetDevVPortProfileOp vmOp)
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
{
    int rc = 0;

    rc = virNetDevMacVLanVPortProfileRegisterCallback(cr_ifname, macaddress,
                                                      linkdev, vmuuid,
                                                      virtPortProfile, vmOp);
    if (rc < 0)
        goto error;

    ignore_value(virNetDevVPortProfileAssociate(cr_ifname,
                                                virtPortProfile,
                                                macaddress,
                                                linkdev,
                                                -1,
                                                vmuuid,
                                                vmOp, true));

1171
 error:
1172 1173 1174 1175
    return rc;

}

1176
#else /* ! WITH_MACVTAP */
J
Ján Tomko 已提交
1177
bool virNetDevMacVLanIsMacvtap(const char *ifname G_GNUC_UNUSED)
1178 1179 1180 1181 1182 1183
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return false;
}

J
Ján Tomko 已提交
1184 1185 1186 1187 1188 1189
int virNetDevMacVLanCreate(const char *ifname G_GNUC_UNUSED,
                           const char *type G_GNUC_UNUSED,
                           const virMacAddr *macaddress G_GNUC_UNUSED,
                           const char *srcdev G_GNUC_UNUSED,
                           uint32_t macvlan_mode G_GNUC_UNUSED,
                           int *retry G_GNUC_UNUSED)
1190 1191 1192 1193 1194 1195
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}

J
Ján Tomko 已提交
1196
int virNetDevMacVLanDelete(const char *ifname G_GNUC_UNUSED)
1197 1198 1199 1200 1201 1202
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}

1203
int
J
Ján Tomko 已提交
1204 1205 1206
virNetDevMacVLanTapOpen(const char *ifname G_GNUC_UNUSED,
                        int *tapfd G_GNUC_UNUSED,
                        size_t tapfdSize G_GNUC_UNUSED)
1207 1208 1209 1210 1211 1212 1213
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}

int
J
Ján Tomko 已提交
1214 1215 1216
virNetDevMacVLanTapSetup(int *tapfd G_GNUC_UNUSED,
                         size_t tapfdSize G_GNUC_UNUSED,
                         bool vnet_hdr G_GNUC_UNUSED)
1217 1218 1219 1220 1221 1222
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}

J
Ján Tomko 已提交
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
int virNetDevMacVLanCreateWithVPortProfile(const char *ifname G_GNUC_UNUSED,
                                           const virMacAddr *macaddress G_GNUC_UNUSED,
                                           const char *linkdev G_GNUC_UNUSED,
                                           virNetDevMacVLanMode mode G_GNUC_UNUSED,
                                           virNetDevVlanPtr vlan G_GNUC_UNUSED,
                                           const unsigned char *vmuuid G_GNUC_UNUSED,
                                           virNetDevVPortProfilePtr virtPortProfile G_GNUC_UNUSED,
                                           char **res_ifname G_GNUC_UNUSED,
                                           virNetDevVPortProfileOp vmop G_GNUC_UNUSED,
                                           char *stateDir G_GNUC_UNUSED,
                                           int *tapfd G_GNUC_UNUSED,
                                           size_t tapfdSize G_GNUC_UNUSED,
                                           unsigned int unused_flags G_GNUC_UNUSED)
1236 1237 1238 1239 1240 1241
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}

J
Ján Tomko 已提交
1242 1243 1244 1245 1246 1247
int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname G_GNUC_UNUSED,
                                           const virMacAddr *macaddress G_GNUC_UNUSED,
                                           const char *linkdev G_GNUC_UNUSED,
                                           int mode G_GNUC_UNUSED,
                                           virNetDevVPortProfilePtr virtPortProfile G_GNUC_UNUSED,
                                           char *stateDir G_GNUC_UNUSED)
1248 1249 1250 1251 1252
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}
1253

J
Ján Tomko 已提交
1254 1255 1256 1257 1258 1259
int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname G_GNUC_UNUSED,
                                            const virMacAddr *macaddress G_GNUC_UNUSED,
                                            const char *linkdev G_GNUC_UNUSED,
                                            const unsigned char *vmuuid G_GNUC_UNUSED,
                                            virNetDevVPortProfilePtr virtPortProfile G_GNUC_UNUSED,
                                            virNetDevVPortProfileOp vmOp G_GNUC_UNUSED)
1260 1261 1262 1263 1264
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}
1265

J
Ján Tomko 已提交
1266 1267 1268 1269 1270 1271
int virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname G_GNUC_UNUSED,
                                                 const virMacAddr *macaddress G_GNUC_UNUSED,
                                                 const char *linkdev G_GNUC_UNUSED,
                                                 const unsigned char *vmuuid G_GNUC_UNUSED,
                                                 virNetDevVPortProfilePtr virtPortProfile G_GNUC_UNUSED,
                                                 virNetDevVPortProfileOp vmOp G_GNUC_UNUSED)
1272 1273 1274 1275 1276
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}
1277

J
Ján Tomko 已提交
1278
int virNetDevMacVLanReleaseName(const char *name G_GNUC_UNUSED)
1279 1280 1281 1282 1283 1284
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}

J
Ján Tomko 已提交
1285 1286
int virNetDevMacVLanReserveName(const char *name G_GNUC_UNUSED,
                                bool quietFail G_GNUC_UNUSED)
1287 1288 1289 1290 1291
{
    virReportSystemError(ENOSYS, "%s",
                         _("Cannot create macvlan devices on this platform"));
    return -1;
}
1292
#endif /* ! WITH_MACVTAP */