virClassPtr virNetworkClass;
virClassPtr virNodeDeviceClass;
virClassPtr virNWFilterClass;
+virClassPtr virNWFilterBindingClass;
virClassPtr virSecretClass;
virClassPtr virStreamClass;
virClassPtr virStorageVolClass;
static void virNetworkDispose(void *obj);
static void virNodeDeviceDispose(void *obj);
static void virNWFilterDispose(void *obj);
+static void virNWFilterBindingDispose(void *obj);
static void virSecretDispose(void *obj);
static void virStreamDispose(void *obj);
static void virStorageVolDispose(void *obj);
DECLARE_CLASS(virNetwork);
DECLARE_CLASS(virNodeDevice);
DECLARE_CLASS(virNWFilter);
+ DECLARE_CLASS(virNWFilterBinding);
DECLARE_CLASS(virSecret);
DECLARE_CLASS(virStream);
DECLARE_CLASS(virStorageVol);
}
+/**
+ * virGetNWFilterBinding:
+ * @conn: the hypervisor connection
+ * @portdev: pointer to the network filter port device name
+ * @filtername: name of the network filter
+ *
+ * Allocates a new network filter binding object. When the object is no longer
+ * needed, virObjectUnref() must be called in order to not leak data.
+ *
+ * Returns a pointer to the network filter binding object, or NULL on error.
+ */
+virNWFilterBindingPtr
+virGetNWFilterBinding(virConnectPtr conn, const char *portdev,
+ const char *filtername)
+{
+ virNWFilterBindingPtr ret = NULL;
+
+ if (virDataTypesInitialize() < 0)
+ return NULL;
+
+ virCheckConnectGoto(conn, error);
+ virCheckNonNullArgGoto(portdev, error);
+
+ if (!(ret = virObjectNew(virNWFilterBindingClass)))
+ goto error;
+
+ if (VIR_STRDUP(ret->portdev, portdev) < 0)
+ goto error;
+
+ if (VIR_STRDUP(ret->filtername, filtername) < 0)
+ goto error;
+
+ ret->conn = virObjectRef(conn);
+
+ return ret;
+
+ error:
+ virObjectUnref(ret);
+ return NULL;
+}
+
+
+/**
+ * virNWFilterBindingDispose:
+ * @obj: the network filter binding to release
+ *
+ * Unconditionally release all memory associated with a nwfilter binding.
+ * The nwfilter binding object must not be used once this method returns.
+ *
+ * It will also unreference the associated connection object,
+ * which may also be released if its ref count hits zero.
+ */
+static void
+virNWFilterBindingDispose(void *obj)
+{
+ virNWFilterBindingPtr binding = obj;
+
+ VIR_DEBUG("release binding %p %s", binding, binding->portdev);
+
+ VIR_FREE(binding->portdev);
+ virObjectUnref(binding->conn);
+}
+
+
/**
* virGetDomainSnapshot:
* @domain: the domain to snapshot
extern virClassPtr virNetworkClass;
extern virClassPtr virNodeDeviceClass;
extern virClassPtr virNWFilterClass;
+extern virClassPtr virNWFilterBindingClass;
extern virClassPtr virSecretClass;
extern virClassPtr virStreamClass;
extern virClassPtr virStorageVolClass;
} \
} while (0)
+# define virCheckNWFilterBindingReturn(obj, retval) \
+ do { \
+ virNWFilterBindingPtr _nw = (obj); \
+ if (!virObjectIsClass(_nw, virNWFilterBindingClass) || \
+ !virObjectIsClass(_nw->conn, virConnectClass)) { \
+ virReportErrorHelper(VIR_FROM_NWFILTER, \
+ VIR_ERR_INVALID_NWFILTER_BINDING, \
+ __FILE__, __FUNCTION__, __LINE__, \
+ __FUNCTION__); \
+ virDispatchError(NULL); \
+ return retval; \
+ } \
+ } while (0)
+
# define virCheckDomainSnapshotReturn(obj, retval) \
do { \
virDomainSnapshotPtr _snap = (obj); \
};
+/**
+* _virNWFilterBinding:
+*
+* Internal structure associated to a network filter port binding
+*/
+struct _virNWFilterBinding {
+ virObject parent;
+ virConnectPtr conn; /* pointer back to the connection */
+ char *portdev; /* the network filter port device name */
+ char *filtername; /* the network filter name */
+};
+
+
/*
* Helper APIs for allocating new object instances
*/
virNWFilterPtr virGetNWFilter(virConnectPtr conn,
const char *name,
const unsigned char *uuid);
+virNWFilterBindingPtr virGetNWFilterBinding(virConnectPtr conn,
+ const char *portdev,
+ const char *filtername);
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
const char *name);
virObjectRef(nwfilter);
return 0;
}
+
+
+/**
+ * virConnectListAllNWFilterBindings:
+ * @conn: Pointer to the hypervisor connection.
+ * @bindings: Pointer to a variable to store the array containing the network
+ * filter objects or NULL if the list is not required (just returns
+ * number of network filters).
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect the list of network filters, and allocate an array to store those
+ * objects.
+ *
+ * Returns the number of network filters found or -1 and sets @filters to NULL
+ * in case of error. On success, the array stored into @filters is guaranteed to
+ * have an extra allocated element set to NULL but not included in the return count,
+ * to make iteration easier. The caller is responsible for calling
+ * virNWFilterFree() on each array element, then calling free() on @filters.
+ */
+int
+virConnectListAllNWFilterBindings(virConnectPtr conn,
+ virNWFilterBindingPtr **bindings,
+ unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, bindings=%p, flags=0x%x", conn, bindings, flags);
+
+ virResetLastError();
+
+ if (bindings)
+ *bindings = NULL;
+
+ virCheckConnectReturn(conn, -1);
+
+ if (conn->nwfilterDriver &&
+ conn->nwfilterDriver->connectListAllNWFilterBindings) {
+ int ret;
+ ret = conn->nwfilterDriver->connectListAllNWFilterBindings(conn, bindings, flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(conn);
+ return -1;
+}
+
+
+/**
+ * virNWFilterBindingLookupByPortDev:
+ * @conn: pointer to the hypervisor connection
+ * @portdev: name for the network port device
+ *
+ * Try to lookup a network filter binding on the given hypervisor based
+ * on network port device name.
+ *
+ * virNWFilterBindingFree should be used to free the resources after the
+ * binding object is no longer needed.
+ *
+ * Returns a new binding object or NULL in case of failure. If the
+ * network filter cannot be found, then VIR_ERR_NO_NWFILTER_BINDING
+ * error is raised.
+ */
+virNWFilterBindingPtr
+virNWFilterBindingLookupByPortDev(virConnectPtr conn, const char *portdev)
+{
+ VIR_DEBUG("conn=%p, name=%s", conn, NULLSTR(portdev));
+
+ virResetLastError();
+
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgGoto(portdev, error);
+
+ if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterBindingLookupByPortDev) {
+ virNWFilterBindingPtr ret;
+ ret = conn->nwfilterDriver->nwfilterBindingLookupByPortDev(conn, portdev);
+ if (!ret)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(conn);
+ return NULL;
+}
+
+
+/**
+ * virNWFilterBindingFree:
+ * @binding: a binding object
+ *
+ * Free the binding object. The running instance is kept alive.
+ * The data structure is freed and should not be used thereafter.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virNWFilterBindingFree(virNWFilterBindingPtr binding)
+{
+ VIR_DEBUG("binding=%p", binding);
+
+ virResetLastError();
+
+ virCheckNWFilterBindingReturn(binding, -1);
+
+ virObjectUnref(binding);
+ return 0;
+}
+
+
+/**
+ * virNWFilterBindingGetPortDev:
+ * @binding: a binding object
+ *
+ * Get the port dev name for the network filter binding
+ *
+ * Returns a pointer to the name or NULL, the string need not be deallocated
+ * its lifetime will be the same as the binding object.
+ */
+const char *
+virNWFilterBindingGetPortDev(virNWFilterBindingPtr binding)
+{
+ VIR_DEBUG("binding=%p", binding);
+
+ virResetLastError();
+
+ virCheckNWFilterBindingReturn(binding, NULL);
+
+ return binding->portdev;
+}
+
+
+/**
+ * virNWFilterBindingGetFilterName:
+ * @binding: a binding object
+ *
+ * Get the filter name for the network filter binding
+ *
+ * Returns a pointer to the name or NULL, the string need not be deallocated
+ * its lifetime will be the same as the binding object.
+ */
+const char *
+virNWFilterBindingGetFilterName(virNWFilterBindingPtr binding)
+{
+ VIR_DEBUG("binding=%p", binding);
+
+ virResetLastError();
+
+ virCheckNWFilterBindingReturn(binding, NULL);
+
+ return binding->filtername;
+}
+
+
+/**
+ * virNWFilterBindingCreateXML:
+ * @conn: pointer to the hypervisor connection
+ * @xml: an XML description of the binding
+ * @flags: currently unused, pass 0
+ *
+ * Define a new network filter, based on an XML description
+ * similar to the one returned by virNWFilterGetXMLDesc()
+ *
+ * virNWFilterFree should be used to free the resources after the
+ * binding object is no longer needed.
+ *
+ * Returns a new binding object or NULL in case of failure
+ */
+virNWFilterBindingPtr
+virNWFilterBindingCreateXML(virConnectPtr conn, const char *xml, unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, xml=%s", conn, NULLSTR(xml));
+
+ virResetLastError();
+
+ virCheckConnectReturn(conn, NULL);
+ virCheckNonNullArgGoto(xml, error);
+ virCheckReadOnlyGoto(conn->flags, error);
+
+ if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterBindingCreateXML) {
+ virNWFilterBindingPtr ret;
+ ret = conn->nwfilterDriver->nwfilterBindingCreateXML(conn, xml, flags);
+ if (!ret)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(conn);
+ return NULL;
+}
+
+
+/**
+ * virNWFilterBindingDelete:
+ * @binding: a binding object
+ *
+ * Delete the binding object. This does not free the
+ * associated virNWFilterBindingPtr object.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virNWFilterBindingDelete(virNWFilterBindingPtr binding)
+{
+ virConnectPtr conn;
+ VIR_DEBUG("binding=%p", binding);
+
+ virResetLastError();
+
+ virCheckNWFilterBindingReturn(binding, -1);
+ conn = binding->conn;
+
+ virCheckReadOnlyGoto(conn->flags, error);
+
+ if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterBindingDelete) {
+ int ret;
+ ret = conn->nwfilterDriver->nwfilterBindingDelete(binding);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(binding->conn);
+ return -1;
+}
+
+
+/**
+ * virNWFilterBindingGetXMLDesc:
+ * @binding: a binding object
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Provide an XML description of the network filter. The description may be
+ * reused later to redefine the network filter with virNWFilterCreateXML().
+ *
+ * Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
+ * the caller must free() the returned value.
+ */
+char *
+virNWFilterBindingGetXMLDesc(virNWFilterBindingPtr binding, unsigned int flags)
+{
+ virConnectPtr conn;
+ VIR_DEBUG("binding=%p, flags=0x%x", binding, flags);
+
+ virResetLastError();
+
+ virCheckNWFilterBindingReturn(binding, NULL);
+ conn = binding->conn;
+
+ if (conn->nwfilterDriver && conn->nwfilterDriver->nwfilterBindingGetXMLDesc) {
+ char *ret;
+ ret = conn->nwfilterDriver->nwfilterBindingGetXMLDesc(binding, flags);
+ if (!ret)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(binding->conn);
+ return NULL;
+}
+
+
+/**
+ * virNWFilterBindingRef:
+ * @binding: the binding to hold a reference on
+ *
+ * Increment the reference count on the binding. For each
+ * additional call to this method, there shall be a corresponding
+ * call to virNWFilterFree to release the reference count, once
+ * the caller no longer needs the reference to this object.
+ *
+ * This method is typically useful for applications where multiple
+ * threads are using a connection, and it is required that the
+ * connection remain open until all threads have finished using
+ * it. ie, each new thread using an binding would increment
+ * the reference count.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virNWFilterBindingRef(virNWFilterBindingPtr binding)
+{
+ VIR_DEBUG("binding=%p refs=%d", binding,
+ binding ? binding->parent.u.s.refs : 0);
+
+ virResetLastError();
+
+ virCheckNWFilterBindingReturn(binding, -1);
+
+ virObjectRef(binding);
+ return 0;
+}