Re: [PATCH bpf-next 4/6] selftests/bpf: Add setsockopt for network_helper_opts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/24/24 8:23 PM, Geliang Tang wrote:
+static int setsockopt_reuseport(int fd, const void *optval, socklen_t optlen)
+{
+	return setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, optval, optlen);
  }

[ ... ]

  void free_fds(int *fds, unsigned int nr_close_fds)
diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h
index c62b54daa914..540ecfc52bd7 100644
--- a/tools/testing/selftests/bpf/network_helpers.h
+++ b/tools/testing/selftests/bpf/network_helpers.h
@@ -28,6 +28,9 @@ struct network_helper_opts {
  	bool noconnect;
  	int type;
  	int proto;
+	int (*setsockopt)(int fd, const void *optval, socklen_t optlen);
+	const void *optval;
+	socklen_t optlen;

optval and optlen could be in the stack of the (*setsockopt) callback.
e.g. the "int on;" could be local to the setsockopt_reuseport() instead of adding optval/len to the network_helper_opts. Passing one optval in network_helper_opts could be less flexible when we want to do multiple setsockopt() after socket().

Another nit I would like to make, rename this from (*setsockopt) to (*post_socket_cb) because this callback could do more than setsockopt, e.g. adding a sk local storage to a socket fd before bind(). Also, add a "const struct post_socket_opts *opts" for future extension, Like:

struct post_socket_opts {};

int (*post_socket_cb)(int fd, const struct post_socket_opts *opts);

Patch 6 will need two setsockopt cb functions because of different optval but I believe the tradeoff is worth it for this callback doing more than just one setsockopt.

Patch 1 to 3 have been applied. Thanks.





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux