net/ipv4/netfilter/arp_tables.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Replace the manual offset-based iteration with xt_entry_foreach(),
thereby removing FIXME. The byte offset semantics and user ABI
are preserved.
Signed-off-by: Kshitiz Bartariya <kshitiz.bartariya@zohomail.in>
---
net/ipv4/netfilter/arp_tables.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 1cdd9c28ab2d..9f82ce0fcaa5 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -684,12 +684,11 @@ static int copy_entries_to_user(unsigned int total_size,
loc_cpu_entry = private->entries;
- /* FIXME: use iterator macros --RR */
- /* ... then go back and fix counters and names */
- for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
+ num = 0;
+ xt_entry_foreach(e, loc_cpu_entry, total_size) {
const struct xt_entry_target *t;
- e = loc_cpu_entry + off;
+ off = (unsigned char *)e - (unsigned char *)loc_cpu_entry;
if (copy_to_user(userptr + off, e, sizeof(*e))) {
ret = -EFAULT;
goto free_counters;
@@ -707,6 +706,7 @@ static int copy_entries_to_user(unsigned int total_size,
ret = -EFAULT;
goto free_counters;
}
+ num++;
}
free_counters:
--
2.50.1 (Apple Git-155)
On Mon, Jan 19, 2026 at 12:07:04PM +0530, Kshitiz Bartariya wrote:
> Replace the manual offset-based iteration with xt_entry_foreach(),
> thereby removing FIXME. The byte offset semantics and user ABI
> are preserved.
>
> Signed-off-by: Kshitiz Bartariya <kshitiz.bartariya@zohomail.in>
> ---
> net/ipv4/netfilter/arp_tables.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
> index 1cdd9c28ab2d..9f82ce0fcaa5 100644
> --- a/net/ipv4/netfilter/arp_tables.c
> +++ b/net/ipv4/netfilter/arp_tables.c
> @@ -684,12 +684,11 @@ static int copy_entries_to_user(unsigned int total_size,
>
> loc_cpu_entry = private->entries;
>
> - /* FIXME: use iterator macros --RR */
> - /* ... then go back and fix counters and names */
> - for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
> + num = 0;
> + xt_entry_foreach(e, loc_cpu_entry, total_size) {
> const struct xt_entry_target *t;
>
> - e = loc_cpu_entry + off;
> + off = (unsigned char *)e - (unsigned char *)loc_cpu_entry;
This offset calculation makes me feel queasy.
Can the code start with off = 0 and increment it by e->next_offset
as the loop iterates, as was the case before this patch?
It would be similar to how num is handled.
> if (copy_to_user(userptr + off, e, sizeof(*e))) {
> ret = -EFAULT;
> goto free_counters;
> @@ -707,6 +706,7 @@ static int copy_entries_to_user(unsigned int total_size,
> ret = -EFAULT;
> goto free_counters;
> }
> + num++;
> }
>
> free_counters:
> --
> 2.50.1 (Apple Git-155)
>
Simon Horman <horms@kernel.org> wrote:
> On Mon, Jan 19, 2026 at 12:07:04PM +0530, Kshitiz Bartariya wrote:
> > Replace the manual offset-based iteration with xt_entry_foreach(),
> > thereby removing FIXME. The byte offset semantics and user ABI
> > are preserved.
> >
> > Signed-off-by: Kshitiz Bartariya <kshitiz.bartariya@zohomail.in>
> > ---
> > net/ipv4/netfilter/arp_tables.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
> > index 1cdd9c28ab2d..9f82ce0fcaa5 100644
> > --- a/net/ipv4/netfilter/arp_tables.c
> > +++ b/net/ipv4/netfilter/arp_tables.c
> > @@ -684,12 +684,11 @@ static int copy_entries_to_user(unsigned int total_size,
> >
> > loc_cpu_entry = private->entries;
> >
> > - /* FIXME: use iterator macros --RR */
> > - /* ... then go back and fix counters and names */
> > - for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
> > + num = 0;
> > + xt_entry_foreach(e, loc_cpu_entry, total_size) {
> > const struct xt_entry_target *t;
> >
> > - e = loc_cpu_entry + off;
> > + off = (unsigned char *)e - (unsigned char *)loc_cpu_entry;
>
> This offset calculation makes me feel queasy.
>
> Can the code start with off = 0 and increment it by e->next_offset
> as the loop iterates, as was the case before this patch?
> It would be similar to how num is handled.
I think this file should just be left alone resp. should be restricted
to bug fixes only. Same for ip/ip6/ebtables.
Its too early to remove this file from the tree, but I don't see
value in making cosmetic improvements, sorry.
On Wed, Jan 21, 2026 at 11:05:21PM +0100, Florian Westphal wrote:
> Simon Horman <horms@kernel.org> wrote:
> > On Mon, Jan 19, 2026 at 12:07:04PM +0530, Kshitiz Bartariya wrote:
> > > Replace the manual offset-based iteration with xt_entry_foreach(),
> > > thereby removing FIXME. The byte offset semantics and user ABI
> > > are preserved.
> > >
> > > Signed-off-by: Kshitiz Bartariya <kshitiz.bartariya@zohomail.in>
> > > ---
> > > net/ipv4/netfilter/arp_tables.c | 8 ++++----
> > > 1 file changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
> > > index 1cdd9c28ab2d..9f82ce0fcaa5 100644
> > > --- a/net/ipv4/netfilter/arp_tables.c
> > > +++ b/net/ipv4/netfilter/arp_tables.c
> > > @@ -684,12 +684,11 @@ static int copy_entries_to_user(unsigned int total_size,
> > >
> > > loc_cpu_entry = private->entries;
> > >
> > > - /* FIXME: use iterator macros --RR */
> > > - /* ... then go back and fix counters and names */
> > > - for (off = 0, num = 0; off < total_size; off += e->next_offset, num++){
> > > + num = 0;
> > > + xt_entry_foreach(e, loc_cpu_entry, total_size) {
> > > const struct xt_entry_target *t;
> > >
> > > - e = loc_cpu_entry + off;
> > > + off = (unsigned char *)e - (unsigned char *)loc_cpu_entry;
> >
> > This offset calculation makes me feel queasy.
> >
> > Can the code start with off = 0 and increment it by e->next_offset
> > as the loop iterates, as was the case before this patch?
> > It would be similar to how num is handled.
>
> I think this file should just be left alone resp. should be restricted
> to bug fixes only. Same for ip/ip6/ebtables.
>
> Its too early to remove this file from the tree, but I don't see
> value in making cosmetic improvements, sorry.
Thanks Florian,
No objection to that approach from my side.
© 2016 - 2026 Red Hat, Inc.