[PATCH] This patch adds support for IPv6 in KVMRedirectionSAP provider

# HG changeset patch # User Sharad Mishra <snmishra@us.ibm.com> # Date 1256685120 25200 # Node ID 34fd1a216b41db1e32ca508cc73c70d45faed33d # Parent 906a78ecf9f3e4972133c6792c1ff543cc57b493 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. diff -r 906a78ecf9f3 -r 34fd1a216b41 src/Virt_KVMRedirectionSAP.c --- a/src/Virt_KVMRedirectionSAP.c Mon Oct 05 06:02:39 2009 -0700 +++ b/src/Virt_KVMRedirectionSAP.c Tue Oct 27 16:12:00 2009 -0700 @@ -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,22 +196,69 @@ inst_list_add(list, inst); } } + + out: + return s; +} - /* Handle any guests that were missed. These guest don't have active - or enabled sessions. */ - for (i = 0; i < ports.max; i++) { - if (ports.list[i]->remote_port != -1) - continue; +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; - inst = get_console_sap(broker, ref, conn, ports.list[i], &s); - if ((s.rc != CMPI_RC_OK) || (inst == NULL)) - goto out; + 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); + goto error; + } - inst_list_add(list, inst); + s = read_tcp_file(broker, + ref, + conn, + ports, + list, + tcp_info); + + if (s.rc != CMPI_RC_OK) + goto error; + + /* Handle any guests that were missed. These guest don't have active + or enabled sessions. */ + for (i = 0; i < ports.max; i++) { + if (ports.list[i]->remote_port != -1) + continue; + + inst = get_console_sap(broker, ref, conn, ports.list[i], &s); + if ((s.rc != CMPI_RC_OK) || (inst == NULL)) + goto error; + + inst_list_add(list, inst); + } + + error: + if (tcp_info != NULL) + fclose(tcp_info); + + if ((j == 0) && (s.rc != CMPI_RC_OK)) { + error = 1; + s.rc = CMPI_RC_OK; + } } - out: - fclose(tcp_info); + if ((s.rc != CMPI_RC_OK) && (error == 0)) + s.rc = CMPI_RC_OK; + 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;
- inst = get_console_sap(broker, ref, conn, ports.list[i], &s); - if ((s.rc != CMPI_RC_OK) || (inst == NULL)) - goto out; + 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); + goto error; + }
- inst_list_add(list, inst); + s = read_tcp_file(broker, + ref, + conn, + ports, + list, + tcp_info); + + if (s.rc != CMPI_RC_OK) + goto error; + + /* Handle any guests that were missed. These guest don't have active + or enabled sessions. */ + for (i = 0; i < ports.max; i++) { + if (ports.list[i]->remote_port != -1) + continue; + + inst = get_console_sap(broker, ref, conn, ports.list[i], &s); + if ((s.rc != CMPI_RC_OK) || (inst == NULL)) + goto error; + + inst_list_add(list, inst); + }
This for loop doesn't need to be part of the greater for loop. Otherwise, you will generate two instances for the same guest: # wbemcli ein http://localhost:5988/root/virt:KVM_KVMRedirectionSAP -nl localhost:5988/root/virt:KVM_KVMRedirectionSAP.CreationClassName="KVM_KVMRedirectionSAP",Name="5903:0",SystemCreationClassName="KVM_ComputerSystem",SystemName="f10_test" localhost:5988/root/virt:KVM_KVMRedirectionSAP.CreationClassName="KVM_KVMRedirectionSAP",Name="-1:-1",SystemCreationClassName="KVM_ComputerSystem",SystemName="xtest2" localhost:5988/root/virt:KVM_KVMRedirectionSAP.CreationClassName="KVM_KVMRedirectionSAP",Name="-1:-1",SystemCreationClassName="KVM_ComputerSystem",SystemName="xtest2" This loop creates an instance for guests that are in define state. For these guests, the remote port is -1 because the hypervisor doesn't start a VNC server for the guest until the guest is running.
+ + error:
Moving the above loop outside of the outer for loop will remove the need for this error tag. And should remove the need for the error variable.
+ if (tcp_info != NULL) + fclose(tcp_info); + + if ((j == 0) && (s.rc != CMPI_RC_OK)) { + error = 1; + s.rc = CMPI_RC_OK; + } }
- out: - fclose(tcp_info); + if ((s.rc != CMPI_RC_OK) && (error == 0)) + s.rc = CMPI_RC_OK; + return s; }
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Sharad Mishra