Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: socket: syscall for socketpair(2) #24367

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/net/net_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ extern "C" {
#define PF_PACKET 3 /**< Packet family. */
#define PF_CAN 4 /**< Controller Area Network. */
#define PF_NET_MGMT 5 /**< Network management info. */
#define PF_LOCAL 6 /**< Inter-process communication */
#define PF_UNIX PF_LOCAL /**< Inter-process communication */

/* Address families. */
#define AF_UNSPEC PF_UNSPEC /**< Unspecified address family. */
Expand All @@ -53,6 +55,8 @@ extern "C" {
#define AF_PACKET PF_PACKET /**< Packet family. */
#define AF_CAN PF_CAN /**< Controller Area Network. */
#define AF_NET_MGMT PF_NET_MGMT /**< Network management info. */
#define AF_LOCAL PF_LOCAL /**< Inter-process communication */
#define AF_UNIX PF_UNIX /**< Inter-process communication */

/** Protocol numbers from IANA/BSD */
enum net_ip_protocol {
Expand Down Expand Up @@ -341,6 +345,12 @@ struct sockaddr_storage {
char data[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
};

/* Socket address struct for UNIX domain sockets */
struct sockaddr_un {
sa_family_t sun_family; /* AF_UNIX */
char sun_path[NET_SOCKADDR_MAX_SIZE - sizeof(sa_family_t)];
};

struct net_addr {
sa_family_t family;
union {
Expand Down
19 changes: 19 additions & 0 deletions include/net/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ struct zsock_addrinfo {
*/
__syscall int zsock_socket(int family, int type, int proto);

/**
* @brief Create an unnamed pair of connected sockets
*
* @details
* @rst
* See `POSIX.1-2017 article
* <https://pubs.opengroup.org/onlinepubs/009695399/functions/socketpair.html>`__
* for normative description.
* This function is also exposed as ``socketpair()``
* if :option:`CONFIG_NET_SOCKETS_POSIX_NAMES` is defined.
* @endrst
*/
__syscall int zsock_socketpair(int family, int type, int proto, int *sv);

/**
* @brief Close a network socket
*
Expand Down Expand Up @@ -566,6 +580,11 @@ static inline int socket(int family, int type, int proto)
return zsock_socket(family, type, proto);
}

static inline int socketpair(int family, int type, int proto, int sv[2])
{
return zsock_socketpair(family, type, proto, sv);
}

static inline int close(int sock)
{
return zsock_close(sock);
Expand Down
6 changes: 6 additions & 0 deletions include/posix/sys/socket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2019 Linaro Limited
* Copyright (c) 2020 Friedt Professional Engineering Services, Inc
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,6 +19,11 @@ static inline int socket(int family, int type, int proto)
return zsock_socket(family, type, proto);
}

static inline int socketpair(int family, int type, int proto, int sv[2])
{
return zsock_socketpair(family, type, proto, sv);
}

#define SHUT_RD ZSOCK_SHUT_RD
#define SHUT_WR ZSOCK_SHUT_WR
#define SHUT_RDWR ZSOCK_SHUT_RDWR
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/lib/sockets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ if(CONFIG_SOCKS)
zephyr_include_directories(${ZEPHYR_BASE}/subsys/net/lib/socks)
endif()

zephyr_sources_ifdef(CONFIG_NET_SOCKETPAIR socketpair.c)

zephyr_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)
14 changes: 14 additions & 0 deletions subsys/net/lib/sockets/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ config NET_SOCKETS_CAN_RECEIVERS
The value tells how many sockets can receive data from same
Socket-CAN interface.

config NET_SOCKETPAIR
bool "Support for the socketpair syscall [EXPERIMENTAL]"
help
Choose y here if you would like to use the socketpair(2)
system call.

config NET_SOCKETPAIR_BUFFER_SIZE
int "Size of the intermediate buffer, in bytes"
default 64
range 64 1048576
depends on NET_SOCKETPAIR
help
Buffer size for socketpair(2)

config NET_SOCKETS_NET_MGMT
bool "Enable network management socket support [EXPERIMENTAL]"
depends on NET_MGMT_EVENT
Expand Down
Loading