Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: add sock_open() for unified socket creation
@ 2026-06-18 13:06 Alex Goltsev
  2026-06-18 21:12 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Alex Goltsev @ 2026-06-18 13:06 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel

From c3d9f58bd314011fdbf18bfb9ea2e410898a9770 Mon Sep 17 00:00:00 2001
From: 0-x-0-0 <sasha.goltsev777@gmail.com>
Date: Thu, 18 Jun 2026 15:21:32 +0300
Subject: [PATCH] net: add sock_open() for unified socket creation

Signed-off-by: 0-x-0-0 <sasha.goltsev777@gmail.com>
---
 include/linux/net.h | 14 ++++++++++++++
 net/socket.c        | 31 +++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/linux/net.h b/include/linux/net.h
index f268f395c..18883ea74 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -116,6 +116,18 @@ enum sock_shutdown_cmd {
  SHUT_RDWR,
 };

+/**
+ * enum sock_create_type_t - Socket create types
+ * @SOCK_USER: creates a userspace socket
+ * @SOCK_KERN: creates a kernel socket
+ * @SOCK_LITE: creates a lightweight uninitialized socket
+ */
+enum sock_create_type_t {
+ SOCK_USER,
+ SOCK_KERN,
+ SOCK_LITE,
+};
+
 struct socket_wq {
  /* Note: wait MUST be first field of socket_wq */
  wait_queue_head_t wait;
@@ -273,6 +285,8 @@ int sock_wake_async(struct socket_wq *sk_wq, int
how, int band);
 int sock_register(const struct net_proto_family *fam);
 void sock_unregister(int family);
 bool sock_is_registered(int family);
+int sock_open(int family, int type, int protocol, struct socket **res,
+       enum sock_create_type_t sock_type);
 int __sock_create(struct net *net, int family, int type, int proto,
    struct socket **res, int kern);
 int sock_create(int family, int type, int proto, struct socket **res);
diff --git a/net/socket.c b/net/socket.c
index 63c69a0fa..2c79c022a 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1562,6 +1562,37 @@ int sock_wake_async(struct socket_wq *wq, int
how, int band)
 }
 EXPORT_SYMBOL(sock_wake_async);

+/**
+ * sock_open - creates a socket (unified interface)
+ * @family: protocol family (AF_INET, ...)
+ * @type: communication type (SOCK_STREAM, ...)
+ * @protocol: protocol (0, ...)
+ * @res: new socket
+ * @sock_type: one of SOCK_USER, SOCK_KERN, or SOCK_LITE
+ *
+ * Unified entry point for all socket creation variants.
+ * SOCK_USER creates a userspace socket (via sock_create).
+ * SOCK_KERN creates a kernel socket (via sock_create_kern).
+ * SOCK_LITE creates a lightweight uninitialized socket (via sock_create_lite).
+ *
+ * Return: 0 on success, negative errno on failure. On failure @res is NULL.
+ */
+
+int sock_open(int family, int type, int protocol, struct socket
**res, enum sock_create_type_t sock_type)
+{
+ switch (sock_type) {
+ case SOCK_USER:
+ return sock_create(family, type, protocol, res);
+ case SOCK_KERN:
+ return sock_create_kern(current->nsproxy->net_ns, family, type,
protocol, res);
+ case SOCK_LITE:
+ return sock_create_lite(family, type, protocol, res);
+ default:
+ return -EINVAL;
+ }
+}
+EXPORT_SYMBOL(sock_open);
+
 /**
  * __sock_create - creates a socket
  * @net: net namespace
-- 
2.47.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: add sock_open() for unified socket creation
  2026-06-18 13:06 [PATCH] net: add sock_open() for unified socket creation Alex Goltsev
@ 2026-06-18 21:12 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2026-06-18 21:12 UTC (permalink / raw)
  To: Alex Goltsev; +Cc: davem, netdev, linux-kernel

On Thu, Jun 18, 2026 at 04:06:31PM +0300, Alex Goltsev wrote:

> +/**
> + * sock_open - creates a socket (unified interface)
> + * @family: protocol family (AF_INET, ...)
> + * @type: communication type (SOCK_STREAM, ...)
> + * @protocol: protocol (0, ...)
> + * @res: new socket
> + * @sock_type: one of SOCK_USER, SOCK_KERN, or SOCK_LITE
> + *
> + * Unified entry point for all socket creation variants.
> + * SOCK_USER creates a userspace socket (via sock_create).
> + * SOCK_KERN creates a kernel socket (via sock_create_kern).
> + * SOCK_LITE creates a lightweight uninitialized socket (via sock_create_lite).
> + *
> + * Return: 0 on success, negative errno on failure. On failure @res is NULL.
> + */

What's the point (and why not make it inline, while we are at it)?

Are there really callers that would pass a non-constant value as the last argument,
and if so, what are they doing next?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-18 21:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-18 13:06 [PATCH] net: add sock_open() for unified socket creation Alex Goltsev
2026-06-18 21:12 ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox