Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Alexander Drozdov and committed by
David S. Miller
682f048b 68c2e5de

+20 -3
+10 -3
Documentation/networking/packet_mmap.txt
··· 440 440 +++ Capture process: 441 441 from include/linux/if_packet.h 442 442 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) 446 447 447 448 TP_STATUS_COPY : This flag indicates that the frame (and associated 448 449 meta information) has been truncated because it's ··· 466 465 its checksum will be done in hardware. So while 467 466 reading the packet we should not try to check the 468 467 checksum. 468 + 469 + TP_STATUS_CSUM_VALID : This flag indicates that at least the transport 470 + header checksum of the packet has been already 471 + validated on the kernel side. If the flag is not set 472 + then we are free to check the checksum by ourselves 473 + provided that TP_STATUS_CSUMNOTREADY is also not set. 469 474 470 475 for convenience there are also the following defines: 471 476
+1
include/uapi/linux/if_packet.h
··· 99 99 #define TP_STATUS_VLAN_VALID (1 << 4) /* auxdata has valid tp_vlan_tci */ 100 100 #define TP_STATUS_BLK_TMO (1 << 5) 101 101 #define TP_STATUS_VLAN_TPID_VALID (1 << 6) /* auxdata has valid tp_vlan_tpid */ 102 + #define TP_STATUS_CSUM_VALID (1 << 7) 102 103 103 104 /* Tx ring - header status */ 104 105 #define TP_STATUS_AVAILABLE 0
+9
net/packet/af_packet.c
··· 1924 1924 1925 1925 if (skb->ip_summed == CHECKSUM_PARTIAL) 1926 1926 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; 1927 1931 1928 1932 if (snaplen > res) 1929 1933 snaplen = res; ··· 3035 3031 aux.tp_status = TP_STATUS_USER; 3036 3032 if (skb->ip_summed == CHECKSUM_PARTIAL) 3037 3033 aux.tp_status |= TP_STATUS_CSUMNOTREADY; 3034 + else if (skb->pkt_type != PACKET_OUTGOING && 3035 + (skb->ip_summed == CHECKSUM_COMPLETE || 3036 + skb_csum_unnecessary(skb))) 3037 + aux.tp_status |= TP_STATUS_CSUM_VALID; 3038 + 3038 3039 aux.tp_len = origlen; 3039 3040 aux.tp_snaplen = skb->len; 3040 3041 aux.tp_mac = 0;