Zephyr Project API 4.4.99
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#include <zephyr/net/dplpmtud.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
41#define NET_CONTEXT_IN_USE BIT(0)
42
44
46enum net_context_state {
47 NET_CONTEXT_IDLE = 0,
48 NET_CONTEXT_UNCONNECTED = 0,
49 NET_CONTEXT_CONFIGURING = 1,
50 NET_CONTEXT_CONNECTING = 1,
51 NET_CONTEXT_READY = 2,
52 NET_CONTEXT_CONNECTED = 2,
53 NET_CONTEXT_LISTENING = 3,
54};
55
57
63#define NET_CONTEXT_FAMILY (BIT(3) | BIT(4) | BIT(5))
64
66#define NET_CONTEXT_TYPE (BIT(6) | BIT(7))
67
69#define NET_CONTEXT_REMOTE_ADDR_SET BIT(8)
70
72#define NET_CONTEXT_BOUND_TO_IFACE BIT(9)
73
74struct net_context;
75
96typedef void (*net_context_recv_cb_t)(struct net_context *context,
97 struct net_pkt *pkt,
98 union net_ip_header *ip_hdr,
99 union net_proto_header *proto_hdr,
100 int status,
101 void *user_data);
102
117typedef void (*net_context_send_cb_t)(struct net_context *context,
118 int status,
119 void *user_data);
120
137typedef void (*net_tcp_accept_cb_t)(struct net_context *new_context,
138 struct net_sockaddr *addr,
139 net_socklen_t addrlen,
140 int status,
141 void *user_data);
142
164typedef void (*net_context_connect_cb_t)(struct net_context *context,
165 int status,
166 void *user_data);
167
168/* The net_pkt_get_slab_func_t is here in order to avoid circular
169 * dependency between net_pkt.h and net_context.h
170 */
179typedef struct k_mem_slab *(*net_pkt_get_slab_func_t)(void);
180
181/* The net_pkt_get_pool_func_t is here in order to avoid circular
182 * dependency between net_pkt.h and net_context.h
183 */
192typedef struct net_buf_pool *(*net_pkt_get_pool_func_t)(void);
193
194struct net_tcp;
195
196struct net_conn_handle;
197
204__net_socket struct net_context {
208
212
216
219 struct k_mutex lock;
220
224 struct net_sockaddr_ptr local;
225
230
232 struct net_conn_handle *conn_handler;
233
238
243
248
249#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
253
256 net_pkt_get_pool_func_t data_pool;
257#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
258
259#if defined(CONFIG_NET_TCP)
261 void *tcp;
262#endif /* CONFIG_NET_TCP */
263
264#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
268 struct k_sem recv_data_wait;
269#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
270
271#if defined(CONFIG_NET_CONTEXT_LINGER)
276 struct k_sem linger_sem;
277#endif /* CONFIG_NET_CONTEXT_LINGER */
278
279#if defined(CONFIG_NET_SOCKETS)
281 void *socket_data;
282
284 union {
285 struct k_fifo recv_q;
286 struct k_fifo accept_q;
287 };
288
289 struct {
291 struct k_condvar recv;
292
294 struct k_mutex *lock;
295 } cond;
296#endif /* CONFIG_NET_SOCKETS */
297
298#if defined(CONFIG_NET_OFFLOAD)
300 void *offload_context;
301#endif /* CONFIG_NET_OFFLOAD */
302
303#if defined(CONFIG_NET_SOCKETS_CAN)
304 int can_filter_id;
305#endif /* CONFIG_NET_SOCKETS_CAN */
306
308 struct {
309#if defined(CONFIG_NET_CONTEXT_PRIORITY)
311 uint8_t priority;
312#endif
313#if defined(CONFIG_NET_CONTEXT_TXTIME)
315 bool txtime;
316#endif
317#if defined(CONFIG_SOCKS)
319 struct {
320 struct net_sockaddr addr;
321 net_socklen_t addrlen;
322 } proxy;
323#endif
324#if defined(CONFIG_NET_CONTEXT_CLAMP_PORT_RANGE)
336 uint32_t port_range;
337#endif
338#if defined(CONFIG_NET_CONTEXT_RCVTIMEO)
340 k_timeout_t rcvtimeo;
341#endif
342#if defined(CONFIG_NET_CONTEXT_SNDTIMEO)
344 k_timeout_t sndtimeo;
345#endif
346#if defined(CONFIG_NET_CONTEXT_RCVBUF)
348 uint16_t rcvbuf;
349#endif
350#if defined(CONFIG_NET_CONTEXT_SNDBUF)
352 uint16_t sndbuf;
353#endif
354#if defined(CONFIG_NET_CONTEXT_DSCP_ECN)
359 uint8_t dscp_ecn;
360#endif
361#if defined(CONFIG_NET_CONTEXT_REUSEADDR)
363 bool reuseaddr;
364#endif
365#if defined(CONFIG_NET_CONTEXT_REUSEPORT)
367 bool reuseport;
368#endif
369#if defined(CONFIG_NET_IPV4_MAPPING_TO_IPV6)
371 bool ipv6_v6only;
372#endif
373#if defined(CONFIG_NET_CONTEXT_RECV_PKTINFO)
375 bool recv_pktinfo;
376#endif
377#if defined(CONFIG_NET_CONTEXT_RECV_HOPLIMIT)
379 bool recv_hoplimit;
380#endif
381#if defined(CONFIG_NET_IPV6)
386 uint16_t addr_preferences;
387#endif
388#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_IPV4)
389 union {
394 uint8_t ipv6_mcast_ifindex;
395
400 uint8_t ipv4_mcast_ifindex;
401 };
403 union {
404 bool ipv6_mcast_loop;
405 bool ipv4_mcast_loop;
406 };
407
409 bool dont_fragment;
410#endif /* CONFIG_NET_IPV6 || CONFIG_NET_IPV4 */
411
412#if defined(CONFIG_NET_CONTEXT_TIMESTAMPING)
414 uint8_t timestamping;
415#endif
416
417#if defined(CONFIG_NET_CONTEXT_LINGER)
422 struct net_linger linger;
423#endif /* CONFIG_NET_CONTEXT_LINGER */
424
425#if defined(CONFIG_NET_UDP_OPTIONS)
426 struct {
428 uint32_t enabled;
430 uint32_t required;
432 bool drop_all_opts;
434 uint16_t mds;
436 struct net_udp_opt_mrds mrds;
437#if defined(CONFIG_NET_UDP_OPTIONS_DPLPMTUD)
439 struct {
441 struct net_dplpmtud_path path;
443 struct k_work_delayable timer;
445 uint32_t token;
447 uint16_t probe_size;
449 bool enabled;
451 bool app_respond;
453 bool base_confirmed;
455 struct k_work echo_work;
457 struct net_sockaddr_storage echo_peer;
459 net_socklen_t echo_peerlen;
461 uint32_t echo_token;
463 bool echo_pending;
467 uint32_t echo_last_ms;
468 } dplpmtud;
469#endif /* CONFIG_NET_UDP_OPTIONS_DPLPMTUD */
470 } udp_opt;
471#endif
473
476
479
482
484 union {
485 struct {
488 };
489 struct {
492 };
493 };
494
495#if defined(CONFIG_SOCKS)
497 bool proxy_enabled;
498#endif
499
500};
501
509static inline bool net_context_is_used(struct net_context *context)
510{
511 NET_ASSERT(context);
512
513 return context->flags & NET_CONTEXT_IN_USE;
514}
515
523static inline bool net_context_is_bound_to_iface(struct net_context *context)
524{
525 NET_ASSERT(context);
526
527 return context->flags & NET_CONTEXT_BOUND_TO_IFACE;
528}
529
531
532#define NET_CONTEXT_STATE_SHIFT 1
533#define NET_CONTEXT_STATE_MASK 0x03
534
536
546static inline
547enum net_context_state net_context_get_state(struct net_context *context)
548{
549 NET_ASSERT(context);
550
551 return (enum net_context_state)
552 ((context->flags >> NET_CONTEXT_STATE_SHIFT) &
553 NET_CONTEXT_STATE_MASK);
554}
555
564static inline void net_context_set_state(struct net_context *context,
565 enum net_context_state state)
566{
567 NET_ASSERT(context);
568
569 context->flags &= ~(NET_CONTEXT_STATE_MASK << NET_CONTEXT_STATE_SHIFT);
570 context->flags |= ((state & NET_CONTEXT_STATE_MASK) <<
571 NET_CONTEXT_STATE_SHIFT);
572}
573
585{
586 NET_ASSERT(context);
587
588 return ((context->flags & NET_CONTEXT_FAMILY) >> 3);
589}
590
600static inline void net_context_set_family(struct net_context *context,
601 net_sa_family_t family)
602{
603 uint8_t flag = 0U;
604
605 NET_ASSERT(context);
606
607 if (family == NET_AF_UNSPEC || family == NET_AF_INET || family == NET_AF_INET6 ||
608 family == NET_AF_PACKET || family == NET_AF_CAN) {
609 /* Family is in BIT(4), BIT(5) and BIT(6) */
610 flag = (uint8_t)(family << 3);
611 }
612
613 context->flags |= flag;
614}
615
626static inline
628{
629 NET_ASSERT(context);
630
631 return (enum net_sock_type)((context->flags & NET_CONTEXT_TYPE) >> 6);
632}
633
643static inline void net_context_set_type(struct net_context *context,
644 enum net_sock_type type)
645{
646 uint16_t flag = 0U;
647
648 NET_ASSERT(context);
649
650 if (type == NET_SOCK_DGRAM || type == NET_SOCK_STREAM || type == NET_SOCK_RAW) {
651 /* Type is in BIT(6) and BIT(7)*/
652 flag = (uint16_t)(type << 6);
653 }
654
655 context->flags |= flag;
656}
657
666#if defined(CONFIG_NET_SOCKETS_CAN)
667static inline void net_context_set_can_filter_id(struct net_context *context,
668 int filter_id)
669{
670 NET_ASSERT(context);
671
672 context->can_filter_id = filter_id;
673}
674#else
675static inline void net_context_set_can_filter_id(struct net_context *context,
676 int filter_id)
677{
678 ARG_UNUSED(context);
679 ARG_UNUSED(filter_id);
680}
681#endif
682
692#if defined(CONFIG_NET_SOCKETS_CAN)
693static inline int net_context_get_can_filter_id(struct net_context *context)
694{
695 NET_ASSERT(context);
696
697 return context->can_filter_id;
698}
699#else
700static inline int net_context_get_can_filter_id(struct net_context *context)
701{
702 ARG_UNUSED(context);
703
704 return -1;
705}
706#endif
707
718static inline uint16_t net_context_get_proto(struct net_context *context)
719{
720 return context->proto;
721}
722
733static inline void net_context_set_proto(struct net_context *context,
734 uint16_t proto)
735{
736 context->proto = proto;
737}
738
749static inline
751{
752 NET_ASSERT(context);
753
754 return net_if_get_by_index(context->iface);
755}
756
765static inline void net_context_set_iface(struct net_context *context,
766 struct net_if *iface)
767{
768 NET_ASSERT(iface);
769
770 context->iface = (uint8_t)net_if_get_by_iface(iface);
771}
772
781static inline void net_context_bind_iface(struct net_context *context,
782 struct net_if *iface)
783{
784 NET_ASSERT(iface);
785
787 net_context_set_iface(context, iface);
788}
789
800static inline uint8_t net_context_get_ipv4_ttl(struct net_context *context)
801{
802 return context->ipv4_ttl;
803}
804
814static inline void net_context_set_ipv4_ttl(struct net_context *context,
815 uint8_t ttl)
816{
817 context->ipv4_ttl = ttl;
818}
819
831{
832 return context->ipv4_mcast_ttl;
833}
834
844static inline void net_context_set_ipv4_mcast_ttl(struct net_context *context,
845 uint8_t ttl)
846{
847 context->ipv4_mcast_ttl = ttl;
848}
849
850#if defined(CONFIG_NET_IPV4)
861static inline bool net_context_get_ipv4_mcast_loop(struct net_context *context)
862{
863 return context->options.ipv4_mcast_loop;
864}
865
875static inline void net_context_set_ipv4_mcast_loop(struct net_context *context,
876 bool ipv4_mcast_loop)
877{
878 context->options.ipv4_mcast_loop = ipv4_mcast_loop;
879}
880#endif
881
893{
894 return context->ipv6_hop_limit;
895}
896
905static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
906 uint8_t hop_limit)
907{
908 context->ipv6_hop_limit = hop_limit;
909}
910
922{
923 return context->ipv6_mcast_hop_limit;
924}
925
935static inline void net_context_set_ipv6_mcast_hop_limit(struct net_context *context,
936 uint8_t hop_limit)
937{
938 context->ipv6_mcast_hop_limit = hop_limit;
939}
940
941#if defined(CONFIG_NET_IPV6)
942
953static inline bool net_context_get_ipv6_mcast_loop(struct net_context *context)
954{
955 return context->options.ipv6_mcast_loop;
956}
957
967static inline void net_context_set_ipv6_mcast_loop(struct net_context *context,
968 bool ipv6_mcast_loop)
969{
970 context->options.ipv6_mcast_loop = ipv6_mcast_loop;
971}
972
973#endif
974
984#if defined(CONFIG_SOCKS)
985static inline void net_context_set_proxy_enabled(struct net_context *context,
986 bool enable)
987{
988 context->proxy_enabled = enable;
989}
990#else
991static inline void net_context_set_proxy_enabled(struct net_context *context,
992 bool enable)
993{
994 ARG_UNUSED(context);
995 ARG_UNUSED(enable);
996}
997#endif
998
1009#if defined(CONFIG_SOCKS)
1010static inline bool net_context_is_proxy_enabled(struct net_context *context)
1011{
1012 return context->proxy_enabled;
1013}
1014#else
1015static inline bool net_context_is_proxy_enabled(struct net_context *context)
1016{
1017 ARG_UNUSED(context);
1018 return false;
1019}
1020#endif
1021
1040 enum net_sock_type type,
1041 uint16_t ip_proto,
1042 struct net_context **context);
1043
1057int net_context_put(struct net_context *context);
1058
1071int net_context_ref(struct net_context *context);
1072
1086int net_context_unref(struct net_context *context);
1087
1096static inline void net_context_signal_linger(struct net_context *context)
1097{
1098#if defined(CONFIG_NET_CONTEXT_LINGER)
1099 k_sem_give(&context->linger_sem);
1100#else
1101 ARG_UNUSED(context);
1102#endif /* CONFIG_NET_CONTEXT_LINGER */
1103}
1104
1115#if defined(CONFIG_NET_IPV4)
1116int net_context_create_ipv4_new(struct net_context *context,
1117 struct net_pkt *pkt,
1118 const struct net_in_addr *src,
1119 const struct net_in_addr *dst);
1120#else
1121static inline int net_context_create_ipv4_new(struct net_context *context,
1122 struct net_pkt *pkt,
1123 const struct net_in_addr *src,
1124 const struct net_in_addr *dst)
1125{
1126 return -1;
1127}
1128#endif /* CONFIG_NET_IPV4 */
1129
1140#if defined(CONFIG_NET_IPV6)
1141int net_context_create_ipv6_new(struct net_context *context,
1142 struct net_pkt *pkt,
1143 const struct net_in6_addr *src,
1144 const struct net_in6_addr *dst);
1145#else
1146static inline int net_context_create_ipv6_new(struct net_context *context,
1147 struct net_pkt *pkt,
1148 const struct net_in6_addr *src,
1149 const struct net_in6_addr *dst)
1150{
1151 ARG_UNUSED(context);
1152 ARG_UNUSED(pkt);
1153 ARG_UNUSED(src);
1154 ARG_UNUSED(dst);
1155 return -1;
1156}
1157#endif /* CONFIG_NET_IPV6 */
1158
1170int net_context_bind(struct net_context *context,
1171 const struct net_sockaddr *addr,
1172 net_socklen_t addrlen);
1173
1185 int backlog);
1186
1216 const struct net_sockaddr *addr,
1217 net_socklen_t addrlen,
1219 k_timeout_t timeout,
1220 void *user_data);
1221
1249 k_timeout_t timeout,
1250 void *user_data);
1251
1271int net_context_send(struct net_context *context,
1272 const void *buf,
1273 size_t len,
1275 k_timeout_t timeout,
1276 void *user_data);
1277
1300 const void *buf,
1301 size_t len,
1302 const struct net_sockaddr *dst_addr,
1303 net_socklen_t addrlen,
1305 k_timeout_t timeout,
1306 void *user_data);
1307
1329 const struct net_msghdr *msghdr,
1330 int flags,
1332 k_timeout_t timeout,
1333 void *user_data);
1334
1371int net_context_recv(struct net_context *context,
1373 k_timeout_t timeout,
1374 void *user_data);
1375
1397 int32_t delta);
1398
1444
1456 enum net_context_option option,
1457 const void *value, uint32_t len);
1458
1470 enum net_context_option option,
1471 void *value, uint32_t *len);
1472
1484#if defined(CONFIG_NET_UDP_OPTIONS_DPLPMTUD) || defined(__DOXYGEN__)
1485int net_context_set_udp_dplpmtud(struct net_context *context, bool enable);
1486#else
1487static inline int net_context_set_udp_dplpmtud(struct net_context *context,
1488 bool enable)
1489{
1490 ARG_UNUSED(context);
1491 ARG_UNUSED(enable);
1492
1493 return -ENOTSUP;
1494}
1495#endif /* CONFIG_NET_UDP_OPTIONS_DPLPMTUD */
1496
1504typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
1505
1514
1535#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1536static inline void net_context_setup_pools(struct net_context *context,
1538 net_pkt_get_pool_func_t data_pool)
1539{
1540 NET_ASSERT(context);
1541
1542 context->tx_slab = tx_slab;
1543 context->data_pool = data_pool;
1544}
1545#else
1546#define net_context_setup_pools(context, tx_slab, data_pool)
1547#endif
1548
1563 uint16_t local_port, const struct net_sockaddr *local_addr);
1564
1565#ifdef __cplusplus
1566}
1567#endif
1568
1572
1573#endif /* ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ */
Datagram PLPMTUD transport-facing API.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
#define NET_AF_PACKET
Packet family.
Definition net_ip.h:57
#define NET_AF_CAN
Controller Area Network.
Definition net_ip.h:58
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
#define NET_AF_INET6
IP protocol family version 6.
Definition net_ip.h:56
#define NET_AF_UNSPEC
Unspecified address family.
Definition net_ip.h:54
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:169
net_sock_type
Socket type.
Definition net_ip.h:89
#define NET_AF_INET
IP protocol family version 4.
Definition net_ip.h:55
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
@ NET_SOCK_STREAM
Stream socket type.
Definition net_ip.h:90
@ NET_SOCK_RAW
RAW socket type.
Definition net_ip.h:92
@ NET_SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:91
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:643
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:905
int net_context_unref(struct net_context *context)
Decrement the reference count to a network context.
static void net_context_set_iface(struct net_context *context, struct net_if *iface)
Set network interface for this context.
Definition net_context.h:765
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:814
static void net_context_signal_linger(struct net_context *context)
Signal that the connection backing a context has been closed by the transport, so a close() blocked o...
Definition net_context.h:1096
void(* net_context_connect_cb_t)(struct net_context *context, int status, void *user_data)
Connection callback.
Definition net_context.h:164
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.
int net_context_bind(struct net_context *context, const struct net_sockaddr *addr, net_socklen_t addrlen)
Assign a socket a local address.
static enum net_sock_type net_context_get_type(struct net_context *context)
Get context type for this network context.
Definition net_context.h:627
static bool net_context_is_bound_to_iface(struct net_context *context)
Is this context bound to a network interface.
Definition net_context.h:523
static void net_context_bind_iface(struct net_context *context, struct net_if *iface)
Bind network interface to this context.
Definition net_context.h:781
static void net_context_set_family(struct net_context *context, net_sa_family_t family)
Set address family for this network context.
Definition net_context.h:600
int net_context_get(net_sa_family_t family, enum net_sock_type type, uint16_t ip_proto, struct net_context **context)
Get network context.
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:179
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:830
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.
#define net_context_setup_pools(context, tx_slab, data_pool)
Set custom network buffer pools for context send operations.
Definition net_context.h:1546
static bool net_context_is_used(struct net_context *context)
Is this context used or not.
Definition net_context.h:509
int net_context_ref(struct net_context *context)
Take a reference count to a net_context, preventing destruction.
static net_sa_family_t net_context_get_family(struct net_context *context)
Get address family for this network context.
Definition net_context.h:584
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition net_context.h:547
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:675
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:1015
#define NET_CONTEXT_IN_USE
Is this context used or not.
Definition net_context.h:41
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:700
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:892
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:921
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:991
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:800
#define NET_CONTEXT_BOUND_TO_IFACE
Context is bound to a specific interface.
Definition net_context.h:72
void(* net_context_cb_t)(struct net_context *context, void *user_data)
Callback used while iterating over network contexts.
Definition net_context.h:1504
static int net_context_create_ipv6_new(struct net_context *context, struct net_pkt *pkt, const struct net_in6_addr *src, const struct net_in6_addr *dst)
Create IPv6 packet in provided net_pkt from context.
Definition net_context.h:1146
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:564
net_context_option
Network context options.
Definition net_context.h:1400
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:844
void(* net_context_send_cb_t)(struct net_context *context, int status, void *user_data)
Network data send callback.
Definition net_context.h:117
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.
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.
#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:63
#define NET_CONTEXT_TYPE
Type of the connection (datagram / stream / raw).
Definition net_context.h:66
bool net_context_port_in_use(enum net_ip_protocol ip_proto, uint16_t local_port, const struct net_sockaddr *local_addr)
Check if a port is in use (bound).
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:733
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition net_context.h:718
int net_context_connect(struct net_context *context, const struct net_sockaddr *addr, net_socklen_t addrlen, net_context_connect_cb_t cb, k_timeout_t timeout, void *user_data)
Create a network connection.
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:192
static int net_context_create_ipv4_new(struct net_context *context, struct net_pkt *pkt, const struct net_in_addr *src, const struct net_in_addr *dst)
Create IPv4 packet in provided net_pkt from context.
Definition net_context.h:1121
int net_context_set_udp_dplpmtud(struct net_context *context, bool enable)
Enable or disable DPLPMTUD (RFC 9869) on a UDP context.
void(* net_tcp_accept_cb_t)(struct net_context *new_context, struct net_sockaddr *addr, net_socklen_t addrlen, int status, void *user_data)
Accept callback.
Definition net_context.h:137
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:935
int net_context_sendmsg(struct net_context *context, const struct net_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 net_msghdr struct.
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:96
int net_context_sendto(struct net_context *context, const void *buf, size_t len, const struct net_sockaddr *dst_addr, net_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:750
@ NET_OPT_UDP_OPT_MDS
UDP options: Maximum Datagram Size.
Definition net_context.h:1431
@ NET_OPT_UDP_OPT_MRDS
UDP options: Maximum Reassembled Datagram Size.
Definition net_context.h:1432
@ NET_OPT_ADDR_PREFERENCES
IPv6 address preference.
Definition net_context.h:1417
@ NET_OPT_MCAST_TTL
IPv4 multicast TTL.
Definition net_context.h:1413
@ NET_OPT_REUSEADDR
Re-use address.
Definition net_context.h:1409
@ NET_OPT_SNDBUF
Send buffer.
Definition net_context.h:1407
@ NET_OPT_IPV4_MCAST_LOOP
IPV4 multicast loop.
Definition net_context.h:1423
@ NET_OPT_RECV_PKTINFO
Receive packet information.
Definition net_context.h:1412
@ NET_OPT_RECV_HOPLIMIT
Receive hop limit information.
Definition net_context.h:1424
@ NET_OPT_LOCAL_PORT_RANGE
Clamp local port range.
Definition net_context.h:1421
@ NET_OPT_UDP_OPT_DPLPMTUD
UDP options: DPLPMTUD enable (RFC 9869).
Definition net_context.h:1441
@ NET_OPT_PRIORITY
Context priority.
Definition net_context.h:1401
@ NET_OPT_REUSEPORT
Re-use port.
Definition net_context.h:1410
@ NET_OPT_MCAST_HOP_LIMIT
IPv6 multicast hop limit.
Definition net_context.h:1414
@ NET_OPT_UDP_OPT_TIME
UDP options: Timestamp.
Definition net_context.h:1435
@ NET_OPT_RCVTIMEO
Receive timeout.
Definition net_context.h:1404
@ NET_OPT_UDP_OPT_REQ
UDP options: Echo Request.
Definition net_context.h:1433
@ NET_OPT_UDP_OPT_APC
UDP options: Additional Payload Checksum.
Definition net_context.h:1429
@ NET_OPT_TXTIME
TX time.
Definition net_context.h:1402
@ NET_OPT_SNDTIMEO
Send timeout.
Definition net_context.h:1405
@ NET_OPT_UDP_OPT_UEXP
UDP options: UNSAFE Experimental.
Definition net_context.h:1440
@ NET_OPT_MCAST_IFINDEX
IPv6 multicast output network interface index.
Definition net_context.h:1419
@ NET_OPT_UDP_OPT_UCMP
UDP options: UNSAFE Compression.
Definition net_context.h:1438
@ NET_OPT_UDP_OPT_FRAG
UDP options: Fragmentation.
Definition net_context.h:1430
@ NET_OPT_UDP_OPT_OCS
UDP options: Option Checksum.
Definition net_context.h:1428
@ NET_OPT_SOCKS5
SOCKS5.
Definition net_context.h:1403
@ NET_OPT_UDP_OPT_EXP
UDP options: Experimental.
Definition net_context.h:1437
@ NET_OPT_IPV6_MCAST_LOOP
IPV6 multicast loop.
Definition net_context.h:1422
@ NET_OPT_UDP_OPT_AUTH
UDP options: Authentication.
Definition net_context.h:1436
@ NET_OPT_TTL
IPv4 unicast TTL.
Definition net_context.h:1416
@ NET_OPT_RCVBUF
Receive buffer.
Definition net_context.h:1406
@ NET_OPT_UDP_OPT
UDP options master enable (RFC 9868).
Definition net_context.h:1427
@ NET_OPT_DONT_FRAGMENT
Disable local IP fragmentation.
Definition net_context.h:1425
@ NET_OPT_MTU
IPv4 socket path MTU.
Definition net_context.h:1420
@ NET_OPT_UNICAST_HOP_LIMIT
IPv6 unicast hop limit.
Definition net_context.h:1415
@ NET_OPT_LINGER
Socket linger (SO_LINGER).
Definition net_context.h:1426
@ NET_OPT_DSCP_ECN
DSCP ECN.
Definition net_context.h:1408
@ NET_OPT_UDP_OPT_RES
UDP options: Echo Response.
Definition net_context.h:1434
@ NET_OPT_UDP_OPT_UENC
UDP options: UNSAFE Encryption.
Definition net_context.h:1439
@ NET_OPT_TIMESTAMPING
Packet timestamping.
Definition net_context.h:1418
@ NET_OPT_IPV6_V6ONLY
Share IPv4 and IPv6 port space.
Definition net_context.h:1411
@ NET_OPT_UDP_OPT_DPLPMTUD_APP_RESPOND
UDP options: app echoes RES itself.
Definition net_context.h:1442
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.
void k_sem_give(struct k_sem *sem)
Give a semaphore.
#define ENOTSUP
Unsupported value.
Definition errno.h:115
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
Kernel condition variable structure.
Definition kernel.h:3693
Kernel FIFO structure.
Definition kernel.h:3023
Kernel mutex structure.
Definition kernel.h:3572
Semaphore structure.
Definition kernel.h:3798
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1151
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:204
atomic_t refcount
Reference count.
Definition net_context.h:215
struct net_sockaddr remote
Remote endpoint address.
Definition net_context.h:229
void * user_data
User data associated with a context.
Definition net_context.h:211
void * fifo_reserved
First member of the structure to allow to put contexts into a FIFO.
Definition net_context.h:207
uint16_t flags
Flags for the context.
Definition net_context.h:478
uint8_t ipv4_mcast_ttl
IPv4 multicast TTL.
Definition net_context.h:491
net_context_send_cb_t send_cb
Send callback to be called when the packet has been sent successfully.
Definition net_context.h:242
struct k_mutex lock
Internal lock for protecting this context from multiple access.
Definition net_context.h:219
struct net_sockaddr_ptr local
Local endpoint address.
Definition net_context.h:224
uint8_t ipv4_ttl
IPv4 TTL.
Definition net_context.h:490
uint8_t ipv6_mcast_hop_limit
IPv6 multicast hop limit.
Definition net_context.h:487
net_context_connect_cb_t connect_cb
Connect callback to be called when a connection has been established.
Definition net_context.h:247
struct net_conn_handle * conn_handler
Connection handle.
Definition net_context.h:232
uint16_t proto
Protocol (UDP, TCP or IEEE 802.3 protocol value).
Definition net_context.h:475
int8_t iface
Network interface assigned to this context.
Definition net_context.h:481
void * tcp
TCP connection information.
Definition net_context.h:261
net_context_recv_cb_t recv_cb
Receive callback to be called when desired packet has been received.
Definition net_context.h:237
uint8_t ipv6_hop_limit
IPv6 hop limit.
Definition net_context.h:486
struct net_context::@301107112163213226102177123023267110210102333022 options
Option values.
Network Interface structure.
Definition net_if.h:744
IPv6 address struct.
Definition net_ip.h:144
IPv4 address struct.
Definition net_ip.h:156
Message struct.
Definition net_ip.h:295
Network packet.
Definition net_pkt.h:119
Generic sockaddr struct.
Definition net_ip.h:455
Header file for the Atomic operations API.