mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
LXC: set IP addresses to veth devices in the container
Uses the new virDomainNetDef ips to set the IP addresses on the network interfaces in the container.
This commit is contained in:
parent
aa2cc72100
commit
ecdc93830e
@ -495,7 +495,7 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||||||
char **veths)
|
char **veths)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
size_t i;
|
size_t i, j;
|
||||||
char *newname = NULL;
|
char *newname = NULL;
|
||||||
virDomainNetDefPtr netDef;
|
virDomainNetDefPtr netDef;
|
||||||
bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
|
bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
|
||||||
@ -516,6 +516,24 @@ static int lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
|
|||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto error_out;
|
goto error_out;
|
||||||
|
|
||||||
|
for (j = 0; j < netDef->nips; j++) {
|
||||||
|
virDomainNetIpDefPtr ip = netDef->ips[j];
|
||||||
|
unsigned int prefix = (ip->prefix > 0) ? ip->prefix :
|
||||||
|
VIR_SOCKET_ADDR_DEFAULT_PREFIX;
|
||||||
|
char *ipStr = virSocketAddrFormat(&ip->address);
|
||||||
|
|
||||||
|
VIR_DEBUG("Adding IP address '%s/%u' to '%s'",
|
||||||
|
ipStr, ip->prefix, newname);
|
||||||
|
if (virNetDevSetIPAddress(newname, &ip->address, prefix) < 0) {
|
||||||
|
virReportError(VIR_ERR_SYSTEM_ERROR,
|
||||||
|
_("Failed to set IP address '%s' on %s"),
|
||||||
|
ipStr, newname);
|
||||||
|
VIR_FREE(ipStr);
|
||||||
|
goto error_out;
|
||||||
|
}
|
||||||
|
VIR_FREE(ipStr);
|
||||||
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Enabling %s", newname);
|
VIR_DEBUG("Enabling %s", newname);
|
||||||
rc = virNetDevSetOnline(newname, true);
|
rc = virNetDevSetOnline(newname, true);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
@ -54,6 +54,8 @@ typedef struct {
|
|||||||
# define VIR_SOCKET_ADDR_FAMILY(s) \
|
# define VIR_SOCKET_ADDR_FAMILY(s) \
|
||||||
((s)->data.sa.sa_family)
|
((s)->data.sa.sa_family)
|
||||||
|
|
||||||
|
# define VIR_SOCKET_ADDR_DEFAULT_PREFIX 24
|
||||||
|
|
||||||
typedef virSocketAddr *virSocketAddrPtr;
|
typedef virSocketAddr *virSocketAddrPtr;
|
||||||
|
|
||||||
typedef struct _virSocketAddrRange virSocketAddrRange;
|
typedef struct _virSocketAddrRange virSocketAddrRange;
|
||||||
|
Loading…
Reference in New Issue
Block a user