net: sockets: Add a way to register a socket family handler
Allow automatic handling of registered socket families. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
252ab55923
commit
89bf1578d9
4 changed files with 58 additions and 1 deletions
|
@ -67,6 +67,16 @@
|
||||||
__net_l2_end = .;
|
__net_l2_end = .;
|
||||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_SOCKETS)
|
||||||
|
SECTION_PROLOGUE(net_socket_register,,)
|
||||||
|
{
|
||||||
|
__net_socket_register_start = .;
|
||||||
|
*(".net_socket_register.init")
|
||||||
|
KEEP(*(SORT_BY_NAME(".net_socket_register.init*")))
|
||||||
|
__net_socket_register_end = .;
|
||||||
|
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||||
|
#endif
|
||||||
|
|
||||||
SECTION_DATA_PROLOGUE(_bt_services_area,,SUBALIGN(4))
|
SECTION_DATA_PROLOGUE(_bt_services_area,,SUBALIGN(4))
|
||||||
{
|
{
|
||||||
_bt_services_start = .;
|
_bt_services_start = .;
|
||||||
|
|
|
@ -719,6 +719,30 @@ static inline char *inet_ntop(sa_family_t family, const void *src, char *dst,
|
||||||
/** sockopt: Don't support IPv4 access (ignored, for compatibility) */
|
/** sockopt: Don't support IPv4 access (ignored, for compatibility) */
|
||||||
#define IPV6_V6ONLY 26
|
#define IPV6_V6ONLY 26
|
||||||
|
|
||||||
|
/** @cond INTERNAL_HIDDEN */
|
||||||
|
/**
|
||||||
|
* @brief Registration information for a given BSD socket family.
|
||||||
|
*/
|
||||||
|
struct net_socket_register {
|
||||||
|
int family;
|
||||||
|
bool (*is_supported)(int family, int type, int proto);
|
||||||
|
int (*handler)(int family, int type, int proto);
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NET_SOCKET_GET_NAME(socket_name) \
|
||||||
|
(__net_socket_register_##socket_name)
|
||||||
|
|
||||||
|
#define NET_SOCKET_REGISTER(socket_name, _family, _is_supported, _handler) \
|
||||||
|
static const struct net_socket_register \
|
||||||
|
(NET_SOCKET_GET_NAME(socket_name)) __used \
|
||||||
|
__attribute__((__section__(".net_socket_register.init"))) = { \
|
||||||
|
.family = _family, \
|
||||||
|
.is_supported = _is_supported, \
|
||||||
|
.handler = _handler, \
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @endcond */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -896,7 +896,8 @@ class SizeCalculator:
|
||||||
# These get copied into RAM only on non-XIP
|
# These get copied into RAM only on non-XIP
|
||||||
ro_sections = ["text", "ctors", "init_array", "reset", "object_access",
|
ro_sections = ["text", "ctors", "init_array", "reset", "object_access",
|
||||||
"rodata", "devconfig", "net_l2", "vector", "sw_isr_table",
|
"rodata", "devconfig", "net_l2", "vector", "sw_isr_table",
|
||||||
"_bt_settings_area", "_bt_services_area", "vectors"]
|
"_bt_settings_area", "_bt_services_area", "vectors",
|
||||||
|
"net_socket_register"]
|
||||||
|
|
||||||
def __init__(self, filename, extra_sections):
|
def __init__(self, filename, extra_sections):
|
||||||
"""Constructor
|
"""Constructor
|
||||||
|
|
|
@ -20,6 +20,9 @@ LOG_MODULE_REGISTER(net_sock, CONFIG_NET_SOCKETS_LOG_LEVEL);
|
||||||
|
|
||||||
#include "sockets_internal.h"
|
#include "sockets_internal.h"
|
||||||
|
|
||||||
|
extern struct net_socket_register __net_socket_register_start[];
|
||||||
|
extern struct net_socket_register __net_socket_register_end[];
|
||||||
|
|
||||||
#define SET_ERRNO(x) \
|
#define SET_ERRNO(x) \
|
||||||
{ int _err = x; if (_err < 0) { errno = -_err; return -1; } }
|
{ int _err = x; if (_err < 0) { errno = -_err; return -1; } }
|
||||||
|
|
||||||
|
@ -129,6 +132,25 @@ int zsock_socket_internal(int family, int type, int proto)
|
||||||
|
|
||||||
int z_impl_zsock_socket(int family, int type, int proto)
|
int z_impl_zsock_socket(int family, int type, int proto)
|
||||||
{
|
{
|
||||||
|
struct net_socket_register *sock_family;
|
||||||
|
|
||||||
|
for (sock_family = __net_socket_register_start;
|
||||||
|
sock_family != __net_socket_register_end;
|
||||||
|
sock_family++) {
|
||||||
|
if (sock_family->family != family &&
|
||||||
|
sock_family->family != AF_UNSPEC) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
NET_ASSERT(sock_family->is_supported);
|
||||||
|
|
||||||
|
if (!sock_family->is_supported(family, type, proto)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sock_family->handler(family, type, proto);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
|
||||||
if (((proto >= IPPROTO_TLS_1_0) && (proto <= IPPROTO_TLS_1_2)) ||
|
if (((proto >= IPPROTO_TLS_1_0) && (proto <= IPPROTO_TLS_1_2)) ||
|
||||||
(proto >= IPPROTO_DTLS_1_0 && proto <= IPPROTO_DTLS_1_2)) {
|
(proto >= IPPROTO_DTLS_1_0 && proto <= IPPROTO_DTLS_1_2)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue