File tree 4 files changed +43
-0
lines changed
4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,20 @@ xdp_get_shared_info_from_buff(struct xdp_buff *xdp)
145
145
return (struct skb_shared_info * )xdp_data_hard_end (xdp );
146
146
}
147
147
148
+ static __always_inline unsigned int xdp_get_buff_len (struct xdp_buff * xdp )
149
+ {
150
+ unsigned int len = xdp -> data_end - xdp -> data ;
151
+ struct skb_shared_info * sinfo ;
152
+
153
+ if (likely (!xdp_buff_has_frags (xdp )))
154
+ goto out ;
155
+
156
+ sinfo = xdp_get_shared_info_from_buff (xdp );
157
+ len += sinfo -> xdp_frags_size ;
158
+ out :
159
+ return len ;
160
+ }
161
+
148
162
struct xdp_frame {
149
163
void * data ;
150
164
u16 len ;
Original file line number Diff line number Diff line change @@ -5054,6 +5054,12 @@ union bpf_attr {
5054
5054
* This helper is currently supported by cgroup programs only.
5055
5055
* Return
5056
5056
* 0 on success, or a negative error in case of failure.
5057
+ *
5058
+ * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)
5059
+ * Description
5060
+ * Get the total size of a given xdp buff (linear and paged area)
5061
+ * Return
5062
+ * The total size of a given xdp buffer.
5057
5063
*/
5058
5064
#define __BPF_FUNC_MAPPER (FN ) \
5059
5065
FN(unspec), \
@@ -5244,6 +5250,7 @@ union bpf_attr {
5244
5250
FN(get_func_arg_cnt), \
5245
5251
FN(get_retval), \
5246
5252
FN(set_retval), \
5253
+ FN(xdp_get_buff_len), \
5247
5254
/* */
5248
5255
5249
5256
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
Original file line number Diff line number Diff line change @@ -3783,6 +3783,19 @@ static const struct bpf_func_proto sk_skb_change_head_proto = {
3783
3783
.arg2_type = ARG_ANYTHING ,
3784
3784
.arg3_type = ARG_ANYTHING ,
3785
3785
};
3786
+
3787
+ BPF_CALL_1 (bpf_xdp_get_buff_len , struct xdp_buff * , xdp )
3788
+ {
3789
+ return xdp_get_buff_len (xdp );
3790
+ }
3791
+
3792
+ static const struct bpf_func_proto bpf_xdp_get_buff_len_proto = {
3793
+ .func = bpf_xdp_get_buff_len ,
3794
+ .gpl_only = false,
3795
+ .ret_type = RET_INTEGER ,
3796
+ .arg1_type = ARG_PTR_TO_CTX ,
3797
+ };
3798
+
3786
3799
static unsigned long xdp_get_metalen (const struct xdp_buff * xdp )
3787
3800
{
3788
3801
return xdp_data_meta_unsupported (xdp ) ? 0 :
@@ -7533,6 +7546,8 @@ xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
7533
7546
return & bpf_xdp_redirect_map_proto ;
7534
7547
case BPF_FUNC_xdp_adjust_tail :
7535
7548
return & bpf_xdp_adjust_tail_proto ;
7549
+ case BPF_FUNC_xdp_get_buff_len :
7550
+ return & bpf_xdp_get_buff_len_proto ;
7536
7551
case BPF_FUNC_fib_lookup :
7537
7552
return & bpf_xdp_fib_lookup_proto ;
7538
7553
case BPF_FUNC_check_mtu :
Original file line number Diff line number Diff line change @@ -5054,6 +5054,12 @@ union bpf_attr {
5054
5054
* This helper is currently supported by cgroup programs only.
5055
5055
* Return
5056
5056
* 0 on success, or a negative error in case of failure.
5057
+ *
5058
+ * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)
5059
+ * Description
5060
+ * Get the total size of a given xdp buff (linear and paged area)
5061
+ * Return
5062
+ * The total size of a given xdp buffer.
5057
5063
*/
5058
5064
#define __BPF_FUNC_MAPPER (FN ) \
5059
5065
FN(unspec), \
@@ -5244,6 +5250,7 @@ union bpf_attr {
5244
5250
FN(get_func_arg_cnt), \
5245
5251
FN(get_retval), \
5246
5252
FN(set_retval), \
5253
+ FN(xdp_get_buff_len), \
5247
5254
/* */
5248
5255
5249
5256
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
You can’t perform that action at this time.
0 commit comments