Skip to contentSkip to conversation

BPF iterator for UNIX domain socket.

PATCH Superseded Kuniyuki Iwashima 3 participants 12 messages Aug 10, 2021 – Aug 12, 2021

Subsystems (6)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover BPF iterator for UNIX domain socket.

This patch set adds BPF iterator support for UNIX domain socket. The first patch implements it, the second adds "%c" support for BPF_SEQ_PRINTF(), and the third adds a selftest.

Changelog:
v4:
- Check IS_BUILTIN(CONFIG_UNIX)
- Support "%c" in BPF_SEQ_PRINTF()
- Uncomment the code to print the name of the abstract socket
- Mention the LLVM fix in README.rst
- Remove the 'aligned' attribute in bpf_iter.h
- Keep the format string on a single line

v3:
https://lore.kernel.org/netdev/[email protected]/
- Export some functions for CONFIG_UNIX=m

v2:
https://lore.kernel.org/netdev/[email protected]/
- Implement bpf_iter specific seq_ops->stop()
- Add bpf_iter__unix in bpf_iter.h
- Move common definitions in selftest to bpf_tracing_net.h
- Include the code for abstract UNIX domain socket as comment in selftest
- Use ASSERT_OK_PTR() instead of CHECK()
- Make ternary operators on single line

v1:
https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (3):
bpf: af_unix: Implement BPF iterator for UNIX domain socket.
bpf: Support "%c" in bpf_bprintf_prepare(). selftest/bpf: Implement sample UNIX domain socket iterator program.

 include/linux/btf_ids.h                       |  3 +-
 kernel/bpf/helpers.c                          | 14 +++
 net/unix/af_unix.c                            | 93 +++++++++++++++++++
 tools/testing/selftests/bpf/README.rst        | 38 ++++++++
 .../selftests/bpf/prog_tests/bpf_iter.c       | 16 ++++
 tools/testing/selftests/bpf/progs/bpf_iter.h  |  8 ++
 .../selftests/bpf/progs/bpf_iter_unix.c       | 77 +++++++++++++++
 .../selftests/bpf/progs/bpf_tracing_net.h     |  4 +
 8 files changed, 252 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_unix.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v4 1/3 bpf: af_unix: Implement BPF iterator for UNIX domain socket.

This patch implements the BPF iterator for the UNIX domain socket.

Currently, the batch optimisation introduced for the TCP iterator in the commit 04c7820b776f ("bpf: tcp: Bpf iter batching and lock_sock") is not used for the UNIX domain socket. It will require replacing the big lock for the hash table with small locks for each hash list not to block other processes.

---
 include/linux/btf_ids.h |  3 +-
 net/unix/af_unix.c      | 93 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)
include/linux/btf_ids.h +2 -1
index 57890b357f85..bed4b9964581 100644
@@ -172,7 +172,8 @@ extern struct btf_id_set name;
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)		\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
 	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
-	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)			\
+	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)
 
 enum {
 #define BTF_SOCK_TYPE(name, str) name,
net/unix/af_unix.c +93 -0

117 lines not on this page · raw message

Signature · 1 line
2.30.2
Acked-by on v4 1/3
#2 lore raw

Re: [PATCH v4 bpf-next 1/3] bpf: af_unix: Implement BPF iterator for UNIX domain socket.

Quoted 9 lines · Kuniyuki Iwashima

This patch implements the BPF iterator for the UNIX domain socket.

Currently, the batch optimisation introduced for the TCP iterator in the commit 04c7820b776f ("bpf: tcp: Bpf iter batching and lock_sock") is not used for the UNIX domain socket. It will require replacing the big lock for the hash table with small locks for each hash list not to block other processes.

#3 lore raw

PATCH v4 2/3 bpf: Support "%c" in bpf_bprintf_prepare().

In reply to Kuniyuki Iwashima

/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in the name of the abstract UNIX domain socket. The following selftest uses it, so this patch adds support for "%c". Note that it does not support wide character ("%lc" and "%llc") for simplicity.

---
 kernel/bpf/helpers.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/bpf/helpers.c +14 -0
index 15746f779fe1..6d3aaf94e9ac 100644
@@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
 			tmp_buf += err;
 			num_spec++;
 
+			continue;
+		} else if (fmt[i] == 'c') {
+			if (!tmp_buf)
+				goto nocopy_fmt;
+
+			if (tmp_buf_end == tmp_buf) {
+				err = -ENOSPC;
+				goto out;
+			}
+
+			*tmp_buf = raw_args[num_spec];
+			tmp_buf++;
+			num_spec++;
+
 			continue;
 		}
 
Signature · 1 line
2.30.2
Acked-by on v4 2/3
#4 lore raw

Re: [PATCH v4 bpf-next 2/3] bpf: Support "%c" in bpf_bprintf_prepare().

Quoted 6 lines · Kuniyuki Iwashima

/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in the name of the abstract UNIX domain socket. The following selftest uses it, so this patch adds support for "%c". Note that it does not support wide character ("%lc" and "%llc") for simplicity.

#5 lore raw

Re: [PATCH v4 bpf-next 2/3] bpf: Support "%c" in bpf_bprintf_prepare().

In reply to Kuniyuki Iwashima
Quoted 16 lines · Kuniyuki Iwashima

/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in the name of the abstract UNIX domain socket. The following selftest uses it, so this patch adds support for "%c". Note that it does not support wide character ("%lc" and "%llc") for simplicity.

---
 kernel/bpf/helpers.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/bpf/helpers.c +0 -0
index 15746f779fe1..6d3aaf94e9ac 100644

kernel/bpf/helpers.c int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, · line 911

Quoted 5 lines
kernel/bpf/helpers.c +2 -0
@@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
                        tmp_buf += err;
                        num_spec++;
 
+                       continue;
+               } else if (fmt[i] == 'c') {

you are adding new features to printk-like helpers, please add corresponding tests as well. I'm particularly curious how something like "% 9c" (which is now allowed, along with a few other unusual combinations) will work.

Quoted 18 lines
kernel/bpf/helpers.c +12 -1
+                       if (!tmp_buf)
+                               goto nocopy_fmt;
+
+                       if (tmp_buf_end == tmp_buf) {
+                               err = -ENOSPC;
+                               goto out;
+                       }
+
+                       *tmp_buf = raw_args[num_spec];
+                       tmp_buf++;
+                       num_spec++;
+
                        continue;
                }
 
--

2.30.2

#6 lore raw

Re: [PATCH v4 bpf-next 2/3] bpf: Support "%c" in bpf_bprintf_prepare().

From:   Andrii Nakryiko <[email protected]>
Date:   Wed, 11 Aug 2021 14:15:50 -0700
Quoted 20 lines · Kuniyuki Iwashima
Quoted 19 lines

/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in the name of the abstract UNIX domain socket. The following selftest uses it, so this patch adds support for "%c". Note that it does not support wide character ("%lc" and "%llc") for simplicity.

---
 kernel/bpf/helpers.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/bpf/helpers.c +0 -0
index 15746f779fe1..6d3aaf94e9ac 100644
@@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
                        tmp_buf += err;
                        num_spec++;
 
Quoted 7 lines

kernel/bpf/helpers.c int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, · line 911

Quoted 2 lines
kernel/bpf/helpers.c +2 -0
+                       continue;
+               } else if (fmt[i] == 'c') {

you are adding new features to printk-like helpers, please add corresponding tests as well. I'm particularly curious how something like "% 9c" (which is now allowed, along with a few other unusual combinations) will work.

I see. I'll add a test.
I'm now thinking of test like:
1. pin the bpf prog that outputs "% 9c" and other format strings.
2. read and validate it

Is there any related test ?
and is there other complicated fomat strings to test ?

Also, "% 9c" worked as is :)

---8<---

$ sudo ./tools/bpftool/bpftool iter pin ./bpf_iter_unix.o /sys/fs/bpf/unix
$ sudo cat /sys/fs/bpf/unix | head -n 1
        a
$ git diff
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +3 -1
index ad397e2962cf..8a7d5aa4c054 100644
@@ -34,8 +34,10 @@ int dump_unix(struct bpf_iter__unix *ctx)
 
        seq = ctx->meta->seq;
        seq_num = ctx->meta->seq_num;
-       if (seq_num == 0)
+       if (seq_num == 0) {
+               BPF_SEQ_PRINTF(seq, "% 9c\n", 'a');
                BPF_SEQ_PRINTF(seq, "Num               RefCount Protocol Flags    Type St Inode    Path\n");
+       }
 
        BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu",
                       unix_sk,

---8<---

Quoted 18 lines
Quoted 18 lines
kernel/bpf/helpers.c +12 -1
+                       if (!tmp_buf)
+                               goto nocopy_fmt;
+
+                       if (tmp_buf_end == tmp_buf) {
+                               err = -ENOSPC;
+                               goto out;
+                       }
+
+                       *tmp_buf = raw_args[num_spec];
+                       tmp_buf++;
+                       num_spec++;
+
                        continue;
                }
 
--

2.30.2

#7 lore raw

Re: [PATCH v4 bpf-next 2/3] bpf: Support "%c" in bpf_bprintf_prepare().

Quoted 31 lines · Kuniyuki Iwashima
From:   Andrii Nakryiko <[email protected]>
Date:   Wed, 11 Aug 2021 14:15:50 -0700
Quoted 20 lines · Kuniyuki Iwashima
Quoted 19 lines

/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in the name of the abstract UNIX domain socket. The following selftest uses it, so this patch adds support for "%c". Note that it does not support wide character ("%lc" and "%llc") for simplicity.

---
 kernel/bpf/helpers.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/bpf/helpers.c +0 -0
index 15746f779fe1..6d3aaf94e9ac 100644
@@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
                        tmp_buf += err;
                        num_spec++;
 
Quoted 7 lines

kernel/bpf/helpers.c int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, · line 911

Quoted 2 lines
kernel/bpf/helpers.c +2 -0
+                       continue;
+               } else if (fmt[i] == 'c') {

you are adding new features to printk-like helpers, please add corresponding tests as well. I'm particularly curious how something like "% 9c" (which is now allowed, along with a few other unusual combinations) will work.

Quoted 4 lines

I see. I'll add a test.
I'm now thinking of test like:
1. pin the bpf prog that outputs "% 9c" and other format strings.
2. read and validate it

Simpler. Use bpf_snprintf() to test all this logic. bpf_trace_printk(), bpf_snprintf() and bpf_seq_printf() share the same "backend" in kernel. No need to use bpf_iter program for testing this. Look for other snprintf() tests and just extend them.

Quoted 49 lines

Is there any related test ?
and is there other complicated fomat strings to test ?

Also, "% 9c" worked as is :)

---8<---

$ sudo ./tools/bpftool/bpftool iter pin ./bpf_iter_unix.o /sys/fs/bpf/unix
$ sudo cat /sys/fs/bpf/unix | head -n 1
        a
$ git diff
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +3 -2
index ad397e2962cf..8a7d5aa4c054 100644
@@ -34,8 +34,10 @@ int dump_unix(struct bpf_iter__unix *ctx)
 
        seq = ctx->meta->seq;
        seq_num = ctx->meta->seq_num;
-       if (seq_num == 0)
+       if (seq_num == 0) {
+               BPF_SEQ_PRINTF(seq, "% 9c\n", 'a');
                BPF_SEQ_PRINTF(seq, "Num               RefCount Protocol Flags    Type St Inode    Path\n");
+       }
 
        BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu",
                       unix_sk,
---8<---
Quoted 21 lines
Quoted 21 lines
kernel/bpf/helpers.c +12 -1
+                       if (!tmp_buf)
+                               goto nocopy_fmt;
+
+                       if (tmp_buf_end == tmp_buf) {
+                               err = -ENOSPC;
+                               goto out;
+                       }
+
+                       *tmp_buf = raw_args[num_spec];
+                       tmp_buf++;
+                       num_spec++;
+
                        continue;
                }
 
--

2.30.2

#8 lore raw

Re: [PATCH v4 bpf-next 2/3] bpf: Support "%c" in bpf_bprintf_prepare().

From:   Andrii Nakryiko <[email protected]>
Date:   Wed, 11 Aug 2021 21:24:31 -0700
Quoted 37 lines · Kuniyuki Iwashima
Quoted 31 lines
From:   Andrii Nakryiko <[email protected]>
Date:   Wed, 11 Aug 2021 14:15:50 -0700
Quoted 20 lines · Kuniyuki Iwashima
Quoted 19 lines

/proc/net/unix uses "%c" to print a single-byte character to escape '\0' in the name of the abstract UNIX domain socket. The following selftest uses it, so this patch adds support for "%c". Note that it does not support wide character ("%lc" and "%llc") for simplicity.

---
 kernel/bpf/helpers.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/bpf/helpers.c +0 -0
index 15746f779fe1..6d3aaf94e9ac 100644
@@ -907,6 +907,20 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
                        tmp_buf += err;
                        num_spec++;
 
Quoted 7 lines

kernel/bpf/helpers.c int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, · line 911

Quoted 2 lines
kernel/bpf/helpers.c +2 -0
+                       continue;
+               } else if (fmt[i] == 'c') {

you are adding new features to printk-like helpers, please add corresponding tests as well. I'm particularly curious how something like "% 9c" (which is now allowed, along with a few other unusual combinations) will work.

Quoted 4 lines

I see. I'll add a test.
I'm now thinking of test like:
1. pin the bpf prog that outputs "% 9c" and other format strings.
2. read and validate it

Quoted 4 lines

Simpler. Use bpf_snprintf() to test all this logic. bpf_trace_printk(), bpf_snprintf() and bpf_seq_printf() share the same "backend" in kernel. No need to use bpf_iter program for testing this. Look for other snprintf() tests and just extend them.

I'll extend prog_tests/snprintf.c.
Thank you!

Quoted 50 lines
Quoted 50 lines

Is there any related test ?
and is there other complicated fomat strings to test ?

Also, "% 9c" worked as is :)

---8<---

$ sudo ./tools/bpftool/bpftool iter pin ./bpf_iter_unix.o /sys/fs/bpf/unix
$ sudo cat /sys/fs/bpf/unix | head -n 1
        a
$ git diff
tools/testing/selftests/bpf/progs/bpf_iter_unix.c +3 -2
index ad397e2962cf..8a7d5aa4c054 100644
@@ -34,8 +34,10 @@ int dump_unix(struct bpf_iter__unix *ctx)
 
        seq = ctx->meta->seq;
        seq_num = ctx->meta->seq_num;
-       if (seq_num == 0)
+       if (seq_num == 0) {
+               BPF_SEQ_PRINTF(seq, "% 9c\n", 'a');
                BPF_SEQ_PRINTF(seq, "Num               RefCount Protocol Flags    Type St Inode    Path\n");
+       }
 
        BPF_SEQ_PRINTF(seq, "%pK: %08X %08X %08X %04X %02X %8lu",
                       unix_sk,
---8<---
Quoted 21 lines
Quoted 21 lines
kernel/bpf/helpers.c +12 -1
+                       if (!tmp_buf)
+                               goto nocopy_fmt;
+
+                       if (tmp_buf_end == tmp_buf) {
+                               err = -ENOSPC;
+                               goto out;
+                       }
+
+                       *tmp_buf = raw_args[num_spec];
+                       tmp_buf++;
+                       num_spec++;
+
                        continue;
                }
 
--

2.30.2

#9 lore raw

PATCH v4 3/3 selftest/bpf: Implement sample UNIX domain socket iterator program.

In reply to Kuniyuki Iwashima

The iterator can output the same result compared to /proc/net/unix.

  # cat /sys/fs/bpf/unix
  Num       RefCount Protocol Flags    Type St Inode Path
  ffff9ab7122db000: 00000002 00000000 00010000 0001 01 10623 private/defer
  ffff9fca0023d000: 00000002 00000000 00000000 0001 01 11058 @Hello@World@
  # cat /proc/net/unix
  Num       RefCount Protocol Flags    Type St Inode Path
  ffff9ab7122db000: 00000002 00000000 00010000 0001 01 10623 private/defer
  ffff9fca0023d000: 00000002 00000000 00000000 0001 01 11058 @Hello@World@

Note that this prog requires the patch ([0]) for LLVM code gen. Thanks to Yonghong Song for analysing and fixing.

[0] https://reviews.llvm.org/D107483

---
 tools/testing/selftests/bpf/README.rst        | 38 +++++++++
 .../selftests/bpf/prog_tests/bpf_iter.c       | 16 ++++
 tools/testing/selftests/bpf/progs/bpf_iter.h  |  8 ++
 .../selftests/bpf/progs/bpf_iter_unix.c       | 77 +++++++++++++++++++
 .../selftests/bpf/progs/bpf_tracing_net.h     |  4 +
 5 files changed, 143 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_unix.c
tools/testing/selftests/bpf/README.rst +38 -0
index 9b17f2867488..314a63b69399 100644
@@ -228,3 +228,41 @@ To fix this issue, user newer libbpf.
 .. Links
 .. _clang reloc patch: https://reviews.llvm.org/D102712
 .. _kernel llvm reloc: /Documentation/bpf/llvm_reloc.rst
+
+bpf_iter_unix.o test failure and LLVM optimisation
+==================================================
+
+The ``bpf_iter/unix`` subtest requires `the fix`__ to prevent the LLVM compiler
+from transforming the loop exit condition.
+
+Without the fix, the compiler generates the following code:
+
+.. code-block:: c
+
+  ; 				 for (i = 1; i < len; i++)
+       110:	07 09 00 00 01 00 00 00	r9 += 1
+       111:	5d 98 09 00 00 00 00 00	if r8 != r9 goto +9 <LBB0_18>
+
+The loop exit condition, where the upper bound is not a constant, is
+changed from ``<`` to ``!=``.  Thus, the verifier always evaluates it as true,
+misleading to an infinite loop.
+
+.. code-block:: c
+
+  The sequence of 8193 jumps is too complex.
+  processed 196506 insns (limit 1000000) max_states_per_insn 4 total_states 1830 peak_states 1830 mark_read 3
+
+The fix prevents the optimisation by estimating its cost higher in such a
+case:
+
+.. code-block:: c
+
+  ; 				 for (i = 1; i < len; i++)
+       110:	07 09 00 00 01 00 00 00	r9 += 1
+       111:	ad 89 09 00 00 00 00 00	if r9 < r8 goto +9 <LBB0_18>
+
+The patch is available in LLVM 14 trunk and has been `backported`__ to the LLVM
+13.x release branch.
+
+__ https://reviews.llvm.org/D107483
+__ https://bugs.llvm.org/show_bug.cgi?id=51363
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +16 -0
index 1f1aade56504..77ac24b191d4 100644
@@ -13,6 +13,7 @@
 #include "bpf_iter_tcp6.skel.h"
 #include "bpf_iter_udp4.skel.h"
 #include "bpf_iter_udp6.skel.h"
+#include "bpf_iter_unix.skel.h"
 #include "bpf_iter_test_kern1.skel.h"
 #include "bpf_iter_test_kern2.skel.h"
 #include "bpf_iter_test_kern3.skel.h"
@@ -313,6 +314,19 @@ static void test_udp6(void)
 	bpf_iter_udp6__destroy(skel);
 }
 
+static void test_unix(void)
+{
+	struct bpf_iter_unix *skel;
+
+	skel = bpf_iter_unix__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "bpf_iter_unix__open_and_load"))
+		return;
+
+	do_dummy_read(skel->progs.dump_unix);
+
+	bpf_iter_unix__destroy(skel);
+}
+
 /* The expected string is less than 16 bytes */
 static int do_read_with_fd(int iter_fd, const char *expected,
 			   bool read_one_char)
@@ -1255,6 +1269,8 @@ void test_bpf_iter(void)
 		test_udp4();
 	if (test__start_subtest("udp6"))
 		test_udp6();
+	if (test__start_subtest("unix"))
+		test_unix();
 	if (test__start_subtest("anon"))
 		test_anon_iter(false);
 	if (test__start_subtest("anon-read-one-char"))
tools/testing/selftests/bpf/progs/bpf_iter.h +8 -0
index 3d83b185c4bc..8cfaeba1ddbf 100644
@@ -12,6 +12,7 @@
 #define tcp6_sock tcp6_sock___not_used
 #define bpf_iter__udp bpf_iter__udp___not_used
 #define udp6_sock udp6_sock___not_used
+#define bpf_iter__unix bpf_iter__unix___not_used
 #define bpf_iter__bpf_map_elem bpf_iter__bpf_map_elem___not_used
 #define bpf_iter__bpf_sk_storage_map bpf_iter__bpf_sk_storage_map___not_used
 #define bpf_iter__sockmap bpf_iter__sockmap___not_used
@@ -32,6 +33,7 @@
 #undef tcp6_sock
 #undef bpf_iter__udp
 #undef udp6_sock
+#undef bpf_iter__unix
 #undef bpf_iter__bpf_map_elem
 #undef bpf_iter__bpf_sk_storage_map
 #undef bpf_iter__sockmap
@@ -103,6 +105,12 @@ struct udp6_sock {
 	struct ipv6_pinfo inet6;
 } __attribute__((preserve_access_index));
 
+struct bpf_iter__unix {
+	struct bpf_iter_meta *meta;
+	struct unix_sock *unix_sk;
+	uid_t uid;
+} __attribute__((preserve_access_index));
+
 struct bpf_iter__bpf_map_elem {
 	struct bpf_iter_meta *meta;
 	struct bpf_map *map;
tools/testing/selftests/bpf/progs/bpf_iter_unix.c new file +77 -0

77 lines not on this page · raw message

tools/testing/selftests/bpf/progs/bpf_tracing_net.h +4 -0
index 3af0998a0623..eef5646ddb19 100644
@@ -5,6 +5,10 @@
 #define AF_INET			2
 #define AF_INET6		10
 
+#define __SO_ACCEPTCON		(1 << 16)
+#define UNIX_HASH_SIZE		256
+#define UNIX_ABSTRACT(unix_sk)	(unix_sk->addr->hash < UNIX_HASH_SIZE)
+
 #define SOL_TCP			6
 #define TCP_CONGESTION		13
 #define TCP_CA_NAME_MAX		16
Signature · 1 line
2.30.2
Acked-by on v4 3/3
#10 lore raw

Re: [PATCH v4 bpf-next 3/3] selftest/bpf: Implement sample UNIX domain socket iterator program.

Quoted 5 lines · Kuniyuki Iwashima

The iterator can output the same result compared to /proc/net/unix.

   # cat /sys/fs/bpf/unix
   Num       RefCount Protocol Flags    Type St Inode Path
   ffff9ab7122db000: 00000002 00000000 00010000 0001 01 10623 private/defer

There seems a misalignment between header line and data line.
I know /proc/net/unix having this issue as well. But can we adjust spacing in bpf program to make header/data properly aligned?

Quoted 7 lines
   ffff9fca0023d000: 00000002 00000000 00000000 0001 01 11058 @Hello@World@

   # cat /proc/net/unix
   Num       RefCount Protocol Flags    Type St Inode Path
   ffff9ab7122db000: 00000002 00000000 00010000 0001 01 10623 private/defer
   ffff9fca0023d000: 00000002 00000000 00000000 0001 01 11058 @Hello@World@
Quoted 6 lines

Note that this prog requires the patch ([0]) for LLVM code gen. Thanks to Yonghong Song for analysing and fixing.

[0] https://reviews.llvm.org/D107483

LGTM. Thanks!

#11 lore raw

Re: [PATCH v4 bpf-next 3/3] selftest/bpf: Implement sample UNIX domain socket iterator program.

From:   Yonghong Song <[email protected]>
Date:   Tue, 10 Aug 2021 16:46:49 -0700
Quoted 10 lines · Kuniyuki Iwashima
Quoted 5 lines

The iterator can output the same result compared to /proc/net/unix.

   # cat /sys/fs/bpf/unix
   Num       RefCount Protocol Flags    Type St Inode Path
   ffff9ab7122db000: 00000002 00000000 00010000 0001 01 10623 private/defer

There seems a misalignment between header line and data line. I know /proc/net/unix having this issue as well. But can we adjust spacing in bpf program to make header/data properly aligned?

I just followed /proc/net/unix not to break old parsers :) I'll align it cleanly in the next spin.

Quoted 11 lines
Quoted 11 lines
   ffff9fca0023d000: 00000002 00000000 00000000 0001 01 11058 @Hello@World@

   # cat /proc/net/unix
   Num       RefCount Protocol Flags    Type St Inode Path
   ffff9ab7122db000: 00000002 00000000 00010000 0001 01 10623 private/defer
   ffff9fca0023d000: 00000002 00000000 00000000 0001 01 11058 @Hello@World@

Note that this prog requires the patch ([0]) for LLVM code gen. Thanks to Yonghong Song for analysing and fixing.

Quoted 7 lines
Quoted 3 lines

[0] https://reviews.llvm.org/D107483

LGTM. Thanks!

Thank you, too!!