---
src/Makefile.am | 3 +-
src/libvirt-network.c | 586 ++++++++++++++++++++++++++++++++++++++++++++++++
src/libvirt-network.h | 73 ++++++
src/libvirt-php.c | 610 +-------------------------------------------------
src/libvirt-php.h | 24 +-
5 files changed, 664 insertions(+), 632 deletions(-)
create mode 100644 src/libvirt-network.c
create mode 100644 src/libvirt-network.h
diff --git a/src/Makefile.am b/src/Makefile.am
index b8eae3a..4ae01db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,7 +25,8 @@ libvirt_php_la_SOURCES = \
libvirt-connection.c libvirt-connection.h \
libvirt-node.c libvirt-node.h \
libvirt-stream.c libvirt-stream.h \
- libvirt-domain.c libvirt-domain.h
+ libvirt-domain.c libvirt-domain.h \
+ libvirt-network.c libvirt-network.h
libvirt_php_la_CFLAGS = \
$(AM_CFLAGS) \
-DCOMPILE_DL_LIBVIRT=1
diff --git a/src/libvirt-network.c b/src/libvirt-network.c
new file mode 100644
index 0000000..4316ee2
--- /dev/null
+++ b/src/libvirt-network.c
@@ -0,0 +1,586 @@
+/*
+ * libvirt-network.c: The PHP bindings to libvirt network API
+ *
+ * See COPYING for the license of this software
+ */
+
+#include <libvirt/libvirt.h>
+
+#include "libvirt-network.h"
+
+DEBUG_INIT("network");
+
+void
+php_libvirt_network_dtor(virt_resource *rsrc TSRMLS_DC)
+{
+ php_libvirt_network *network = (php_libvirt_network *)rsrc->ptr;
+ int rv = 0;
+
+ if (network != NULL) {
+ if (network->network != NULL) {
+ if (!check_resource_allocation(network->conn->conn,
INT_RESOURCE_NETWORK, network->network TSRMLS_CC)) {
+ network->network = NULL;
+ efree(network);
+ return;
+ }
+ rv = virNetworkFree(network->network);
+ if (rv != 0) {
+ DPRINTF("%s: virNetworkFree(%p) returned %d (%s)\n",
__FUNCTION__, network->network, rv, LIBVIRT_G(last_error));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
+ } else {
+ DPRINTF("%s: virNetworkFree(%p) completed successfully\n",
__FUNCTION__, network->network);
+ resource_change_counter(INT_RESOURCE_NETWORK, NULL, network->network,
0 TSRMLS_CC);
+ }
+ network->network = NULL;
+ }
+ efree(network);
+ }
+}
+
+/*
+ * Function name: libvirt_network_define_xml
+ * Since version: 0.4.2
+ * Description: Function is used to define a new virtual network based on the XML
description
+ * Arguments: @res [resource]: libvirt connection resource
+ * @xml [string]: XML string definition of network to be defined
+ * Returns: libvirt network resource of newly defined network
+ */
+PHP_FUNCTION(libvirt_network_define_xml)
+{
+ php_libvirt_connection *conn = NULL;
+ php_libvirt_network *res_net = NULL;
+ virNetwork *net;
+ zval *zconn;
+ char *xml = NULL;
+ strsize_t xml_len;
+
+ GET_CONNECTION_FROM_ARGS("rs", &zconn, &xml, &xml_len);
+
+ if ((net = virNetworkDefineXML(conn->conn, xml)) == NULL) {
+ set_error_if_unset("Cannot define a new network" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ res_net = (php_libvirt_network *)emalloc(sizeof(php_libvirt_network));
+ res_net->network = net;
+ res_net->conn = conn;
+
+ DPRINTF("%s: returning %p\n", PHPFUNC, res_net->network);
+ resource_change_counter(INT_RESOURCE_NETWORK, conn->conn, res_net->network, 1
TSRMLS_CC);
+
+ VIRT_REGISTER_RESOURCE(res_net, le_libvirt_network);
+}
+
+/*
+ * Function name: libvirt_network_get_xml_desc
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the XML description for the network
+ * Arguments: @res [resource]: libvirt network resource
+ * @xpath [string]: optional xPath expression string to get just this
entry, can be NULL
+ * Returns: network XML string or result of xPath expression
+ */
+PHP_FUNCTION(libvirt_network_get_xml_desc)
+{
+ php_libvirt_network *network;
+ zval *znetwork;
+ char *xml = NULL;
+ char *xpath = NULL;
+ char *tmp;
+ strsize_t xpath_len;
+ int retval = -1;
+
+ GET_NETWORK_FROM_ARGS("r|s", &znetwork, &xpath, &xpath_len);
+ if (xpath_len < 1)
+ xpath = NULL;
+
+ xml = virNetworkGetXMLDesc(network->network, 0);
+
+ if (xml == NULL) {
+ set_error_if_unset("Cannot get network XML" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
+ if ((tmp == NULL) || (retval < 0)) {
+ VIRT_RETVAL_STRING(xml);
+ } else {
+ VIRT_RETVAL_STRING(tmp);
+ }
+
+ free(xml);
+ free(tmp);
+}
+
+/*
+ * Function name: libvirt_network_undefine
+ * Since version: 0.4.2
+ * Description: Function is used to undefine already defined network
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: TRUE for success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_network_undefine)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ if (virNetworkUndefine(network->network) != 0)
+ RETURN_FALSE;
+
+ RETURN_TRUE;
+}
+
+/*
+ * Function name: libvirt_network_get
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the network resource from name
+ * Arguments: @res [resource]: libvirt connection resource
+ * @name [string]: network name string
+ * Returns: libvirt network resource
+ */
+PHP_FUNCTION(libvirt_network_get)
+{
+ php_libvirt_connection *conn = NULL;
+ php_libvirt_network *res_net = NULL;
+ virNetwork *net;
+ zval *zconn;
+ char *name;
+ strsize_t name_len;
+
+ GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len);
+
+ if ((net = virNetworkLookupByName(conn->conn, name)) == NULL) {
+ set_error_if_unset("Cannot get find requested network" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ res_net = (php_libvirt_network *)emalloc(sizeof(php_libvirt_network));
+ res_net->network = net;
+ res_net->conn = conn;
+
+ DPRINTF("%s: returning %p\n", PHPFUNC, res_net->network);
+ resource_change_counter(INT_RESOURCE_NETWORK, conn->conn, res_net->network, 1
TSRMLS_CC);
+
+ VIRT_REGISTER_RESOURCE(res_net, le_libvirt_network);
+}
+
+/*
+ * Function name: libvirt_network_get_bridge
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the bridge associated with the network
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: bridge name string
+ */
+PHP_FUNCTION(libvirt_network_get_bridge)
+{
+ php_libvirt_network *network;
+ zval *znetwork;
+ char *name;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ name = virNetworkGetBridgeName(network->network);
+
+ if (name == NULL) {
+ set_error_if_unset("Cannot get network bridge name" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ VIRT_RETVAL_STRING(name);
+ free(name);
+}
+
+/*
+ * Function name: libvirt_network_get_active
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the activity state of the network
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: 1 when active, 0 when inactive, FALSE on error
+ */
+PHP_FUNCTION(libvirt_network_get_active)
+{
+ php_libvirt_network *network;
+ zval *znetwork;
+ int res;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ res = virNetworkIsActive(network->network);
+
+ if (res == -1) {
+ set_error_if_unset("Error getting virtual network state" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ RETURN_LONG(res);
+}
+
+/*
+ * Function name: libvirt_network_set_active
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to set the activity state of the network
+ * Arguments: @res [resource]: libvirt network resource
+ * @flags [int]: active
+ * Returns: TRUE if success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_network_set_active)
+{
+ php_libvirt_network *network;
+ zval *znetwork;
+ zend_long act = 0;
+
+ DPRINTF("%s: Setting network activity...\n", PHPFUNC);
+
+ GET_NETWORK_FROM_ARGS("rl", &znetwork, &act);
+
+ if ((act != 0) && (act != 1)) {
+ set_error("Invalid network activity state" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ DPRINTF("%s: %sabling network...\n", PHPFUNC, (act == 1) ? "En" :
"Dis");
+
+ if (act == 1) {
+ if (virNetworkCreate(network->network) == 0) {
+ // Network is up and running
+ RETURN_TRUE;
+ } else {
+ // We don't have to set error since it's caught by libvirt error
handler itself
+ RETURN_FALSE;
+ }
+ }
+
+ if (virNetworkDestroy(network->network) == 0) {
+ // Network is down
+ RETURN_TRUE;
+ } else {
+ // Caught by libvirt error handler too
+ RETURN_FALSE;
+ }
+}
+
+/*
+ * Function name: libvirt_network_get_information
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to get the network information
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: network information array
+ */
+PHP_FUNCTION(libvirt_network_get_information)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ int retval = 0;
+ char *xml = NULL;
+ char *name = NULL;
+ char *ipaddr = NULL;
+ char *netmask = NULL;
+ char *mode = NULL;
+ char *dev = NULL;
+ char *dhcp_start = NULL;
+ char *dhcp_end = NULL;
+ char fixedtemp[32] = { 0 };
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ xml = virNetworkGetXMLDesc(network->network, 0);
+
+ if (xml == NULL) {
+ set_error_if_unset("Cannot get network XML" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+
+ /* Get name */
+ name = get_string_from_xpath(xml, "//network/name", NULL, &retval);
+ if (name == NULL) {
+ set_error("Invalid XPath node for network name" TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ if (retval < 0) {
+ set_error("Cannot get XPath expression result for network name"
TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ VIRT_ADD_ASSOC_STRING(return_value, "name", name);
+
+ /* Get gateway IP address */
+ ipaddr = get_string_from_xpath(xml, "//network/ip/@address", NULL,
&retval);
+ if (ipaddr && retval > 0)
+ VIRT_ADD_ASSOC_STRING(return_value, "ip", ipaddr);
+
+ /* Get netmask */
+ netmask = get_string_from_xpath(xml, "//network/ip/@netmask", NULL,
&retval);
+ if (netmask && retval > 0) {
+ int subnet_bits = get_subnet_bits(netmask);
+ VIRT_ADD_ASSOC_STRING(return_value, "netmask", netmask);
+ add_assoc_long(return_value, "netmask_bits", (long) subnet_bits);
+
+ /* Format CIDR address representation */
+ ipaddr[strlen(ipaddr) - 1] = ipaddr[strlen(ipaddr) - 1] - 1;
+ snprintf(fixedtemp, sizeof(fixedtemp), "%s/%d", ipaddr, subnet_bits);
+ VIRT_ADD_ASSOC_STRING(return_value, "ip_range", fixedtemp);
+ }
+
+ /* Get forwarding settings */
+ mode = get_string_from_xpath(xml, "//network/forward/@mode", NULL,
&retval);
+ if (mode && retval > 0)
+ VIRT_ADD_ASSOC_STRING(return_value, "forwarding", mode);
+
+ /* Get forwarding settings */
+ dev = get_string_from_xpath(xml, "//network/forward/@dev", NULL,
&retval);
+ if (dev && retval > 0)
+ VIRT_ADD_ASSOC_STRING(return_value, "forward_dev", dev);
+
+ /* Get DHCP values */
+ dhcp_start = get_string_from_xpath(xml, "//network/ip/dhcp/range/@start",
NULL, &retval);
+ dhcp_end = get_string_from_xpath(xml, "//network/ip/dhcp/range/@end", NULL,
&retval);
+ if (dhcp_start && dhcp_end && retval > 0) {
+ VIRT_ADD_ASSOC_STRING(return_value, "dhcp_start", dhcp_start);
+ VIRT_ADD_ASSOC_STRING(return_value, "dhcp_end", dhcp_end);
+ }
+
+ free(dhcp_end);
+ free(dhcp_start);
+ free(dev);
+ free(mode);
+ free(netmask);
+ free(ipaddr);
+ free(name);
+ free(xml);
+}
+
+/*
+ * Function name: libvirt_network_get_uuid_string
+ * Since version: 0.5.3
+ * Description: Function is used to get network's UUID in string format
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: network UUID string or FALSE on failure
+ */
+PHP_FUNCTION(libvirt_network_get_uuid_string)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ char *uuid = NULL;
+ int ret = -1;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ uuid = (char *) emalloc(VIR_UUID_STRING_BUFLEN);
+ ret = virNetworkGetUUIDString(network->network, uuid);
+
+ DPRINTF("%s: virNetworkGetUUIDString(%p) returned %d (%s)\n", PHPFUNC,
+ network->network, ret, uuid);
+
+ if (ret != 0)
+ RETURN_FALSE;
+
+ VIRT_RETURN_STRING(uuid);
+ efree(uuid);
+}
+
+/*
+ * Function name: libvirt_network_get_uuid
+ * Since version: 0.5.3
+ * Descirption: Function is used to get network's UUID in binary format
+ * Arguments: @res [resource]: libvirt netowrk resource
+ * Returns: network UUID in binary format or FALSE on failure
+ */
+PHP_FUNCTION(libvirt_network_get_uuid)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ char *uuid = NULL;
+ int ret = -1;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ uuid = (char *) emalloc(VIR_UUID_BUFLEN);
+ ret = virNetworkGetUUID(network->network, (unsigned char *)uuid);
+
+ DPRINTF("%s: virNetworkGetUUID(%p, %p) returned %d\n", PHPFUNC,
+ network->network, uuid, ret);
+
+ if (ret != 0)
+ RETURN_FALSE;
+
+ VIRT_RETVAL_STRING(uuid);
+ efree(uuid);
+}
+
+/*
+ * Function name: libvirt_network_get_name
+ * Since version: 0.5.3
+ * Description: Function is used to get network's name
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: network name string or FALSE on failure
+ */
+PHP_FUNCTION(libvirt_network_get_name)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ const char *name = NULL;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+ name = virNetworkGetName(network->network);
+
+ DPRINTF("%s: virNetworkGetName(%p) returned %s\n", PHPFUNC,
+ network->network, name);
+
+ if (name == NULL)
+ RETURN_FALSE;
+
+ /* name should not be freed as its lifetime is the same as network resource */
+ VIRT_RETURN_STRING(name);
+}
+
+/*
+ * Function name: libvirt_network_get_autostart
+ * Since version: 0.5.4
+ * Description: Function is getting the autostart value for the network
+ * Arguments: @res [resource]: libvirt network resource
+ * Returns: autostart value or -1 on error
+ */
+PHP_FUNCTION(libvirt_network_get_autostart)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ int autostart;
+
+ GET_NETWORK_FROM_ARGS("r", &znetwork);
+
+ if (virNetworkGetAutostart(network->network, &autostart) != 0)
+ RETURN_LONG(-1);
+
+ RETURN_LONG((long) autostart);
+}
+
+/*
+ * Function name: libvirt_network_set_autostart
+ * Since version: 0.5.4
+ * Description: Function is setting the autostart value for the network
+ * Arguments: @res [resource]: libvirt network resource
+ * @flags [int]: flag to enable/disable autostart
+ * Returns: TRUE on success, FALSE on error
+ */
+PHP_FUNCTION(libvirt_network_set_autostart)
+{
+ php_libvirt_network *network = NULL;
+ zval *znetwork;
+ zend_long autostart = 0;
+
+ GET_NETWORK_FROM_ARGS("rl", &znetwork, &autostart);
+
+ if (virNetworkSetAutostart(network->network, autostart) < 0)
+ RETURN_FALSE;
+
+ RETURN_TRUE;
+}
+
+/*
+ * Function name: libvirt_list_all_networks
+ * Since version: 0.5.3
+ * Description: Function is used to list networks on the connection
+ * Arguments: @res [resource]: libvirt connection resource
+ * @flags [int]: optional flags to filter the results for a smaller list
of targetted networks (bitwise-OR VIR_CONNECT_LIST_NETWORKS_* constants)
+ * Returns: libvirt network resources array for the connection
+ */
+PHP_FUNCTION(libvirt_list_all_networks)
+{
+ php_libvirt_connection *conn = NULL;
+ zval *zconn;
+ zend_long flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE |
+ VIR_CONNECT_LIST_NETWORKS_INACTIVE;
+ int count = -1;
+ size_t i = 0;
+ virNetworkPtr *nets = NULL;
+ virNetworkPtr network = NULL;
+ php_libvirt_network *res_network;
+
+ GET_CONNECTION_FROM_ARGS("r|l", &zconn, &flags);
+
+ if ((count = virConnectListAllNetworks(conn->conn, &nets, flags)) < 0)
+ RETURN_FALSE;
+
+ DPRINTF("%s: Found %d networks\n", PHPFUNC, count);
+
+ array_init(return_value);
+
+ for (i = 0; i < count; i++) {
+ network = nets[i];
+ res_network = (php_libvirt_network *) emalloc(sizeof(php_libvirt_network));
+ res_network->network = network;
+ res_network->conn = conn;
+
+ VIRT_REGISTER_LIST_RESOURCE(network);
+ resource_change_counter(INT_RESOURCE_NETWORK, conn->conn,
+ res_network->network, 1 TSRMLS_CC);
+ }
+}
+
+/*
+ * Function name: libvirt_list_networks
+ * Since version: 0.4.1(-1)
+ * Description: Function is used to list networks on the connection
+ * Arguments: @res [resource]: libvirt connection resource
+ * @flags [int]: flags whether to list active, inactive or all networks
(VIR_NETWORKS_{ACTIVE|INACTIVE|ALL} constants)
+ * Returns: libvirt network names array for the connection
+ */
+PHP_FUNCTION(libvirt_list_networks)
+{
+ php_libvirt_connection *conn = NULL;
+ zval *zconn;
+ zend_long flags = VIR_NETWORKS_ACTIVE | VIR_NETWORKS_INACTIVE;
+ int count = -1;
+ int expectedcount = -1;
+ char **names;
+ int i, done = 0;
+
+ GET_CONNECTION_FROM_ARGS("r|l", &zconn, &flags);
+
+ array_init(return_value);
+ if (flags & VIR_NETWORKS_ACTIVE) {
+ if ((expectedcount = virConnectNumOfNetworks(conn->conn)) < 0)
+ RETURN_FALSE;
+
+ names = (char **)emalloc(expectedcount*sizeof(char *));
+ count = virConnectListNetworks(conn->conn, names, expectedcount);
+ if ((count != expectedcount) || (count < 0)) {
+ efree(names);
+ RETURN_FALSE;
+ }
+
+ for (i = 0; i < count; i++) {
+ VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
+ free(names[i]);
+ }
+
+ efree(names);
+ done++;
+ }
+
+ if (flags & VIR_NETWORKS_INACTIVE) {
+ if ((expectedcount = virConnectNumOfDefinedNetworks(conn->conn)) < 0)
+ RETURN_FALSE;
+ names = (char **)emalloc(expectedcount*sizeof(char *));
+ count = virConnectListDefinedNetworks(conn->conn, names, expectedcount);
+ if ((count != expectedcount) || (count < 0)) {
+ efree(names);
+ RETURN_FALSE;
+ }
+
+ for (i = 0; i < count; i++) {
+ VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
+ free(names[i]);
+ }
+
+ efree(names);
+ done++;
+ }
+
+ if (!done)
+ RETURN_FALSE;
+}
diff --git a/src/libvirt-network.h b/src/libvirt-network.h
new file mode 100644
index 0000000..604b803
--- /dev/null
+++ b/src/libvirt-network.h
@@ -0,0 +1,73 @@
+/*
+ * libvirt-network.h: The PHP bindings to libvirt network API
+ *
+ * See COPYING for the license of this software
+ */
+
+#ifndef __LIBVIRT_NETWORK_H__
+# define __LIBVIRT_NETWORK_H__
+
+# include "libvirt-connection.h"
+
+# define PHP_LIBVIRT_NETWORK_RES_NAME "Libvirt virtual network"
+# define INT_RESOURCE_NETWORK 0x04
+
+# define GET_NETWORK_FROM_ARGS(args, ...) \
+ do { \
+ reset_error(TSRMLS_C); \
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \
+ args, \
+ __VA_ARGS__) == FAILURE) { \
+ set_error("Invalid arguments" TSRMLS_CC);
\
+ RETURN_FALSE; \
+ } \
+ \
+ VIRT_FETCH_RESOURCE(network, php_libvirt_network*, &znetwork, \
+ PHP_LIBVIRT_NETWORK_RES_NAME, le_libvirt_network); \
+ if (network == NULL || network->network == NULL) \
+ RETURN_FALSE; \
+ } while (0) \
+
+# define PHP_FE_LIBVIRT_NETWORK \
+ PHP_FE(libvirt_network_define_xml, arginfo_libvirt_conn_xml) \
+ PHP_FE(libvirt_network_get_xml_desc, arginfo_libvirt_conn_xpath) \
+ PHP_FE(libvirt_network_undefine, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_get, arginfo_libvirt_conn_name) \
+ PHP_FE(libvirt_network_get_active, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_set_active, arginfo_libvirt_conn_flags) \
+ PHP_FE(libvirt_network_get_bridge, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_get_information, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_get_uuid_string, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_get_uuid, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_get_name, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_get_autostart, arginfo_libvirt_conn) \
+ PHP_FE(libvirt_network_set_autostart, arginfo_libvirt_conn_flags) \
+ PHP_FE(libvirt_list_all_networks, arginfo_libvirt_conn_optflags) \
+ PHP_FE(libvirt_list_networks, arginfo_libvirt_conn_optflags)
+
+int le_libvirt_network;
+
+typedef struct _php_libvirt_network {
+ virNetworkPtr network;
+ php_libvirt_connection* conn;
+} php_libvirt_network;
+
+void php_libvirt_network_dtor(virt_resource *rsrc TSRMLS_DC);
+
+PHP_FUNCTION(libvirt_network_define_xml);
+PHP_FUNCTION(libvirt_network_get_xml_desc);
+PHP_FUNCTION(libvirt_network_undefine);
+PHP_FUNCTION(libvirt_network_get);
+PHP_FUNCTION(libvirt_network_get_active);
+PHP_FUNCTION(libvirt_network_set_active);
+PHP_FUNCTION(libvirt_network_get_bridge);
+PHP_FUNCTION(libvirt_network_get_information);
+PHP_FUNCTION(libvirt_network_get_uuid_string);
+PHP_FUNCTION(libvirt_network_get_uuid);
+PHP_FUNCTION(libvirt_network_get_name);
+PHP_FUNCTION(libvirt_network_get_autostart);
+PHP_FUNCTION(libvirt_network_set_autostart);
+PHP_FUNCTION(libvirt_list_all_networks);
+PHP_FUNCTION(libvirt_list_networks);
+
+#endif
diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 05f36ae..9e43a71 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -24,6 +24,7 @@
#include "libvirt-node.h"
#include "libvirt-stream.h"
#include "libvirt-domain.h"
+#include "libvirt-network.h"
DEBUG_INIT("core");
@@ -39,7 +40,6 @@ const char *features_binaries[] = { NULL };
/* ZEND thread safe per request globals definition */
int le_libvirt_storagepool;
int le_libvirt_volume;
-int le_libvirt_network;
int le_libvirt_nodedev;
int le_libvirt_snapshot;
int le_libvirt_nwfilter;
@@ -517,20 +517,7 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE(libvirt_storagepool_build, arginfo_libvirt_conn)
PHP_FE(libvirt_storagepool_delete, arginfo_libvirt_conn)
/* Network functions */
- PHP_FE(libvirt_network_define_xml, arginfo_libvirt_conn_xml)
- PHP_FE(libvirt_network_undefine, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_get, arginfo_libvirt_conn_name)
- PHP_FE(libvirt_network_get_xml_desc, arginfo_libvirt_conn_xpath)
- PHP_FE(libvirt_network_get_bridge, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_get_information, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_get_active, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_set_active, arginfo_libvirt_conn_flags)
- PHP_FE(libvirt_network_get_uuid_string, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_get_uuid, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_get_name, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_get_autostart, arginfo_libvirt_conn)
- PHP_FE(libvirt_network_set_autostart, arginfo_libvirt_conn_flags)
- /* Node functions */
+ PHP_FE_LIBVIRT_NETWORK
PHP_FE_LIBVIRT_NODE
/* Nodedev functions */
PHP_FE(libvirt_nodedev_get, arginfo_libvirt_conn)
@@ -550,8 +537,6 @@ static zend_function_entry libvirt_functions[] = {
/* List functions */
PHP_FE(libvirt_list_domain_snapshots, arginfo_libvirt_conn_optflags)
PHP_FE(libvirt_list_nodedevs, arginfo_libvirt_conn_optcap)
- PHP_FE(libvirt_list_all_networks, arginfo_libvirt_conn_optflags)
- PHP_FE(libvirt_list_networks, arginfo_libvirt_conn_optflags)
PHP_FE(libvirt_list_storagepools, arginfo_libvirt_conn)
PHP_FE(libvirt_list_active_storagepools, arginfo_libvirt_conn)
PHP_FE(libvirt_list_inactive_storagepools, arginfo_libvirt_conn)
@@ -571,7 +556,6 @@ static zend_function_entry libvirt_functions[] = {
PHP_FE_END
};
-
/* Zend module basic definition */
zend_module_entry libvirt_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
@@ -1293,33 +1277,6 @@ static void php_libvirt_volume_dtor(virt_resource *rsrc TSRMLS_DC)
}
}
-/* Destructor for network resource */
-static void php_libvirt_network_dtor(virt_resource *rsrc TSRMLS_DC)
-{
- php_libvirt_network *network = (php_libvirt_network *)rsrc->ptr;
- int rv = 0;
-
- if (network != NULL) {
- if (network->network != NULL) {
- if (!check_resource_allocation(network->conn->conn,
INT_RESOURCE_NETWORK, network->network TSRMLS_CC)) {
- network->network = NULL;
- efree(network);
- return;
- }
- rv = virNetworkFree(network->network);
- if (rv != 0) {
- DPRINTF("%s: virNetworkFree(%p) returned %d (%s)\n",
__FUNCTION__, network->network, rv, LIBVIRT_G(last_error));
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "virStorageVolFree
failed with %i on destructor: %s", rv, LIBVIRT_G(last_error));
- } else {
- DPRINTF("%s: virNetworkFree(%p) completed successfully\n",
__FUNCTION__, network->network);
- resource_change_counter(INT_RESOURCE_NETWORK, NULL, network->network,
0 TSRMLS_CC);
- }
- network->network = NULL;
- }
- efree(network);
- }
-}
-
/* Destructor for nodedev resource */
static void php_libvirt_nodedev_dtor(virt_resource *rsrc TSRMLS_DC)
{
@@ -1727,19 +1684,6 @@ PHP_MSHUTDOWN_FUNCTION(libvirt)
}
/* Macros for obtaining resources from arguments */
-#define GET_NETWORK_FROM_ARGS(args, ...)
\
- do {
\
- reset_error(TSRMLS_C);
\
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, args, __VA_ARGS__) ==
FAILURE) { \
- set_error("Invalid arguments" TSRMLS_CC);
\
- RETURN_FALSE;
\
- }
\
-
\
- VIRT_FETCH_RESOURCE(network, php_libvirt_network*, &znetwork,
PHP_LIBVIRT_NETWORK_RES_NAME, le_libvirt_network);\
- if ((network == NULL) || (network->network == NULL))
\
- RETURN_FALSE;
\
- } while (0)
\
-
#define GET_NODEDEV_FROM_ARGS(args, ...)
\
do {
\
reset_error(TSRMLS_C);
\
@@ -4054,111 +3998,6 @@ PHP_FUNCTION(libvirt_list_inactive_storagepools)
}
/*
- * Function name: libvirt_list_all_networks
- * Since version: 0.5.3
- * Description: Function is used to list networks on the connection
- * Arguments: @res [resource]: libvirt connection resource
- * @flags [int]: optional flags to filter the results for a smaller list
of targetted networks (bitwise-OR VIR_CONNECT_LIST_NETWORKS_* constants)
- * Returns: libvirt network resources array for the connection
- */
-PHP_FUNCTION(libvirt_list_all_networks)
-{
- php_libvirt_connection *conn = NULL;
- zval *zconn;
- zend_long flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE |
- VIR_CONNECT_LIST_NETWORKS_INACTIVE;
- int count = -1;
- size_t i = 0;
- virNetworkPtr *nets = NULL;
- virNetworkPtr network = NULL;
- php_libvirt_network *res_network;
-
- GET_CONNECTION_FROM_ARGS("r|l", &zconn, &flags);
-
- if ((count = virConnectListAllNetworks(conn->conn, &nets, flags)) < 0)
- RETURN_FALSE;
-
- DPRINTF("%s: Found %d networks\n", PHPFUNC, count);
-
- array_init(return_value);
-
- for (i = 0; i < count; i++) {
- network = nets[i];
- res_network = (php_libvirt_network *) emalloc(sizeof(php_libvirt_network));
- res_network->network = network;
- res_network->conn = conn;
-
- VIRT_REGISTER_LIST_RESOURCE(network);
- resource_change_counter(INT_RESOURCE_NETWORK, conn->conn,
- res_network->network, 1 TSRMLS_CC);
- }
-}
-
-/*
- * Function name: libvirt_list_networks
- * Since version: 0.4.1(-1)
- * Description: Function is used to list networks on the connection
- * Arguments: @res [resource]: libvirt connection resource
- * @flags [int]: flags whether to list active, inactive or all networks
(VIR_NETWORKS_{ACTIVE|INACTIVE|ALL} constants)
- * Returns: libvirt network names array for the connection
- */
-PHP_FUNCTION(libvirt_list_networks)
-{
- php_libvirt_connection *conn = NULL;
- zval *zconn;
- zend_long flags = VIR_NETWORKS_ACTIVE | VIR_NETWORKS_INACTIVE;
- int count = -1;
- int expectedcount = -1;
- char **names;
- int i, done = 0;
-
- GET_CONNECTION_FROM_ARGS("r|l", &zconn, &flags);
-
- array_init(return_value);
- if (flags & VIR_NETWORKS_ACTIVE) {
- if ((expectedcount = virConnectNumOfNetworks(conn->conn)) < 0)
- RETURN_FALSE;
-
- names = (char **)emalloc(expectedcount*sizeof(char *));
- count = virConnectListNetworks(conn->conn, names, expectedcount);
- if ((count != expectedcount) || (count < 0)) {
- efree(names);
- RETURN_FALSE;
- }
-
- for (i = 0; i < count; i++) {
- VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
- free(names[i]);
- }
-
- efree(names);
- done++;
- }
-
- if (flags & VIR_NETWORKS_INACTIVE) {
- if ((expectedcount = virConnectNumOfDefinedNetworks(conn->conn)) < 0)
- RETURN_FALSE;
- names = (char **)emalloc(expectedcount*sizeof(char *));
- count = virConnectListDefinedNetworks(conn->conn, names, expectedcount);
- if ((count != expectedcount) || (count < 0)) {
- efree(names);
- RETURN_FALSE;
- }
-
- for (i = 0; i < count; i++) {
- VIRT_ADD_NEXT_INDEX_STRING(return_value, names[i]);
- free(names[i]);
- }
-
- efree(names);
- done++;
- }
-
- if (!done)
- RETURN_FALSE;
-}
-
-/*
* Function name: libvirt_list_nodedevs
* Since version: 0.4.1(-1)
* Description: Function is used to list node devices on the connection
@@ -4546,451 +4385,6 @@ PHP_FUNCTION(libvirt_nodedev_get_information)
RETURN_FALSE;
}
-/* Network functions */
-
-/*
- * Function name: libvirt_network_define_xml
- * Since version: 0.4.2
- * Description: Function is used to define a new virtual network based on the XML
description
- * Arguments: @res [resource]: libvirt connection resource
- * @xml [string]: XML string definition of network to be defined
- * Returns: libvirt network resource of newly defined network
- */
-PHP_FUNCTION(libvirt_network_define_xml)
-{
- php_libvirt_connection *conn = NULL;
- php_libvirt_network *res_net = NULL;
- virNetwork *net;
- zval *zconn;
- char *xml = NULL;
- strsize_t xml_len;
-
- GET_CONNECTION_FROM_ARGS("rs", &zconn, &xml, &xml_len);
-
- if ((net = virNetworkDefineXML(conn->conn, xml)) == NULL) {
- set_error_if_unset("Cannot define a new network" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- res_net = (php_libvirt_network *)emalloc(sizeof(php_libvirt_network));
- res_net->network = net;
- res_net->conn = conn;
-
- DPRINTF("%s: returning %p\n", PHPFUNC, res_net->network);
- resource_change_counter(INT_RESOURCE_NETWORK, conn->conn, res_net->network, 1
TSRMLS_CC);
-
- VIRT_REGISTER_RESOURCE(res_net, le_libvirt_network);
-}
-
-/*
- * Function name: libvirt_network_undefine
- * Since version: 0.4.2
- * Description: Function is used to undefine already defined network
- * Arguments: @res [resource]: libvirt network resource
- * Returns: TRUE for success, FALSE on error
- */
-PHP_FUNCTION(libvirt_network_undefine)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- if (virNetworkUndefine(network->network) != 0)
- RETURN_FALSE;
-
- RETURN_TRUE;
-}
-
-/*
- * Function name: libvirt_network_get
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the network resource from name
- * Arguments: @res [resource]: libvirt connection resource
- * @name [string]: network name string
- * Returns: libvirt network resource
- */
-PHP_FUNCTION(libvirt_network_get)
-{
- php_libvirt_connection *conn = NULL;
- php_libvirt_network *res_net = NULL;
- virNetwork *net;
- zval *zconn;
- char *name;
- strsize_t name_len;
-
- GET_CONNECTION_FROM_ARGS("rs", &zconn, &name, &name_len);
-
- if ((net = virNetworkLookupByName(conn->conn, name)) == NULL) {
- set_error_if_unset("Cannot get find requested network" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- res_net = (php_libvirt_network *)emalloc(sizeof(php_libvirt_network));
- res_net->network = net;
- res_net->conn = conn;
-
- DPRINTF("%s: returning %p\n", PHPFUNC, res_net->network);
- resource_change_counter(INT_RESOURCE_NETWORK, conn->conn, res_net->network, 1
TSRMLS_CC);
-
- VIRT_REGISTER_RESOURCE(res_net, le_libvirt_network);
-}
-
-/*
- * Function name: libvirt_network_get_bridge
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the bridge associated with the network
- * Arguments: @res [resource]: libvirt network resource
- * Returns: bridge name string
- */
-PHP_FUNCTION(libvirt_network_get_bridge)
-{
- php_libvirt_network *network;
- zval *znetwork;
- char *name;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- name = virNetworkGetBridgeName(network->network);
-
- if (name == NULL) {
- set_error_if_unset("Cannot get network bridge name" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- VIRT_RETVAL_STRING(name);
- free(name);
-}
-
-/*
- * Function name: libvirt_network_get_active
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the activity state of the network
- * Arguments: @res [resource]: libvirt network resource
- * Returns: 1 when active, 0 when inactive, FALSE on error
- */
-PHP_FUNCTION(libvirt_network_get_active)
-{
- php_libvirt_network *network;
- zval *znetwork;
- int res;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- res = virNetworkIsActive(network->network);
-
- if (res == -1) {
- set_error_if_unset("Error getting virtual network state" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- RETURN_LONG(res);
-}
-
-/*
- * Function name: libvirt_network_get_information
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the network information
- * Arguments: @res [resource]: libvirt network resource
- * Returns: network information array
- */
-PHP_FUNCTION(libvirt_network_get_information)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
- int retval = 0;
- char *xml = NULL;
- char *name = NULL;
- char *ipaddr = NULL;
- char *netmask = NULL;
- char *mode = NULL;
- char *dev = NULL;
- char *dhcp_start = NULL;
- char *dhcp_end = NULL;
- char fixedtemp[32] = { 0 };
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- xml = virNetworkGetXMLDesc(network->network, 0);
-
- if (xml == NULL) {
- set_error_if_unset("Cannot get network XML" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- array_init(return_value);
-
- /* Get name */
- name = get_string_from_xpath(xml, "//network/name", NULL, &retval);
- if (name == NULL) {
- set_error("Invalid XPath node for network name" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- if (retval < 0) {
- set_error("Cannot get XPath expression result for network name"
TSRMLS_CC);
- RETURN_FALSE;
- }
-
- VIRT_ADD_ASSOC_STRING(return_value, "name", name);
-
- /* Get gateway IP address */
- ipaddr = get_string_from_xpath(xml, "//network/ip/@address", NULL,
&retval);
- if (ipaddr && retval > 0)
- VIRT_ADD_ASSOC_STRING(return_value, "ip", ipaddr);
-
- /* Get netmask */
- netmask = get_string_from_xpath(xml, "//network/ip/@netmask", NULL,
&retval);
- if (netmask && retval > 0) {
- int subnet_bits = get_subnet_bits(netmask);
- VIRT_ADD_ASSOC_STRING(return_value, "netmask", netmask);
- add_assoc_long(return_value, "netmask_bits", (long) subnet_bits);
-
- /* Format CIDR address representation */
- ipaddr[strlen(ipaddr) - 1] = ipaddr[strlen(ipaddr) - 1] - 1;
- snprintf(fixedtemp, sizeof(fixedtemp), "%s/%d", ipaddr, subnet_bits);
- VIRT_ADD_ASSOC_STRING(return_value, "ip_range", fixedtemp);
- }
-
- /* Get forwarding settings */
- mode = get_string_from_xpath(xml, "//network/forward/@mode", NULL,
&retval);
- if (mode && retval > 0)
- VIRT_ADD_ASSOC_STRING(return_value, "forwarding", mode);
-
- /* Get forwarding settings */
- dev = get_string_from_xpath(xml, "//network/forward/@dev", NULL,
&retval);
- if (dev && retval > 0)
- VIRT_ADD_ASSOC_STRING(return_value, "forward_dev", dev);
-
- /* Get DHCP values */
- dhcp_start = get_string_from_xpath(xml, "//network/ip/dhcp/range/@start",
NULL, &retval);
- dhcp_end = get_string_from_xpath(xml, "//network/ip/dhcp/range/@end", NULL,
&retval);
- if (dhcp_start && dhcp_end && retval > 0) {
- VIRT_ADD_ASSOC_STRING(return_value, "dhcp_start", dhcp_start);
- VIRT_ADD_ASSOC_STRING(return_value, "dhcp_end", dhcp_end);
- }
-
- free(dhcp_end);
- free(dhcp_start);
- free(dev);
- free(mode);
- free(netmask);
- free(ipaddr);
- free(name);
- free(xml);
-}
-
-/*
- * Function name: libvirt_network_set_active
- * Since version: 0.4.1(-1)
- * Description: Function is used to set the activity state of the network
- * Arguments: @res [resource]: libvirt network resource
- * @flags [int]: active
- * Returns: TRUE if success, FALSE on error
- */
-PHP_FUNCTION(libvirt_network_set_active)
-{
- php_libvirt_network *network;
- zval *znetwork;
- zend_long act = 0;
-
- DPRINTF("%s: Setting network activity...\n", PHPFUNC);
-
- GET_NETWORK_FROM_ARGS("rl", &znetwork, &act);
-
- if ((act != 0) && (act != 1)) {
- set_error("Invalid network activity state" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- DPRINTF("%s: %sabling network...\n", PHPFUNC, (act == 1) ? "En" :
"Dis");
-
- if (act == 1) {
- if (virNetworkCreate(network->network) == 0) {
- // Network is up and running
- RETURN_TRUE;
- } else {
- // We don't have to set error since it's caught by libvirt error
handler itself
- RETURN_FALSE;
- }
- }
-
- if (virNetworkDestroy(network->network) == 0) {
- // Network is down
- RETURN_TRUE;
- } else {
- // Caught by libvirt error handler too
- RETURN_FALSE;
- }
-}
-
-/*
- * Function name: libvirt_network_get_xml_desc
- * Since version: 0.4.1(-1)
- * Description: Function is used to get the XML description for the network
- * Arguments: @res [resource]: libvirt network resource
- * @xpath [string]: optional xPath expression string to get just this
entry, can be NULL
- * Returns: network XML string or result of xPath expression
- */
-PHP_FUNCTION(libvirt_network_get_xml_desc)
-{
- php_libvirt_network *network;
- zval *znetwork;
- char *xml = NULL;
- char *xpath = NULL;
- char *tmp;
- strsize_t xpath_len;
- int retval = -1;
-
- GET_NETWORK_FROM_ARGS("r|s", &znetwork, &xpath, &xpath_len);
- if (xpath_len < 1)
- xpath = NULL;
-
- xml = virNetworkGetXMLDesc(network->network, 0);
-
- if (xml == NULL) {
- set_error_if_unset("Cannot get network XML" TSRMLS_CC);
- RETURN_FALSE;
- }
-
- tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
- if ((tmp == NULL) || (retval < 0)) {
- VIRT_RETVAL_STRING(xml);
- } else {
- VIRT_RETVAL_STRING(tmp);
- }
-
- free(xml);
- free(tmp);
-}
-
-/*
- * Function name: libvirt_network_get_uuid_string
- * Since version: 0.5.3
- * Description: Function is used to get network's UUID in string format
- * Arguments: @res [resource]: libvirt network resource
- * Returns: network UUID string or FALSE on failure
- */
-PHP_FUNCTION(libvirt_network_get_uuid_string)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
- char *uuid = NULL;
- int ret = -1;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- uuid = (char *) emalloc(VIR_UUID_STRING_BUFLEN);
- ret = virNetworkGetUUIDString(network->network, uuid);
-
- DPRINTF("%s: virNetworkGetUUIDString(%p) returned %d (%s)\n", PHPFUNC,
- network->network, ret, uuid);
-
- if (ret != 0)
- RETURN_FALSE;
-
- VIRT_RETURN_STRING(uuid);
- efree(uuid);
-}
-
-/*
- * Function name: libvirt_network_get_uuid
- * Since version: 0.5.3
- * Descirption: Function is used to get network's UUID in binary format
- * Arguments: @res [resource]: libvirt netowrk resource
- * Returns: network UUID in binary format or FALSE on failure
- */
-PHP_FUNCTION(libvirt_network_get_uuid)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
- char *uuid = NULL;
- int ret = -1;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- uuid = (char *) emalloc(VIR_UUID_BUFLEN);
- ret = virNetworkGetUUID(network->network, (unsigned char *)uuid);
-
- DPRINTF("%s: virNetworkGetUUID(%p, %p) returned %d\n", PHPFUNC,
- network->network, uuid, ret);
-
- if (ret != 0)
- RETURN_FALSE;
-
- VIRT_RETVAL_STRING(uuid);
- efree(uuid);
-}
-
-/*
- * Function name: libvirt_network_get_name
- * Since version: 0.5.3
- * Description: Function is used to get network's name
- * Arguments: @res [resource]: libvirt network resource
- * Returns: network name string or FALSE on failure
- */
-PHP_FUNCTION(libvirt_network_get_name)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
- const char *name = NULL;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
- name = virNetworkGetName(network->network);
-
- DPRINTF("%s: virNetworkGetName(%p) returned %s\n", PHPFUNC,
- network->network, name);
-
- if (name == NULL)
- RETURN_FALSE;
-
- /* name should not be freed as its lifetime is the same as network resource */
- VIRT_RETURN_STRING(name);
-}
-
-/*
- * Function name: libvirt_network_get_autostart
- * Since version: 0.5.4
- * Description: Function is getting the autostart value for the network
- * Arguments: @res [resource]: libvirt network resource
- * Returns: autostart value or -1 on error
- */
-PHP_FUNCTION(libvirt_network_get_autostart)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
- int autostart;
-
- GET_NETWORK_FROM_ARGS("r", &znetwork);
-
- if (virNetworkGetAutostart(network->network, &autostart) != 0)
- RETURN_LONG(-1);
-
- RETURN_LONG((long) autostart);
-}
-
-/*
- * Function name: libvirt_network_set_autostart
- * Since version: 0.5.4
- * Description: Function is setting the autostart value for the network
- * Arguments: @res [resource]: libvirt network resource
- * @flags [int]: flag to enable/disable autostart
- * Returns: TRUE on success, FALSE on error
- */
-PHP_FUNCTION(libvirt_network_set_autostart)
-{
- php_libvirt_network *network = NULL;
- zval *znetwork;
- zend_long autostart = 0;
-
- GET_NETWORK_FROM_ARGS("rl", &znetwork, &autostart);
-
- if (virNetworkSetAutostart(network->network, autostart) < 0)
- RETURN_FALSE;
-
- RETURN_TRUE;
-}
-
/* NWFilter functions */
/*
diff --git a/src/libvirt-php.h b/src/libvirt-php.h
index a27ed82..7670582 100644
--- a/src/libvirt-php.h
+++ b/src/libvirt-php.h
@@ -128,7 +128,6 @@ typedef uint64_t arch_uint;
#define PHP_LIBVIRT_WORLD_EXTNAME "libvirt"
/* Internal resource identifier objects */
-#define INT_RESOURCE_NETWORK 0x04
#define INT_RESOURCE_NODEDEV 0x08
#define INT_RESOURCE_STORAGEPOOL 0x10
#define INT_RESOURCE_VOLUME 0x20
@@ -172,11 +171,6 @@ typedef struct _php_libvirt_snapshot {
php_libvirt_domain* domain;
} php_libvirt_snapshot;
-typedef struct _php_libvirt_network {
- virNetworkPtr network;
- php_libvirt_connection* conn;
-} php_libvirt_network;
-
typedef struct _php_libvirt_nodedev {
virNodeDevicePtr device;
php_libvirt_connection* conn;
@@ -247,10 +241,10 @@ int streamSink(virStreamPtr st ATTRIBUTE_UNUSED,
const char *bytes, size_t nbytes, void *opaque);
const char *get_feature_binary(const char *name);
long get_next_free_numeric_value(virDomainPtr domain, char *xpath);
+int get_subnet_bits(char *ip);
#define PHP_LIBVIRT_STORAGEPOOL_RES_NAME "Libvirt storagepool"
#define PHP_LIBVIRT_VOLUME_RES_NAME "Libvirt volume"
-#define PHP_LIBVIRT_NETWORK_RES_NAME "Libvirt virtual network"
#define PHP_LIBVIRT_NODEDEV_RES_NAME "Libvirt node device"
#define PHP_LIBVIRT_SNAPSHOT_RES_NAME "Libvirt domain snapshot"
#define PHP_LIBVIRT_NWFILTER_RES_NAME "Libvirt nwfilter"
@@ -302,20 +296,6 @@ PHP_FUNCTION(libvirt_storagepool_set_autostart);
PHP_FUNCTION(libvirt_storagepool_get_autostart);
PHP_FUNCTION(libvirt_storagepool_build);
PHP_FUNCTION(libvirt_storagepool_delete);
-/* Network functions */
-PHP_FUNCTION(libvirt_network_define_xml);
-PHP_FUNCTION(libvirt_network_undefine);
-PHP_FUNCTION(libvirt_network_get);
-PHP_FUNCTION(libvirt_network_get_xml_desc);
-PHP_FUNCTION(libvirt_network_get_bridge);
-PHP_FUNCTION(libvirt_network_get_information);
-PHP_FUNCTION(libvirt_network_get_active);
-PHP_FUNCTION(libvirt_network_set_active);
-PHP_FUNCTION(libvirt_network_get_uuid_string);
-PHP_FUNCTION(libvirt_network_get_uuid);
-PHP_FUNCTION(libvirt_network_get_name);
-PHP_FUNCTION(libvirt_network_get_autostart);
-PHP_FUNCTION(libvirt_network_set_autostart);
/* Nodedev functions */
PHP_FUNCTION(libvirt_nodedev_get);
PHP_FUNCTION(libvirt_nodedev_capabilities);
@@ -333,8 +313,6 @@ PHP_FUNCTION(libvirt_nwfilter_lookup_by_uuid_string);
PHP_FUNCTION(libvirt_nwfilter_lookup_by_uuid);
/* Listing functions */
PHP_FUNCTION(libvirt_list_nodedevs);
-PHP_FUNCTION(libvirt_list_all_networks);
-PHP_FUNCTION(libvirt_list_networks);
PHP_FUNCTION(libvirt_list_all_nwfilters);
PHP_FUNCTION(libvirt_list_nwfilters);
PHP_FUNCTION(libvirt_list_domain_snapshots);
--
2.13.3