Zephyr API Documentation 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
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 net_sockaddr *addr,
144 net_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 net_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
281 union {
282 struct k_fifo recv_q;
283 struct k_fifo accept_q;
284 };
285
286 struct {
288 struct k_condvar recv;
289
291 struct k_mutex *lock;
292 } cond;
293#endif /* CONFIG_NET_SOCKETS */
294
295#if defined(CONFIG_NET_OFFLOAD)
297 void *offload_context;
298#endif /* CONFIG_NET_OFFLOAD */
299
300#if defined(CONFIG_NET_SOCKETS_CAN)
301 int can_filter_id;
302#endif /* CONFIG_NET_SOCKETS_CAN */
303
305 struct {
306#if defined(CONFIG_NET_CONTEXT_PRIORITY)
308 uint8_t priority;
309#endif
310#if defined(CONFIG_NET_CONTEXT_TXTIME)
312 bool txtime;
313#endif
314#if defined(CONFIG_SOCKS)
316 struct {
317 struct net_sockaddr addr;
318 net_socklen_t addrlen;
319 } proxy;
320#endif
321#if defined(CONFIG_NET_CONTEXT_CLAMP_PORT_RANGE)
333 uint32_t port_range;
334#endif
335#if defined(CONFIG_NET_CONTEXT_RCVTIMEO)
337 k_timeout_t rcvtimeo;
338#endif
339#if defined(CONFIG_NET_CONTEXT_SNDTIMEO)
341 k_timeout_t sndtimeo;
342#endif
343#if defined(CONFIG_NET_CONTEXT_RCVBUF)
345 uint16_t rcvbuf;
346#endif
347#if defined(CONFIG_NET_CONTEXT_SNDBUF)
349 uint16_t sndbuf;
350#endif
351#if defined(CONFIG_NET_CONTEXT_DSCP_ECN)
356 uint8_t dscp_ecn;
357#endif
358#if defined(CONFIG_NET_CONTEXT_REUSEADDR)
360 bool reuseaddr;
361#endif
362#if defined(CONFIG_NET_CONTEXT_REUSEPORT)
364 bool reuseport;
365#endif
366#if defined(CONFIG_NET_IPV4_MAPPING_TO_IPV6)
368 bool ipv6_v6only;
369#endif
370#if defined(CONFIG_NET_CONTEXT_RECV_PKTINFO)
372 bool recv_pktinfo;
373#endif
374#if defined(CONFIG_NET_CONTEXT_RECV_HOPLIMIT)
376 bool recv_hoplimit;
377#endif
378#if defined(CONFIG_NET_IPV6)
383 uint16_t addr_preferences;
384#endif
385#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_IPV4)
386 union {
391 uint8_t ipv6_mcast_ifindex;
392
397 uint8_t ipv4_mcast_ifindex;
398 };
400 union {
401 bool ipv6_mcast_loop;
402 bool ipv4_mcast_loop;
403 };
404
406 bool dont_fragment;
407#endif /* CONFIG_NET_IPV6 || CONFIG_NET_IPV4 */
408
409#if defined(CONFIG_NET_CONTEXT_TIMESTAMPING)
411 uint8_t timestamping;
412#endif
414
417
420
423
425 union {
426 struct {
429 };
430 struct {
433 };
434 };
435
436#if defined(CONFIG_SOCKS)
438 bool proxy_enabled;
439#endif
440
441};
442
450static inline bool net_context_is_used(struct net_context *context)
451{
452 NET_ASSERT(context);
453
454 return context->flags & NET_CONTEXT_IN_USE;
455}
456
464static inline bool net_context_is_bound_to_iface(struct net_context *context)
465{
466 NET_ASSERT(context);
467
468 return context->flags & NET_CONTEXT_BOUND_TO_IFACE;
469}
470
478static inline bool net_context_is_accepting(struct net_context *context)
479{
480 NET_ASSERT(context);
481
482 return context->flags & NET_CONTEXT_ACCEPTING_SOCK;
483}
484
491static inline void net_context_set_accepting(struct net_context *context,
492 bool accepting)
493{
494 NET_ASSERT(context);
495
496 if (accepting) {
498 } else {
500 }
501}
502
510static inline bool net_context_is_closing(struct net_context *context)
511{
512 NET_ASSERT(context);
513
514 return context->flags & NET_CONTEXT_CLOSING_SOCK;
515}
516
523static inline void net_context_set_closing(struct net_context *context,
524 bool closing)
525{
526 NET_ASSERT(context);
527
528 if (closing) {
530 } else {
532 }
533}
534
536
537#define NET_CONTEXT_STATE_SHIFT 1
538#define NET_CONTEXT_STATE_MASK 0x03
539
541
551static inline
552enum net_context_state net_context_get_state(struct net_context *context)
553{
554 NET_ASSERT(context);
555
556 return (enum net_context_state)
557 ((context->flags >> NET_CONTEXT_STATE_SHIFT) &
558 NET_CONTEXT_STATE_MASK);
559}
560
569static inline void net_context_set_state(struct net_context *context,
570 enum net_context_state state)
571{
572 NET_ASSERT(context);
573
574 context->flags &= ~(NET_CONTEXT_STATE_MASK << NET_CONTEXT_STATE_SHIFT);
575 context->flags |= ((state & NET_CONTEXT_STATE_MASK) <<
576 NET_CONTEXT_STATE_SHIFT);
577}
578
590{
591 NET_ASSERT(context);
592
593 return ((context->flags & NET_CONTEXT_FAMILY) >> 3);
594}
595
605static inline void net_context_set_family(struct net_context *context,
606 net_sa_family_t family)
607{
608 uint8_t flag = 0U;
609
610 NET_ASSERT(context);
611
612 if (family == NET_AF_UNSPEC || family == NET_AF_INET || family == NET_AF_INET6 ||
613 family == NET_AF_PACKET || family == NET_AF_CAN) {
614 /* Family is in BIT(4), BIT(5) and BIT(6) */
615 flag = (uint8_t)(family << 3);
616 }
617
618 context->flags |= flag;
619}
620
631static inline
633{
634 NET_ASSERT(context);
635
636 return (enum net_sock_type)((context->flags & NET_CONTEXT_TYPE) >> 6);
637}
638
648static inline void net_context_set_type(struct net_context *context,
649 enum net_sock_type type)
650{
651 uint16_t flag = 0U;
652
653 NET_ASSERT(context);
654
655 if (type == NET_SOCK_DGRAM || type == NET_SOCK_STREAM || type == NET_SOCK_RAW) {
656 /* Type is in BIT(6) and BIT(7)*/
657 flag = (uint16_t)(type << 6);
658 }
659
660 context->flags |= flag;
661}
662
671#if defined(CONFIG_NET_SOCKETS_CAN)
672static inline void net_context_set_can_filter_id(struct net_context *context,
673 int filter_id)
674{
675 NET_ASSERT(context);
676
677 context->can_filter_id = filter_id;
678}
679#else
680static inline void net_context_set_can_filter_id(struct net_context *context,
681 int filter_id)
682{
683 ARG_UNUSED(context);
684 ARG_UNUSED(filter_id);
685}
686#endif
687
697#if defined(CONFIG_NET_SOCKETS_CAN)
698static inline int net_context_get_can_filter_id(struct net_context *context)
699{
700 NET_ASSERT(context);
701
702 return context->can_filter_id;
703}
704#else
705static inline int net_context_get_can_filter_id(struct net_context *context)
706{
707 ARG_UNUSED(context);
708
709 return -1;
710}
711#endif
712
723static inline uint16_t net_context_get_proto(struct net_context *context)
724{
725 return context->proto;
726}
727
738static inline void net_context_set_proto(struct net_context *context,
739 uint16_t proto)
740{
741 context->proto = proto;
742}
743
754static inline
756{
757 NET_ASSERT(context);
758
759 return net_if_get_by_index(context->iface);
760}
761
770static inline void net_context_set_iface(struct net_context *context,
771 struct net_if *iface)
772{
773 NET_ASSERT(iface);
774
775 context->iface = (uint8_t)net_if_get_by_iface(iface);
776}
777
786static inline void net_context_bind_iface(struct net_context *context,
787 struct net_if *iface)
788{
789 NET_ASSERT(iface);
790
792 net_context_set_iface(context, iface);
793}
794
805static inline uint8_t net_context_get_ipv4_ttl(struct net_context *context)
806{
807 return context->ipv4_ttl;
808}
809
819static inline void net_context_set_ipv4_ttl(struct net_context *context,
820 uint8_t ttl)
821{
822 context->ipv4_ttl = ttl;
823}
824
836{
837 return context->ipv4_mcast_ttl;
838}
839
849static inline void net_context_set_ipv4_mcast_ttl(struct net_context *context,
850 uint8_t ttl)
851{
852 context->ipv4_mcast_ttl = ttl;
853}
854
855#if defined(CONFIG_NET_IPV4)
866static inline bool net_context_get_ipv4_mcast_loop(struct net_context *context)
867{
868 return context->options.ipv4_mcast_loop;
869}
870
880static inline void net_context_set_ipv4_mcast_loop(struct net_context *context,
881 bool ipv4_mcast_loop)
882{
883 context->options.ipv4_mcast_loop = ipv4_mcast_loop;
884}
885#endif
886
898{
899 return context->ipv6_hop_limit;
900}
901
910static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
911 uint8_t hop_limit)
912{
913 context->ipv6_hop_limit = hop_limit;
914}
915
927{
928 return context->ipv6_mcast_hop_limit;
929}
930
940static inline void net_context_set_ipv6_mcast_hop_limit(struct net_context *context,
941 uint8_t hop_limit)
942{
943 context->ipv6_mcast_hop_limit = hop_limit;
944}
945
946#if defined(CONFIG_NET_IPV6)
947
958static inline bool net_context_get_ipv6_mcast_loop(struct net_context *context)
959{
960 return context->options.ipv6_mcast_loop;
961}
962
972static inline void net_context_set_ipv6_mcast_loop(struct net_context *context,
973 bool ipv6_mcast_loop)
974{
975 context->options.ipv6_mcast_loop = ipv6_mcast_loop;
976}
977
978#endif
979
989#if defined(CONFIG_SOCKS)
990static inline void net_context_set_proxy_enabled(struct net_context *context,
991 bool enable)
992{
993 context->proxy_enabled = enable;
994}
995#else
996static inline void net_context_set_proxy_enabled(struct net_context *context,
997 bool enable)
998{
999 ARG_UNUSED(context);
1000 ARG_UNUSED(enable);
1001}
1002#endif
1003
1014#if defined(CONFIG_SOCKS)
1015static inline bool net_context_is_proxy_enabled(struct net_context *context)
1016{
1017 return context->proxy_enabled;
1018}
1019#else
1020static inline bool net_context_is_proxy_enabled(struct net_context *context)
1021{
1022 ARG_UNUSED(context);
1023 return false;
1024}
1025#endif
1026
1045 enum net_sock_type type,
1046 uint16_t ip_proto,
1047 struct net_context **context);
1048
1062int net_context_put(struct net_context *context);
1063
1076int net_context_ref(struct net_context *context);
1077
1091int net_context_unref(struct net_context *context);
1092
1103#if defined(CONFIG_NET_IPV4)
1104int net_context_create_ipv4_new(struct net_context *context,
1105 struct net_pkt *pkt,
1106 const struct net_in_addr *src,
1107 const struct net_in_addr *dst);
1108#else
1109static inline int net_context_create_ipv4_new(struct net_context *context,
1110 struct net_pkt *pkt,
1111 const struct net_in_addr *src,
1112 const struct net_in_addr *dst)
1113{
1114 return -1;
1115}
1116#endif /* CONFIG_NET_IPV4 */
1117
1128#if defined(CONFIG_NET_IPV6)
1129int net_context_create_ipv6_new(struct net_context *context,
1130 struct net_pkt *pkt,
1131 const struct net_in6_addr *src,
1132 const struct net_in6_addr *dst);
1133#else
1134static inline int net_context_create_ipv6_new(struct net_context *context,
1135 struct net_pkt *pkt,
1136 const struct net_in6_addr *src,
1137 const struct net_in6_addr *dst)
1138{
1139 ARG_UNUSED(context);
1140 ARG_UNUSED(pkt);
1141 ARG_UNUSED(src);
1142 ARG_UNUSED(dst);
1143 return -1;
1144}
1145#endif /* CONFIG_NET_IPV6 */
1146
1158int net_context_bind(struct net_context *context,
1159 const struct net_sockaddr *addr,
1160 net_socklen_t addrlen);
1161
1173 int backlog);
1174
1204 const struct net_sockaddr *addr,
1205 net_socklen_t addrlen,
1207 k_timeout_t timeout,
1208 void *user_data);
1209
1237 k_timeout_t timeout,
1238 void *user_data);
1239
1259int net_context_send(struct net_context *context,
1260 const void *buf,
1261 size_t len,
1263 k_timeout_t timeout,
1264 void *user_data);
1265
1288 const void *buf,
1289 size_t len,
1290 const struct net_sockaddr *dst_addr,
1291 net_socklen_t addrlen,
1293 k_timeout_t timeout,
1294 void *user_data);
1295
1315 const struct net_msghdr *msghdr,
1316 int flags,
1318 k_timeout_t timeout,
1319 void *user_data);
1320
1357int net_context_recv(struct net_context *context,
1359 k_timeout_t timeout,
1360 void *user_data);
1361
1383 int32_t delta);
1384
1413
1425 enum net_context_option option,
1426 const void *value, uint32_t len);
1427
1439 enum net_context_option option,
1440 void *value, uint32_t *len);
1441
1449typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
1450
1459
1480#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1481static inline void net_context_setup_pools(struct net_context *context,
1483 net_pkt_get_pool_func_t data_pool)
1484{
1485 NET_ASSERT(context);
1486
1487 context->tx_slab = tx_slab;
1488 context->data_pool = data_pool;
1489}
1490#else
1491#define net_context_setup_pools(context, tx_pool, data_pool)
1492#endif
1493
1508 uint16_t local_port, const struct net_sockaddr *local_addr);
1509
1510#ifdef __cplusplus
1511}
1512#endif
1513
1517
1518#endif /* ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ */
Header file for the Atomic operations 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:648
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:910
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:770
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:819
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.
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:632
static bool net_context_is_accepting(struct net_context *context)
Is this context is accepting data now.
Definition net_context.h:478
static bool net_context_is_bound_to_iface(struct net_context *context)
Is this context bound to a network interface.
Definition net_context.h:464
static void net_context_bind_iface(struct net_context *context, struct net_if *iface)
Bind network interface to this context.
Definition net_context.h:786
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:605
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: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:835
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:450
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:589
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition net_context.h:552
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:680
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:1020
#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:491
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:705
#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:897
static void net_context_set_closing(struct net_context *context, bool closing)
Set this context to closing.
Definition net_context.h:523
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:926
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:996
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:805
#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:1449
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:1134
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:569
net_context_option
Network context options.
Definition net_context.h:1386
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:849
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.
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:510
#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
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:738
#define net_context_setup_pools(context, tx_pool, data_pool)
Set custom network buffer pools for context send operations.
Definition net_context.h:1491
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition net_context.h:723
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:197
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:1109
#define NET_CONTEXT_ACCEPTING_SOCK
Is the socket accepting connections.
Definition net_context.h:71
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:142
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:940
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:101
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:755
@ NET_OPT_ADDR_PREFERENCES
IPv6 address preference.
Definition net_context.h:1403
@ NET_OPT_MCAST_TTL
IPv4 multicast TTL.
Definition net_context.h:1399
@ NET_OPT_REUSEADDR
Re-use address.
Definition net_context.h:1395
@ NET_OPT_SNDBUF
Send buffer.
Definition net_context.h:1393
@ NET_OPT_IPV4_MCAST_LOOP
IPV4 multicast loop.
Definition net_context.h:1409
@ NET_OPT_RECV_PKTINFO
Receive packet information.
Definition net_context.h:1398
@ NET_OPT_RECV_HOPLIMIT
Receive hop limit information.
Definition net_context.h:1410
@ NET_OPT_LOCAL_PORT_RANGE
Clamp local port range.
Definition net_context.h:1407
@ NET_OPT_PRIORITY
Context priority.
Definition net_context.h:1387
@ NET_OPT_REUSEPORT
Re-use port.
Definition net_context.h:1396
@ NET_OPT_MCAST_HOP_LIMIT
IPv6 multicast hop limit.
Definition net_context.h:1400
@ NET_OPT_RCVTIMEO
Receive timeout.
Definition net_context.h:1390
@ NET_OPT_TXTIME
TX time.
Definition net_context.h:1388
@ NET_OPT_SNDTIMEO
Send timeout.
Definition net_context.h:1391
@ NET_OPT_MCAST_IFINDEX
IPv6 multicast output network interface index.
Definition net_context.h:1405
@ NET_OPT_SOCKS5
SOCKS5.
Definition net_context.h:1389
@ NET_OPT_IPV6_MCAST_LOOP
IPV6 multicast loop.
Definition net_context.h:1408
@ NET_OPT_TTL
IPv4 unicast TTL.
Definition net_context.h:1402
@ NET_OPT_RCVBUF
Receive buffer.
Definition net_context.h:1392
@ NET_OPT_DONT_FRAGMENT
Disable local IP fragmentation.
Definition net_context.h:1411
@ NET_OPT_MTU
IPv4 socket path MTU.
Definition net_context.h:1406
@ NET_OPT_UNICAST_HOP_LIMIT
IPv6 unicast hop limit.
Definition net_context.h:1401
@ NET_OPT_DSCP_ECN
DSCP ECN.
Definition net_context.h:1394
@ NET_OPT_TIMESTAMPING
Packet timestamping.
Definition net_context.h:1404
@ NET_OPT_IPV6_V6ONLY
Share IPv4 and IPv6 port space.
Definition net_context.h:1397
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
Kernel condition variable structure.
Definition kernel.h:3598
Kernel FIFO structure.
Definition kernel.h:2935
Kernel mutex structure.
Definition kernel.h:3477
Semaphore structure.
Definition kernel.h:3703
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:209
atomic_t refcount
Reference count.
Definition net_context.h:220
struct net_sockaddr remote
Remote endpoint address.
Definition net_context.h:234
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:419
uint8_t ipv4_mcast_ttl
IPv4 multicast TTL.
Definition net_context.h:432
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 k_mutex lock
Internal lock for protecting this context from multiple access.
Definition net_context.h:224
struct net_sockaddr_ptr local
Local endpoint address.
Definition net_context.h:229
uint8_t ipv4_ttl
IPv4 TTL.
Definition net_context.h:431
uint8_t ipv6_mcast_hop_limit
IPv6 multicast hop limit.
Definition net_context.h:428
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:416
int8_t iface
Network interface assigned to this context.
Definition net_context.h:422
void * tcp
TCP connection information.
Definition net_context.h:266
struct net_context::@301222043044136136127251054270033130365030331345 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:242
uint8_t ipv6_hop_limit
IPv6 hop limit.
Definition net_context.h:427
Network Interface structure.
Definition net_if.h:733
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:449