Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_context.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2016 Intel Corporation
9 * Copyright (c) 2021 Nordic Semiconductor
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
14#ifndef ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_
15#define ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_
16
24#include <zephyr/kernel.h>
25#include <zephyr/sys/atomic.h>
26
27#include <zephyr/net/net_ip.h>
28#include <zephyr/net/net_if.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
36#define NET_CONTEXT_IN_USE BIT(0)
37
41enum net_context_state {
42 NET_CONTEXT_IDLE = 0,
43 NET_CONTEXT_UNCONNECTED = 0,
44 NET_CONTEXT_CONFIGURING = 1,
45 NET_CONTEXT_CONNECTING = 1,
46 NET_CONTEXT_READY = 2,
47 NET_CONTEXT_CONNECTED = 2,
48 NET_CONTEXT_LISTENING = 3,
49};
50
58#define NET_CONTEXT_FAMILY (BIT(3) | BIT(4) | BIT(5))
59
61#define NET_CONTEXT_TYPE (BIT(6) | BIT(7))
62
64#define NET_CONTEXT_REMOTE_ADDR_SET BIT(8)
65
67#define NET_CONTEXT_ACCEPTING_SOCK BIT(9)
68
70#define NET_CONTEXT_CLOSING_SOCK BIT(10)
71
73#define NET_CONTEXT_BOUND_TO_IFACE BIT(11)
74
75struct net_context;
76
97typedef void (*net_context_recv_cb_t)(struct net_context *context,
98 struct net_pkt *pkt,
99 union net_ip_header *ip_hdr,
100 union net_proto_header *proto_hdr,
101 int status,
102 void *user_data);
103
118typedef void (*net_context_send_cb_t)(struct net_context *context,
119 int status,
120 void *user_data);
121
138typedef void (*net_tcp_accept_cb_t)(struct net_context *new_context,
139 struct sockaddr *addr,
140 socklen_t addrlen,
141 int status,
142 void *user_data);
143
165typedef void (*net_context_connect_cb_t)(struct net_context *context,
166 int status,
167 void *user_data);
168
169/* The net_pkt_get_slab_func_t is here in order to avoid circular
170 * dependency between net_pkt.h and net_context.h
171 */
180typedef struct k_mem_slab *(*net_pkt_get_slab_func_t)(void);
181
182/* The net_pkt_get_pool_func_t is here in order to avoid circular
183 * dependency between net_pkt.h and net_context.h
184 */
193typedef struct net_buf_pool *(*net_pkt_get_pool_func_t)(void);
194
195struct net_tcp;
196
197struct net_conn_handle;
198
205__net_socket struct net_context {
209
213
217
220 struct k_mutex lock;
221
225 struct sockaddr_ptr local;
226
231
233 struct net_conn_handle *conn_handler;
234
239
244
249
250#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
254
257 net_pkt_get_pool_func_t data_pool;
258#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
259
260#if defined(CONFIG_NET_TCP)
262 void *tcp;
263#endif /* CONFIG_NET_TCP */
264
265#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
269 struct k_sem recv_data_wait;
270#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
271
272#if defined(CONFIG_NET_SOCKETS)
274 void *socket_data;
275
277 union {
278 struct k_fifo recv_q;
279 struct k_fifo accept_q;
280 };
281
282 struct {
284 struct k_condvar recv;
285
287 struct k_mutex *lock;
288 } cond;
289#endif /* CONFIG_NET_SOCKETS */
290
291#if defined(CONFIG_NET_OFFLOAD)
293 void *offload_context;
294#endif /* CONFIG_NET_OFFLOAD */
295
296#if defined(CONFIG_NET_SOCKETS_CAN)
297 int can_filter_id;
298#endif /* CONFIG_NET_SOCKETS_CAN */
299
301 struct {
302#if defined(CONFIG_NET_CONTEXT_PRIORITY)
304 uint8_t priority;
305#endif
306#if defined(CONFIG_NET_CONTEXT_TXTIME)
308 bool txtime;
309#endif
310#if defined(CONFIG_SOCKS)
312 struct {
313 struct sockaddr addr;
314 socklen_t addrlen;
315 } proxy;
316#endif
317#if defined(CONFIG_NET_CONTEXT_RCVTIMEO)
319 k_timeout_t rcvtimeo;
320#endif
321#if defined(CONFIG_NET_CONTEXT_SNDTIMEO)
323 k_timeout_t sndtimeo;
324#endif
325#if defined(CONFIG_NET_CONTEXT_RCVBUF)
327 uint16_t rcvbuf;
328#endif
329#if defined(CONFIG_NET_CONTEXT_SNDBUF)
331 uint16_t sndbuf;
332#endif
333#if defined(CONFIG_NET_CONTEXT_DSCP_ECN)
338 uint8_t dscp_ecn;
339#endif
340#if defined(CONFIG_NET_CONTEXT_REUSEADDR)
342 bool reuseaddr;
343#endif
344#if defined(CONFIG_NET_CONTEXT_REUSEPORT)
346 bool reuseport;
347#endif
348#if defined(CONFIG_NET_IPV4_MAPPING_TO_IPV6)
350 bool ipv6_v6only;
351#endif
352#if defined(CONFIG_NET_CONTEXT_RECV_PKTINFO)
354 bool recv_pktinfo;
355#endif
356#if defined(CONFIG_NET_IPV6)
361 uint16_t addr_preferences;
362#endif
364
367
370
373
375 union {
376 struct {
379 };
380 struct {
383 };
384 };
385
386#if defined(CONFIG_SOCKS)
388 bool proxy_enabled;
389#endif
390
391};
392
400static inline bool net_context_is_used(struct net_context *context)
401{
402 NET_ASSERT(context);
403
404 return context->flags & NET_CONTEXT_IN_USE;
405}
406
414static inline bool net_context_is_bound_to_iface(struct net_context *context)
415{
416 NET_ASSERT(context);
417
418 return context->flags & NET_CONTEXT_BOUND_TO_IFACE;
419}
420
428static inline bool net_context_is_accepting(struct net_context *context)
429{
430 NET_ASSERT(context);
431
432 return context->flags & NET_CONTEXT_ACCEPTING_SOCK;
433}
434
441static inline void net_context_set_accepting(struct net_context *context,
442 bool accepting)
443{
444 NET_ASSERT(context);
445
446 if (accepting) {
448 } else {
450 }
451}
452
460static inline bool net_context_is_closing(struct net_context *context)
461{
462 NET_ASSERT(context);
463
464 return context->flags & NET_CONTEXT_CLOSING_SOCK;
465}
466
473static inline void net_context_set_closing(struct net_context *context,
474 bool closing)
475{
476 NET_ASSERT(context);
477
478 if (closing) {
480 } else {
482 }
483}
484
487#define NET_CONTEXT_STATE_SHIFT 1
488#define NET_CONTEXT_STATE_MASK 0x03
489
501static inline
502enum net_context_state net_context_get_state(struct net_context *context)
503{
504 NET_ASSERT(context);
505
506 return (enum net_context_state)
507 ((context->flags >> NET_CONTEXT_STATE_SHIFT) &
508 NET_CONTEXT_STATE_MASK);
509}
510
519static inline void net_context_set_state(struct net_context *context,
520 enum net_context_state state)
521{
522 NET_ASSERT(context);
523
524 context->flags &= ~(NET_CONTEXT_STATE_MASK << NET_CONTEXT_STATE_SHIFT);
525 context->flags |= ((state & NET_CONTEXT_STATE_MASK) <<
526 NET_CONTEXT_STATE_SHIFT);
527}
528
539static inline sa_family_t net_context_get_family(struct net_context *context)
540{
541 NET_ASSERT(context);
542
543 return ((context->flags & NET_CONTEXT_FAMILY) >> 3);
544}
545
555static inline void net_context_set_family(struct net_context *context,
556 sa_family_t family)
557{
558 uint8_t flag = 0U;
559
560 NET_ASSERT(context);
561
562 if (family == AF_UNSPEC || family == AF_INET || family == AF_INET6 ||
563 family == AF_PACKET || family == AF_CAN) {
564 /* Family is in BIT(4), BIT(5) and BIT(6) */
565 flag = (uint8_t)(family << 3);
566 }
567
568 context->flags |= flag;
569}
570
581static inline
583{
584 NET_ASSERT(context);
585
586 return (enum net_sock_type)((context->flags & NET_CONTEXT_TYPE) >> 6);
587}
588
598static inline void net_context_set_type(struct net_context *context,
599 enum net_sock_type type)
600{
601 uint16_t flag = 0U;
602
603 NET_ASSERT(context);
604
605 if (type == SOCK_DGRAM || type == SOCK_STREAM || type == SOCK_RAW) {
606 /* Type is in BIT(6) and BIT(7)*/
607 flag = (uint16_t)(type << 6);
608 }
609
610 context->flags |= flag;
611}
612
621#if defined(CONFIG_NET_SOCKETS_CAN)
622static inline void net_context_set_can_filter_id(struct net_context *context,
623 int filter_id)
624{
625 NET_ASSERT(context);
626
627 context->can_filter_id = filter_id;
628}
629#else
630static inline void net_context_set_can_filter_id(struct net_context *context,
631 int filter_id)
632{
633 ARG_UNUSED(context);
634 ARG_UNUSED(filter_id);
635}
636#endif
637
647#if defined(CONFIG_NET_SOCKETS_CAN)
648static inline int net_context_get_can_filter_id(struct net_context *context)
649{
650 NET_ASSERT(context);
651
652 return context->can_filter_id;
653}
654#else
655static inline int net_context_get_can_filter_id(struct net_context *context)
656{
657 ARG_UNUSED(context);
658
659 return -1;
660}
661#endif
662
673static inline uint16_t net_context_get_proto(struct net_context *context)
674{
675 return context->proto;
676}
677
688static inline void net_context_set_proto(struct net_context *context,
689 uint16_t proto)
690{
691 context->proto = proto;
692}
693
704static inline
706{
707 NET_ASSERT(context);
708
709 return net_if_get_by_index(context->iface);
710}
711
720static inline void net_context_set_iface(struct net_context *context,
721 struct net_if *iface)
722{
723 NET_ASSERT(iface);
724
725 context->iface = (uint8_t)net_if_get_by_iface(iface);
726}
727
736static inline void net_context_bind_iface(struct net_context *context,
737 struct net_if *iface)
738{
739 NET_ASSERT(iface);
740
742 net_context_set_iface(context, iface);
743}
744
755static inline uint8_t net_context_get_ipv4_ttl(struct net_context *context)
756{
757 return context->ipv4_ttl;
758}
759
769static inline void net_context_set_ipv4_ttl(struct net_context *context,
770 uint8_t ttl)
771{
772 context->ipv4_ttl = ttl;
773}
774
786{
787 return context->ipv4_mcast_ttl;
788}
789
799static inline void net_context_set_ipv4_mcast_ttl(struct net_context *context,
800 uint8_t ttl)
801{
802 context->ipv4_mcast_ttl = ttl;
803}
804
816{
817 return context->ipv6_hop_limit;
818}
819
828static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
829 uint8_t hop_limit)
830{
831 context->ipv6_hop_limit = hop_limit;
832}
833
845{
846 return context->ipv6_mcast_hop_limit;
847}
848
858static inline void net_context_set_ipv6_mcast_hop_limit(struct net_context *context,
859 uint8_t hop_limit)
860{
861 context->ipv6_mcast_hop_limit = hop_limit;
862}
863
873#if defined(CONFIG_SOCKS)
874static inline void net_context_set_proxy_enabled(struct net_context *context,
875 bool enable)
876{
877 context->proxy_enabled = enable;
878}
879#else
880static inline void net_context_set_proxy_enabled(struct net_context *context,
881 bool enable)
882{
883 ARG_UNUSED(context);
884 ARG_UNUSED(enable);
885}
886#endif
887
898#if defined(CONFIG_SOCKS)
899static inline bool net_context_is_proxy_enabled(struct net_context *context)
900{
901 return context->proxy_enabled;
902}
903#else
904static inline bool net_context_is_proxy_enabled(struct net_context *context)
905{
906 ARG_UNUSED(context);
907 return false;
908}
909#endif
910
929 enum net_sock_type type,
930 uint16_t ip_proto,
931 struct net_context **context);
932
946int net_context_put(struct net_context *context);
947
960int net_context_ref(struct net_context *context);
961
975int net_context_unref(struct net_context *context);
976
987#if defined(CONFIG_NET_IPV4)
988int net_context_create_ipv4_new(struct net_context *context,
989 struct net_pkt *pkt,
990 const struct in_addr *src,
991 const struct in_addr *dst);
992#else
993static inline int net_context_create_ipv4_new(struct net_context *context,
994 struct net_pkt *pkt,
995 const struct in_addr *src,
996 const struct in_addr *dst)
997{
998 return -1;
999}
1000#endif /* CONFIG_NET_IPV4 */
1001
1012#if defined(CONFIG_NET_IPV6)
1013int net_context_create_ipv6_new(struct net_context *context,
1014 struct net_pkt *pkt,
1015 const struct in6_addr *src,
1016 const struct in6_addr *dst);
1017#else
1018static inline int net_context_create_ipv6_new(struct net_context *context,
1019 struct net_pkt *pkt,
1020 const struct in6_addr *src,
1021 const struct in6_addr *dst)
1022{
1023 ARG_UNUSED(context);
1024 ARG_UNUSED(pkt);
1025 ARG_UNUSED(src);
1026 ARG_UNUSED(dst);
1027 return -1;
1028}
1029#endif /* CONFIG_NET_IPV6 */
1030
1042int net_context_bind(struct net_context *context,
1043 const struct sockaddr *addr,
1044 socklen_t addrlen);
1045
1057 int backlog);
1058
1088 const struct sockaddr *addr,
1089 socklen_t addrlen,
1091 k_timeout_t timeout,
1092 void *user_data);
1093
1121 k_timeout_t timeout,
1122 void *user_data);
1123
1143int net_context_send(struct net_context *context,
1144 const void *buf,
1145 size_t len,
1147 k_timeout_t timeout,
1148 void *user_data);
1149
1172 const void *buf,
1173 size_t len,
1174 const struct sockaddr *dst_addr,
1175 socklen_t addrlen,
1177 k_timeout_t timeout,
1178 void *user_data);
1179
1199 const struct msghdr *msghdr,
1200 int flags,
1202 k_timeout_t timeout,
1203 void *user_data);
1204
1241int net_context_recv(struct net_context *context,
1243 k_timeout_t timeout,
1244 void *user_data);
1245
1267 int32_t delta);
1268
1288};
1289
1301 enum net_context_option option,
1302 const void *value, size_t len);
1303
1315 enum net_context_option option,
1316 void *value, size_t *len);
1317
1325typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
1326
1335
1356#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1357static inline void net_context_setup_pools(struct net_context *context,
1359 net_pkt_get_pool_func_t data_pool)
1360{
1361 NET_ASSERT(context);
1362
1363 context->tx_slab = tx_slab;
1364 context->data_pool = data_pool;
1365}
1366#else
1367#define net_context_setup_pools(context, tx_pool, data_pool)
1368#endif
1369
1384 uint16_t local_port, const struct sockaddr *local_addr);
1385
1386#ifdef __cplusplus
1387}
1388#endif
1389
1394#endif /* ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ */
long atomic_t
Definition: atomic_types.h:15
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
POSIX wrapper for zsock_recv.
Definition: socket.h:923
unsigned short int sa_family_t
Socket address family type.
Definition: net_ip.h:164
#define AF_CAN
Controller Area Network.
Definition: net_ip.h:56
#define AF_INET
IP protocol family version 4.
Definition: net_ip.h:53
#define AF_INET6
IP protocol family version 6.
Definition: net_ip.h:54
#define AF_PACKET
Packet family.
Definition: net_ip.h:55
net_sock_type
Socket type.
Definition: net_ip.h:84
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
#define AF_UNSPEC
Unspecified address family.
Definition: net_ip.h:52
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition: net_ip.h:62
@ SOCK_DGRAM
Datagram socket type.
Definition: net_ip.h:86
@ SOCK_RAW
RAW socket type
Definition: net_ip.h:87
@ SOCK_STREAM
Stream socket type
Definition: net_ip.h:85
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:598
void(* net_context_cb_t)(struct net_context *context, void *user_data)
Callback used while iterating over network contexts.
Definition: net_context.h:1325
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:97
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:828
int net_context_unref(struct net_context *context)
Decrement the reference count to a network context.
int net_context_bind(struct net_context *context, const struct sockaddr *addr, socklen_t addrlen)
Assign a socket a local address.
static void net_context_set_iface(struct net_context *context, struct net_if *iface)
Set network interface for this context.
Definition: net_context.h:720
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:769
int net_context_accept(struct net_context *context, net_tcp_accept_cb_t cb, k_timeout_t timeout, void *user_data)
Accept a network connection attempt.
int net_context_put(struct net_context *context)
Close and unref a network context.
static enum net_sock_type net_context_get_type(struct net_context *context)
Get context type for this network context.
Definition: net_context.h:582
static bool net_context_is_accepting(struct net_context *context)
Is this context is accepting data now.
Definition: net_context.h:428
static sa_family_t net_context_get_family(struct net_context *context)
Get address family for this network context.
Definition: net_context.h:539
static bool net_context_is_bound_to_iface(struct net_context *context)
Is this context bound to a network interface.
Definition: net_context.h:414
static void net_context_bind_iface(struct net_context *context, struct net_if *iface)
Bind network interface to this context.
Definition: net_context.h:736
void(* net_tcp_accept_cb_t)(struct net_context *new_context, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data)
Accept callback.
Definition: net_context.h:138
int net_context_listen(struct net_context *context, int backlog)
Mark the context as a listening one.
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:785
static bool net_context_is_used(struct net_context *context)
Is this context used or not.
Definition: net_context.h:400
int net_context_sendmsg(struct net_context *context, const struct msghdr *msghdr, int flags, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data)
Send data in iovec to a peer specified in msghdr struct.
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:180
int net_context_ref(struct net_context *context)
Take a reference count to a net_context, preventing destruction.
void(* net_context_send_cb_t)(struct net_context *context, int status, void *user_data)
Network data send callback.
Definition: net_context.h:118
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition: net_context.h:502
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:193
int net_context_connect(struct net_context *context, const struct sockaddr *addr, socklen_t addrlen, net_context_connect_cb_t cb, k_timeout_t timeout, void *user_data)
Create a network connection.
static void net_context_set_can_filter_id(struct net_context *context, int filter_id)
Set CAN filter id for this network context.
Definition: net_context.h:630
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:904
#define NET_CONTEXT_IN_USE
Is this context used or not.
Definition: net_context.h:36
static void net_context_set_accepting(struct net_context *context, bool accepting)
Set this context to accept data now.
Definition: net_context.h:441
bool net_context_port_in_use(enum net_ip_protocol ip_proto, uint16_t local_port, const struct sockaddr *local_addr)
Check if a port is in use (bound)
static void net_context_set_family(struct net_context *context, sa_family_t family)
Set address family for this network context.
Definition: net_context.h:555
static int net_context_create_ipv6_new(struct net_context *context, struct net_pkt *pkt, const struct in6_addr *src, const struct in6_addr *dst)
Create IPv6 packet in provided net_pkt from context.
Definition: net_context.h:1018
static int net_context_create_ipv4_new(struct net_context *context, struct net_pkt *pkt, const struct in_addr *src, const struct in_addr *dst)
Create IPv4 packet in provided net_pkt from context.
Definition: net_context.h:993
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:655
#define NET_CONTEXT_CLOSING_SOCK
Is the socket closing / closed.
Definition: net_context.h:70
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:815
static void net_context_set_closing(struct net_context *context, bool closing)
Set this context to closing.
Definition: net_context.h:473
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:844
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:880
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:755
#define NET_CONTEXT_BOUND_TO_IFACE
Context is bound to a specific interface.
Definition: net_context.h:73
void(* net_context_connect_cb_t)(struct net_context *context, int status, void *user_data)
Connection callback.
Definition: net_context.h:165
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:519
net_context_option
Network context options.
Definition: net_context.h:1270
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:799
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_set_option(struct net_context *context, enum net_context_option option, const void *value, size_t len)
Set an connection option 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:460
#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:58
#define NET_CONTEXT_TYPE
Type of the connection (datagram / stream / raw)
Definition: net_context.h:61
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:688
#define net_context_setup_pools(context, tx_pool, data_pool)
Set custom network buffer pools for context send operations.
Definition: net_context.h:1367
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition: net_context.h:673
int net_context_get(sa_family_t family, enum net_sock_type type, uint16_t ip_proto, struct net_context **context)
Get network context.
#define NET_CONTEXT_ACCEPTING_SOCK
Is the socket accepting connections.
Definition: net_context.h:67
int net_context_get_option(struct net_context *context, enum net_context_option option, void *value, size_t *len)
Get connection option value for this context.
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:858
int net_context_sendto(struct net_context *context, const void *buf, size_t len, const struct sockaddr *dst_addr, socklen_t addrlen, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data)
Send data to a peer specified by address.
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition: net_context.h:705
@ NET_OPT_ADDR_PREFERENCES
IPv6 address preference.
Definition: net_context.h:1287
@ NET_OPT_MCAST_TTL
IPv4 multicast TTL.
Definition: net_context.h:1283
@ NET_OPT_REUSEADDR
Re-use address.
Definition: net_context.h:1279
@ NET_OPT_SNDBUF
Send buffer.
Definition: net_context.h:1277
@ NET_OPT_RECV_PKTINFO
Receive packet information.
Definition: net_context.h:1282
@ NET_OPT_PRIORITY
Context priority.
Definition: net_context.h:1271
@ NET_OPT_REUSEPORT
Re-use port.
Definition: net_context.h:1280
@ NET_OPT_MCAST_HOP_LIMIT
IPv6 multicast hop limit.
Definition: net_context.h:1284
@ NET_OPT_RCVTIMEO
Receive timeout.
Definition: net_context.h:1274
@ NET_OPT_TXTIME
TX time.
Definition: net_context.h:1272
@ NET_OPT_SNDTIMEO
Send timeout.
Definition: net_context.h:1275
@ NET_OPT_SOCKS5
SOCKS5.
Definition: net_context.h:1273
@ NET_OPT_TTL
IPv4 unicast TTL.
Definition: net_context.h:1286
@ NET_OPT_RCVBUF
Receive buffer.
Definition: net_context.h:1276
@ NET_OPT_UNICAST_HOP_LIMIT
IPv6 unicast hop limit.
Definition: net_context.h:1285
@ NET_OPT_DSCP_ECN
DSCP ECN.
Definition: net_context.h:1278
@ NET_OPT_IPV6_V6ONLY
Share IPv4 and IPv6 port space.
Definition: net_context.h:1281
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:96
state
Definition: parser_state.h:29
__INT32_TYPE__ int32_t
Definition: stdint.h:74
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT8_TYPE__ int8_t
Definition: stdint.h:72
IPv6 address struct.
Definition: net_ip.h:139
IPv4 address struct.
Definition: net_ip.h:151
Definition: kernel.h:3026
Definition: kernel.h:2388
Mutex Structure.
Definition: kernel.h:2914
Kernel timeout type.
Definition: sys_clock.h:65
Message struct.
Definition: net_ip.h:247
Network buffer pool representation.
Definition: buf.h:1076
Note that we do not store the actual source IP address in the context because the address is already ...
Definition: net_context.h:205
atomic_t refcount
Reference count.
Definition: net_context.h:216
void * user_data
User data associated with a context.
Definition: net_context.h:212
void * fifo_reserved
First member of the structure to allow to put contexts into a FIFO.
Definition: net_context.h:208
uint16_t flags
Flags for the context.
Definition: net_context.h:369
uint8_t ipv4_mcast_ttl
IPv4 multicast TTL.
Definition: net_context.h:382
net_context_send_cb_t send_cb
Send callback to be called when the packet has been sent successfully.
Definition: net_context.h:243
struct sockaddr remote
Remote endpoint address.
Definition: net_context.h:230
struct k_mutex lock
Internal lock for protecting this context from multiple access.
Definition: net_context.h:220
struct sockaddr_ptr local
Local endpoint address.
Definition: net_context.h:225
uint8_t ipv4_ttl
IPv4 TTL.
Definition: net_context.h:381
uint8_t ipv6_mcast_hop_limit
IPv6 multicast hop limit.
Definition: net_context.h:378
net_context_connect_cb_t connect_cb
Connect callback to be called when a connection has been established.
Definition: net_context.h:248
struct net_conn_handle * conn_handler
Connection handle.
Definition: net_context.h:233
uint16_t proto
Protocol (UDP, TCP or IEEE 802.3 protocol value)
Definition: net_context.h:366
int8_t iface
Network interface assigned to this context.
Definition: net_context.h:372
void * tcp
TCP connection information.
Definition: net_context.h:262
net_context_recv_cb_t recv_cb
Receive callback to be called when desired packet has been received.
Definition: net_context.h:238
uint8_t ipv6_hop_limit
IPv6 hop limit.
Definition: net_context.h:377
struct net_context::@328 options
Option values.
Network Interface structure.
Definition: net_if.h:675
Network packet.
Definition: net_pkt.h:67
Generic sockaddr struct.
Definition: net_ip.h:385