Florian Westphal <fw@xxxxxxxxx> writes: > Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> wrote: >> This change adds conntrack lookup helpers using the unstable kfunc call >> interface for the XDP and TC-BPF hooks. >> >> Also add acquire/release functions (randomly returning NULL), and also >> exercise the RET_PTR_TO_BTF_ID_OR_NULL path so that BPF program caller >> has to check for NULL before dereferencing the pointer, for the TC hook. >> These will be used in selftest. >> >> Export get_net_ns_by_id and btf_type_by_id as nf_conntrack needs to call >> them. > > It would be good to get a summary on how this is useful. > > I tried to find a use case but I could not. > Entry will time out soon once packets stop appearing, so it can't be > used for stack bypass. Is it for something else? If so, what? I think Maxim's use case was to implement a SYN proxy in XDP, where the XDP program just needs to answer the question "do I have state for this flow already". For TCP flows terminating on the local box this can be done via a socket lookup, but for a middlebox, a conntrack lookup is useful. Maxim, please correct me if I got your use case wrong. > For UDP it will work to let a packet pass through classic forward > path once in a while, but this will not work for tcp, depending > on conntrack settings (lose mode, liberal pickup etc. pp). The idea is certainly to follow up with some kind of 'update' helper. At a minimum a "keep this entry alive" update, but potentially more complicated stuff as well. Details TBD, input welcome :) >> +/* Unstable Kernel Helpers for XDP hook */ >> +static struct nf_conn *__bpf_nf_ct_lookup(struct net *net, >> + struct bpf_sock_tuple *bpf_tuple, >> + u32 tuple_len, u8 protonum, >> + u64 netns_id, u64 flags) >> +{ >> + struct nf_conntrack_tuple_hash *hash; >> + struct nf_conntrack_tuple tuple; >> + >> + if (flags != IP_CT_DIR_ORIGINAL && flags != IP_CT_DIR_REPLY) >> + return ERR_PTR(-EINVAL); > > The flags argument is not needed. > >> + tuple.dst.dir = flags; > > .dir can be 0, its not used by nf_conntrack_find_get(). > >> + hash = nf_conntrack_find_get(net, &nf_ct_zone_dflt, &tuple); > > Ok, so default zone. Depending on meaning of "unstable helper" this > is ok and can be changed in incompatible way later. I'm not sure about the meaning of "unstable" either, TBH, but in either case I'd rather avoid changing things if we don't have to, so I think adding the zone as an argument from the get-go may be better... -Toke