• Martin KaFai Lau's avatar
    bpf: Add __sk_buff->delivery_time_type and bpf_skb_set_skb_delivery_time() · 8d21ec0e
    Martin KaFai Lau authored
    * __sk_buff->delivery_time_type:
    This patch adds __sk_buff->delivery_time_type.  It tells if the
    delivery_time is stored in __sk_buff->tstamp or not.
    
    It will be most useful for ingress to tell if the __sk_buff->tstamp
    has the (rcv) timestamp or delivery_time.  If delivery_time_type
    is 0 (BPF_SKB_DELIVERY_TIME_NONE), it has the (rcv) timestamp.
    
    Two non-zero types are defined for the delivery_time_type,
    BPF_SKB_DELIVERY_TIME_MONO and BPF_SKB_DELIVERY_TIME_UNSPEC.  For UNSPEC,
    it can only happen in egress because only mono delivery_time can be
    forwarded to ingress now.  The clock of UNSPEC delivery_time
    can be deduced from the skb->sk->sk_clockid which is how
    the sch_etf doing it also.
    
    * Provide forwarded delivery_time to tc-bpf@ingress:
    With the help of the new delivery_time_type, the tc-bpf has a way
    to tell if the __sk_buff->tstamp has the (rcv) timestamp or
    the delivery_time.  During bpf load time, the verifier will learn if
    the bpf prog has accessed the new __sk_buff->delivery_time_type.
    If it does, it means the tc-bpf@ingress is expecting the
    skb->tstamp could have the delivery_time.  The kernel will then
    read the skb->tstamp as-is during bpf insn rewrite without
    checking the skb->mono_delivery_time.  This is done by adding a
    new prog->delivery_time_access bit.  The same goes for
    writing skb->tstamp.
    
    * bpf_skb_set_delivery_time():
    The bpf_skb_set_delivery_time() helper is added to allow setting both
    delivery_time and the delivery_time_type at the same time.  If the
    tc-bpf does not need to change the delivery_time_type, it can directly
    write to the __sk_buff->tstamp as the existing tc-bpf has already been
    doing.  It will be most useful at ingress to change the
    __sk_buff->tstamp from the (rcv) timestamp to
    a mono delivery_time and then bpf_redirect_*().
    
    bpf only has mono clock helper (bpf_ktime_get_ns), and
    the current known use case is the mono EDT for fq, and
    only mono delivery time can be kept during forward now,
    so bpf_skb_set_delivery_time() only supports setting
    BPF_SKB_DELIVERY_TIME_MONO.  It can be extended later when use cases
    come up and the forwarding path also supports other clock bases.
    Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    8d21ec0e
bpf.h 241 KB