Skip to content

Commit 7278b3c

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: add and use BE register load-store helpers
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>
1 parent d86473b commit 7278b3c

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

include/net/netfilter/nf_tables.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,26 @@ static inline void nft_reg_store16(u32 *dreg, u16 val)
157157
*(u16 *)dreg = val;
158158
}
159159

160+
static inline void nft_reg_store_be16(u32 *dreg, __be16 val)
161+
{
162+
nft_reg_store16(dreg, (__force __u16)val);
163+
}
164+
160165
static inline u16 nft_reg_load16(const u32 *sreg)
161166
{
162167
return *(u16 *)sreg;
163168
}
164169

170+
static inline __be16 nft_reg_load_be16(const u32 *sreg)
171+
{
172+
return (__force __be16)nft_reg_load16(sreg);
173+
}
174+
175+
static inline __be32 nft_reg_load_be32(const u32 *sreg)
176+
{
177+
return *(__force __be32 *)sreg;
178+
}
179+
165180
static inline void nft_reg_store64(u32 *dreg, u64 val)
166181
{
167182
put_unaligned(val, (u64 *)dreg);

net/bridge/netfilter/nft_meta_bridge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void nft_meta_bridge_get_eval(const struct nft_expr *expr,
5353
goto err;
5454

5555
br_vlan_get_proto(br_dev, &p_proto);
56-
nft_reg_store16(dest, htons(p_proto));
56+
nft_reg_store_be16(dest, htons(p_proto));
5757
return;
5858
}
5959
default:

net/netfilter/nft_tproxy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ static void nft_tproxy_eval_v4(const struct nft_expr *expr,
5252
skb->dev, NF_TPROXY_LOOKUP_ESTABLISHED);
5353

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

5858
if (priv->sreg_port)
59-
tport = nft_reg_load16(&regs->data[priv->sreg_port]);
59+
tport = nft_reg_load_be16(&regs->data[priv->sreg_port]);
6060
if (!tport)
6161
tport = hp->dest;
6262

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

126126
if (priv->sreg_port)
127-
tport = nft_reg_load16(&regs->data[priv->sreg_port]);
127+
tport = nft_reg_load_be16(&regs->data[priv->sreg_port]);
128128
if (!tport)
129129
tport = hp->dest;
130130

0 commit comments

Comments
 (0)