aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Drozdov <al.drozdov@gmail.com>2015-03-23 02:11:13 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-23 22:01:28 -0400
commit682f048bd49449f4ab978664a7f69a44a74e3caa (patch)
tree4b623e8ddd2e4f874947e3c9f128591661dd10e8
parent68c2e5de360411674d9821ee2b46f5d8ee965161 (diff)
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>
-rw-r--r--Documentation/networking/packet_mmap.txt13
-rw-r--r--include/uapi/linux/if_packet.h1
-rw-r--r--net/packet/af_packet.c9
3 files changed, 20 insertions, 3 deletions
diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index a6d7cb91069e..daa015af16a0 100644
--- a/Documentation/networking/packet_mmap.txt
+++ b/Documentation/networking/packet_mmap.txt
@@ -440,9 +440,10 @@ and the following flags apply:
440+++ Capture process: 440+++ Capture process:
441 from include/linux/if_packet.h 441 from include/linux/if_packet.h
442 442
443 #define TP_STATUS_COPY 2 443 #define TP_STATUS_COPY (1 << 1)
444 #define TP_STATUS_LOSING 4 444 #define TP_STATUS_LOSING (1 << 2)
445 #define TP_STATUS_CSUMNOTREADY 8 445 #define TP_STATUS_CSUMNOTREADY (1 << 3)
446 #define TP_STATUS_CSUM_VALID (1 << 7)
446 447
447TP_STATUS_COPY : This flag indicates that the frame (and associated 448TP_STATUS_COPY : This flag indicates that the frame (and associated
448 meta information) has been truncated because it's 449 meta information) has been truncated because it's
@@ -466,6 +467,12 @@ TP_STATUS_CSUMNOTREADY: currently it's used for outgoing IP packets which
466 reading the packet we should not try to check the 467 reading the packet we should not try to check the
467 checksum. 468 checksum.
468 469
470TP_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
469for convenience there are also the following defines: 476for convenience there are also the following defines:
470 477
471 #define TP_STATUS_KERNEL 0 478 #define TP_STATUS_KERNEL 0
diff --git a/include/uapi/linux/if_packet.h b/include/uapi/linux/if_packet.h
index da2d668b8cf1..053bd102fbe0 100644
--- a/include/uapi/linux/if_packet.h
+++ b/include/uapi/linux/if_packet.h
@@ -99,6 +99,7 @@ struct tpacket_auxdata {
99#define TP_STATUS_VLAN_VALID (1 << 4) /* auxdata has valid tp_vlan_tci */ 99#define TP_STATUS_VLAN_VALID (1 << 4) /* auxdata has valid tp_vlan_tci */
100#define TP_STATUS_BLK_TMO (1 << 5) 100#define TP_STATUS_BLK_TMO (1 << 5)
101#define TP_STATUS_VLAN_TPID_VALID (1 << 6) /* auxdata has valid tp_vlan_tpid */ 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/* Tx ring - header status */ 104/* Tx ring - header status */
104#define TP_STATUS_AVAILABLE 0 105#define TP_STATUS_AVAILABLE 0
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 9d854c5ce0b5..5102c3cc4eec 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1924,6 +1924,10 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
1924 1924
1925 if (skb->ip_summed == CHECKSUM_PARTIAL) 1925 if (skb->ip_summed == CHECKSUM_PARTIAL)
1926 status |= TP_STATUS_CSUMNOTREADY; 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 if (snaplen > res) 1932 if (snaplen > res)
1929 snaplen = res; 1933 snaplen = res;
@@ -3031,6 +3035,11 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
3031 aux.tp_status = TP_STATUS_USER; 3035 aux.tp_status = TP_STATUS_USER;
3032 if (skb->ip_summed == CHECKSUM_PARTIAL) 3036 if (skb->ip_summed == CHECKSUM_PARTIAL)
3033 aux.tp_status |= TP_STATUS_CSUMNOTREADY; 3037 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
3034 aux.tp_len = origlen; 3043 aux.tp_len = origlen;
3035 aux.tp_snaplen = skb->len; 3044 aux.tp_snaplen = skb->len;
3036 aux.tp_mac = 0; 3045 aux.tp_mac = 0;