Skip to content

Commit e633508

Browse files
Phil Sutterummakynes
authored andcommitted
netfilter: nft_fib: Fix existence check support
NFTA_FIB_F_PRESENT flag was not always honored since eval functions did not call nft_fib_store_result in all cases. Given that in all callsites there is a struct net_device pointer available which holds the interface data to be stored in destination register, simplify nft_fib_store_result() to just accept that pointer instead of the nft_pktinfo pointer and interface index. This also allows to drop the index to interface lookup previously needed to get the name associated with given index. Fixes: 055c4b3 ("netfilter: nft_fib: Support existence check") Signed-off-by: Phil Sutter <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 946c0d8 commit e633508

File tree

4 files changed

+9
-38
lines changed

4 files changed

+9
-38
lines changed

include/net/netfilter/nft_fib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
3434
const struct nft_pktinfo *pkt);
3535

3636
void nft_fib_store_result(void *reg, const struct nft_fib *priv,
37-
const struct nft_pktinfo *pkt, int index);
37+
const struct net_device *dev);
3838
#endif

net/ipv4/netfilter/nft_fib_ipv4.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs,
5858
}
5959
EXPORT_SYMBOL_GPL(nft_fib4_eval_type);
6060

61-
static int get_ifindex(const struct net_device *dev)
62-
{
63-
return dev ? dev->ifindex : 0;
64-
}
65-
6661
void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
6762
const struct nft_pktinfo *pkt)
6863
{
@@ -94,8 +89,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
9489

9590
if (nft_hook(pkt) == NF_INET_PRE_ROUTING &&
9691
nft_fib_is_loopback(pkt->skb, nft_in(pkt))) {
97-
nft_fib_store_result(dest, priv, pkt,
98-
nft_in(pkt)->ifindex);
92+
nft_fib_store_result(dest, priv, nft_in(pkt));
9993
return;
10094
}
10195

@@ -108,8 +102,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
108102
if (ipv4_is_zeronet(iph->saddr)) {
109103
if (ipv4_is_lbcast(iph->daddr) ||
110104
ipv4_is_local_multicast(iph->daddr)) {
111-
nft_fib_store_result(dest, priv, pkt,
112-
get_ifindex(pkt->skb->dev));
105+
nft_fib_store_result(dest, priv, pkt->skb->dev);
113106
return;
114107
}
115108
}
@@ -150,17 +143,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
150143
found = oif;
151144
}
152145

153-
switch (priv->result) {
154-
case NFT_FIB_RESULT_OIF:
155-
*dest = found->ifindex;
156-
break;
157-
case NFT_FIB_RESULT_OIFNAME:
158-
strncpy((char *)dest, found->name, IFNAMSIZ);
159-
break;
160-
default:
161-
WARN_ON_ONCE(1);
162-
break;
163-
}
146+
nft_fib_store_result(dest, priv, found);
164147
}
165148
EXPORT_SYMBOL_GPL(nft_fib4_eval);
166149

net/ipv6/netfilter/nft_fib_ipv6.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
169169

170170
if (nft_hook(pkt) == NF_INET_PRE_ROUTING &&
171171
nft_fib_is_loopback(pkt->skb, nft_in(pkt))) {
172-
nft_fib_store_result(dest, priv, pkt,
173-
nft_in(pkt)->ifindex);
172+
nft_fib_store_result(dest, priv, nft_in(pkt));
174173
return;
175174
}
176175

@@ -187,18 +186,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
187186
if (oif && oif != rt->rt6i_idev->dev)
188187
goto put_rt_err;
189188

190-
switch (priv->result) {
191-
case NFT_FIB_RESULT_OIF:
192-
*dest = rt->rt6i_idev->dev->ifindex;
193-
break;
194-
case NFT_FIB_RESULT_OIFNAME:
195-
strncpy((char *)dest, rt->rt6i_idev->dev->name, IFNAMSIZ);
196-
break;
197-
default:
198-
WARN_ON_ONCE(1);
199-
break;
200-
}
201-
189+
nft_fib_store_result(dest, priv, rt->rt6i_idev->dev);
202190
put_rt_err:
203191
ip6_rt_put(rt);
204192
}

net/netfilter/nft_fib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr)
135135
EXPORT_SYMBOL_GPL(nft_fib_dump);
136136

137137
void nft_fib_store_result(void *reg, const struct nft_fib *priv,
138-
const struct nft_pktinfo *pkt, int index)
138+
const struct net_device *dev)
139139
{
140-
struct net_device *dev;
141140
u32 *dreg = reg;
141+
int index;
142142

143143
switch (priv->result) {
144144
case NFT_FIB_RESULT_OIF:
145+
index = dev ? dev->ifindex : 0;
145146
*dreg = (priv->flags & NFTA_FIB_F_PRESENT) ? !!index : index;
146147
break;
147148
case NFT_FIB_RESULT_OIFNAME:
148-
dev = dev_get_by_index_rcu(nft_net(pkt), index);
149149
if (priv->flags & NFTA_FIB_F_PRESENT)
150150
*dreg = !!dev;
151151
else

0 commit comments

Comments
 (0)