mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
Santize naming of socket address APIs
The socket address APIs in src/util/network.h either take the form virSocketAddrXXX, virSocketXXX or virSocketXXXAddr. Sanitize this so everything is virSocketAddrXXXX, and ensure that the virSocketAddr parameter is always the first one. * src/util/network.c, src/util/network.h: Santize socket address API naming * src/conf/domain_conf.c, src/conf/network_conf.c, src/conf/nwfilter_conf.c, src/network/bridge_driver.c, src/nwfilter/nwfilter_ebiptables_driver.c, src/nwfilter/nwfilter_learnipaddr.c, src/qemu/qemu_command.c, src/rpc/virnetsocket.c, src/util/dnsmasq.c, src/util/iptables.c, src/util/virnetdev.c, src/vbox/vbox_tmpl.c: Update for API renaming
This commit is contained in:
parent
e49c9bf25c
commit
4c544e6c61
@ -3685,7 +3685,7 @@ virDomainChrDefParseTargetXML(virCapsPtr caps,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(def->target.addr, addrStr, AF_UNSPEC) < 0)
|
||||
goto error;
|
||||
|
||||
if (def->target.addr->data.stor.ss_family != AF_INET) {
|
||||
@ -3709,7 +3709,7 @@ virDomainChrDefParseTargetXML(virCapsPtr caps,
|
||||
goto error;
|
||||
}
|
||||
|
||||
virSocketSetPort(def->target.addr, port);
|
||||
virSocketAddrSetPort(def->target.addr, port);
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:
|
||||
@ -8379,8 +8379,8 @@ static bool virDomainChannelDefCheckABIStability(virDomainChrDefPtr src,
|
||||
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD:
|
||||
if (memcmp(src->target.addr, dst->target.addr,
|
||||
sizeof(*src->target.addr)) != 0) {
|
||||
char *saddr = virSocketFormatAddrFull(src->target.addr, true, ":");
|
||||
char *daddr = virSocketFormatAddrFull(dst->target.addr, true, ":");
|
||||
char *saddr = virSocketAddrFormatFull(src->target.addr, true, ":");
|
||||
char *daddr = virSocketAddrFormatFull(dst->target.addr, true, ":");
|
||||
virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Target channel addr %s does not match source %s"),
|
||||
NULLSTR(daddr), NULLSTR(saddr));
|
||||
@ -10035,14 +10035,14 @@ virDomainChrDefFormat(virBufferPtr buf,
|
||||
|
||||
switch (def->targetType) {
|
||||
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD: {
|
||||
int port = virSocketGetPort(def->target.addr);
|
||||
int port = virSocketAddrGetPort(def->target.addr);
|
||||
if (port < 0) {
|
||||
virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to format guestfwd port"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *addr = virSocketFormatAddr(def->target.addr);
|
||||
const char *addr = virSocketAddrFormat(def->target.addr);
|
||||
if (addr == NULL)
|
||||
return -1;
|
||||
|
||||
|
@ -286,7 +286,7 @@ virNetworkDefGetIpByIndex(const virNetworkDefPtr def,
|
||||
|
||||
/* find the nth ip of type "family" */
|
||||
for (ii = 0; ii < def->nips; ii++) {
|
||||
if (VIR_SOCKET_IS_FAMILY(&def->ips[ii].address, family)
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&def->ips[ii].address, family)
|
||||
&& (n-- <= 0)) {
|
||||
return &def->ips[ii];
|
||||
}
|
||||
@ -302,9 +302,9 @@ int virNetworkIpDefPrefix(const virNetworkIpDefPtr def)
|
||||
{
|
||||
if (def->prefix > 0) {
|
||||
return def->prefix;
|
||||
} else if (VIR_SOCKET_HAS_ADDR(&def->netmask)) {
|
||||
return virSocketGetNumNetmaskBits(&def->netmask);
|
||||
} else if (VIR_SOCKET_IS_FAMILY(&def->address, AF_INET)) {
|
||||
} else if (VIR_SOCKET_ADDR_VALID(&def->netmask)) {
|
||||
return virSocketAddrGetNumNetmaskBits(&def->netmask);
|
||||
} else if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)) {
|
||||
/* Return the natural prefix for the network's ip address.
|
||||
* On Linux we could use the IN_CLASSx() macros, but those
|
||||
* aren't guaranteed on all platforms, so we just deal with
|
||||
@ -323,7 +323,7 @@ int virNetworkIpDefPrefix(const virNetworkIpDefPtr def)
|
||||
return 24;
|
||||
}
|
||||
return -1;
|
||||
} else if (VIR_SOCKET_IS_FAMILY(&def->address, AF_INET6)) {
|
||||
} else if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET6)) {
|
||||
return 64;
|
||||
}
|
||||
return -1;
|
||||
@ -336,13 +336,13 @@ int virNetworkIpDefPrefix(const virNetworkIpDefPtr def)
|
||||
int virNetworkIpDefNetmask(const virNetworkIpDefPtr def,
|
||||
virSocketAddrPtr netmask)
|
||||
{
|
||||
if (VIR_SOCKET_IS_FAMILY(&def->netmask, AF_INET)) {
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&def->netmask, AF_INET)) {
|
||||
*netmask = def->netmask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return virSocketAddrPrefixToNetmask(virNetworkIpDefPrefix(def), netmask,
|
||||
VIR_SOCKET_FAMILY(&def->address));
|
||||
VIR_SOCKET_ADDR_FAMILY(&def->address));
|
||||
}
|
||||
|
||||
|
||||
@ -372,18 +372,18 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (virSocketParseAddr(start, &saddr, AF_UNSPEC) < 0) {
|
||||
if (virSocketAddrParse(&saddr, start, AF_UNSPEC) < 0) {
|
||||
VIR_FREE(start);
|
||||
VIR_FREE(end);
|
||||
return -1;
|
||||
}
|
||||
if (virSocketParseAddr(end, &eaddr, AF_UNSPEC) < 0) {
|
||||
if (virSocketAddrParse(&eaddr, end, AF_UNSPEC) < 0) {
|
||||
VIR_FREE(start);
|
||||
VIR_FREE(end);
|
||||
return -1;
|
||||
}
|
||||
|
||||
range = virSocketGetRange(&saddr, &eaddr);
|
||||
range = virSocketAddrGetRange(&saddr, &eaddr);
|
||||
if (range < 0) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("Invalid dhcp range '%s' to '%s' in network '%s'"),
|
||||
@ -434,7 +434,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
|
||||
}
|
||||
ip = virXMLPropString(cur, "ip");
|
||||
if ((ip == NULL) ||
|
||||
(virSocketParseAddr(ip, &inaddr, AF_UNSPEC) < 0)) {
|
||||
(virSocketAddrParse(&inaddr, ip, AF_UNSPEC) < 0)) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("Missing IP address in static host definition for network '%s'"),
|
||||
networkName);
|
||||
@ -469,7 +469,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
|
||||
server = virXMLPropString(cur, "server");
|
||||
|
||||
if (server &&
|
||||
virSocketParseAddr(server, &inaddr, AF_UNSPEC) < 0) {
|
||||
virSocketAddrParse(&inaddr, server, AF_UNSPEC) < 0) {
|
||||
VIR_FREE(file);
|
||||
VIR_FREE(server);
|
||||
return -1;
|
||||
@ -504,7 +504,7 @@ virNetworkDNSHostsDefParseXML(virNetworkDNSDefPtr def,
|
||||
}
|
||||
|
||||
if (!(ip = virXMLPropString(node, "ip")) ||
|
||||
(virSocketParseAddr(ip, &inaddr, AF_UNSPEC) < 0)) {
|
||||
(virSocketAddrParse(&inaddr, ip, AF_UNSPEC) < 0)) {
|
||||
virNetworkReportError(VIR_ERR_XML_DETAIL,
|
||||
_("Missing IP address in DNS host definition"));
|
||||
VIR_FREE(ip);
|
||||
@ -649,7 +649,7 @@ virNetworkIPParseXML(const char *networkName,
|
||||
netmask = virXPathString("string(./@netmask)", ctxt);
|
||||
|
||||
if (address) {
|
||||
if (virSocketParseAddr(address, &def->address, AF_UNSPEC) < 0) {
|
||||
if (virSocketAddrParse(&def->address, address, AF_UNSPEC) < 0) {
|
||||
virNetworkReportError(VIR_ERR_XML_ERROR,
|
||||
_("Bad address '%s' in definition of network '%s'"),
|
||||
address, networkName);
|
||||
@ -660,22 +660,22 @@ virNetworkIPParseXML(const char *networkName,
|
||||
|
||||
/* validate family vs. address */
|
||||
if (def->family == NULL) {
|
||||
if (!(VIR_SOCKET_IS_FAMILY(&def->address, AF_INET) ||
|
||||
VIR_SOCKET_IS_FAMILY(&def->address, AF_UNSPEC))) {
|
||||
if (!(VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET) ||
|
||||
VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_UNSPEC))) {
|
||||
virNetworkReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("no family specified for non-IPv4 address address '%s' in network '%s'"),
|
||||
address, networkName);
|
||||
goto error;
|
||||
}
|
||||
} else if (STREQ(def->family, "ipv4")) {
|
||||
if (!VIR_SOCKET_IS_FAMILY(&def->address, AF_INET)) {
|
||||
if (!VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)) {
|
||||
virNetworkReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("family 'ipv4' specified for non-IPv4 address '%s' in network '%s'"),
|
||||
address, networkName);
|
||||
goto error;
|
||||
}
|
||||
} else if (STREQ(def->family, "ipv6")) {
|
||||
if (!VIR_SOCKET_IS_FAMILY(&def->address, AF_INET6)) {
|
||||
if (!VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET6)) {
|
||||
virNetworkReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("family 'ipv6' specified for non-IPv6 address '%s' in network '%s'"),
|
||||
address, networkName);
|
||||
@ -698,7 +698,7 @@ virNetworkIPParseXML(const char *networkName,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!VIR_SOCKET_IS_FAMILY(&def->address, AF_INET)) {
|
||||
if (!VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)) {
|
||||
virNetworkReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("netmask not supported for address '%s' in network '%s' (IPv4 only)"),
|
||||
address, networkName);
|
||||
@ -713,10 +713,10 @@ virNetworkIPParseXML(const char *networkName,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virSocketParseAddr(netmask, &def->netmask, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(&def->netmask, netmask, AF_UNSPEC) < 0)
|
||||
goto error;
|
||||
|
||||
if (!VIR_SOCKET_IS_FAMILY(&def->netmask, AF_INET)) {
|
||||
if (!VIR_SOCKET_ADDR_IS_FAMILY(&def->netmask, AF_INET)) {
|
||||
virNetworkReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("network '%s' has invalid netmask '%s' for address '%s' (both must be IPv4)"),
|
||||
networkName, netmask, address);
|
||||
@ -724,7 +724,7 @@ virNetworkIPParseXML(const char *networkName,
|
||||
}
|
||||
}
|
||||
|
||||
if (VIR_SOCKET_IS_FAMILY(&def->address, AF_INET)) {
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)) {
|
||||
/* parse IPv4-related info */
|
||||
cur = node->children;
|
||||
while (cur != NULL) {
|
||||
@ -1151,7 +1151,7 @@ virNetworkDNSDefFormat(virBufferPtr buf,
|
||||
int ii, j;
|
||||
|
||||
for (ii = 0 ; ii < def->nhosts; ii++) {
|
||||
char *ip = virSocketFormatAddr(&def->hosts[ii].ip);
|
||||
char *ip = virSocketAddrFormat(&def->hosts[ii].ip);
|
||||
|
||||
virBufferAsprintf(buf, " <host ip='%s'>\n", ip);
|
||||
|
||||
@ -1180,15 +1180,15 @@ virNetworkIpDefFormat(virBufferPtr buf,
|
||||
if (def->family) {
|
||||
virBufferAsprintf(buf, " family='%s'", def->family);
|
||||
}
|
||||
if (VIR_SOCKET_HAS_ADDR(&def->address)) {
|
||||
char *addr = virSocketFormatAddr(&def->address);
|
||||
if (VIR_SOCKET_ADDR_VALID(&def->address)) {
|
||||
char *addr = virSocketAddrFormat(&def->address);
|
||||
if (!addr)
|
||||
goto error;
|
||||
virBufferAsprintf(buf, " address='%s'", addr);
|
||||
VIR_FREE(addr);
|
||||
}
|
||||
if (VIR_SOCKET_HAS_ADDR(&def->netmask)) {
|
||||
char *addr = virSocketFormatAddr(&def->netmask);
|
||||
if (VIR_SOCKET_ADDR_VALID(&def->netmask)) {
|
||||
char *addr = virSocketAddrFormat(&def->netmask);
|
||||
if (!addr)
|
||||
goto error;
|
||||
virBufferAsprintf(buf, " netmask='%s'", addr);
|
||||
@ -1207,10 +1207,10 @@ virNetworkIpDefFormat(virBufferPtr buf,
|
||||
int ii;
|
||||
virBufferAddLit(buf, " <dhcp>\n");
|
||||
for (ii = 0 ; ii < def->nranges ; ii++) {
|
||||
char *saddr = virSocketFormatAddr(&def->ranges[ii].start);
|
||||
char *saddr = virSocketAddrFormat(&def->ranges[ii].start);
|
||||
if (!saddr)
|
||||
goto error;
|
||||
char *eaddr = virSocketFormatAddr(&def->ranges[ii].end);
|
||||
char *eaddr = virSocketAddrFormat(&def->ranges[ii].end);
|
||||
if (!eaddr) {
|
||||
VIR_FREE(saddr);
|
||||
goto error;
|
||||
@ -1226,8 +1226,8 @@ virNetworkIpDefFormat(virBufferPtr buf,
|
||||
virBufferAsprintf(buf, "mac='%s' ", def->hosts[ii].mac);
|
||||
if (def->hosts[ii].name)
|
||||
virBufferAsprintf(buf, "name='%s' ", def->hosts[ii].name);
|
||||
if (VIR_SOCKET_HAS_ADDR(&def->hosts[ii].ip)) {
|
||||
char *ipaddr = virSocketFormatAddr(&def->hosts[ii].ip);
|
||||
if (VIR_SOCKET_ADDR_VALID(&def->hosts[ii].ip)) {
|
||||
char *ipaddr = virSocketAddrFormat(&def->hosts[ii].ip);
|
||||
if (!ipaddr)
|
||||
goto error;
|
||||
virBufferAsprintf(buf, "ip='%s' ", ipaddr);
|
||||
@ -1238,8 +1238,8 @@ virNetworkIpDefFormat(virBufferPtr buf,
|
||||
if (def->bootfile) {
|
||||
virBufferEscapeString(buf, " <bootp file='%s' ",
|
||||
def->bootfile);
|
||||
if (VIR_SOCKET_HAS_ADDR(&def->bootserver)) {
|
||||
char *ipaddr = virSocketFormatAddr(&def->bootserver);
|
||||
if (VIR_SOCKET_ADDR_VALID(&def->bootserver)) {
|
||||
char *ipaddr = virSocketAddrFormat(&def->bootserver);
|
||||
if (!ipaddr)
|
||||
goto error;
|
||||
virBufferEscapeString(buf, "server='%s' ", ipaddr);
|
||||
|
@ -1523,8 +1523,7 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
||||
break;
|
||||
|
||||
case DATATYPE_IPADDR:
|
||||
if (virSocketParseIpv4Addr(prop,
|
||||
&item->u.ipaddr) < 0)
|
||||
if (virSocketAddrParseIPv4(&item->u.ipaddr, prop) < 0)
|
||||
rc = -1;
|
||||
found = 1;
|
||||
break;
|
||||
@ -1539,10 +1538,10 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
||||
} else
|
||||
rc = -1;
|
||||
} else {
|
||||
if (virSocketParseIpv4Addr(prop, &ipaddr) < 0) {
|
||||
if (virSocketAddrParseIPv4(&ipaddr, prop) < 0) {
|
||||
rc = -1;
|
||||
} else {
|
||||
int_val = virSocketGetNumNetmaskBits(&ipaddr);
|
||||
int_val = virSocketAddrGetNumNetmaskBits(&ipaddr);
|
||||
if (int_val >= 0)
|
||||
item->u.u8 = int_val;
|
||||
else
|
||||
@ -1571,8 +1570,7 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
||||
break;
|
||||
|
||||
case DATATYPE_IPV6ADDR:
|
||||
if (virSocketParseIpv6Addr(prop,
|
||||
&item->u.ipaddr) < 0)
|
||||
if (virSocketAddrParseIPv6(&item->u.ipaddr, prop) < 0)
|
||||
rc = -1;
|
||||
found = 1;
|
||||
break;
|
||||
@ -1587,10 +1585,10 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
|
||||
} else
|
||||
rc = -1;
|
||||
} else {
|
||||
if (virSocketParseIpv6Addr(prop, &ipaddr) < 0) {
|
||||
if (virSocketAddrParseIPv6(&ipaddr, prop) < 0) {
|
||||
rc = -1;
|
||||
} else {
|
||||
int_val = virSocketGetNumNetmaskBits(&ipaddr);
|
||||
int_val = virSocketAddrGetNumNetmaskBits(&ipaddr);
|
||||
if (int_val >= 0)
|
||||
item->u.u8 = int_val;
|
||||
else
|
||||
@ -2596,7 +2594,7 @@ virNWFilterObjDeleteDef(virNWFilterObjPtr nwfilter)
|
||||
static void
|
||||
virNWIPAddressFormat(virBufferPtr buf, virSocketAddrPtr ipaddr)
|
||||
{
|
||||
char *output = virSocketFormatAddr(ipaddr);
|
||||
char *output = virSocketAddrFormat(ipaddr);
|
||||
|
||||
if (output) {
|
||||
virBufferAdd(buf, output, -1);
|
||||
|
@ -773,19 +773,19 @@ virBandwidthEnable;
|
||||
virBandwidthEqual;
|
||||
virSocketAddrBroadcast;
|
||||
virSocketAddrBroadcastByPrefix;
|
||||
virSocketAddrCheckNetmask;
|
||||
virSocketAddrFormat;
|
||||
virSocketAddrFormatFull;
|
||||
virSocketAddrGetPort;
|
||||
virSocketAddrGetRange;
|
||||
virSocketAddrIsNetmask;
|
||||
virSocketAddrMask;
|
||||
virSocketAddrMaskByPrefix;
|
||||
virSocketAddrParse;
|
||||
virSocketAddrParseIPv4;
|
||||
virSocketAddrParseIPv6;
|
||||
virSocketAddrPrefixToNetmask;
|
||||
virSocketCheckNetmask;
|
||||
virSocketFormatAddr;
|
||||
virSocketFormatAddrFull;
|
||||
virSocketGetPort;
|
||||
virSocketGetRange;
|
||||
virSocketParseAddr;
|
||||
virSocketParseIpv4Addr;
|
||||
virSocketParseIpv6Addr;
|
||||
virSocketSetPort;
|
||||
virSocketAddrSetPort;
|
||||
virVirtualPortProfileEqual;
|
||||
virVirtualPortProfileFormat;
|
||||
virVirtualPortProfileParseXML;
|
||||
|
@ -432,7 +432,7 @@ networkBuildDnsmasqHostsfile(dnsmasqContext *dctx,
|
||||
|
||||
for (i = 0; i < ipdef->nhosts; i++) {
|
||||
virNetworkDHCPHostDefPtr host = &(ipdef->hosts[i]);
|
||||
if ((host->mac) && VIR_SOCKET_HAS_ADDR(&host->ip))
|
||||
if ((host->mac) && VIR_SOCKET_ADDR_VALID(&host->ip))
|
||||
if (dnsmasqAddDhcpHost(dctx, host->mac, &host->ip, host->name) < 0)
|
||||
return -1;
|
||||
}
|
||||
@ -440,7 +440,7 @@ networkBuildDnsmasqHostsfile(dnsmasqContext *dctx,
|
||||
if (dnsdef) {
|
||||
for (i = 0; i < dnsdef->nhosts; i++) {
|
||||
virNetworkDNSHostsDefPtr host = &(dnsdef->hosts[i]);
|
||||
if (VIR_SOCKET_HAS_ADDR(&host->ip)) {
|
||||
if (VIR_SOCKET_ADDR_VALID(&host->ip)) {
|
||||
for (j = 0; j < host->nnames; j++)
|
||||
if (dnsmasqAddHost(dctx, &host->ip, host->names[j]) < 0)
|
||||
return -1;
|
||||
@ -543,7 +543,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
|
||||
for (ii = 0;
|
||||
(tmpipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii));
|
||||
ii++) {
|
||||
char *ipaddr = virSocketFormatAddr(&tmpipdef->address);
|
||||
char *ipaddr = virSocketAddrFormat(&tmpipdef->address);
|
||||
if (!ipaddr)
|
||||
goto cleanup;
|
||||
virCommandAddArgList(cmd, "--listen-address", ipaddr, NULL);
|
||||
@ -552,10 +552,10 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
|
||||
|
||||
if (ipdef) {
|
||||
for (r = 0 ; r < ipdef->nranges ; r++) {
|
||||
char *saddr = virSocketFormatAddr(&ipdef->ranges[r].start);
|
||||
char *saddr = virSocketAddrFormat(&ipdef->ranges[r].start);
|
||||
if (!saddr)
|
||||
goto cleanup;
|
||||
char *eaddr = virSocketFormatAddr(&ipdef->ranges[r].end);
|
||||
char *eaddr = virSocketAddrFormat(&ipdef->ranges[r].end);
|
||||
if (!eaddr) {
|
||||
VIR_FREE(saddr);
|
||||
goto cleanup;
|
||||
@ -564,8 +564,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
|
||||
virCommandAddArgFormat(cmd, "%s,%s", saddr, eaddr);
|
||||
VIR_FREE(saddr);
|
||||
VIR_FREE(eaddr);
|
||||
nbleases += virSocketGetRange(&ipdef->ranges[r].start,
|
||||
&ipdef->ranges[r].end);
|
||||
nbleases += virSocketAddrGetRange(&ipdef->ranges[r].start,
|
||||
&ipdef->ranges[r].end);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -574,7 +574,7 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
|
||||
* dnsmasq.
|
||||
*/
|
||||
if (!ipdef->nranges && ipdef->nhosts) {
|
||||
char *bridgeaddr = virSocketFormatAddr(&ipdef->address);
|
||||
char *bridgeaddr = virSocketAddrFormat(&ipdef->address);
|
||||
if (!bridgeaddr)
|
||||
goto cleanup;
|
||||
virCommandAddArg(cmd, "--dhcp-range");
|
||||
@ -615,8 +615,8 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network,
|
||||
}
|
||||
if (ipdef->bootfile) {
|
||||
virCommandAddArg(cmd, "--dhcp-boot");
|
||||
if (VIR_SOCKET_HAS_ADDR(&ipdef->bootserver)) {
|
||||
char *bootserver = virSocketFormatAddr(&ipdef->bootserver);
|
||||
if (VIR_SOCKET_ADDR_VALID(&ipdef->bootserver)) {
|
||||
char *bootserver = virSocketAddrFormat(&ipdef->bootserver);
|
||||
|
||||
if (!bootserver)
|
||||
goto cleanup;
|
||||
@ -815,7 +815,7 @@ networkStartRadvd(virNetworkObjPtr network)
|
||||
network->def->bridge);
|
||||
goto cleanup;
|
||||
}
|
||||
if (!(netaddr = virSocketFormatAddr(&ipdef->address)))
|
||||
if (!(netaddr = virSocketAddrFormat(&ipdef->address)))
|
||||
goto cleanup;
|
||||
virBufferAsprintf(&configbuf,
|
||||
" prefix %s/%d\n"
|
||||
@ -1389,9 +1389,9 @@ networkAddIpSpecificIptablesRules(struct network_driver *driver,
|
||||
*/
|
||||
|
||||
if (network->def->forwardType == VIR_NETWORK_FORWARD_NAT) {
|
||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET))
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET))
|
||||
return networkAddMasqueradingIptablesRules(driver, network, ipdef);
|
||||
else if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET6))
|
||||
else if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6))
|
||||
return networkAddRoutingIptablesRules(driver, network, ipdef);
|
||||
} else if (network->def->forwardType == VIR_NETWORK_FORWARD_ROUTE) {
|
||||
return networkAddRoutingIptablesRules(driver, network, ipdef);
|
||||
@ -1405,9 +1405,9 @@ networkRemoveIpSpecificIptablesRules(struct network_driver *driver,
|
||||
virNetworkIpDefPtr ipdef)
|
||||
{
|
||||
if (network->def->forwardType == VIR_NETWORK_FORWARD_NAT) {
|
||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET))
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET))
|
||||
networkRemoveMasqueradingIptablesRules(driver, network, ipdef);
|
||||
else if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET6))
|
||||
else if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6))
|
||||
networkRemoveRoutingIptablesRules(driver, network, ipdef);
|
||||
} else if (network->def->forwardType == VIR_NETWORK_FORWARD_ROUTE) {
|
||||
networkRemoveRoutingIptablesRules(driver, network, ipdef);
|
||||
@ -1746,9 +1746,9 @@ networkStartNetworkVirtual(struct network_driver *driver,
|
||||
for (ii = 0;
|
||||
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii));
|
||||
ii++) {
|
||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET))
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET))
|
||||
v4present = true;
|
||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET6))
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6))
|
||||
v6present = true;
|
||||
|
||||
/* Add the IP address/netmask to the bridge */
|
||||
@ -2302,7 +2302,7 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
||||
for (ii = 0;
|
||||
(ipdef = virNetworkDefGetIpByIndex(def, AF_UNSPEC, ii));
|
||||
ii++) {
|
||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET)) {
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
|
||||
if (ipdef->nranges || ipdef->nhosts) {
|
||||
if (ipv4def) {
|
||||
networkReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
@ -2366,10 +2366,10 @@ static int networkUndefine(virNetworkPtr net) {
|
||||
for (ii = 0;
|
||||
(ipdef = virNetworkDefGetIpByIndex(network->def, AF_UNSPEC, ii));
|
||||
ii++) {
|
||||
if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET)) {
|
||||
if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET)) {
|
||||
if (ipdef->nranges || ipdef->nhosts)
|
||||
dhcp_present = true;
|
||||
} else if (VIR_SOCKET_IS_FAMILY(&ipdef->address, AF_INET6)) {
|
||||
} else if (VIR_SOCKET_ADDR_IS_FAMILY(&ipdef->address, AF_INET6)) {
|
||||
v6present = true;
|
||||
}
|
||||
}
|
||||
@ -3165,7 +3165,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
|
||||
}
|
||||
|
||||
if (addrptr &&
|
||||
(*netaddr = virSocketFormatAddr(addrptr))) {
|
||||
(*netaddr = virSocketAddrFormat(addrptr))) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ _printDataType(virNWFilterHashTablePtr vars,
|
||||
|
||||
switch (item->datatype) {
|
||||
case DATATYPE_IPADDR:
|
||||
data = virSocketFormatAddr(&item->u.ipaddr);
|
||||
data = virSocketAddrFormat(&item->u.ipaddr);
|
||||
if (!data)
|
||||
return 1;
|
||||
if (snprintf(buf, bufsize, "%s", data) >= bufsize) {
|
||||
@ -209,7 +209,7 @@ _printDataType(virNWFilterHashTablePtr vars,
|
||||
break;
|
||||
|
||||
case DATATYPE_IPV6ADDR:
|
||||
data = virSocketFormatAddr(&item->u.ipaddr);
|
||||
data = virSocketAddrFormat(&item->u.ipaddr);
|
||||
if (!data)
|
||||
return 1;
|
||||
|
||||
|
@ -630,7 +630,7 @@ learnIPAddressThread(void *arg)
|
||||
sa.data.inet4.sin_addr.s_addr = vmaddr;
|
||||
char *inetaddr;
|
||||
|
||||
if ((inetaddr = virSocketFormatAddr(&sa))!= NULL) {
|
||||
if ((inetaddr = virSocketAddrFormat(&sa))!= NULL) {
|
||||
virNWFilterAddIpAddrForIfname(req->ifname, inetaddr);
|
||||
|
||||
ret = virNWFilterInstantiateFilterLate(NULL,
|
||||
|
@ -4440,10 +4440,10 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
virCommandAddArg(cmd, devstr);
|
||||
VIR_FREE(devstr);
|
||||
|
||||
addr = virSocketFormatAddr(channel->target.addr);
|
||||
addr = virSocketAddrFormat(channel->target.addr);
|
||||
if (!addr)
|
||||
goto error;
|
||||
port = virSocketGetPort(channel->target.addr);
|
||||
port = virSocketAddrGetPort(channel->target.addr);
|
||||
|
||||
virCommandAddArg(cmd, "-netdev");
|
||||
virCommandAddArgFormat(cmd,
|
||||
|
@ -163,11 +163,11 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
|
||||
|
||||
|
||||
if (localAddr &&
|
||||
!(sock->localAddrStr = virSocketFormatAddrFull(localAddr, true, ";")))
|
||||
!(sock->localAddrStr = virSocketAddrFormatFull(localAddr, true, ";")))
|
||||
goto error;
|
||||
|
||||
if (remoteAddr &&
|
||||
!(sock->remoteAddrStr = virSocketFormatAddrFull(remoteAddr, true, ";")))
|
||||
!(sock->remoteAddrStr = virSocketAddrFormatFull(remoteAddr, true, ";")))
|
||||
goto error;
|
||||
|
||||
sock->client = isClient;
|
||||
@ -809,7 +809,7 @@ int virNetSocketGetPort(virNetSocketPtr sock)
|
||||
{
|
||||
int port;
|
||||
virMutexLock(&sock->lock);
|
||||
port = virSocketGetPort(&sock->localAddr);
|
||||
port = virSocketAddrGetPort(&sock->localAddr);
|
||||
virMutexUnlock(&sock->lock);
|
||||
return port;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
||||
int idx = -1;
|
||||
int i;
|
||||
|
||||
if (!(ipstr = virSocketFormatAddr(ip)))
|
||||
if (!(ipstr = virSocketAddrFormat(ip)))
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < addnhostsfile->nhosts; i++) {
|
||||
@ -300,7 +300,7 @@ hostsfileAdd(dnsmasqHostsfile *hostsfile,
|
||||
if (VIR_REALLOC_N(hostsfile->hosts, hostsfile->nhosts + 1) < 0)
|
||||
goto alloc_error;
|
||||
|
||||
if (!(ipstr = virSocketFormatAddr(ip)))
|
||||
if (!(ipstr = virSocketAddrFormat(ip)))
|
||||
return -1;
|
||||
|
||||
if (name) {
|
||||
|
@ -291,8 +291,8 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr,
|
||||
char *netstr;
|
||||
char *ret;
|
||||
|
||||
if (!(VIR_SOCKET_IS_FAMILY(netaddr, AF_INET) ||
|
||||
VIR_SOCKET_IS_FAMILY(netaddr, AF_INET6))) {
|
||||
if (!(VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET) ||
|
||||
VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET6))) {
|
||||
iptablesError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Only IPv4 or IPv6 addresses can be used with iptables"));
|
||||
return NULL;
|
||||
@ -304,7 +304,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netaddr,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
netstr = virSocketFormatAddr(&network);
|
||||
netstr = virSocketAddrFormat(&network);
|
||||
|
||||
if (!netstr)
|
||||
return NULL;
|
||||
@ -336,7 +336,7 @@ iptablesForwardAllowOut(iptablesContext *ctx,
|
||||
|
||||
if (physdev && physdev[0]) {
|
||||
ret = iptablesAddRemoveRule(ctx->forward_filter,
|
||||
VIR_SOCKET_FAMILY(netaddr),
|
||||
VIR_SOCKET_ADDR_FAMILY(netaddr),
|
||||
action,
|
||||
"--source", networkstr,
|
||||
"--in-interface", iface,
|
||||
@ -345,7 +345,7 @@ iptablesForwardAllowOut(iptablesContext *ctx,
|
||||
NULL);
|
||||
} else {
|
||||
ret = iptablesAddRemoveRule(ctx->forward_filter,
|
||||
VIR_SOCKET_FAMILY(netaddr),
|
||||
VIR_SOCKET_ADDR_FAMILY(netaddr),
|
||||
action,
|
||||
"--source", networkstr,
|
||||
"--in-interface", iface,
|
||||
@ -422,7 +422,7 @@ iptablesForwardAllowRelatedIn(iptablesContext *ctx,
|
||||
|
||||
if (physdev && physdev[0]) {
|
||||
ret = iptablesAddRemoveRule(ctx->forward_filter,
|
||||
VIR_SOCKET_FAMILY(netaddr),
|
||||
VIR_SOCKET_ADDR_FAMILY(netaddr),
|
||||
action,
|
||||
"--destination", networkstr,
|
||||
"--in-interface", physdev,
|
||||
@ -433,7 +433,7 @@ iptablesForwardAllowRelatedIn(iptablesContext *ctx,
|
||||
NULL);
|
||||
} else {
|
||||
ret = iptablesAddRemoveRule(ctx->forward_filter,
|
||||
VIR_SOCKET_FAMILY(netaddr),
|
||||
VIR_SOCKET_ADDR_FAMILY(netaddr),
|
||||
action,
|
||||
"--destination", networkstr,
|
||||
"--out-interface", iface,
|
||||
@ -510,7 +510,7 @@ iptablesForwardAllowIn(iptablesContext *ctx,
|
||||
|
||||
if (physdev && physdev[0]) {
|
||||
ret = iptablesAddRemoveRule(ctx->forward_filter,
|
||||
VIR_SOCKET_FAMILY(netaddr),
|
||||
VIR_SOCKET_ADDR_FAMILY(netaddr),
|
||||
action,
|
||||
"--destination", networkstr,
|
||||
"--in-interface", physdev,
|
||||
@ -519,7 +519,7 @@ iptablesForwardAllowIn(iptablesContext *ctx,
|
||||
NULL);
|
||||
} else {
|
||||
ret = iptablesAddRemoveRule(ctx->forward_filter,
|
||||
VIR_SOCKET_FAMILY(netaddr),
|
||||
VIR_SOCKET_ADDR_FAMILY(netaddr),
|
||||
action,
|
||||
"--destination", networkstr,
|
||||
"--out-interface", iface,
|
||||
@ -761,7 +761,7 @@ iptablesForwardMasquerade(iptablesContext *ctx,
|
||||
if (!(networkstr = iptablesFormatNetwork(netaddr, prefix)))
|
||||
return -1;
|
||||
|
||||
if (!VIR_SOCKET_IS_FAMILY(netaddr, AF_INET)) {
|
||||
if (!VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET)) {
|
||||
/* Higher level code *should* guaranteee it's impossible to get here. */
|
||||
iptablesError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Attempted to NAT '%s'. NAT is only supported for IPv4."),
|
||||
|
@ -27,12 +27,12 @@
|
||||
* Helpers to extract the IP arrays from the virSocketAddrPtr
|
||||
* That part is the less portable of the module
|
||||
*/
|
||||
typedef unsigned char virIPv4Addr[4];
|
||||
typedef virIPv4Addr *virIPv4AddrPtr;
|
||||
typedef unsigned short virIPv6Addr[8];
|
||||
typedef virIPv6Addr *virIPv6AddrPtr;
|
||||
typedef unsigned char virSocketAddrIPv4[4];
|
||||
typedef virSocketAddrIPv4 *virSocketAddrIPv4Ptr;
|
||||
typedef unsigned short virSocketAddrIPv6[8];
|
||||
typedef virSocketAddrIPv6 *virSocketAddrIPv6Ptr;
|
||||
|
||||
static int getIPv4Addr(virSocketAddrPtr addr, virIPv4AddrPtr tab) {
|
||||
static int virSocketAddrGetIPv4Addr(virSocketAddrPtr addr, virSocketAddrIPv4Ptr tab) {
|
||||
unsigned long val;
|
||||
int i;
|
||||
|
||||
@ -49,7 +49,7 @@ static int getIPv4Addr(virSocketAddrPtr addr, virIPv4AddrPtr tab) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
|
||||
static int virSocketAddrGetIPv6Addr(virSocketAddrPtr addr, virSocketAddrIPv6Ptr tab) {
|
||||
int i;
|
||||
|
||||
if ((addr == NULL) || (tab == NULL) || (addr->data.stor.ss_family != AF_INET6))
|
||||
@ -64,7 +64,7 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
|
||||
}
|
||||
|
||||
/**
|
||||
* virSocketParseAddr:
|
||||
* virSocketAddrParse:
|
||||
* @val: a numeric network address IPv4 or IPv6
|
||||
* @addr: where to store the return value, optional.
|
||||
* @family: address family to pass down to getaddrinfo
|
||||
@ -74,8 +74,7 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
|
||||
*
|
||||
* Returns the length of the network address or -1 in case of error.
|
||||
*/
|
||||
int
|
||||
virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) {
|
||||
int virSocketAddrParse(virSocketAddrPtr addr, const char *val, int family) {
|
||||
int len;
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *res = NULL;
|
||||
@ -114,7 +113,7 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) {
|
||||
}
|
||||
|
||||
/*
|
||||
* virSocketParseIpv4Addr:
|
||||
* virSocketAddrParseIPv4:
|
||||
* @val: an IPv4 numeric address
|
||||
* @addr: the location to store the result
|
||||
*
|
||||
@ -123,12 +122,12 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) {
|
||||
* Returns the length of the network address or -1 in case of error.
|
||||
*/
|
||||
int
|
||||
virSocketParseIpv4Addr(const char *val, virSocketAddrPtr addr) {
|
||||
return(virSocketParseAddr(val, addr, AF_INET));
|
||||
virSocketAddrParseIPv4(virSocketAddrPtr addr, const char *val) {
|
||||
return virSocketAddrParse(addr, val, AF_INET);
|
||||
}
|
||||
|
||||
/*
|
||||
* virSocketParseIpv6Addr:
|
||||
* virSocketAddrParseIPv6:
|
||||
* @val: an IPv6 numeric address
|
||||
* @addr: the location to store the result
|
||||
*
|
||||
@ -137,12 +136,12 @@ virSocketParseIpv4Addr(const char *val, virSocketAddrPtr addr) {
|
||||
* Returns the length of the network address or -1 in case of error.
|
||||
*/
|
||||
int
|
||||
virSocketParseIpv6Addr(const char *val, virSocketAddrPtr addr) {
|
||||
return(virSocketParseAddr(val, addr, AF_INET6));
|
||||
virSocketAddrParseIPv6(virSocketAddrPtr addr, const char *val) {
|
||||
return virSocketAddrParse(addr, val, AF_INET6);
|
||||
}
|
||||
|
||||
/*
|
||||
* virSocketFormatAddr:
|
||||
* virSocketAddrFormat:
|
||||
* @addr: an initialized virSocketAddrPtr
|
||||
*
|
||||
* Returns a string representation of the given address
|
||||
@ -150,13 +149,13 @@ virSocketParseIpv6Addr(const char *val, virSocketAddrPtr addr) {
|
||||
* Caller must free the returned string
|
||||
*/
|
||||
char *
|
||||
virSocketFormatAddr(virSocketAddrPtr addr) {
|
||||
return virSocketFormatAddrFull(addr, false, NULL);
|
||||
virSocketAddrFormat(virSocketAddrPtr addr) {
|
||||
return virSocketAddrFormatFull(addr, false, NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* virSocketFormatAddrFull:
|
||||
* virSocketAddrFormatFull:
|
||||
* @addr: an initialized virSocketAddrPtr
|
||||
* @withService: if true, then service info is appended
|
||||
* @separator: separator between hostname & service.
|
||||
@ -166,7 +165,7 @@ virSocketFormatAddr(virSocketAddrPtr addr) {
|
||||
* Caller must free the returned string
|
||||
*/
|
||||
char *
|
||||
virSocketFormatAddrFull(virSocketAddrPtr addr,
|
||||
virSocketAddrFormatFull(virSocketAddrPtr addr,
|
||||
bool withService,
|
||||
const char *separator)
|
||||
{
|
||||
@ -221,7 +220,7 @@ no_memory:
|
||||
|
||||
|
||||
/*
|
||||
* virSocketSetPort:
|
||||
* virSocketAddrSetPort:
|
||||
* @addr: an initialized virSocketAddrPtr
|
||||
* @port: the port number to set
|
||||
*
|
||||
@ -230,7 +229,7 @@ no_memory:
|
||||
* Returns 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
virSocketSetPort(virSocketAddrPtr addr, int port) {
|
||||
virSocketAddrSetPort(virSocketAddrPtr addr, int port) {
|
||||
if (addr == NULL)
|
||||
return -1;
|
||||
|
||||
@ -259,7 +258,7 @@ virSocketSetPort(virSocketAddrPtr addr, int port) {
|
||||
* Returns -1 if @addr is invalid
|
||||
*/
|
||||
int
|
||||
virSocketGetPort(virSocketAddrPtr addr) {
|
||||
virSocketAddrGetPort(virSocketAddrPtr addr) {
|
||||
if (addr == NULL)
|
||||
return -1;
|
||||
|
||||
@ -283,7 +282,7 @@ virSocketGetPort(virSocketAddrPtr addr) {
|
||||
* Returns 0 in case of success and -1 in case of error
|
||||
*/
|
||||
int virSocketAddrIsNetmask(virSocketAddrPtr netmask) {
|
||||
int n = virSocketGetNumNetmaskBits(netmask);
|
||||
int n = virSocketAddrGetNumNetmaskBits(netmask);
|
||||
if (n < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
@ -429,8 +428,8 @@ virSocketAddrBroadcastByPrefix(const virSocketAddrPtr addr,
|
||||
* Returns 1 in case of success and 0 in case of failure and
|
||||
* -1 in case of error
|
||||
*/
|
||||
int virSocketCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
|
||||
virSocketAddrPtr netmask) {
|
||||
int virSocketAddrCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
|
||||
virSocketAddrPtr netmask) {
|
||||
int i;
|
||||
|
||||
if ((addr1 == NULL) || (addr2 == NULL) || (netmask == NULL))
|
||||
@ -443,11 +442,11 @@ int virSocketCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
|
||||
return(-1);
|
||||
|
||||
if (addr1->data.stor.ss_family == AF_INET) {
|
||||
virIPv4Addr t1, t2, tm;
|
||||
virSocketAddrIPv4 t1, t2, tm;
|
||||
|
||||
if ((getIPv4Addr(addr1, &t1) < 0) ||
|
||||
(getIPv4Addr(addr2, &t2) < 0) ||
|
||||
(getIPv4Addr(netmask, &tm) < 0))
|
||||
if ((virSocketAddrGetIPv4Addr(addr1, &t1) < 0) ||
|
||||
(virSocketAddrGetIPv4Addr(addr2, &t2) < 0) ||
|
||||
(virSocketAddrGetIPv4Addr(netmask, &tm) < 0))
|
||||
return(-1);
|
||||
|
||||
for (i = 0;i < 4;i++) {
|
||||
@ -456,11 +455,11 @@ int virSocketCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
|
||||
}
|
||||
|
||||
} else if (addr1->data.stor.ss_family == AF_INET6) {
|
||||
virIPv6Addr t1, t2, tm;
|
||||
virSocketAddrIPv6 t1, t2, tm;
|
||||
|
||||
if ((getIPv6Addr(addr1, &t1) < 0) ||
|
||||
(getIPv6Addr(addr2, &t2) < 0) ||
|
||||
(getIPv6Addr(netmask, &tm) < 0))
|
||||
if ((virSocketAddrGetIPv6Addr(addr1, &t1) < 0) ||
|
||||
(virSocketAddrGetIPv6Addr(addr2, &t2) < 0) ||
|
||||
(virSocketAddrGetIPv6Addr(netmask, &tm) < 0))
|
||||
return(-1);
|
||||
|
||||
for (i = 0;i < 8;i++) {
|
||||
@ -486,7 +485,7 @@ int virSocketCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
|
||||
*
|
||||
* Returns the size of the range or -1 in case of failure
|
||||
*/
|
||||
int virSocketGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
|
||||
int virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
|
||||
int ret = 0, i;
|
||||
|
||||
if ((start == NULL) || (end == NULL))
|
||||
@ -495,10 +494,10 @@ int virSocketGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
|
||||
return(-1);
|
||||
|
||||
if (start->data.stor.ss_family == AF_INET) {
|
||||
virIPv4Addr t1, t2;
|
||||
virSocketAddrIPv4 t1, t2;
|
||||
|
||||
if ((getIPv4Addr(start, &t1) < 0) ||
|
||||
(getIPv4Addr(end, &t2) < 0))
|
||||
if ((virSocketAddrGetIPv4Addr(start, &t1) < 0) ||
|
||||
(virSocketAddrGetIPv4Addr(end, &t2) < 0))
|
||||
return(-1);
|
||||
|
||||
for (i = 0;i < 2;i++) {
|
||||
@ -510,10 +509,10 @@ int virSocketGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
|
||||
return(-1);
|
||||
ret++;
|
||||
} else if (start->data.stor.ss_family == AF_INET6) {
|
||||
virIPv6Addr t1, t2;
|
||||
virSocketAddrIPv6 t1, t2;
|
||||
|
||||
if ((getIPv6Addr(start, &t1) < 0) ||
|
||||
(getIPv6Addr(end, &t2) < 0))
|
||||
if ((virSocketAddrGetIPv6Addr(start, &t1) < 0) ||
|
||||
(virSocketAddrGetIPv6Addr(end, &t2) < 0))
|
||||
return(-1);
|
||||
|
||||
for (i = 0;i < 7;i++) {
|
||||
@ -532,7 +531,7 @@ int virSocketGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
|
||||
|
||||
|
||||
/**
|
||||
* virGetNumNetmaskBits
|
||||
* virSocketAddrGetNumNetmaskBits
|
||||
* @netmask: the presumed netmask
|
||||
*
|
||||
* Get the number of netmask bits in a netmask.
|
||||
@ -540,16 +539,16 @@ int virSocketGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
|
||||
* Returns the number of bits in the netmask or -1 if an error occurred
|
||||
* or the netmask is invalid.
|
||||
*/
|
||||
int virSocketGetNumNetmaskBits(const virSocketAddrPtr netmask)
|
||||
int virSocketAddrGetNumNetmaskBits(const virSocketAddrPtr netmask)
|
||||
{
|
||||
int i, j;
|
||||
int c = 0;
|
||||
|
||||
if (netmask->data.stor.ss_family == AF_INET) {
|
||||
virIPv4Addr tm;
|
||||
virSocketAddrIPv4 tm;
|
||||
uint8_t bit;
|
||||
|
||||
if (getIPv4Addr(netmask, &tm) < 0)
|
||||
if (virSocketAddrGetIPv4Addr(netmask, &tm) < 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
@ -580,10 +579,10 @@ int virSocketGetNumNetmaskBits(const virSocketAddrPtr netmask)
|
||||
|
||||
return c;
|
||||
} else if (netmask->data.stor.ss_family == AF_INET6) {
|
||||
virIPv6Addr tm;
|
||||
virSocketAddrIPv6 tm;
|
||||
uint16_t bit;
|
||||
|
||||
if (getIPv6Addr(netmask, &tm) < 0)
|
||||
if (virSocketAddrGetIPv6Addr(netmask, &tm) < 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
|
@ -37,13 +37,13 @@ typedef struct {
|
||||
socklen_t len;
|
||||
} virSocketAddr;
|
||||
|
||||
# define VIR_SOCKET_HAS_ADDR(s) \
|
||||
# define VIR_SOCKET_ADDR_VALID(s) \
|
||||
((s)->data.sa.sa_family != AF_UNSPEC)
|
||||
|
||||
# define VIR_SOCKET_IS_FAMILY(s, f) \
|
||||
# define VIR_SOCKET_ADDR_IS_FAMILY(s, f) \
|
||||
((s)->data.sa.sa_family == f)
|
||||
|
||||
# define VIR_SOCKET_FAMILY(s) \
|
||||
# define VIR_SOCKET_ADDR_FAMILY(s) \
|
||||
((s)->data.sa.sa_family)
|
||||
|
||||
typedef virSocketAddr *virSocketAddrPtr;
|
||||
@ -62,36 +62,36 @@ typedef struct {
|
||||
|
||||
typedef virBandwidth *virBandwidthPtr;
|
||||
|
||||
int virSocketParseAddr (const char *val,
|
||||
virSocketAddrPtr addr,
|
||||
int hint);
|
||||
int virSocketAddrParse(virSocketAddrPtr addr,
|
||||
const char *val,
|
||||
int family);
|
||||
|
||||
int virSocketParseIpv4Addr(const char *val,
|
||||
virSocketAddrPtr addr);
|
||||
int virSocketAddrParseIPv4(virSocketAddrPtr addr,
|
||||
const char *val);
|
||||
|
||||
int virSocketParseIpv6Addr(const char *val,
|
||||
virSocketAddrPtr addr);
|
||||
int virSocketAddrParseIPv6(virSocketAddrPtr addr,
|
||||
const char *val);
|
||||
|
||||
char * virSocketFormatAddr(virSocketAddrPtr addr);
|
||||
char * virSocketFormatAddrFull(virSocketAddrPtr addr,
|
||||
char * virSocketAddrFormat(virSocketAddrPtr addr);
|
||||
char * virSocketAddrFormatFull(virSocketAddrPtr addr,
|
||||
bool withService,
|
||||
const char *separator);
|
||||
|
||||
int virSocketSetPort(virSocketAddrPtr addr, int port);
|
||||
int virSocketAddrSetPort(virSocketAddrPtr addr, int port);
|
||||
|
||||
int virSocketGetPort(virSocketAddrPtr addr);
|
||||
int virSocketAddrGetPort(virSocketAddrPtr addr);
|
||||
|
||||
int virSocketGetRange (virSocketAddrPtr start,
|
||||
virSocketAddrPtr end);
|
||||
int virSocketAddrGetRange(virSocketAddrPtr start,
|
||||
virSocketAddrPtr end);
|
||||
|
||||
int virSocketAddrIsNetmask(virSocketAddrPtr netmask);
|
||||
|
||||
int virSocketCheckNetmask (virSocketAddrPtr addr1,
|
||||
virSocketAddrPtr addr2,
|
||||
virSocketAddrPtr netmask);
|
||||
int virSocketAddrMask (const virSocketAddrPtr addr,
|
||||
const virSocketAddrPtr netmask,
|
||||
virSocketAddrPtr network);
|
||||
int virSocketAddrCheckNetmask(virSocketAddrPtr addr1,
|
||||
virSocketAddrPtr addr2,
|
||||
virSocketAddrPtr netmask);
|
||||
int virSocketAddrMask(const virSocketAddrPtr addr,
|
||||
const virSocketAddrPtr netmask,
|
||||
virSocketAddrPtr network);
|
||||
int virSocketAddrMaskByPrefix(const virSocketAddrPtr addr,
|
||||
unsigned int prefix,
|
||||
virSocketAddrPtr network);
|
||||
@ -102,7 +102,7 @@ int virSocketAddrBroadcastByPrefix(const virSocketAddrPtr addr,
|
||||
unsigned int prefix,
|
||||
virSocketAddrPtr broadcast);
|
||||
|
||||
int virSocketGetNumNetmaskBits(const virSocketAddrPtr netmask);
|
||||
int virSocketAddrGetNumNetmaskBits(const virSocketAddrPtr netmask);
|
||||
int virSocketAddrPrefixToNetmask(unsigned int prefix,
|
||||
virSocketAddrPtr netmask,
|
||||
int family);
|
||||
|
@ -461,12 +461,12 @@ int virNetDevSetIPv4Address(const char *ifname,
|
||||
virSocketAddr broadcast;
|
||||
int ret = -1;
|
||||
|
||||
if (!(addrstr = virSocketFormatAddr(addr)))
|
||||
if (!(addrstr = virSocketAddrFormat(addr)))
|
||||
goto cleanup;
|
||||
/* format up a broadcast address if this is IPv4 */
|
||||
if ((VIR_SOCKET_IS_FAMILY(addr, AF_INET)) &&
|
||||
if ((VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) &&
|
||||
((virSocketAddrBroadcastByPrefix(addr, prefix, &broadcast) < 0) ||
|
||||
!(bcaststr = virSocketFormatAddr(&broadcast)))) {
|
||||
!(bcaststr = virSocketAddrFormat(&broadcast)))) {
|
||||
goto cleanup;
|
||||
}
|
||||
cmd = virCommandNew(IP_PATH);
|
||||
@ -506,7 +506,7 @@ int virNetDevClearIPv4Address(const char *ifname,
|
||||
char *addrstr;
|
||||
int ret = -1;
|
||||
|
||||
if (!(addrstr = virSocketFormatAddr(addr)))
|
||||
if (!(addrstr = virSocketAddrFormat(addr)))
|
||||
goto cleanup;
|
||||
cmd = virCommandNew(IP_PATH);
|
||||
virCommandAddArgList(cmd, "addr", "del", NULL);
|
||||
|
@ -792,7 +792,7 @@ vboxSocketFormatAddrUtf16(vboxGlobalData *data, virSocketAddrPtr addr)
|
||||
char *utf8 = NULL;
|
||||
PRUnichar *utf16 = NULL;
|
||||
|
||||
utf8 = virSocketFormatAddr(addr);
|
||||
utf8 = virSocketAddrFormat(addr);
|
||||
|
||||
if (utf8 == NULL) {
|
||||
return NULL;
|
||||
@ -813,7 +813,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
|
||||
|
||||
VBOX_UTF16_TO_UTF8(utf16, &utf8);
|
||||
|
||||
if (virSocketParseAddr(utf8, addr, AF_UNSPEC) < 0) {
|
||||
if (virSocketAddrParse(addr, utf8, AF_UNSPEC) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -7679,8 +7679,8 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char *
|
||||
* with contigious address space from start to end
|
||||
*/
|
||||
if ((ipdef->nranges >= 1) &&
|
||||
VIR_SOCKET_HAS_ADDR(&ipdef->ranges[0].start) &&
|
||||
VIR_SOCKET_HAS_ADDR(&ipdef->ranges[0].end)) {
|
||||
VIR_SOCKET_ADDR_VALID(&ipdef->ranges[0].start) &&
|
||||
VIR_SOCKET_ADDR_VALID(&ipdef->ranges[0].end)) {
|
||||
IDHCPServer *dhcpServer = NULL;
|
||||
|
||||
data->vboxObj->vtbl->FindDHCPServerByNetworkName(data->vboxObj,
|
||||
@ -7741,7 +7741,7 @@ static virNetworkPtr vboxNetworkDefineCreateXML(virConnectPtr conn, const char *
|
||||
}
|
||||
|
||||
if ((ipdef->nhosts >= 1) &&
|
||||
VIR_SOCKET_HAS_ADDR(&ipdef->hosts[0].ip)) {
|
||||
VIR_SOCKET_ADDR_VALID(&ipdef->hosts[0].ip)) {
|
||||
PRUnichar *ipAddressUtf16 = NULL;
|
||||
PRUnichar *networkMaskUtf16 = NULL;
|
||||
|
||||
|
@ -40,7 +40,7 @@ static int testParse(virSocketAddr *addr, const char *addrstr, int family, bool
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = virSocketParseAddr(addrstr, addr, family);
|
||||
rc = virSocketAddrParse(addr, addrstr, family);
|
||||
|
||||
if (rc < 0)
|
||||
return pass ? -1 : 0;
|
||||
@ -52,7 +52,7 @@ static int testFormat(virSocketAddr *addr, const char *addrstr, bool pass)
|
||||
{
|
||||
char *newaddrstr;
|
||||
|
||||
newaddrstr = virSocketFormatAddr(addr);
|
||||
newaddrstr = virSocketAddrFormat(addr);
|
||||
if (!newaddrstr)
|
||||
return pass ? -1 : 0;
|
||||
|
||||
@ -95,12 +95,12 @@ static int testRange(const char *saddrstr, const char *eaddrstr, int size, bool
|
||||
virSocketAddr saddr;
|
||||
virSocketAddr eaddr;
|
||||
|
||||
if (virSocketParseAddr(saddrstr, &saddr, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(&saddr, saddrstr, AF_UNSPEC) < 0)
|
||||
return -1;
|
||||
if (virSocketParseAddr(eaddrstr, &eaddr, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(&eaddr, eaddrstr, AF_UNSPEC) < 0)
|
||||
return -1;
|
||||
|
||||
int gotsize = virSocketGetRange(&saddr, &eaddr);
|
||||
int gotsize = virSocketAddrGetRange(&saddr, &eaddr);
|
||||
VIR_DEBUG("Size want %d vs got %d", size, gotsize);
|
||||
if (gotsize < 0 || gotsize != size) {
|
||||
return pass ? -1 : 0;
|
||||
@ -129,14 +129,14 @@ static int testNetmask(const char *addr1str, const char *addr2str,
|
||||
virSocketAddr addr2;
|
||||
virSocketAddr netmask;
|
||||
|
||||
if (virSocketParseAddr(addr1str, &addr1, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(&addr1, addr1str, AF_UNSPEC) < 0)
|
||||
return -1;
|
||||
if (virSocketParseAddr(addr2str, &addr2, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(&addr2, addr2str, AF_UNSPEC) < 0)
|
||||
return -1;
|
||||
if (virSocketParseAddr(netmaskstr, &netmask, AF_UNSPEC) < 0)
|
||||
if (virSocketAddrParse(&netmask, netmaskstr, AF_UNSPEC) < 0)
|
||||
return -1;
|
||||
|
||||
int ret = virSocketCheckNetmask(&addr1, &addr2, &netmask);
|
||||
int ret = virSocketAddrCheckNetmask(&addr1, &addr2, &netmask);
|
||||
|
||||
if (ret <= 0) {
|
||||
return pass ? -1 : 0;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
# include <ifaddrs.h>
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
|
||||
#include "testutils.h"
|
||||
#include "util.h"
|
||||
|
@ -231,7 +231,7 @@ testTLSGenerateCert(struct testTLSCertReq *req)
|
||||
virSocketAddr addr;
|
||||
char *data;
|
||||
int len;
|
||||
if (virSocketParseAddr(req->ipaddr1, &addr, 0) < 0) {
|
||||
if (virSocketAddrParse(&addr, req->ipaddr1, 0) < 0) {
|
||||
VIR_WARN("Cannot parse %s", req->ipaddr1);
|
||||
abort();
|
||||
}
|
||||
@ -254,7 +254,7 @@ testTLSGenerateCert(struct testTLSCertReq *req)
|
||||
virSocketAddr addr;
|
||||
char *data;
|
||||
int len;
|
||||
if (virSocketParseAddr(req->ipaddr2, &addr, 0) < 0) {
|
||||
if (virSocketAddrParse(&addr, req->ipaddr2, 0) < 0) {
|
||||
VIR_WARN("Cannot parse %s", req->ipaddr2);
|
||||
abort();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user