net: sockets: Store socket private data into its own variable

Do not try to re-use net_context.user_data field as in many places
(like in accept) it is expected to contain pointer to net_context.
Storing the socket flags will corrupt the value. To simplify and
make things less error prone, use socket specific field in net_context
to store the socket flags.

Fixes #19191

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2019-09-17 09:51:26 +03:00
parent 06733d53df
commit e98f5d37f5
3 changed files with 9 additions and 3 deletions

View file

@ -257,6 +257,9 @@ struct net_context {
#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
#if defined(CONFIG_NET_SOCKETS)
/** BSD socket private data */
void *socket_data;
/** Per-socket packet or connection queues */
union {
struct k_fifo recv_q;

View file

@ -111,6 +111,9 @@ int zsock_socket_internal(int family, int type, int proto)
/* Initialize user_data, all other calls will preserve it */
ctx->user_data = NULL;
/* The socket flags are stored here */
ctx->socket_data = NULL;
/* recv_q and accept_q are in union */
k_fifo_init(&ctx->recv_q);

View file

@ -15,15 +15,15 @@
static inline void sock_set_flag(struct net_context *ctx, uintptr_t mask,
uintptr_t flag)
{
uintptr_t val = POINTER_TO_UINT(ctx->user_data);
uintptr_t val = POINTER_TO_UINT(ctx->socket_data);
val = (val & ~mask) | flag;
(ctx)->user_data = UINT_TO_POINTER(val);
(ctx)->socket_data = UINT_TO_POINTER(val);
}
static inline uintptr_t sock_get_flag(struct net_context *ctx, uintptr_t mask)
{
return POINTER_TO_UINT(ctx->user_data) & mask;
return POINTER_TO_UINT(ctx->socket_data) & mask;
}
#define sock_is_eof(ctx) sock_get_flag(ctx, SOCK_EOF)