Skip to content

Commit 0dbdcc7

Browse files
rluboscfriedt
authored andcommitted
net: sockets: Add socket processing priority
When creating a socket, all of the registered socket implementation are processed in a sequence, allowing to find appropriate socket implementation for specified family/type/protocol. So far however, the order of processing was not clearly defined, leaving ambiguity if multiple implmentations supported the same set of parameters. Fix this, by registering socket priority along with implementation. This makes the processing order of particular socket implementations explicit, giving more flexibility to the user, for example when it's neeed to prioritze one implementation over another if they support the same set of parameters. Signed-off-by: Robert Lubos <[email protected]>
1 parent 8b851af commit 0dbdcc7

File tree

12 files changed

+58
-25
lines changed

12 files changed

+58
-25
lines changed

drivers/modem/quectel-bg9x.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,4 +1203,5 @@ NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, modem_init, NULL,
12031203
&api_funcs, MDM_MAX_DATA_LENGTH);
12041204

12051205
/* Register NET sockets. */
1206-
NET_SOCKET_REGISTER(quectel_bg9x, AF_UNSPEC, offload_is_supported, offload_socket);
1206+
NET_SOCKET_REGISTER(quectel_bg9x, NET_SOCKET_DEFAULT_PRIO, AF_UNSPEC,
1207+
offload_is_supported, offload_socket);

drivers/modem/ublox-sara-r4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,8 +1956,8 @@ static bool offload_is_supported(int family, int type, int proto)
19561956
return true;
19571957
}
19581958

1959-
NET_SOCKET_REGISTER(ublox_sara_r4, AF_UNSPEC, offload_is_supported,
1960-
offload_socket);
1959+
NET_SOCKET_REGISTER(ublox_sara_r4, NET_SOCKET_DEFAULT_PRIO, AF_UNSPEC,
1960+
offload_is_supported, offload_socket);
19611961

19621962
#if defined(CONFIG_DNS_RESOLVER)
19631963
/* TODO: This is a bare-bones implementation of DNS handling

drivers/wifi/eswifi/eswifi_socket_offload.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ static const struct socket_op_vtable eswifi_socket_fd_op_vtable = {
571571
};
572572

573573
#ifdef CONFIG_NET_SOCKETS_OFFLOAD
574-
NET_SOCKET_REGISTER(eswifi, AF_UNSPEC, eswifi_socket_is_supported,
575-
eswifi_socket_create);
574+
NET_SOCKET_REGISTER(eswifi, NET_SOCKET_DEFAULT_PRIO, AF_UNSPEC,
575+
eswifi_socket_is_supported, eswifi_socket_create);
576576
#endif
577577

578578
static int eswifi_off_getaddrinfo(const char *node, const char *service,

drivers/wifi/simplelink/simplelink_sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,8 @@ static int simplelink_socket_accept(void *obj, struct sockaddr *addr,
12641264
}
12651265

12661266
#ifdef CONFIG_NET_SOCKETS_OFFLOAD
1267-
NET_SOCKET_REGISTER(simplelink, AF_UNSPEC, simplelink_is_supported,
1268-
simplelink_socket_create);
1267+
NET_SOCKET_REGISTER(simplelink, NET_SOCKET_DEFAULT_PRIO, AF_UNSPEC,
1268+
simplelink_is_supported, simplelink_socket_create);
12691269
#endif
12701270

12711271
void simplelink_sockets_init(void)

include/net/socket.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,14 @@ struct net_socket_register {
880880
int (*handler)(int family, int type, int proto);
881881
};
882882

883-
#define NET_SOCKET_GET_NAME(socket_name) \
884-
(__net_socket_register_##socket_name)
883+
#define NET_SOCKET_DEFAULT_PRIO CONFIG_NET_SOCKETS_PRIORITY_DEFAULT
885884

886-
#define NET_SOCKET_REGISTER(socket_name, _family, _is_supported, _handler) \
885+
#define NET_SOCKET_GET_NAME(socket_name, prio) \
886+
(__net_socket_register_##prio##_##socket_name)
887+
888+
#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \
887889
static const STRUCT_SECTION_ITERABLE(net_socket_register, \
888-
NET_SOCKET_GET_NAME(socket_name)) = { \
890+
NET_SOCKET_GET_NAME(socket_name, prio)) = { \
889891
.family = _family, \
890892
.is_supported = _is_supported, \
891893
.handler = _handler, \

subsys/net/lib/sockets/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ menuconfig NET_SOCKETS
1010

1111
if NET_SOCKETS
1212

13+
config NET_SOCKETS_PRIORITY_DEFAULT
14+
int "Default processing priority for sockets"
15+
default 50
16+
help
17+
Default processing priority for socket implementations. This defines
18+
the order of processing of particular socket implementations when
19+
creating a new socket, lower value indicate earlier processing. This
20+
allows to for instance prioritize offloaded socket processing during
21+
socket creation over the native one, or vice versa.
22+
1323
config NET_SOCKETS_POSIX_NAMES
1424
bool "POSIX names for Sockets API (without full POSIX API)"
1525
default y if !POSIX_API
@@ -62,6 +72,13 @@ config NET_SOCKETS_SOCKOPT_TLS
6272
Enable TLS socket option support which automatically establishes
6373
a TLS connection to the remote host.
6474

75+
config NET_SOCKETS_TLS_PRIORITY
76+
int "Default processing priority for TLS sockets"
77+
default 45
78+
help
79+
Processing priority for TLS sockets. Should be lower than
80+
NET_SOCKETS_PRIORITY_DEFAULT in order to be processed correctly.
81+
6582
config NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH
6683
bool "Set Maximum Fragment Length (MFL)"
6784
default y

subsys/net/lib/sockets/sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,6 @@ static bool inet_is_supported(int family, int type, int proto)
22172217
return true;
22182218
}
22192219

2220-
NET_SOCKET_REGISTER(af_inet46, AF_UNSPEC, inet_is_supported,
2221-
zsock_socket_internal);
2220+
NET_SOCKET_REGISTER(af_inet46, NET_SOCKET_DEFAULT_PRIO, AF_UNSPEC,
2221+
inet_is_supported, zsock_socket_internal);
22222222
#endif /* CONFIG_NET_NATIVE */

subsys/net/lib/sockets/sockets_can.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,5 @@ static bool can_is_supported(int family, int type, int proto)
703703
return true;
704704
}
705705

706-
NET_SOCKET_REGISTER(af_can, AF_CAN, can_is_supported, zcan_socket);
706+
NET_SOCKET_REGISTER(af_can, NET_SOCKET_DEFAULT_PRIO, AF_CAN, can_is_supported,
707+
zcan_socket);

subsys/net/lib/sockets/sockets_net_mgmt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,5 @@ static bool net_mgmt_is_supported(int family, int type, int proto)
390390
return true;
391391
}
392392

393-
NET_SOCKET_REGISTER(af_net_mgmt, AF_NET_MGMT, net_mgmt_is_supported,
394-
znet_mgmt_socket);
393+
NET_SOCKET_REGISTER(af_net_mgmt, NET_SOCKET_DEFAULT_PRIO, AF_NET_MGMT,
394+
net_mgmt_is_supported, znet_mgmt_socket);

subsys/net/lib/sockets/sockets_packet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,5 @@ static bool packet_is_supported(int family, int type, int proto)
394394
return false;
395395
}
396396

397-
NET_SOCKET_REGISTER(af_packet, AF_PACKET, packet_is_supported, zpacket_socket);
397+
NET_SOCKET_REGISTER(af_packet, NET_SOCKET_DEFAULT_PRIO, AF_PACKET,
398+
packet_is_supported, zpacket_socket);

0 commit comments

Comments
 (0)