* [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly
@ 2023-08-08 21:42 Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 2/4] Add utility to convert an unsigned int to string Mathieu Schroeter
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Mathieu Schroeter @ 2023-08-08 21:42 UTC (permalink / raw)
To: netdev; +Cc: Mathieu Schroeter
Signed-off-by: Mathieu Schroeter <mathieu@schroetersa.ch>
---
include/utils.h | 1 +
lib/utils.c | 13 ++++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/include/utils.h b/include/utils.h
index 3159dbab..cf11174d 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -142,6 +142,7 @@ int get_addr_rta(inet_prefix *dst, const struct rtattr *rta, int family);
int get_addr_ila(__u64 *val, const char *arg);
int read_prop(const char *dev, char *prop, long *value);
+int get_long(long *val, const char *arg, int base);
int get_integer(int *val, const char *arg, int base);
int get_unsigned(unsigned *val, const char *arg, int base);
int get_time_rtt(unsigned *val, const char *arg, int *raw);
diff --git a/lib/utils.c b/lib/utils.c
index b1f27305..68f44303 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -108,7 +108,7 @@ static int get_hex(char c)
return -1;
}
-int get_integer(int *val, const char *arg, int base)
+int get_long(long *val, const char *arg, int base)
{
long res;
char *ptr;
@@ -133,6 +133,17 @@ int get_integer(int *val, const char *arg, int base)
if ((res == LONG_MAX || res == LONG_MIN) && errno == ERANGE)
return -1;
+ if (val)
+ *val = res;
+ return 0;
+}
+
+int get_integer(int *val, const char *arg, int base)
+{
+ long res;
+
+ res = get_long(NULL, arg, base);
+
/* Outside range of int */
if (res < INT_MIN || res > INT_MAX)
return -1;
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH iproute2-next 2/4] Add utility to convert an unsigned int to string
2023-08-08 21:42 [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly Mathieu Schroeter
@ 2023-08-08 21:42 ` Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 3/4] ss: change aafilter port from int to long (inode support) Mathieu Schroeter
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Mathieu Schroeter @ 2023-08-08 21:42 UTC (permalink / raw)
To: netdev; +Cc: Mathieu Schroeter
Signed-off-by: Mathieu Schroeter <mathieu@schroetersa.ch>
---
include/utils.h | 1 +
lib/utils.c | 6 ++++++
2 files changed, 7 insertions(+)
diff --git a/include/utils.h b/include/utils.h
index cf11174d..f26ed822 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -309,6 +309,7 @@ unsigned int print_name_and_link(const char *fmt,
extern int cmdlineno;
char *int_to_str(int val, char *buf);
+char *uint_to_str(unsigned int val, char *buf);
int get_guid(__u64 *guid, const char *arg);
int get_real_family(int rtm_type, int rtm_family);
diff --git a/lib/utils.c b/lib/utils.c
index 68f44303..efa01668 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1409,6 +1409,12 @@ char *int_to_str(int val, char *buf)
return buf;
}
+char *uint_to_str(unsigned int val, char *buf)
+{
+ sprintf(buf, "%u", val);
+ return buf;
+}
+
int get_guid(__u64 *guid, const char *arg)
{
unsigned long tmp;
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH iproute2-next 3/4] ss: change aafilter port from int to long (inode support)
2023-08-08 21:42 [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 2/4] Add utility to convert an unsigned int to string Mathieu Schroeter
@ 2023-08-08 21:42 ` Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 4/4] ss: print unix socket "ports" as unsigned int (inode) Mathieu Schroeter
2023-08-13 16:30 ` [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Mathieu Schroeter @ 2023-08-08 21:42 UTC (permalink / raw)
To: netdev; +Cc: Mathieu Schroeter
The aafilter struct considers the port as (usually) 32 bit signed
integer. In case of a unix socket, the port is used with an inode
number which is an unsigned int. In this case, the 'ss' command
fails because it assumes that the value does not look like a port
(<0).
Here an example of command call where the inode is passed and
is larger than a signed integer:
ss -H -A unix_stream src :2259952798
Signed-off-by: Mathieu Schroeter <mathieu@schroetersa.ch>
---
misc/ss.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index e9d81359..baa83514 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1733,7 +1733,7 @@ static void inet_addr_print(const inet_prefix *a, int port,
struct aafilter {
inet_prefix addr;
- int port;
+ long port;
unsigned int iface;
__u32 mark;
__u32 mask;
@@ -2256,7 +2256,7 @@ void *parse_hostcond(char *addr, bool is_port)
port = find_port(addr, is_port);
if (port) {
if (*port && strcmp(port, "*")) {
- if (get_integer(&a.port, port, 0)) {
+ if (get_long(&a.port, port, 0)) {
if ((a.port = xll_name_to_index(port)) <= 0)
return NULL;
}
@@ -2279,7 +2279,7 @@ void *parse_hostcond(char *addr, bool is_port)
port = find_port(addr, is_port);
if (port) {
if (*port && strcmp(port, "*")) {
- if (get_integer(&a.port, port, 0)) {
+ if (get_long(&a.port, port, 0)) {
if (strcmp(port, "kernel") == 0)
a.port = 0;
else
@@ -2335,7 +2335,7 @@ void *parse_hostcond(char *addr, bool is_port)
*port++ = 0;
if (*port && *port != '*') {
- if (get_integer(&a.port, port, 0)) {
+ if (get_long(&a.port, port, 0)) {
struct servent *se1 = NULL;
struct servent *se2 = NULL;
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH iproute2-next 4/4] ss: print unix socket "ports" as unsigned int (inode)
2023-08-08 21:42 [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 2/4] Add utility to convert an unsigned int to string Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 3/4] ss: change aafilter port from int to long (inode support) Mathieu Schroeter
@ 2023-08-08 21:42 ` Mathieu Schroeter
2023-08-13 16:30 ` [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Mathieu Schroeter @ 2023-08-08 21:42 UTC (permalink / raw)
To: netdev; +Cc: Mathieu Schroeter
Signed-off-by: Mathieu Schroeter <mathieu@schroetersa.ch>
---
misc/ss.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index baa83514..13b2523f 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -4073,9 +4073,9 @@ static void unix_stats_print(struct sockstat *s, struct filter *f)
sock_state_print(s);
sock_addr_print(s->name ?: "*", " ",
- int_to_str(s->lport, port_name), NULL);
+ uint_to_str(s->lport, port_name), NULL);
sock_addr_print(s->peer_name ?: "*", " ",
- int_to_str(s->rport, port_name), NULL);
+ uint_to_str(s->rport, port_name), NULL);
proc_ctx_print(s);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly
2023-08-08 21:42 [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly Mathieu Schroeter
` (2 preceding siblings ...)
2023-08-08 21:42 ` [PATCH iproute2-next 4/4] ss: print unix socket "ports" as unsigned int (inode) Mathieu Schroeter
@ 2023-08-13 16:30 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-13 16:30 UTC (permalink / raw)
To: Mathieu Schroeter; +Cc: netdev
Hello:
This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:
On Tue, 8 Aug 2023 23:42:55 +0200 you wrote:
> Signed-off-by: Mathieu Schroeter <mathieu@schroetersa.ch>
> ---
> include/utils.h | 1 +
> lib/utils.c | 13 ++++++++++++-
> 2 files changed, 13 insertions(+), 1 deletion(-)
Here is the summary with links:
- [iproute2-next,1/4] Add get_long utility and adapt get_integer accordingly
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=3a463c152a9a
- [iproute2-next,2/4] Add utility to convert an unsigned int to string
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=db7fb3f19657
- [iproute2-next,3/4] ss: change aafilter port from int to long (inode support)
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=012cb5152d05
- [iproute2-next,4/4] ss: print unix socket "ports" as unsigned int (inode)
https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=e12d0c929cf5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-13 16:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-08 21:42 [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 2/4] Add utility to convert an unsigned int to string Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 3/4] ss: change aafilter port from int to long (inode support) Mathieu Schroeter
2023-08-08 21:42 ` [PATCH iproute2-next 4/4] ss: print unix socket "ports" as unsigned int (inode) Mathieu Schroeter
2023-08-13 16:30 ` [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).