
this is the API layer let the libvirt-cim call. Signed-off-by: Wayne Xia <xiawenc@linux.vnet.ibm.com> --- libxkutil/host_network_API.c | 150 ++++++++++++++++++++++++++++++++++++++++++ libxkutil/host_network_API.h | 32 +++++++++ 2 files changed, 182 insertions(+), 0 deletions(-) create mode 100644 libxkutil/host_network_API.c create mode 100644 libxkutil/host_network_API.h diff --git a/libxkutil/host_network_API.c b/libxkutil/host_network_API.c new file mode 100644 index 0000000..89a9879 --- /dev/null +++ b/libxkutil/host_network_API.c @@ -0,0 +1,150 @@ +/* + * Copyright IBM Corp. 2011 + * + * Authors: + * Wenchao Xia <xiawenc@cn.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + */ + + +#include "host_network_API.h" +#include "host_network_implement_cmdline.h" +#include "host_network_error.h" + +/* this layer is added to devide the abstraction and implemention, so that + different implemention could be used and switched */ + +int get_host_ifaces(EthIfacesList *plist, + eth_iface_filter_func filter_func, void *filter_opaque) +{ + return get_host_eth_ifaces_cmd_all(plist, filter_func, filter_opaque); +} + +int add_host_iface(EthIface *piface, int persist_flag) +{ + int ret = 0; + if (piface->eth_type == ETH_TYPE_BRIDGE) { + ret = add_host_br_cmd(piface, persist_flag); + } else if (piface->eth_type == ETH_TYPE_VLAN) { + + if (piface->pvlan_prop == NULL) { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } else { + if (piface->pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) { + ret = add_host_vlan_8021q_cmd(piface, persist_flag); + } else { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } + } + + } else { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } + + return ret; +} + +int del_host_iface(EthIface *piface, int persist_flag) +{ + int ret = 0; + if (piface->eth_type == ETH_TYPE_BRIDGE) { + ret = del_host_br_cmd(piface, persist_flag); + } else if (piface->eth_type == ETH_TYPE_VLAN) { + + if (piface->pvlan_prop == NULL) { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } else { + if (piface->pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) { + ret = del_host_vlan_8021q_cmd(piface, persist_flag); + } else { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } + } + + } else { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } + + return ret; +} + +int mod_host_iface(EthIface *piface, int persist_flag) +{ + int ret = 0; + if (piface->eth_type == ETH_TYPE_BRIDGE) { + ret = mod_host_br_cmd(piface, persist_flag); + } else if (piface->eth_type == ETH_TYPE_VLAN) { + + if (piface->pvlan_prop == NULL) { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } else { + if (piface->pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) { + ret = mod_host_vlan_8021q_cmd(piface, persist_flag); + } else { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } + } + + } else { + CU_DEBUG("requested an unsupported operation."); + ret = ERR_REQUEST_NOT_SUPPORT; + } + + return ret; +} + +int change_state_host_iface(EthIface *piface, int state) +{ + return change_state_host_iface_cmd(piface, state); +} + +int connect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag) +{ + if ((p1 == NULL) || (p2 == NULL)) { + return 0; + } + if ((p1->eth_type == ETH_TYPE_BRIDGE) && + (p2->eth_type != ETH_TYPE_BRIDGE)) { + return add_host_iface_to_br_cmd(p2, p1, persist_flag); + } else if ((p1->eth_type != ETH_TYPE_BRIDGE) && + (p2->eth_type == ETH_TYPE_BRIDGE)) { + return add_host_iface_to_br_cmd(p1, p2, persist_flag); + } else { + CU_DEBUG("requested an unsupported operation."); + return ERR_REQUEST_NOT_SUPPORT; + } +} + +int disconnect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag) +{ + if ((p1 == NULL) || (p2 == NULL)) { + return 0; + } + if ((p1->eth_type == ETH_TYPE_BRIDGE) && + (p2->eth_type != ETH_TYPE_BRIDGE)) { + return remove_host_iface_from_br_cmd(p2, p1, persist_flag); + } else if ((p1->eth_type != ETH_TYPE_BRIDGE) && + (p2->eth_type == ETH_TYPE_BRIDGE)) { + return remove_host_iface_from_br_cmd(p1, p2, persist_flag); + } else { + CU_DEBUG("requested an unsupported operation."); + return ERR_REQUEST_NOT_SUPPORT; + } +} + +char *get_host_iface_error_reason(int errno) +{ + return translate_error_no(errno); +} diff --git a/libxkutil/host_network_API.h b/libxkutil/host_network_API.h new file mode 100644 index 0000000..b821d58 --- /dev/null +++ b/libxkutil/host_network_API.h @@ -0,0 +1,32 @@ +/* + * Copyright IBM Corp. 2011 + * + * Authors: + * Wenchao Xia <xiawenc@cn.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + */ + +#ifndef HOST_NETWORK_API +#define HOST_NETWORK_API + +#include "host_network_basic.h" +#include "host_network_helper.h" + +int get_host_ifaces(EthIfacesList *plist, + eth_iface_filter_func filter_func, void *filter_opaque); + +int add_host_iface(EthIface *piface, int persist_flag); +int del_host_iface(EthIface *piface, int persist_flag); +int mod_host_iface(EthIface *piface, int persist_flag); +int change_state_host_iface(EthIface *piface, int state); + +int connect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag); +int disconnect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag); + +char *get_host_iface_error_reason(int errno); + +#endif -- 1.7.6