@@ -5123,6 +5123,17 @@ sk_skb_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
51235123 }
51245124}
51255125
5126+ static const struct bpf_func_proto *
5127+ flow_dissector_func_proto (enum bpf_func_id func_id , const struct bpf_prog * prog )
5128+ {
5129+ switch (func_id ) {
5130+ case BPF_FUNC_skb_load_bytes :
5131+ return & bpf_skb_load_bytes_proto ;
5132+ default :
5133+ return bpf_base_func_proto (func_id );
5134+ }
5135+ }
5136+
51265137static const struct bpf_func_proto *
51275138lwt_out_func_proto (enum bpf_func_id func_id , const struct bpf_prog * prog )
51285139{
@@ -5241,6 +5252,10 @@ static bool bpf_skb_is_valid_access(int off, int size, enum bpf_access_type type
52415252 if (size != size_default )
52425253 return false;
52435254 break ;
5255+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5256+ if (size != sizeof (struct bpf_flow_keys * ))
5257+ return false;
5258+ break ;
52445259 default :
52455260 /* Only narrow read access allowed for now. */
52465261 if (type == BPF_WRITE ) {
@@ -5266,6 +5281,7 @@ static bool sk_filter_is_valid_access(int off, int size,
52665281 case bpf_ctx_range (struct __sk_buff , data ):
52675282 case bpf_ctx_range (struct __sk_buff , data_meta ):
52685283 case bpf_ctx_range (struct __sk_buff , data_end ):
5284+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
52695285 case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
52705286 return false;
52715287 }
@@ -5291,6 +5307,7 @@ static bool lwt_is_valid_access(int off, int size,
52915307 case bpf_ctx_range (struct __sk_buff , tc_classid ):
52925308 case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
52935309 case bpf_ctx_range (struct __sk_buff , data_meta ):
5310+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
52945311 return false;
52955312 }
52965313
@@ -5501,6 +5518,7 @@ static bool tc_cls_act_is_valid_access(int off, int size,
55015518 case bpf_ctx_range (struct __sk_buff , data_end ):
55025519 info -> reg_type = PTR_TO_PACKET_END ;
55035520 break ;
5521+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
55045522 case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
55055523 return false;
55065524 }
@@ -5702,6 +5720,7 @@ static bool sk_skb_is_valid_access(int off, int size,
57025720 switch (off ) {
57035721 case bpf_ctx_range (struct __sk_buff , tc_classid ):
57045722 case bpf_ctx_range (struct __sk_buff , data_meta ):
5723+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
57055724 return false;
57065725 }
57075726
@@ -5761,6 +5780,39 @@ static bool sk_msg_is_valid_access(int off, int size,
57615780 return true;
57625781}
57635782
5783+ static bool flow_dissector_is_valid_access (int off , int size ,
5784+ enum bpf_access_type type ,
5785+ const struct bpf_prog * prog ,
5786+ struct bpf_insn_access_aux * info )
5787+ {
5788+ if (type == BPF_WRITE ) {
5789+ switch (off ) {
5790+ case bpf_ctx_range_till (struct __sk_buff , cb [0 ], cb [4 ]):
5791+ break ;
5792+ default :
5793+ return false;
5794+ }
5795+ }
5796+
5797+ switch (off ) {
5798+ case bpf_ctx_range (struct __sk_buff , data ):
5799+ info -> reg_type = PTR_TO_PACKET ;
5800+ break ;
5801+ case bpf_ctx_range (struct __sk_buff , data_end ):
5802+ info -> reg_type = PTR_TO_PACKET_END ;
5803+ break ;
5804+ case bpf_ctx_range (struct __sk_buff , flow_keys ):
5805+ info -> reg_type = PTR_TO_FLOW_KEYS ;
5806+ break ;
5807+ case bpf_ctx_range (struct __sk_buff , tc_classid ):
5808+ case bpf_ctx_range (struct __sk_buff , data_meta ):
5809+ case bpf_ctx_range_till (struct __sk_buff , family , local_port ):
5810+ return false;
5811+ }
5812+
5813+ return bpf_skb_is_valid_access (off , size , type , prog , info );
5814+ }
5815+
57645816static u32 bpf_convert_ctx_access (enum bpf_access_type type ,
57655817 const struct bpf_insn * si ,
57665818 struct bpf_insn * insn_buf ,
@@ -6055,6 +6107,15 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
60556107 bpf_target_off (struct sock_common ,
60566108 skc_num , 2 , target_size ));
60576109 break ;
6110+
6111+ case offsetof(struct __sk_buff , flow_keys ):
6112+ off = si -> off ;
6113+ off -= offsetof(struct __sk_buff , flow_keys );
6114+ off += offsetof(struct sk_buff , cb );
6115+ off += offsetof(struct qdisc_skb_cb , flow_keys );
6116+ * insn ++ = BPF_LDX_MEM (BPF_SIZEOF (void * ), si -> dst_reg ,
6117+ si -> src_reg , off );
6118+ break ;
60586119 }
60596120
60606121 return insn - insn_buf ;
@@ -7018,6 +7079,15 @@ const struct bpf_verifier_ops sk_msg_verifier_ops = {
70187079const struct bpf_prog_ops sk_msg_prog_ops = {
70197080};
70207081
7082+ const struct bpf_verifier_ops flow_dissector_verifier_ops = {
7083+ .get_func_proto = flow_dissector_func_proto ,
7084+ .is_valid_access = flow_dissector_is_valid_access ,
7085+ .convert_ctx_access = bpf_convert_ctx_access ,
7086+ };
7087+
7088+ const struct bpf_prog_ops flow_dissector_prog_ops = {
7089+ };
7090+
70217091int sk_detach_filter (struct sock * sk )
70227092{
70237093 int ret = - ENOENT ;
0 commit comments