Skip to content

Commit e4d26f4

Browse files
iAtsumuWatanabedavem330
authored andcommitted
packet: fill the gap of TPACKET_ALIGNMENT with zeros
struct tpacket{2,3}_hdr is aligned to a multiple of TPACKET_ALIGNMENT. Explicitly defining and zeroing the gap of this makes additional changes easier. Signed-off-by: Atzm Watanabe <atzm@stratosphere.co.jp> Acked-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5184635 commit e4d26f4

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎include/uapi/linux/if_packet.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ struct tpacket2_hdr {
133133
__u32 tp_sec;
134134
__u32 tp_nsec;
135135
__u16 tp_vlan_tci;
136-
__u16 tp_padding;
136+
__u8 tp_padding[6];
137137
};
138138

139139
struct tpacket_hdr_variant1 {
@@ -154,6 +154,7 @@ struct tpacket3_hdr {
154154
union {
155155
struct tpacket_hdr_variant1 hv1;
156156
};
157+
__u8 tp_padding[12];
157158
};
158159

159160
struct tpacket_bd_ts {

‎net/packet/af_packet.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
19291929
} else {
19301930
h.h2->tp_vlan_tci = 0;
19311931
}
1932-
h.h2->tp_padding = 0;
1932+
memset(h.h2->tp_padding, 0, sizeof(h.h2->tp_padding));
19331933
hdrlen = sizeof(*h.h2);
19341934
break;
19351935
case TPACKET_V3:
@@ -1943,6 +1943,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
19431943
h.h3->tp_net = netoff;
19441944
h.h3->tp_sec = ts.tv_sec;
19451945
h.h3->tp_nsec = ts.tv_nsec;
1946+
memset(h.h3->tp_padding, 0, sizeof(h.h3->tp_padding));
19461947
hdrlen = sizeof(*h.h3);
19471948
break;
19481949
default:

0 commit comments

Comments
 (0)