On Mon, Apr 26, 2021 at 04:49 AM CEST, Cong Wang wrote: > From: Cong Wang <cong.wang@xxxxxxxxxxxxx> > > unix_proto is special, it is very different from INET proto, > which even does not have a ->close(). We have to add a dummy > one to satisfy sockmap. > > And now we can implement unix_bpf_update_proto() to update > sk_prot. > > Cc: John Fastabend <john.fastabend@xxxxxxxxx> > Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx> > Cc: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx> > Cc: Lorenz Bauer <lmb@xxxxxxxxxxxxxx> > Signed-off-by: Cong Wang <cong.wang@xxxxxxxxxxxxx> > --- [...] > diff --git a/net/unix/unix_bpf.c b/net/unix/unix_bpf.c > new file mode 100644 > index 000000000000..b1582a659427 > --- /dev/null > +++ b/net/unix/unix_bpf.c > @@ -0,0 +1,47 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright (c) 2021 Cong Wang <cong.wang@xxxxxxxxxxxxx> */ > + > +#include <linux/skmsg.h> > +#include <linux/bpf.h> > +#include <net/sock.h> > +#include <net/af_unix.h> > + > +static struct proto *unix_prot_saved __read_mostly; > +static DEFINE_SPINLOCK(unix_prot_lock); > +static struct proto unix_bpf_prot; > + > +static void unix_bpf_rebuild_protos(struct proto *prot, const struct proto *base) > +{ > + *prot = *base; > + prot->close = sock_map_close; > +} I think we also need unhash so that socket gets removed from sockmap on disconnect, that is connect(fd, {sa_family=AF_UNSPEC, ...}, ...).