History

net-tc: extract skip classify bit from tc_verd

Packets sent by the IFB device skip subsequent tc classification. A single bit governs this state. Move it out of tc_verd in anticipation of removing that __u16 completely. The new bitfield tc_skip_classify temporarily uses one bit of a hole, until tc_verd is removed completely in a follow-up patch. Remove the bit hole comment. It could be 2, 3, 4 or 5 bits long. With that many options, little value in documenting it. Introduce a helper function to deduplicate the logic in the two sites that check this bit. The field tc_skip_classify is set only in IFB on skbs cloned in act_mirred, so original packet sources do not have to clear the bit when reusing packets (notably, pktgen and octeon).

Willem de Bruijn committed 9 years ago

Commit e7246e11 parent d6264076 files · +23 −22Browse files

Unified · Split

6 files
  1. drivers/net/ifb.c +1 −1
  2. include/linux/skbuff.h +4 −1
  3. include/net/sch_generic.h +11 −0
  4. include/uapi/linux/pkt_cls.h +0 −6
  5. net/core/dev.c +3 −7
  6. net/sched/act_api.c +4 −7
drivers/net/ifb.c+1−1
@@ -81,7 +81,7 @@ static void ifb_ri_tasklet(unsigned long _txp) · 80 unmodified lines
8181 u32 from = G_TC_FROM(skb->tc_verd);
8282
8383 skb->tc_verd = 0;
84− skb->tc_verd = SET_TC_NCLS(skb->tc_verd);
84+ skb->tc_skip_classify = 1;
8585
8686 u64_stats_update_begin(&txp->tsync);
8787 txp->tx_packets++;
include/linux/skbuff.h+4−1
@@ -589,6 +589,7 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1, · 588 unmodified lines
589589 * @pkt_type: Packet class
590590 * @fclone: skbuff clone status
591591 * @ipvs_property: skbuff is owned by ipvs
592+ * @tc_skip_classify: do not classify packet. set by IFB device
592593 * @peeked: this packet has been seen already, so stats have been
593594 * done for it, don't do them again
594595 * @nf_trace: netfilter packet trace flag
@@ -749,7 +750,9 @@ struct sk_buff { · 154 unmodified lines
749750 #ifdef CONFIG_NET_SWITCHDEV
750751 __u8 offload_fwd_mark:1;
751752 #endif
752− /* 2, 4 or 5 bit hole */
753+#ifdef CONFIG_NET_CLS_ACT
754+ __u8 tc_skip_classify:1;
755+#endif
753756
754757 #ifdef CONFIG_NET_SCHED
755758 __u16 tc_index; /* traffic control index */
include/net/sch_generic.h+11−0
@@ -418,6 +418,17 @@ static inline bool skb_at_tc_ingress(const struct sk_buff *skb) · 417 unmodified lines
418418 #endif
419419 }
420420
421+static inline bool skb_skip_tc_classify(struct sk_buff *skb)
422+{
423+#ifdef CONFIG_NET_CLS_ACT
424+ if (skb->tc_skip_classify) {
425+ skb->tc_skip_classify = 0;
426+ return true;
427+ }
428+#endif
429+ return false;
430+}
431+
421432 /* Reset all TX qdiscs greater then index of a device. */
422433 static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i)
423434 {
include/uapi/linux/pkt_cls.h+0−6
@@ -22,8 +22,6 @@ bit 6,7: Where this packet was last seen · 21 unmodified lines
2222 1: on the Ingress
2323 2: on the Egress
2424
25−bit 8: when set --> Request not to classify on ingress.
26−
2725 *
2826 * */
2927
@@ -36,10 +34,6 @@ bit 8: when set --> Request not to classify on ingress. · 6 unmodified lines
3634 #define AT_INGRESS 0x1
3735 #define AT_EGRESS 0x2
3836
39−#define TC_NCLS _TC_MAKEMASK1(8)
40−#define SET_TC_NCLS(v) ( TC_NCLS | (v & ~TC_NCLS))
41−#define CLR_TC_NCLS(v) ( v & ~TC_NCLS)
42−
4337 #define S_TC_AT _TC_MAKE32(12)
4438 #define M_TC_AT _TC_MAKEMASK(2,S_TC_AT)
4539 #define G_TC_AT(x) _TC_GETVALUE(x,S_TC_AT,M_TC_AT)
net/core/dev.c+3−7
@@ -4093,12 +4093,8 @@ another_round: · 4092 unmodified lines
40934093 goto out;
40944094 }
40954095
4096−#ifdef CONFIG_NET_CLS_ACT
4097− if (skb->tc_verd & TC_NCLS) {
4098− skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
4099− goto ncls;
4100− }
4101−#endif
4096+ if (skb_skip_tc_classify(skb))
4097+ goto skip_classify;
41024098
41034099 if (pfmemalloc)
41044100 goto skip_taps;
@@ -4128,8 +4124,8 @@ skip_taps: · 23 unmodified lines
41284124 #endif
41294125 #ifdef CONFIG_NET_CLS_ACT
41304126 skb->tc_verd = 0;
4131−ncls:
41324127 #endif
4128+skip_classify:
41334129 if (pfmemalloc && !skb_pfmemalloc_protocol(skb))
41344130 goto drop;
41354131
net/sched/act_api.c+4−7
@@ -426,11 +426,9 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, · 425 unmodified lines
426426 {
427427 int ret = -1, i;
428428
429− if (skb->tc_verd & TC_NCLS) {
430− skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
431− ret = TC_ACT_OK;
432− goto exec_done;
433− }
429+ if (skb_skip_tc_classify(skb))
430+ return TC_ACT_OK;
431+
434432 for (i = 0; i < nr_actions; i++) {
435433 const struct tc_action *a = actions[i];
436434
@@ -439,9 +437,8 @@ repeat: · 2 unmodified lines
439437 if (ret == TC_ACT_REPEAT)
440438 goto repeat; /* we need a ttl - JHS */
441439 if (ret != TC_ACT_PIPE)
442− goto exec_done;
440+ break;
443441 }
444−exec_done:
445442 return ret;
446443 }
447444 EXPORT_SYMBOL(tcf_action_exec);