You need to sign in or sign up before continuing.
network_conf.h 12.1 KB
Newer Older
1 2 3
/*
 * network_conf.h: network XML handling
 *
4
 * Copyright (C) 2006-2016 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 2006-2008 Daniel P. Berrange
 *
 * 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
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21
 */

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#pragma once

#define DNS_RECORD_LENGTH_SRV  (512 - 30)  /* Limit minus overhead as mentioned in RFC-2782 */

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>

#include "internal.h"
#include "virthread.h"
#include "virsocketaddr.h"
#include "virnetdevbandwidth.h"
#include "virnetdevvportprofile.h"
#include "virnetdevvlan.h"
#include "virmacaddr.h"
#include "device_conf.h"
#include "virbitmap.h"
#include "networkcommon_conf.h"
#include "virobject.h"
#include "virmacmap.h"
#include "virenum.h"
43

C
Cole Robinson 已提交
44 45 46 47 48 49 50 51

struct _virNetworkXMLOption {
    virObject parent;
};
typedef struct _virNetworkXMLOption virNetworkXMLOption;
typedef virNetworkXMLOption *virNetworkXMLOptionPtr;


52
typedef enum {
53 54 55
    VIR_NETWORK_FORWARD_NONE   = 0,
    VIR_NETWORK_FORWARD_NAT,
    VIR_NETWORK_FORWARD_ROUTE,
56
    VIR_NETWORK_FORWARD_OPEN,
57 58 59 60
    VIR_NETWORK_FORWARD_BRIDGE,
    VIR_NETWORK_FORWARD_PRIVATE,
    VIR_NETWORK_FORWARD_VEPA,
    VIR_NETWORK_FORWARD_PASSTHROUGH,
61
    VIR_NETWORK_FORWARD_HOSTDEV,
62 63

    VIR_NETWORK_FORWARD_LAST,
64
} virNetworkForwardType;
65

66 67 68 69 70 71 72 73
typedef enum {
   VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_DEFAULT = 0,
   VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_KERNEL,
   VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT,

   VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LAST,
} virNetworkBridgeMACTableManagerType;

74
VIR_ENUM_DECL(virNetworkBridgeMACTableManager);
75

76
typedef enum {
77 78 79 80 81 82
    VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NONE = 0,
    VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI,
    VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV,
    /* USB Device to be added here when supported */

    VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_LAST,
83
} virNetworkForwardHostdevDeviceType;
84

85 86 87 88 89 90 91 92 93 94 95 96
/* The backend driver used for devices from the pool. Currently used
 * only for PCI devices (vfio vs. kvm), but could be used for other
 * device types in the future.
 */
typedef enum {
    VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT, /* kvm now, could change */
    VIR_NETWORK_FORWARD_DRIVER_NAME_KVM,    /* force legacy kvm style */
    VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO,   /* force vfio */

    VIR_NETWORK_FORWARD_DRIVER_NAME_LAST
} virNetworkForwardDriverNameType;

97
VIR_ENUM_DECL(virNetworkForwardDriverName);
98

99 100 101 102
typedef struct _virNetworkDHCPHostDef virNetworkDHCPHostDef;
typedef virNetworkDHCPHostDef *virNetworkDHCPHostDefPtr;
struct _virNetworkDHCPHostDef {
    char *mac;
103
    char *id;
104
    char *name;
105
    virSocketAddr ip;
106 107
};

108 109 110
typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef;
typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr;
struct _virNetworkDNSTxtDef {
111 112 113 114
    char *name;
    char *value;
};

115 116 117
typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr;
struct _virNetworkDNSSrvDef {
118 119 120 121
    char *domain;
    char *service;
    char *protocol;
    char *target;
122 123 124
    unsigned int port;
    unsigned int priority;
    unsigned int weight;
125 126
};

127 128 129
typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
struct _virNetworkDNSHostDef {
130
    virSocketAddr ip;
131
    size_t nnames;
132
    char **names;
133
};
134

135

136 137 138
typedef struct _virNetworkDNSForwarder virNetworkDNSForwarder;
typedef virNetworkDNSForwarder *virNetworkDNSForwarderPtr;
struct _virNetworkDNSForwarder {
139 140
    virSocketAddr addr;
    char *domain;
141
};
142

143 144
typedef struct _virNetworkDNSDef virNetworkDNSDef;
typedef virNetworkDNSDef *virNetworkDNSDefPtr;
145
struct _virNetworkDNSDef {
146
    int enable;            /* enum virTristateBool */
J
Ján Tomko 已提交
147
    int forwardPlainNames; /* enum virTristateBool */
148 149 150 151 152 153
    size_t ntxts;
    virNetworkDNSTxtDefPtr txts;
    size_t nhosts;
    virNetworkDNSHostDefPtr hosts;
    size_t nsrvs;
    virNetworkDNSSrvDefPtr srvs;
154
    size_t nfwds;
155
    virNetworkDNSForwarderPtr forwarders;
156
};
157

158 159 160
typedef struct _virNetworkIPDef virNetworkIPDef;
typedef virNetworkIPDef *virNetworkIPDefPtr;
struct _virNetworkIPDef {
161 162 163 164 165
    char *family;               /* ipv4 or ipv6 - default is ipv4 */
    virSocketAddr address;      /* Bridge IP address */

    /* One or the other of the following two will be used for a given
     * IP address, but never both. The parser guarantees this.
166
     * Use virNetworkIPDefPrefix/virNetworkIPDefNetmask rather
167 168 169 170 171 172
     * than accessing the data directly - these utility functions
     * will convert one into the other as necessary.
     */
    unsigned int prefix;        /* ipv6 - only prefix allowed */
    virSocketAddr netmask;      /* ipv4 - either netmask or prefix specified */

173 174
    int localPTR; /* virTristateBool */

175
    size_t nranges;             /* Zero or more dhcp ranges */
176
    virSocketAddrRangePtr ranges;
177

178
    size_t nhosts;              /* Zero or more dhcp hosts */
179 180 181 182 183 184 185
    virNetworkDHCPHostDefPtr hosts;

    char *tftproot;
    char *bootfile;
    virSocketAddr bootserver;
   };

186 187 188
typedef struct _virNetworkForwardIfDef virNetworkForwardIfDef;
typedef virNetworkForwardIfDef *virNetworkForwardIfDefPtr;
struct _virNetworkForwardIfDef {
189 190
    int type;
    union {
191
        virPCIDeviceAddress pci; /*PCI Address of device */
192 193 194 195
        /* when USB devices are supported a new variable to be added here */
        char *dev;      /* name of device */
    }device;
    int connections; /* how many guest interfaces are connected to this device? */
196 197
};

198 199 200 201
typedef struct _virNetworkForwardPfDef virNetworkForwardPfDef;
typedef virNetworkForwardPfDef *virNetworkForwardPfDefPtr;
struct _virNetworkForwardPfDef {
    char *dev;      /* name of device */
202
    int connections; /* how many guest interfaces are connected to this device? */
203 204
};

205 206 207 208 209
typedef struct _virNetworkForwardDef virNetworkForwardDef;
typedef virNetworkForwardDef *virNetworkForwardDefPtr;
struct _virNetworkForwardDef {
    int type;     /* One of virNetworkForwardType constants */
    bool managed;  /* managed attribute for hostdev mode */
210
    int driverName; /* enum virNetworkForwardDriverNameType */
211 212 213 214 215 216 217 218 219

    /* If there are multiple forward devices (i.e. a pool of
     * interfaces), they will be listed here.
     */
    size_t npfs;
    virNetworkForwardPfDefPtr pfs;

    size_t nifs;
    virNetworkForwardIfDefPtr ifs;
220

221
    /* ranges for NAT */
222 223
    virSocketAddrRange addr;
    virPortRange port;
224 225
};

226 227 228 229 230
typedef struct _virPortGroupDef virPortGroupDef;
typedef virPortGroupDef *virPortGroupDefPtr;
struct _virPortGroupDef {
    char *name;
    bool isDefault;
231
    virNetDevVPortProfilePtr virtPortProfile;
232
    virNetDevBandwidthPtr bandwidth;
233
    virNetDevVlan vlan;
234
    int trustGuestRxFilters; /* enum virTristateBool */
235 236
};

237 238 239 240
typedef struct _virNetworkDef virNetworkDef;
typedef virNetworkDef *virNetworkDefPtr;
struct _virNetworkDef {
    unsigned char uuid[VIR_UUID_BUFLEN];
M
Matthias Bolte 已提交
241
    bool uuid_specified;
242
    char *name;
243
    int   connections; /* # of guest interfaces connected to this network */
244 245

    char *bridge;       /* Name of bridge device */
246
    char *bridgeZone;  /* name of firewalld zone for bridge */
247
    int  macTableManager; /* enum virNetworkBridgeMACTableManager */
248
    char *domain;
249
    int domainLocalOnly; /* enum virTristateBool: yes disables dns forwarding */
250
    unsigned long delay;   /* Bridge forward delay (ms) */
251
    bool stp; /* Spanning tree protocol */
252
    unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in config */
253
    virMacAddr mac; /* mac address of bridge device */
254
    bool mac_specified;
255

256 257 258 259 260
    /* specified if ip6tables rules added
     * when no ipv6 gateway addresses specified.
     */
    bool ipv6nogw;

261
    virNetworkForwardDef forward;
262

263
    size_t nips;
264
    virNetworkIPDefPtr ips; /* ptr to array of IP addresses on this network */
265

266
    size_t nroutes;
267
    virNetDevIPRoutePtr *routes; /* ptr to array of static routes on this interface */
268

269
    virNetworkDNSDef dns;   /* dns related configuration */
270
    virNetDevVPortProfilePtr virtPortProfile;
271 272 273

    size_t nPortGroups;
    virPortGroupDefPtr portGroups;
274
    virNetDevBandwidthPtr bandwidth;
275
    virNetDevVlan vlan;
276
    int trustGuestRxFilters; /* enum virTristateBool */
277 278 279

    /* Application-specific custom metadata */
    xmlNodePtr metadata;
280 281
};

282
typedef enum {
283 284 285 286 287 288 289 290
    VIR_NETWORK_TAINT_HOOK,                 /* Hook script was executed over
                                               network. We can't guarantee
                                               connectivity or other settings
                                               as the script may have played
                                               with iptables, tc, you name it.
                                             */

    VIR_NETWORK_TAINT_LAST
291
} virNetworkTaintFlags;
292

293
void virNetworkDefFree(virNetworkDefPtr def);
294

295 296 297 298
enum {
    VIR_NETWORK_OBJ_LIST_ADD_LIVE = (1 << 0),
    VIR_NETWORK_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
};
299

C
Cole Robinson 已提交
300 301 302
virNetworkXMLOptionPtr
virNetworkXMLOptionNew(void);

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
virNetworkDefPtr
virNetworkDefCopy(virNetworkDefPtr def, unsigned int flags);

virNetworkDefPtr
virNetworkDefParseXML(xmlXPathContextPtr ctxt);

virNetworkDefPtr
virNetworkDefParseString(const char *xmlStr);

virNetworkDefPtr
virNetworkDefParseFile(const char *filename);

virNetworkDefPtr
virNetworkDefParseNode(xmlDocPtr xml,
                       xmlNodePtr root);

char *
virNetworkDefFormat(const virNetworkDef *def,
                    unsigned int flags);

int
virNetworkDefFormatBuf(virBufferPtr buf,
                       const virNetworkDef *def,
                       unsigned int flags);

const char *
virNetworkDefForwardIf(const virNetworkDef *def,
                       size_t n);

virPortGroupDefPtr
virPortGroupFindByName(virNetworkDefPtr net,
                       const char *portgroup);
335

336 337
virNetworkIPDefPtr
virNetworkDefGetIPByIndex(const virNetworkDef *def,
338 339 340
                          int family,
                          size_t n);

341
virNetDevIPRoutePtr
342
virNetworkDefGetRouteByIndex(const virNetworkDef *def,
343 344 345 346 347 348 349 350 351
                             int family,
                             size_t n);

int
virNetworkIPDefPrefix(const virNetworkIPDef *def);

int
virNetworkIPDefNetmask(const virNetworkIPDef *def,
                       virSocketAddrPtr netmask);
352

353 354 355 356
int
virNetworkSaveXML(const char *configDir,
                  virNetworkDefPtr def,
                  const char *xml);
357

358 359 360
int
virNetworkSaveConfig(const char *configDir,
                     virNetworkDefPtr def);
361

362 363 364
char *
virNetworkConfigFile(const char *dir,
                     const char *name);
365

366 367
void
virNetworkSetBridgeMacAddr(virNetworkDefPtr def);
368

369
VIR_ENUM_DECL(virNetworkForward);
M
Matthias Bolte 已提交
370

371
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE \
372 373 374
                (VIR_CONNECT_LIST_NETWORKS_ACTIVE | \
                 VIR_CONNECT_LIST_NETWORKS_INACTIVE)

375
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT \
376 377 378
                (VIR_CONNECT_LIST_NETWORKS_PERSISTENT | \
                 VIR_CONNECT_LIST_NETWORKS_TRANSIENT)

379
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART \
380
                (VIR_CONNECT_LIST_NETWORKS_AUTOSTART | \
381 382
                 VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)

383
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL \
384 385 386 387
                (VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE     | \
                 VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT | \
                 VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART)

J
Ján Tomko 已提交
388 389 390 391 392 393 394 395 396
/* for testing */
int
virNetworkDefUpdateSection(virNetworkDefPtr def,
                           unsigned int command, /* virNetworkUpdateCommand */
                           unsigned int section, /* virNetworkUpdateSection */
                           int parentIndex,
                           const char *xml,
                           unsigned int flags);  /* virNetworkUpdateFlags */

397
VIR_ENUM_DECL(virNetworkTaint);