All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Sowden <jeremy@azazel.net>
To: Netfilter Devel <netfilter-devel@vger.kernel.org>
Subject: [PATCH libnetfilter_conntrack 2/2] conntrack: simplify calculation of `struct sock_fprog` length
Date: Fri, 23 Dec 2022 16:24:41 +0000	[thread overview]
Message-ID: <20221223162441.2692988-2-jeremy@azazel.net> (raw)
In-Reply-To: <20221223162441.2692988-1-jeremy@azazel.net>

When assigning the length to the `struct sock_fprog` object, we
calculate it by multiplying the number of `struct sock_filter` objects,
`j`, by `sizeof(struct sock_filter)` and then dividing by
`sizeof(bsf[0])`, which, since `bsf[0]` is a `struct sock_filter`, is
equal to `sizeof(struct sock_filter)`.

Remove the `sizeof` expressions and just assign `j`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
---
 src/conntrack/bsf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conntrack/bsf.c b/src/conntrack/bsf.c
index 589bfd8e5d18..35cc8b7690c0 100644
--- a/src/conntrack/bsf.c
+++ b/src/conntrack/bsf.c
@@ -783,7 +783,7 @@ int __setup_netlink_socket_filter(int fd, struct nfct_filter *f)
 	show_filter(bsf, from, j, "---- final verdict ----");
 	from = j;
 
-	sf.len = (sizeof(struct sock_filter) * j) / sizeof(bsf[0]);
+	sf.len = j;
 	sf.filter = bsf;
 
 	return setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &sf, sizeof(sf));
-- 
2.35.1


  reply	other threads:[~2022-12-23 16:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-23 16:24 [PATCH libnetfilter_conntrack 1/2] conntrack: fix BPF code for filtering on big-endian architectures Jeremy Sowden
2022-12-23 16:24 ` Jeremy Sowden [this message]
2023-01-02 16:19   ` [PATCH libnetfilter_conntrack 2/2] conntrack: simplify calculation of `struct sock_fprog` length Pablo Neira Ayuso
2023-01-02 16:19 ` [PATCH libnetfilter_conntrack 1/2] conntrack: fix BPF code for filtering on big-endian architectures Pablo Neira Ayuso

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=20221223162441.2692988-2-jeremy@azazel.net \
    --to=jeremy@azazel.net \
    --cc=netfilter-devel@vger.kernel.org \
    /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.