Zephyr API Documentation 4.5.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
75#define NET_CONTEXT_LOCAL_ADDR_SET BIT(10)
76
77struct net_context;
78
99typedef void (*net_context_recv_cb_t)(struct net_context *context,
100 struct net_pkt *pkt,
101 union net_ip_header *ip_hdr,
102 union net_proto_header *proto_hdr,
103 int status,
104 void *user_data);
105
120typedef void (*net_context_send_cb_t)(struct net_context *context,
121 int status,
122 void *user_data);
123
140typedef void (*net_tcp_accept_cb_t)(struct net_context *new_context,
141 struct net_sockaddr *addr,
142 net_socklen_t addrlen,
143 int status,
144 void *user_data);
145
167typedef void (*net_context_connect_cb_t)(struct net_context *context,
168 int status,
169 void *user_data);
170
171/* The net_pkt_get_slab_func_t is here in order to avoid circular
172 * dependency between net_pkt.h and net_context.h
173 */
182typedef struct k_mem_slab *(*net_pkt_get_slab_func_t)(void);
183
184/* The net_pkt_get_pool_func_t is here in order to avoid circular
185 * dependency between net_pkt.h and net_context.h
186 */
195typedef struct net_buf_pool *(*net_pkt_get_pool_func_t)(void);
196
197struct net_tcp;
198
199struct net_conn_handle;
200
207__net_socket struct net_context {
211
215
219
222 struct k_mutex lock;
223
227 union {
231 struct net_sockaddr_storage local_storage;
232 };
233
237 union {
241 struct net_sockaddr_storage remote_storage;
242 };
243
245 struct net_conn_handle *conn_handler;
246
251
256
261
262#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
266
269 net_pkt_get_pool_func_t data_pool;
270#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
271
272#if defined(CONFIG_NET_TCP)
274 void *tcp;
275#endif /* CONFIG_NET_TCP */
276
277#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
281 struct k_sem recv_data_wait;
282#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
283
284#if defined(CONFIG_NET_CONTEXT_LINGER)
289 struct k_sem linger_sem;
290#endif /* CONFIG_NET_CONTEXT_LINGER */
291
292#if defined(CONFIG_NET_SOCKETS)
294 void *socket_data;
295
300 int sock_error;
301
303 union {
304 struct k_fifo recv_q;
305 struct k_fifo accept_q;
306 };
307
308 struct {
310 struct k_condvar recv;
311
313 struct k_mutex *lock;
314 } cond;
315#endif /* CONFIG_NET_SOCKETS */
316
317#if defined(CONFIG_NET_OFFLOAD)
319 void *offload_context;
320#endif /* CONFIG_NET_OFFLOAD */
321
322#if defined(CONFIG_NET_SOCKETS_CAN)
323 int can_filter_id;
324#endif /* CONFIG_NET_SOCKETS_CAN */
325
327 struct {
328#if defined(CONFIG_NET_CONTEXT_PRIORITY)
330 uint8_t priority;
331#endif
332#if defined(CONFIG_NET_CONTEXT_TXTIME)
334 bool txtime;
335#endif
336#if defined(CONFIG_SOCKS)
338 struct {
339 struct net_sockaddr addr;
340 net_socklen_t addrlen;
341 } proxy;
342#endif
343#if defined(CONFIG_NET_CONTEXT_CLAMP_PORT_RANGE)
355 uint32_t port_range;
356#endif
357#if defined(CONFIG_NET_CONTEXT_RCVTIMEO)
359 k_timeout_t rcvtimeo;
360#endif
361#if defined(CONFIG_NET_CONTEXT_SNDTIMEO)
363 k_timeout_t sndtimeo;
364#endif
365#if defined(CONFIG_NET_CONTEXT_RCVBUF)
367 uint32_t rcvbuf;
368#endif
369#if defined(CONFIG_NET_CONTEXT_SNDBUF)
371 uint32_t sndbuf;
372#endif
373#if defined(CONFIG_NET_CONTEXT_DSCP_ECN)
378 uint8_t dscp_ecn;
379#endif
380#if defined(CONFIG_NET_CONTEXT_REUSEADDR)
382 bool reuseaddr;
383#endif
384#if defined(CONFIG_NET_CONTEXT_REUSEPORT)
386 bool reuseport;
387#endif
390#if defined(CONFIG_NET_IPV4_MAPPING_TO_IPV6)
392 bool ipv6_v6only;
393#endif
394#if defined(CONFIG_NET_CONTEXT_RECV_PKTINFO)
396 bool recv_pktinfo;
397#endif
398#if defined(CONFIG_NET_CONTEXT_RECV_HOPLIMIT)
400 bool recv_hoplimit;
401#endif
402#if defined(CONFIG_NET_IPV6)
407 uint16_t addr_preferences;
408#endif
409#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_IPV4)
410 union {
415 uint8_t ipv6_mcast_ifindex;
416
421 uint8_t ipv4_mcast_ifindex;
422 };
424 union {
425 bool ipv6_mcast_loop;
426 bool ipv4_mcast_loop;
427 };
428
430 bool dont_fragment;
431#endif /* CONFIG_NET_IPV6 || CONFIG_NET_IPV4 */
432
433#if defined(CONFIG_NET_CONTEXT_TIMESTAMPING)
435 uint8_t timestamping;
436#endif
437
438#if defined(CONFIG_NET_CONTEXT_LINGER)
443 struct net_linger linger;
444#endif /* CONFIG_NET_CONTEXT_LINGER */
445
446#if defined(CONFIG_NET_UDP_OPTIONS)
447 struct {
449 uint32_t enabled;
451 uint32_t required;
453 bool drop_all_opts;
455 uint16_t mds;
457 struct net_udp_opt_mrds mrds;
458#if defined(CONFIG_NET_UDP_OPTIONS_DPLPMTUD)
460 struct {
462 struct net_dplpmtud_path path;
464 struct k_work_delayable timer;
466 uint32_t token;
468 uint16_t probe_size;
470 bool enabled;
472 bool app_respond;
474 bool base_confirmed;
476 struct k_work echo_work;
478 struct net_sockaddr_storage echo_peer;
480 net_socklen_t echo_peerlen;
482 uint32_t echo_token;
484 bool echo_pending;
488 uint32_t echo_last_ms;
489 } dplpmtud;
490#endif /* CONFIG_NET_UDP_OPTIONS_DPLPMTUD */
491 } udp_opt;
492#endif
494
497
500
503
505 union {
506 struct {
509 };
510 struct {
513 };
514 };
515
516#if defined(CONFIG_SOCKS)
518 bool proxy_enabled;
519#endif
520
521};
522
530static inline bool net_context_is_used(struct net_context *context)
531{
532 NET_ASSERT(context);
533
534 return context->flags & NET_CONTEXT_IN_USE;
535}
536
544static inline bool net_context_is_bound_to_iface(struct net_context *context)
545{
546 NET_ASSERT(context);
547
548 return context->flags & NET_CONTEXT_BOUND_TO_IFACE;
549}
550
559static inline bool net_context_is_local_addr_set(struct net_context *context)
560{
561 NET_ASSERT(context);
562
563 return context->flags & NET_CONTEXT_LOCAL_ADDR_SET;
564}
565
567
568#define NET_CONTEXT_STATE_SHIFT 1
569#define NET_CONTEXT_STATE_MASK 0x03
570
572
582static inline
583enum net_context_state net_context_get_state(struct net_context *context)
584{
585 NET_ASSERT(context);
586
587 return (enum net_context_state)
588 ((context->flags >> NET_CONTEXT_STATE_SHIFT) &
589 NET_CONTEXT_STATE_MASK);
590}
591
600static inline void net_context_set_state(struct net_context *context,
601 enum net_context_state state)
602{
603 NET_ASSERT(context);
604
605 context->flags &= ~(NET_CONTEXT_STATE_MASK << NET_CONTEXT_STATE_SHIFT);
606 context->flags |= ((state & NET_CONTEXT_STATE_MASK) <<
607 NET_CONTEXT_STATE_SHIFT);
608}
609
621{
622 NET_ASSERT(context);
623
624 return ((context->flags & NET_CONTEXT_FAMILY) >> 3);
625}
626
636static inline void net_context_set_family(struct net_context *context,
637 net_sa_family_t family)
638{
639 uint8_t flag = 0U;
640
641 NET_ASSERT(context);
642
643 if (family == NET_AF_UNSPEC || family == NET_AF_INET || family == NET_AF_INET6 ||
644 family == NET_AF_PACKET || family == NET_AF_CAN) {
645 /* Family is in BIT(4), BIT(5) and BIT(6) */
646 flag = (uint8_t)(family << 3);
647 }
648
649 context->flags |= flag;
650}
651
662static inline
664{
665 NET_ASSERT(context);
666
667 return (enum net_sock_type)((context->flags & NET_CONTEXT_TYPE) >> 6);
668}
669
679static inline void net_context_set_type(struct net_context *context,
680 enum net_sock_type type)
681{
682 uint16_t flag = 0U;
683
684 NET_ASSERT(context);
685
686 if (type == NET_SOCK_DGRAM || type == NET_SOCK_STREAM || type == NET_SOCK_RAW) {
687 /* Type is in BIT(6) and BIT(7)*/
688 flag = (uint16_t)(type << 6);
689 }
690
691 context->flags |= flag;
692}
693
702#if defined(CONFIG_NET_SOCKETS_CAN)
703static inline void net_context_set_can_filter_id(struct net_context *context,
704 int filter_id)
705{
706 NET_ASSERT(context);
707
708 context->can_filter_id = filter_id;
709}
710#else
711static inline void net_context_set_can_filter_id(struct net_context *context,
712 int filter_id)
713{
714 ARG_UNUSED(context);
715 ARG_UNUSED(filter_id);
716}
717#endif
718
728#if defined(CONFIG_NET_SOCKETS_CAN)
729static inline int net_context_get_can_filter_id(struct net_context *context)
730{
731 NET_ASSERT(context);
732
733 return context->can_filter_id;
734}
735#else
736static inline int net_context_get_can_filter_id(struct net_context *context)
737{
738 ARG_UNUSED(context);
739
740 return -1;
741}
742#endif
743
754static inline uint16_t net_context_get_proto(struct net_context *context)
755{
756 return context->proto;
757}
758
769static inline void net_context_set_proto(struct net_context *context,
770 uint16_t proto)
771{
772 context->proto = proto;
773}
774
785static inline
787{
788 NET_ASSERT(context);
789
790 return net_if_get_by_index(context->iface);
791}
792
801static inline void net_context_set_iface(struct net_context *context,
802 struct net_if *iface)
803{
804 NET_ASSERT(context);
805 NET_ASSERT(iface);
806
807 context->iface = (uint8_t)net_if_get_by_iface(iface);
808}
809
818static inline void net_context_bind_iface(struct net_context *context,
819 struct net_if *iface)
820{
821 NET_ASSERT(context);
822 NET_ASSERT(iface);
823
825 net_context_set_iface(context, iface);
826}
827
838static inline uint8_t net_context_get_ipv4_ttl(struct net_context *context)
839{
840 return context->ipv4_ttl;
841}
842
852static inline void net_context_set_ipv4_ttl(struct net_context *context,
853 uint8_t ttl)
854{
855 context->ipv4_ttl = ttl;
856}
857
869{
870 return context->ipv4_mcast_ttl;
871}
872
882static inline void net_context_set_ipv4_mcast_ttl(struct net_context *context,
883 uint8_t ttl)
884{
885 context->ipv4_mcast_ttl = ttl;
886}
887
888#if defined(CONFIG_NET_IPV4)
899static inline bool net_context_get_ipv4_mcast_loop(struct net_context *context)
900{
901 return context->options.ipv4_mcast_loop;
902}
903
913static inline void net_context_set_ipv4_mcast_loop(struct net_context *context,
914 bool ipv4_mcast_loop)
915{
916 context->options.ipv4_mcast_loop = ipv4_mcast_loop;
917}
918#endif
919
931{
932 return context->ipv6_hop_limit;
933}
934
943static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
944 uint8_t hop_limit)
945{
946 context->ipv6_hop_limit = hop_limit;
947}
948
960{
961 return context->ipv6_mcast_hop_limit;
962}
963
973static inline void net_context_set_ipv6_mcast_hop_limit(struct net_context *context,
974 uint8_t hop_limit)
975{
976 context->ipv6_mcast_hop_limit = hop_limit;
977}
978
979#if defined(CONFIG_NET_IPV6)
980
991static inline bool net_context_get_ipv6_mcast_loop(struct net_context *context)
992{
993 return context->options.ipv6_mcast_loop;
994}
995
1005static inline void net_context_set_ipv6_mcast_loop(struct net_context *context,
1006 bool ipv6_mcast_loop)
1007{
1008 context->options.ipv6_mcast_loop = ipv6_mcast_loop;
1009}
1010
1011#endif
1012
1022#if defined(CONFIG_SOCKS)
1023static inline void net_context_set_proxy_enabled(struct net_context *context,
1024 bool enable)
1025{
1026 context->proxy_enabled = enable;
1027}
1028#else
1029static inline void net_context_set_proxy_enabled(struct net_context *context,
1030 bool enable)
1031{
1032 ARG_UNUSED(context);
1033 ARG_UNUSED(enable);
1034}
1035#endif
1036
1047#if defined(CONFIG_SOCKS)
1048static inline bool net_context_is_proxy_enabled(struct net_context *context)
1049{
1050 return context->proxy_enabled;
1051}
1052#else
1053static inline bool net_context_is_proxy_enabled(struct net_context *context)
1054{
1055 ARG_UNUSED(context);
1056 return false;
1057}
1058#endif
1059
1078 enum net_sock_type type,
1079 uint16_t ip_proto,
1080 struct net_context **context);
1081
1095int net_context_put(struct net_context *context);
1096
1109int net_context_ref(struct net_context *context);
1110
1124int net_context_unref(struct net_context *context);
1125
1134static inline void net_context_signal_linger(struct net_context *context)
1135{
1136#if defined(CONFIG_NET_CONTEXT_LINGER)
1137 k_sem_give(&context->linger_sem);
1138#else
1139 ARG_UNUSED(context);
1140#endif /* CONFIG_NET_CONTEXT_LINGER */
1141}
1142
1153#if defined(CONFIG_NET_IPV4)
1154int net_context_create_ipv4_new(struct net_context *context,
1155 struct net_pkt *pkt,
1156 const struct net_in_addr *src,
1157 const struct net_in_addr *dst);
1158#else
1159static inline int net_context_create_ipv4_new(struct net_context *context,
1160 struct net_pkt *pkt,
1161 const struct net_in_addr *src,
1162 const struct net_in_addr *dst)
1163{
1164 return -1;
1165}
1166#endif /* CONFIG_NET_IPV4 */
1167
1178#if defined(CONFIG_NET_IPV6)
1179int net_context_create_ipv6_new(struct net_context *context,
1180 struct net_pkt *pkt,
1181 const struct net_in6_addr *src,
1182 const struct net_in6_addr *dst);
1183#else
1184static inline int net_context_create_ipv6_new(struct net_context *context,
1185 struct net_pkt *pkt,
1186 const struct net_in6_addr *src,
1187 const struct net_in6_addr *dst)
1188{
1189 ARG_UNUSED(context);
1190 ARG_UNUSED(pkt);
1191 ARG_UNUSED(src);
1192 ARG_UNUSED(dst);
1193 return -1;
1194}
1195#endif /* CONFIG_NET_IPV6 */
1196
1208int net_context_bind(struct net_context *context,
1209 const struct net_sockaddr *addr,
1210 net_socklen_t addrlen);
1211
1223 int backlog);
1224
1254 const struct net_sockaddr *addr,
1255 net_socklen_t addrlen,
1257 k_timeout_t timeout,
1258 void *user_data);
1259
1287 k_timeout_t timeout,
1288 void *user_data);
1289
1309int net_context_send(struct net_context *context,
1310 const void *buf,
1311 size_t len,
1313 k_timeout_t timeout,
1314 void *user_data);
1315
1338 const void *buf,
1339 size_t len,
1340 const struct net_sockaddr *dst_addr,
1341 net_socklen_t addrlen,
1343 k_timeout_t timeout,
1344 void *user_data);
1345
1367 const struct net_msghdr *msghdr,
1368 int flags,
1370 k_timeout_t timeout,
1371 void *user_data);
1372
1409int net_context_recv(struct net_context *context,
1411 k_timeout_t timeout,
1412 void *user_data);
1413
1435 int32_t delta);
1436
1483
1495 enum net_context_option option,
1496 const void *value, uint32_t len);
1497
1509 enum net_context_option option,
1510 void *value, uint32_t *len);
1511
1523#if defined(CONFIG_NET_UDP_OPTIONS_DPLPMTUD) || defined(__DOXYGEN__)
1524int net_context_set_udp_dplpmtud(struct net_context *context, bool enable);
1525#else
1526static inline int net_context_set_udp_dplpmtud(struct net_context *context,
1527 bool enable)
1528{
1529 ARG_UNUSED(context);
1530 ARG_UNUSED(enable);
1531
1532 return -ENOTSUP;
1533}
1534#endif /* CONFIG_NET_UDP_OPTIONS_DPLPMTUD */
1535
1543typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
1544
1553
1574#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1575static inline void net_context_setup_pools(struct net_context *context,
1577 net_pkt_get_pool_func_t data_pool)
1578{
1579 NET_ASSERT(context);
1580
1581 context->tx_slab = tx_slab;
1582 context->data_pool = data_pool;
1583}
1584#else
1585#define net_context_setup_pools(context, tx_slab, data_pool)
1586#endif
1587
1602 uint16_t local_port, const struct net_sockaddr *local_addr);
1603
1604#ifdef __cplusplus
1605}
1606#endif
1607
1611
1612#endif /* ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ */
Header file for the Atomic operations API.
Datagram PLPMTUD transport-facing API.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
#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:679
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:943
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:801
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:852
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:1134
void(* net_context_connect_cb_t)(struct net_context *context, int status, void *user_data)
Connection callback.
Definition net_context.h:167
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:663
static bool net_context_is_bound_to_iface(struct net_context *context)
Is this context bound to a network interface.
Definition net_context.h:544
static void net_context_bind_iface(struct net_context *context, struct net_if *iface)
Bind network interface to this context.
Definition net_context.h:818
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:636
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:182
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:868
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:1585
static bool net_context_is_used(struct net_context *context)
Is this context used or not.
Definition net_context.h:530
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:620
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition net_context.h:583
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:711
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:1053
#define NET_CONTEXT_IN_USE
Is this context used or not.
Definition net_context.h:41
#define NET_CONTEXT_LOCAL_ADDR_SET
A local address has been bound to this context.
Definition net_context.h:75
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:736
static bool net_context_is_local_addr_set(struct net_context *context)
Has a local address been bound to this context.
Definition net_context.h:559
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:930
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:959
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:1029
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:838
#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:1543
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:1184
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:600
net_context_option
Network context options.
Definition net_context.h:1438
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:882
void(* net_context_send_cb_t)(struct net_context *context, int status, void *user_data)
Network data send callback.
Definition net_context.h:120
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:769
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition net_context.h:754
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:195
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:1159
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:140
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:973
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:99
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:786
@ NET_OPT_UDP_OPT_MDS
UDP options: Maximum Datagram Size.
Definition net_context.h:1469
@ NET_OPT_UDP_OPT_MRDS
UDP options: Maximum Reassembled Datagram Size.
Definition net_context.h:1470
@ NET_OPT_ADDR_PREFERENCES
IPv6 address preference.
Definition net_context.h:1455
@ NET_OPT_MCAST_TTL
IPv4 multicast TTL.
Definition net_context.h:1451
@ NET_OPT_REUSEADDR
Re-use address.
Definition net_context.h:1447
@ NET_OPT_SNDBUF
Send buffer.
Definition net_context.h:1445
@ NET_OPT_IPV4_MCAST_LOOP
IPV4 multicast loop.
Definition net_context.h:1461
@ NET_OPT_RECV_PKTINFO
Receive packet information.
Definition net_context.h:1450
@ NET_OPT_RECV_HOPLIMIT
Receive hop limit information.
Definition net_context.h:1462
@ NET_OPT_LOCAL_PORT_RANGE
Clamp local port range.
Definition net_context.h:1459
@ NET_OPT_UDP_OPT_DPLPMTUD
UDP options: DPLPMTUD enable (RFC 9869).
Definition net_context.h:1479
@ NET_OPT_PRIORITY
Context priority.
Definition net_context.h:1439
@ NET_OPT_REUSEPORT
Re-use port.
Definition net_context.h:1448
@ NET_OPT_MCAST_HOP_LIMIT
IPv6 multicast hop limit.
Definition net_context.h:1452
@ NET_OPT_UDP_OPT_TIME
UDP options: Timestamp.
Definition net_context.h:1473
@ NET_OPT_RCVTIMEO
Receive timeout.
Definition net_context.h:1442
@ NET_OPT_UDP_OPT_REQ
UDP options: Echo Request.
Definition net_context.h:1471
@ NET_OPT_UDP_OPT_APC
UDP options: Additional Payload Checksum.
Definition net_context.h:1467
@ NET_OPT_TXTIME
TX time.
Definition net_context.h:1440
@ NET_OPT_SNDTIMEO
Send timeout.
Definition net_context.h:1443
@ NET_OPT_UDP_OPT_UEXP
UDP options: UNSAFE Experimental.
Definition net_context.h:1478
@ NET_OPT_MCAST_IFINDEX
IPv6 multicast output network interface index.
Definition net_context.h:1457
@ NET_OPT_UDP_OPT_UCMP
UDP options: UNSAFE Compression.
Definition net_context.h:1476
@ NET_OPT_UDP_OPT_FRAG
UDP options: Fragmentation.
Definition net_context.h:1468
@ NET_OPT_UDP_OPT_OCS
UDP options: Option Checksum.
Definition net_context.h:1466
@ NET_OPT_SOCKS5
SOCKS5.
Definition net_context.h:1441
@ NET_OPT_UDP_OPT_EXP
UDP options: Experimental.
Definition net_context.h:1475
@ NET_OPT_IPV6_MCAST_LOOP
IPV6 multicast loop.
Definition net_context.h:1460
@ NET_OPT_UDP_OPT_AUTH
UDP options: Authentication.
Definition net_context.h:1474
@ NET_OPT_TTL
IPv4 unicast TTL.
Definition net_context.h:1454
@ NET_OPT_RCVBUF
Receive buffer.
Definition net_context.h:1444
@ NET_OPT_UDP_OPT
UDP options master enable (RFC 9868).
Definition net_context.h:1465
@ NET_OPT_DONT_FRAGMENT
Disable local IP fragmentation.
Definition net_context.h:1463
@ NET_OPT_MTU
IPv4 socket path MTU.
Definition net_context.h:1458
@ NET_OPT_UNICAST_HOP_LIMIT
IPv6 unicast hop limit.
Definition net_context.h:1453
@ NET_OPT_LINGER
Socket linger (SO_LINGER).
Definition net_context.h:1464
@ NET_OPT_DSCP_ECN
DSCP ECN.
Definition net_context.h:1446
@ NET_OPT_UDP_OPT_RES
UDP options: Echo Response.
Definition net_context.h:1472
@ NET_OPT_UDP_OPT_UENC
UDP options: UNSAFE Encryption.
Definition net_context.h:1477
@ NET_OPT_TIMESTAMPING
Packet timestamping.
Definition net_context.h:1456
@ NET_OPT_IPV6_V6ONLY
Share IPv4 and IPv6 port space.
Definition net_context.h:1449
@ NET_OPT_UDP_OPT_DPLPMTUD_APP_RESPOND
UDP options: app echoes RES itself.
Definition net_context.h:1480
@ NET_OPT_BROADCAST
Broadcast flag (SO_BROADCAST).
Definition net_context.h:1481
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:86
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:3907
Kernel FIFO structure.
Definition kernel.h:3117
Kernel mutex structure.
Definition kernel.h:3774
Semaphore structure.
Definition kernel.h:4012
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1199
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:207
atomic_t refcount
Reference count.
Definition net_context.h:218
struct net_sockaddr remote
Remote endpoint address.
Definition net_context.h:239
void * user_data
User data associated with a context.
Definition net_context.h:214
void * fifo_reserved
First member of the structure to allow to put contexts into a FIFO.
Definition net_context.h:210
uint16_t flags
Flags for the context.
Definition net_context.h:499
uint8_t ipv4_mcast_ttl
IPv4 multicast TTL.
Definition net_context.h:512
net_context_send_cb_t send_cb
Send callback to be called when the packet has been sent successfully.
Definition net_context.h:255
bool broadcast
Allow sending to a broadcast address (SO_BROADCAST).
Definition net_context.h:389
struct net_sockaddr_storage local_storage
Storage-typed alias of the local endpoint address.
Definition net_context.h:231
struct k_mutex lock
Internal lock for protecting this context from multiple access.
Definition net_context.h:222
struct net_sockaddr local
Local endpoint address.
Definition net_context.h:229
struct net_sockaddr_storage remote_storage
Storage-typed alias of the remote endpoint address.
Definition net_context.h:241
uint8_t ipv4_ttl
IPv4 TTL.
Definition net_context.h:511
uint8_t ipv6_mcast_hop_limit
IPv6 multicast hop limit.
Definition net_context.h:508
net_context_connect_cb_t connect_cb
Connect callback to be called when a connection has been established.
Definition net_context.h:260
struct net_conn_handle * conn_handler
Connection handle.
Definition net_context.h:245
uint16_t proto
Protocol (UDP, TCP or IEEE 802.3 protocol value).
Definition net_context.h:496
int8_t iface
Network interface assigned to this context.
Definition net_context.h:502
void * tcp
TCP connection information.
Definition net_context.h:274
struct net_context::@334350074236271326166202131051343301353247270064 options
Option values.
net_context_recv_cb_t recv_cb
Receive callback to be called when desired packet has been received.
Definition net_context.h:250
uint8_t ipv6_hop_limit
IPv6 hop limit.
Definition net_context.h:507
Network Interface structure.
Definition net_if.h:875
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:462