• Martin KaFai Lau's avatar
    net: Handle delivery_time in skb->tstamp during network tapping with af_packet · 27942a15
    Martin KaFai Lau authored
    A latter patch will set the skb->mono_delivery_time to flag the skb->tstamp
    is used as the mono delivery_time (EDT) instead of the (rcv) timestamp.
    skb_clear_tstamp() will then keep this delivery_time during forwarding.
    
    This patch is to make the network tapping (with af_packet) to handle
    the delivery_time stored in skb->tstamp.
    
    Regardless of tapping at the ingress or egress,  the tapped skb is
    received by the af_packet socket, so it is ingress to the af_packet
    socket and it expects the (rcv) timestamp.
    
    When tapping at egress, dev_queue_xmit_nit() is used.  It has already
    expected skb->tstamp may have delivery_time,  so it does
    skb_clone()+net_timestamp_set() to ensure the cloned skb has
    the (rcv) timestamp before passing to the af_packet sk.
    This patch only adds to clear the skb->mono_delivery_time
    bit in net_timestamp_set().
    
    When tapping at ingress, it currently expects the skb->tstamp is either 0
    or the (rcv) timestamp.  Meaning, the tapping at ingress path
    has already expected the skb->tstamp could be 0 and it will get
    the (rcv) timestamp by ktime_get_real() when needed.
    
    There are two cases for tapping at ingress:
    
    One case is af_packet queues the skb to its sk_receive_queue.
    The skb is either not shared or new clone created.  The newly
    added skb_clear_delivery_time() is called to clear the
    delivery_time (if any) and set the (rcv) timestamp if
    needed before the skb is queued to the sk_receive_queue.
    
    Another case, the ingress skb is directly copied to the rx_ring
    and tpacket_get_timestamp() is used to get the (rcv) timestamp.
    The newly added skb_tstamp() is used in tpacket_get_timestamp()
    to check the skb->mono_delivery_time bit before returning skb->tstamp.
    As mentioned earlier, the tapping@ingress has already expected
    the skb may not have the (rcv) timestamp (because no sk has asked
    for it) and has handled this case by directly calling ktime_get_real().
    Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    27942a15
af_packet.c 111 KB