Skip to content

Commit 744d5a3

Browse files
ebirgerdavem330
authored andcommitted
net: move skb->dropcount to skb->cb[]
Commit 9777500 ("af_packet: add interframe drop cmsg (v6)") unionized skb->mark and skb->dropcount in order to allow recording of the socket drop count while maintaining struct sk_buff size. skb->dropcount was introduced since there was no available room in skb->cb[] in packet sockets. However, its introduction led to the inability to export skb->mark, or any other aliased field to userspace if so desired. Moving the dropcount metric to skb->cb[] eliminates this problem at the expense of 4 bytes less in skb->cb[] for protocol families using it. Signed-off-by: Eyal Birger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3bc3b96 commit 744d5a3

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

include/linux/skbuff.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ static inline u32 skb_mstamp_us_delta(const struct skb_mstamp *t1,
492492
* @napi_id: id of the NAPI struct this skb came from
493493
* @secmark: security marking
494494
* @mark: Generic packet mark
495-
* @dropcount: total number of sk_receive_queue overflows
496495
* @vlan_proto: vlan encapsulation protocol
497496
* @vlan_tci: vlan tag control information
498497
* @inner_protocol: Protocol (encapsulation)
@@ -641,7 +640,6 @@ struct sk_buff {
641640
#endif
642641
union {
643642
__u32 mark;
644-
__u32 dropcount;
645643
__u32 reserved_tailroom;
646644
};
647645

include/net/sock.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,13 +2078,27 @@ static inline int sock_intr_errno(long timeo)
20782078
return timeo == MAX_SCHEDULE_TIMEOUT ? -ERESTARTSYS : -EINTR;
20792079
}
20802080

2081+
struct sock_skb_cb {
2082+
u32 dropcount;
2083+
};
2084+
2085+
/* Store sock_skb_cb at the end of skb->cb[] so protocol families
2086+
* using skb->cb[] would keep using it directly and utilize its
2087+
* alignement guarantee.
2088+
*/
2089+
#define SOCK_SKB_CB_OFFSET ((FIELD_SIZEOF(struct sk_buff, cb) - \
2090+
sizeof(struct sock_skb_cb)))
2091+
2092+
#define SOCK_SKB_CB(__skb) ((struct sock_skb_cb *)((__skb)->cb + \
2093+
SOCK_SKB_CB_OFFSET))
2094+
20812095
#define sock_skb_cb_check_size(size) \
2082-
BUILD_BUG_ON((size) > FIELD_SIZEOF(struct sk_buff, cb))
2096+
BUILD_BUG_ON((size) > SOCK_SKB_CB_OFFSET)
20832097

20842098
static inline void
20852099
sock_skb_set_dropcount(const struct sock *sk, struct sk_buff *skb)
20862100
{
2087-
skb->dropcount = atomic_read(&sk->sk_drops);
2101+
SOCK_SKB_CB(skb)->dropcount = atomic_read(&sk->sk_drops);
20882102
}
20892103

20902104
void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,

net/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,9 @@ EXPORT_SYMBOL_GPL(__sock_recv_wifi_status);
731731
static inline void sock_recv_drops(struct msghdr *msg, struct sock *sk,
732732
struct sk_buff *skb)
733733
{
734-
if (sock_flag(sk, SOCK_RXQ_OVFL) && skb && skb->dropcount)
734+
if (sock_flag(sk, SOCK_RXQ_OVFL) && skb && SOCK_SKB_CB(skb)->dropcount)
735735
put_cmsg(msg, SOL_SOCKET, SO_RXQ_OVFL,
736-
sizeof(__u32), &skb->dropcount);
736+
sizeof(__u32), &SOCK_SKB_CB(skb)->dropcount);
737737
}
738738

739739
void __sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,

0 commit comments

Comments
 (0)