From: Martin KaFai Lau <martin.lau@linux.dev>
To: Quentin Deslandes <qde@naccy.de>
Cc: David Ahern <dsahern@gmail.com>,
Martin KaFai Lau <martin.lau@kernel.org>,
kernel-team@meta.com, netdev@vger.kernel.org
Subject: Re: [PATCH v2 1/2] ss: add support for BPF socket-local storage
Date: Tue, 12 Dec 2023 14:49:28 -0800 [thread overview]
Message-ID: <6436a347-c4b1-4260-8f4f-96ed133626a8@linux.dev> (raw)
In-Reply-To: <20231208145720.411075-2-qde@naccy.de>
On 12/8/23 6:57 AM, Quentin Deslandes wrote:
> +static inline bool bpf_map_opts_is_enabled(void)
nit.
This is the only "inline" usage in this file. I would avoid it and depend on the
compiler to decide.
> +{
> + return bpf_map_opts.nr_maps;
> +}
> +
[ ... ]
> static int inet_show_sock(struct nlmsghdr *nlh,
> struct sockstat *s)
> {
> @@ -3381,8 +3620,8 @@ static int inet_show_sock(struct nlmsghdr *nlh,
> struct inet_diag_msg *r = NLMSG_DATA(nlh);
> unsigned char v6only = 0;
>
> - parse_rtattr(tb, INET_DIAG_MAX, (struct rtattr *)(r+1),
> - nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
> + parse_rtattr_flags(tb, INET_DIAG_MAX, (struct rtattr *)(r+1),
> + nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)), NLA_F_NESTED);
>
> if (tb[INET_DIAG_PROTOCOL])
> s->type = rta_getattr_u8(tb[INET_DIAG_PROTOCOL]);
> @@ -3479,6 +3718,11 @@ static int inet_show_sock(struct nlmsghdr *nlh,
> }
> sctp_ino = s->ino;
>
> + if (tb[INET_DIAG_SK_BPF_STORAGES]) {
> + field_set(COL_SKSTOR);
> + show_sk_bpf_storages(tb[INET_DIAG_SK_BPF_STORAGES]);
> + }
> +
> return 0;
> }
>
> @@ -3560,13 +3804,14 @@ static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
> {
> struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
> DIAG_REQUEST(req, struct inet_diag_req_v2 r);
> + struct rtattr *bpf_stgs_rta = NULL;
> char *bc = NULL;
> int bclen;
> __u32 proto;
> struct msghdr msg;
> struct rtattr rta_bc;
> struct rtattr rta_proto;
> - struct iovec iov[5];
> + struct iovec iov[6];
> int iovlen = 1;
>
> if (family == PF_UNSPEC)
> @@ -3619,6 +3864,17 @@ static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
> iovlen += 2;
> }
>
> + if (bpf_map_opts_is_enabled()) {
This will have compiler error when HAVE_LIBBPF is not set.
> + bpf_stgs_rta = bpf_map_opts_alloc_rta();
> + if (!bpf_stgs_rta) {
> + fprintf(stderr, "ss: cannot alloc request for --bpf-map\n");
> + return -1;
> + }
> +
> + iov[iovlen++] = (struct iovec){ bpf_stgs_rta, bpf_stgs_rta->rta_len };
> + req.nlh.nlmsg_len += bpf_stgs_rta->rta_len;
> + }
> +
> msg = (struct msghdr) {
> .msg_name = (void *)&nladdr,
> .msg_namelen = sizeof(nladdr),
[ ... ]
> @@ -5712,6 +5982,16 @@ int main(int argc, char *argv[])
> case OPT_INET_SOCKOPT:
> show_inet_sockopt = 1;
> break;
> +#ifdef HAVE_LIBBPF
> + case OPT_BPF_MAPS:
> + if (bpf_map_opts_add_all())
> + exit(1);
> + break;
> + case OPT_BPF_MAP_ID:
> + if (bpf_map_opts_add_id(optarg))
> + exit(1);
> + break;
> +#endif
> case 'h':
> help();
> case '?':
> @@ -5810,6 +6090,9 @@ int main(int argc, char *argv[])
> if (!(current_filter.states & (current_filter.states - 1)))
> columns[COL_STATE].disabled = 1;
>
> + if (bpf_map_opts.nr_maps)
same here when HAVE_LIBBPF is not set
> + columns[COL_SKSTOR].disabled = 0;
> +
> if (show_header)
> print_header();
>
> @@ -5845,6 +6128,7 @@ int main(int argc, char *argv[])
>
> if (show_processes || show_threads || show_proc_ctx || show_sock_ctx)
> user_ent_destroy();
> + bpf_map_opts_destroy();
same here.
A #ifdef is needed.
Another option is to create an empty or always-return-false function.
>
> render();
>
next prev parent reply other threads:[~2023-12-12 22:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-08 14:57 [PATCH v2 0/2] ss: pretty-printing BPF socket-local storage Quentin Deslandes
2023-12-08 14:57 ` [PATCH v2 1/2] ss: add support for " Quentin Deslandes
2023-12-12 22:49 ` Martin KaFai Lau [this message]
2023-12-08 14:57 ` [PATCH v2 2/2] ss: pretty-print " Quentin Deslandes
2023-12-12 22:58 ` Martin KaFai Lau
2023-12-13 17:46 ` Alan Maguire
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6436a347-c4b1-4260-8f4f-96ed133626a8@linux.dev \
--to=martin.lau@linux.dev \
--cc=dsahern@gmail.com \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=qde@naccy.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.