Skip to content

Commit b68b0dd

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: Keep private info in the skb->cb
Map a DSA structure over the 48-byte control block that will hold skb info on transmit and receive. This is only for use within the DSA processing layer (e.g. communicating between DSA core and tagger) and not for passing info around with other layers such as the master net device. Also add a DSA_SKB_CB_PRIV() macro which retrieves a pointer to the space up to 48 bytes that the DSA structure does not use. This space can be used for drivers to add their own private info. One use is for the PTP timestamping code path. When cloning a skb, annotate the original with a pointer to the clone, which the driver can then find easily and place the timestamp to. This avoids the need of a separate queue to hold clones and a way to match an original to a cloned skb. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cc1939e commit b68b0dd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

include/net/dsa.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ struct dsa_device_ops {
8383
#define MODULE_ALIAS_DSA_TAG_DRIVER(__proto) \
8484
MODULE_ALIAS(DSA_TAG_DRIVER_ALIAS __stringify(__proto##_VALUE))
8585

86+
struct dsa_skb_cb {
87+
struct sk_buff *clone;
88+
};
89+
90+
struct __dsa_skb_cb {
91+
struct dsa_skb_cb cb;
92+
u8 priv[48 - sizeof(struct dsa_skb_cb)];
93+
};
94+
95+
#define __DSA_SKB_CB(skb) ((struct __dsa_skb_cb *)((skb)->cb))
96+
97+
#define DSA_SKB_CB(skb) ((struct dsa_skb_cb *)((skb)->cb))
98+
99+
#define DSA_SKB_CB_COPY(nskb, skb) \
100+
{ *__DSA_SKB_CB(nskb) = *__DSA_SKB_CB(skb); }
101+
102+
#define DSA_SKB_CB_ZERO(skb) \
103+
{ *__DSA_SKB_CB(skb) = (struct __dsa_skb_cb) {0}; }
104+
105+
#define DSA_SKB_CB_PRIV(skb) \
106+
((void *)(skb)->cb + offsetof(struct __dsa_skb_cb, priv))
107+
108+
#define DSA_SKB_CB_CLONE(_clone, _skb) \
109+
{ \
110+
struct sk_buff *clone = _clone; \
111+
struct sk_buff *skb = _skb; \
112+
\
113+
DSA_SKB_CB_COPY(clone, skb); \
114+
DSA_SKB_CB(skb)->clone = clone; \
115+
}
116+
86117
struct dsa_switch_tree {
87118
struct list_head list;
88119

0 commit comments

Comments
 (0)