On Fri, Jan 19, 2018 at 05:45:48PM -0800, Lawrence Brakmo wrote:
> Added a selftest for tcpbpf (sock_ops) that checks that the appropriate
> callbacks occured and that it can access tcp_sock fields and that their
> values are correct.
> 
> Run with command: ./test_tcpbpf_user
> 
> Signed-off-by: Lawrence Brakmo <bra...@fb.com>
...
> +     __u32 key = 0;
> +     struct tcpbpf_globals g, *gp;
> +
> +     gp = bpf_map_lookup_elem(&global_map, &key);
> +     if (gp == NULL) {
> +             struct tcpbpf_globals g = {0, 0, 0, 0, 0, 0, 0, 0};
> +
> +             g.event_map |= (1 << event);
> +             bpf_map_update_elem(&global_map, &key, &g,
> +                         BPF_ANY);
> +     } else {
> +             g = *gp;
> +             g.event_map |= (1 << event);
> +             bpf_map_update_elem(&global_map, &key, &g,
> +                         BPF_ANY);
...
> +                     __u32 key = 0;
> +                     struct tcpbpf_globals g, *gp;
> +
> +                     gp = bpf_map_lookup_elem(&global_map, &key);
> +                     if (!gp)
> +                             break;
> +                     g = *gp;
> +                     g.bad_cb_test_rv = bad_call_rv;
> +                     g.good_cb_test_rv = good_call_rv;
> +                     bpf_map_update_elem(&global_map, &key, &g,
> +                                         BPF_ANY);

since 'g' is an array of one element and the tests designed
for single flow anyway, there is no need to use map_update_elem.
the program can directly assign into fields like:
        gp->bad_cb_test_rv = bad_call_rv;
        gp->good_cb_test_rv = good_call_rv;
probably not worth respining just for that. Mainly fyi.
Acked-by: Alexei Starovoitov <a...@kernel.org>

Reply via email to