interface_conf.h 7.6 KB
Newer Older
1 2 3
/*
 * interface_conf.h: interface XML handling entry points
 *
E
Eric Blake 已提交
4
 * Copyright (C) 2006-2009, 2013 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22 23 24
 *
 * Author: Daniel Veillard <veillard@redhat.com>
 *         Laine Stump <laine@redhat.com>
 */

#ifndef __INTERFACE_CONF_H__
25
# define __INTERFACE_CONF_H__
26

27 28 29
# include <libxml/parser.h>
# include <libxml/tree.h>
# include <libxml/xpath.h>
30

31
# include "internal.h"
32
# include "virutil.h"
33
# include "virthread.h"
34 35 36

/* There is currently 3 types of interfaces */

37
typedef enum {
38 39 40 41 42 43
    VIR_INTERFACE_TYPE_ETHERNET,  /* simple ethernet */
    VIR_INTERFACE_TYPE_BRIDGE,    /* bridge interface */
    VIR_INTERFACE_TYPE_BOND,      /* bonding interface */
    VIR_INTERFACE_TYPE_VLAN,      /* vlan description */

    VIR_INTERFACE_TYPE_LAST,
44
} virInterfaceType;
45 46 47 48 49

VIR_ENUM_DECL(virInterface)

/* types of start mode */

50
typedef enum {
51 52
    VIR_INTERFACE_START_UNSPECIFIED = 0, /* not given in config */
    VIR_INTERFACE_START_NONE,     /* specified as not defined */
53 54
    VIR_INTERFACE_START_ONBOOT,   /* startup at boot */
    VIR_INTERFACE_START_HOTPLUG,  /* on hotplug */
55
} virInterfaceStartMode;
56

57
typedef enum {
58 59 60 61 62 63 64 65
    VIR_INTERFACE_BOND_NONE = 0,
    VIR_INTERFACE_BOND_BALRR,     /* balance-rr */
    VIR_INTERFACE_BOND_ABACKUP,   /* active backup */
    VIR_INTERFACE_BOND_BALXOR,    /* balance-xor */
    VIR_INTERFACE_BOND_BCAST,     /* broadcast */
    VIR_INTERFACE_BOND_8023AD,    /* 802.3ad */
    VIR_INTERFACE_BOND_BALTLB,    /* balance-tlb */
    VIR_INTERFACE_BOND_BALALB,    /* balance-alb */
66
} virInterfaceBondMode;
67

68
typedef enum {
69 70 71
    VIR_INTERFACE_BOND_MONIT_NONE = 0,
    VIR_INTERFACE_BOND_MONIT_MII, /* mii based monitoring */
    VIR_INTERFACE_BOND_MONIT_ARP, /* arp based monitoring */
72
} virInterfaceBondMonit;
73

74
typedef enum {
75 76 77
    VIR_INTERFACE_BOND_MII_NONE = 0,
    VIR_INTERFACE_BOND_MII_IOCTL, /* mii/ethtool ioctl */
    VIR_INTERFACE_BOND_MII_NETIF, /* netif_carrier_ok */
78
} virInterfaceBondMiiCarrier;
79

80
typedef enum {
81 82 83 84
    VIR_INTERFACE_BOND_ARP_NONE = 0,
    VIR_INTERFACE_BOND_ARP_ACTIVE, /* validate active */
    VIR_INTERFACE_BOND_ARP_BACKUP, /* validate backup */
    VIR_INTERFACE_BOND_ARP_ALL,    /* validate all */
85
} virInterfaceBondArpValid;
86

87
struct _virInterfaceDef; /* forward declaration required for bridge/bond */
88 89 90 91 92

typedef struct _virInterfaceBridgeDef virInterfaceBridgeDef;
typedef virInterfaceBridgeDef *virInterfaceBridgeDefPtr;
struct _virInterfaceBridgeDef {
    int stp;         /* 0, 1 or -1 if undefined */
93
    char *delay;
94
    int nbItf;       /* number of defined interfaces */
95
    struct _virInterfaceDef **itf;/* interfaces */
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
};

typedef struct _virInterfaceBondDef virInterfaceBondDef;
typedef virInterfaceBondDef *virInterfaceBondDefPtr;
struct _virInterfaceBondDef {
    int mode;                    /* virInterfaceBondMode */
    int monit;                   /* virInterfaceBondMonit */
    int frequency;               /* miimon frequency in ms */
    int downdelay;               /* miimon downdelay */
    int updelay;                 /* miimon updelay */
    int carrier;                 /* virInterfaceBondMiiCarrier */
    int interval;                /* arp monitoring interval */
    char *target;                /* arp monitoring target */
    int validate;                /* virInterfaceBondArpmValid */
    int nbItf;                   /* number of defined interfaces */
111
    struct _virInterfaceDef **itf; /* interfaces ethernet only */
112 113 114 115 116 117 118 119 120
};

typedef struct _virInterfaceVlanDef virInterfaceVlanDef;
typedef virInterfaceVlanDef *virInterfaceVlanDefPtr;
struct _virInterfaceVlanDef {
    char *tag;       /* TAG for vlan */
    char *devname;   /* device name for vlan */
};

121 122 123 124 125 126 127 128
typedef struct _virInterfaceIpDef virInterfaceIpDef;
typedef virInterfaceIpDef *virInterfaceIpDefPtr;
struct _virInterfaceIpDef {
    char *address;   /* ip address */
    int prefix;      /* ip prefix */
};


129 130 131
typedef struct _virInterfaceProtocolDef virInterfaceProtocolDef;
typedef virInterfaceProtocolDef *virInterfaceProtocolDefPtr;
struct _virInterfaceProtocolDef {
132
    char *family;    /* ipv4 or ipv6 */
133 134
    int dhcp;        /* use dhcp */
    int peerdns;     /* dhcp peerdns ? */
135 136 137
    int autoconf;    /* only useful if family is ipv6 */
    int nips;
    virInterfaceIpDefPtr *ips; /* ptr to array of ips[nips] */
138 139 140 141 142 143 144 145 146 147 148 149
    char *gateway;   /* route gateway */
};


typedef struct _virInterfaceDef virInterfaceDef;
typedef virInterfaceDef *virInterfaceDefPtr;
struct _virInterfaceDef {
    int type;                /* interface type */
    char *name;              /* interface name */
    unsigned int mtu;        /* maximum transmit size in byte */
    char *mac;               /* MAC address */

150
    virInterfaceStartMode startmode; /* how it is started */
151 152 153 154 155 156 157

    union {
        virInterfaceBridgeDef bridge;
        virInterfaceVlanDef vlan;
        virInterfaceBondDef bond;
    } data;

158 159
    int nprotos;
    virInterfaceProtocolDefPtr *protos; /* ptr to array of protos[nprotos] */
160 161 162 163 164 165 166
};

typedef struct _virInterfaceObj virInterfaceObj;
typedef virInterfaceObj *virInterfaceObjPtr;
struct _virInterfaceObj {
    virMutex lock;

M
Michal Privoznik 已提交
167
    bool active;           /* true if interface is active (up) */
168 169 170 171 172 173
    virInterfaceDefPtr def; /* The interface definition */
};

typedef struct _virInterfaceObjList virInterfaceObjList;
typedef virInterfaceObjList *virInterfaceObjListPtr;
struct _virInterfaceObjList {
174
    size_t count;
175 176 177
    virInterfaceObjPtr *objs;
};

M
Michal Privoznik 已提交
178
static inline bool
E
Eric Blake 已提交
179
virInterfaceObjIsActive(const virInterfaceObj *iface)
180 181 182 183
{
    return iface->active;
}

E
Eric Blake 已提交
184
int virInterfaceFindByMACString(virInterfaceObjListPtr interfaces,
185 186
                                const char *mac,
                                virInterfaceObjPtr *matches, int maxmatches);
E
Eric Blake 已提交
187
virInterfaceObjPtr virInterfaceFindByName(virInterfaceObjListPtr interfaces,
188 189 190 191
                                          const char *name);


void virInterfaceDefFree(virInterfaceDefPtr def);
192
void virInterfaceObjFree(virInterfaceObjPtr iface);
193
void virInterfaceObjListFree(virInterfaceObjListPtr vms);
194 195 196
int virInterfaceObjListClone(virInterfaceObjListPtr src,
                             virInterfaceObjListPtr dest);

197

198
virInterfaceObjPtr virInterfaceAssignDef(virInterfaceObjListPtr interfaces,
E
Eric Blake 已提交
199
                                         virInterfaceDefPtr def);
200
void virInterfaceRemove(virInterfaceObjListPtr interfaces,
E
Eric Blake 已提交
201
                        virInterfaceObjPtr iface);
202

203 204 205
virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr);
virInterfaceDefPtr virInterfaceDefParseFile(const char *filename);
virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml,
206 207
                                            xmlNodePtr root);

E
Eric Blake 已提交
208
char *virInterfaceDefFormat(const virInterfaceDef *def);
209 210 211 212

void virInterfaceObjLock(virInterfaceObjPtr obj);
void virInterfaceObjUnlock(virInterfaceObjPtr obj);

213 214 215
typedef bool (*virInterfaceObjListFilter)(virConnectPtr conn,
                                          virInterfaceDefPtr def);

O
Osier Yang 已提交
216
# define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE   \
217 218 219
                (VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
                 VIR_CONNECT_LIST_INTERFACES_INACTIVE)

220
#endif /* __INTERFACE_CONF_H__ */