From nobody Mon Oct 27 17:18:53 2025
Delivered-To: importer@patchew.org
Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28
as permitted sender) client-ip=209.132.183.28;
envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com;
Authentication-Results: mx.zoho.com;
spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as
permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com;
Return-Path:
+... +<devices> + <interface type=3D'ethernet'> + <source> + <link state=3D'down'/> + <target dev=3D'vnet0'/> + </interface> +</devices> +...+ +
+ This element provides means of setting state of the phisical network=
interface.
+ Possible values for attribute state are up=
and
+ down. If down is specified as the value, t=
he interface
+ put in down state. Default behavior if this element is unspecified i=
s to have the
+ link state up.
+ Since 3.3.2
+
...
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 281309ec09da..89213d63b6e9 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2798,6 +2798,17 @@
All ip-related info for either the host or guest side of an interface
-->
+
+
+
+
+ up
+ down
+
+
+
+
+
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0ff216e3a373..b7398276af57 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9606,6 +9606,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
char *devaddr =3D NULL;
char *mode =3D NULL;
char *linkstate =3D NULL;
+ char *hostlinkstate =3D NULL;
char *addrtype =3D NULL;
char *domain_name =3D NULL;
char *vhostuser_mode =3D NULL;
@@ -9654,6 +9655,10 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
if (virDomainNetIPInfoParseXML(_("interface host IP"),
ctxt, &def->hostIP) < 0)
goto error;
+
+ if (!hostlinkstate)
+ hostlinkstate =3D virXPathString("string(./link/@st=
ate)", ctxt);
+
ctxt->node =3D tmpnode;
}
if (!macaddr && xmlStrEqual(cur->name, BAD_CAST "mac")) {
@@ -10303,6 +10308,16 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo=
pt,
}
}
=20
+ def->hostlinkstate =3D VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT;
+ if (hostlinkstate !=3D NULL) {
+ if ((def->hostlinkstate =3D virDomainNetInterfaceLinkStateTypeFrom=
String(hostlinkstate)) <=3D 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unknown interface link state '%s'"),
+ hostlinkstate);
+ goto error;
+ }
+ }
+
if (filter !=3D NULL) {
switch (def->type) {
case VIR_DOMAIN_NET_TYPE_ETHERNET:
@@ -10371,6 +10386,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop=
t,
VIR_FREE(devaddr);
VIR_FREE(mode);
VIR_FREE(linkstate);
+ VIR_FREE(hostlinkstate);
VIR_FREE(addrtype);
VIR_FREE(domain_name);
VIR_FREE(trustGuestRxFilters);
@@ -22113,6 +22129,18 @@ virDomainNetDefFormat(virBufferPtr buf,
break;
}
=20
+ if (def->hostlinkstate) {
+ if (sourceLines =3D=3D 0) {
+ virBufferAddLit(buf, "\n");
+ sourceLines +=3D 2;
+ }
+ virBufferAdjustIndent(buf, 2);
+ virBufferAsprintf(buf, "\n",
+ virDomainNetInterfaceLinkStateTypeToString(def->hostli=
nkstate));
+ virBufferAdjustIndent(buf, -2);
+ sourceLines +=3D 2;
+ }
+
/* if sourceLines =3D=3D 0 - no info at all so far
* sourceLines =3D=3D 1 - first line written, no terminating ">"
* sourceLines > 1 - multiple lines, including subelements
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 09fb7aada4b2..71e12a30c2c1 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1037,6 +1037,7 @@ struct _virDomainNetDef {
virNetDevVlan vlan;
int trustGuestRxFilters; /* enum virTristateBool */
int linkstate;
+ int hostlinkstate;
unsigned int mtu;
virNetDevCoalescePtr coalesce;
};
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e8d29186eb32..7fc41b28d9f8 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2978,6 +2978,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
bool needBridgeChange =3D false;
bool needFilterChange =3D false;
bool needLinkStateChange =3D false;
+ bool needHostLinkStateChange =3D false;
bool needReplaceDevDef =3D false;
bool needBandwidthSet =3D false;
int ret =3D -1;
@@ -3264,6 +3265,9 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
if (olddev->linkstate !=3D newdev->linkstate)
needLinkStateChange =3D true;
=20
+ if (olddev->hostlinkstate !=3D newdev->hostlinkstate)
+ needHostLinkStateChange =3D true;
+
if (!virNetDevBandwidthEqual(virDomainNetGetActualBandwidth(olddev),
virDomainNetGetActualBandwidth(newdev)))
needBandwidthSet =3D true;
@@ -3308,6 +3312,19 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
goto cleanup;
}
=20
+ if (needHostLinkStateChange) {
+ if (newdev->hostlinkstate =3D=3D VIR_DOMAIN_NET_INTERFACE_LINK_STA=
TE_DOWN) {
+ if (virNetDevSetOnline(newdev->ifname, false) < 0)
+ goto cleanup;
+ } else {
+ if (virNetDevSetOnline(newdev->ifname, true) < 0)
+ goto cleanup;
+ if (virNetDevIPInfoAddToDev(newdev->ifname, &newdev->hostIP) <=
0)
+ goto cleanup;
+ }
+ needReplaceDevDef =3D true;
+ }
+
if (needReplaceDevDef) {
/* the changes above warrant replacing olddev with newdev in
* the domain's nets list.
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index d8a678b4ab13..f3afbdae4009 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -413,7 +413,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
{
virMacAddr tapmac;
int ret =3D -1;
- unsigned int tap_create_flags =3D VIR_NETDEV_TAP_CREATE_IFUP;
+ unsigned int tap_create_flags =3D 0;
bool template_ifname =3D false;
virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver);
const char *tunpath =3D "/dev/net/tun";
@@ -427,6 +427,9 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
}
}
=20
+ if (net->hostlinkstate !=3D VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
+ tap_create_flags |=3D VIR_NETDEV_TAP_CREATE_IFUP;
+
if (!net->ifname ||
STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) ||
strchr(net->ifname, '%')) {
@@ -453,9 +456,6 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
if (virNetDevSetMAC(net->ifname, &tapmac) < 0)
goto cleanup;
=20
- if (virNetDevSetOnline(net->ifname, true) < 0)
- goto cleanup;
-
if (net->script &&
virNetDevRunEthernetScript(net->ifname, net->script) < 0)
goto cleanup;
--=20
2.9.3
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list