2008-07-11 10:48:34 +00:00
|
|
|
/*
|
|
|
|
* network_conf.h: network XML handling
|
|
|
|
*
|
2016-06-08 16:48:50 +00:00
|
|
|
* Copyright (C) 2006-2016 Red Hat, Inc.
|
2008-07-11 10:48:34 +00:00
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-07-11 10:48:34 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-07 20:20:17 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#define DNS_RECORD_LENGTH_SRV (512 - 30) /* Limit minus overhead as mentioned in RFC-2782 */
|
|
|
|
|
|
|
|
#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"
|
2019-08-20 19:52:08 +00:00
|
|
|
#include "virxml.h"
|
2019-07-14 16:11:06 +00:00
|
|
|
|
|
|
|
struct _virNetworkXMLOption {
|
|
|
|
virObject parent;
|
2019-07-14 11:36:44 +00:00
|
|
|
|
2019-08-20 19:52:08 +00:00
|
|
|
virXMLNamespace ns;
|
2019-07-14 16:11:06 +00:00
|
|
|
};
|
|
|
|
typedef struct _virNetworkXMLOption virNetworkXMLOption;
|
|
|
|
typedef virNetworkXMLOption *virNetworkXMLOptionPtr;
|
|
|
|
|
|
|
|
|
2014-04-28 00:15:22 +00:00
|
|
|
typedef enum {
|
2008-07-11 10:48:34 +00:00
|
|
|
VIR_NETWORK_FORWARD_NONE = 0,
|
|
|
|
VIR_NETWORK_FORWARD_NAT,
|
|
|
|
VIR_NETWORK_FORWARD_ROUTE,
|
2016-08-10 23:09:55 +00:00
|
|
|
VIR_NETWORK_FORWARD_OPEN,
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
VIR_NETWORK_FORWARD_BRIDGE,
|
|
|
|
VIR_NETWORK_FORWARD_PRIVATE,
|
|
|
|
VIR_NETWORK_FORWARD_VEPA,
|
|
|
|
VIR_NETWORK_FORWARD_PASSTHROUGH,
|
2012-08-16 15:41:41 +00:00
|
|
|
VIR_NETWORK_FORWARD_HOSTDEV,
|
2008-07-11 10:48:34 +00:00
|
|
|
|
|
|
|
VIR_NETWORK_FORWARD_LAST,
|
2014-04-28 00:15:22 +00:00
|
|
|
} virNetworkForwardType;
|
2008-07-11 10:48:34 +00:00
|
|
|
|
conf: new network bridge device attribute macTableManager
The macTableManager attribute of a network's bridge subelement tells
libvirt how the bridge's MAC address table (used to determine the
egress port for packets) is managed. In the default mode, "kernel",
management is left to the kernel, which usually determines entries in
part by turning on promiscuous mode on all ports of the bridge,
flooding packets to all ports when the correct destination is unknown,
and adding/removing entries to the fdb as it sees incoming traffic
from particular MAC addresses. In "libvirt" mode, libvirt turns off
learning and flooding on all the bridge ports connected to guest
domain interfaces, and adds/removes entries according to the MAC
addresses in the domain interface configurations. A side effect of
turning off learning and unicast_flood on the ports of a bridge is
that (with Linux kernel 3.17 and newer), the kernel can automatically
turn off promiscuous mode on one or more of the bridge's ports
(usually only the one interface that is used to connect the bridge to
the physical network). The result is better performance (because
packets aren't being flooded to all ports, and can be dropped earlier
when they are of no interest) and slightly better security (a guest
can still send out packets with a spoofed source MAC address, but will
only receive traffic intended for the guest interface's configured MAC
address).
The attribute looks like this in the configuration:
<network>
<name>test</name>
<bridge name='br0' macTableManager='libvirt'/>
...
This patch only adds the config knob, documentation, and test
cases. The functionality behind this knob is added in later patches.
2014-11-20 17:40:33 +00:00
|
|
|
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;
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virNetworkBridgeMACTableManager);
|
conf: new network bridge device attribute macTableManager
The macTableManager attribute of a network's bridge subelement tells
libvirt how the bridge's MAC address table (used to determine the
egress port for packets) is managed. In the default mode, "kernel",
management is left to the kernel, which usually determines entries in
part by turning on promiscuous mode on all ports of the bridge,
flooding packets to all ports when the correct destination is unknown,
and adding/removing entries to the fdb as it sees incoming traffic
from particular MAC addresses. In "libvirt" mode, libvirt turns off
learning and flooding on all the bridge ports connected to guest
domain interfaces, and adds/removes entries according to the MAC
addresses in the domain interface configurations. A side effect of
turning off learning and unicast_flood on the ports of a bridge is
that (with Linux kernel 3.17 and newer), the kernel can automatically
turn off promiscuous mode on one or more of the bridge's ports
(usually only the one interface that is used to connect the bridge to
the physical network). The result is better performance (because
packets aren't being flooded to all ports, and can be dropped earlier
when they are of no interest) and slightly better security (a guest
can still send out packets with a spoofed source MAC address, but will
only receive traffic intended for the guest interface's configured MAC
address).
The attribute looks like this in the configuration:
<network>
<name>test</name>
<bridge name='br0' macTableManager='libvirt'/>
...
This patch only adds the config knob, documentation, and test
cases. The functionality behind this knob is added in later patches.
2014-11-20 17:40:33 +00:00
|
|
|
|
2014-04-28 00:15:22 +00:00
|
|
|
typedef enum {
|
2012-08-16 15:41:41 +00:00
|
|
|
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,
|
2014-04-28 00:15:22 +00:00
|
|
|
} virNetworkForwardHostdevDeviceType;
|
2012-08-16 15:41:41 +00:00
|
|
|
|
2020-04-22 20:05:57 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_NETWORK_DHCP_LEASETIME_UNIT_SECONDS = 0,
|
|
|
|
VIR_NETWORK_DHCP_LEASETIME_UNIT_MINUTES,
|
|
|
|
VIR_NETWORK_DHCP_LEASETIME_UNIT_HOURS,
|
|
|
|
|
|
|
|
VIR_NETWORK_DHCP_LEASETIME_UNIT_LAST,
|
|
|
|
} virNetworkDHCPLeaseTimeUnitType;
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virNetworkDHCPLeaseTimeUnit);
|
|
|
|
|
2013-04-26 20:23:27 +00:00
|
|
|
/* 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;
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virNetworkForwardDriverName);
|
2013-04-26 20:23:27 +00:00
|
|
|
|
2020-04-22 20:05:57 +00:00
|
|
|
typedef struct _virNetworkDHCPLeaseTimeDef virNetworkDHCPLeaseTimeDef;
|
|
|
|
typedef virNetworkDHCPLeaseTimeDef *virNetworkDHCPLeaseTimeDefPtr;
|
|
|
|
struct _virNetworkDHCPLeaseTimeDef {
|
|
|
|
unsigned long expiry;
|
|
|
|
virNetworkDHCPLeaseTimeUnitType unit;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _virNetworkDHCPRangeDef virNetworkDHCPRangeDef;
|
|
|
|
typedef virNetworkDHCPRangeDef *virNetworkDHCPRangeDefPtr;
|
|
|
|
struct _virNetworkDHCPRangeDef {
|
|
|
|
virSocketAddrRange addr;
|
|
|
|
virNetworkDHCPLeaseTimeDefPtr lease;
|
|
|
|
};
|
|
|
|
|
2008-08-20 12:50:29 +00:00
|
|
|
typedef struct _virNetworkDHCPHostDef virNetworkDHCPHostDef;
|
|
|
|
typedef virNetworkDHCPHostDef *virNetworkDHCPHostDefPtr;
|
|
|
|
struct _virNetworkDHCPHostDef {
|
|
|
|
char *mac;
|
2013-02-15 19:02:26 +00:00
|
|
|
char *id;
|
2008-08-20 12:50:29 +00:00
|
|
|
char *name;
|
Convert virNetwork to use virSocketAddr everywhere
Instead of storing the IP address string in virNetwork related
structs, store the parsed virSocketAddr. This will make it
easier to add IPv6 support in the future, by letting driver
code directly check what address family is present
* src/conf/network_conf.c, src/conf/network_conf.h,
src/network/bridge_driver.c: Convert to use virSocketAddr
in virNetwork, instead of char *.
* src/util/bridge.c, src/util/bridge.h,
src/util/dnsmasq.c, src/util/dnsmasq.h,
src/util/iptables.c, src/util/iptables.h: Convert to
take a virSocketAddr instead of char * for any IP
address parameters
* src/util/network.h: Add macros to determine if an address
is set, and what address family is set.
2010-10-21 12:14:33 +00:00
|
|
|
virSocketAddr ip;
|
2020-04-22 20:05:57 +00:00
|
|
|
virNetworkDHCPLeaseTimeDefPtr lease;
|
2008-08-20 12:50:29 +00:00
|
|
|
};
|
|
|
|
|
2012-11-11 23:59:28 +00:00
|
|
|
typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef;
|
|
|
|
typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr;
|
|
|
|
struct _virNetworkDNSTxtDef {
|
2011-06-24 10:04:36 +00:00
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
};
|
|
|
|
|
2012-11-11 23:59:28 +00:00
|
|
|
typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
|
|
|
|
typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr;
|
|
|
|
struct _virNetworkDNSSrvDef {
|
2012-01-02 14:23:54 +00:00
|
|
|
char *domain;
|
|
|
|
char *service;
|
|
|
|
char *protocol;
|
|
|
|
char *target;
|
conf: clear and parse functions for dns host/srv/txt records
Since there is only a single virNetworkDNSDef for any virNetworkDef,
and it's trivial to determine whether or not it contains any real
data, it's much simpler (and fits more uniformly with the parse
function calling sequence of the parsers for many other objects that
are subordinates of virNetworkDef) if virNetworkDef *contains* an
virNetworkDNSDef rather than pointing to one.
Since it is now just a part of another object rather than its own
object, it no longer makes sense to have a *Free() function, so that
is changed to a *Clear() function.
More importantly though, ParseXML and Clear functions are needed for
the individual items contained in a virNetworkDNSDef (srv, txt, and
host records), but none of them have a *Clear(), and only two of the
three had *ParseXML() functions (both of which used a non-uniform
arglist). Those problems are cleared up by this patch - it splits the
higher-level Clear function into separate functions for each of the
three, creates a parse for txt records, and cleans up the srv and host
parsers, so we now have all the utility functions necessary to
implement virNetworkDefUpdateDNS(Host|Srv|Txt).
2012-11-12 00:00:22 +00:00
|
|
|
unsigned int port;
|
|
|
|
unsigned int priority;
|
|
|
|
unsigned int weight;
|
2012-01-02 14:23:54 +00:00
|
|
|
};
|
|
|
|
|
2012-11-11 23:59:28 +00:00
|
|
|
typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
|
|
|
|
typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
|
|
|
|
struct _virNetworkDNSHostDef {
|
2011-06-24 10:04:40 +00:00
|
|
|
virSocketAddr ip;
|
2014-03-07 08:33:31 +00:00
|
|
|
size_t nnames;
|
2011-06-24 10:04:40 +00:00
|
|
|
char **names;
|
2011-07-04 15:20:02 +00:00
|
|
|
};
|
2011-06-24 10:04:40 +00:00
|
|
|
|
2016-08-12 02:28:27 +00:00
|
|
|
|
2017-03-06 17:39:48 +00:00
|
|
|
typedef struct _virNetworkDNSForwarder virNetworkDNSForwarder;
|
|
|
|
typedef virNetworkDNSForwarder *virNetworkDNSForwarderPtr;
|
|
|
|
struct _virNetworkDNSForwarder {
|
2016-08-12 02:28:27 +00:00
|
|
|
virSocketAddr addr;
|
|
|
|
char *domain;
|
2017-03-06 17:39:48 +00:00
|
|
|
};
|
2016-08-12 02:28:27 +00:00
|
|
|
|
2012-11-11 23:59:28 +00:00
|
|
|
typedef struct _virNetworkDNSDef virNetworkDNSDef;
|
|
|
|
typedef virNetworkDNSDef *virNetworkDNSDefPtr;
|
2011-07-04 15:20:02 +00:00
|
|
|
struct _virNetworkDNSDef {
|
2016-08-11 21:29:43 +00:00
|
|
|
int enable; /* enum virTristateBool */
|
2014-06-27 15:16:54 +00:00
|
|
|
int forwardPlainNames; /* enum virTristateBool */
|
2012-11-11 23:59:28 +00:00
|
|
|
size_t ntxts;
|
|
|
|
virNetworkDNSTxtDefPtr txts;
|
|
|
|
size_t nhosts;
|
|
|
|
virNetworkDNSHostDefPtr hosts;
|
|
|
|
size_t nsrvs;
|
|
|
|
virNetworkDNSSrvDefPtr srvs;
|
2013-09-13 16:31:07 +00:00
|
|
|
size_t nfwds;
|
2016-08-12 02:28:27 +00:00
|
|
|
virNetworkDNSForwarderPtr forwarders;
|
2011-07-04 15:20:02 +00:00
|
|
|
};
|
2011-06-24 10:04:36 +00:00
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
typedef struct _virNetworkIPDef virNetworkIPDef;
|
|
|
|
typedef virNetworkIPDef *virNetworkIPDefPtr;
|
|
|
|
struct _virNetworkIPDef {
|
2010-11-17 18:36:19 +00:00
|
|
|
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.
|
2016-06-08 16:48:50 +00:00
|
|
|
* Use virNetworkIPDefPrefix/virNetworkIPDefNetmask rather
|
2010-11-17 18:36:19 +00:00
|
|
|
* 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 */
|
|
|
|
|
2016-12-08 21:23:09 +00:00
|
|
|
int localPTR; /* virTristateBool */
|
|
|
|
|
2012-10-08 17:42:21 +00:00
|
|
|
size_t nranges; /* Zero or more dhcp ranges */
|
2020-04-22 20:05:57 +00:00
|
|
|
virNetworkDHCPRangeDefPtr ranges;
|
2010-11-17 18:36:19 +00:00
|
|
|
|
2012-10-08 17:42:21 +00:00
|
|
|
size_t nhosts; /* Zero or more dhcp hosts */
|
2010-11-17 18:36:19 +00:00
|
|
|
virNetworkDHCPHostDefPtr hosts;
|
|
|
|
|
|
|
|
char *tftproot;
|
|
|
|
char *bootfile;
|
|
|
|
virSocketAddr bootserver;
|
|
|
|
};
|
|
|
|
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
typedef struct _virNetworkForwardIfDef virNetworkForwardIfDef;
|
|
|
|
typedef virNetworkForwardIfDef *virNetworkForwardIfDefPtr;
|
|
|
|
struct _virNetworkForwardIfDef {
|
2012-08-16 15:41:41 +00:00
|
|
|
int type;
|
|
|
|
union {
|
2016-04-03 18:16:51 +00:00
|
|
|
virPCIDeviceAddress pci; /*PCI Address of device */
|
2012-08-16 15:41:41 +00:00
|
|
|
/* 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? */
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
};
|
|
|
|
|
2012-08-05 06:32:49 +00:00
|
|
|
typedef struct _virNetworkForwardPfDef virNetworkForwardPfDef;
|
|
|
|
typedef virNetworkForwardPfDef *virNetworkForwardPfDefPtr;
|
|
|
|
struct _virNetworkForwardPfDef {
|
|
|
|
char *dev; /* name of device */
|
2012-08-16 15:41:41 +00:00
|
|
|
int connections; /* how many guest interfaces are connected to this device? */
|
2012-08-05 06:32:49 +00:00
|
|
|
};
|
|
|
|
|
2012-11-08 02:16:17 +00:00
|
|
|
typedef struct _virNetworkForwardDef virNetworkForwardDef;
|
|
|
|
typedef virNetworkForwardDef *virNetworkForwardDefPtr;
|
|
|
|
struct _virNetworkForwardDef {
|
|
|
|
int type; /* One of virNetworkForwardType constants */
|
|
|
|
bool managed; /* managed attribute for hostdev mode */
|
2013-04-26 20:23:27 +00:00
|
|
|
int driverName; /* enum virNetworkForwardDriverNameType */
|
2012-11-08 02:16:17 +00:00
|
|
|
|
|
|
|
/* 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;
|
2013-02-19 10:44:14 +00:00
|
|
|
|
2013-02-19 10:44:15 +00:00
|
|
|
/* ranges for NAT */
|
2013-02-19 10:44:16 +00:00
|
|
|
virSocketAddrRange addr;
|
|
|
|
virPortRange port;
|
2020-06-08 13:35:02 +00:00
|
|
|
|
|
|
|
virTristateBool natIPv6;
|
2012-11-08 02:16:17 +00:00
|
|
|
};
|
|
|
|
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
typedef struct _virPortGroupDef virPortGroupDef;
|
|
|
|
typedef virPortGroupDef *virPortGroupDefPtr;
|
|
|
|
struct _virPortGroupDef {
|
|
|
|
char *name;
|
|
|
|
bool isDefault;
|
2011-11-02 14:43:16 +00:00
|
|
|
virNetDevVPortProfilePtr virtPortProfile;
|
Adjust naming of network device bandwidth management APIs
Rename virBandwidth to virNetDevBandwidth, and virRate to
virNetDevBandwidthRate.
* src/util/network.c, src/util/network.h: Rename bandwidth
structs and APIs
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/network_conf.c, src/conf/network_conf.h,
src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/qemu/qemu_command.c, src/util/macvtap.c,
src/util/macvtap.h, tools/virsh.c: Update for API changes.
2011-11-02 14:29:05 +00:00
|
|
|
virNetDevBandwidthPtr bandwidth;
|
2012-08-12 07:51:30 +00:00
|
|
|
virNetDevVlan vlan;
|
2014-09-23 18:19:08 +00:00
|
|
|
int trustGuestRxFilters; /* enum virTristateBool */
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
};
|
|
|
|
|
2008-07-11 10:48:34 +00:00
|
|
|
typedef struct _virNetworkDef virNetworkDef;
|
|
|
|
typedef virNetworkDef *virNetworkDefPtr;
|
|
|
|
struct _virNetworkDef {
|
|
|
|
unsigned char uuid[VIR_UUID_BUFLEN];
|
2012-08-05 20:11:50 +00:00
|
|
|
bool uuid_specified;
|
2008-07-11 10:48:34 +00:00
|
|
|
char *name;
|
2012-08-06 20:17:58 +00:00
|
|
|
int connections; /* # of guest interfaces connected to this network */
|
2008-07-11 10:48:34 +00:00
|
|
|
|
|
|
|
char *bridge; /* Name of bridge device */
|
2019-01-09 21:51:31 +00:00
|
|
|
char *bridgeZone; /* name of firewalld zone for bridge */
|
conf: new network bridge device attribute macTableManager
The macTableManager attribute of a network's bridge subelement tells
libvirt how the bridge's MAC address table (used to determine the
egress port for packets) is managed. In the default mode, "kernel",
management is left to the kernel, which usually determines entries in
part by turning on promiscuous mode on all ports of the bridge,
flooding packets to all ports when the correct destination is unknown,
and adding/removing entries to the fdb as it sees incoming traffic
from particular MAC addresses. In "libvirt" mode, libvirt turns off
learning and flooding on all the bridge ports connected to guest
domain interfaces, and adds/removes entries according to the MAC
addresses in the domain interface configurations. A side effect of
turning off learning and unicast_flood on the ports of a bridge is
that (with Linux kernel 3.17 and newer), the kernel can automatically
turn off promiscuous mode on one or more of the bridge's ports
(usually only the one interface that is used to connect the bridge to
the physical network). The result is better performance (because
packets aren't being flooded to all ports, and can be dropped earlier
when they are of no interest) and slightly better security (a guest
can still send out packets with a spoofed source MAC address, but will
only receive traffic intended for the guest interface's configured MAC
address).
The attribute looks like this in the configuration:
<network>
<name>test</name>
<bridge name='br0' macTableManager='libvirt'/>
...
This patch only adds the config knob, documentation, and test
cases. The functionality behind this knob is added in later patches.
2014-11-20 17:40:33 +00:00
|
|
|
int macTableManager; /* enum virNetworkBridgeMACTableManager */
|
2008-09-08 12:45:29 +00:00
|
|
|
char *domain;
|
2014-12-04 00:01:33 +00:00
|
|
|
int domainLocalOnly; /* enum virTristateBool: yes disables dns forwarding */
|
2008-07-11 10:48:34 +00:00
|
|
|
unsigned long delay; /* Bridge forward delay (ms) */
|
2013-04-12 09:08:59 +00:00
|
|
|
bool stp; /* Spanning tree protocol */
|
2017-01-23 02:23:48 +00:00
|
|
|
unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in config */
|
2012-07-17 12:07:59 +00:00
|
|
|
virMacAddr mac; /* mac address of bridge device */
|
Give each virtual network bridge its own fixed MAC address
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=609463
The problem was that, since a bridge always acquires the MAC address
of the connected interface with the numerically lowest MAC, as guests
are started and stopped, it was possible for the MAC address to change
over time, and this change in the network was being detected by
Windows 7 (it sees the MAC of the default route change), so on each
reboot it would bring up a dialog box asking about this "new network".
The solution is to create a dummy tap interface with a MAC guaranteed
to be lower than any guest interface's MAC, and attach that tap to the
bridge as soon as it's created. Since all guest MAC addresses start
with 0xFE, we can just generate a MAC with the standard "0x52, 0x54,
0" prefix, and it's guaranteed to always win (physical interfaces are
never connected to these bridges, so we don't need to worry about
competing numerically with them).
Note that the dummy tap is never set to IFF_UP state - that's not
necessary in order for the bridge to take its MAC, and not setting it
to UP eliminates the clutter of having an (eg) "virbr0-nic" displayed
in the output of the ifconfig command.
I chose to not auto-generate the MAC address in the network XML
parser, as there are likely to be consumers of that API that don't
need or want to have a MAC address associated with the
bridge.
Instead, in bridge_driver.c when the network is being defined, if
there is no MAC, one is generated. To account for virtual network
configs that already exist when upgrading from an older version of
libvirt, I've added a %post script to the specfile that searches for
all network definitions in both the config directory
(/etc/libvirt/qemu/networks) and the state directory
(/var/lib/libvirt/network) that are missing a mac address, generates a
random address, and adds it to the config (and a matching address to
the state file, if there is one).
docs/formatnetwork.html.in: document <mac address.../>
docs/schemas/network.rng: add nac address to schema
libvirt.spec.in: %post script to update existing networks
src/conf/network_conf.[ch]: parse and format <mac address.../>
src/libvirt_private.syms: export a couple private symbols we need
src/network/bridge_driver.c:
auto-generate mac address when needed,
create dummy interface if mac address is present.
tests/networkxml2xmlin/isolated-network.xml
tests/networkxml2xmlin/routed-network.xml
tests/networkxml2xmlout/isolated-network.xml
tests/networkxml2xmlout/routed-network.xml: add mac address to some tests
2011-02-09 08:28:12 +00:00
|
|
|
bool mac_specified;
|
2008-07-11 10:48:34 +00:00
|
|
|
|
2012-12-03 16:13:36 +00:00
|
|
|
/* specified if ip6tables rules added
|
|
|
|
* when no ipv6 gateway addresses specified.
|
|
|
|
*/
|
|
|
|
bool ipv6nogw;
|
|
|
|
|
2012-11-08 02:16:17 +00:00
|
|
|
virNetworkForwardDef forward;
|
2008-07-11 10:48:34 +00:00
|
|
|
|
2010-11-17 18:36:19 +00:00
|
|
|
size_t nips;
|
2016-06-08 16:48:50 +00:00
|
|
|
virNetworkIPDefPtr ips; /* ptr to array of IP addresses on this network */
|
2011-06-24 10:04:36 +00:00
|
|
|
|
Support for static routes on a virtual bridge
network: static route support for <network>
This patch adds the <route> subelement of <network> to define a static
route. the address and prefix (or netmask) attribute identify the
destination network, and the gateway attribute specifies the next hop
address (which must be directly reachable from the containing
<network>) which is to receive the packets destined for
"address/(prefix|netmask)".
These attributes are translated into an "ip route add" command that is
executed when the network is started. The command used is of the
following form:
ip route add <address>/<prefix> via <gateway> \
dev <virbr-bridge> proto static metric <metric>
Tests are done to validate that the input data are correct. For
example, for a static route ip definition, the address must be a
network address and not a host address. Additional checks are added
to ensure that the specified gateway is directly reachable via this
network (i.e. that the gateway IP address is in the same subnet as one
of the IP's defined for the network).
prefix='0' is supported for both family='ipv4' address='0.0.0.0'
netmask='0.0.0.0' or prefix='0', and for family='ipv6' address='::',
prefix=0', although care should be taken to not override a desired
system default route.
Anytime an attempt is made to define a static route which *exactly*
duplicates an existing static route (for example, address=::,
prefix=0, metric=1), the following error message will be sent to
syslog:
RTNETLINK answers: File exists
This can be overridden by decreasing the metric value for the route
that should be preferred, or increasing the metric for the route that
shouldn't be preferred (and is thus in place only in anticipation that
the preferred route may be removed in the future). Caution should be
used when manipulating route metrics, especially for a default route.
Note: The use of the command-line interface should be replaced by
direct use of libnl so that error conditions can be handled better. But,
that is being left as an exercise for another day.
Signed-off-by: Gene Czarcinski <gene@czarc.net>
Signed-off-by: Laine Stump <laine@laine.org>
2013-05-07 17:42:55 +00:00
|
|
|
size_t nroutes;
|
2016-06-14 17:40:04 +00:00
|
|
|
virNetDevIPRoutePtr *routes; /* ptr to array of static routes on this interface */
|
Support for static routes on a virtual bridge
network: static route support for <network>
This patch adds the <route> subelement of <network> to define a static
route. the address and prefix (or netmask) attribute identify the
destination network, and the gateway attribute specifies the next hop
address (which must be directly reachable from the containing
<network>) which is to receive the packets destined for
"address/(prefix|netmask)".
These attributes are translated into an "ip route add" command that is
executed when the network is started. The command used is of the
following form:
ip route add <address>/<prefix> via <gateway> \
dev <virbr-bridge> proto static metric <metric>
Tests are done to validate that the input data are correct. For
example, for a static route ip definition, the address must be a
network address and not a host address. Additional checks are added
to ensure that the specified gateway is directly reachable via this
network (i.e. that the gateway IP address is in the same subnet as one
of the IP's defined for the network).
prefix='0' is supported for both family='ipv4' address='0.0.0.0'
netmask='0.0.0.0' or prefix='0', and for family='ipv6' address='::',
prefix=0', although care should be taken to not override a desired
system default route.
Anytime an attempt is made to define a static route which *exactly*
duplicates an existing static route (for example, address=::,
prefix=0, metric=1), the following error message will be sent to
syslog:
RTNETLINK answers: File exists
This can be overridden by decreasing the metric value for the route
that should be preferred, or increasing the metric for the route that
shouldn't be preferred (and is thus in place only in anticipation that
the preferred route may be removed in the future). Caution should be
used when manipulating route metrics, especially for a default route.
Note: The use of the command-line interface should be replaced by
direct use of libnl so that error conditions can be handled better. But,
that is being left as an exercise for another day.
Signed-off-by: Gene Czarcinski <gene@czarc.net>
Signed-off-by: Laine Stump <laine@laine.org>
2013-05-07 17:42:55 +00:00
|
|
|
|
conf: clear and parse functions for dns host/srv/txt records
Since there is only a single virNetworkDNSDef for any virNetworkDef,
and it's trivial to determine whether or not it contains any real
data, it's much simpler (and fits more uniformly with the parse
function calling sequence of the parsers for many other objects that
are subordinates of virNetworkDef) if virNetworkDef *contains* an
virNetworkDNSDef rather than pointing to one.
Since it is now just a part of another object rather than its own
object, it no longer makes sense to have a *Free() function, so that
is changed to a *Clear() function.
More importantly though, ParseXML and Clear functions are needed for
the individual items contained in a virNetworkDNSDef (srv, txt, and
host records), but none of them have a *Clear(), and only two of the
three had *ParseXML() functions (both of which used a non-uniform
arglist). Those problems are cleared up by this patch - it splits the
higher-level Clear function into separate functions for each of the
three, creates a parse for txt records, and cleans up the srv and host
parsers, so we now have all the utility functions necessary to
implement virNetworkDefUpdateDNS(Host|Srv|Txt).
2012-11-12 00:00:22 +00:00
|
|
|
virNetworkDNSDef dns; /* dns related configuration */
|
2011-11-02 14:43:16 +00:00
|
|
|
virNetDevVPortProfilePtr virtPortProfile;
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
|
|
|
|
size_t nPortGroups;
|
|
|
|
virPortGroupDefPtr portGroups;
|
Adjust naming of network device bandwidth management APIs
Rename virBandwidth to virNetDevBandwidth, and virRate to
virNetDevBandwidthRate.
* src/util/network.c, src/util/network.h: Rename bandwidth
structs and APIs
* src/conf/domain_conf.c, src/conf/domain_conf.h,
src/conf/network_conf.c, src/conf/network_conf.h,
src/lxc/lxc_driver.c, src/network/bridge_driver.c,
src/qemu/qemu_command.c, src/util/macvtap.c,
src/util/macvtap.h, tools/virsh.c: Update for API changes.
2011-11-02 14:29:05 +00:00
|
|
|
virNetDevBandwidthPtr bandwidth;
|
2012-08-12 07:51:30 +00:00
|
|
|
virNetDevVlan vlan;
|
2014-09-23 18:19:08 +00:00
|
|
|
int trustGuestRxFilters; /* enum virTristateBool */
|
2020-01-29 15:29:21 +00:00
|
|
|
virTristateBool isolatedPort;
|
2016-06-22 22:05:50 +00:00
|
|
|
|
|
|
|
/* Application-specific custom metadata */
|
|
|
|
xmlNodePtr metadata;
|
2019-07-14 11:36:44 +00:00
|
|
|
|
|
|
|
/* Network specific XML namespace data */
|
|
|
|
void *namespaceData;
|
2019-08-20 19:52:08 +00:00
|
|
|
virXMLNamespace ns;
|
2008-07-11 10:48:34 +00:00
|
|
|
};
|
|
|
|
|
2014-04-28 00:15:22 +00:00
|
|
|
typedef enum {
|
2014-02-04 16:36:54 +00:00
|
|
|
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
|
2014-04-28 00:15:22 +00:00
|
|
|
} virNetworkTaintFlags;
|
2014-02-04 16:36:54 +00:00
|
|
|
|
2008-07-11 10:48:34 +00:00
|
|
|
void virNetworkDefFree(virNetworkDefPtr def);
|
2020-06-10 03:43:56 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkDef, virNetworkDefFree);
|
2013-06-26 15:42:27 +00:00
|
|
|
|
network_conf: Drop virNetworkObjIsDuplicate
This function does not make any sense now, that network driver is
(almost) dropped. I mean, previously, when threads were
serialized, this function was there to check, if no other network
with the same name or UUID exists. However, nowadays that threads
can run more in parallel, this function is useless, in fact it
gives misleading return values. Consider the following scenario.
Two threads, both trying to define networks with same name but
different UUID (e.g. because it was generated during XML parsing
phase, whatever). Lets assume that both threads are about to call
networkValidate() which immediately calls
virNetworkObjIsDuplicate().
T1: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T2: calls virNetworkObjIsDuplicate() and since no network with
given name or UUID exist, success is returned.
T1: calls virNetworkAssignDef() and successfully places its
network into the virNetworkObjList.
T2: calls virNetworkAssignDef() and since network with the same
name exists, the network definition is replaced.
Okay, this is mainly because virNetworkAssignDef() does not check
whether name and UUID matches. Well, lets make it so! And drop
useless function too.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-14 10:18:21 +00:00
|
|
|
enum {
|
|
|
|
VIR_NETWORK_OBJ_LIST_ADD_LIVE = (1 << 0),
|
|
|
|
VIR_NETWORK_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
|
|
|
|
};
|
2008-07-11 10:48:34 +00:00
|
|
|
|
2019-07-14 16:11:06 +00:00
|
|
|
virNetworkXMLOptionPtr
|
2019-08-20 19:52:08 +00:00
|
|
|
virNetworkXMLOptionNew(virXMLNamespacePtr xmlns);
|
2019-07-14 16:11:06 +00:00
|
|
|
|
2017-03-08 15:52:18 +00:00
|
|
|
virNetworkDefPtr
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkDefCopy(virNetworkDefPtr def,
|
|
|
|
virNetworkXMLOptionPtr xmlopt,
|
|
|
|
unsigned int flags);
|
2017-03-08 15:52:18 +00:00
|
|
|
|
|
|
|
virNetworkDefPtr
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkDefParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
virNetworkXMLOptionPtr xmlopt);
|
2017-03-08 15:52:18 +00:00
|
|
|
|
|
|
|
virNetworkDefPtr
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkDefParseString(const char *xmlStr,
|
|
|
|
virNetworkXMLOptionPtr xmlopt);
|
2017-03-08 15:52:18 +00:00
|
|
|
|
|
|
|
virNetworkDefPtr
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkDefParseFile(const char *filename,
|
|
|
|
virNetworkXMLOptionPtr xmlopt);
|
2017-03-08 15:52:18 +00:00
|
|
|
|
|
|
|
virNetworkDefPtr
|
|
|
|
virNetworkDefParseNode(xmlDocPtr xml,
|
2019-07-14 16:15:12 +00:00
|
|
|
xmlNodePtr root,
|
|
|
|
virNetworkXMLOptionPtr xmlopt);
|
2017-03-08 15:52:18 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
virNetworkDefFormat(const virNetworkDef *def,
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkXMLOptionPtr xmlopt,
|
2017-03-08 15:52:18 +00:00
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
int
|
|
|
|
virNetworkDefFormatBuf(virBufferPtr buf,
|
|
|
|
const virNetworkDef *def,
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkXMLOptionPtr xmlopt,
|
2017-03-08 15:52:18 +00:00
|
|
|
unsigned int flags);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
virNetworkDefForwardIf(const virNetworkDef *def,
|
|
|
|
size_t n);
|
|
|
|
|
|
|
|
virPortGroupDefPtr
|
|
|
|
virPortGroupFindByName(virNetworkDefPtr net,
|
|
|
|
const char *portgroup);
|
conf: support abstracted interface info in network XML
The network XML is updated in the following ways:
1) The <forward> element can now contain a list of forward interfaces:
<forward .... >
<interface dev='eth10'/>
<interface dev='eth11'/>
<interface dev='eth12'/>
<interface dev='eth13'/>
</forward>
The first of these takes the place of the dev attribute that is
normally in <forward> - when defining a network you can specify
either one, and on output both will be present. If you specify
both on input, they must match.
2) In addition to forward modes of 'nat' and 'route', these new modes
are supported:
private, passthrough, vepa - when this network is referenced by a
domain's interface, it will have the same effect as if the
interface had been defined as type='direct', e.g.:
<interface type='direct'>
<source mode='${mode}' dev='${dev}>
...
</interface>
where ${mode} is one of the three new modes, and ${dev} is an interface
selected from the list given in <forward>.
bridge - if a <forward> dev (or multiple devs) is defined, and
forward mode is 'bridge' this is just like the modes 'private',
'passthrough', and 'vepa' above. If there is no forward dev
specified but a bridge name is given (e.g. "<bridge
name='br0'/>"), then guest interfaces using this network will use
libvirt's "host bridge" mode, equivalent to this:
<interface type='bridge'>
<source bridge='${bridge-name}'/>
...
</interface>
3) A network can have multiple <portgroup> elements, which may be
selected by the guest interface definition (by adding
"portgroup='${name}'" in the <source> element along with the
network name). Currently a portgroup can only contain a
virtportprofile, but the intent is that other configuration items
may be put there int the future (e.g. bandwidth config). When
building a guest's interface, if the <interface> XML itself has no
virtportprofile, and if the requested network has a portgroup with
a name matching the name given in the <interface> (or if one of the
network's portgroups is marked with the "default='yes'" attribute),
the virtportprofile from that portgroup will be used by the
interface.
4) A network can have a virtportprofile defined at the top level,
which will be used by a guest interface when connecting in one of
the 'direct' modes if the guest interface XML itself hasn't
specified any virtportprofile, and if there are also no matching
portgroups on the network.
2011-07-20 03:01:09 +00:00
|
|
|
|
2016-06-08 16:48:50 +00:00
|
|
|
virNetworkIPDefPtr
|
|
|
|
virNetworkDefGetIPByIndex(const virNetworkDef *def,
|
2017-03-08 15:52:18 +00:00
|
|
|
int family,
|
|
|
|
size_t n);
|
|
|
|
|
2016-06-14 17:40:04 +00:00
|
|
|
virNetDevIPRoutePtr
|
2015-07-09 13:50:41 +00:00
|
|
|
virNetworkDefGetRouteByIndex(const virNetworkDef *def,
|
2017-03-08 15:52:18 +00:00
|
|
|
int family,
|
|
|
|
size_t n);
|
|
|
|
|
|
|
|
int
|
|
|
|
virNetworkIPDefPrefix(const virNetworkIPDef *def);
|
|
|
|
|
|
|
|
int
|
|
|
|
virNetworkIPDefNetmask(const virNetworkIPDef *def,
|
|
|
|
virSocketAddrPtr netmask);
|
2008-07-11 10:48:34 +00:00
|
|
|
|
2017-03-08 15:52:18 +00:00
|
|
|
int
|
|
|
|
virNetworkSaveXML(const char *configDir,
|
|
|
|
virNetworkDefPtr def,
|
|
|
|
const char *xml);
|
2009-01-20 22:36:10 +00:00
|
|
|
|
2017-03-08 15:52:18 +00:00
|
|
|
int
|
|
|
|
virNetworkSaveConfig(const char *configDir,
|
2019-07-14 16:15:12 +00:00
|
|
|
virNetworkDefPtr def,
|
|
|
|
virNetworkXMLOptionPtr xmlopt);
|
2008-07-11 10:48:34 +00:00
|
|
|
|
2017-03-08 15:52:18 +00:00
|
|
|
char *
|
|
|
|
virNetworkConfigFile(const char *dir,
|
|
|
|
const char *name);
|
2009-01-20 22:36:10 +00:00
|
|
|
|
2017-03-08 15:52:18 +00:00
|
|
|
void
|
|
|
|
virNetworkSetBridgeMacAddr(virNetworkDefPtr def);
|
Give each virtual network bridge its own fixed MAC address
This fixes https://bugzilla.redhat.com/show_bug.cgi?id=609463
The problem was that, since a bridge always acquires the MAC address
of the connected interface with the numerically lowest MAC, as guests
are started and stopped, it was possible for the MAC address to change
over time, and this change in the network was being detected by
Windows 7 (it sees the MAC of the default route change), so on each
reboot it would bring up a dialog box asking about this "new network".
The solution is to create a dummy tap interface with a MAC guaranteed
to be lower than any guest interface's MAC, and attach that tap to the
bridge as soon as it's created. Since all guest MAC addresses start
with 0xFE, we can just generate a MAC with the standard "0x52, 0x54,
0" prefix, and it's guaranteed to always win (physical interfaces are
never connected to these bridges, so we don't need to worry about
competing numerically with them).
Note that the dummy tap is never set to IFF_UP state - that's not
necessary in order for the bridge to take its MAC, and not setting it
to UP eliminates the clutter of having an (eg) "virbr0-nic" displayed
in the output of the ifconfig command.
I chose to not auto-generate the MAC address in the network XML
parser, as there are likely to be consumers of that API that don't
need or want to have a MAC address associated with the
bridge.
Instead, in bridge_driver.c when the network is being defined, if
there is no MAC, one is generated. To account for virtual network
configs that already exist when upgrading from an older version of
libvirt, I've added a %post script to the specfile that searches for
all network definitions in both the config directory
(/etc/libvirt/qemu/networks) and the state directory
(/var/lib/libvirt/network) that are missing a mac address, generates a
random address, and adds it to the config (and a matching address to
the state file, if there is one).
docs/formatnetwork.html.in: document <mac address.../>
docs/schemas/network.rng: add nac address to schema
libvirt.spec.in: %post script to update existing networks
src/conf/network_conf.[ch]: parse and format <mac address.../>
src/libvirt_private.syms: export a couple private symbols we need
src/network/bridge_driver.c:
auto-generate mac address when needed,
create dummy interface if mac address is present.
tests/networkxml2xmlin/isolated-network.xml
tests/networkxml2xmlin/routed-network.xml
tests/networkxml2xmlout/isolated-network.xml
tests/networkxml2xmlout/routed-network.xml: add mac address to some tests
2011-02-09 08:28:12 +00:00
|
|
|
|
2020-01-29 15:29:21 +00:00
|
|
|
int
|
|
|
|
virNetworkPortOptionsParseXML(xmlXPathContextPtr ctxt,
|
|
|
|
virTristateBool *isolatedPort);
|
|
|
|
|
|
|
|
void
|
|
|
|
virNetworkPortOptionsFormat(virTristateBool isolatedPort,
|
|
|
|
virBufferPtr buf);
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virNetworkForward);
|
2012-08-05 20:11:50 +00:00
|
|
|
|
2019-06-07 20:20:17 +00:00
|
|
|
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE \
|
2012-09-04 15:55:17 +00:00
|
|
|
(VIR_CONNECT_LIST_NETWORKS_ACTIVE | \
|
|
|
|
VIR_CONNECT_LIST_NETWORKS_INACTIVE)
|
|
|
|
|
2019-06-07 20:20:17 +00:00
|
|
|
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT \
|
2012-09-04 15:55:17 +00:00
|
|
|
(VIR_CONNECT_LIST_NETWORKS_PERSISTENT | \
|
|
|
|
VIR_CONNECT_LIST_NETWORKS_TRANSIENT)
|
|
|
|
|
2019-06-07 20:20:17 +00:00
|
|
|
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART \
|
2017-11-03 12:09:47 +00:00
|
|
|
(VIR_CONNECT_LIST_NETWORKS_AUTOSTART | \
|
2012-09-04 15:55:17 +00:00
|
|
|
VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)
|
|
|
|
|
2019-06-07 20:20:17 +00:00
|
|
|
#define VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL \
|
2012-09-04 15:55:17 +00:00
|
|
|
(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE | \
|
|
|
|
VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT | \
|
|
|
|
VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART)
|
|
|
|
|
2013-07-29 15:17:47 +00:00
|
|
|
/* for testing */
|
|
|
|
int
|
|
|
|
virNetworkDefUpdateSection(virNetworkDefPtr def,
|
|
|
|
unsigned int command, /* virNetworkUpdateCommand */
|
|
|
|
unsigned int section, /* virNetworkUpdateSection */
|
|
|
|
int parentIndex,
|
|
|
|
const char *xml,
|
|
|
|
unsigned int flags); /* virNetworkUpdateFlags */
|
|
|
|
|
2019-01-20 16:04:56 +00:00
|
|
|
VIR_ENUM_DECL(virNetworkTaint);
|