Skip to content

Commit 2c64605

Browse files
ummakynesdavem330
authored andcommitted
net: Fix CONFIG_NET_CLS_ACT=n and CONFIG_NFT_FWD_NETDEV={y, m} build
net/netfilter/nft_fwd_netdev.c: In function ‘nft_fwd_netdev_eval’: net/netfilter/nft_fwd_netdev.c:32:10: error: ‘struct sk_buff’ has no member named ‘tc_redirected’ pkt->skb->tc_redirected = 1; ^~ net/netfilter/nft_fwd_netdev.c:33:10: error: ‘struct sk_buff’ has no member named ‘tc_from_ingress’ pkt->skb->tc_from_ingress = 1; ^~ To avoid a direct dependency with tc actions from netfilter, wrap the redirect bits around CONFIG_NET_REDIRECT and move helpers to include/linux/skbuff.h. Turn on this toggle from the ifb driver, the only existing client of these bits in the tree. This patch adds skb_set_redirected() that sets on the redirected bit on the skbuff, it specifies if the packet was redirect from ingress and resets the timestamp (timestamp reset was originally missing in the netfilter bugfix). Fixes: bcfabee ("netfilter: nft_fwd_netdev: allow to redirect to ifb via ingress") Reported-by: [email protected] Reported-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 428c491 commit 2c64605

File tree

10 files changed

+47
-34
lines changed

10 files changed

+47
-34
lines changed

drivers/net/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ config NET_FC
149149
config IFB
150150
tristate "Intermediate Functional Block support"
151151
depends on NET_CLS_ACT
152+
select NET_REDIRECT
152153
---help---
153154
This is an intermediate driver that allows sharing of
154155
resources.

drivers/net/ifb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void ifb_ri_tasklet(unsigned long _txp)
7575
}
7676

7777
while ((skb = __skb_dequeue(&txp->tq)) != NULL) {
78-
skb->tc_redirected = 0;
78+
skb->redirected = 0;
7979
skb->tc_skip_classify = 1;
8080

8181
u64_stats_update_begin(&txp->tsync);
@@ -96,7 +96,7 @@ static void ifb_ri_tasklet(unsigned long _txp)
9696
rcu_read_unlock();
9797
skb->skb_iif = txp->dev->ifindex;
9898

99-
if (!skb->tc_from_ingress) {
99+
if (!skb->from_ingress) {
100100
dev_queue_xmit(skb);
101101
} else {
102102
skb_pull_rcsum(skb, skb->mac_len);
@@ -243,7 +243,7 @@ static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
243243
txp->rx_bytes += skb->len;
244244
u64_stats_update_end(&txp->rsync);
245245

246-
if (!skb->tc_redirected || !skb->skb_iif) {
246+
if (!skb->redirected || !skb->skb_iif) {
247247
dev_kfree_skb(skb);
248248
dev->stats.rx_dropped++;
249249
return NETDEV_TX_OK;

drivers/net/wireguard/queueing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ static inline void wg_reset_packet(struct sk_buff *skb)
100100
skb->dev = NULL;
101101
#ifdef CONFIG_NET_SCHED
102102
skb->tc_index = 0;
103-
skb_reset_tc(skb);
104103
#endif
104+
skb_reset_redirect(skb);
105105
skb->hdr_len = skb_headroom(skb);
106106
skb_reset_mac_header(skb);
107107
skb_reset_network_header(skb);

include/linux/skbuff.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ typedef unsigned char *sk_buff_data_t;
645645
* @offload_l3_fwd_mark: Packet was L3-forwarded in hardware
646646
* @tc_skip_classify: do not classify packet. set by IFB device
647647
* @tc_at_ingress: used within tc_classify to distinguish in/egress
648-
* @tc_redirected: packet was redirected by a tc action
649-
* @tc_from_ingress: if tc_redirected, tc_at_ingress at time of redirect
648+
* @redirected: packet was redirected by packet classifier
649+
* @from_ingress: packet was redirected from the ingress path
650650
* @peeked: this packet has been seen already, so stats have been
651651
* done for it, don't do them again
652652
* @nf_trace: netfilter packet trace flag
@@ -848,8 +848,10 @@ struct sk_buff {
848848
#ifdef CONFIG_NET_CLS_ACT
849849
__u8 tc_skip_classify:1;
850850
__u8 tc_at_ingress:1;
851-
__u8 tc_redirected:1;
852-
__u8 tc_from_ingress:1;
851+
#endif
852+
#ifdef CONFIG_NET_REDIRECT
853+
__u8 redirected:1;
854+
__u8 from_ingress:1;
853855
#endif
854856
#ifdef CONFIG_TLS_DEVICE
855857
__u8 decrypted:1;
@@ -4579,5 +4581,31 @@ static inline __wsum lco_csum(struct sk_buff *skb)
45794581
return csum_partial(l4_hdr, csum_start - l4_hdr, partial);
45804582
}
45814583

4584+
static inline bool skb_is_redirected(const struct sk_buff *skb)
4585+
{
4586+
#ifdef CONFIG_NET_REDIRECT
4587+
return skb->redirected;
4588+
#else
4589+
return false;
4590+
#endif
4591+
}
4592+
4593+
static inline void skb_set_redirected(struct sk_buff *skb, bool from_ingress)
4594+
{
4595+
#ifdef CONFIG_NET_REDIRECT
4596+
skb->redirected = 1;
4597+
skb->from_ingress = from_ingress;
4598+
if (skb->from_ingress)
4599+
skb->tstamp = 0;
4600+
#endif
4601+
}
4602+
4603+
static inline void skb_reset_redirect(struct sk_buff *skb)
4604+
{
4605+
#ifdef CONFIG_NET_REDIRECT
4606+
skb->redirected = 0;
4607+
#endif
4608+
}
4609+
45824610
#endif /* __KERNEL__ */
45834611
#endif /* _LINUX_SKBUFF_H */

include/net/sch_generic.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -675,22 +675,6 @@ void __qdisc_calculate_pkt_len(struct sk_buff *skb,
675675
const struct qdisc_size_table *stab);
676676
int skb_do_redirect(struct sk_buff *);
677677

678-
static inline void skb_reset_tc(struct sk_buff *skb)
679-
{
680-
#ifdef CONFIG_NET_CLS_ACT
681-
skb->tc_redirected = 0;
682-
#endif
683-
}
684-
685-
static inline bool skb_is_tc_redirected(const struct sk_buff *skb)
686-
{
687-
#ifdef CONFIG_NET_CLS_ACT
688-
return skb->tc_redirected;
689-
#else
690-
return false;
691-
#endif
692-
}
693-
694678
static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
695679
{
696680
#ifdef CONFIG_NET_CLS_ACT

net/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ config NET_INGRESS
5252
config NET_EGRESS
5353
bool
5454

55+
config NET_REDIRECT
56+
bool
57+
5558
config SKB_EXTENSIONS
5659
bool
5760

net/core/dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4516,7 +4516,7 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
45164516
/* Reinjected packets coming from act_mirred or similar should
45174517
* not get XDP generic processing.
45184518
*/
4519-
if (skb_is_tc_redirected(skb))
4519+
if (skb_is_redirected(skb))
45204520
return XDP_PASS;
45214521

45224522
/* XDP packets must be linear and must have sufficient headroom
@@ -5063,7 +5063,7 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc,
50635063
goto out;
50645064
}
50655065
#endif
5066-
skb_reset_tc(skb);
5066+
skb_reset_redirect(skb);
50675067
skip_classify:
50685068
if (pfmemalloc && !skb_pfmemalloc_protocol(skb))
50695069
goto drop;

net/core/pktgen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
33623362
/* skb was 'freed' by stack, so clean few
33633363
* bits and reuse it
33643364
*/
3365-
skb_reset_tc(skb);
3365+
skb_reset_redirect(skb);
33663366
} while (--burst > 0);
33673367
goto out; /* Skips xmit_mode M_START_XMIT */
33683368
} else if (pkt_dev->xmit_mode == M_QUEUE_XMIT) {

net/netfilter/nft_fwd_netdev.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ static void nft_fwd_netdev_eval(const struct nft_expr *expr,
2828
struct nft_fwd_netdev *priv = nft_expr_priv(expr);
2929
int oif = regs->data[priv->sreg_dev];
3030

31-
/* These are used by ifb only. */
32-
pkt->skb->tc_redirected = 1;
33-
pkt->skb->tc_from_ingress = 1;
31+
/* This is used by ifb only. */
32+
skb_set_redirected(pkt->skb, true);
3433

3534
nf_fwd_netdev_egress(pkt, oif);
3635
regs->verdict.code = NF_STOLEN;

net/sched/act_mirred.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ static int tcf_mirred_act(struct sk_buff *skb, const struct tc_action *a,
284284

285285
/* mirror is always swallowed */
286286
if (is_redirect) {
287-
skb2->tc_redirected = 1;
288-
skb2->tc_from_ingress = skb2->tc_at_ingress;
289-
if (skb2->tc_from_ingress)
290-
skb2->tstamp = 0;
287+
skb_set_redirected(skb2, skb2->tc_at_ingress);
288+
291289
/* let's the caller reinsert the packet, if possible */
292290
if (use_reinsert) {
293291
res->ingress = want_ingress;

0 commit comments

Comments
 (0)