[libvirt] [PATCH] nwfilter: use virFindFileInPath for needed CLI tools
by Stefan Berger
I am getting rid of determining the path to necessary CLI tools at
compile time. Instead, now the firewall driver has an initialization
function that uses virFindFileInPath() to determine the path to
necessary CLI tools and a shutdown function to free allocated memory.
The rest of the patch mostly deals with availability of the CLI tools
and to not call certain code blocks if a tool is not available and that
strings now have to be built slightly differently.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
configure.ac | 12
src/conf/nwfilter_conf.h | 10
src/nwfilter/nwfilter_driver.c | 3
src/nwfilter/nwfilter_ebiptables_driver.c | 454 +++++++++++++++++++-----------
src/nwfilter/nwfilter_gentech_driver.c | 25 +
src/nwfilter/nwfilter_gentech_driver.h | 2
6 files changed, 337 insertions(+), 169 deletions(-)
Index: libvirt-acl/src/conf/nwfilter_conf.h
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.h
+++ libvirt-acl/src/conf/nwfilter_conf.h
@@ -451,6 +451,9 @@ struct domUpdateCBStruct {
};
+typedef int (*virNWFilterTechDrvInit)(void);
+typedef void (*virNWFilterTechDrvShutdown)(void);
+
enum virDomainNetType;
typedef int (*virNWFilterRuleCreateInstance)(virConnectPtr conn,
@@ -484,9 +487,16 @@ typedef int (*virNWFilterRuleFreeInstanc
typedef int (*virNWFilterRuleDisplayInstanceData)(virConnectPtr conn,
void *_inst);
+enum techDrvFlags {
+ TECHDRV_FLAG_INITIALIZED = (1 << 0),
+};
struct _virNWFilterTechDriver {
const char *name;
+ enum techDrvFlags flags;
+
+ virNWFilterTechDrvInit init;
+ virNWFilterTechDrvShutdown shutdown;
virNWFilterRuleCreateInstance createRuleInstance;
virNWFilterRuleApplyNewRules applyNewRules;
Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -62,12 +62,13 @@
: ""
-#define EBTABLES_CMD EBTABLES_PATH
-#define IPTABLES_CMD IPTABLES_PATH
-#define IP6TABLES_CMD IP6TABLES_PATH
-#define BASH_CMD BASH_PATH
-#define GREP_CMD GREP_PATH
-#define GAWK_CMD GAWK_PATH
+static char *ebtables_cmd_path;
+static char *iptables_cmd_path;
+static char *ip6tables_cmd_path;
+static char *bash_cmd_path;
+static char *grep_cmd_path;
+static char *gawk_cmd_path;
+
#define PRINT_ROOT_CHAIN(buf, prefix, ifname) \
snprintf(buf, sizeof(buf), "libvirt-%c-%s", prefix, ifname)
@@ -97,6 +98,10 @@ static const char *m_physdev_out_str = "
#define MATCH_PHYSDEV_OUT m_physdev_out_str
+static int ebiptablesDriverInit(void);
+static void ebiptablesDriverShutdown(void);
+
+
static const char *supported_protocols[] = {
"ipv4",
"ipv6",
@@ -367,11 +372,11 @@ static int iptablesLinkIPTablesBaseChain
{
virBufferVSprintf(buf,
"res=$(%s -L %s -n --line-number | "
- GREP_CMD " \" %s \")\n"
+ "%s \" %s \")\n"
"if [ $? -ne 0 ]; then\n"
" %s -I %s %d -j %s\n"
"else\n"
- " r=$(echo $res | " GAWK_CMD " '{print $1}')\n"
+ " r=$(echo $res | %s '{print $1}')\n"
" if [ \"${r}\" != \"%d\" ]; then\n"
" " CMD_DEF("%s -I %s %d -j %s") CMD_SEPARATOR
" " CMD_EXEC
@@ -384,9 +389,10 @@ static int iptablesLinkIPTablesBaseChain
"fi\n",
iptables_cmd, syschain,
- udchain,
+ grep_cmd_path, udchain,
iptables_cmd, syschain, pos, udchain,
+ gawk_cmd_path,
pos,
@@ -1052,10 +1058,19 @@ _iptablesCreateRuleInstance(int directio
char number[20];
virBuffer buf = VIR_BUFFER_INITIALIZER;
const char *target;
- const char *iptables_cmd = (isIPv6) ? IP6TABLES_CMD : IPTABLES_CMD;
+ const char *iptables_cmd = (isIPv6) ? ip6tables_cmd_path
+ : iptables_cmd_path;
unsigned int bufUsed;
bool srcMacSkipped = false;
+ if (!iptables_cmd) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot create rule since %s tool is "
+ "missing."),
+ isIPv6 ? "ip6tables" : "iptables");
+ goto err_exit;
+ }
+
PRINT_IPT_ROOT_CHAIN(chain, chainPrefix, ifname);
switch (rule->prtclType) {
@@ -1518,6 +1533,13 @@ ebtablesCreateRuleInstance(char chainPre
char chain[MAX_CHAINNAME_LENGTH];
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ if (!ebtables_cmd_path) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("cannot create rule since ebtables tool is "
+ "missing."));
+ goto err_exit;
+ }
+
if (nwfilter->chainsuffix == VIR_NWFILTER_CHAINSUFFIX_ROOT)
PRINT_ROOT_CHAIN(chain, chainPrefix, ifname);
else
@@ -1529,8 +1551,8 @@ ebtablesCreateRuleInstance(char chainPre
case VIR_NWFILTER_RULE_PROTOCOL_MAC:
virBufferVSprintf(&buf,
- CMD_DEF_PRE EBTABLES_CMD " -t %s -%%c %s %%s",
- EBTABLES_DEFAULT_TABLE, chain);
+ CMD_DEF_PRE "%s -t %s -%%c %s %%s",
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
if (ebtablesHandleEthHdr(&buf,
@@ -1554,8 +1576,8 @@ ebtablesCreateRuleInstance(char chainPre
case VIR_NWFILTER_RULE_PROTOCOL_ARP:
virBufferVSprintf(&buf,
- CMD_DEF_PRE EBTABLES_CMD " -t %s -%%c %s %%s",
- EBTABLES_DEFAULT_TABLE, chain);
+ CMD_DEF_PRE "%s -t %s -%%c %s %%s",
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
if (ebtablesHandleEthHdr(&buf,
vars,
@@ -1653,8 +1675,8 @@ ebtablesCreateRuleInstance(char chainPre
case VIR_NWFILTER_RULE_PROTOCOL_IP:
virBufferVSprintf(&buf,
- CMD_DEF_PRE EBTABLES_CMD " -t %s -%%c %s %%s",
- EBTABLES_DEFAULT_TABLE, chain);
+ CMD_DEF_PRE "%s -t %s -%%c %s %%s",
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
if (ebtablesHandleEthHdr(&buf,
vars,
@@ -1789,8 +1811,8 @@ ebtablesCreateRuleInstance(char chainPre
case VIR_NWFILTER_RULE_PROTOCOL_IPV6:
virBufferVSprintf(&buf,
- CMD_DEF_PRE EBTABLES_CMD " -t %s -%%c %s %%s",
- EBTABLES_DEFAULT_TABLE, chain);
+ CMD_DEF_PRE "%s -t %s -%%c %s %%s",
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
if (ebtablesHandleEthHdr(&buf,
vars,
@@ -1913,8 +1935,8 @@ ebtablesCreateRuleInstance(char chainPre
case VIR_NWFILTER_RULE_PROTOCOL_NONE:
virBufferVSprintf(&buf,
- CMD_DEF_PRE EBTABLES_CMD " -t %s -%%c %s %%s",
- EBTABLES_DEFAULT_TABLE, chain);
+ CMD_DEF_PRE "%s -t %s -%%c %s %%s",
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
break;
default:
@@ -2103,16 +2125,26 @@ ebiptablesWriteToTempFile(const char *st
char filename[] = "/tmp/virtdXXXXXX";
int len;
char *filnam;
- const char header[] = "#!" BASH_CMD "\n";
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *header;
size_t written;
+ virBufferVSprintf(&buf, "#!%s\n", bash_cmd_path);
+
+ if (virBufferError(&buf)) {
+ virBufferFreeAndReset(&buf);
+ virReportOOMError();
+ return NULL;
+ }
+ header = virBufferContentAndReset(&buf);
+
int fd = mkstemp(filename);
if (fd < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
"%s",
_("cannot create temporary file"));
- return NULL;
+ goto err_exit;
}
if (fchmod(fd, S_IXUSR| S_IRUSR | S_IWUSR) < 0) {
@@ -2146,10 +2178,12 @@ ebiptablesWriteToTempFile(const char *st
goto err_exit;
}
+ VIR_FREE(header);
close(fd);
return filnam;
err_exit:
+ VIR_FREE(header);
close(fd);
unlink(filename);
return NULL;
@@ -2227,10 +2261,10 @@ ebtablesCreateTmpRootChain(virBufferPtr
PRINT_ROOT_CHAIN(chain, chainPrefix, ifname);
virBufferVSprintf(buf,
- CMD_DEF(EBTABLES_CMD " -t %s -N %s") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -N %s") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE, chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
CMD_STOPONERR(stopOnError));
return 0;
@@ -2250,10 +2284,10 @@ ebtablesLinkTmpRootChain(virBufferPtr bu
PRINT_ROOT_CHAIN(chain, chainPrefix, ifname);
virBufferVSprintf(buf,
- CMD_DEF(EBTABLES_CMD " -t %s -A %s -%c %s -j %s") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -%c %s -j %s") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE,
(incoming) ? EBTABLES_CHAIN_INCOMING
: EBTABLES_CHAIN_OUTGOING,
iodev, ifname, chain,
@@ -2281,10 +2315,10 @@ _ebtablesRemoveRootChain(virBufferPtr bu
PRINT_ROOT_CHAIN(chain, chainPrefix, ifname);
virBufferVSprintf(buf,
- EBTABLES_CMD " -t %s -F %s" CMD_SEPARATOR
- EBTABLES_CMD " -t %s -X %s" CMD_SEPARATOR,
- EBTABLES_DEFAULT_TABLE, chain,
- EBTABLES_DEFAULT_TABLE, chain);
+ "%s -t %s -F %s" CMD_SEPARATOR
+ "%s -t %s -X %s" CMD_SEPARATOR,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
return 0;
}
@@ -2326,8 +2360,8 @@ _ebtablesUnlinkRootChain(virBufferPtr bu
PRINT_ROOT_CHAIN(chain, chainPrefix, ifname);
virBufferVSprintf(buf,
- EBTABLES_CMD " -t %s -D %s -%c %s -j %s" CMD_SEPARATOR,
- EBTABLES_DEFAULT_TABLE,
+ "%s -t %s -D %s -%c %s -j %s" CMD_SEPARATOR,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE,
(incoming) ? EBTABLES_CHAIN_INCOMING
: EBTABLES_CHAIN_OUTGOING,
iodev, ifname, chain);
@@ -2367,20 +2401,19 @@ ebtablesCreateTmpSubChain(virBufferPtr b
PRINT_CHAIN(chain, chainPrefix, ifname, protocol);
virBufferVSprintf(buf,
- CMD_DEF(EBTABLES_CMD " -t %s -N %s") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -N %s") CMD_SEPARATOR
CMD_EXEC
"%s"
- CMD_DEF(EBTABLES_CMD " -t %s -A %s -p %s -j %s") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -p %s -j %s") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE, chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
CMD_STOPONERR(stopOnError),
- EBTABLES_DEFAULT_TABLE,
- rootchain,
- protocol, chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE,
+ rootchain, protocol, chain,
CMD_STOPONERR(stopOnError));
@@ -2409,16 +2442,15 @@ _ebtablesRemoveSubChain(virBufferPtr buf
PRINT_CHAIN(chain, chainPrefix, ifname, protocol);
virBufferVSprintf(buf,
- EBTABLES_CMD " -t %s -D %s -p %s -j %s" CMD_SEPARATOR
- EBTABLES_CMD " -t %s -F %s" CMD_SEPARATOR
- EBTABLES_CMD " -t %s -X %s" CMD_SEPARATOR,
- EBTABLES_DEFAULT_TABLE,
- rootchain,
- protocol, chain,
+ "%s -t %s -D %s -p %s -j %s" CMD_SEPARATOR
+ "%s -t %s -F %s" CMD_SEPARATOR
+ "%s -t %s -X %s" CMD_SEPARATOR,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE,
+ rootchain, protocol, chain,
- EBTABLES_DEFAULT_TABLE, chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
- EBTABLES_DEFAULT_TABLE, chain);
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain);
return 0;
}
@@ -2497,10 +2529,8 @@ ebtablesRenameTmpSubChain(virBufferPtr b
}
virBufferVSprintf(buf,
- EBTABLES_CMD " -t %s -E %s %s" CMD_SEPARATOR,
- EBTABLES_DEFAULT_TABLE,
- tmpchain,
- chain);
+ "%s -t %s -E %s %s" CMD_SEPARATOR,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, tmpchain, chain);
return 0;
}
@@ -2568,6 +2598,13 @@ ebtablesApplyBasicRules(const char *ifna
char chainPrefix = CHAINPREFIX_HOST_IN_TEMP;
char macaddr_str[VIR_MAC_STRING_BUFLEN];
+ if (!ebtables_cmd_path) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("cannot create rules since ebtables tool is "
+ "missing."));
+ return 1;
+ }
+
virFormatMacAddr(macaddr, macaddr_str);
ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
@@ -2581,44 +2618,36 @@ ebtablesApplyBasicRules(const char *ifna
PRINT_ROOT_CHAIN(chain, chainPrefix, ifname);
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s -s ! %s -j DROP") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -s ! %s -j DROP") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain,
- macaddr_str,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE,
+ chain, macaddr_str,
CMD_STOPONERR(1));
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s -p IPv4 -j ACCEPT") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -p IPv4 -j ACCEPT") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
CMD_STOPONERR(1));
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s -p ARP -j ACCEPT") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -p ARP -j ACCEPT") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
CMD_STOPONERR(1));
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s -j DROP") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -j DROP") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain,
CMD_STOPONERR(1));
ebtablesLinkTmpRootChain(&buf, 1, ifname, 1);
@@ -2665,6 +2694,13 @@ ebtablesApplyDHCPOnlyRules(const char *i
char macaddr_str[VIR_MAC_STRING_BUFLEN];
char *srcIPParam = NULL;
+ if (!ebtables_cmd_path) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("cannot create rules since ebtables tool is "
+ "missing."));
+ return 1;
+ }
+
if (dhcpserver) {
virBufferVSprintf(&buf, " --ip-src %s", dhcpserver);
if (virBufferError(&buf))
@@ -2688,8 +2724,7 @@ ebtablesApplyDHCPOnlyRules(const char *i
PRINT_ROOT_CHAIN(chain_out, CHAINPREFIX_HOST_OUT_TEMP, ifname);
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s"
+ CMD_DEF("%s -t %s -A %s"
" -s %s -d Broadcast "
" -p ipv4 --ip-protocol udp"
" --ip-src 0.0.0.0 --ip-dst 255.255.255.255"
@@ -2698,24 +2733,20 @@ ebtablesApplyDHCPOnlyRules(const char *i
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain_in,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain_in,
macaddr_str,
CMD_STOPONERR(1));
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s -j DROP") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -j DROP") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain_in,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain_in,
CMD_STOPONERR(1));
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s"
+ CMD_DEF("%s -t %s -A %s"
" -d %s"
" -p ipv4 --ip-protocol udp"
" %s"
@@ -2724,20 +2755,17 @@ ebtablesApplyDHCPOnlyRules(const char *i
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain_out,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain_out,
macaddr_str,
srcIPParam != NULL ? srcIPParam : "",
CMD_STOPONERR(1));
virBufferVSprintf(&buf,
- CMD_DEF(EBTABLES_CMD
- " -t %s -A %s -j DROP") CMD_SEPARATOR
+ CMD_DEF("%s -t %s -A %s -j DROP") CMD_SEPARATOR
CMD_EXEC
"%s",
- EBTABLES_DEFAULT_TABLE,
- chain_out,
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE, chain_out,
CMD_STOPONERR(1));
ebtablesLinkTmpRootChain(&buf, 1, ifname, 1);
@@ -2769,6 +2797,9 @@ ebtablesRemoveBasicRules(const char *ifn
virBuffer buf = VIR_BUFFER_INITIALIZER;
int cli_status;
+ if (!ebtables_cmd_path)
+ return 0;
+
ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
ebtablesRemoveTmpSubChains(&buf, ifname);
@@ -2800,8 +2831,8 @@ ebiptablesApplyNewRules(virConnectPtr co
ebiptablesRuleInstPtr *inst = (ebiptablesRuleInstPtr *)_inst;
int chains_in = 0, chains_out = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- int haveIptables = 0;
- int haveIp6tables = 0;
+ bool haveIptables = false;
+ bool haveIp6tables = false;
if (inst)
qsort(inst, nruleInstances, sizeof(inst[0]),
@@ -2816,12 +2847,14 @@ ebiptablesApplyNewRules(virConnectPtr co
}
}
- ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
- ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
- ebtablesRemoveTmpSubChains(&buf, ifname);
- ebtablesRemoveTmpRootChain(&buf, 1, ifname);
- ebtablesRemoveTmpRootChain(&buf, 0, ifname);
- ebiptablesExecCLI(&buf, &cli_status);
+ if (ebtables_cmd_path) {
+ ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
+ ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
+ ebtablesRemoveTmpSubChains(&buf, ifname);
+ ebtablesRemoveTmpRootChain(&buf, 1, ifname);
+ ebtablesRemoveTmpRootChain(&buf, 0, ifname);
+ ebiptablesExecCLI(&buf, &cli_status);
+ }
if (chains_in != 0)
ebtablesCreateTmpRootChain(&buf, 1, ifname, 1);
@@ -2855,34 +2888,32 @@ ebiptablesApplyNewRules(virConnectPtr co
'A', -1, 1);
break;
case RT_IPTABLES:
- haveIptables = 1;
+ haveIptables = true;
break;
case RT_IP6TABLES:
- haveIp6tables = 1;
+ haveIp6tables = true;
break;
}
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpebchains;
- // FIXME: establishment of iptables user define table tree goes here
-
if (haveIptables) {
- iptablesUnlinkTmpRootChains(IPTABLES_CMD, &buf, ifname);
- iptablesRemoveTmpRootChains(IPTABLES_CMD, &buf, ifname);
+ iptablesUnlinkTmpRootChains(iptables_cmd_path, &buf, ifname);
+ iptablesRemoveTmpRootChains(iptables_cmd_path, &buf, ifname);
- iptablesCreateBaseChains(IPTABLES_CMD, &buf);
+ iptablesCreateBaseChains(iptables_cmd_path, &buf);
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpebchains;
- iptablesCreateTmpRootChains(IPTABLES_CMD, &buf, ifname);
+ iptablesCreateTmpRootChains(iptables_cmd_path, &buf, ifname);
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpiptchains;
- iptablesLinkTmpRootChains(IPTABLES_CMD, &buf, ifname);
- iptablesSetupVirtInPost(IPTABLES_CMD, &buf, ifname);
+ iptablesLinkTmpRootChains(iptables_cmd_path, &buf, ifname);
+ iptablesSetupVirtInPost(iptables_cmd_path, &buf, ifname);
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpiptchains;
@@ -2898,21 +2929,21 @@ ebiptablesApplyNewRules(virConnectPtr co
}
if (haveIp6tables) {
- iptablesUnlinkTmpRootChains(IP6TABLES_CMD, &buf, ifname);
- iptablesRemoveTmpRootChains(IP6TABLES_CMD, &buf, ifname);
+ iptablesUnlinkTmpRootChains(ip6tables_cmd_path, &buf, ifname);
+ iptablesRemoveTmpRootChains(ip6tables_cmd_path, &buf, ifname);
- iptablesCreateBaseChains(IP6TABLES_CMD, &buf);
+ iptablesCreateBaseChains(ip6tables_cmd_path, &buf);
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpiptchains;
- iptablesCreateTmpRootChains(IP6TABLES_CMD, &buf, ifname);
+ iptablesCreateTmpRootChains(ip6tables_cmd_path, &buf, ifname);
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpip6tchains;
- iptablesLinkTmpRootChains(IP6TABLES_CMD, &buf, ifname);
- iptablesSetupVirtInPost(IP6TABLES_CMD, &buf, ifname);
+ iptablesLinkTmpRootChains(ip6tables_cmd_path, &buf, ifname);
+ iptablesSetupVirtInPost(ip6tables_cmd_path, &buf, ifname);
if (ebiptablesExecCLI(&buf, &cli_status) || cli_status != 0)
goto tear_down_tmpip6tchains;
@@ -2927,9 +2958,6 @@ ebiptablesApplyNewRules(virConnectPtr co
goto tear_down_tmpip6tchains;
}
-
- // END IPTABLES stuff
-
if (chains_in != 0)
ebtablesLinkTmpRootChain(&buf, 1, ifname, 1);
if (chains_out != 0)
@@ -2941,25 +2969,29 @@ ebiptablesApplyNewRules(virConnectPtr co
return 0;
tear_down_ebsubchains_and_unlink:
- ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
- ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
+ if (ebtables_cmd_path) {
+ ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
+ ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
+ }
tear_down_tmpip6tchains:
if (haveIp6tables) {
- iptablesUnlinkTmpRootChains(IP6TABLES_CMD, &buf, ifname);
- iptablesRemoveTmpRootChains(IP6TABLES_CMD, &buf, ifname);
+ iptablesUnlinkTmpRootChains(ip6tables_cmd_path, &buf, ifname);
+ iptablesRemoveTmpRootChains(ip6tables_cmd_path, &buf, ifname);
}
tear_down_tmpiptchains:
if (haveIptables) {
- iptablesUnlinkTmpRootChains(IPTABLES_CMD, &buf, ifname);
- iptablesRemoveTmpRootChains(IPTABLES_CMD, &buf, ifname);
+ iptablesUnlinkTmpRootChains(iptables_cmd_path, &buf, ifname);
+ iptablesRemoveTmpRootChains(iptables_cmd_path, &buf, ifname);
}
tear_down_tmpebchains:
- ebtablesRemoveTmpSubChains(&buf, ifname);
- ebtablesRemoveTmpRootChain(&buf, 1, ifname);
- ebtablesRemoveTmpRootChain(&buf, 0, ifname);
+ if (ebtables_cmd_path) {
+ ebtablesRemoveTmpSubChains(&buf, ifname);
+ ebtablesRemoveTmpRootChain(&buf, 1, ifname);
+ ebtablesRemoveTmpRootChain(&buf, 0, ifname);
+ }
ebiptablesExecCLI(&buf, &cli_status);
@@ -2978,18 +3010,24 @@ ebiptablesTearNewRules(virConnectPtr con
int cli_status;
virBuffer buf = VIR_BUFFER_INITIALIZER;
- iptablesUnlinkTmpRootChains(IPTABLES_CMD, &buf, ifname);
- iptablesRemoveTmpRootChains(IPTABLES_CMD, &buf, ifname);
+ if (iptables_cmd_path) {
+ iptablesUnlinkTmpRootChains(iptables_cmd_path, &buf, ifname);
+ iptablesRemoveTmpRootChains(iptables_cmd_path, &buf, ifname);
+ }
- iptablesUnlinkTmpRootChains(IP6TABLES_CMD, &buf, ifname);
- iptablesRemoveTmpRootChains(IP6TABLES_CMD, &buf, ifname);
+ if (ip6tables_cmd_path) {
+ iptablesUnlinkTmpRootChains(ip6tables_cmd_path, &buf, ifname);
+ iptablesRemoveTmpRootChains(ip6tables_cmd_path, &buf, ifname);
+ }
- ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
- ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
+ if (ebtables_cmd_path) {
+ ebtablesUnlinkTmpRootChain(&buf, 1, ifname);
+ ebtablesUnlinkTmpRootChain(&buf, 0, ifname);
- ebtablesRemoveTmpSubChains(&buf, ifname);
- ebtablesRemoveTmpRootChain(&buf, 1, ifname);
- ebtablesRemoveTmpRootChain(&buf, 0, ifname);
+ ebtablesRemoveTmpSubChains(&buf, ifname);
+ ebtablesRemoveTmpRootChain(&buf, 1, ifname);
+ ebtablesRemoveTmpRootChain(&buf, 0, ifname);
+ }
ebiptablesExecCLI(&buf, &cli_status);
@@ -3005,31 +3043,37 @@ ebiptablesTearOldRules(virConnectPtr con
virBuffer buf = VIR_BUFFER_INITIALIZER;
// switch to new iptables user defined chains
- iptablesUnlinkRootChains(IPTABLES_CMD, &buf, ifname);
- iptablesRemoveRootChains(IPTABLES_CMD, &buf, ifname);
+ if (iptables_cmd_path) {
+ iptablesUnlinkRootChains(iptables_cmd_path, &buf, ifname);
+ iptablesRemoveRootChains(iptables_cmd_path, &buf, ifname);
- iptablesRenameTmpRootChains(IPTABLES_CMD, &buf, ifname);
- ebiptablesExecCLI(&buf, &cli_status);
+ iptablesRenameTmpRootChains(iptables_cmd_path, &buf, ifname);
+ ebiptablesExecCLI(&buf, &cli_status);
+ }
- iptablesUnlinkRootChains(IP6TABLES_CMD, &buf, ifname);
- iptablesRemoveRootChains(IP6TABLES_CMD, &buf, ifname);
+ if (ip6tables_cmd_path) {
+ iptablesUnlinkRootChains(ip6tables_cmd_path, &buf, ifname);
+ iptablesRemoveRootChains(ip6tables_cmd_path, &buf, ifname);
- iptablesRenameTmpRootChains(IP6TABLES_CMD, &buf, ifname);
- ebiptablesExecCLI(&buf, &cli_status);
+ iptablesRenameTmpRootChains(ip6tables_cmd_path, &buf, ifname);
+ ebiptablesExecCLI(&buf, &cli_status);
+ }
- ebtablesUnlinkRootChain(&buf, 1, ifname);
- ebtablesUnlinkRootChain(&buf, 0, ifname);
+ if (ebtables_cmd_path) {
+ ebtablesUnlinkRootChain(&buf, 1, ifname);
+ ebtablesUnlinkRootChain(&buf, 0, ifname);
- ebtablesRemoveSubChains(&buf, ifname);
+ ebtablesRemoveSubChains(&buf, ifname);
- ebtablesRemoveRootChain(&buf, 1, ifname);
- ebtablesRemoveRootChain(&buf, 0, ifname);
+ ebtablesRemoveRootChain(&buf, 1, ifname);
+ ebtablesRemoveRootChain(&buf, 0, ifname);
- ebtablesRenameTmpSubChains(&buf, ifname);
- ebtablesRenameTmpRootChain(&buf, 1, ifname);
- ebtablesRenameTmpRootChain(&buf, 0, ifname);
+ ebtablesRenameTmpSubChains(&buf, ifname);
+ ebtablesRenameTmpRootChain(&buf, 1, ifname);
+ ebtablesRenameTmpRootChain(&buf, 0, ifname);
- ebiptablesExecCLI(&buf, &cli_status);
+ ebiptablesExecCLI(&buf, &cli_status);
+ }
return 0;
}
@@ -3095,21 +3139,27 @@ ebiptablesAllTeardown(const char *ifname
virBuffer buf = VIR_BUFFER_INITIALIZER;
int cli_status;
- iptablesUnlinkRootChains(IPTABLES_CMD, &buf, ifname);
- iptablesClearVirtInPost (IPTABLES_CMD, &buf, ifname);
- iptablesRemoveRootChains(IPTABLES_CMD, &buf, ifname);
+ if (iptables_cmd_path) {
+ iptablesUnlinkRootChains(iptables_cmd_path, &buf, ifname);
+ iptablesClearVirtInPost (iptables_cmd_path, &buf, ifname);
+ iptablesRemoveRootChains(iptables_cmd_path, &buf, ifname);
+ }
- iptablesUnlinkRootChains(IP6TABLES_CMD, &buf, ifname);
- iptablesClearVirtInPost (IP6TABLES_CMD, &buf, ifname);
- iptablesRemoveRootChains(IP6TABLES_CMD, &buf, ifname);
+ if (ip6tables_cmd_path) {
+ iptablesUnlinkRootChains(ip6tables_cmd_path, &buf, ifname);
+ iptablesClearVirtInPost (ip6tables_cmd_path, &buf, ifname);
+ iptablesRemoveRootChains(ip6tables_cmd_path, &buf, ifname);
+ }
- ebtablesUnlinkRootChain(&buf, 1, ifname);
- ebtablesUnlinkRootChain(&buf, 0, ifname);
+ if (ebtables_cmd_path) {
+ ebtablesUnlinkRootChain(&buf, 1, ifname);
+ ebtablesUnlinkRootChain(&buf, 0, ifname);
- ebtablesRemoveRootChain(&buf, 1, ifname);
- ebtablesRemoveRootChain(&buf, 0, ifname);
+ ebtablesRemoveRootChain(&buf, 1, ifname);
+ ebtablesRemoveRootChain(&buf, 0, ifname);
- ebtablesRemoveSubChains(&buf, ifname);
+ ebtablesRemoveSubChains(&buf, ifname);
+ }
ebiptablesExecCLI(&buf, &cli_status);
@@ -3119,6 +3169,10 @@ ebiptablesAllTeardown(const char *ifname
virNWFilterTechDriver ebiptables_driver = {
.name = EBIPTABLES_DRIVER_ID,
+ .flags = 0,
+
+ .init = ebiptablesDriverInit,
+ .shutdown = ebiptablesDriverShutdown,
.createRuleInstance = ebiptablesCreateRuleInstance,
.applyNewRules = ebiptablesApplyNewRules,
@@ -3129,3 +3183,91 @@ virNWFilterTechDriver ebiptables_driver
.freeRuleInstance = ebiptablesFreeRuleInstance,
.displayRuleInstance = ebiptablesDisplayRuleInstance,
};
+
+
+static int
+ebiptablesDriverInit(void)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ int cli_status;
+
+ bash_cmd_path = virFindFileInPath("bash");
+ gawk_cmd_path = virFindFileInPath("gawk");
+ grep_cmd_path = virFindFileInPath("grep");
+
+ ebtables_cmd_path = virFindFileInPath("ebtables");
+ if (ebtables_cmd_path) {
+ /* basic probing */
+ virBufferVSprintf(&buf,
+ CMD_DEF("%s -t %s -L") CMD_SEPARATOR
+ CMD_EXEC
+ "%s",
+ ebtables_cmd_path, EBTABLES_DEFAULT_TABLE,
+ CMD_STOPONERR(1));
+
+ if (ebiptablesExecCLI(&buf, &cli_status) || cli_status)
+ VIR_FREE(ebtables_cmd_path);
+ }
+
+ iptables_cmd_path = virFindFileInPath("iptables");
+ if (iptables_cmd_path) {
+ virBufferVSprintf(&buf,
+ CMD_DEF("%s -L FORWARD") CMD_SEPARATOR
+ CMD_EXEC
+ "%s",
+ iptables_cmd_path,
+ CMD_STOPONERR(1));
+
+ if (ebiptablesExecCLI(&buf, &cli_status) || cli_status)
+ VIR_FREE(iptables_cmd_path);
+ }
+
+ ip6tables_cmd_path = virFindFileInPath("ip6tables");
+ if (ip6tables_cmd_path) {
+ virBufferVSprintf(&buf,
+ CMD_DEF("%s -L FORWARD") CMD_SEPARATOR
+ CMD_EXEC
+ "%s",
+ ip6tables_cmd_path,
+ CMD_STOPONERR(1));
+
+ if (ebiptablesExecCLI(&buf, &cli_status) || cli_status)
+ VIR_FREE(ip6tables_cmd_path);
+ }
+
+ /* ip(6)tables support needs bash, gawk & grep, ebtables doesn't */
+ if ((iptables_cmd_path != NULL || ip6tables_cmd_path != NULL) &&
+ (!grep_cmd_path || !bash_cmd_path || !gawk_cmd_path)) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("essential tools to support ip(6)tables "
+ "firewalls could not be located"));
+ VIR_FREE(iptables_cmd_path);
+ VIR_FREE(ip6tables_cmd_path);
+ }
+
+
+ if (!ebtables_cmd_path && !iptables_cmd_path && !ip6tables_cmd_path) {
+ virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("firewall tools were not found or "
+ "cannot be used"));
+ ebiptablesDriverShutdown();
+ return ENOTSUP;
+ }
+
+ ebiptables_driver.flags = TECHDRV_FLAG_INITIALIZED;
+
+ return 0;
+}
+
+
+static void
+ebiptablesDriverShutdown()
+{
+ VIR_FREE(gawk_cmd_path);
+ VIR_FREE(bash_cmd_path);
+ VIR_FREE(grep_cmd_path);
+ VIR_FREE(ebtables_cmd_path);
+ VIR_FREE(iptables_cmd_path);
+ VIR_FREE(ip6tables_cmd_path);
+ ebiptables_driver.flags = 0;
+}
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
@@ -50,12 +50,35 @@ static virNWFilterTechDriverPtr filter_t
};
+void virNWFilterTechDriversInit() {
+ int i = 0;
+ while (filter_tech_drivers[i]) {
+ if (!(filter_tech_drivers[i]->flags & TECHDRV_FLAG_INITIALIZED))
+ filter_tech_drivers[i]->init();
+ i++;
+ }
+}
+
+
+void virNWFilterTechDriversShutdown() {
+ int i = 0;
+ while (filter_tech_drivers[i]) {
+ if ((filter_tech_drivers[i]->flags & TECHDRV_FLAG_INITIALIZED))
+ filter_tech_drivers[i]->shutdown();
+ i++;
+ }
+}
+
+
virNWFilterTechDriverPtr
virNWFilterTechDriverForName(const char *name) {
int i = 0;
while (filter_tech_drivers[i]) {
- if (STREQ(filter_tech_drivers[i]->name, name))
+ if (STREQ(filter_tech_drivers[i]->name, name)) {
+ if ((filter_tech_drivers[i]->flags & TECHDRV_FLAG_INITIALIZED) == 0)
+ break;
return filter_tech_drivers[i];
+ }
i++;
}
return NULL;
Index: libvirt-acl/configure.ac
===================================================================
--- libvirt-acl.orig/configure.ac
+++ libvirt-acl/configure.ac
@@ -295,24 +295,12 @@ if test x"$with_rhel5_api" = x"yes"; the
AC_DEFINE([WITH_RHEL5_API], [1], [whether building for the RHEL-5 API])
fi
-AC_PATH_PROG([BASH_PATH], [bash], /bin/bash, [/bin:$PATH])
-AC_DEFINE_UNQUOTED([BASH_PATH], "$BASH_PATH", [path to bash binary])
-
AC_PATH_PROG([IPTABLES_PATH], [iptables], /sbin/iptables, [/usr/sbin:$PATH])
AC_DEFINE_UNQUOTED([IPTABLES_PATH], "$IPTABLES_PATH", [path to iptables binary])
-AC_PATH_PROG([IP6TABLES_PATH], [ip6tables], /sbin/ip6tables, [/usr/sbin:$PATH])
-AC_DEFINE_UNQUOTED([IP6TABLES_PATH], "$IP6TABLES_PATH", [path to ip6tables binary])
-
AC_PATH_PROG([EBTABLES_PATH], [ebtables], /sbin/ebtables, [/usr/sbin:$PATH])
AC_DEFINE_UNQUOTED([EBTABLES_PATH], "$EBTABLES_PATH", [path to ebtables binary])
-AC_PATH_PROG([GREP_PATH], [grep], /bin/grep, [/bin:$PATH])
-AC_DEFINE_UNQUOTED([GREP_PATH], "$GREP_PATH", [path to grep binary])
-
-AC_PATH_PROG([GAWK_PATH], [gawk], /bin/gawk, [/bin:$PATH])
-AC_DEFINE_UNQUOTED([GAWK_PATH], "$GAWK_PATH", [path to gawk binary])
-
if test "$with_openvz" = "yes"; then
AC_DEFINE_UNQUOTED([WITH_OPENVZ], 1, [whether OpenVZ driver is enabled])
Index: libvirt-acl/src/nwfilter/nwfilter_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_driver.c
@@ -70,6 +70,8 @@ nwfilterDriverStartup(int privileged) {
if (virNWFilterLearnInit() < 0)
return -1;
+ virNWFilterTechDriversInit();
+
if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB) < 0)
goto conf_init_err;
@@ -126,6 +128,7 @@ alloc_err_exit:
virNWFilterConfLayerShutdown();
conf_init_err:
+ virNWFilterTechDriversShutdown();
virNWFilterLearnShutdown();
return -1;
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.h
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
@@ -28,6 +28,8 @@ virNWFilterTechDriverPtr virNWFilterTech
int virNWFilterRuleInstAddData(virNWFilterRuleInstPtr res,
void *data);
+void virNWFilterTechDriversInit(void);
+void virNWFilterTechDriversShutdown(void);
enum instCase {
INSTANTIATE_ALWAYS,
14 years, 7 months
[libvirt] [PATCH] Fix build of openvz on RHEL-5.
by Chris Lalancette
When building libvirt on RHEL-5, I saw this error:
cc1: warnings being treated as errors
openvz/openvz_conf.c: In function 'openvzGetVPSUUID':
openvz/openvz_conf.c:835: warning: 'saveptr' may be used uninitialized in this function
make[3]: *** [libvirt_driver_openvz_la-openvz_conf.lo] Error 1
gcc in RHEL-5 gets upset about this usage of strtok_r (even though
it is perfectly valid). Just set *saveptr to NULL at the
start to quiet it down.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/openvz/openvz_conf.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 51567d4..8735cc1 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -832,7 +832,7 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
{
char conf_file[PATH_MAX];
char line[1024];
- char *saveptr;
+ char *saveptr = NULL;
char *uuidbuf;
char *iden;
int fd, ret;
--
1.6.6.1
14 years, 7 months
[libvirt] FYI: pushed trivial patches
by Chris Lalancette
I just pushed these 4 trivial patches:
>From 9295dfda8632aeb19f2c7553b35817f01381491a Mon Sep 17 00:00:00 2001
From: Chris Lalancette <clalance(a)redhat.com>
Date: Wed, 7 Apr 2010 11:23:11 -0400
Subject: [PATCH] Fix up formatting of remote protocol stuff.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
daemon/remote_dispatch_prototypes.h | 66 +++++++++++++++++-----------------
src/remote/remote_protocol.x | 1 +
2 files changed, 34 insertions(+), 33 deletions(-)
diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h
index 5ce2873..f6fcff8 100644
--- a/daemon/remote_dispatch_prototypes.h
+++ b/daemon/remote_dispatch_prototypes.h
@@ -282,6 +282,14 @@ static int remoteDispatchDomainGetVcpus(
remote_error *err,
remote_domain_get_vcpus_args *args,
remote_domain_get_vcpus_ret *ret);
+static int remoteDispatchDomainHasCurrentSnapshot(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_message_header *hdr,
+ remote_error *err,
+ remote_domain_has_current_snapshot_args *args,
+ remote_domain_has_current_snapshot_ret *ret);
static int remoteDispatchDomainHasManagedSaveImage(
struct qemud_server *server,
struct qemud_client *client,
@@ -458,6 +466,14 @@ static int remoteDispatchDomainResume(
remote_error *err,
remote_domain_resume_args *args,
void *ret);
+static int remoteDispatchDomainRevertToSnapshot(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_message_header *hdr,
+ remote_error *err,
+ remote_domain_revert_to_snapshot_args *args,
+ void *ret);
static int remoteDispatchDomainSave(
struct qemud_server *server,
struct qemud_client *client,
@@ -522,22 +538,30 @@ static int remoteDispatchDomainSnapshotCreateXml(
remote_error *err,
remote_domain_snapshot_create_xml_args *args,
remote_domain_snapshot_create_xml_ret *ret);
-static int remoteDispatchDomainSnapshotDumpXml(
+static int remoteDispatchDomainSnapshotCurrent(
struct qemud_server *server,
struct qemud_client *client,
virConnectPtr conn,
remote_message_header *hdr,
remote_error *err,
- remote_domain_snapshot_dump_xml_args *args,
- remote_domain_snapshot_dump_xml_ret *ret);
-static int remoteDispatchDomainSnapshotNum(
+ remote_domain_snapshot_current_args *args,
+ remote_domain_snapshot_current_ret *ret);
+static int remoteDispatchDomainSnapshotDelete(
struct qemud_server *server,
struct qemud_client *client,
virConnectPtr conn,
remote_message_header *hdr,
remote_error *err,
- remote_domain_snapshot_num_args *args,
- remote_domain_snapshot_num_ret *ret);
+ remote_domain_snapshot_delete_args *args,
+ void *ret);
+static int remoteDispatchDomainSnapshotDumpXml(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_message_header *hdr,
+ remote_error *err,
+ remote_domain_snapshot_dump_xml_args *args,
+ remote_domain_snapshot_dump_xml_ret *ret);
static int remoteDispatchDomainSnapshotListNames(
struct qemud_server *server,
struct qemud_client *client,
@@ -554,38 +578,14 @@ static int remoteDispatchDomainSnapshotLookupByName(
remote_error *err,
remote_domain_snapshot_lookup_by_name_args *args,
remote_domain_snapshot_lookup_by_name_ret *ret);
-static int remoteDispatchDomainHasCurrentSnapshot(
- struct qemud_server *server,
- struct qemud_client *client,
- virConnectPtr conn,
- remote_message_header *hdr,
- remote_error *err,
- remote_domain_has_current_snapshot_args *args,
- remote_domain_has_current_snapshot_ret *ret);
-static int remoteDispatchDomainSnapshotCurrent(
- struct qemud_server *server,
- struct qemud_client *client,
- virConnectPtr conn,
- remote_message_header *hdr,
- remote_error *err,
- remote_domain_snapshot_current_args *args,
- remote_domain_snapshot_current_ret *ret);
-static int remoteDispatchDomainRevertToSnapshot(
- struct qemud_server *server,
- struct qemud_client *client,
- virConnectPtr conn,
- remote_message_header *hdr,
- remote_error *err,
- remote_domain_revert_to_snapshot_args *args,
- void *ret);
-static int remoteDispatchDomainSnapshotDelete(
+static int remoteDispatchDomainSnapshotNum(
struct qemud_server *server,
struct qemud_client *client,
virConnectPtr conn,
remote_message_header *hdr,
remote_error *err,
- remote_domain_snapshot_delete_args *args,
- void *ret);
+ remote_domain_snapshot_num_args *args,
+ remote_domain_snapshot_num_ret *ret);
static int remoteDispatchDomainSuspend(
struct qemud_server *server,
struct qemud_client *client,
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 61b4bc1..9aa3a7e 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1967,6 +1967,7 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_NAMES = 188,
REMOTE_PROC_DOMAIN_SNAPSHOT_LOOKUP_BY_NAME = 189,
REMOTE_PROC_DOMAIN_HAS_CURRENT_SNAPSHOT = 190,
+
REMOTE_PROC_DOMAIN_SNAPSHOT_CURRENT = 191,
REMOTE_PROC_DOMAIN_REVERT_TO_SNAPSHOT = 192,
REMOTE_PROC_DOMAIN_SNAPSHOT_DELETE = 193
--
1.6.6.1
>From 1aad611e3a88940e275e795c0963ac26d7dcf350 Mon Sep 17 00:00:00 2001
From: Chris Lalancette <clalance(a)redhat.com>
Date: Thu, 8 Apr 2010 08:19:35 -0400
Subject: [PATCH] Fix messsage -> message.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
daemon/dispatch.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/dispatch.c b/daemon/dispatch.c
index f024900..e24acc1 100644
--- a/daemon/dispatch.c
+++ b/daemon/dispatch.c
@@ -348,7 +348,7 @@ remoteDispatchClientCall (struct qemud_server *server,
* @msg: the complete incoming message packet, with header already decoded
*
* This function gets called from qemud when it pulls a incoming
- * remote protocol messsage off the dispatch queue for processing.
+ * remote protocol message off the dispatch queue for processing.
*
* The @msg parameter must have had its header decoded already by
* calling remoteDecodeClientMessageHeader
--
1.6.6.1
>From a94484ad7b7dbd4a16f12ae86053b876a253c337 Mon Sep 17 00:00:00 2001
From: Chris Lalancette <clalance(a)redhat.com>
Date: Thu, 8 Apr 2010 08:47:02 -0400
Subject: [PATCH] Fix up a debug typo.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
daemon/dispatch.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/dispatch.c b/daemon/dispatch.c
index e24acc1..8f55eaa 100644
--- a/daemon/dispatch.c
+++ b/daemon/dispatch.c
@@ -363,7 +363,7 @@ remoteDispatchClientRequest (struct qemud_server *server,
int ret;
remote_error rerr;
- DEBUG("prog=%d ver=%d type=%d satus=%d serial=%d proc=%d",
+ DEBUG("prog=%d ver=%d type=%d status=%d serial=%d proc=%d",
msg->hdr.prog, msg->hdr.vers, msg->hdr.type,
msg->hdr.status, msg->hdr.serial, msg->hdr.proc);
--
1.6.6.1
>From 33857dfdeee444a7f5c7d856ebe5e64fb22610cd Mon Sep 17 00:00:00 2001
From: Chris Lalancette <clalance(a)redhat.com>
Date: Thu, 8 Apr 2010 10:29:46 -0400
Subject: [PATCH] Remove some debugging leftovers.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
src/remote/remote_driver.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 98cc7f9..eec3322 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -7421,15 +7421,12 @@ remoteDomainReadEventGraphics(virConnectPtr conn, XDR *xdr)
!(remoteAddr->node = strdup(msg.remote.node)))
goto no_memory;
- fprintf(stderr, "Got %d\n", msg.subject.subject_len);
if (VIR_ALLOC(subject) < 0)
goto no_memory;
if (VIR_ALLOC_N(subject->identities, msg.subject.subject_len) < 0)
goto no_memory;
subject->nidentity = msg.subject.subject_len;
for (i = 0 ; i < subject->nidentity ; i++) {
- fprintf(stderr, " %s=%s\n", msg.subject.subject_val[i].type,
- msg.subject.subject_val[i].name);
if (!(subject->identities[i].type = strdup(msg.subject.subject_val[i].type)) ||
!(subject->identities[i].name = strdup(msg.subject.subject_val[i].name)))
goto no_memory;
--
1.6.6.1
14 years, 7 months
[libvirt] small bug in spec file (0.8.0)
by Daniel Berteaud
Hi.
I've downloaded libvirt 0.8.0, and tried to re-build a rpm (on CentOS
5.4 x86_64), and found that there's a small bug in the spec file.
Line 608:
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.qemu
Should be:
rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.lxc
Without this modification, the package fails to build when LXC is
disabled or not abailable.
(Sorry, I really don't know GIT, and so, cannot provide a clean patch)
Regards, Daniel
--
Daniel Berteaud
FIREWALL-SERVICES SARL.
Société de Services en Logiciels Libres
Technopôle Montesquieu
33650 MARTILLAC
Tel : 05 56 64 15 32
Fax : 05 56 64 15 32
Mail: daniel(a)firewall-services.com
Web : http://www.firewall-services.com
14 years, 7 months
[libvirt] [PATCH v2] Consolidate interface related functions in interface.c
by Stefan Berger
Changes from v1 to v2:
- changed function name prefixes to 'iface' from previous 'Iface'
I am consolidating network interface related functions used in nwfilter
and macvtap code in utils/interface.c. All function names are prefixed
with 'Iface'. The following functions are now available through
interface.h:
int ifaceCtrl(const char *name, bool up);
int ifaceUp(const char *name);
int ifaceDown(const char *name);
int ifaceCheck(bool reportError, const char *ifname,
const unsigned char *macaddr, int ifindex);
int ifaceGetIndex(bool reportError, const char *ifname, int *ifindex);
I added 'int ifindex' as parameter to ifaceCheck to the original
function and modified the code accordingly.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/Makefile.am | 1
src/libvirt_private.syms | 4
src/nwfilter/nwfilter_gentech_driver.c | 120 -----------------
src/nwfilter/nwfilter_gentech_driver.h | 2
src/nwfilter/nwfilter_learnipaddr.c | 3
src/util/interface.c | 224 +++++++++++++++++++++++++++++++++
src/util/interface.h | 31 ++++
src/util/macvtap.c | 112 ----------------
8 files changed, 269 insertions(+), 228 deletions(-)
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
@@ -23,16 +23,11 @@
#include <config.h>
-#include <stdint.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <linux/if.h>
-
#include "internal.h"
#include "memory.h"
#include "logging.h"
-#include "datatypes.h"
+#include "interface.h"
#include "domain_conf.h"
#include "virterror_internal.h"
#include "nwfilter_gentech_driver.h"
@@ -792,117 +787,6 @@ _virNWFilterInstantiateFilter(virConnect
}
-// FIXME: move chgIfFlags, ifUp, checkIf into common file & share w/ macvtap.c
-
-/*
- * chgIfFlags: Change flags on an interface
- * @ifname : name of the interface
- * @flagclear : the flags to clear
- * @flagset : the flags to set
- *
- * The new flags of the interface will be calculated as
- * flagmask = (~0 ^ flagclear)
- * newflags = (curflags & flagmask) | flagset;
- *
- * Returns 0 on success, errno on failure.
- */
-static int chgIfFlags(const char *ifname, short flagclear, short flagset) {
- struct ifreq ifr;
- int rc = 0;
- int flags;
- short flagmask = (~0 ^ flagclear);
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifr.ifr_name,
- ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
- rc = ENODEV;
- goto err_exit;
- }
-
- if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
- rc = errno;
- goto err_exit;
- }
-
- flags = (ifr.ifr_flags & flagmask) | flagset;
-
- if (ifr.ifr_flags != flags) {
- ifr.ifr_flags = flags;
-
- if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
- rc = errno;
- }
-
-err_exit:
- close(fd);
- return rc;
-}
-
-/*
- * ifUp
- * @name: name of the interface
- * @up: 1 for up, 0 for down
- *
- * Function to control if an interface is activated (up, 1) or not (down, 0)
- *
- * Returns 0 in case of success or an errno code in case of failure.
- */
-static int
-ifUp(const char *name, int up)
-{
- return chgIfFlags(name,
- (up) ? 0 : IFF_UP,
- (up) ? IFF_UP : 0);
-}
-
-
-/**
- * checkIf
- *
- * @ifname: Name of the interface
- * @macaddr: expected MAC address of the interface
- *
- * FIXME: the interface's index is another good parameter to check
- *
- * Determine whether a given interface is still available. If so,
- * it must have the given MAC address.
- *
- * Returns an error code ENODEV in case the interface does not exist
- * anymore or its MAC address is different, 0 otherwise.
- */
-int
-checkIf(const char *ifname, const unsigned char *macaddr)
-{
- struct ifreq ifr;
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
- int rc = 0;
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifr.ifr_name,
- ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
- rc = ENODEV;
- goto err_exit;
- }
-
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
- rc = errno;
- goto err_exit;
- }
-
- if (memcmp(&ifr.ifr_hwaddr.sa_data, macaddr, 6) != 0)
- rc = ENODEV;
-
- err_exit:
- close(fd);
- return rc;
-}
-
-
int
virNWFilterInstantiateFilterLate(virConnectPtr conn,
const char *ifname,
@@ -926,7 +810,7 @@ virNWFilterInstantiateFilterLate(virConn
driver);
if (rc) {
//something went wrong... 'DOWN' the interface
- if (ifUp(ifname ,0)) {
+ if (ifaceDown(ifname)) {
// assuming interface disappeared...
_virNWFilterTeardownFilter(ifname);
}
Index: libvirt-acl/src/util/interface.c
===================================================================
--- /dev/null
+++ libvirt-acl/src/util/interface.c
@@ -0,0 +1,226 @@
+/*
+ * interface.c: interface support functions
+ *
+ * Copyright (C) 2010 IBM Corp.
+ * Copyright (C) 2010 Stefan Berger
+ *
+ * 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.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * chgIfaceFlags originated from bridge.c
+ *
+ * Author: Stefan Berger <stefanb(a)us.ibm.com>
+ */
+
+#include <config.h>
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <linux/if.h>
+
+#include "internal.h"
+
+#include "util.h"
+#include "interface.h"
+#include "virterror_internal.h"
+
+#define ifaceError(code, ...) \
+ virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__, \
+ __FUNCTION__, __LINE__, __VA_ARGS__)
+
+/*
+ * chgIfFlags: Change flags on an interface
+ *
+ * @ifname : name of the interface
+ * @flagclear : the flags to clear
+ * @flagset : the flags to set
+ *
+ * The new flags of the interface will be calculated as
+ * flagmask = (~0 ^ flagclear)
+ * newflags = (curflags & flagmask) | flagset;
+ *
+ * Returns 0 on success, errno on failure.
+ */
+static int chgIfaceFlags(const char *ifname, short flagclear, short flagset) {
+ struct ifreq ifr;
+ int rc = 0;
+ int flags;
+ short flagmask = (~0 ^ flagclear);
+ int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+
+ if (fd < 0)
+ return errno;
+
+ if (virStrncpy(ifr.ifr_name,
+ ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
+ rc = ENODEV;
+ goto err_exit;
+ }
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ rc = errno;
+ goto err_exit;
+ }
+
+ flags = (ifr.ifr_flags & flagmask) | flagset;
+
+ if (ifr.ifr_flags != flags) {
+ ifr.ifr_flags = flags;
+
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
+ rc = errno;
+ }
+
+err_exit:
+ close(fd);
+ return rc;
+}
+
+
+/*
+ * ifaceCtrl
+ * @name: name of the interface
+ * @up: true (1) for up, false (0) for down
+ *
+ * Function to control if an interface is activated (up, 1) or not (down, 0)
+ *
+ * Returns 0 in case of success or an errno code in case of failure.
+ */
+int
+ifaceCtrl(const char *name, bool up)
+{
+ return chgIfaceFlags(name,
+ (up) ? 0 : IFF_UP,
+ (up) ? IFF_UP : 0);
+}
+
+
+/**
+ * ifaceCheck
+ *
+ * @reportError: whether to report errors or keep silent
+ * @ifname: Name of the interface
+ * @macaddr: expected MAC address of the interface; not checked if NULL
+ * @ifindex: expected index of the interface; not checked if '-1'
+ *
+ * Determine whether a given interface is still available. If so,
+ * it must have the given MAC address and if an interface index is
+ * passed, it must also match the interface index.
+ *
+ * Returns 0 on success, an error code on failure.
+ * ENODEV : if interface with given name does not exist or its interface
+ * index is different than the one passed
+ * EINVAL : if interface name is invalid (too long)
+ */
+int
+ifaceCheck(bool reportError, const char *ifname,
+ const unsigned char *macaddr, int ifindex)
+{
+ struct ifreq ifr;
+ int fd = -1;
+ int rc = 0;
+ int idx;
+
+ if (macaddr != NULL) {
+ fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ return errno;
+
+ if (virStrncpy(ifr.ifr_name,
+ ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid interface name %s"),
+ ifname);
+ rc = EINVAL;
+ goto err_exit;
+ }
+
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("coud not get MAC address of interface %s"),
+ ifname);
+ rc = errno;
+ goto err_exit;
+ }
+
+ if (memcmp(&ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN) != 0) {
+ rc = ENODEV;
+ goto err_exit;
+ }
+ }
+
+ if (ifindex != -1) {
+ rc = ifaceGetIndex(reportError, ifname, &idx);
+ if (rc == 0 && idx != ifindex)
+ rc = ENODEV;
+ }
+
+ err_exit:
+ if (fd >= 0)
+ close(fd);
+
+ return rc;
+}
+
+
+/**
+ * ifaceGetIndex
+ *
+ * @reportError: whether to report errors or keep silent
+ * @ifname : Name of the interface whose index is to be found
+ * @ifindex: Pointer to int where the index will be written into
+ *
+ * Get the index of an interface given its name.
+ *
+ * Returns 0 on success, an error code on failure.
+ * ENODEV : if interface with given name does not exist
+ * EINVAL : if interface name is invalid (too long)
+ */
+int
+ifaceGetIndex(bool reportError, const char *ifname, int *ifindex)
+{
+ int rc = 0;
+ struct ifreq ifreq;
+ int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+
+ if (fd < 0)
+ return errno;
+
+ if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
+ sizeof(ifreq.ifr_name)) == NULL) {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid interface name %s"),
+ ifname);
+ rc = EINVAL;
+ goto err_exit;
+ }
+
+ if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0)
+ *ifindex = ifreq.ifr_ifindex;
+ else {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("interface %s does not exist"),
+ ifname);
+ rc = ENODEV;
+ }
+
+err_exit:
+ close(fd);
+
+ return rc;
+}
Index: libvirt-acl/src/util/interface.h
===================================================================
--- /dev/null
+++ libvirt-acl/src/util/interface.h
@@ -0,0 +1,31 @@
+/*
+ * interface.h: interface helper APIs for libvirt
+ *
+ * Copyright (C) 2010 IBM Corporation, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Stefan Berger <stefanb(a)us.ibm.com>
+ */
+#ifndef __VIR_INTERFACE_H__
+# define __VIR_INTERFACE_H__
+
+#include "datatypes.h"
+
+int ifaceCtrl(const char *name, bool up);
+
+static inline int ifaceUp(const char *name) {
+ return ifaceCtrl(name, true);
+}
+
+static inline int ifaceDown(const char *name) {
+ return ifaceCtrl(name, false);
+}
+
+int ifaceCheck(bool reportError, const char *ifname,
+ const unsigned char *macaddr, int ifindex);
+
+int ifaceGetIndex(bool reportError, const char *ifname, int *ifindex);
+
+#endif /* __VIR_INTERFACE_H__ */
+
Index: libvirt-acl/src/Makefile.am
===================================================================
--- libvirt-acl.orig/src/Makefile.am
+++ libvirt-acl/src/Makefile.am
@@ -67,6 +67,7 @@ UTIL_SOURCES = \
util/processinfo.c util/processinfo.h \
util/hostusb.c util/hostusb.h \
util/network.c util/network.h \
+ util/interface.c util/interface.h \
util/qparams.c util/qparams.h \
util/stats_linux.c util/stats_linux.h \
util/storage_file.c util/storage_file.h \
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -681,6 +681,10 @@ virFileWaitForDevices;
virFileMatchesNameSuffix;
virArgvToString;
+# interface.h
+ifaceCtrl;
+ifaceCheck;
+ifaceGetIndex;
# usb.h
usbGetDevice;
Index: libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_learnipaddr.c
+++ libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c
@@ -43,6 +43,7 @@
#include "memory.h"
#include "logging.h"
#include "datatypes.h"
+#include "interface.h"
#include "virterror_internal.h"
#include "threads.h"
#include "conf/nwfilter_params.h"
@@ -339,7 +340,7 @@ learnIPAddressThread(void *arg)
break;
}
/* listening on linkdev, check whether VM's dev is still there */
- if (checkIf(req->ifname, req->macaddr)) {
+ if (ifaceCheck(false, req->ifname, req->macaddr, -1)) {
req->status = ENODEV;
break;
}
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -44,6 +44,7 @@
# include "util.h"
# include "memory.h"
# include "macvtap.h"
+# include "interface.h"
# include "conf/domain_conf.h"
# include "virterror_internal.h"
@@ -193,109 +194,6 @@ nlAppend(struct nlmsghdr *nlm, int totle
static int
-getIfIndex(bool reportError,
- const char *ifname,
- int *idx)
-{
- int rc = 0;
- struct ifreq ifreq;
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
- sizeof(ifreq.ifr_name)) == NULL) {
- if (reportError)
- macvtapError(VIR_ERR_INTERNAL_ERROR,
- _("invalid interface name %s"),
- ifname);
- rc = EINVAL;
- goto err_exit;
- }
- if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0)
- *idx = ifreq.ifr_ifindex;
- else {
- if (reportError)
- macvtapError(VIR_ERR_INTERNAL_ERROR,
- _("interface %s does not exist"),
- ifname);
- rc = ENODEV;
- }
-
-err_exit:
- close(fd);
-
- return rc;
-}
-
-
-/*
- * chgIfFlags: Change flags on an interface
- * @ifname : name of the interface
- * @flagclear : the flags to clear
- * @flagset : the flags to set
- *
- * The new flags of the interface will be calculated as
- * flagmask = (~0 ^ flagclear)
- * newflags = (curflags & flagmask) | flagset;
- *
- * Returns 0 on success, errno on failure.
- */
-static int chgIfFlags(const char *ifname, short flagclear, short flagset) {
- struct ifreq ifr;
- int rc = 0;
- int flags;
- short flagmask = (~0 ^ flagclear);
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifr.ifr_name,
- ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
- rc = ENODEV;
- goto err_exit;
- }
-
- if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
- rc = errno;
- goto err_exit;
- }
-
- flags = (ifr.ifr_flags & flagmask) | flagset;
-
- if (ifr.ifr_flags != flags) {
- ifr.ifr_flags = flags;
-
- if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
- rc = errno;
- }
-
-err_exit:
- close(fd);
- return rc;
-}
-
-/*
- * ifUp
- * @name: name of the interface
- * @up: 1 for up, 0 for down
- *
- * Function to control if an interface is activated (up, 1) or not (down, 0)
- *
- * Returns 0 in case of success or an errno code in case of failure.
- */
-static int
-ifUp(const char *name, int up)
-{
- return chgIfFlags(name,
- (up) ? 0 : IFF_UP,
- (up) ? IFF_UP : 0);
-}
-
-
-static int
link_add(const char *type,
const unsigned char *macaddress, int macaddrsize,
const char *ifname,
@@ -314,7 +212,7 @@ link_add(const char *type,
char *recvbuf = NULL;
int recvbuflen;
- if (getIfIndex(true, srcdev, &ifindex) != 0)
+ if (ifaceGetIndex(true, srcdev, &ifindex) != 0)
return -1;
*retry = 0;
@@ -708,7 +606,7 @@ openMacvtapTap(const char *tgifname,
*res_ifname = NULL;
if (tgifname) {
- if(getIfIndex(false, tgifname, &ifindex) == 0) {
+ if(ifaceGetIndex(false, tgifname, &ifindex) == 0) {
if (STRPREFIX(tgifname,
MACVTAP_NAME_PREFIX)) {
goto create_name;
@@ -727,7 +625,7 @@ create_name:
retries = 5;
for (c = 0; c < 8192; c++) {
snprintf(ifname, sizeof(ifname), MACVTAP_NAME_PATTERN, c);
- if (getIfIndex(false, ifname, &ifindex) == ENODEV) {
+ if (ifaceGetIndex(false, ifname, &ifindex) == ENODEV) {
rc = link_add(type, macaddress, 6, ifname, linkdev,
macvtapMode, &do_retry);
if (rc == 0)
@@ -741,7 +639,7 @@ create_name:
cr_ifname = ifname;
}
- rc = ifUp(cr_ifname, 1);
+ rc = ifaceUp(cr_ifname);
if (rc != 0) {
virReportSystemError(errno,
_("cannot 'up' interface %s -- another "
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.h
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
@@ -63,6 +63,4 @@ void virNWFilterDomainFWUpdateCB(void *p
const char *name ATTRIBUTE_UNUSED,
void *data);
-int checkIf(const char *ifname, const unsigned char *macaddr);
-
#endif
14 years, 7 months
[libvirt] [PATCH] build: include usleep gnulib module
by Eric Blake
Without this module, attempts to sleep for 1 or more seconds
on mingw instead become a no-delay no-op.
* bootstrap.conf (gnulib_modules): Add usleep.
---
bootstrap.conf | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index ac2f8e6..d55dc71 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -56,6 +56,7 @@ strsep
sys_stat
time_r
useless-if-before-free
+usleep
vasprintf
verify
vc-list-files
--
1.6.6.1
14 years, 7 months
[libvirt] [PATCH] Fix nodeinfotest on NUMA machines
by Daniel P. Berrange
The nodeinfotest was reliant on the host NUMA topology, but all
the test data files assumed 1 single NUMA node. This test thus
failed on any NUMA machine with > 1 node
* tests/nodeinfotest.c: Hardcode 1 single numa node
---
tests/nodeinfotest.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 768fd4d..9aeb459 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -46,6 +46,11 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
}
fclose(cpuinfo);
+ /* 'nodes' is filled using libnuma.so from current machine
+ * topology, which makes it unsuitable for the test suite
+ * so blank it to a predictable value */
+ nodeinfo.nodes = 1;
+
snprintf(actualData, MAX_FILE,
"CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n",
nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes, nodeinfo.cores);
--
1.6.6.1
14 years, 7 months
Re: [libvirt] Domain not stable while created...
by Sankamesh
Thanks Mr.Stefan
I was getting some errors when i ran like xm create
libvirt-ttylinux.conf
----------------------------------------------------------------------------------------------------------------------------------------
Mounting root filesystem.
mount: could not find filesystem '/dev/root'
Setting up other filesystems.
Setting up new root fs
setuproot: moving /dev failed: No such file or directory
no fstab.sys, mounting internal defaults
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
switchroot: mount failed: No such file or directory
------------------------------------------------------------------------
So this time as sure that there is some problem with my configuration
file. I googled , then I found some solution to change the ramdisk
option by some command mentioned in the following link.
http://www.virtuatopia.com/index.php/A_Xen_Guest_OS_fails_to_boot_with_a_....
But after doing this when I restart my process by "xm create..." and "virsh console..." , I get
--------------------------------------------------------------
Creating root device.
Mounting root filesystem.
ext3: No journal on filesystem on sda1
mount: error mounting /dev/root on /sysroot as ext3: Invalid argument
Setting up other filesystems.
Setting up new root fs
setuproot: moving /dev failed: No such file or directory
no fstab.sys, mounting internal defaults
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
--------------------------------------------------------------------------------------------------------------------------
Similary when I try other way by changing the ramdisk option in
ttylinux.xml file and use "virsh -c xen:/// create
libvirt-ttylinux.xml" , then virsh console domainname,
I get some kernel error
--------------------------------------------------------------------------------------------------
..............................................................
Initalizing network drop monitor service
Freeing unused kernel memory: 176k freed
Write protecting the kernel read-only data: 390k
Registering block device major 8
USB Universal Host Controller Interface driver v3.0
SCSI subsystem initialized
device-mapper: uevent: version 1.0.3
device-mapper: ioctl: 4.11.5-ioctl (2007-12-12) initialised: dm-devel(a)redhat.com
device-mapper: dm-raid45: initialized v0.2594l
netfront: Initialising virtual ethernet driver.
netfront: device eth0 has flipping receive path.
ext3: No journal on filesystem on sda1
Kernel panic - not syncing: Attempted to kill init!
--------------------------------------------------------------------------------------------------
So , There is something terribly wrong with my kernel options in the
configuration file in both cases, that doesn't allow the image to boot.
Can you identify the nature of the error?
Can You help me out in someway?
Thanks
________________________________
Sankamesh <sankamesh_rb(a)yahoo.co.in> wrote on
04/12/2010 04:29:36 AM:
>
> Thanks Mr. Stefan
> Will that crash mainly be due to the kernel ?
Since am not sure
> about that,else I should try with different image.
> When I use via a config file using "xm create
libvirt-ttylinux.conf
> ", then the domain runs stable....
>
> But when I use the virsh -c xen:/// define libvirt-ttylinux.xml"
and
> "virsh start ttyimage, it crashes after sometime.
>
> The ibvirt-ttylinux.conf file ::
>
> --------------------------------------------------------------------------------------------------------------------------------
> kernel = "/boot/vmlinuz-2.6.18-164.2.1.el5xen"
> ramdisk= "/boot/initrd-2.6.18-164.2.1.el5xen.img"
> memory = 64
Maybe try to give it some more memory...
Otherwise I can just guess as to why there is such
a difference in this vm running stable. Are there any significant difference
between an 'xm list' after the 'xm create' and an
'xm list' after the 'virsh -c ... define'? Did you ever try 'xm new <vm
config file name>' followed
by an 'xm start <domainname>'?
> name = "ttylinux"
> disk = ['file:/usr/local/ttylinux-xen-libvirt/ttylinux-xen.img,sda1,w']
> root = "/dev/sda1 ro"
> vif = ['']
> --------------------------------------------------------------------------------------------------------------------------------
>
> I give the same Xen kernel parameter here in
xml file, and use virsh
> to create domain
>
> ---------------------------------------------------------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
> <domain type='xen'>
> <name>ttyimage</name>
> <os>
> <type>linux</type>
> <kernel>/boot/vmlinuz-2.6.18-164.2.1.el5xen</kernel>
> <initrd>/boot/initrd-2.6.18-164.2.1.el5xen.img</initrd>
> </os>
> <memory>65536</memory>
> <vcpu>1</vcpu>
> <on_poweroff>destroy</on_poweroff>
> <on_reboot>restart</on_reboot>
> <on_crash>destroy</on_crash>
> <devices>
> <graphics type='vnc' port='5900'/>
> <disk type='file'>
> <source file='/usr/local/ttylinux-xen-libvirt/ttylinux-xen.img'
/>
> <target dev='sda1' />
> </disk>
> <interface type='bridge'>
> <source bridge='virbr0'
/>
> <mac address='00:1d:60:ec:ae:1c'
/>
> <target dev='testnimb-0'
/>
> </interface>
> </devices>
> </domain>
> ---------------------------------------------------------------------------------------------------------------------------------------
> My Boot grub file data::
>
> --------------------------------------------------------------------------------------------------------------------------------------
> title Scientific Linux (2.6.18-164.2.1.el5xen)
> root (hd0,0)
> kernel /xen.gz-2.6.18-164.2.1.el5
> module /vmlinuz-2.6.18-164.2.1.el5xen ro root=LABEL=/1
rhgb quiet
> module /initrd-2.6.18-164.2.1.el5xen.img
> --------------------------------------------------------------------------------------------------------------------------------------
>
>
> Why is this difference between the xm (when i destroy the
> image,domain is also destroyed) and virsh (domain is not destroyed
> while destroying the image) .
xm new <vm definition filename> -> xm start
<domainname> -> xm destroy <domainname> -> xm delete
<domainname>
is similar to
virsh ... define -> virsh start <domainname>
-> virsh destroy <domainname> -> virsh undefine <domainname>
Stefan
>
> I doubt that am making some mistake with the xml file .... Is that
true?
>
> Kindly give some suggestions
>
> Thanks
>
>
> libvir-list-bounces(a)redhat.com wrote on 04/10/2010
09:47:17 AM:
>
>
> > libvir-list
> >
> > Hello,
> >
> > Thanks Alex
> >
> > I created a domain using "virsh -c xen:/// define
libvirt-ttylinux.xml" and
> > "virsh start ttyimage" for a simple ttyimage.
> >
> > Problem I face is that the image shutsdown immedialtely once
virsh
> > start guest is typed.
> > I checked the Xend Logs
> >
> ----------------------------------------------------------------------------------------------------------
> > ---[2010-04-11 07:08:02 xend 3155] DEBUG (DevController:116)
> > DevController: writing {'frontend-id': '6', 'domain': 'ttyimage',
> [...]
> > [2010-04-11 07:08:02 xend 3155] DEBUG (vfbif:11) Spawn: ['/usr/lib/
> > xen/bin/qemu-dm', '-M', 'xenpv', '-d', '6', '-domain-name',
> > 'ttyimage', '-vnc', '127.0.0.1:0', '-vncunused', '-k', 'en-us']
> > [2010-04-11 07:08:02 xend.XendDomainInfo 3155] DEBUG
> > (XendDomainInfo:992) Storing VM details: {'shadow_memory': '0',
> > 'uuid': 'd5e916b0-bc2d-01f9-8156-4808c754f67a', 'on_reboot':
> > 'restart', 'start_time': '1270937282.29', 'on_poweroff': 'destroy',
> > 'name': 'ttyimage', 'xend/restart_count': '0', 'vcpus': '1',
> > 'vcpu_avail': '1', 'memory': '64', 'on_crash': 'destroy', 'image':
> > '(linux (kernel /boot/vmlinuz-2.6.18-164.2.1.el5xen))', 'maxmem':
'64'}
> > [2010-04-11 07:08:02 xend.XendDomainInfo 3155] DEBUG
> > (XendDomainInfo:1027) Storing domain details: {'console/ring-ref':
> > '65674', 'console/port': '2', 'name': 'ttyimage', 'console/limit':
> > '1048576', 'vm': '/vm/d5e916b0-bc2d-01f9-8156-4808c754f67a',
> > 'domid': '6', 'cpu/0/availability': 'online', 'memory/target':
> > '65536', 'store/ring-ref': '65675', 'store/port': '1'}
> > [2010-04-11 07:08:02 xend.XendDomainInfo 3155] DEBUG
> > (XendDomainInfo:1249) XendDomainInfo.handleShutdownWatch
> > [2010-04-11 07:08:02 xend 3155] DEBUG (DevController:158) Waiting
> > for devices vif.
> > [2010-04-11 07:08:02 xend 3155] DEBUG (DevController:164) Waiting
for 0.
> > [2010-04-11 07:08:02 xend 3155] DEBUG (DevController:509)
> > hotplugStatusCallback /local/domain/0/backend/vif/6/0/hotplug-status.
> > [2010-04-11 07:08:51 xend 3155] INFO (XendDomain:387) Domain
> > ttyimage (6) unpaused.
> > [2010-04-11 07:08:54 xend.XendDomainInfo 3155] WARNING
> > (XendDomainInfo:1177) Domain has crashed: name=ttyimage id=6.
>
> You domain crashed here... Is the VM image and kernel in that
image
> known to work?
>
> Regards,
> Stefan
>
> Send free SMS to your Friends on Mobile from your Yahoo! Messenger.
> Download Now! http://messenger.yahoo.com/download.php
Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php
14 years, 7 months
[libvirt] [PATCH] build: fix syntax-check problems
by Eric Blake
* .x-sc_prohibit_gettext_noop: Add new exemption.
* .x-sc_prohibit_test_minus_ao: Likewise.
* Makefile.am (EXTRA_DIST): Distribute new files.
* .gitignore: Ignore built file.
---
Pushing as obvious, since otherwise 'make syntax-check' fails,
and with my name prominently listed in the failure message,
even though I wasn't the one that touched docs/news.html.in.
It's interesting that documenting the commit logs for what we
fixed introduces new instances of the broken semantics. :)
.gitignore | 1 +
.x-sc_prohibit_gettext_noop | 2 ++
.x-sc_prohibit_test_minus_ao | 1 +
Makefile.am | 2 ++
4 files changed, 6 insertions(+), 0 deletions(-)
create mode 100644 .x-sc_prohibit_gettext_noop
create mode 100644 .x-sc_prohibit_test_minus_ao
diff --git a/.gitignore b/.gitignore
index a638e0d..a7466fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,4 +44,5 @@ stamp-h
stamp-h.in
stamp-h1
tests/*.log
+tests/nwfilterxml2xmltest
update.log
diff --git a/.x-sc_prohibit_gettext_noop b/.x-sc_prohibit_gettext_noop
new file mode 100644
index 0000000..c40474e
--- /dev/null
+++ b/.x-sc_prohibit_gettext_noop
@@ -0,0 +1,2 @@
+ChangeLog*
+docs/news.html.in
diff --git a/.x-sc_prohibit_test_minus_ao b/.x-sc_prohibit_test_minus_ao
new file mode 100644
index 0000000..3939616
--- /dev/null
+++ b/.x-sc_prohibit_test_minus_ao
@@ -0,0 +1 @@
+docs/news.html.in
diff --git a/Makefile.am b/Makefile.am
index dd334b5..286b13b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,12 +27,14 @@ EXTRA_DIST = \
.x-sc_prohibit_asprintf \
.x-sc_prohibit_gethostby \
.x-sc_prohibit_gethostname \
+ .x-sc_prohibit_gettext_noop \
.x-sc_prohibit_have_config_h \
.x-sc_prohibit_HAVE_MBRTOWC \
.x-sc_prohibit_nonreentrant \
.x-sc_prohibit_strcmp \
.x-sc_prohibit_strcmp_and_strncmp \
.x-sc_prohibit_strncpy \
+ .x-sc_prohibit_test_minus_ao \
.x-sc_prohibit_VIR_ERR_NO_MEMORY \
.x-sc_require_config_h \
.x-sc_require_config_h_first \
--
1.6.6.1
14 years, 7 months
[libvirt] [PATCH] Consolidate interface related functions in interface.c
by Stefan Berger
I am consolidating network interface related functions used in nwfilter
and macvtap code in utils/interface.c. All function names are prefixed
with 'Iface'. The following functions are now available through
interface.h:
int IfaceCtrl(const char *name, bool up);
int IfaceUp(const char *name);
int IfaceDown(const char *name);
int IfaceCheck(bool reportError, const char *ifname,
const unsigned char *macaddr, int ifindex);
int IfaceGetIndex(bool reportError, const char *ifname, int *ifindex);
I added 'int ifindex' as parameter to IfaceCheck to the original
function and modified the code accordingly.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/Makefile.am | 1
src/libvirt_private.syms | 4
src/nwfilter/nwfilter_gentech_driver.c | 120 -----------------
src/nwfilter/nwfilter_gentech_driver.h | 2
src/nwfilter/nwfilter_learnipaddr.c | 3
src/util/interface.c | 224 +++++++++++++++++++++++++++++++++
src/util/interface.h | 31 ++++
src/util/macvtap.c | 112 ----------------
8 files changed, 269 insertions(+), 228 deletions(-)
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
@@ -23,16 +23,11 @@
#include <config.h>
-#include <stdint.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <linux/if.h>
-
#include "internal.h"
#include "memory.h"
#include "logging.h"
-#include "datatypes.h"
+#include "interface.h"
#include "domain_conf.h"
#include "virterror_internal.h"
#include "nwfilter_gentech_driver.h"
@@ -792,117 +787,6 @@ _virNWFilterInstantiateFilter(virConnect
}
-// FIXME: move chgIfFlags, ifUp, checkIf into common file & share w/ macvtap.c
-
-/*
- * chgIfFlags: Change flags on an interface
- * @ifname : name of the interface
- * @flagclear : the flags to clear
- * @flagset : the flags to set
- *
- * The new flags of the interface will be calculated as
- * flagmask = (~0 ^ flagclear)
- * newflags = (curflags & flagmask) | flagset;
- *
- * Returns 0 on success, errno on failure.
- */
-static int chgIfFlags(const char *ifname, short flagclear, short flagset) {
- struct ifreq ifr;
- int rc = 0;
- int flags;
- short flagmask = (~0 ^ flagclear);
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifr.ifr_name,
- ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
- rc = ENODEV;
- goto err_exit;
- }
-
- if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
- rc = errno;
- goto err_exit;
- }
-
- flags = (ifr.ifr_flags & flagmask) | flagset;
-
- if (ifr.ifr_flags != flags) {
- ifr.ifr_flags = flags;
-
- if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
- rc = errno;
- }
-
-err_exit:
- close(fd);
- return rc;
-}
-
-/*
- * ifUp
- * @name: name of the interface
- * @up: 1 for up, 0 for down
- *
- * Function to control if an interface is activated (up, 1) or not (down, 0)
- *
- * Returns 0 in case of success or an errno code in case of failure.
- */
-static int
-ifUp(const char *name, int up)
-{
- return chgIfFlags(name,
- (up) ? 0 : IFF_UP,
- (up) ? IFF_UP : 0);
-}
-
-
-/**
- * checkIf
- *
- * @ifname: Name of the interface
- * @macaddr: expected MAC address of the interface
- *
- * FIXME: the interface's index is another good parameter to check
- *
- * Determine whether a given interface is still available. If so,
- * it must have the given MAC address.
- *
- * Returns an error code ENODEV in case the interface does not exist
- * anymore or its MAC address is different, 0 otherwise.
- */
-int
-checkIf(const char *ifname, const unsigned char *macaddr)
-{
- struct ifreq ifr;
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
- int rc = 0;
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifr.ifr_name,
- ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
- rc = ENODEV;
- goto err_exit;
- }
-
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
- rc = errno;
- goto err_exit;
- }
-
- if (memcmp(&ifr.ifr_hwaddr.sa_data, macaddr, 6) != 0)
- rc = ENODEV;
-
- err_exit:
- close(fd);
- return rc;
-}
-
-
int
virNWFilterInstantiateFilterLate(virConnectPtr conn,
const char *ifname,
@@ -926,7 +810,7 @@ virNWFilterInstantiateFilterLate(virConn
driver);
if (rc) {
//something went wrong... 'DOWN' the interface
- if (ifUp(ifname ,0)) {
+ if (IfaceDown(ifname)) {
// assuming interface disappeared...
_virNWFilterTeardownFilter(ifname);
}
Index: libvirt-acl/src/util/interface.c
===================================================================
--- /dev/null
+++ libvirt-acl/src/util/interface.c
@@ -0,0 +1,226 @@
+/*
+ * interface.c: interface support functions
+ *
+ * Copyright (C) 2010 IBM Corp.
+ * Copyright (C) 2010 Stefan Berger
+ *
+ * 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.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * chgIfaceFlags originated from bridge.c
+ *
+ * Author: Stefan Berger <stefanb(a)us.ibm.com>
+ */
+
+#include <config.h>
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <linux/if.h>
+
+#include "internal.h"
+
+#include "util.h"
+#include "interface.h"
+#include "virterror_internal.h"
+
+#define ifaceError(code, ...) \
+ virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__, \
+ __FUNCTION__, __LINE__, __VA_ARGS__)
+
+/*
+ * chgIfFlags: Change flags on an interface
+ *
+ * @ifname : name of the interface
+ * @flagclear : the flags to clear
+ * @flagset : the flags to set
+ *
+ * The new flags of the interface will be calculated as
+ * flagmask = (~0 ^ flagclear)
+ * newflags = (curflags & flagmask) | flagset;
+ *
+ * Returns 0 on success, errno on failure.
+ */
+static int chgIfaceFlags(const char *ifname, short flagclear, short flagset) {
+ struct ifreq ifr;
+ int rc = 0;
+ int flags;
+ short flagmask = (~0 ^ flagclear);
+ int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+
+ if (fd < 0)
+ return errno;
+
+ if (virStrncpy(ifr.ifr_name,
+ ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
+ rc = ENODEV;
+ goto err_exit;
+ }
+
+ if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
+ rc = errno;
+ goto err_exit;
+ }
+
+ flags = (ifr.ifr_flags & flagmask) | flagset;
+
+ if (ifr.ifr_flags != flags) {
+ ifr.ifr_flags = flags;
+
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
+ rc = errno;
+ }
+
+err_exit:
+ close(fd);
+ return rc;
+}
+
+
+/*
+ * IfaceCtrl
+ * @name: name of the interface
+ * @up: true (1) for up, false (0) for down
+ *
+ * Function to control if an interface is activated (up, 1) or not (down, 0)
+ *
+ * Returns 0 in case of success or an errno code in case of failure.
+ */
+int
+IfaceCtrl(const char *name, bool up)
+{
+ return chgIfaceFlags(name,
+ (up) ? 0 : IFF_UP,
+ (up) ? IFF_UP : 0);
+}
+
+
+/**
+ * IfaceCheck
+ *
+ * @reportError: whether to report errors or keep silent
+ * @ifname: Name of the interface
+ * @macaddr: expected MAC address of the interface; not checked if NULL
+ * @ifindex: expected index of the interface; not checked if '-1'
+ *
+ * Determine whether a given interface is still available. If so,
+ * it must have the given MAC address and if an interface index is
+ * passed, it must also match the interface index.
+ *
+ * Returns 0 on success, an error code on failure.
+ * ENODEV : if interface with given name does not exist or its interface
+ * index is different than the one passed
+ * EINVAL : if interface name is invalid (too long)
+ */
+int
+IfaceCheck(bool reportError, const char *ifname,
+ const unsigned char *macaddr, int ifindex)
+{
+ struct ifreq ifr;
+ int fd = -1;
+ int rc = 0;
+ int idx;
+
+ if (macaddr != NULL) {
+ fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ return errno;
+
+ if (virStrncpy(ifr.ifr_name,
+ ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid interface name %s"),
+ ifname);
+ rc = EINVAL;
+ goto err_exit;
+ }
+
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("coud not get MAC address of interface %s"),
+ ifname);
+ rc = errno;
+ goto err_exit;
+ }
+
+ if (memcmp(&ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN) != 0) {
+ rc = ENODEV;
+ goto err_exit;
+ }
+ }
+
+ if (ifindex != -1) {
+ rc = IfaceGetIndex(reportError, ifname, &idx);
+ if (rc == 0 && idx != ifindex)
+ rc = ENODEV;
+ }
+
+ err_exit:
+ if (fd >= 0)
+ close(fd);
+
+ return rc;
+}
+
+
+/**
+ * IfaceGetIndex
+ *
+ * @reportError: whether to report errors or keep silent
+ * @ifname : Name of the interface whose index is to be found
+ * @ifindex: Pointer to int where the index will be written into
+ *
+ * Get the index of an interface given its name.
+ *
+ * Returns 0 on success, an error code on failure.
+ * ENODEV : if interface with given name does not exist
+ * EINVAL : if interface name is invalid (too long)
+ */
+int
+IfaceGetIndex(bool reportError, const char *ifname, int *ifindex)
+{
+ int rc = 0;
+ struct ifreq ifreq;
+ int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+
+ if (fd < 0)
+ return errno;
+
+ if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
+ sizeof(ifreq.ifr_name)) == NULL) {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid interface name %s"),
+ ifname);
+ rc = EINVAL;
+ goto err_exit;
+ }
+
+ if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0)
+ *ifindex = ifreq.ifr_ifindex;
+ else {
+ if (reportError)
+ ifaceError(VIR_ERR_INTERNAL_ERROR,
+ _("interface %s does not exist"),
+ ifname);
+ rc = ENODEV;
+ }
+
+err_exit:
+ close(fd);
+
+ return rc;
+}
Index: libvirt-acl/src/util/interface.h
===================================================================
--- /dev/null
+++ libvirt-acl/src/util/interface.h
@@ -0,0 +1,31 @@
+/*
+ * interface.h: interface helper APIs for libvirt
+ *
+ * Copyright (C) 2010 IBM Corporation, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Stefan Berger <stefanb(a)us.ibm.com>
+ */
+#ifndef __VIR_INTERFACE_H__
+# define __VIR_INTERFACE_H__
+
+#include "datatypes.h"
+
+int IfaceCtrl(const char *name, bool up);
+
+static inline int IfaceUp(const char *name) {
+ return IfaceCtrl(name, true);
+}
+
+static inline int IfaceDown(const char *name) {
+ return IfaceCtrl(name, false);
+}
+
+int IfaceCheck(bool reportError, const char *ifname,
+ const unsigned char *macaddr, int ifindex);
+
+int IfaceGetIndex(bool reportError, const char *ifname, int *ifindex);
+
+#endif /* __VIR_INTERFACE_H__ */
+
Index: libvirt-acl/src/Makefile.am
===================================================================
--- libvirt-acl.orig/src/Makefile.am
+++ libvirt-acl/src/Makefile.am
@@ -67,6 +67,7 @@ UTIL_SOURCES = \
util/processinfo.c util/processinfo.h \
util/hostusb.c util/hostusb.h \
util/network.c util/network.h \
+ util/interface.c util/interface.h \
util/qparams.c util/qparams.h \
util/stats_linux.c util/stats_linux.h \
util/storage_file.c util/storage_file.h \
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -681,6 +681,10 @@ virFileWaitForDevices;
virFileMatchesNameSuffix;
virArgvToString;
+# interface.h
+IfaceCtrl;
+IfaceCheck;
+IfaceGetIndex;
# usb.h
usbGetDevice;
Index: libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_learnipaddr.c
+++ libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c
@@ -43,6 +43,7 @@
#include "memory.h"
#include "logging.h"
#include "datatypes.h"
+#include "interface.h"
#include "virterror_internal.h"
#include "threads.h"
#include "conf/nwfilter_params.h"
@@ -339,7 +340,7 @@ learnIPAddressThread(void *arg)
break;
}
/* listening on linkdev, check whether VM's dev is still there */
- if (checkIf(req->ifname, req->macaddr)) {
+ if (IfaceCheck(false, req->ifname, req->macaddr, -1)) {
req->status = ENODEV;
break;
}
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -44,6 +44,7 @@
# include "util.h"
# include "memory.h"
# include "macvtap.h"
+# include "interface.h"
# include "conf/domain_conf.h"
# include "virterror_internal.h"
@@ -193,109 +194,6 @@ nlAppend(struct nlmsghdr *nlm, int totle
static int
-getIfIndex(bool reportError,
- const char *ifname,
- int *idx)
-{
- int rc = 0;
- struct ifreq ifreq;
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
- sizeof(ifreq.ifr_name)) == NULL) {
- if (reportError)
- macvtapError(VIR_ERR_INTERNAL_ERROR,
- _("invalid interface name %s"),
- ifname);
- rc = EINVAL;
- goto err_exit;
- }
- if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0)
- *idx = ifreq.ifr_ifindex;
- else {
- if (reportError)
- macvtapError(VIR_ERR_INTERNAL_ERROR,
- _("interface %s does not exist"),
- ifname);
- rc = ENODEV;
- }
-
-err_exit:
- close(fd);
-
- return rc;
-}
-
-
-/*
- * chgIfFlags: Change flags on an interface
- * @ifname : name of the interface
- * @flagclear : the flags to clear
- * @flagset : the flags to set
- *
- * The new flags of the interface will be calculated as
- * flagmask = (~0 ^ flagclear)
- * newflags = (curflags & flagmask) | flagset;
- *
- * Returns 0 on success, errno on failure.
- */
-static int chgIfFlags(const char *ifname, short flagclear, short flagset) {
- struct ifreq ifr;
- int rc = 0;
- int flags;
- short flagmask = (~0 ^ flagclear);
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- if (fd < 0)
- return errno;
-
- if (virStrncpy(ifr.ifr_name,
- ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
- rc = ENODEV;
- goto err_exit;
- }
-
- if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
- rc = errno;
- goto err_exit;
- }
-
- flags = (ifr.ifr_flags & flagmask) | flagset;
-
- if (ifr.ifr_flags != flags) {
- ifr.ifr_flags = flags;
-
- if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
- rc = errno;
- }
-
-err_exit:
- close(fd);
- return rc;
-}
-
-/*
- * ifUp
- * @name: name of the interface
- * @up: 1 for up, 0 for down
- *
- * Function to control if an interface is activated (up, 1) or not (down, 0)
- *
- * Returns 0 in case of success or an errno code in case of failure.
- */
-static int
-ifUp(const char *name, int up)
-{
- return chgIfFlags(name,
- (up) ? 0 : IFF_UP,
- (up) ? IFF_UP : 0);
-}
-
-
-static int
link_add(const char *type,
const unsigned char *macaddress, int macaddrsize,
const char *ifname,
@@ -314,7 +212,7 @@ link_add(const char *type,
char *recvbuf = NULL;
int recvbuflen;
- if (getIfIndex(true, srcdev, &ifindex) != 0)
+ if (IfaceGetIndex(true, srcdev, &ifindex) != 0)
return -1;
*retry = 0;
@@ -708,7 +606,7 @@ openMacvtapTap(const char *tgifname,
*res_ifname = NULL;
if (tgifname) {
- if(getIfIndex(false, tgifname, &ifindex) == 0) {
+ if(IfaceGetIndex(false, tgifname, &ifindex) == 0) {
if (STRPREFIX(tgifname,
MACVTAP_NAME_PREFIX)) {
goto create_name;
@@ -727,7 +625,7 @@ create_name:
retries = 5;
for (c = 0; c < 8192; c++) {
snprintf(ifname, sizeof(ifname), MACVTAP_NAME_PATTERN, c);
- if (getIfIndex(false, ifname, &ifindex) == ENODEV) {
+ if (IfaceGetIndex(false, ifname, &ifindex) == ENODEV) {
rc = link_add(type, macaddress, 6, ifname, linkdev,
macvtapMode, &do_retry);
if (rc == 0)
@@ -741,7 +639,7 @@ create_name:
cr_ifname = ifname;
}
- rc = ifUp(cr_ifname, 1);
+ rc = IfaceUp(cr_ifname);
if (rc != 0) {
virReportSystemError(errno,
_("cannot 'up' interface %s -- another "
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.h
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
@@ -63,6 +63,4 @@ void virNWFilterDomainFWUpdateCB(void *p
const char *name ATTRIBUTE_UNUSED,
void *data);
-int checkIf(const char *ifname, const unsigned char *macaddr);
-
#endif
14 years, 7 months