From patchwork Tue Aug 8 21:42:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Schroeter X-Patchwork-Id: 13347077 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2EC4E569 for ; Tue, 8 Aug 2023 21:44:36 +0000 (UTC) Received: from authsmtp.register.it (authsmtp08.register.it [81.88.48.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57A6110D1 for ; Tue, 8 Aug 2023 14:44:33 -0700 (PDT) Received: from localhost.localdomain ([213.230.62.249]) by cmsmtp with ESMTPSA id TUUDqYXukCJCaTUUDqEu4c; Tue, 08 Aug 2023 23:43:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schroetersa.ch; s=key_mmumrc8kf9; t=1691531009; bh=Vgf9WaXByktY1QmN6KvRZlFTz+cLxrhgeQg1RDwJoTY=; h=From:To:Cc:Subject:Date; b=vXoDimFYSQte9zI9UaFuhTUcBJSBNG5DNbU5+CYoYzHai3z+WnkIwKF1T0idB3t8A y42n7kI9E7EeLyL/f2wTQaWdhzkJAPE85TUNIepCdHOVcq6wKP0fXNt/uFTINIrsuX GQchgZD8/8Ry1xmTvlIi0WSsGFfo4j2M8YplJlmX7XjHDBtoe6MktOeXocExhEObfl VqXNejnuzNLtYyBJmntDRxnUo7aSmcZHUrBRKDoM2ddeopf9wUUEh2Up+5pdaXPd55 teKUKTD+Xv7s+ZMJIwFQ0Rqcl0pVWcuC+cr1uDsRKKdbduWY+uaksY6qXzFPT2kztD y9+3W1gSbEfWw== X-Rid: mathieu@schroetersa.ch@213.230.62.249 From: Mathieu Schroeter To: netdev@vger.kernel.org Cc: Mathieu Schroeter Subject: [PATCH iproute2-next 1/4] Add get_long utility and adapt get_integer accordingly Date: Tue, 8 Aug 2023 23:42:55 +0200 Message-Id: <20230808214258.975440-1-mathieu@schroetersa.ch> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfLt7SBoWUeaf3xVaYQb4iEtj++3AhAg0eXHa0B6Hau3WZ783Y67BQeMaSPhjG427t+7abRj05edwBeIGBrdZ4gU5fkZ32GjbZdkoZE5y3H/79EXmIQMK 0z4lfkOeF81TettWceUuo0CrzIYoJCrPcl/j5G6j2ULz/ca/mcz2rENYIniS0+myFt5iJ2CiIucSIOKihvsXtEzimfFdPQTjgwUUdgjL43PBuGQ04TyhDCVX j3SwWad1V/EySEyVtN6xNg== X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com Signed-off-by: Mathieu Schroeter --- 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; From patchwork Tue Aug 8 21:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Schroeter X-Patchwork-Id: 13347079 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B563B174C4 for ; Tue, 8 Aug 2023 21:44:36 +0000 (UTC) X-Greylist: delayed 60 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 08 Aug 2023 14:44:32 PDT Received: from authsmtp.register.it (authsmtp40.register.it [81.88.55.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D0A196 for ; Tue, 8 Aug 2023 14:44:32 -0700 (PDT) Received: from localhost.localdomain ([213.230.62.249]) by cmsmtp with ESMTPSA id TUUDqYXukCJCaTUUDqEu4j; Tue, 08 Aug 2023 23:43:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schroetersa.ch; s=key_mmumrc8kf9; t=1691531010; bh=kq80xGxH8d+kQYHmp4G8gY23FD7LmZhfznJZdss4Mh4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yPoWxjBk4ZI22Z4Wz5XRutdyTEl59N3DmowYFD8lduzUNRQNqEld/ZHV0H7Ab2zqU NrDw28UT1LiExynmfUwlmSKFMCKfssfkFHNawztEWu7rNsPdHhyiJ11Pz7KPb7ifGq tP6k8RGlwk/pCIUGy+22fWei8iJkKfL6b0ODFCPakjnYQ+8gCLYrTSLH6qhVlDcOut I8yNMs+JJuvy4L2kJchM6kDE/rSyMAOE5b0n8FuhbcmuCSdcZFqUtc3oET43BY07q7 6CVuV1VWu3nT9X0mkPDLZwr81wp0psbazrivaXwa0Nz59nQUyHtmJPvWxknbUPfY0N oMByQ991Fa+Hg== X-Rid: mathieu@schroetersa.ch@213.230.62.249 From: Mathieu Schroeter To: netdev@vger.kernel.org Cc: Mathieu Schroeter Subject: [PATCH iproute2-next 2/4] Add utility to convert an unsigned int to string Date: Tue, 8 Aug 2023 23:42:56 +0200 Message-Id: <20230808214258.975440-2-mathieu@schroetersa.ch> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808214258.975440-1-mathieu@schroetersa.ch> References: <20230808214258.975440-1-mathieu@schroetersa.ch> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfLt7SBoWUeaf3xVaYQb4iEtj++3AhAg0eXHa0B6Hau3WZ783Y67BQeMaSPhjG427t+7abRj05edwBeIGBrdZ4gU5fkZ32GjbZdkoZE5y3H/79EXmIQMK 0z4lfkOeF81TettWceUuo0CrzIYoJCrPcl/j5G6j2ULz/ca/mcz2rENYIniS0+myFt5iJ2CiIucSIOKihvsXtEzimfFdPQTjgwUUdgjL43PBuGQ04TyhDCVX j3SwWad1V/EySEyVtN6xNg== X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com Signed-off-by: Mathieu Schroeter --- 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; From patchwork Tue Aug 8 21:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Schroeter X-Patchwork-Id: 13347080 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0642719896 for ; Tue, 8 Aug 2023 21:44:36 +0000 (UTC) Received: from authsmtp.register.it (authsmtp19.register.it [81.88.48.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57BEF1BEA for ; Tue, 8 Aug 2023 14:44:33 -0700 (PDT) Received: from localhost.localdomain ([213.230.62.249]) by cmsmtp with ESMTPSA id TUUDqYXukCJCaTUUEqEu4p; Tue, 08 Aug 2023 23:43:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schroetersa.ch; s=key_mmumrc8kf9; t=1691531010; bh=8Yb4Jl0Mb1TmDbXrGPNIPZesvom88SnHDY80EoicmSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D6HSCPjpyAHsJBfkGZIT4ogUx0bQdaBGJjwJ7p/25Cn2Bor7rH8kgpWSVD7hq8ZKg XGvSY9kcsFerPhKate0Q5JU5ETBtxBsKKG5nxC6XLrcZ6abLz84kVVe8tB9Zs93Z+w TZ/xRGxgdfsXkpAeoTzX7eF7a/iuLo3SWZysrZb3NbWeMIxe5ZqAhsrdDOCXyMGpfY MTAEWT1cJoNdUgUTgVNDsmrqQBfW2CHRXIQISL2Oo27CHbtCSC2q2lD1sFiAc8fGBf lB4dKfI1RJkigY6slqC3bgxZL6UZ4LLP8nwof4eXocHBIzEq22qWHA8C/+9b/VVx2G Z4u+RlQ0TaiUA== X-Rid: mathieu@schroetersa.ch@213.230.62.249 From: Mathieu Schroeter To: netdev@vger.kernel.org Cc: Mathieu Schroeter Subject: [PATCH iproute2-next 3/4] ss: change aafilter port from int to long (inode support) Date: Tue, 8 Aug 2023 23:42:57 +0200 Message-Id: <20230808214258.975440-3-mathieu@schroetersa.ch> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808214258.975440-1-mathieu@schroetersa.ch> References: <20230808214258.975440-1-mathieu@schroetersa.ch> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfIeu2yRNlD6HCRfYz+sUir1zNW5O61EciCMSD8red2oD4n7rVPf5VsQAwCWV8Nhlg50/Dus8SP4EjaEEsBxih9GP6zB/IMlEwSOVvsJYGDjfKDxn1s/H qS+XJmjJesFiUDpl3YBINhzGsexTGCKAqz7K8YEUz6/MgOAVYvb1nO25Me8DdnF+MDd0LHhOwfPdav2WTl276KHNLSHkje7+xAxBH2YL7+OlDiEuHqW6YYal wWx2WDA5b/RdM+PXOzX/ZQ== X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com 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 --- 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; From patchwork Tue Aug 8 21:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Schroeter X-Patchwork-Id: 13347078 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B725C174C5 for ; Tue, 8 Aug 2023 21:44:36 +0000 (UTC) X-Greylist: delayed 60 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 08 Aug 2023 14:44:32 PDT Received: from authsmtp.register.it (authsmtp19.register.it [81.88.48.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5EAEE72 for ; Tue, 8 Aug 2023 14:44:32 -0700 (PDT) Received: from localhost.localdomain ([213.230.62.249]) by cmsmtp with ESMTPSA id TUUDqYXukCJCaTUUEqEu4t; Tue, 08 Aug 2023 23:43:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schroetersa.ch; s=key_mmumrc8kf9; t=1691531010; bh=zV4X3zC1bPRXds5czW6LbbWAuj9Sc1c0deqWSTzZD9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eJhyAy428t3TQGeRi1vKhItIb//ayvjItKTIGNhRcrpwhWb7OlKNV5KMqGXSUS9sP vrx+mw27nxvcXUoWeqp7RK3rXdauhlg6m970+iuEyaSovSO3oCQmJWTgZiJKMLl3FK J/aiyYV1F/AHWn//AvxUcUAZg4ePmXPEyLHPHi7zPuqR80t6XYPudZdSmLFwGNRN5K Sdmxe2Jxn9xLxcT/2oc+uIJpBAf+wcVF+mteDWn38sv0dYttIX+vlFjWMsn6LjmRrp qkUFa4EAkWC+RObsCdrjXUV1Qys7qiXdroxMkEh7989FS/u3z9VTnSo9rm/U9+YyvD HMXL8hWqfMBeg== X-Rid: mathieu@schroetersa.ch@213.230.62.249 From: Mathieu Schroeter To: netdev@vger.kernel.org Cc: Mathieu Schroeter Subject: [PATCH iproute2-next 4/4] ss: print unix socket "ports" as unsigned int (inode) Date: Tue, 8 Aug 2023 23:42:58 +0200 Message-Id: <20230808214258.975440-4-mathieu@schroetersa.ch> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230808214258.975440-1-mathieu@schroetersa.ch> References: <20230808214258.975440-1-mathieu@schroetersa.ch> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CMAE-Envelope: MS4xfIeu2yRNlD6HCRfYz+sUir1zNW5O61EciCMSD8red2oD4n7rVPf5VsQAwCWV8Nhlg50/Dus8SP4EjaEEsBxih9GP6zB/IMlEwSOVvsJYGDjfKDxn1s/H qS+XJmjJesFiUDpl3YBINhzGsexTGCKAqz7K8YEUz6/MgOAVYvb1nO25Me8DdnF+MDd0LHhOwfPdav2WTl276KHNLSHkje7+xAxBH2YL7+OlDiEuHqW6YYal wWx2WDA5b/RdM+PXOzX/ZQ== X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: dsahern@gmail.com Signed-off-by: Mathieu Schroeter --- 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); }