Skip to contentSkip to conversation

packet: make aligned size of struct tpacket{2,3}_hdr clear

PATCH In review Atzm Watanabe 2 participants 2 messages Dec 17, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 packet: make aligned size of struct tpacket{2,3}_hdr clear

struct tpacket{2,3}_hdr is aligned to a multiple of TPACKET_ALIGNMENT. We may add members to them until current aligned size without forcing userspace to call getsockopt(..., PACKET_HDRLEN, ...).

---
 net/packet/af_packet.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/packet/af_packet.c +7 -0
index cc803c6..c6baa59 100644
@@ -1812,6 +1812,13 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
 	struct timespec ts;
 	__u32 ts_status;
 
+	/* struct tpacket{2,3}_hdr is aligned to a multiple of TPACKET_ALIGNMENT.
+	 * We may add members to them until current aligned size without forcing
+	 * userspace to call getsockopt(..., PACKET_HDRLEN, ...).
+	 */
+	BUILD_BUG_ON(TPACKET_ALIGN(sizeof(*h.h2)) != 32);
+	BUILD_BUG_ON(TPACKET_ALIGN(sizeof(*h.h3)) != 48);
+
 	if (skb->pkt_type == PACKET_LOOPBACK)
 		goto drop;
 
Signature · 1 line
1.8.1.5