Skip to content

Commit 086f956

Browse files
fomichevAlexei Starovoitov
authored andcommitted
bpf/flow_dissector: pass input flags to BPF flow dissector program
C flow dissector supports input flags that tell it to customize parsing by either stopping early or trying to parse as deep as possible. Pass those flags to the BPF flow dissector so it can make the same decisions. In the next commits I'll add support for those flags to our reference bpf_flow.c v3: * Export copy of flow dissector flags instead of moving (Alexei Starovoitov) Acked-by: Petar Penkov <ppenkov@google.com> Acked-by: Willem de Bruijn <willemb@google.com> Acked-by: Song Liu <songliubraving@fb.com> Cc: Song Liu <songliubraving@fb.com> Cc: Willem de Bruijn <willemb@google.com> Cc: Petar Penkov <ppenkov@google.com> Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 03cd1d1 commit 086f956

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ static inline int skb_flow_dissector_bpf_prog_detach(const union bpf_attr *attr)
12711271

12721272
struct bpf_flow_dissector;
12731273
bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
1274-
__be16 proto, int nhoff, int hlen);
1274+
__be16 proto, int nhoff, int hlen, unsigned int flags);
12751275

12761276
bool __skb_flow_dissect(const struct net *net,
12771277
const struct sk_buff *skb,

‎include/uapi/linux/bpf.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,6 +3507,10 @@ enum bpf_task_fd_type {
35073507
BPF_FD_TYPE_URETPROBE, /* filename + offset */
35083508
};
35093509

3510+
#define BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG (1U << 0)
3511+
#define BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL (1U << 1)
3512+
#define BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP (1U << 2)
3513+
35103514
struct bpf_flow_keys {
35113515
__u16 nhoff;
35123516
__u16 thoff;
@@ -3528,6 +3532,7 @@ struct bpf_flow_keys {
35283532
__u32 ipv6_dst[4]; /* in6_addr; network order */
35293533
};
35303534
};
3535+
__u32 flags;
35313536
};
35323537

35333538
struct bpf_func_info {

‎net/bpf/test_run.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
419419
time_start = ktime_get_ns();
420420
for (i = 0; i < repeat; i++) {
421421
retval = bpf_flow_dissect(prog, &ctx, eth->h_proto, ETH_HLEN,
422-
size);
422+
size, 0);
423423

424424
if (signal_pending(current)) {
425425
preempt_enable();

‎net/core/flow_dissector.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ static void __skb_flow_bpf_to_target(const struct bpf_flow_keys *flow_keys,
784784
}
785785

786786
bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
787-
__be16 proto, int nhoff, int hlen)
787+
__be16 proto, int nhoff, int hlen, unsigned int flags)
788788
{
789789
struct bpf_flow_keys *flow_keys = ctx->flow_keys;
790790
u32 result;
@@ -795,6 +795,14 @@ bool bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
795795
flow_keys->nhoff = nhoff;
796796
flow_keys->thoff = flow_keys->nhoff;
797797

798+
BUILD_BUG_ON((int)BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG !=
799+
(int)FLOW_DISSECTOR_F_PARSE_1ST_FRAG);
800+
BUILD_BUG_ON((int)BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL !=
801+
(int)FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
802+
BUILD_BUG_ON((int)BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP !=
803+
(int)FLOW_DISSECTOR_F_STOP_AT_ENCAP);
804+
flow_keys->flags = flags;
805+
798806
preempt_disable();
799807
result = BPF_PROG_RUN(prog, ctx);
800808
preempt_enable();
@@ -914,7 +922,7 @@ bool __skb_flow_dissect(const struct net *net,
914922
}
915923

916924
ret = bpf_flow_dissect(attached, &ctx, n_proto, nhoff,
917-
hlen);
925+
hlen, flags);
918926
__skb_flow_bpf_to_target(&flow_keys, flow_dissector,
919927
target_container);
920928
rcu_read_unlock();

0 commit comments

Comments
 (0)