# HG changeset patch
# User Sharad Mishra <snmishra(a)us.ibm.com>
# Date 1257536605 28800
# Node ID 131932045d30226468c63942407321f29c65a33f
# Parent 906a78ecf9f3e4972133c6792c1ff543cc57b493
(#2) This patch adds support for IPv6 in KVMRedirectionSAP provider.
The code now loops through currently active IPv4 and IPv6 connections.
It tries to read both /proc/net/tcp and /proc/net/tcp6 files. If one
of the two files is successfully read, it does not return an error. For
the function to return an error, both IPv4 and IPv6 file reads should fail.
Signed-off-by: Sharad Mishra <snmishra(a)us.ibm.com>
diff -r 906a78ecf9f3 -r 131932045d30 src/Virt_KVMRedirectionSAP.c
--- a/src/Virt_KVMRedirectionSAP.c Mon Oct 05 06:02:39 2009 -0700
+++ b/src/Virt_KVMRedirectionSAP.c Fri Nov 06 11:43:25 2009 -0800
@@ -39,7 +39,8 @@
#include "Virt_KVMRedirectionSAP.h"
-#define PROC_TCP "/proc/net/tcp"
+#define PROC_TCP4 "/proc/net/tcp"
+#define PROC_TCP6 "/proc/net/tcp6"
const static CMPIBroker *_BROKER;
@@ -139,50 +140,47 @@
return inst;
}
-static CMPIStatus get_vnc_sessions(const CMPIBroker *broker,
- const CMPIObjectPath *ref,
- virConnectPtr conn,
- struct vnc_ports ports,
- struct inst_list *list)
+static CMPIStatus read_tcp_file(const CMPIBroker *broker,
+ const CMPIObjectPath *ref,
+ virConnectPtr conn,
+ struct vnc_ports ports,
+ struct inst_list *list,
+ FILE *fl)
{
CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIInstance *inst;
- const char *path = PROC_TCP;
unsigned int lport = 0;
unsigned int rport = 0;
- FILE *tcp_info;
char *line = NULL;
size_t len = 0;
int val;
int ret;
int i;
- tcp_info = fopen(path, "r");
- if (tcp_info == NULL) {
- cu_statusf(broker, &s,
+ if (getline(&line, &len, fl) == -1) {
+ cu_statusf(broker,
+ &s,
CMPI_RC_ERR_FAILED,
- "Failed to open %s: %m", tcp_info);
+ "Failed to read from %s",
+ fl);
goto out;
}
- if (getline(&line, &len, tcp_info) == -1) {
- cu_statusf(broker, &s,
- CMPI_RC_ERR_FAILED,
- "Failed to read from %s", tcp_info);
- goto out;
- }
-
- while (getline(&line, &len, tcp_info) > 0) {
- ret = sscanf(line, "%d: %*[^:]:%X %*[^:]:%X", &val,
&lport,
+ while (getline(&line, &len, fl) > 0) {
+ ret = sscanf(line,
+ "%d: %*[^:]:%X %*[^:]:%X",
+ &val,
+ &lport,
&rport);
if (ret != 3) {
- cu_statusf(broker, &s,
+ cu_statusf(broker,
+ &s,
CMPI_RC_ERR_FAILED,
"Unable to determine active sessions");
goto out;
}
- for (i = 0; i < ports.max; i++) {
+ for (i = 0; i < ports.max; i++) {
if (lport != ports.list[i]->port)
continue;
@@ -198,6 +196,46 @@
inst_list_add(list, inst);
}
}
+
+ out:
+ return s;
+}
+
+static CMPIStatus get_vnc_sessions(const CMPIBroker *broker,
+ const CMPIObjectPath *ref,
+ virConnectPtr conn,
+ struct vnc_ports ports,
+ struct inst_list *list)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+ const char *path[2] = {PROC_TCP4, PROC_TCP6};
+ FILE *tcp_info;
+ int i, j;
+ int error = 0;
+
+ for (j = 0; j < 2; j++) {
+ tcp_info = fopen(path[j], "r");
+ if (tcp_info == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to open %s: %m", tcp_info);
+ error++;
+ continue;
+ }
+
+ s = read_tcp_file(broker,
+ ref,
+ conn,
+ ports,
+ list,
+ tcp_info);
+
+ fclose(tcp_info);
+
+ if (s.rc != CMPI_RC_OK)
+ error++;
+ }
/* Handle any guests that were missed. These guest don't have active
or enabled sessions. */
@@ -212,8 +250,10 @@
inst_list_add(list, inst);
}
+ if (error != 2)
+ s.rc = CMPI_RC_OK;
+
out:
- fclose(tcp_info);
return s;
}