libvirt/src/conf/network_conf.h

459 lines
16 KiB
C
Raw Normal View History

/*
* network_conf.h: network XML handling
*
* Copyright (C) 2006-2014 Red Hat, Inc.
* 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
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: Daniel P. Berrange <berrange@redhat.com>
*/
#ifndef __NETWORK_CONF_H__
# define __NETWORK_CONF_H__
# 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"
conf: add <vlan> element to network and domain interface elements The following config elements now support a <vlan> subelements: within a domain: <interface>, and the <actual> subelement of <interface> within a network: the toplevel, as well as any <portgroup> Each vlan element must have one or more <tag id='n'/> subelements. If there is more than one tag, it is assumed that vlan trunking is being requested. If trunking is required with only a single tag, the attribute "trunk='yes'" should be added to the toplevel <vlan> element. Some examples: <interface type='hostdev'/> <vlan> <tag id='42'/> </vlan> <mac address='52:54:00:12:34:56'/> ... </interface> <network> <name>vlan-net</name> <vlan trunk='yes'> <tag id='30'/> </vlan> <virtualport type='openvswitch'/> </network> <interface type='network'/> <source network='vlan-net'/> ... </interface> <network> <name>trunk-vlan</name> <vlan> <tag id='42'/> <tag id='43'/> </vlan> ... </network> <network> <name>multi</name> ... <portgroup name='production'/> <vlan> <tag id='42'/> </vlan> </portgroup> <portgroup name='test'/> <vlan> <tag id='666'/> </vlan> </portgroup> </network> <interface type='network'/> <source network='multi' portgroup='test'/> ... </interface> IMPORTANT NOTE: As of this patch there is no backend support for the vlan element for *any* network device type. When support is added in later patches, it will only be for those select network types that support setting up a vlan on the host side, without the guest's involvement. (For example, it will be possible to configure a vlan for a guest connected to an openvswitch bridge, but it won't be possible to do that for one that is connected to a standard Linux host bridge.)
2012-08-12 07:51:30 +00:00
# include "virnetdevvlan.h"
# include "virmacaddr.h"
# include "device_conf.h"
# include "virbitmap.h"
# include "networkcommon_conf.h"
typedef enum {
VIR_NETWORK_FORWARD_NONE = 0,
VIR_NETWORK_FORWARD_NAT,
VIR_NETWORK_FORWARD_ROUTE,
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,
VIR_NETWORK_FORWARD_HOSTDEV,
VIR_NETWORK_FORWARD_LAST,
} virNetworkForwardType;
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;
VIR_ENUM_DECL(virNetworkBridgeMACTableManager)
typedef enum {
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,
} virNetworkForwardHostdevDeviceType;
/* 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;
VIR_ENUM_DECL(virNetworkForwardDriverName)
typedef struct _virNetworkDHCPHostDef virNetworkDHCPHostDef;
typedef virNetworkDHCPHostDef *virNetworkDHCPHostDefPtr;
struct _virNetworkDHCPHostDef {
char *mac;
char *id;
char *name;
virSocketAddr ip;
};
typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef;
typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr;
struct _virNetworkDNSTxtDef {
char *name;
char *value;
};
typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef;
typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr;
struct _virNetworkDNSSrvDef {
char *domain;
char *service;
char *protocol;
char *target;
unsigned int port;
unsigned int priority;
unsigned int weight;
};
typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef;
typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr;
struct _virNetworkDNSHostDef {
virSocketAddr ip;
size_t nnames;
char **names;
};
typedef struct _virNetworkDNSDef virNetworkDNSDef;
typedef virNetworkDNSDef *virNetworkDNSDefPtr;
struct _virNetworkDNSDef {
int forwardPlainNames; /* enum virTristateBool */
size_t ntxts;
virNetworkDNSTxtDefPtr txts;
size_t nhosts;
virNetworkDNSHostDefPtr hosts;
size_t nsrvs;
virNetworkDNSSrvDefPtr srvs;
size_t nfwds;
char **forwarders;
};
typedef struct _virNetworkIpDef virNetworkIpDef;
typedef virNetworkIpDef *virNetworkIpDefPtr;
struct _virNetworkIpDef {
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.
* Use virNetworkIpDefPrefix/virNetworkIpDefNetmask rather
* 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 */
size_t nranges; /* Zero or more dhcp ranges */
virSocketAddrRangePtr ranges;
size_t nhosts; /* Zero or more dhcp hosts */
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 {
int type;
union {
virDevicePCIAddress pci; /*PCI Address of device */
/* 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
};
typedef struct _virNetworkForwardPfDef virNetworkForwardPfDef;
typedef virNetworkForwardPfDef *virNetworkForwardPfDefPtr;
struct _virNetworkForwardPfDef {
char *dev; /* name of device */
int connections; /* how many guest interfaces are connected to this device? */
};
typedef struct _virNetworkForwardDef virNetworkForwardDef;
typedef virNetworkForwardDef *virNetworkForwardDefPtr;
struct _virNetworkForwardDef {
int type; /* One of virNetworkForwardType constants */
bool managed; /* managed attribute for hostdev mode */
int driverName; /* enum virNetworkForwardDriverNameType */
/* 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;
/* ranges for NAT */
virSocketAddrRange addr;
virPortRange port;
};
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;
virNetDevVPortProfilePtr virtPortProfile;
virNetDevBandwidthPtr bandwidth;
conf: add <vlan> element to network and domain interface elements The following config elements now support a <vlan> subelements: within a domain: <interface>, and the <actual> subelement of <interface> within a network: the toplevel, as well as any <portgroup> Each vlan element must have one or more <tag id='n'/> subelements. If there is more than one tag, it is assumed that vlan trunking is being requested. If trunking is required with only a single tag, the attribute "trunk='yes'" should be added to the toplevel <vlan> element. Some examples: <interface type='hostdev'/> <vlan> <tag id='42'/> </vlan> <mac address='52:54:00:12:34:56'/> ... </interface> <network> <name>vlan-net</name> <vlan trunk='yes'> <tag id='30'/> </vlan> <virtualport type='openvswitch'/> </network> <interface type='network'/> <source network='vlan-net'/> ... </interface> <network> <name>trunk-vlan</name> <vlan> <tag id='42'/> <tag id='43'/> </vlan> ... </network> <network> <name>multi</name> ... <portgroup name='production'/> <vlan> <tag id='42'/> </vlan> </portgroup> <portgroup name='test'/> <vlan> <tag id='666'/> </vlan> </portgroup> </network> <interface type='network'/> <source network='multi' portgroup='test'/> ... </interface> IMPORTANT NOTE: As of this patch there is no backend support for the vlan element for *any* network device type. When support is added in later patches, it will only be for those select network types that support setting up a vlan on the host side, without the guest's involvement. (For example, it will be possible to configure a vlan for a guest connected to an openvswitch bridge, but it won't be possible to do that for one that is connected to a standard Linux host bridge.)
2012-08-12 07:51:30 +00:00
virNetDevVlan vlan;
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
};
typedef struct _virNetworkDef virNetworkDef;
typedef virNetworkDef *virNetworkDefPtr;
struct _virNetworkDef {
unsigned char uuid[VIR_UUID_BUFLEN];
esx: Implement network driver An ESX server has one or more PhysicalNics that represent the actual hardware NICs. Those can be listed via the interface driver. A libvirt virtual network is mapped to a HostVirtualSwitch. On the physical side a HostVirtualSwitch can be connected to PhysicalNics. On the virtual side a HostVirtualSwitch has HostPortGroups that are mapped to libvirt virtual network's portgroups. Typically there is HostPortGroups named 'VM Network' that is used to connect virtual machines to a HostVirtualSwitch. A second HostPortGroup typically named 'Management Network' is used to connect the hypervisor itself to the HostVirtualSwitch. This one is not mapped to a libvirt virtual network's portgroup. There can be more HostPortGroups than those typical two on a HostVirtualSwitch. +---------------+-------------------+ ...---| | | +-------------+ | HostPortGroup | |---| PhysicalNic | | VM Network | | | vmnic0 | ...---| | | +-------------+ +---------------+ HostVirtualSwitch | | vSwitch0 | +---------------+ | | HostPortGroup | | ...---| Management | | | Network | | +---------------+-------------------+ The virtual counterparts of the PhysicalNic is the HostVirtualNic for the hypervisor and the VirtualEthernetCard for the virtual machines that are grouped into HostPortGroups. +---------------------+ +---------------+---... | VirtualEthernetCard |---| | +---------------------+ | HostPortGroup | +---------------------+ | VM Network | | VirtualEthernetCard |---| | +---------------------+ +---------------+ | +---------------+ +---------------------+ | HostPortGroup | | HostVirtualNic |---| Management | +---------------------+ | Network | +---------------+---... The currently implemented network driver can list, define and undefine HostVirtualSwitches including HostPortGroups for virtual machines. Existing HostVirtualSwitches cannot be edited yet. This will be added in a followup patch.
2012-08-05 20:11:50 +00:00
bool uuid_specified;
char *name;
int connections; /* # of guest interfaces connected to this network */
char *bridge; /* Name of bridge device */
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 */
char *domain;
int domainLocalOnly; /* enum virTristateBool: yes disables dns forwarding */
unsigned long delay; /* Bridge forward delay (ms) */
bool stp; /* Spanning tree protocol */
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;
/* specified if ip6tables rules added
* when no ipv6 gateway addresses specified.
*/
bool ipv6nogw;
virNetworkForwardDef forward;
size_t nips;
virNetworkIpDefPtr ips; /* ptr to array of IP addresses on this network */
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;
virNetworkRouteDefPtr *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
virNetworkDNSDef dns; /* dns related configuration */
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;
virNetDevBandwidthPtr bandwidth;
conf: add <vlan> element to network and domain interface elements The following config elements now support a <vlan> subelements: within a domain: <interface>, and the <actual> subelement of <interface> within a network: the toplevel, as well as any <portgroup> Each vlan element must have one or more <tag id='n'/> subelements. If there is more than one tag, it is assumed that vlan trunking is being requested. If trunking is required with only a single tag, the attribute "trunk='yes'" should be added to the toplevel <vlan> element. Some examples: <interface type='hostdev'/> <vlan> <tag id='42'/> </vlan> <mac address='52:54:00:12:34:56'/> ... </interface> <network> <name>vlan-net</name> <vlan trunk='yes'> <tag id='30'/> </vlan> <virtualport type='openvswitch'/> </network> <interface type='network'/> <source network='vlan-net'/> ... </interface> <network> <name>trunk-vlan</name> <vlan> <tag id='42'/> <tag id='43'/> </vlan> ... </network> <network> <name>multi</name> ... <portgroup name='production'/> <vlan> <tag id='42'/> </vlan> </portgroup> <portgroup name='test'/> <vlan> <tag id='666'/> </vlan> </portgroup> </network> <interface type='network'/> <source network='multi' portgroup='test'/> ... </interface> IMPORTANT NOTE: As of this patch there is no backend support for the vlan element for *any* network device type. When support is added in later patches, it will only be for those select network types that support setting up a vlan on the host side, without the guest's involvement. (For example, it will be possible to configure a vlan for a guest connected to an openvswitch bridge, but it won't be possible to do that for one that is connected to a standard Linux host bridge.)
2012-08-12 07:51:30 +00:00
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
};
typedef struct _virNetworkObj virNetworkObj;
typedef virNetworkObj *virNetworkObjPtr;
struct _virNetworkObj {
2009-01-15 19:56:05 +00:00
virMutex lock;
2008-12-04 22:00:14 +00:00
pid_t dnsmasqPid;
pid_t radvdPid;
unsigned int active : 1;
unsigned int autostart : 1;
unsigned int persistent : 1;
virNetworkDefPtr def; /* The current definition */
virNetworkDefPtr newDef; /* New definition to activate at shutdown */
virBitmapPtr class_id; /* bitmap of class IDs for QoS */
unsigned long long floor_sum; /* sum of all 'floor'-s of attached NICs */
unsigned int taint;
};
typedef struct _virNetworkObjList virNetworkObjList;
typedef virNetworkObjList *virNetworkObjListPtr;
struct _virNetworkObjList {
size_t count;
virNetworkObjPtr *objs;
};
typedef enum {
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
} virNetworkTaintFlags;
static inline int
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkObjIsActive(const virNetworkObj *net)
{
return net->active;
}
bool virNetworkObjTaint(virNetworkObjPtr obj,
virNetworkTaintFlags taint);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkObjPtr virNetworkFindByUUID(virNetworkObjListPtr nets,
const unsigned char *uuid);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkObjPtr virNetworkFindByName(virNetworkObjListPtr nets,
const char *name);
void virNetworkDefFree(virNetworkDefPtr def);
void virNetworkObjFree(virNetworkObjPtr net);
void virNetworkObjListFree(virNetworkObjListPtr vms);
typedef bool (*virNetworkObjListFilter)(virConnectPtr conn,
virNetworkDefPtr def);
virNetworkObjPtr virNetworkAssignDef(virNetworkObjListPtr nets,
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkDefPtr def,
bool live);
network: fix virNetworkObjAssignDef and persistence Experimentation showed that if virNetworkCreateXML() was called for a network that was already defined, and then the network was subsequently shutdown, the network would continue to be persistent after the shutdown (expected/desired), but the original config would be lost in favor of the transient config sent in with virNetworkCreateXML() (which would then be the new persistent config) (obviously unexpected/not desired). To fix this, virNetworkObjAssignDef() has been changed to 1) properly save/free network->def and network->newDef for all the various combinations of live/active/persistent, including some combinations that were previously considered to be an error but didn't need to be (e.g. setting a "live" config for a network that isn't yet active but soon will be - that was previously considered an error, even though in practice it can be very useful). 2) automatically set the persistent flag whenever a new non-live config is assigned to the network (and clear it when the non-live config is set to NULL). the libvirt network driver no longer directly manipulates network->persistent, but instead relies entirely on virNetworkObjAssignDef() to do the right thing automatically. After this patch, the following sequence will behave as expected: virNetworkDefineXML(X) virNetworkCreateXML(X') (same name but some config different) virNetworkDestroy(X) At the end of these calls, the network config will remain as it was after the initial virNetworkDefine(), whereas previously it would take on the changes given during virNetworkCreateXML(). Another effect of this tighter coupling between a) setting a !live def and b) setting/clearing the "persistent" flag, is that future patches which change the details of network lifecycle management (e.g. upcoming patches to fix detection of "active" networks when libvirtd is restarted) will find it much more difficult to break persistence functionality.
2014-04-22 13:48:54 +00:00
void virNetworkObjAssignDef(virNetworkObjPtr network,
virNetworkDefPtr def,
bool live);
int virNetworkObjSetDefTransient(virNetworkObjPtr network, bool live);
network: free/null newDef if network fails to start https://bugzilla.redhat.com/show_bug.cgi?id=866364 pointed out a crash due to virNetworkObjAssignDef free'ing network->newDef without NULLing it afterward. A fix for this is in upstream commit b7e9202401ebaa039b8f05acdefda8c24081537a. While the NULLing of newDef was a legitimate fix, newDef should have already been empty (NULL) anyway (as indicated in the comment that was deleted by that commit). The reason that newDef had a non-NULL value (i.e. the root cause) was that networkStartNetwork() had failed after populating network->newDef, but then neglected to free/NULL newDef in the cleanup. (A bit of background here: network->newDef should contain the persistent config of a network when a network is active (and of course only when it is persisten), and NULL at all other times. There is also a network->def which should contain the persistent definition of the network when it is inactive, and the current live state at all other times. The idea is that you can make changes to network->newDef which will take effect the next time the network is restarted, but won't mess with the current state of the network (virDomainObj has a similar pair of virDomainDefs that behave in the same fashion). Personally I think there should be a network->live and network->config, and the location of the persistent config should *always* be in network->config, but that's for a later cleanup). Since I love things to be symmetric, I created a new function called virNetworkObjUnsetDefTransient(), which reverses the effects of virNetworkObjSetDefTransient(). I don't really like the name of the new function, but then I also didn't really like the name of the old one either (it's just named that way to match a similar function in the domain conf code).
2012-10-19 16:13:49 +00:00
void virNetworkObjUnsetDefTransient(virNetworkObjPtr network);
virNetworkDefPtr virNetworkObjGetPersistentDef(virNetworkObjPtr network);
int virNetworkObjReplacePersistentDef(virNetworkObjPtr network,
virNetworkDefPtr def);
virNetworkDefPtr virNetworkDefCopy(virNetworkDefPtr def, unsigned int flags);
int virNetworkConfigChangeSetup(virNetworkObjPtr dom, unsigned int flags);
void virNetworkRemoveInactive(virNetworkObjListPtr nets,
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkObjPtr net);
virNetworkDefPtr virNetworkDefParseString(const char *xmlStr);
virNetworkDefPtr virNetworkDefParseFile(const char *filename);
virNetworkDefPtr virNetworkDefParseNode(xmlDocPtr xml,
xmlNodePtr root);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
char *virNetworkDefFormat(const virNetworkDef *def, unsigned int flags);
int virNetworkDefFormatBuf(virBufferPtr buf,
const virNetworkDef *def,
unsigned int flags);
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
static inline const char *
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkDefForwardIf(const virNetworkDef *def, size_t n)
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
{
return ((def->forward.ifs && (def->forward.nifs > n) &&
def->forward.ifs[n].type == VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV)
? def->forward.ifs[n].device.dev : NULL);
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
}
virPortGroupDefPtr virPortGroupFindByName(virNetworkDefPtr net,
const char *portgroup);
virNetworkIpDefPtr
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
virNetworkDefGetIpByIndex(const virNetworkDef *def,
int family, size_t n);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
int virNetworkIpDefPrefix(const virNetworkIpDef *def);
int virNetworkIpDefNetmask(const virNetworkIpDef *def,
virSocketAddrPtr netmask);
int virNetworkSaveXML(const char *configDir,
virNetworkDefPtr def,
const char *xml);
int virNetworkSaveConfig(const char *configDir,
virNetworkDefPtr def);
int virNetworkSaveStatus(const char *statusDir,
virNetworkObjPtr net) ATTRIBUTE_RETURN_CHECK;
virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
const char *configDir,
const char *autostartDir,
const char *file);
virNetworkObjPtr virNetworkLoadState(virNetworkObjListPtr nets,
const char *stateDir,
const char *name);
int virNetworkLoadAllConfigs(virNetworkObjListPtr nets,
const char *configDir,
const char *autostartDir);
int virNetworkLoadAllState(virNetworkObjListPtr nets,
const char *stateDir);
int virNetworkDeleteConfig(const char *configDir,
const char *autostartDir,
virNetworkObjPtr net);
char *virNetworkConfigFile(const char *dir,
const char *name);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
int virNetworkBridgeInUse(virNetworkObjListPtr nets,
const char *bridge,
const char *skipname);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
char *virNetworkAllocateBridge(virNetworkObjListPtr nets,
const char *template);
maint: avoid 'const fooPtr' in conf 'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up remaining offenders in src/conf, and their fallout. * src/conf/snapshot_conf.h (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Drop attempt at const. * src/conf/interface_conf.h (virInterfaceObjIsActive) (virInterfaceDefFormat): Use intended type. (virInterfaceFindByMACString, virInterfaceFindByName) (virInterfaceAssignDef, virInterfaceRemove): Drop attempt at const. * src/conf/network_conf.h (virNetworkObjIsActive) (virNetworkDefFormat, virNetworkDefForwardIf) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask): Use intended type. (virNetworkFindByUUID, virNetworkFindByName, virNetworkAssignDef) (virNetworkObjAssignDef, virNetworkRemoveInactive) (virNetworkBridgeInUse, virNetworkSetBridgeName) (virNetworkAllocateBridge): Drop attempt at const. * src/conf/netdev_vlan_conf.h (virNetDevVlanFormat): Make const-correct. * src/conf/node_device_conf.h (virNodeDeviceHasCap) (virNodeDeviceDefFormat): Use intended type. (virNodeDeviceFindByName, virNodeDeviceFindBySysfsPath) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceGetParentHost): Drop attempt at const. * src/conf/secret_conf.h (virSecretDefFormat): Use intended type. * src/conf/snapshot_conf.c (virDomainSnapshotAssignDef) (virDomainSnapshotFindByName): Fix fallout. * src/conf/interface_conf.c (virInterfaceBridgeDefFormat) (virInterfaceBondDefFormat, virInterfaceVlanDefFormat) (virInterfaceProtocolDefFormat, virInterfaceDefDevFormat) (virInterfaceDefFormat, virInterfaceFindByMACString) (virInterfaceFindByName, virInterfaceAssignDef) (virInterfaceRemove): Likewise. * src/conf/network_conf.c (VIR_ENUM_IMPL, virNetworkFindByName, virNetworkObjAssignDef) (virNetworkAssignDef, virNetworkRemoveInactive) (virNetworkDefGetIpByIndex, virNetworkIpDefPrefix) (virNetworkIpDefNetmask, virNetworkDHCPHostDefParseXML) (virNetworkIpDefFormat, virNetworkRouteDefFormat) (virPortGroupDefFormat, virNetworkForwardNatDefFormat) (virNetworkDefFormatInternal, virNetworkBridgeInUse) (virNetworkAllocateBridge, virNetworkSetBridgeName) (virNetworkDNSDefFormat, virNetworkDefFormat): Likewise. * src/conf/netdev_vlan_conf.c (virNetDevVlanFormat): Likewise. * src/conf/node_device_conf.c (virNodeDeviceHasCap) (virNodeDeviceFindBySysfsPath, virNodeDeviceFindByName) (virNodeDeviceAssignDef, virNodeDeviceObjRemove) (virNodeDeviceDefFormat, virNodeDeviceGetParentHost): Likewise. * src/conf/secret_conf.c (virSecretDefFormatUsage) (virSecretDefFormat): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-08 16:36:37 +00:00
int virNetworkSetBridgeName(virNetworkObjListPtr nets,
virNetworkDefPtr def,
int check_collision);
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
void virNetworkSetBridgeMacAddr(virNetworkDefPtr def);
int
virNetworkObjUpdate(virNetworkObjPtr obj,
unsigned int command, /* virNetworkUpdateCommand */
unsigned int section, /* virNetworkUpdateSection */
int parentIndex,
const char *xml,
unsigned int flags); /* virNetworkUpdateFlags */
int virNetworkObjIsDuplicate(virNetworkObjListPtr doms,
virNetworkDefPtr def,
bool check_active);
2008-12-04 20:53:20 +00:00
void virNetworkObjLock(virNetworkObjPtr obj);
void virNetworkObjUnlock(virNetworkObjPtr obj);
esx: Implement network driver An ESX server has one or more PhysicalNics that represent the actual hardware NICs. Those can be listed via the interface driver. A libvirt virtual network is mapped to a HostVirtualSwitch. On the physical side a HostVirtualSwitch can be connected to PhysicalNics. On the virtual side a HostVirtualSwitch has HostPortGroups that are mapped to libvirt virtual network's portgroups. Typically there is HostPortGroups named 'VM Network' that is used to connect virtual machines to a HostVirtualSwitch. A second HostPortGroup typically named 'Management Network' is used to connect the hypervisor itself to the HostVirtualSwitch. This one is not mapped to a libvirt virtual network's portgroup. There can be more HostPortGroups than those typical two on a HostVirtualSwitch. +---------------+-------------------+ ...---| | | +-------------+ | HostPortGroup | |---| PhysicalNic | | VM Network | | | vmnic0 | ...---| | | +-------------+ +---------------+ HostVirtualSwitch | | vSwitch0 | +---------------+ | | HostPortGroup | | ...---| Management | | | Network | | +---------------+-------------------+ The virtual counterparts of the PhysicalNic is the HostVirtualNic for the hypervisor and the VirtualEthernetCard for the virtual machines that are grouped into HostPortGroups. +---------------------+ +---------------+---... | VirtualEthernetCard |---| | +---------------------+ | HostPortGroup | +---------------------+ | VM Network | | VirtualEthernetCard |---| | +---------------------+ +---------------+ | +---------------+ +---------------------+ | HostPortGroup | | HostVirtualNic |---| Management | +---------------------+ | Network | +---------------+---... The currently implemented network driver can list, define and undefine HostVirtualSwitches including HostPortGroups for virtual machines. Existing HostVirtualSwitches cannot be edited yet. This will be added in a followup patch.
2012-08-05 20:11:50 +00:00
VIR_ENUM_DECL(virNetworkForward)
# define VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE \
(VIR_CONNECT_LIST_NETWORKS_ACTIVE | \
VIR_CONNECT_LIST_NETWORKS_INACTIVE)
# define VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT \
(VIR_CONNECT_LIST_NETWORKS_PERSISTENT | \
VIR_CONNECT_LIST_NETWORKS_TRANSIENT)
# define VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART \
(VIR_CONNECT_LIST_NETWORKS_AUTOSTART | \
VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)
# define VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL \
(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE | \
VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT | \
VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART)
int virNetworkObjListExport(virConnectPtr conn,
virNetworkObjList netobjs,
virNetworkPtr **nets,
virNetworkObjListFilter filter,
unsigned int flags);
/* for testing */
int
virNetworkDefUpdateSection(virNetworkDefPtr def,
unsigned int command, /* virNetworkUpdateCommand */
unsigned int section, /* virNetworkUpdateSection */
int parentIndex,
const char *xml,
unsigned int flags); /* virNetworkUpdateFlags */
VIR_ENUM_DECL(virNetworkTaint)
#endif /* __NETWORK_CONF_H__ */