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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'bpf-tstamp-follow-ups'

Martin KaFai Lau says:

====================
This set is a follow up on the bpf side based on discussion [0].

Patch 1 is to remove some skbuff macros that are used in bpf filter.c.

Patch 2 and 3 are to simplify the bpf insn rewrite on __sk_buff->tstamp.

Patch 4 is to simplify the bpf uapi by modeling the __sk_buff->tstamp
and __sk_buff->tstamp_type (was delivery_time_type) the same as its kernel
counter part skb->tstamp and skb->mono_delivery_time.

Patch 5 is to adjust the bpf selftests due to changes in patch 4.

[0]: https://lore.kernel.org/bpf/419d994e-ff61-7c11-0ec7-11fefcb0186e@iogearbox.net/
====================

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

+125 -138
+1 -1
include/linux/filter.h
··· 573 573 enforce_expected_attach_type:1, /* Enforce expected_attach_type checking at attach time */ 574 574 call_get_stack:1, /* Do we call bpf_get_stack() or bpf_get_stackid() */ 575 575 call_get_func_ip:1, /* Do we call get_func_ip() */ 576 - delivery_time_access:1; /* Accessed __sk_buff->delivery_time_type */ 576 + tstamp_type_access:1; /* Accessed __sk_buff->tstamp_type */ 577 577 enum bpf_prog_type type; /* Type of BPF program */ 578 578 enum bpf_attach_type expected_attach_type; /* For some prog types */ 579 579 u32 len; /* Number of filter blocks */
+5 -5
include/linux/skbuff.h
··· 960 960 __u8 csum_complete_sw:1; 961 961 __u8 csum_level:2; 962 962 __u8 dst_pending_confirm:1; 963 - __u8 mono_delivery_time:1; 963 + __u8 mono_delivery_time:1; /* See SKB_MONO_DELIVERY_TIME_MASK */ 964 964 #ifdef CONFIG_NET_CLS_ACT 965 965 __u8 tc_skip_classify:1; 966 - __u8 tc_at_ingress:1; 966 + __u8 tc_at_ingress:1; /* See TC_AT_INGRESS_MASK */ 967 967 #endif 968 968 #ifdef CONFIG_IPV6_NDISC_NODETYPE 969 969 __u8 ndisc_nodetype:2; ··· 1062 1062 #endif 1063 1063 #define PKT_TYPE_OFFSET offsetof(struct sk_buff, __pkt_type_offset) 1064 1064 1065 - /* if you move pkt_vlan_present around you also must adapt these constants */ 1065 + /* if you move pkt_vlan_present, tc_at_ingress, or mono_delivery_time 1066 + * around, you also must adapt these constants. 1067 + */ 1066 1068 #ifdef __BIG_ENDIAN_BITFIELD 1067 1069 #define PKT_VLAN_PRESENT_BIT 7 1068 1070 #define TC_AT_INGRESS_MASK (1 << 0) ··· 1075 1073 #define SKB_MONO_DELIVERY_TIME_MASK (1 << 5) 1076 1074 #endif 1077 1075 #define PKT_VLAN_PRESENT_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset) 1078 - #define TC_AT_INGRESS_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset) 1079 - #define SKB_MONO_DELIVERY_TIME_OFFSET offsetof(struct sk_buff, __pkt_vlan_present_offset) 1080 1076 1081 1077 #ifdef __KERNEL__ 1082 1078 /*
+21 -19
include/uapi/linux/bpf.h
··· 5090 5090 * 0 on success, or a negative error in case of failure. On error 5091 5091 * *dst* buffer is zeroed out. 5092 5092 * 5093 - * long bpf_skb_set_delivery_time(struct sk_buff *skb, u64 dtime, u32 dtime_type) 5093 + * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type) 5094 5094 * Description 5095 - * Set a *dtime* (delivery time) to the __sk_buff->tstamp and also 5096 - * change the __sk_buff->delivery_time_type to *dtime_type*. 5095 + * Change the __sk_buff->tstamp_type to *tstamp_type* 5096 + * and set *tstamp* to the __sk_buff->tstamp together. 5097 5097 * 5098 - * When setting a delivery time (non zero *dtime*) to 5099 - * __sk_buff->tstamp, only BPF_SKB_DELIVERY_TIME_MONO *dtime_type* 5100 - * is supported. It is the only delivery_time_type that will be 5101 - * kept after bpf_redirect_*(). 5102 - * 5103 - * If there is no need to change the __sk_buff->delivery_time_type, 5104 - * the delivery time can be directly written to __sk_buff->tstamp 5098 + * If there is no need to change the __sk_buff->tstamp_type, 5099 + * the tstamp value can be directly written to __sk_buff->tstamp 5105 5100 * instead. 5106 5101 * 5107 - * *dtime* 0 and *dtime_type* BPF_SKB_DELIVERY_TIME_NONE 5108 - * can be used to clear any delivery time stored in 5109 - * __sk_buff->tstamp. 5102 + * BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that 5103 + * will be kept during bpf_redirect_*(). A non zero 5104 + * *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO 5105 + * *tstamp_type*. 5106 + * 5107 + * A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used 5108 + * with a zero *tstamp*. 5110 5109 * 5111 5110 * Only IPv4 and IPv6 skb->protocol are supported. 5112 5111 * ··· 5118 5119 * Return 5119 5120 * 0 on success. 5120 5121 * **-EINVAL** for invalid input 5121 - * **-EOPNOTSUPP** for unsupported delivery_time_type and protocol 5122 + * **-EOPNOTSUPP** for unsupported protocol 5122 5123 */ 5123 5124 #define __BPF_FUNC_MAPPER(FN) \ 5124 5125 FN(unspec), \ ··· 5313 5314 FN(xdp_load_bytes), \ 5314 5315 FN(xdp_store_bytes), \ 5315 5316 FN(copy_from_user_task), \ 5316 - FN(skb_set_delivery_time), \ 5317 + FN(skb_set_tstamp), \ 5317 5318 /* */ 5318 5319 5319 5320 /* integer value in 'imm' field of BPF_CALL instruction selects which helper ··· 5504 5505 } __attribute__((aligned(8))) 5505 5506 5506 5507 enum { 5507 - BPF_SKB_DELIVERY_TIME_NONE, 5508 - BPF_SKB_DELIVERY_TIME_UNSPEC, 5509 - BPF_SKB_DELIVERY_TIME_MONO, 5508 + BPF_SKB_TSTAMP_UNSPEC, 5509 + BPF_SKB_TSTAMP_DELIVERY_MONO, /* tstamp has mono delivery time */ 5510 + /* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle, 5511 + * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC 5512 + * and try to deduce it by ingress, egress or skb->sk->sk_clockid. 5513 + */ 5510 5514 }; 5511 5515 5512 5516 /* user accessible mirror of in-kernel sk_buff. ··· 5552 5550 __u32 gso_segs; 5553 5551 __bpf_md_ptr(struct bpf_sock *, sk); 5554 5552 __u32 gso_size; 5555 - __u8 delivery_time_type; 5553 + __u8 tstamp_type; 5556 5554 __u32 :24; /* Padding, future use. */ 5557 5555 __u64 hwtstamp; 5558 5556 };
+58 -75
net/core/filter.c
··· 7388 7388 .arg3_type = ARG_ANYTHING, 7389 7389 }; 7390 7390 7391 - BPF_CALL_3(bpf_skb_set_delivery_time, struct sk_buff *, skb, 7392 - u64, dtime, u32, dtime_type) 7391 + BPF_CALL_3(bpf_skb_set_tstamp, struct sk_buff *, skb, 7392 + u64, tstamp, u32, tstamp_type) 7393 7393 { 7394 7394 /* skb_clear_delivery_time() is done for inet protocol */ 7395 7395 if (skb->protocol != htons(ETH_P_IP) && 7396 7396 skb->protocol != htons(ETH_P_IPV6)) 7397 7397 return -EOPNOTSUPP; 7398 7398 7399 - switch (dtime_type) { 7400 - case BPF_SKB_DELIVERY_TIME_MONO: 7401 - if (!dtime) 7399 + switch (tstamp_type) { 7400 + case BPF_SKB_TSTAMP_DELIVERY_MONO: 7401 + if (!tstamp) 7402 7402 return -EINVAL; 7403 - skb->tstamp = dtime; 7403 + skb->tstamp = tstamp; 7404 7404 skb->mono_delivery_time = 1; 7405 7405 break; 7406 - case BPF_SKB_DELIVERY_TIME_NONE: 7407 - if (dtime) 7406 + case BPF_SKB_TSTAMP_UNSPEC: 7407 + if (tstamp) 7408 7408 return -EINVAL; 7409 7409 skb->tstamp = 0; 7410 7410 skb->mono_delivery_time = 0; 7411 7411 break; 7412 7412 default: 7413 - return -EOPNOTSUPP; 7413 + return -EINVAL; 7414 7414 } 7415 7415 7416 7416 return 0; 7417 7417 } 7418 7418 7419 - static const struct bpf_func_proto bpf_skb_set_delivery_time_proto = { 7420 - .func = bpf_skb_set_delivery_time, 7419 + static const struct bpf_func_proto bpf_skb_set_tstamp_proto = { 7420 + .func = bpf_skb_set_tstamp, 7421 7421 .gpl_only = false, 7422 7422 .ret_type = RET_INTEGER, 7423 7423 .arg1_type = ARG_PTR_TO_CTX, ··· 7786 7786 return &bpf_tcp_gen_syncookie_proto; 7787 7787 case BPF_FUNC_sk_assign: 7788 7788 return &bpf_sk_assign_proto; 7789 - case BPF_FUNC_skb_set_delivery_time: 7790 - return &bpf_skb_set_delivery_time_proto; 7789 + case BPF_FUNC_skb_set_tstamp: 7790 + return &bpf_skb_set_tstamp_proto; 7791 7791 #endif 7792 7792 default: 7793 7793 return bpf_sk_base_func_proto(func_id); ··· 8127 8127 return false; 8128 8128 info->reg_type = PTR_TO_SOCK_COMMON_OR_NULL; 8129 8129 break; 8130 - case offsetof(struct __sk_buff, delivery_time_type): 8130 + case offsetof(struct __sk_buff, tstamp_type): 8131 8131 return false; 8132 - case offsetofend(struct __sk_buff, delivery_time_type) ... offsetof(struct __sk_buff, hwtstamp) - 1: 8132 + case offsetofend(struct __sk_buff, tstamp_type) ... offsetof(struct __sk_buff, hwtstamp) - 1: 8133 8133 /* Explicitly prohibit access to padding in __sk_buff. */ 8134 8134 return false; 8135 8135 default: ··· 8484 8484 break; 8485 8485 case bpf_ctx_range_till(struct __sk_buff, family, local_port): 8486 8486 return false; 8487 - case offsetof(struct __sk_buff, delivery_time_type): 8487 + case offsetof(struct __sk_buff, tstamp_type): 8488 8488 /* The convert_ctx_access() on reading and writing 8489 8489 * __sk_buff->tstamp depends on whether the bpf prog 8490 - * has used __sk_buff->delivery_time_type or not. 8491 - * Thus, we need to set prog->delivery_time_access 8490 + * has used __sk_buff->tstamp_type or not. 8491 + * Thus, we need to set prog->tstamp_type_access 8492 8492 * earlier during is_valid_access() here. 8493 8493 */ 8494 - ((struct bpf_prog *)prog)->delivery_time_access = 1; 8494 + ((struct bpf_prog *)prog)->tstamp_type_access = 1; 8495 8495 return size == sizeof(__u8); 8496 8496 } 8497 8497 ··· 8888 8888 return insn - insn_buf; 8889 8889 } 8890 8890 8891 - static struct bpf_insn *bpf_convert_dtime_type_read(const struct bpf_insn *si, 8892 - struct bpf_insn *insn) 8891 + static struct bpf_insn *bpf_convert_tstamp_type_read(const struct bpf_insn *si, 8892 + struct bpf_insn *insn) 8893 8893 { 8894 8894 __u8 value_reg = si->dst_reg; 8895 8895 __u8 skb_reg = si->src_reg; 8896 + /* AX is needed because src_reg and dst_reg could be the same */ 8896 8897 __u8 tmp_reg = BPF_REG_AX; 8897 8898 8898 8899 *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, 8899 - SKB_MONO_DELIVERY_TIME_OFFSET); 8900 - *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, 8901 - SKB_MONO_DELIVERY_TIME_MASK); 8902 - *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, 0, 2); 8903 - /* value_reg = BPF_SKB_DELIVERY_TIME_MONO */ 8904 - *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_DELIVERY_TIME_MONO); 8905 - *insn++ = BPF_JMP_A(IS_ENABLED(CONFIG_NET_CLS_ACT) ? 10 : 5); 8906 - 8907 - *insn++ = BPF_LDX_MEM(BPF_DW, tmp_reg, skb_reg, 8908 - offsetof(struct sk_buff, tstamp)); 8909 - *insn++ = BPF_JMP_IMM(BPF_JNE, tmp_reg, 0, 2); 8910 - /* value_reg = BPF_SKB_DELIVERY_TIME_NONE */ 8911 - *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_DELIVERY_TIME_NONE); 8912 - *insn++ = BPF_JMP_A(IS_ENABLED(CONFIG_NET_CLS_ACT) ? 6 : 1); 8913 - 8914 - #ifdef CONFIG_NET_CLS_ACT 8915 - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, TC_AT_INGRESS_OFFSET); 8916 - *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, TC_AT_INGRESS_MASK); 8917 - *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, 0, 2); 8918 - /* At ingress, value_reg = 0 */ 8919 - *insn++ = BPF_MOV32_IMM(value_reg, 0); 8900 + PKT_VLAN_PRESENT_OFFSET); 8901 + *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, 8902 + SKB_MONO_DELIVERY_TIME_MASK, 2); 8903 + *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_TSTAMP_UNSPEC); 8920 8904 *insn++ = BPF_JMP_A(1); 8921 - #endif 8905 + *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_TSTAMP_DELIVERY_MONO); 8922 8906 8923 - /* value_reg = BPF_SKB_DELIVERYT_TIME_UNSPEC */ 8924 - *insn++ = BPF_MOV32_IMM(value_reg, BPF_SKB_DELIVERY_TIME_UNSPEC); 8925 - 8926 - /* 15 insns with CONFIG_NET_CLS_ACT */ 8927 8907 return insn; 8928 8908 } 8929 8909 ··· 8936 8956 __u8 skb_reg = si->src_reg; 8937 8957 8938 8958 #ifdef CONFIG_NET_CLS_ACT 8939 - if (!prog->delivery_time_access) { 8959 + /* If the tstamp_type is read, 8960 + * the bpf prog is aware the tstamp could have delivery time. 8961 + * Thus, read skb->tstamp as is if tstamp_type_access is true. 8962 + */ 8963 + if (!prog->tstamp_type_access) { 8964 + /* AX is needed because src_reg and dst_reg could be the same */ 8940 8965 __u8 tmp_reg = BPF_REG_AX; 8941 8966 8942 - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, TC_AT_INGRESS_OFFSET); 8943 - *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, TC_AT_INGRESS_MASK); 8944 - *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, 0, 5); 8945 - /* @ingress, read __sk_buff->tstamp as the (rcv) timestamp, 8946 - * so check the skb->mono_delivery_time. 8947 - */ 8948 - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, 8949 - SKB_MONO_DELIVERY_TIME_OFFSET); 8967 + *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET); 8950 8968 *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, 8951 - SKB_MONO_DELIVERY_TIME_MASK); 8952 - *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, 0, 2); 8953 - /* skb->mono_delivery_time is set, read 0 as the (rcv) timestamp. */ 8969 + TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK); 8970 + *insn++ = BPF_JMP32_IMM(BPF_JNE, tmp_reg, 8971 + TC_AT_INGRESS_MASK | SKB_MONO_DELIVERY_TIME_MASK, 2); 8972 + /* skb->tc_at_ingress && skb->mono_delivery_time, 8973 + * read 0 as the (rcv) timestamp. 8974 + */ 8954 8975 *insn++ = BPF_MOV64_IMM(value_reg, 0); 8955 8976 *insn++ = BPF_JMP_A(1); 8956 8977 } ··· 8970 8989 __u8 skb_reg = si->dst_reg; 8971 8990 8972 8991 #ifdef CONFIG_NET_CLS_ACT 8973 - if (!prog->delivery_time_access) { 8992 + /* If the tstamp_type is read, 8993 + * the bpf prog is aware the tstamp could have delivery time. 8994 + * Thus, write skb->tstamp as is if tstamp_type_access is true. 8995 + * Otherwise, writing at ingress will have to clear the 8996 + * mono_delivery_time bit also. 8997 + */ 8998 + if (!prog->tstamp_type_access) { 8974 8999 __u8 tmp_reg = BPF_REG_AX; 8975 9000 8976 - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, TC_AT_INGRESS_OFFSET); 8977 - *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, TC_AT_INGRESS_MASK); 8978 - *insn++ = BPF_JMP32_IMM(BPF_JEQ, tmp_reg, 0, 3); 8979 - /* Writing __sk_buff->tstamp at ingress as the (rcv) timestamp. 8980 - * Clear the skb->mono_delivery_time. 8981 - */ 8982 - *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, 8983 - SKB_MONO_DELIVERY_TIME_OFFSET); 8984 - *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, 8985 - ~SKB_MONO_DELIVERY_TIME_MASK); 8986 - *insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, 8987 - SKB_MONO_DELIVERY_TIME_OFFSET); 9001 + *insn++ = BPF_LDX_MEM(BPF_B, tmp_reg, skb_reg, PKT_VLAN_PRESENT_OFFSET); 9002 + /* Writing __sk_buff->tstamp as ingress, goto <clear> */ 9003 + *insn++ = BPF_JMP32_IMM(BPF_JSET, tmp_reg, TC_AT_INGRESS_MASK, 1); 9004 + /* goto <store> */ 9005 + *insn++ = BPF_JMP_A(2); 9006 + /* <clear>: mono_delivery_time */ 9007 + *insn++ = BPF_ALU32_IMM(BPF_AND, tmp_reg, ~SKB_MONO_DELIVERY_TIME_MASK); 9008 + *insn++ = BPF_STX_MEM(BPF_B, skb_reg, tmp_reg, PKT_VLAN_PRESENT_OFFSET); 8988 9009 } 8989 9010 #endif 8990 9011 8991 - /* skb->tstamp = tstamp */ 9012 + /* <store>: skb->tstamp = tstamp */ 8992 9013 *insn++ = BPF_STX_MEM(BPF_DW, skb_reg, value_reg, 8993 9014 offsetof(struct sk_buff, tstamp)); 8994 9015 return insn; ··· 9309 9326 insn = bpf_convert_tstamp_read(prog, si, insn); 9310 9327 break; 9311 9328 9312 - case offsetof(struct __sk_buff, delivery_time_type): 9313 - insn = bpf_convert_dtime_type_read(si, insn); 9329 + case offsetof(struct __sk_buff, tstamp_type): 9330 + insn = bpf_convert_tstamp_type_read(si, insn); 9314 9331 break; 9315 9332 9316 9333 case offsetof(struct __sk_buff, gso_segs):
+21 -19
tools/include/uapi/linux/bpf.h
··· 5090 5090 * 0 on success, or a negative error in case of failure. On error 5091 5091 * *dst* buffer is zeroed out. 5092 5092 * 5093 - * long bpf_skb_set_delivery_time(struct sk_buff *skb, u64 dtime, u32 dtime_type) 5093 + * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type) 5094 5094 * Description 5095 - * Set a *dtime* (delivery time) to the __sk_buff->tstamp and also 5096 - * change the __sk_buff->delivery_time_type to *dtime_type*. 5095 + * Change the __sk_buff->tstamp_type to *tstamp_type* 5096 + * and set *tstamp* to the __sk_buff->tstamp together. 5097 5097 * 5098 - * When setting a delivery time (non zero *dtime*) to 5099 - * __sk_buff->tstamp, only BPF_SKB_DELIVERY_TIME_MONO *dtime_type* 5100 - * is supported. It is the only delivery_time_type that will be 5101 - * kept after bpf_redirect_*(). 5102 - * 5103 - * If there is no need to change the __sk_buff->delivery_time_type, 5104 - * the delivery time can be directly written to __sk_buff->tstamp 5098 + * If there is no need to change the __sk_buff->tstamp_type, 5099 + * the tstamp value can be directly written to __sk_buff->tstamp 5105 5100 * instead. 5106 5101 * 5107 - * *dtime* 0 and *dtime_type* BPF_SKB_DELIVERY_TIME_NONE 5108 - * can be used to clear any delivery time stored in 5109 - * __sk_buff->tstamp. 5102 + * BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that 5103 + * will be kept during bpf_redirect_*(). A non zero 5104 + * *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO 5105 + * *tstamp_type*. 5106 + * 5107 + * A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used 5108 + * with a zero *tstamp*. 5110 5109 * 5111 5110 * Only IPv4 and IPv6 skb->protocol are supported. 5112 5111 * ··· 5118 5119 * Return 5119 5120 * 0 on success. 5120 5121 * **-EINVAL** for invalid input 5121 - * **-EOPNOTSUPP** for unsupported delivery_time_type and protocol 5122 + * **-EOPNOTSUPP** for unsupported protocol 5122 5123 */ 5123 5124 #define __BPF_FUNC_MAPPER(FN) \ 5124 5125 FN(unspec), \ ··· 5313 5314 FN(xdp_load_bytes), \ 5314 5315 FN(xdp_store_bytes), \ 5315 5316 FN(copy_from_user_task), \ 5316 - FN(skb_set_delivery_time), \ 5317 + FN(skb_set_tstamp), \ 5317 5318 /* */ 5318 5319 5319 5320 /* integer value in 'imm' field of BPF_CALL instruction selects which helper ··· 5504 5505 } __attribute__((aligned(8))) 5505 5506 5506 5507 enum { 5507 - BPF_SKB_DELIVERY_TIME_NONE, 5508 - BPF_SKB_DELIVERY_TIME_UNSPEC, 5509 - BPF_SKB_DELIVERY_TIME_MONO, 5508 + BPF_SKB_TSTAMP_UNSPEC, 5509 + BPF_SKB_TSTAMP_DELIVERY_MONO, /* tstamp has mono delivery time */ 5510 + /* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle, 5511 + * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC 5512 + * and try to deduce it by ingress, egress or skb->sk->sk_clockid. 5513 + */ 5510 5514 }; 5511 5515 5512 5516 /* user accessible mirror of in-kernel sk_buff. ··· 5552 5550 __u32 gso_segs; 5553 5551 __bpf_md_ptr(struct bpf_sock *, sk); 5554 5552 __u32 gso_size; 5555 - __u8 delivery_time_type; 5553 + __u8 tstamp_type; 5556 5554 __u32 :24; /* Padding, future use. */ 5557 5555 __u64 hwtstamp; 5558 5556 };
+19 -19
tools/testing/selftests/bpf/progs/test_tc_dtime.c
··· 174 174 return TC_ACT_OK; 175 175 176 176 if (skb_proto(skb_type) == IPPROTO_TCP) { 177 - if (skb->delivery_time_type == BPF_SKB_DELIVERY_TIME_MONO && 177 + if (skb->tstamp_type == BPF_SKB_TSTAMP_DELIVERY_MONO && 178 178 skb->tstamp) 179 179 inc_dtimes(EGRESS_ENDHOST); 180 180 else 181 181 inc_errs(EGRESS_ENDHOST); 182 182 } else { 183 - if (skb->delivery_time_type == BPF_SKB_DELIVERY_TIME_UNSPEC && 183 + if (skb->tstamp_type == BPF_SKB_TSTAMP_UNSPEC && 184 184 skb->tstamp) 185 185 inc_dtimes(EGRESS_ENDHOST); 186 186 else ··· 204 204 if (!skb_type) 205 205 return TC_ACT_OK; 206 206 207 - if (skb->delivery_time_type == BPF_SKB_DELIVERY_TIME_MONO && 207 + if (skb->tstamp_type == BPF_SKB_TSTAMP_DELIVERY_MONO && 208 208 skb->tstamp == EGRESS_FWDNS_MAGIC) 209 209 inc_dtimes(INGRESS_ENDHOST); 210 210 else ··· 226 226 return TC_ACT_OK; 227 227 228 228 /* delivery_time is only available to the ingress 229 - * if the tc-bpf checks the skb->delivery_time_type. 229 + * if the tc-bpf checks the skb->tstamp_type. 230 230 */ 231 231 if (skb->tstamp == EGRESS_ENDHOST_MAGIC) 232 232 inc_errs(INGRESS_FWDNS_P100); ··· 250 250 return TC_ACT_OK; 251 251 252 252 /* delivery_time is always available to egress even 253 - * the tc-bpf did not use the delivery_time_type. 253 + * the tc-bpf did not use the tstamp_type. 254 254 */ 255 255 if (skb->tstamp == INGRESS_FWDNS_MAGIC) 256 256 inc_dtimes(EGRESS_FWDNS_P100); ··· 278 278 if (skb_proto(skb_type) == IPPROTO_UDP) 279 279 expected_dtime = 0; 280 280 281 - if (skb->delivery_time_type) { 281 + if (skb->tstamp_type) { 282 282 if (fwdns_clear_dtime() || 283 - skb->delivery_time_type != BPF_SKB_DELIVERY_TIME_MONO || 283 + skb->tstamp_type != BPF_SKB_TSTAMP_DELIVERY_MONO || 284 284 skb->tstamp != expected_dtime) 285 285 inc_errs(INGRESS_FWDNS_P101); 286 286 else ··· 290 290 inc_errs(INGRESS_FWDNS_P101); 291 291 } 292 292 293 - if (skb->delivery_time_type == BPF_SKB_DELIVERY_TIME_MONO) { 293 + if (skb->tstamp_type == BPF_SKB_TSTAMP_DELIVERY_MONO) { 294 294 skb->tstamp = INGRESS_FWDNS_MAGIC; 295 295 } else { 296 - if (bpf_skb_set_delivery_time(skb, INGRESS_FWDNS_MAGIC, 297 - BPF_SKB_DELIVERY_TIME_MONO)) 296 + if (bpf_skb_set_tstamp(skb, INGRESS_FWDNS_MAGIC, 297 + BPF_SKB_TSTAMP_DELIVERY_MONO)) 298 298 inc_errs(SET_DTIME); 299 - if (!bpf_skb_set_delivery_time(skb, INGRESS_FWDNS_MAGIC, 300 - BPF_SKB_DELIVERY_TIME_UNSPEC)) 299 + if (!bpf_skb_set_tstamp(skb, INGRESS_FWDNS_MAGIC, 300 + BPF_SKB_TSTAMP_UNSPEC)) 301 301 inc_errs(SET_DTIME); 302 302 } 303 303 ··· 320 320 /* Should have handled in prio100 */ 321 321 return TC_ACT_SHOT; 322 322 323 - if (skb->delivery_time_type) { 323 + if (skb->tstamp_type) { 324 324 if (fwdns_clear_dtime() || 325 - skb->delivery_time_type != BPF_SKB_DELIVERY_TIME_MONO || 325 + skb->tstamp_type != BPF_SKB_TSTAMP_DELIVERY_MONO || 326 326 skb->tstamp != INGRESS_FWDNS_MAGIC) 327 327 inc_errs(EGRESS_FWDNS_P101); 328 328 else ··· 332 332 inc_errs(EGRESS_FWDNS_P101); 333 333 } 334 334 335 - if (skb->delivery_time_type == BPF_SKB_DELIVERY_TIME_MONO) { 335 + if (skb->tstamp_type == BPF_SKB_TSTAMP_DELIVERY_MONO) { 336 336 skb->tstamp = EGRESS_FWDNS_MAGIC; 337 337 } else { 338 - if (bpf_skb_set_delivery_time(skb, EGRESS_FWDNS_MAGIC, 339 - BPF_SKB_DELIVERY_TIME_MONO)) 338 + if (bpf_skb_set_tstamp(skb, EGRESS_FWDNS_MAGIC, 339 + BPF_SKB_TSTAMP_DELIVERY_MONO)) 340 340 inc_errs(SET_DTIME); 341 - if (!bpf_skb_set_delivery_time(skb, EGRESS_FWDNS_MAGIC, 342 - BPF_SKB_DELIVERY_TIME_UNSPEC)) 341 + if (!bpf_skb_set_tstamp(skb, INGRESS_FWDNS_MAGIC, 342 + BPF_SKB_TSTAMP_UNSPEC)) 343 343 inc_errs(SET_DTIME); 344 344 } 345 345