[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] qga: replace GetIfEntry
From: |
Michael Roth |
Subject: |
Re: [Qemu-devel] [PATCH v2] qga: replace GetIfEntry |
Date: |
Tue, 07 Nov 2017 11:06:15 -0600 |
User-agent: |
alot/0.6 |
Quoting ZhiPeng Lu (2017-11-03 09:54:20)
> The data obtained by GetIfEntry is 32 bits, and it may overflow. Thus using
> GetIfEntry2 instead of GetIfEntry.
>
> Signed-off-by: ZhiPeng Lu <address@hidden>
> ---
> qga/commands-win32.c | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
>
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index 0322188..d096dc2 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -1173,20 +1173,25 @@ static int guest_get_network_stats(const char *name,
> GuestNetworkInterfaceStat *stats)
> {
> DWORD if_index = 0;
> - MIB_IFROW a_mid_ifrow;
> - memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow));
> + OSVERSIONINFO OSver;
> if_index = get_interface_index(name);
> - a_mid_ifrow.dwIndex = if_index;
> - if (NO_ERROR == GetIfEntry(&a_mid_ifrow)) {
> - stats->rx_bytes = a_mid_ifrow.dwInOctets;
> - stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
> - stats->rx_errs = a_mid_ifrow.dwInErrors;
> - stats->rx_dropped = a_mid_ifrow.dwInDiscards;
> - stats->tx_bytes = a_mid_ifrow.dwOutOctets;
> - stats->tx_packets = a_mid_ifrow.dwOutUcastPkts;
> - stats->tx_errs = a_mid_ifrow.dwOutErrors;
> - stats->tx_dropped = a_mid_ifrow.dwOutDiscards;
> - return 0;
> + OSver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
> + GetVersionEx(&OSver);
> + if (OSver.dwMajorVersion >= 6) {
> + MIB_IF_ROW2 a_mid_ifrow;
> + memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow));
> + a_mid_ifrow.dwIndex = if_index;
> + if (NO_ERROR == GetIfEntry2(&a_mid_ifrow)) {
> + stats->rx_bytes = a_mid_ifrow.dwInOctets;
> + stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
> + stats->rx_errs = a_mid_ifrow.dwInErrors;
> + stats->rx_dropped = a_mid_ifrow.dwInDiscards;
> + stats->tx_bytes = a_mid_ifrow.dwOutOctets;
> + stats->tx_packets = a_mid_ifrow.dwOutUcastPkts;
> + stats->tx_errs = a_mid_ifrow.dwOutErrors;
> + stats->tx_dropped = a_mid_ifrow.dwOutDiscards;
> + return 0;
This fails to build in my fc20 mingw64 environment:
/home/mdroth/w/qemu4.git/qga/commands-win32.c:1184:20: error: 'MIB_IF_ROW2' has
no member named 'dwIndex'
a_mid_ifrow.dwIndex = if_index;
^
/home/mdroth/w/qemu4.git/qga/commands-win32.c:1186:42: error: 'MIB_IF_ROW2' has
no member named 'dwInOctets'
stats->rx_bytes = a_mid_ifrow.dwInOctets;
^
/home/mdroth/w/qemu4.git/qga/commands-win32.c:1187:44: error: 'MIB_IF_ROW2' has
no member named 'dwInUcastPkts'
stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
etc ...
The patch seems to assume MIB_IFROW and MIB_IF_ROW2 have the same field names
for the stats, but according to this they're slightly different:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa814491(v=vs.85).aspx
This change on top of your patch seems to work:
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index e17fc3c284..58e470877f 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1181,16 +1181,16 @@ static int guest_get_network_stats(const char *name,
if (os_ver.dwMajorVersion >= 6) {
MIB_IF_ROW2 a_mid_ifrow;
memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow));
- a_mid_ifrow.dwIndex = if_index;
+ a_mid_ifrow.InterfaceIndex = if_index;
if (NO_ERROR == GetIfEntry2(&a_mid_ifrow)) {
- stats->rx_bytes = a_mid_ifrow.dwInOctets;
- stats->rx_packets = a_mid_ifrow.dwInUcastPkts;
- stats->rx_errs = a_mid_ifrow.dwInErrors;
- stats->rx_dropped = a_mid_ifrow.dwInDiscards;
- stats->tx_bytes = a_mid_ifrow.dwOutOctets;
- stats->tx_packets = a_mid_ifrow.dwOutUcastPkts;
- stats->tx_errs = a_mid_ifrow.dwOutErrors;
- stats->tx_dropped = a_mid_ifrow.dwOutDiscards;
+ stats->rx_bytes = a_mid_ifrow.InOctets;
+ stats->rx_packets = a_mid_ifrow.InUcastPkts;
+ stats->rx_errs = a_mid_ifrow.InErrors;
+ stats->rx_dropped = a_mid_ifrow.InDiscards;
+ stats->tx_bytes = a_mid_ifrow.OutOctets;
+ stats->tx_packets = a_mid_ifrow.OutUcastPkts;
+ stats->tx_errs = a_mid_ifrow.OutErrors;
+ stats->tx_dropped = a_mid_ifrow.OutDiscards;
return 0;
}
}
I have the modified patch staged here:
https://github.com/mdroth/qemu/commit/de597a8b27722ce4f9cc660f930f7dccc712712d
Let me know if it looks okay and I'll send a pull request for rc1
> + }
> }
> return -1;
> }
> --
> 1.8.3.1
>
- [Qemu-devel] [PATCH v2] qga: replace GetIfEntry, ZhiPeng Lu, 2017/11/03
- Re: [Qemu-devel] [PATCH v2] qga: replace GetIfEntry, no-reply, 2017/11/04
- Re: [Qemu-devel] [PATCH v2] qga: replace GetIfEntry,
Michael Roth <=
- [Qemu-devel] 答复: Re: [PATCH v2] qga: replace GetIfEntry, lu.zhipeng, 2017/11/07
- [Qemu-devel] 答复: Re: [PATCH v2] qga: replace GetIfEntry, lu.zhipeng, 2017/11/09
- Re: [Qemu-devel] 答复: Re: [PATCH v2] qga: replace GetIfEntry, Michael Roth, 2017/11/13
- [Qemu-devel] 答复:Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, lu.zhipeng, 2017/11/13
- [Qemu-devel] 答复: Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, lu.zhipeng, 2017/11/14
- Re: [Qemu-devel] 答复: Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, Michael Roth, 2017/11/14
- [Qemu-devel] 答复: Re: 答复: Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, lu.zhipeng, 2017/11/14
- Re: [Qemu-devel] 答复: Re: 答复: Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, Michael Roth, 2017/11/14
- [Qemu-devel] 答复: Re: 答复: Re: 答复: Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, lu.zhipeng, 2017/11/14
- Re: [Qemu-devel] 答复: Re: 答复: Re: 答复: Re: [PATCH v2] qga: replace GetIfEntry, Michael Roth, 2017/11/20