|
Packit Service |
ea0369 |
/*
|
|
Packit Service |
ea0369 |
* libvirt-gconfig-domain-interface.c: libvirt domain interface configuration
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Copyright (C) 2008 Daniel P. Berrange
|
|
Packit Service |
ea0369 |
* Copyright (C) 2010-2011 Red Hat, Inc.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
ea0369 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
ea0369 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
ea0369 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
ea0369 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
ea0369 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
ea0369 |
* Lesser General Public License for more details.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
ea0369 |
* License along with this library. If not, see
|
|
Packit Service |
ea0369 |
* <http://www.gnu.org/licenses/>.
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
Packit Service |
ea0369 |
* Christophe Fergeau <cfergeau@redhat.com>
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#include <config.h>
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#include "libvirt-gconfig/libvirt-gconfig.h"
|
|
Packit Service |
ea0369 |
#include "libvirt-gconfig/libvirt-gconfig-private.h"
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
#define GVIR_CONFIG_DOMAIN_INTERFACE_GET_PRIVATE(obj) \
|
|
Packit Service |
ea0369 |
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_INTERFACE, GVirConfigDomainInterfacePrivate))
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
struct _GVirConfigDomainInterfacePrivate
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
gboolean unused;
|
|
Packit Service |
ea0369 |
};
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GVirConfigDomainInterface, gvir_config_domain_interface, GVIR_CONFIG_TYPE_DOMAIN_DEVICE);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
static void gvir_config_domain_interface_class_init(GVirConfigDomainInterfaceClass *klass G_GNUC_UNUSED)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
static void gvir_config_domain_interface_init(GVirConfigDomainInterface *interface)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
interface->priv = GVIR_CONFIG_DOMAIN_INTERFACE_GET_PRIVATE(interface);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_domain_interface_set_ifname(GVirConfigDomainInterface *interface,
|
|
Packit Service |
ea0369 |
const char *ifname)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"target", "dev", ifname);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_domain_interface_set_link_state(GVirConfigDomainInterface *interface,
|
|
Packit Service |
ea0369 |
GVirConfigDomainInterfaceLinkState state)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
GVirConfigObject *node;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"link");
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
|
|
Packit Service |
ea0369 |
gvir_config_object_set_attribute_with_type(node,
|
|
Packit Service |
ea0369 |
"state",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_LINK_STATE,
|
|
Packit Service |
ea0369 |
state,
|
|
Packit Service |
ea0369 |
NULL);
|
|
Packit Service |
ea0369 |
g_object_unref(G_OBJECT(node));
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_domain_interface_set_mac(GVirConfigDomainInterface *interface,
|
|
Packit Service |
ea0369 |
const char *mac_address)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"mac", "address", mac_address);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface,
|
|
Packit Service |
ea0369 |
const char *model)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_replace_child_with_attribute(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"model", "type", model);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
const char *gvir_config_domain_interface_get_ifname(GVirConfigDomainInterface *interface)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"target", "dev");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
GVirConfigDomainInterfaceLinkState gvir_config_domain_interface_get_link_state(GVirConfigDomainInterface *interface)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface),
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"link", "state",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_LINK_STATE,
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
const char *gvir_config_domain_interface_get_mac(GVirConfigDomainInterface *interface)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"mac", "address");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
const char *gvir_config_domain_interface_get_model(GVirConfigDomainInterface *interface)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"model", "type");
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_interface_set_filterref:
|
|
Packit Service |
ea0369 |
* @interface: a #GVirConfigDomainInterface
|
|
Packit Service |
ea0369 |
* @filterref: (allow-none): the filterref to set
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
void gvir_config_domain_interface_set_filterref(GVirConfigDomainInterface *interface,
|
|
Packit Service |
ea0369 |
GVirConfigDomainInterfaceFilterref *filterref)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface));
|
|
Packit Service |
ea0369 |
g_return_if_fail(filterref == NULL || GVIR_CONFIG_IS_DOMAIN_INTERFACE_FILTERREF(filterref));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"filterref",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_OBJECT(filterref));
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
/**
|
|
Packit Service |
ea0369 |
* gvir_config_domain_interface_get_filterref:
|
|
Packit Service |
ea0369 |
* @interface: a #GVirConfigDomainInterface
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Gets the filterref associated with the @interface
|
|
Packit Service |
ea0369 |
*
|
|
Packit Service |
ea0369 |
* Returns: (transfer full): A #GVirConfigDomainInterfaceFilterref. The returned
|
|
Packit Service |
ea0369 |
* object should be unreffed with g_object_unref() when no longer needed.
|
|
Packit Service |
ea0369 |
*/
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
GVirConfigDomainInterfaceFilterref *gvir_config_domain_interface_get_filterref(GVirConfigDomainInterface *interface)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
GVirConfigObject *object;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_INTERFACE(interface), NULL);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
object = gvir_config_object_get_child_with_type
|
|
Packit Service |
ea0369 |
(GVIR_CONFIG_OBJECT(interface),
|
|
Packit Service |
ea0369 |
"filterref",
|
|
Packit Service |
ea0369 |
GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_FILTERREF);
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_DOMAIN_INTERFACE_FILTERREF(object);
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
G_GNUC_INTERNAL GVirConfigDomainDevice *
|
|
Packit Service |
ea0369 |
gvir_config_domain_interface_new_from_tree(GVirConfigXmlDoc *doc,
|
|
Packit Service |
ea0369 |
xmlNodePtr tree)
|
|
Packit Service |
ea0369 |
{
|
|
Packit Service |
ea0369 |
const char *type;
|
|
Packit Service |
ea0369 |
GType gtype;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
type = gvir_config_xml_get_attribute_content(tree, "type");
|
|
Packit Service |
ea0369 |
if (type == NULL)
|
|
Packit Service |
ea0369 |
return NULL;
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
if (g_str_equal(type, "network")) {
|
|
Packit Service |
ea0369 |
gtype = GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_NETWORK;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "user")) {
|
|
Packit Service |
ea0369 |
gtype = GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_USER;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "bridge")) {
|
|
Packit Service |
ea0369 |
gtype = GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_BRIDGE;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "direct")) {
|
|
Packit Service |
ea0369 |
goto unimplemented;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "server")) {
|
|
Packit Service |
ea0369 |
goto unimplemented;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "mcast")) {
|
|
Packit Service |
ea0369 |
goto unimplemented;
|
|
Packit Service |
ea0369 |
} else if (g_str_equal(type, "ethernet")) {
|
|
Packit Service |
ea0369 |
goto unimplemented;
|
|
Packit Service |
ea0369 |
} else {
|
|
Packit Service |
ea0369 |
g_debug("Unknown domain interface node: %s", type);
|
|
Packit Service |
ea0369 |
return NULL;
|
|
Packit Service |
ea0369 |
}
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
return GVIR_CONFIG_DOMAIN_DEVICE(gvir_config_object_new_from_tree(gtype, doc, NULL, tree));
|
|
Packit Service |
ea0369 |
|
|
Packit Service |
ea0369 |
unimplemented:
|
|
Packit Service |
ea0369 |
g_debug("Parsing of '%s' domain interface nodes is unimplemented", type);
|
|
Packit Service |
ea0369 |
return NULL;
|
|
Packit Service |
ea0369 |
}
|