Zephyr Project API 4.3.2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_context.h
Go to the documentation of this file.
1
6
7/*
8 * Copyright (c) 2016 Intel Corporation
9 * Copyright (c) 2021 Nordic Semiconductor
10 * Copyright (c) 2025 Aerlync Labs Inc.
11 * Copyright 2025 NXP
12 *
13 * SPDX-License-Identifier: Apache-2.0
14 */
15
16#ifndef ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_
17#define ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_
18
27
28#include <zephyr/kernel.h>
29#include <zephyr/sys/atomic.h>
30
31#include <zephyr/net/net_ip.h>
32#include <zephyr/net/net_if.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
40#define NET_CONTEXT_IN_USE BIT(0)
41
43
45enum net_context_state {
46 NET_CONTEXT_IDLE = 0,
47 NET_CONTEXT_UNCONNECTED = 0,
48 NET_CONTEXT_CONFIGURING = 1,
49 NET_CONTEXT_CONNECTING = 1,
50 NET_CONTEXT_READY = 2,
51 NET_CONTEXT_CONNECTED = 2,
52 NET_CONTEXT_LISTENING = 3,
53};
54
56
62#define NET_CONTEXT_FAMILY (BIT(3) | BIT(4) | BIT(5))
63
65#define NET_CONTEXT_TYPE (BIT(6) | BIT(7))
66
68#define NET_CONTEXT_REMOTE_ADDR_SET BIT(8)
69
71#define NET_CONTEXT_ACCEPTING_SOCK BIT(9)
72
74#define NET_CONTEXT_CLOSING_SOCK BIT(10)
75
77#define NET_CONTEXT_BOUND_TO_IFACE BIT(11)
78
79struct net_context;
80
101typedef void (*net_context_recv_cb_t)(struct net_context *context,
102 struct net_pkt *pkt,
103 union net_ip_header *ip_hdr,
104 union net_proto_header *proto_hdr,
105 int status,
106 void *user_data);
107
122typedef void (*net_context_send_cb_t)(struct net_context *context,
123 int status,
124 void *user_data);
125
142typedef void (*net_tcp_accept_cb_t)(struct net_context *new_context,
143 struct sockaddr *addr,
144 socklen_t addrlen,
145 int status,
146 void *user_data);
147
169typedef void (*net_context_connect_cb_t)(struct net_context *context,
170 int status,
171 void *user_data);
172
173/* The net_pkt_get_slab_func_t is here in order to avoid circular
174 * dependency between net_pkt.h and net_context.h
175 */
184typedef struct k_mem_slab *(*net_pkt_get_slab_func_t)(void);
185
186/* The net_pkt_get_pool_func_t is here in order to avoid circular
187 * dependency between net_pkt.h and net_context.h
188 */
197typedef struct net_buf_pool *(*net_pkt_get_pool_func_t)(void);
198
199struct net_tcp;
200
201struct net_conn_handle;
202
209__net_socket struct net_context {
213
217
221
224 struct k_mutex lock;
225
229 struct sockaddr_ptr local;
230
235
237 struct net_conn_handle *conn_handler;
238
243
248
253
254#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
258
261 net_pkt_get_pool_func_t data_pool;
262#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
263
264#if defined(CONFIG_NET_TCP)
266 void *tcp;
267#endif /* CONFIG_NET_TCP */
268
269#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
273 struct k_sem recv_data_wait;
274#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
275
276#if defined(CONFIG_NET_SOCKETS)
278 void *socket_data;
279
284 int sock_error;
285
287 union {
288 struct k_fifo recv_q;
289 struct k_fifo accept_q;
290 };
291
292 struct {
294 struct k_condvar recv;
295
297 struct k_mutex *lock;
298 } cond;
299#endif /* CONFIG_NET_SOCKETS */
300
301#if defined(CONFIG_NET_OFFLOAD)
303 void *offload_context;
304#endif /* CONFIG_NET_OFFLOAD */
305
306#if defined(CONFIG_NET_SOCKETS_CAN)
307 int can_filter_id;
308#endif /* CONFIG_NET_SOCKETS_CAN */
309
311 struct {
312#if defined(CONFIG_NET_CONTEXT_PRIORITY)
314 uint8_t priority;
315#endif
316#if defined(CONFIG_NET_CONTEXT_TXTIME)
318 bool txtime;
319#endif
320#if defined(CONFIG_SOCKS)
322 struct {
323 struct sockaddr addr;
324 socklen_t addrlen;
325 } proxy;
326#endif
327#if defined(CONFIG_NET_CONTEXT_CLAMP_PORT_RANGE)
339 uint32_t port_range;
340#endif
341#if defined(CONFIG_NET_CONTEXT_RCVTIMEO)
343 k_timeout_t rcvtimeo;
344#endif
345#if defined(CONFIG_NET_CONTEXT_SNDTIMEO)
347 k_timeout_t sndtimeo;
348#endif
349#if defined(CONFIG_NET_CONTEXT_RCVBUF)
351 uint16_t rcvbuf;
352#endif
353#if defined(CONFIG_NET_CONTEXT_SNDBUF)
355 uint16_t sndbuf;
356#endif
357#if defined(CONFIG_NET_CONTEXT_DSCP_ECN)
362 uint8_t dscp_ecn;
363#endif
364#if defined(CONFIG_NET_CONTEXT_REUSEADDR)
366 bool reuseaddr;
367#endif
368#if defined(CONFIG_NET_CONTEXT_REUSEPORT)
370 bool reuseport;
371#endif
372#if defined(CONFIG_NET_IPV4_MAPPING_TO_IPV6)
374 bool ipv6_v6only;
375#endif
376#if defined(CONFIG_NET_CONTEXT_RECV_PKTINFO)
378 bool recv_pktinfo;
379#endif
380#if defined(CONFIG_NET_CONTEXT_RECV_HOPLIMIT)
382 bool recv_hoplimit;
383#endif
384#if defined(CONFIG_NET_IPV6)
389 uint16_t addr_preferences;
390#endif
391#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_IPV4)
392 union {
397 uint8_t ipv6_mcast_ifindex;
398
403 uint8_t ipv4_mcast_ifindex;
404 };
406 union {
407 bool ipv6_mcast_loop;
408 bool ipv4_mcast_loop;
409 };
410#endif /* CONFIG_NET_IPV6 || CONFIG_NET_IPV4 */
411
412#if defined(CONFIG_NET_CONTEXT_TIMESTAMPING)
414 uint8_t timestamping;
415#endif
417
420
423
426
428 union {
429 struct {
432 };
433 struct {
436 };
437 };
438
439#if defined(CONFIG_SOCKS)
441 bool proxy_enabled;
442#endif
443
444};
445
453static inline bool net_context_is_used(struct net_context *context)
454{
455 NET_ASSERT(context);
456
457 return context->flags & NET_CONTEXT_IN_USE;
458}
459
467static inline bool net_context_is_bound_to_iface(struct net_context *context)
468{
469 NET_ASSERT(context);
470
471 return context->flags & NET_CONTEXT_BOUND_TO_IFACE;
472}
473
481static inline bool net_context_is_accepting(struct net_context *context)
482{
483 NET_ASSERT(context);
484
485 return context->flags & NET_CONTEXT_ACCEPTING_SOCK;
486}
487
494static inline void net_context_set_accepting(struct net_context *context,
495 bool accepting)
496{
497 NET_ASSERT(context);
498
499 if (accepting) {
501 } else {
503 }
504}
505
513static inline bool net_context_is_closing(struct net_context *context)
514{
515 NET_ASSERT(context);
516
517 return context->flags & NET_CONTEXT_CLOSING_SOCK;
518}
519
526static inline void net_context_set_closing(struct net_context *context,
527 bool closing)
528{
529 NET_ASSERT(context);
530
531 if (closing) {
533 } else {
535 }
536}
537
539
540#define NET_CONTEXT_STATE_SHIFT 1
541#define NET_CONTEXT_STATE_MASK 0x03
542
544
554static inline
555enum net_context_state net_context_get_state(struct net_context *context)
556{
557 NET_ASSERT(context);
558
559 return (enum net_context_state)
560 ((context->flags >> NET_CONTEXT_STATE_SHIFT) &
561 NET_CONTEXT_STATE_MASK);
562}
563
572static inline void net_context_set_state(struct net_context *context,
573 enum net_context_state state)
574{
575 NET_ASSERT(context);
576
577 context->flags &= ~(NET_CONTEXT_STATE_MASK << NET_CONTEXT_STATE_SHIFT);
578 context->flags |= ((state & NET_CONTEXT_STATE_MASK) <<
579 NET_CONTEXT_STATE_SHIFT);
580}
581
592static inline sa_family_t net_context_get_family(struct net_context *context)
593{
594 NET_ASSERT(context);
595
596 return ((context->flags & NET_CONTEXT_FAMILY) >> 3);
597}
598
608static inline void net_context_set_family(struct net_context *context,
609 sa_family_t family)
610{
611 uint8_t flag = 0U;
612
613 NET_ASSERT(context);
614
615 if (family == AF_UNSPEC || family == AF_INET || family == AF_INET6 ||
616 family == AF_PACKET || family == AF_CAN) {
617 /* Family is in BIT(4), BIT(5) and BIT(6) */
618 flag = (uint8_t)(family << 3);
619 }
620
621 context->flags |= flag;
622}
623
634static inline
636{
637 NET_ASSERT(context);
638
639 return (enum net_sock_type)((context->flags & NET_CONTEXT_TYPE) >> 6);
640}
641
651static inline void net_context_set_type(struct net_context *context,
652 enum net_sock_type type)
653{
654 uint16_t flag = 0U;
655
656 NET_ASSERT(context);
657
658 if (type == SOCK_DGRAM || type == SOCK_STREAM || type == SOCK_RAW) {
659 /* Type is in BIT(6) and BIT(7)*/
660 flag = (uint16_t)(type << 6);
661 }
662
663 context->flags |= flag;
664}
665
674#if defined(CONFIG_NET_SOCKETS_CAN)
675static inline void net_context_set_can_filter_id(struct net_context *context,
676 int filter_id)
677{
678 NET_ASSERT(context);
679
680 context->can_filter_id = filter_id;
681}
682#else
683static inline void net_context_set_can_filter_id(struct net_context *context,
684 int filter_id)
685{
686 ARG_UNUSED(context);
687 ARG_UNUSED(filter_id);
688}
689#endif
690
700#if defined(CONFIG_NET_SOCKETS_CAN)
701static inline int net_context_get_can_filter_id(struct net_context *context)
702{
703 NET_ASSERT(context);
704
705 return context->can_filter_id;
706}
707#else
708static inline int net_context_get_can_filter_id(struct net_context *context)
709{
710 ARG_UNUSED(context);
711
712 return -1;
713}
714#endif
715
726static inline uint16_t net_context_get_proto(struct net_context *context)
727{
728 return context->proto;
729}
730
741static inline void net_context_set_proto(struct net_context *context,
742 uint16_t proto)
743{
744 context->proto = proto;
745}
746
757static inline
759{
760 NET_ASSERT(context);
761
762 return net_if_get_by_index(context->iface);
763}
764
773static inline void net_context_set_iface(struct net_context *context,
774 struct net_if *iface)
775{
776 NET_ASSERT(iface);
777
778 context->iface = (uint8_t)net_if_get_by_iface(iface);
779}
780
789static inline void net_context_bind_iface(struct net_context *context,
790 struct net_if *iface)
791{
792 NET_ASSERT(iface);
793
795 net_context_set_iface(context, iface);
796}
797
808static inline uint8_t net_context_get_ipv4_ttl(struct net_context *context)
809{
810 return context->ipv4_ttl;
811}
812
822static inline void net_context_set_ipv4_ttl(struct net_context *context,
823 uint8_t ttl)
824{
825 context->ipv4_ttl = ttl;
826}
827
839{
840 return context->ipv4_mcast_ttl;
841}
842
852static inline void net_context_set_ipv4_mcast_ttl(struct net_context *context,
853 uint8_t ttl)
854{
855 context->ipv4_mcast_ttl = ttl;
856}
857
858#if defined(CONFIG_NET_IPV4)
869static inline bool net_context_get_ipv4_mcast_loop(struct net_context *context)
870{
871 return context->options.ipv4_mcast_loop;
872}
873
883static inline void net_context_set_ipv4_mcast_loop(struct net_context *context,
884 bool ipv4_mcast_loop)
885{
886 context->options.ipv4_mcast_loop = ipv4_mcast_loop;
887}
888#endif
889
901{
902 return context->ipv6_hop_limit;
903}
904
913static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
914 uint8_t hop_limit)
915{
916 context->ipv6_hop_limit = hop_limit;
917}
918
930{
931 return context->ipv6_mcast_hop_limit;
932}
933
943static inline void net_context_set_ipv6_mcast_hop_limit(struct net_context *context,
944 uint8_t hop_limit)
945{
946 context->ipv6_mcast_hop_limit = hop_limit;
947}
948
949#if defined(CONFIG_NET_IPV6)
950
961static inline bool net_context_get_ipv6_mcast_loop(struct net_context *context)
962{
963 return context->options.ipv6_mcast_loop;
964}
965
975static inline void net_context_set_ipv6_mcast_loop(struct net_context *context,
976 bool ipv6_mcast_loop)
977{
978 context->options.ipv6_mcast_loop = ipv6_mcast_loop;
979}
980
981#endif
982
992#if defined(CONFIG_SOCKS)
993static inline void net_context_set_proxy_enabled(struct net_context *context,
994 bool enable)
995{
996 context->proxy_enabled = enable;
997}
998#else
999static inline void net_context_set_proxy_enabled(struct net_context *context,
1000 bool enable)
1001{
1002 ARG_UNUSED(context);
1003 ARG_UNUSED(enable);
1004}
1005#endif
1006
1017#if defined(CONFIG_SOCKS)
1018static inline bool net_context_is_proxy_enabled(struct net_context *context)
1019{
1020 return context->proxy_enabled;
1021}
1022#else
1023static inline bool net_context_is_proxy_enabled(struct net_context *context)
1024{
1025 ARG_UNUSED(context);
1026 return false;
1027}
1028#endif
1029
1048 enum net_sock_type type,
1049 uint16_t ip_proto,
1050 struct net_context **context);
1051
1065int net_context_put(struct net_context *context);
1066
1079int net_context_ref(struct net_context *context);
1080
1094int net_context_unref(struct net_context *context);
1095
1106#if defined(CONFIG_NET_IPV4)
1107int net_context_create_ipv4_new(struct net_context *context,
1108 struct net_pkt *pkt,
1109 const struct in_addr *src,
1110 const struct in_addr *dst);
1111#else
1112static inline int net_context_create_ipv4_new(struct net_context *context,
1113 struct net_pkt *pkt,
1114 const struct in_addr *src,
1115 const struct in_addr *dst)
1116{
1117 return -1;
1118}
1119#endif /* CONFIG_NET_IPV4 */
1120
1131#if defined(CONFIG_NET_IPV6)
1132int net_context_create_ipv6_new(struct net_context *context,
1133 struct net_pkt *pkt,
1134 const struct in6_addr *src,
1135 const struct in6_addr *dst);
1136#else
1137static inline int net_context_create_ipv6_new(struct net_context *context,
1138 struct net_pkt *pkt,
1139 const struct in6_addr *src,
1140 const struct in6_addr *dst)
1141{
1142 ARG_UNUSED(context);
1143 ARG_UNUSED(pkt);
1144 ARG_UNUSED(src);
1145 ARG_UNUSED(dst);
1146 return -1;
1147}
1148#endif /* CONFIG_NET_IPV6 */
1149
1161int net_context_bind(struct net_context *context,
1162 const struct sockaddr *addr,
1163 socklen_t addrlen);
1164
1176 int backlog);
1177
1207 const struct sockaddr *addr,
1208 socklen_t addrlen,
1210 k_timeout_t timeout,
1211 void *user_data);
1212
1240 k_timeout_t timeout,
1241 void *user_data);
1242
1262int net_context_send(struct net_context *context,
1263 const void *buf,
1264 size_t len,
1266 k_timeout_t timeout,
1267 void *user_data);
1268
1291 const void *buf,
1292 size_t len,
1293 const struct sockaddr *dst_addr,
1294 socklen_t addrlen,
1296 k_timeout_t timeout,
1297 void *user_data);
1298
1318 const struct msghdr *msghdr,
1319 int flags,
1321 k_timeout_t timeout,
1322 void *user_data);
1323
1360int net_context_recv(struct net_context *context,
1362 k_timeout_t timeout,
1363 void *user_data);
1364
1386 int32_t delta);
1387
1415
1427 enum net_context_option option,
1428 const void *value, uint32_t len);
1429
1441 enum net_context_option option,
1442 void *value, uint32_t *len);
1443
1451typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
1452
1461
1482#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1483static inline void net_context_setup_pools(struct net_context *context,
1485 net_pkt_get_pool_func_t data_pool)
1486{
1487 NET_ASSERT(context);
1488
1489 context->tx_slab = tx_slab;
1490 context->data_pool = data_pool;
1491}
1492#else
1493#define net_context_setup_pools(context, tx_pool, data_pool)
1494#endif
1495
1510 uint16_t local_port, const struct sockaddr *local_addr);
1511
1512#ifdef __cplusplus
1513}
1514#endif
1515
1519
1520#endif /* ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ */
long atomic_t
Definition atomic_types.h:15
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:168
uint32_t socklen_t
Length of a socket address.
Definition net_ip.h:172
#define AF_CAN
Controller Area Network.
Definition net_ip.h:58
#define AF_INET
IP protocol family version 4.
Definition net_ip.h:55
#define AF_INET6
IP protocol family version 6.
Definition net_ip.h:56
#define AF_PACKET
Packet family.
Definition net_ip.h:57
net_sock_type
Socket type.
Definition net_ip.h:88
#define AF_UNSPEC
Unspecified address family.
Definition net_ip.h:54
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
@ SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:90
@ SOCK_RAW
RAW socket type.
Definition net_ip.h:91
@ SOCK_STREAM
Stream socket type.
Definition net_ip.h:89
static void net_context_set_type(struct net_context *context, enum net_sock_type type)
Set context type for this network context.
Definition net_context.h:651
static void net_context_set_ipv6_hop_limit(struct net_context *context, uint8_t hop_limit)
Set IPv6 hop limit value for this context.
Definition net_context.h:913
int net_context_unref(struct net_context *context)
Decrement the reference count to a network context.
int net_context_bind(struct net_context *context, const struct sockaddr *addr, socklen_t addrlen)
Assign a socket a local address.
static void net_context_set_iface(struct net_context *context, struct net_if *iface)
Set network interface for this context.
Definition net_context.h:773
static void net_context_set_ipv4_ttl(struct net_context *context, uint8_t ttl)
Set IPv4 TTL (time-to-live) value for this context.
Definition net_context.h:822
void(* net_context_connect_cb_t)(struct net_context *context, int status, void *user_data)
Connection callback.
Definition net_context.h:169
int net_context_accept(struct net_context *context, net_tcp_accept_cb_t cb, k_timeout_t timeout, void *user_data)
Accept a network connection attempt.
int net_context_put(struct net_context *context)
Close and unref a network context.
static enum net_sock_type net_context_get_type(struct net_context *context)
Get context type for this network context.
Definition net_context.h:635
static bool net_context_is_accepting(struct net_context *context)
Is this context is accepting data now.
Definition net_context.h:481
static sa_family_t net_context_get_family(struct net_context *context)
Get address family for this network context.
Definition net_context.h:592
static bool net_context_is_bound_to_iface(struct net_context *context)
Is this context bound to a network interface.
Definition net_context.h:467
static void net_context_bind_iface(struct net_context *context, struct net_if *iface)
Bind network interface to this context.
Definition net_context.h:789
int net_context_listen(struct net_context *context, int backlog)
Mark the context as a listening one.
struct k_mem_slab *(* net_pkt_get_slab_func_t)(void)
Function that is called to get the slab that is used for net_pkt allocations.
Definition net_context.h:184
static uint8_t net_context_get_ipv4_mcast_ttl(struct net_context *context)
Get IPv4 multicast TTL (time-to-live) value for this context.
Definition net_context.h:838
int net_context_set_option(struct net_context *context, enum net_context_option option, const void *value, uint32_t len)
Set an connection option for this context.
static bool net_context_is_used(struct net_context *context)
Is this context used or not.
Definition net_context.h:453
int net_context_sendmsg(struct net_context *context, const struct msghdr *msghdr, int flags, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data)
Send data in iovec to a peer specified in msghdr struct.
int net_context_ref(struct net_context *context)
Take a reference count to a net_context, preventing destruction.
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition net_context.h:555
int net_context_connect(struct net_context *context, const struct sockaddr *addr, socklen_t addrlen, net_context_connect_cb_t cb, k_timeout_t timeout, void *user_data)
Create a network connection.
static void net_context_set_can_filter_id(struct net_context *context, int filter_id)
Set CAN filter id for this network context.
Definition net_context.h:683
static bool net_context_is_proxy_enabled(struct net_context *context)
Is socks proxy support enabled or disabled for this context.
Definition net_context.h:1023
#define NET_CONTEXT_IN_USE
Is this context used or not.
Definition net_context.h:40
static void net_context_set_accepting(struct net_context *context, bool accepting)
Set this context to accept data now.
Definition net_context.h:494
bool net_context_port_in_use(enum net_ip_protocol ip_proto, uint16_t local_port, const struct sockaddr *local_addr)
Check if a port is in use (bound)
static void net_context_set_family(struct net_context *context, sa_family_t family)
Set address family for this network context.
Definition net_context.h:608
static int net_context_create_ipv6_new(struct net_context *context, struct net_pkt *pkt, const struct in6_addr *src, const struct in6_addr *dst)
Create IPv6 packet in provided net_pkt from context.
Definition net_context.h:1137
static int net_context_create_ipv4_new(struct net_context *context, struct net_pkt *pkt, const struct in_addr *src, const struct in_addr *dst)
Create IPv4 packet in provided net_pkt from context.
Definition net_context.h:1112
int net_context_recv(struct net_context *context, net_context_recv_cb_t cb, k_timeout_t timeout, void *user_data)
Receive network data from a peer specified by context.
static int net_context_get_can_filter_id(struct net_context *context)
Get CAN filter id for this network context.
Definition net_context.h:708
#define NET_CONTEXT_CLOSING_SOCK
Is the socket closing / closed.
Definition net_context.h:74
static uint8_t net_context_get_ipv6_hop_limit(struct net_context *context)
Get IPv6 hop limit value for this context.
Definition net_context.h:900
static void net_context_set_closing(struct net_context *context, bool closing)
Set this context to closing.
Definition net_context.h:526
static uint8_t net_context_get_ipv6_mcast_hop_limit(struct net_context *context)
Get IPv6 multicast hop limit value for this context.
Definition net_context.h:929
static void net_context_set_proxy_enabled(struct net_context *context, bool enable)
Enable or disable socks proxy support for this context.
Definition net_context.h:999
static uint8_t net_context_get_ipv4_ttl(struct net_context *context)
Get IPv4 TTL (time-to-live) value for this context.
Definition net_context.h:808
#define NET_CONTEXT_BOUND_TO_IFACE
Context is bound to a specific interface.
Definition net_context.h:77
void(* net_context_cb_t)(struct net_context *context, void *user_data)
Callback used while iterating over network contexts.
Definition net_context.h:1451
static void net_context_set_state(struct net_context *context, enum net_context_state state)
Set state for this network context.
Definition net_context.h:572
net_context_option
Network context options.
Definition net_context.h:1389
static void net_context_set_ipv4_mcast_ttl(struct net_context *context, uint8_t ttl)
Set IPv4 multicast TTL (time-to-live) value for this context.
Definition net_context.h:852
void(* net_context_send_cb_t)(struct net_context *context, int status, void *user_data)
Network data send callback.
Definition net_context.h:122
int net_context_update_recv_wnd(struct net_context *context, int32_t delta)
Update TCP receive window for context.
void net_context_foreach(net_context_cb_t cb, void *user_data)
Go through all the network connections and call callback for each network context.
int net_context_get_option(struct net_context *context, enum net_context_option option, void *value, uint32_t *len)
Get connection option value for this context.
void(* net_tcp_accept_cb_t)(struct net_context *new_context, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data)
Accept callback.
Definition net_context.h:142
int net_context_send(struct net_context *context, const void *buf, size_t len, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data)
Send data to a peer.
static bool net_context_is_closing(struct net_context *context)
Is this context closing.
Definition net_context.h:513
#define NET_CONTEXT_FAMILY
The address family, connection type and IP protocol are stored into a bit field to save space.
Definition net_context.h:62
#define NET_CONTEXT_TYPE
Type of the connection (datagram / stream / raw)
Definition net_context.h:65
static void net_context_set_proto(struct net_context *context, uint16_t proto)
Set context IP protocol for this network context.
Definition net_context.h:741
#define net_context_setup_pools(context, tx_pool, data_pool)
Set custom network buffer pools for context send operations.
Definition net_context.h:1493
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition net_context.h:726
int net_context_get(sa_family_t family, enum net_sock_type type, uint16_t ip_proto, struct net_context **context)
Get network context.
struct net_buf_pool *(* net_pkt_get_pool_func_t)(void)
Function that is called to get the pool that is used for net_buf allocations.
Definition net_context.h:197
#define NET_CONTEXT_ACCEPTING_SOCK
Is the socket accepting connections.
Definition net_context.h:71
static void net_context_set_ipv6_mcast_hop_limit(struct net_context *context, uint8_t hop_limit)
Set IPv6 multicast hop limit value for this context.
Definition net_context.h:943
void(* net_context_recv_cb_t)(struct net_context *context, struct net_pkt *pkt, union net_ip_header *ip_hdr, union net_proto_header *proto_hdr, int status, void *user_data)
Network data receive callback.
Definition net_context.h:101
int net_context_sendto(struct net_context *context, const void *buf, size_t len, const struct sockaddr *dst_addr, socklen_t addrlen, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data)
Send data to a peer specified by address.
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:758
@ NET_OPT_ADDR_PREFERENCES
IPv6 address preference.
Definition net_context.h:1406
@ NET_OPT_MCAST_TTL
IPv4 multicast TTL.
Definition net_context.h:1402
@ NET_OPT_REUSEADDR
Re-use address.
Definition net_context.h:1398
@ NET_OPT_SNDBUF
Send buffer.
Definition net_context.h:1396
@ NET_OPT_IPV4_MCAST_LOOP
IPV4 multicast loop.
Definition net_context.h:1412
@ NET_OPT_RECV_PKTINFO
Receive packet information.
Definition net_context.h:1401
@ NET_OPT_RECV_HOPLIMIT
Receive hop limit information.
Definition net_context.h:1413
@ NET_OPT_LOCAL_PORT_RANGE
Clamp local port range.
Definition net_context.h:1410
@ NET_OPT_PRIORITY
Context priority.
Definition net_context.h:1390
@ NET_OPT_REUSEPORT
Re-use port.
Definition net_context.h:1399
@ NET_OPT_MCAST_HOP_LIMIT
IPv6 multicast hop limit.
Definition net_context.h:1403
@ NET_OPT_RCVTIMEO
Receive timeout.
Definition net_context.h:1393
@ NET_OPT_TXTIME
TX time.
Definition net_context.h:1391
@ NET_OPT_SNDTIMEO
Send timeout.
Definition net_context.h:1394
@ NET_OPT_MCAST_IFINDEX
IPv6 multicast output network interface index.
Definition net_context.h:1408
@ NET_OPT_SOCKS5
SOCKS5.
Definition net_context.h:1392
@ NET_OPT_IPV6_MCAST_LOOP
IPV6 multicast loop.
Definition net_context.h:1411
@ NET_OPT_TTL
IPv4 unicast TTL.
Definition net_context.h:1405
@ NET_OPT_RCVBUF
Receive buffer.
Definition net_context.h:1395
@ NET_OPT_MTU
IPv4 socket path MTU.
Definition net_context.h:1409
@ NET_OPT_UNICAST_HOP_LIMIT
IPv6 unicast hop limit.
Definition net_context.h:1404
@ NET_OPT_DSCP_ECN
DSCP ECN.
Definition net_context.h:1397
@ NET_OPT_TIMESTAMPING
Packet timestamping.
Definition net_context.h:1407
@ NET_OPT_IPV6_V6ONLY
Share IPv4 and IPv6 port space.
Definition net_context.h:1400
int net_if_get_by_iface(struct net_if *iface)
Get interface index according to pointer.
struct net_if * net_if_get_by_index(int index)
Get interface according to index.
Public kernel APIs.
Public API for network interface.
IPv6 and IPv4 definitions.
Network statistics.
flags
Definition parser.h:97
state
Definition parser_state.h:29
ssize_t recv(int sock, void *buf, size_t max_len, int flags)
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72
IPv6 address struct.
Definition net_ip.h:143
IPv4 address struct.
Definition net_ip.h:155
Definition kernel.h:3344
Definition kernel.h:2704
Mutex Structure.
Definition kernel.h:3232
Semaphore structure.
Definition kernel.h:3437
Kernel timeout type.
Definition clock.h:65
Message struct.
Definition net_ip.h:257
Network buffer pool representation.
Definition net_buf.h:1142
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:209
atomic_t refcount
Reference count.
Definition net_context.h:220
void * user_data
User data associated with a context.
Definition net_context.h:216
void * fifo_reserved
First member of the structure to allow to put contexts into a FIFO.
Definition net_context.h:212
uint16_t flags
Flags for the context.
Definition net_context.h:422
uint8_t ipv4_mcast_ttl
IPv4 multicast TTL.
Definition net_context.h:435
net_context_send_cb_t send_cb
Send callback to be called when the packet has been sent successfully.
Definition net_context.h:247
struct sockaddr remote
Remote endpoint address.
Definition net_context.h:234
struct k_mutex lock
Internal lock for protecting this context from multiple access.
Definition net_context.h:224
struct sockaddr_ptr local
Local endpoint address.
Definition net_context.h:229
uint8_t ipv4_ttl
IPv4 TTL.
Definition net_context.h:434
uint8_t ipv6_mcast_hop_limit
IPv6 multicast hop limit.
Definition net_context.h:431
net_context_connect_cb_t connect_cb
Connect callback to be called when a connection has been established.
Definition net_context.h:252
struct net_conn_handle * conn_handler
Connection handle.
Definition net_context.h:237
uint16_t proto
Protocol (UDP, TCP or IEEE 802.3 protocol value)
Definition net_context.h:419
int8_t iface
Network interface assigned to this context.
Definition net_context.h:425
void * tcp
TCP connection information.
Definition net_context.h:266
net_context_recv_cb_t recv_cb
Receive callback to be called when desired packet has been received.
Definition net_context.h:242
uint8_t ipv6_hop_limit
IPv6 hop limit.
Definition net_context.h:430
struct net_context::@301107112163213226102177123023267110210102333022 options
Option values.
Network Interface structure.
Definition net_if.h:726
Network packet.
Definition net_pkt.h:91
Generic sockaddr struct.
Definition net_ip.h:417