提交 a5135bcf 编写于 作者: W Willem de Bruijn 提交者: David S. Miller

net-tc: convert tc_verd to integer bitfields

Extract the remaining two fields from tc_verd and remove the __u16
completely. TC_AT and TC_FROM are converted to equivalent two-bit
integer fields tc_at and tc_from. Where possible, use existing
helper skb_at_tc_ingress when reading tc_at. Introduce helper
skb_reset_tc to clear fields.

Not documenting tc_from and tc_at, because they will be replaced
with single bit fields in follow-on patches.
Signed-off-by: NWillem de Bruijn <willemb@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 e7246e12
...@@ -78,9 +78,9 @@ static void ifb_ri_tasklet(unsigned long _txp) ...@@ -78,9 +78,9 @@ static void ifb_ri_tasklet(unsigned long _txp)
} }
while ((skb = __skb_dequeue(&txp->tq)) != NULL) { while ((skb = __skb_dequeue(&txp->tq)) != NULL) {
u32 from = G_TC_FROM(skb->tc_verd); u32 from = skb->tc_from;
skb->tc_verd = 0; skb_reset_tc(skb);
skb->tc_skip_classify = 1; skb->tc_skip_classify = 1;
u64_stats_update_begin(&txp->tsync); u64_stats_update_begin(&txp->tsync);
...@@ -239,7 +239,6 @@ static void ifb_setup(struct net_device *dev) ...@@ -239,7 +239,6 @@ static void ifb_setup(struct net_device *dev)
static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev) static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct ifb_dev_private *dp = netdev_priv(dev); struct ifb_dev_private *dp = netdev_priv(dev);
u32 from = G_TC_FROM(skb->tc_verd);
struct ifb_q_private *txp = dp->tx_private + skb_get_queue_mapping(skb); struct ifb_q_private *txp = dp->tx_private + skb_get_queue_mapping(skb);
u64_stats_update_begin(&txp->rsync); u64_stats_update_begin(&txp->rsync);
...@@ -247,7 +246,7 @@ static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -247,7 +246,7 @@ static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
txp->rx_bytes += skb->len; txp->rx_bytes += skb->len;
u64_stats_update_end(&txp->rsync); u64_stats_update_end(&txp->rsync);
if (!(from & (AT_INGRESS|AT_EGRESS)) || !skb->skb_iif) { if (skb->tc_from == AT_STACK || !skb->skb_iif) {
dev_kfree_skb(skb); dev_kfree_skb(skb);
dev->stats.rx_dropped++; dev->stats.rx_dropped++;
return NETDEV_TX_OK; return NETDEV_TX_OK;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#endif /* CONFIG_XFRM */ #endif /* CONFIG_XFRM */
#include <linux/atomic.h> #include <linux/atomic.h>
#include <net/sch_generic.h>
#include <asm/octeon/octeon.h> #include <asm/octeon/octeon.h>
...@@ -369,9 +370,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -369,9 +370,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
#ifdef CONFIG_NET_SCHED #ifdef CONFIG_NET_SCHED
skb->tc_index = 0; skb->tc_index = 0;
#ifdef CONFIG_NET_CLS_ACT skb_reset_tc(skb);
skb->tc_verd = 0;
#endif /* CONFIG_NET_CLS_ACT */
#endif /* CONFIG_NET_SCHED */ #endif /* CONFIG_NET_SCHED */
#endif /* REUSE_SKBUFFS_WITHOUT_FREE */ #endif /* REUSE_SKBUFFS_WITHOUT_FREE */
......
...@@ -599,7 +599,6 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1, ...@@ -599,7 +599,6 @@ static inline bool skb_mstamp_after(const struct skb_mstamp *t1,
* @nf_bridge: Saved data about a bridged frame - see br_netfilter.c * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
* @skb_iif: ifindex of device we arrived on * @skb_iif: ifindex of device we arrived on
* @tc_index: Traffic control index * @tc_index: Traffic control index
* @tc_verd: traffic control verdict
* @hash: the packet hash * @hash: the packet hash
* @queue_mapping: Queue mapping for multiqueue devices * @queue_mapping: Queue mapping for multiqueue devices
* @xmit_more: More SKBs are pending for this queue * @xmit_more: More SKBs are pending for this queue
...@@ -752,13 +751,12 @@ struct sk_buff { ...@@ -752,13 +751,12 @@ struct sk_buff {
#endif #endif
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
__u8 tc_skip_classify:1; __u8 tc_skip_classify:1;
__u8 tc_at:2;
__u8 tc_from:2;
#endif #endif
#ifdef CONFIG_NET_SCHED #ifdef CONFIG_NET_SCHED
__u16 tc_index; /* traffic control index */ __u16 tc_index; /* traffic control index */
#ifdef CONFIG_NET_CLS_ACT
__u16 tc_verd; /* traffic control verdict */
#endif
#endif #endif
union { union {
......
...@@ -409,10 +409,18 @@ bool tcf_destroy(struct tcf_proto *tp, bool force); ...@@ -409,10 +409,18 @@ bool tcf_destroy(struct tcf_proto *tp, bool force);
void tcf_destroy_chain(struct tcf_proto __rcu **fl); void tcf_destroy_chain(struct tcf_proto __rcu **fl);
int skb_do_redirect(struct sk_buff *); int skb_do_redirect(struct sk_buff *);
static inline void skb_reset_tc(struct sk_buff *skb)
{
#ifdef CONFIG_NET_CLS_ACT
skb->tc_at = 0;
skb->tc_from = 0;
#endif
}
static inline bool skb_at_tc_ingress(const struct sk_buff *skb) static inline bool skb_at_tc_ingress(const struct sk_buff *skb)
{ {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
return G_TC_AT(skb->tc_verd) & AT_INGRESS; return skb->tc_at & AT_INGRESS;
#else #else
return false; return false;
#endif #endif
......
...@@ -5,40 +5,9 @@ ...@@ -5,40 +5,9 @@
#include <linux/pkt_sched.h> #include <linux/pkt_sched.h>
#ifdef __KERNEL__ #ifdef __KERNEL__
/* I think i could have done better macros ; for now this is stolen from
* some arch/mips code - jhs
*/
#define _TC_MAKE32(x) ((x))
#define _TC_MAKEMASK1(n) (_TC_MAKE32(1) << _TC_MAKE32(n))
#define _TC_MAKEMASK(v,n) (_TC_MAKE32((_TC_MAKE32(1)<<(v))-1) << _TC_MAKE32(n))
#define _TC_MAKEVALUE(v,n) (_TC_MAKE32(v) << _TC_MAKE32(n))
#define _TC_GETVALUE(v,n,m) ((_TC_MAKE32(v) & _TC_MAKE32(m)) >> _TC_MAKE32(n))
/* verdict bit breakdown
*
bit 6,7: Where this packet was last seen
0: Above the transmit example at the socket level
1: on the Ingress
2: on the Egress
*
* */
#define S_TC_FROM _TC_MAKE32(6)
#define M_TC_FROM _TC_MAKEMASK(2,S_TC_FROM)
#define G_TC_FROM(x) _TC_GETVALUE(x,S_TC_FROM,M_TC_FROM)
#define V_TC_FROM(x) _TC_MAKEVALUE(x,S_TC_FROM)
#define SET_TC_FROM(v,n) ((V_TC_FROM(n)) | (v & ~M_TC_FROM))
#define AT_STACK 0x0 #define AT_STACK 0x0
#define AT_INGRESS 0x1 #define AT_INGRESS 0x1
#define AT_EGRESS 0x2 #define AT_EGRESS 0x2
#define S_TC_AT _TC_MAKE32(12)
#define M_TC_AT _TC_MAKEMASK(2,S_TC_AT)
#define G_TC_AT(x) _TC_GETVALUE(x,S_TC_AT,M_TC_AT)
#define V_TC_AT(x) _TC_MAKEVALUE(x,S_TC_AT)
#define SET_TC_AT(v,n) ((V_TC_AT(n)) | (v & ~M_TC_AT))
#endif #endif
/* Action attributes */ /* Action attributes */
......
...@@ -3153,7 +3153,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev) ...@@ -3153,7 +3153,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev)
if (!cl) if (!cl)
return skb; return skb;
/* skb->tc_verd and qdisc_skb_cb(skb)->pkt_len were already set /* skb->tc_at and qdisc_skb_cb(skb)->pkt_len were already set
* earlier by the caller. * earlier by the caller.
*/ */
qdisc_bstats_cpu_update(cl->q, skb); qdisc_bstats_cpu_update(cl->q, skb);
...@@ -3320,7 +3320,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv) ...@@ -3320,7 +3320,7 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
qdisc_pkt_len_init(skb); qdisc_pkt_len_init(skb);
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); skb->tc_at = AT_EGRESS;
# ifdef CONFIG_NET_EGRESS # ifdef CONFIG_NET_EGRESS
if (static_key_false(&egress_needed)) { if (static_key_false(&egress_needed)) {
skb = sch_handle_egress(skb, &rc, dev); skb = sch_handle_egress(skb, &rc, dev);
...@@ -3920,7 +3920,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret, ...@@ -3920,7 +3920,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
} }
qdisc_skb_cb(skb)->pkt_len = skb->len; qdisc_skb_cb(skb)->pkt_len = skb->len;
skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS); skb->tc_at = AT_INGRESS;
qdisc_bstats_cpu_update(cl->q, skb); qdisc_bstats_cpu_update(cl->q, skb);
switch (tc_classify(skb, cl, &cl_res, false)) { switch (tc_classify(skb, cl, &cl_res, false)) {
...@@ -4122,9 +4122,7 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc) ...@@ -4122,9 +4122,7 @@ static int __netif_receive_skb_core(struct sk_buff *skb, bool pfmemalloc)
goto out; goto out;
} }
#endif #endif
#ifdef CONFIG_NET_CLS_ACT skb_reset_tc(skb);
skb->tc_verd = 0;
#endif
skip_classify: skip_classify:
if (pfmemalloc && !skb_pfmemalloc_protocol(skb)) if (pfmemalloc && !skb_pfmemalloc_protocol(skb))
goto drop; goto drop;
......
...@@ -3439,9 +3439,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev) ...@@ -3439,9 +3439,7 @@ static void pktgen_xmit(struct pktgen_dev *pkt_dev)
/* skb was 'freed' by stack, so clean few /* skb was 'freed' by stack, so clean few
* bits and reuse it * bits and reuse it
*/ */
#ifdef CONFIG_NET_CLS_ACT skb_reset_tc(skb);
skb->tc_verd = 0; /* reset reclass/redir ttl */
#endif
} while (--burst > 0); } while (--burst > 0);
goto out; /* Skips xmit_mode M_START_XMIT */ goto out; /* Skips xmit_mode M_START_XMIT */
} else if (pkt_dev->xmit_mode == M_QUEUE_XMIT) { } else if (pkt_dev->xmit_mode == M_QUEUE_XMIT) {
......
...@@ -878,9 +878,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old) ...@@ -878,9 +878,6 @@ static void __copy_skb_header(struct sk_buff *new, const struct sk_buff *old)
#endif #endif
#ifdef CONFIG_NET_SCHED #ifdef CONFIG_NET_SCHED
CHECK_SKB_FIELD(tc_index); CHECK_SKB_FIELD(tc_index);
#ifdef CONFIG_NET_CLS_ACT
CHECK_SKB_FIELD(tc_verd);
#endif
#endif #endif
} }
......
...@@ -736,12 +736,11 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, ...@@ -736,12 +736,11 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
u16 metalen = ife_get_sz(skb, ife); u16 metalen = ife_get_sz(skb, ife);
int hdrm = metalen + skb->dev->hard_header_len + IFE_METAHDRLEN; int hdrm = metalen + skb->dev->hard_header_len + IFE_METAHDRLEN;
unsigned int skboff = skb->dev->hard_header_len; unsigned int skboff = skb->dev->hard_header_len;
u32 at = G_TC_AT(skb->tc_verd);
int new_len = skb->len + hdrm; int new_len = skb->len + hdrm;
bool exceed_mtu = false; bool exceed_mtu = false;
int err; int err;
if (at & AT_EGRESS) { if (!skb_at_tc_ingress(skb)) {
if (new_len > skb->dev->mtu) if (new_len > skb->dev->mtu)
exceed_mtu = true; exceed_mtu = true;
} }
...@@ -773,7 +772,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, ...@@ -773,7 +772,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
return TC_ACT_SHOT; return TC_ACT_SHOT;
} }
if (!(at & AT_EGRESS)) if (skb_at_tc_ingress(skb))
skb_push(skb, skb->dev->hard_header_len); skb_push(skb, skb->dev->hard_header_len);
iethh = (struct ethhdr *)skb->data; iethh = (struct ethhdr *)skb->data;
...@@ -816,7 +815,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, ...@@ -816,7 +815,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,
ether_addr_copy(oethh->h_dest, iethh->h_dest); ether_addr_copy(oethh->h_dest, iethh->h_dest);
oethh->h_proto = htons(ife->eth_type); oethh->h_proto = htons(ife->eth_type);
if (!(at & AT_EGRESS)) if (skb_at_tc_ingress(skb))
skb_pull(skb, skb->dev->hard_header_len); skb_pull(skb, skb->dev->hard_header_len);
spin_unlock(&ife->tcf_lock); spin_unlock(&ife->tcf_lock);
......
...@@ -170,7 +170,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a, ...@@ -170,7 +170,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
int retval, err = 0; int retval, err = 0;
int m_eaction; int m_eaction;
int mac_len; int mac_len;
u32 at;
tcf_lastuse_update(&m->tcf_tm); tcf_lastuse_update(&m->tcf_tm);
bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb); bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
...@@ -191,7 +190,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a, ...@@ -191,7 +190,6 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
goto out; goto out;
} }
at = G_TC_AT(skb->tc_verd);
skb2 = skb_clone(skb, GFP_ATOMIC); skb2 = skb_clone(skb, GFP_ATOMIC);
if (!skb2) if (!skb2)
goto out; goto out;
...@@ -200,8 +198,9 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a, ...@@ -200,8 +198,9 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
* and devices expect a mac header on xmit, then mac push/pull is * and devices expect a mac header on xmit, then mac push/pull is
* needed. * needed.
*/ */
if (at != tcf_mirred_act_direction(m_eaction) && m_mac_header_xmit) { if (skb->tc_at != tcf_mirred_act_direction(m_eaction) &&
if (at & AT_EGRESS) { m_mac_header_xmit) {
if (!skb_at_tc_ingress(skb)) {
/* caught at egress, act ingress: pull mac */ /* caught at egress, act ingress: pull mac */
mac_len = skb_network_header(skb) - skb_mac_header(skb); mac_len = skb_network_header(skb) - skb_mac_header(skb);
skb_pull_rcsum(skb2, mac_len); skb_pull_rcsum(skb2, mac_len);
...@@ -213,7 +212,7 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a, ...@@ -213,7 +212,7 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
/* mirror is always swallowed */ /* mirror is always swallowed */
if (tcf_mirred_is_act_redirect(m_eaction)) if (tcf_mirred_is_act_redirect(m_eaction))
skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at); skb2->tc_from = skb2->tc_at;
skb2->skb_iif = skb->dev->ifindex; skb2->skb_iif = skb->dev->ifindex;
skb2->dev = dev; skb2->dev = dev;
......
...@@ -626,7 +626,7 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch) ...@@ -626,7 +626,7 @@ static struct sk_buff *netem_dequeue(struct Qdisc *sch)
* If it's at ingress let's pretend the delay is * If it's at ingress let's pretend the delay is
* from the network (tstamp will be updated). * from the network (tstamp will be updated).
*/ */
if (G_TC_FROM(skb->tc_verd) & AT_INGRESS) if (skb->tc_from & AT_INGRESS)
skb->tstamp = 0; skb->tstamp = 0;
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册