Skip to content

Commit

Permalink
netfilter: nf_tables: add and use BE register load-store helpers
Browse files Browse the repository at this point in the history
Same as the existing ones, no conversions. This is just for sparse sake
only so that we no longer mix be16/u16 and be32/u32 types.

Alternative is to add __force __beX in various places, but this
seems nicer.

objdiff shows no changes.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Florian Westphal authored and ummakynes committed Jul 11, 2022
1 parent d86473b commit 7278b3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions include/net/netfilter/nf_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,26 @@ static inline void nft_reg_store16(u32 *dreg, u16 val)
*(u16 *)dreg = val;
}

static inline void nft_reg_store_be16(u32 *dreg, __be16 val)
{
nft_reg_store16(dreg, (__force __u16)val);
}

static inline u16 nft_reg_load16(const u32 *sreg)
{
return *(u16 *)sreg;
}

static inline __be16 nft_reg_load_be16(const u32 *sreg)
{
return (__force __be16)nft_reg_load16(sreg);
}

static inline __be32 nft_reg_load_be32(const u32 *sreg)
{
return *(__force __be32 *)sreg;
}

static inline void nft_reg_store64(u32 *dreg, u64 val)
{
put_unaligned(val, (u64 *)dreg);
Expand Down
2 changes: 1 addition & 1 deletion net/bridge/netfilter/nft_meta_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,
goto err;

br_vlan_get_proto(br_dev, &p_proto);
nft_reg_store16(dest, htons(p_proto));
nft_reg_store_be16(dest, htons(p_proto));
return;
}
default:
Expand Down
6 changes: 3 additions & 3 deletions net/netfilter/nft_tproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ static void nft_tproxy_eval_v4(const struct nft_expr *expr,
skb->dev, NF_TPROXY_LOOKUP_ESTABLISHED);

if (priv->sreg_addr)
taddr = regs->data[priv->sreg_addr];
taddr = nft_reg_load_be32(&regs->data[priv->sreg_addr]);
taddr = nf_tproxy_laddr4(skb, taddr, iph->daddr);

if (priv->sreg_port)
tport = nft_reg_load16(&regs->data[priv->sreg_port]);
tport = nft_reg_load_be16(&regs->data[priv->sreg_port]);
if (!tport)
tport = hp->dest;

Expand Down Expand Up @@ -124,7 +124,7 @@ static void nft_tproxy_eval_v6(const struct nft_expr *expr,
taddr = *nf_tproxy_laddr6(skb, &taddr, &iph->daddr);

if (priv->sreg_port)
tport = nft_reg_load16(&regs->data[priv->sreg_port]);
tport = nft_reg_load_be16(&regs->data[priv->sreg_port]);
if (!tport)
tport = hp->dest;

Expand Down

0 comments on commit 7278b3c

Please sign in to comment.