Skip to content

Commit 682f048

Browse files
sorc1davem330
authored andcommitted
af_packet: pass checksum validation status to the user
Introduce TP_STATUS_CSUM_VALID tp_status flag to tell the af_packet user that at least the transport header checksum has been already validated. For now, the flag may be set for incoming packets only. Signed-off-by: Alexander Drozdov <al.drozdov@gmail.com> Cc: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 68c2e5d commit 682f048

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Documentation/networking/packet_mmap.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,10 @@ and the following flags apply:
440440
+++ Capture process:
441441
from include/linux/if_packet.h
442442

443-
#define TP_STATUS_COPY 2
444-
#define TP_STATUS_LOSING 4
445-
#define TP_STATUS_CSUMNOTREADY 8
443+
#define TP_STATUS_COPY (1 << 1)
444+
#define TP_STATUS_LOSING (1 << 2)
445+
#define TP_STATUS_CSUMNOTREADY (1 << 3)
446+
#define TP_STATUS_CSUM_VALID (1 << 7)
446447

447448
TP_STATUS_COPY : This flag indicates that the frame (and associated
448449
meta information) has been truncated because it's
@@ -466,6 +467,12 @@ TP_STATUS_CSUMNOTREADY: currently it's used for outgoing IP packets which
466467
reading the packet we should not try to check the
467468
checksum.
468469

470+
TP_STATUS_CSUM_VALID : This flag indicates that at least the transport
471+
header checksum of the packet has been already
472+
validated on the kernel side. If the flag is not set
473+
then we are free to check the checksum by ourselves
474+
provided that TP_STATUS_CSUMNOTREADY is also not set.
475+
469476
for convenience there are also the following defines:
470477

471478
#define TP_STATUS_KERNEL 0

include/uapi/linux/if_packet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct tpacket_auxdata {
9999
#define TP_STATUS_VLAN_VALID (1 << 4) /* auxdata has valid tp_vlan_tci */
100100
#define TP_STATUS_BLK_TMO (1 << 5)
101101
#define TP_STATUS_VLAN_TPID_VALID (1 << 6) /* auxdata has valid tp_vlan_tpid */
102+
#define TP_STATUS_CSUM_VALID (1 << 7)
102103

103104
/* Tx ring - header status */
104105
#define TP_STATUS_AVAILABLE 0

net/packet/af_packet.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,10 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
19241924

19251925
if (skb->ip_summed == CHECKSUM_PARTIAL)
19261926
status |= TP_STATUS_CSUMNOTREADY;
1927+
else if (skb->pkt_type != PACKET_OUTGOING &&
1928+
(skb->ip_summed == CHECKSUM_COMPLETE ||
1929+
skb_csum_unnecessary(skb)))
1930+
status |= TP_STATUS_CSUM_VALID;
19271931

19281932
if (snaplen > res)
19291933
snaplen = res;
@@ -3031,6 +3035,11 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
30313035
aux.tp_status = TP_STATUS_USER;
30323036
if (skb->ip_summed == CHECKSUM_PARTIAL)
30333037
aux.tp_status |= TP_STATUS_CSUMNOTREADY;
3038+
else if (skb->pkt_type != PACKET_OUTGOING &&
3039+
(skb->ip_summed == CHECKSUM_COMPLETE ||
3040+
skb_csum_unnecessary(skb)))
3041+
aux.tp_status |= TP_STATUS_CSUM_VALID;
3042+
30343043
aux.tp_len = origlen;
30353044
aux.tp_snaplen = skb->len;
30363045
aux.tp_mac = 0;

0 commit comments

Comments
 (0)