From 91e61c8f05b190f403be00efa87041604b6a02a7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Nov 2014 11:35:02 +0100 Subject: [PATCH 1/2] idiag: add missing enum types for idiagnl_exts2str() Acked-by: Thomas Graf Signed-off-by: Thomas Haller --- lib/idiag/idiag.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/idiag/idiag.c b/lib/idiag/idiag.c index d8f5065..11d3810 100644 --- a/lib/idiag/idiag.c +++ b/lib/idiag/idiag.c @@ -164,6 +164,8 @@ static const struct trans_tbl idiag_exts[] = { __ADD(INET_DIAG_CONG, congestion), __ADD(INET_DIAG_TOS, tos), __ADD(INET_DIAG_TCLASS, tclass), + __ADD(INET_DIAG_SKMEMINFO, skmeminfo), + __ADD(INET_DIAG_SHUTDOWN, shutdown), }; /** From f0e3017d0ec9ec83cc36bc012dacda523c3037fd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 25 Nov 2014 11:35:03 +0100 Subject: [PATCH 2/2] idiag: fix idiagnl_exts2str() idiagnl_exts2str() is used to print req->idiag_ext, which is the extention types combined as flags, such as ( (1 << (INET_DIAG_TOS - 1)) | (1 << (INET_DIAG_MEMINFO - 1)) ). This function was wrong from the beginning because the string lookup array had indexes such as 'INET_DIAG_TOS', instead of '(1 << (INET_DIAG_TOS - 1)'. Fix also idiagnl_attrs2str() which now converts an extension type (e.g. INET_DIAG_TOS) to a string. Still this function is deprecated, as the function name is not clear and it is not used or very useful. Fixes: 22eb2569a595be98ae09fc4192860c1d2c3aa54c Acked-by: Thomas Graf Signed-off-by: Thomas Haller --- lib/idiag/idiag.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/idiag/idiag.c b/lib/idiag/idiag.c index 11d3810..34dc0d6 100644 --- a/lib/idiag/idiag.c +++ b/lib/idiag/idiag.c @@ -156,7 +156,7 @@ int idiagnl_str2timer(const char *name) return __str2type(name, idiag_timers, ARRAY_SIZE(idiag_timers)); } -static const struct trans_tbl idiag_exts[] = { +static const struct trans_tbl idiag_attrs[] = { __ADD(INET_DIAG_NONE, none), __ADD(INET_DIAG_MEMINFO, meminfo), __ADD(INET_DIAG_INFO, info), @@ -169,24 +169,35 @@ static const struct trans_tbl idiag_exts[] = { }; /** - * Convert inet diag extension flags to a string. - * @arg attrs inet diag extension flag (e.g., INET_DIAG_MEMINFO) + * Convert inet diag extension type to a string. + * @arg attrs inet diag extension type (e.g. INET_DIAG_MEMINFO) * @arg buf output buffer which will hold string result * @arg len length in bytes of the output buffer * - * @return string representation of attrs or an empty string. - * @deprecated This function returns almost the same as idiagnl_exts2str(), - * except that the latter only supports @attrs of uint8_t. + * @return string representation of inet diag extension type or an empty string. + * @deprecated: don't use this function. It is not very useful and should + * never have been exposed as public API. */ char *idiagnl_attrs2str(int attrs, char *buf, size_t len) { - return __flags2str(attrs, buf, len, idiag_exts, ARRAY_SIZE(idiag_exts)); + return __type2str(attrs, buf, len, idiag_attrs, ARRAY_SIZE(idiag_attrs)); } +static const struct trans_tbl idiag_exts[] = { + __ADD((1 << (INET_DIAG_MEMINFO - 1)), meminfo), + __ADD((1 << (INET_DIAG_INFO - 1)), info), + __ADD((1 << (INET_DIAG_VEGASINFO - 1)), vegasinfo), + __ADD((1 << (INET_DIAG_CONG - 1)), congestion), + __ADD((1 << (INET_DIAG_TOS - 1)), tos), + __ADD((1 << (INET_DIAG_TCLASS - 1)), tclass), + __ADD((1 << (INET_DIAG_SKMEMINFO - 1)), skmeminfo), + __ADD((1 << (INET_DIAG_SHUTDOWN - 1)), shutdown), +}; + /** * Convert inet diag extension flags to a string. - * @arg attrs inet diag extension flags (e.g., (INET_DIAG_MEMINFO | - * INET_DIAG_CONG | INET_DIAG_TOS)) + * @arg attrs inet diag extension flags (e.g. + * ( (1<<(INET_DIAG_MEMINFO-1)) | (1<<(INET_DIAG_CONG-1)) | (1<<(INET_DIAG_TOS-1)) ) ) * @arg buf Output buffer to hold string representation * @arg len length in bytes of the output buffer */