Zephyr API Documentation 4.0.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
26#include <zephyr/kernel.h>
27#include <zephyr/sys/atomic.h>
28
29#include <zephyr/net/net_ip.h>
30#include <zephyr/net/net_if.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38#define NET_CONTEXT_IN_USE BIT(0)
39
43enum net_context_state {
44 NET_CONTEXT_IDLE = 0,
45 NET_CONTEXT_UNCONNECTED = 0,
46 NET_CONTEXT_CONFIGURING = 1,
47 NET_CONTEXT_CONNECTING = 1,
48 NET_CONTEXT_READY = 2,
49 NET_CONTEXT_CONNECTED = 2,
50 NET_CONTEXT_LISTENING = 3,
51};
52
60#define NET_CONTEXT_FAMILY (BIT(3) | BIT(4) | BIT(5))
61
63#define NET_CONTEXT_TYPE (BIT(6) | BIT(7))
64
66#define NET_CONTEXT_REMOTE_ADDR_SET BIT(8)
67
69#define NET_CONTEXT_ACCEPTING_SOCK BIT(9)
70
72#define NET_CONTEXT_CLOSING_SOCK BIT(10)
73
75#define NET_CONTEXT_BOUND_TO_IFACE BIT(11)
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 sockaddr *addr,
142 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 struct sockaddr_ptr local;
228
233
235 struct net_conn_handle *conn_handler;
236
241
246
251
252#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
256
259 net_pkt_get_pool_func_t data_pool;
260#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
261
262#if defined(CONFIG_NET_TCP)
264 void *tcp;
265#endif /* CONFIG_NET_TCP */
266
267#if defined(CONFIG_NET_CONTEXT_SYNC_RECV)
271 struct k_sem recv_data_wait;
272#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
273
274#if defined(CONFIG_NET_SOCKETS)
276 void *socket_data;
277
279 union {
280 struct k_fifo recv_q;
281 struct k_fifo accept_q;
282 };
283
284 struct {
286 struct k_condvar recv;
287
289 struct k_mutex *lock;
290 } cond;
291#endif /* CONFIG_NET_SOCKETS */
292
293#if defined(CONFIG_NET_OFFLOAD)
295 void *offload_context;
296#endif /* CONFIG_NET_OFFLOAD */
297
298#if defined(CONFIG_NET_SOCKETS_CAN)
299 int can_filter_id;
300#endif /* CONFIG_NET_SOCKETS_CAN */
301
303 struct {
304#if defined(CONFIG_NET_CONTEXT_PRIORITY)
306 uint8_t priority;
307#endif
308#if defined(CONFIG_NET_CONTEXT_TXTIME)
310 bool txtime;
311#endif
312#if defined(CONFIG_SOCKS)
314 struct {
315 struct sockaddr addr;
316 socklen_t addrlen;
317 } proxy;
318#endif
319#if defined(CONFIG_NET_CONTEXT_CLAMP_PORT_RANGE)
331 uint32_t port_range;
332#endif
333#if defined(CONFIG_NET_CONTEXT_RCVTIMEO)
335 k_timeout_t rcvtimeo;
336#endif
337#if defined(CONFIG_NET_CONTEXT_SNDTIMEO)
339 k_timeout_t sndtimeo;
340#endif
341#if defined(CONFIG_NET_CONTEXT_RCVBUF)
343 uint16_t rcvbuf;
344#endif
345#if defined(CONFIG_NET_CONTEXT_SNDBUF)
347 uint16_t sndbuf;
348#endif
349#if defined(CONFIG_NET_CONTEXT_DSCP_ECN)
354 uint8_t dscp_ecn;
355#endif
356#if defined(CONFIG_NET_CONTEXT_REUSEADDR)
358 bool reuseaddr;
359#endif
360#if defined(CONFIG_NET_CONTEXT_REUSEPORT)
362 bool reuseport;
363#endif
364#if defined(CONFIG_NET_IPV4_MAPPING_TO_IPV6)
366 bool ipv6_v6only;
367#endif
368#if defined(CONFIG_NET_CONTEXT_RECV_PKTINFO)
370 bool recv_pktinfo;
371#endif
372#if defined(CONFIG_NET_IPV6)
377 uint16_t addr_preferences;
378#endif
379#if defined(CONFIG_NET_IPV6) || defined(CONFIG_NET_IPV4)
380 union {
385 uint8_t ipv6_mcast_ifindex;
386
391 uint8_t ipv4_mcast_ifindex;
392 };
393#endif /* CONFIG_NET_IPV6 || CONFIG_NET_IPV4 */
394
395#if defined(CONFIG_NET_CONTEXT_TIMESTAMPING)
397 uint8_t timestamping;
398#endif
400
403
406
409
411 union {
412 struct {
415 };
416 struct {
419 };
420 };
421
422#if defined(CONFIG_SOCKS)
424 bool proxy_enabled;
425#endif
426
427};
428
436static inline bool net_context_is_used(struct net_context *context)
437{
438 NET_ASSERT(context);
439
440 return context->flags & NET_CONTEXT_IN_USE;
441}
442
450static inline bool net_context_is_bound_to_iface(struct net_context *context)
451{
452 NET_ASSERT(context);
453
454 return context->flags & NET_CONTEXT_BOUND_TO_IFACE;
455}
456
464static inline bool net_context_is_accepting(struct net_context *context)
465{
466 NET_ASSERT(context);
467
468 return context->flags & NET_CONTEXT_ACCEPTING_SOCK;
469}
470
477static inline void net_context_set_accepting(struct net_context *context,
478 bool accepting)
479{
480 NET_ASSERT(context);
481
482 if (accepting) {
484 } else {
486 }
487}
488
496static inline bool net_context_is_closing(struct net_context *context)
497{
498 NET_ASSERT(context);
499
500 return context->flags & NET_CONTEXT_CLOSING_SOCK;
501}
502
509static inline void net_context_set_closing(struct net_context *context,
510 bool closing)
511{
512 NET_ASSERT(context);
513
514 if (closing) {
516 } else {
518 }
519}
520
523#define NET_CONTEXT_STATE_SHIFT 1
524#define NET_CONTEXT_STATE_MASK 0x03
525
537static inline
538enum net_context_state net_context_get_state(struct net_context *context)
539{
540 NET_ASSERT(context);
541
542 return (enum net_context_state)
543 ((context->flags >> NET_CONTEXT_STATE_SHIFT) &
544 NET_CONTEXT_STATE_MASK);
545}
546
555static inline void net_context_set_state(struct net_context *context,
556 enum net_context_state state)
557{
558 NET_ASSERT(context);
559
560 context->flags &= ~(NET_CONTEXT_STATE_MASK << NET_CONTEXT_STATE_SHIFT);
561 context->flags |= ((state & NET_CONTEXT_STATE_MASK) <<
562 NET_CONTEXT_STATE_SHIFT);
563}
564
575static inline sa_family_t net_context_get_family(struct net_context *context)
576{
577 NET_ASSERT(context);
578
579 return ((context->flags & NET_CONTEXT_FAMILY) >> 3);
580}
581
591static inline void net_context_set_family(struct net_context *context,
592 sa_family_t family)
593{
594 uint8_t flag = 0U;
595
596 NET_ASSERT(context);
597
598 if (family == AF_UNSPEC || family == AF_INET || family == AF_INET6 ||
599 family == AF_PACKET || family == AF_CAN) {
600 /* Family is in BIT(4), BIT(5) and BIT(6) */
601 flag = (uint8_t)(family << 3);
602 }
603
604 context->flags |= flag;
605}
606
617static inline
619{
620 NET_ASSERT(context);
621
622 return (enum net_sock_type)((context->flags & NET_CONTEXT_TYPE) >> 6);
623}
624
634static inline void net_context_set_type(struct net_context *context,
635 enum net_sock_type type)
636{
637 uint16_t flag = 0U;
638
639 NET_ASSERT(context);
640
641 if (type == SOCK_DGRAM || type == SOCK_STREAM || type == SOCK_RAW) {
642 /* Type is in BIT(6) and BIT(7)*/
643 flag = (uint16_t)(type << 6);
644 }
645
646 context->flags |= flag;
647}
648
657#if defined(CONFIG_NET_SOCKETS_CAN)
658static inline void net_context_set_can_filter_id(struct net_context *context,
659 int filter_id)
660{
661 NET_ASSERT(context);
662
663 context->can_filter_id = filter_id;
664}
665#else
666static inline void net_context_set_can_filter_id(struct net_context *context,
667 int filter_id)
668{
669 ARG_UNUSED(context);
670 ARG_UNUSED(filter_id);
671}
672#endif
673
683#if defined(CONFIG_NET_SOCKETS_CAN)
684static inline int net_context_get_can_filter_id(struct net_context *context)
685{
686 NET_ASSERT(context);
687
688 return context->can_filter_id;
689}
690#else
691static inline int net_context_get_can_filter_id(struct net_context *context)
692{
693 ARG_UNUSED(context);
694
695 return -1;
696}
697#endif
698
709static inline uint16_t net_context_get_proto(struct net_context *context)
710{
711 return context->proto;
712}
713
724static inline void net_context_set_proto(struct net_context *context,
725 uint16_t proto)
726{
727 context->proto = proto;
728}
729
740static inline
742{
743 NET_ASSERT(context);
744
745 return net_if_get_by_index(context->iface);
746}
747
756static inline void net_context_set_iface(struct net_context *context,
757 struct net_if *iface)
758{
759 NET_ASSERT(iface);
760
761 context->iface = (uint8_t)net_if_get_by_iface(iface);
762}
763
772static inline void net_context_bind_iface(struct net_context *context,
773 struct net_if *iface)
774{
775 NET_ASSERT(iface);
776
778 net_context_set_iface(context, iface);
779}
780
791static inline uint8_t net_context_get_ipv4_ttl(struct net_context *context)
792{
793 return context->ipv4_ttl;
794}
795
805static inline void net_context_set_ipv4_ttl(struct net_context *context,
806 uint8_t ttl)
807{
808 context->ipv4_ttl = ttl;
809}
810
822{
823 return context->ipv4_mcast_ttl;
824}
825
835static inline void net_context_set_ipv4_mcast_ttl(struct net_context *context,
836 uint8_t ttl)
837{
838 context->ipv4_mcast_ttl = ttl;
839}
840
852{
853 return context->ipv6_hop_limit;
854}
855
864static inline void net_context_set_ipv6_hop_limit(struct net_context *context,
865 uint8_t hop_limit)
866{
867 context->ipv6_hop_limit = hop_limit;
868}
869
881{
882 return context->ipv6_mcast_hop_limit;
883}
884
894static inline void net_context_set_ipv6_mcast_hop_limit(struct net_context *context,
895 uint8_t hop_limit)
896{
897 context->ipv6_mcast_hop_limit = hop_limit;
898}
899
909#if defined(CONFIG_SOCKS)
910static inline void net_context_set_proxy_enabled(struct net_context *context,
911 bool enable)
912{
913 context->proxy_enabled = enable;
914}
915#else
916static inline void net_context_set_proxy_enabled(struct net_context *context,
917 bool enable)
918{
919 ARG_UNUSED(context);
920 ARG_UNUSED(enable);
921}
922#endif
923
934#if defined(CONFIG_SOCKS)
935static inline bool net_context_is_proxy_enabled(struct net_context *context)
936{
937 return context->proxy_enabled;
938}
939#else
940static inline bool net_context_is_proxy_enabled(struct net_context *context)
941{
942 ARG_UNUSED(context);
943 return false;
944}
945#endif
946
965 enum net_sock_type type,
966 uint16_t ip_proto,
967 struct net_context **context);
968
982int net_context_put(struct net_context *context);
983
996int net_context_ref(struct net_context *context);
997
1011int net_context_unref(struct net_context *context);
1012
1023#if defined(CONFIG_NET_IPV4)
1024int net_context_create_ipv4_new(struct net_context *context,
1025 struct net_pkt *pkt,
1026 const struct in_addr *src,
1027 const struct in_addr *dst);
1028#else
1029static inline int net_context_create_ipv4_new(struct net_context *context,
1030 struct net_pkt *pkt,
1031 const struct in_addr *src,
1032 const struct in_addr *dst)
1033{
1034 return -1;
1035}
1036#endif /* CONFIG_NET_IPV4 */
1037
1048#if defined(CONFIG_NET_IPV6)
1049int net_context_create_ipv6_new(struct net_context *context,
1050 struct net_pkt *pkt,
1051 const struct in6_addr *src,
1052 const struct in6_addr *dst);
1053#else
1054static inline int net_context_create_ipv6_new(struct net_context *context,
1055 struct net_pkt *pkt,
1056 const struct in6_addr *src,
1057 const struct in6_addr *dst)
1058{
1059 ARG_UNUSED(context);
1060 ARG_UNUSED(pkt);
1061 ARG_UNUSED(src);
1062 ARG_UNUSED(dst);
1063 return -1;
1064}
1065#endif /* CONFIG_NET_IPV6 */
1066
1078int net_context_bind(struct net_context *context,
1079 const struct sockaddr *addr,
1080 socklen_t addrlen);
1081
1093 int backlog);
1094
1124 const struct sockaddr *addr,
1125 socklen_t addrlen,
1127 k_timeout_t timeout,
1128 void *user_data);
1129
1157 k_timeout_t timeout,
1158 void *user_data);
1159
1179int net_context_send(struct net_context *context,
1180 const void *buf,
1181 size_t len,
1183 k_timeout_t timeout,
1184 void *user_data);
1185
1208 const void *buf,
1209 size_t len,
1210 const struct sockaddr *dst_addr,
1211 socklen_t addrlen,
1213 k_timeout_t timeout,
1214 void *user_data);
1215
1235 const struct msghdr *msghdr,
1236 int flags,
1238 k_timeout_t timeout,
1239 void *user_data);
1240
1277int net_context_recv(struct net_context *context,
1279 k_timeout_t timeout,
1280 void *user_data);
1281
1303 int32_t delta);
1304
1329
1341 enum net_context_option option,
1342 const void *value, size_t len);
1343
1355 enum net_context_option option,
1356 void *value, size_t *len);
1357
1365typedef void (*net_context_cb_t)(struct net_context *context, void *user_data);
1366
1375
1396#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
1397static inline void net_context_setup_pools(struct net_context *context,
1399 net_pkt_get_pool_func_t data_pool)
1400{
1401 NET_ASSERT(context);
1402
1403 context->tx_slab = tx_slab;
1404 context->data_pool = data_pool;
1405}
1406#else
1407#define net_context_setup_pools(context, tx_pool, data_pool)
1408#endif
1409
1424 uint16_t local_port, const struct sockaddr *local_addr);
1425
1426#ifdef __cplusplus
1427}
1428#endif
1429
1434#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:873
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:168
#define AF_CAN
Controller Area Network.
Definition net_ip.h:58
#define AF_INET
IP protocol family version 4.
Definition net_ip.h:55
#define AF_INET6
IP protocol family version 6.
Definition net_ip.h:56
#define AF_PACKET
Packet family.
Definition net_ip.h:57
net_sock_type
Socket type.
Definition net_ip.h:88
size_t socklen_t
Length of a socket address.
Definition net_ip.h:172
#define AF_UNSPEC
Unspecified address family.
Definition net_ip.h:54
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
@ SOCK_DGRAM
Datagram socket type.
Definition net_ip.h:90
@ SOCK_RAW
RAW socket type
Definition net_ip.h:91
@ SOCK_STREAM
Stream socket type
Definition net_ip.h:89
static void net_context_set_type(struct net_context *context, enum net_sock_type type)
Set context type for this network context.
Definition net_context.h:634
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:864
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:756
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:805
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.
static enum net_sock_type net_context_get_type(struct net_context *context)
Get context type for this network context.
Definition net_context.h:618
static bool net_context_is_accepting(struct net_context *context)
Is this context is accepting data now.
Definition net_context.h:464
static sa_family_t net_context_get_family(struct net_context *context)
Get address family for this network context.
Definition net_context.h:575
static bool net_context_is_bound_to_iface(struct net_context *context)
Is this context bound to a network interface.
Definition net_context.h:450
static void net_context_bind_iface(struct net_context *context, struct net_if *iface)
Bind network interface to this context.
Definition net_context.h:772
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:821
static bool net_context_is_used(struct net_context *context)
Is this context used or not.
Definition net_context.h:436
int net_context_sendmsg(struct net_context *context, const struct msghdr *msghdr, int flags, net_context_send_cb_t cb, k_timeout_t timeout, void *user_data)
Send data in iovec to a peer specified in msghdr struct.
int net_context_ref(struct net_context *context)
Take a reference count to a net_context, preventing destruction.
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition net_context.h:538
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:666
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:940
#define NET_CONTEXT_IN_USE
Is this context used or not.
Definition net_context.h:38
static void net_context_set_accepting(struct net_context *context, bool accepting)
Set this context to accept data now.
Definition net_context.h:477
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:591
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:1054
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:1029
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:691
#define NET_CONTEXT_CLOSING_SOCK
Is the socket closing / closed.
Definition net_context.h:72
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:851
static void net_context_set_closing(struct net_context *context, bool closing)
Set this context to closing.
Definition net_context.h:509
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:880
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:916
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:791
#define NET_CONTEXT_BOUND_TO_IFACE
Context is bound to a specific interface.
Definition net_context.h:75
void(* net_context_cb_t)(struct net_context *context, void *user_data)
Callback used while iterating over network contexts.
Definition net_context.h:1365
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:555
net_context_option
Network context options.
Definition net_context.h:1306
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:835
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_set_option(struct net_context *context, enum net_context_option option, const void *value, size_t len)
Set an connection option for this context.
void(* net_tcp_accept_cb_t)(struct net_context *new_context, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data)
Accept callback.
Definition net_context.h:140
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:496
#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:60
#define NET_CONTEXT_TYPE
Type of the connection (datagram / stream / raw)
Definition net_context.h:63
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:724
#define net_context_setup_pools(context, tx_pool, data_pool)
Set custom network buffer pools for context send operations.
Definition net_context.h:1407
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition net_context.h:709
int net_context_get(sa_family_t family, enum net_sock_type type, uint16_t ip_proto, struct net_context **context)
Get network context.
struct net_buf_pool *(* net_pkt_get_pool_func_t)(void)
Function that is called to get the pool that is used for net_buf allocations.
Definition net_context.h:195
#define NET_CONTEXT_ACCEPTING_SOCK
Is the socket accepting connections.
Definition net_context.h:69
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:894
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 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:741
@ NET_OPT_ADDR_PREFERENCES
IPv6 address preference.
Definition net_context.h:1323
@ NET_OPT_MCAST_TTL
IPv4 multicast TTL.
Definition net_context.h:1319
@ NET_OPT_REUSEADDR
Re-use address.
Definition net_context.h:1315
@ NET_OPT_SNDBUF
Send buffer.
Definition net_context.h:1313
@ NET_OPT_RECV_PKTINFO
Receive packet information.
Definition net_context.h:1318
@ NET_OPT_LOCAL_PORT_RANGE
Clamp local port range.
Definition net_context.h:1327
@ NET_OPT_PRIORITY
Context priority.
Definition net_context.h:1307
@ NET_OPT_REUSEPORT
Re-use port.
Definition net_context.h:1316
@ NET_OPT_MCAST_HOP_LIMIT
IPv6 multicast hop limit.
Definition net_context.h:1320
@ NET_OPT_RCVTIMEO
Receive timeout.
Definition net_context.h:1310
@ NET_OPT_TXTIME
TX time.
Definition net_context.h:1308
@ NET_OPT_SNDTIMEO
Send timeout.
Definition net_context.h:1311
@ NET_OPT_MCAST_IFINDEX
IPv6 multicast output network interface index.
Definition net_context.h:1325
@ NET_OPT_SOCKS5
SOCKS5.
Definition net_context.h:1309
@ NET_OPT_TTL
IPv4 unicast TTL.
Definition net_context.h:1322
@ NET_OPT_RCVBUF
Receive buffer.
Definition net_context.h:1312
@ NET_OPT_MTU
IPv4 socket path MTU.
Definition net_context.h:1326
@ NET_OPT_UNICAST_HOP_LIMIT
IPv6 unicast hop limit.
Definition net_context.h:1321
@ NET_OPT_DSCP_ECN
DSCP ECN.
Definition net_context.h:1314
@ NET_OPT_TIMESTAMPING
Packet timestamping.
Definition net_context.h:1324
@ NET_OPT_IPV6_V6ONLY
Share IPv4 and IPv6 port space.
Definition net_context.h:1317
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
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72
IPv6 address struct.
Definition net_ip.h:143
IPv4 address struct.
Definition net_ip.h:155
Definition kernel.h:3106
Definition kernel.h:2468
Mutex Structure.
Definition kernel.h:2994
Kernel timeout type.
Definition sys_clock.h:65
Message struct.
Definition net_ip.h:257
Network buffer pool representation.
Definition net_buf.h:1078
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
void * user_data
User data associated with a context.
Definition net_context.h:214
struct net_context::@383 options
Option values.
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:405
uint8_t ipv4_mcast_ttl
IPv4 multicast TTL.
Definition net_context.h:418
net_context_send_cb_t send_cb
Send callback to be called when the packet has been sent successfully.
Definition net_context.h:245
struct sockaddr remote
Remote endpoint address.
Definition net_context.h:232
struct k_mutex lock
Internal lock for protecting this context from multiple access.
Definition net_context.h:222
struct sockaddr_ptr local
Local endpoint address.
Definition net_context.h:227
uint8_t ipv4_ttl
IPv4 TTL.
Definition net_context.h:417
uint8_t ipv6_mcast_hop_limit
IPv6 multicast hop limit.
Definition net_context.h:414
net_context_connect_cb_t connect_cb
Connect callback to be called when a connection has been established.
Definition net_context.h:250
struct net_conn_handle * conn_handler
Connection handle.
Definition net_context.h:235
uint16_t proto
Protocol (UDP, TCP or IEEE 802.3 protocol value)
Definition net_context.h:402
int8_t iface
Network interface assigned to this context.
Definition net_context.h:408
void * tcp
TCP connection information.
Definition net_context.h:264
net_context_recv_cb_t recv_cb
Receive callback to be called when desired packet has been received.
Definition net_context.h:240
uint8_t ipv6_hop_limit
IPv6 hop limit.
Definition net_context.h:413
Network Interface structure.
Definition net_if.h:690
Network packet.
Definition net_pkt.h:91
Generic sockaddr struct.
Definition net_ip.h:408