static int virInterfaceDefParseProtoIPv6(virInterfaceProtocolDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr dhcp, autoconf; xmlNodePtr *ipNodes = NULL; int nIpNodes, ii, ret = -1; char *tmp; tmp = virXPathString("string(./route[1]/@gateway)", ctxt); def->gateway = tmp; autoconf = virXPathNode("./autoconf", ctxt); if (autoconf != NULL) def->autoconf = 1; dhcp = virXPathNode("./dhcp", ctxt); if (dhcp != NULL) { ret = virInterfaceDefParseDhcp(def, dhcp, ctxt); if (ret != 0) return ret; } nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes); if (nIpNodes < 0) return -1; if (ipNodes == NULL) return 0; if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) { virReportOOMError(); goto error; } def->nips = 0; for (ii = 0; ii < nIpNodes; ii++) { virInterfaceIpDefPtr ip; if (VIR_ALLOC(ip) < 0) { virReportOOMError(); goto error; } ctxt->node = ipNodes[ii]; ret = virInterfaceDefParseIp(ip, ctxt); if (ret != 0) { virInterfaceIpDefFree(ip); goto error; } def->ips[def->nips++] = ip; } ret = 0; error: VIR_FREE(ipNodes); return ret; }
static void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def) { int ii; if (def == NULL) return; for (ii = 0; ii < def->nips; ii++) { virInterfaceIpDefFree(def->ips[ii]); } VIR_FREE(def->ips); VIR_FREE(def->family); VIR_FREE(def->gateway); VIR_FREE(def); }
static int virInterfaceDefParseProtoIPv4(virInterfaceProtocolDefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr dhcp; xmlNodePtr *ipNodes = NULL; int nIpNodes, ret = -1; size_t i; char *tmp; tmp = virXPathString("string(./route[1]/@gateway)", ctxt); def->gateway = tmp; dhcp = virXPathNode("./dhcp", ctxt); if (dhcp != NULL) { if (virInterfaceDefParseDhcp(def, dhcp, ctxt) < 0) return -1; } nIpNodes = virXPathNodeSet("./ip", ctxt, &ipNodes); if (nIpNodes < 0) return -1; if (ipNodes == NULL) return 0; if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) goto error; def->nips = 0; for (i = 0; i < nIpNodes; i++) { virInterfaceIpDefPtr ip; if (VIR_ALLOC(ip) < 0) goto error; ctxt->node = ipNodes[i]; if (virInterfaceDefParseIp(ip, ctxt) < 0) { virInterfaceIpDefFree(ip); goto error; } def->ips[def->nips++] = ip; } ret = 0; error: VIR_FREE(ipNodes); return ret; }