virnetdevmacvlan.h 5.4 KB
Newer Older
1
/*
2
 * Copyright (C) 2011, 2013, 2016 Red Hat, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15
 * Copyright (C) 2010 IBM Corporation
 *
 * 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
#pragma once
21

22 23 24 25 26 27 28
#include "internal.h"
#include "virmacaddr.h"
#include "virsocketaddr.h"
#include "virnetdevbandwidth.h"
#include "virnetdevvportprofile.h"
#include "virnetdevvlan.h"
#include "virenum.h"
29

30
/* the mode type for macvtap devices */
31
typedef enum {
32 33 34 35
    VIR_NETDEV_MACVLAN_MODE_VEPA,
    VIR_NETDEV_MACVLAN_MODE_PRIVATE,
    VIR_NETDEV_MACVLAN_MODE_BRIDGE,
    VIR_NETDEV_MACVLAN_MODE_PASSTHRU,
36

37
    VIR_NETDEV_MACVLAN_MODE_LAST,
38
} virNetDevMacVLanMode;
39
VIR_ENUM_DECL(virNetDevMacVLanMode);
40

41 42 43 44
typedef enum {
   VIR_NETDEV_MACVLAN_CREATE_NONE     = 0,
   /* Create with a tap device */
   VIR_NETDEV_MACVLAN_CREATE_WITH_TAP = 1 << 0,
45 46
   /* Bring the interface up */
   VIR_NETDEV_MACVLAN_CREATE_IFUP     = 1 << 1,
47 48
   /* Enable VNET_HDR */
   VIR_NETDEV_MACVLAN_VNET_HDR          = 1 << 2,
49 50
} virNetDevMacVLanCreateFlags;

51 52 53
/* libvirt will start macvtap/macvlan interface names with one of
 * these prefixes when it auto-generates the name
 */
54 55
#define VIR_NET_GENERATED_MACVTAP_PREFIX "macvtap"
#define VIR_NET_GENERATED_MACVLAN_PREFIX "macvlan"
56

57 58 59
int virNetDevMacVLanReserveName(const char *name, bool quietfail);
int virNetDevMacVLanReleaseName(const char *name);

60
bool virNetDevMacVLanIsMacvtap(const char *ifname)
61
   ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT G_GNUC_NO_INLINE;
62

63 64
int virNetDevMacVLanCreate(const char *ifname,
                           const char *type,
65
                           const virMacAddr *macaddress,
66 67 68 69
                           const char *srcdev,
                           uint32_t macvlan_mode,
                           int *retry)
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
70
    G_GNUC_WARN_UNUSED_RESULT;
71 72

int virNetDevMacVLanDelete(const char *ifname)
73
    ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
74

75
int virNetDevMacVLanCreateWithVPortProfile(const char *ifname,
76
                                           const virMacAddr *macaddress,
77
                                           const char *linkdev,
78
                                           virNetDevMacVLanMode mode,
79
                                           const virNetDevVlan *vlan,
80
                                           const unsigned char *vmuuid,
81
                                           const virNetDevVPortProfile *virtPortProfile,
82
                                           char **res_ifname,
83
                                           virNetDevVPortProfileOp vmop,
84
                                           char *stateDir,
85 86
                                           int *tapfd,
                                           size_t tapfdSize,
87
                                           unsigned int flags)
88
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(6)
89
    ATTRIBUTE_NONNULL(8) ATTRIBUTE_NONNULL(10) G_GNUC_WARN_UNUSED_RESULT;
90

91 92 93 94
int virNetDevMacVLanTapOpen(const char *ifname,
                            int *tapfd,
                            size_t tapfdSize)
   ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
95
   G_GNUC_WARN_UNUSED_RESULT;
96 97

int virNetDevMacVLanTapSetup(int *tapfd, size_t tapfdSize, bool vnet_hdr)
98
   ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
99

100
int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
101
                                           const virMacAddr *macaddress,
102 103
                                           const char *linkdev,
                                           int mode,
104
                                           const virNetDevVPortProfile *virtPortProfile,
105
                                           char *stateDir)
106
    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
107
    ATTRIBUTE_NONNULL(6) G_GNUC_WARN_UNUSED_RESULT;
108

109
int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname,
110 111 112
                                            const virMacAddr *macaddress,
                                            const char *linkdev,
                                            const unsigned char *vmuuid,
113
                                            const virNetDevVPortProfile *virtPortProfile,
114
                                            virNetDevVPortProfileOp vmOp)
115
    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
116
    ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT;
117

118
int virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
119 120 121
                                                 const virMacAddr *macaddress,
                                                 const char *linkdev,
                                                 const unsigned char *vmuuid,
122
                                                 const virNetDevVPortProfile *virtPortProfile,
123
                                                 virNetDevVPortProfileOp vmOp)
124
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
125
ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT;