static int virInterfaceBondDefFormat(virBufferPtr buf, const virInterfaceDefPtr def, int level) { int i; int ret = 0; virBufferAsprintf(buf, "%*s <bond", level*2, ""); if (def->data.bond.mode == VIR_INTERFACE_BOND_BALRR) virBufferAddLit(buf, " mode='balance-rr'"); else if (def->data.bond.mode == VIR_INTERFACE_BOND_ABACKUP) virBufferAddLit(buf, " mode='active-backup'"); else if (def->data.bond.mode == VIR_INTERFACE_BOND_BALXOR) virBufferAddLit(buf, " mode='balance-xor'"); else if (def->data.bond.mode == VIR_INTERFACE_BOND_BCAST) virBufferAddLit(buf, " mode='broadcast'"); else if (def->data.bond.mode == VIR_INTERFACE_BOND_8023AD) virBufferAddLit(buf, " mode='802.3ad'"); else if (def->data.bond.mode == VIR_INTERFACE_BOND_BALTLB) virBufferAddLit(buf, " mode='balance-tlb'"); else if (def->data.bond.mode == VIR_INTERFACE_BOND_BALALB) virBufferAddLit(buf, " mode='balance-alb'"); virBufferAddLit(buf, ">\n"); if (def->data.bond.monit == VIR_INTERFACE_BOND_MONIT_MII) { virBufferAsprintf(buf, "%*s <miimon freq='%d'", level*2, "", def->data.bond.frequency); if (def->data.bond.downdelay > 0) virBufferAsprintf(buf, " downdelay='%d'", def->data.bond.downdelay); if (def->data.bond.updelay > 0) virBufferAsprintf(buf, " updelay='%d'", def->data.bond.updelay); if (def->data.bond.carrier == VIR_INTERFACE_BOND_MII_IOCTL) virBufferAddLit(buf, " carrier='ioctl'"); else if (def->data.bond.carrier == VIR_INTERFACE_BOND_MII_NETIF) virBufferAddLit(buf, " carrier='netif'"); virBufferAddLit(buf, "/>\n"); } else if (def->data.bond.monit == VIR_INTERFACE_BOND_MONIT_ARP) { if (def->data.bond.target == NULL) { virInterfaceReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("bond arp monitoring has no target")); return -1; } virBufferAsprintf(buf, "%*s <arpmon interval='%d' target='%s'", level*2, "", def->data.bond.interval, def->data.bond.target); if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_ACTIVE) virBufferAddLit(buf, " validate='active'"); else if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_BACKUP) virBufferAddLit(buf, " validate='backup'"); else if (def->data.bond.validate == VIR_INTERFACE_BOND_ARP_ALL) virBufferAddLit(buf, " validate='all'"); virBufferAddLit(buf, "/>\n"); } for (i = 0;i < def->data.bond.nbItf;i++) { if (virInterfaceDefDevFormat(buf, def->data.bond.itf[i], level+2) < 0) ret = -1; } virBufferAsprintf(buf, "%*s </bond>\n", level*2, ""); return ret; }
static int virInterfaceBridgeDefFormat(virBufferPtr buf, const virInterfaceDef *def, int level) { size_t i; int ret = 0; virBufferAsprintf(buf, "%*s <bridge", level*2, ""); if (def->data.bridge.stp == 1) virBufferAddLit(buf, " stp='on'"); else if (def->data.bridge.stp == 0) virBufferAddLit(buf, " stp='off'"); if (def->data.bridge.delay != NULL) virBufferAsprintf(buf, " delay='%s'", def->data.bridge.delay); virBufferAddLit(buf, ">\n"); for (i = 0; i < def->data.bridge.nbItf; i++) { if (virInterfaceDefDevFormat(buf, def->data.bridge.itf[i], level+2) < 0) ret = -1; } virBufferAsprintf(buf, "%*s </bridge>\n", level*2, ""); return ret; }
char *virInterfaceDefFormat(const virInterfaceDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; if (virInterfaceDefDevFormat(&buf, def, 0) < 0) { virBufferFreeAndReset(&buf); return NULL; } return virBufferContentAndReset(&buf); }