14#ifndef ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ 
   15#define ZEPHYR_INCLUDE_NET_NET_CONTEXT_H_ 
   36#define NET_CONTEXT_IN_USE BIT(0) 
   54#define NET_CONTEXT_FAMILY (BIT(3) | BIT(4) | BIT(5)) 
   57#define NET_CONTEXT_TYPE   (BIT(6) | BIT(7)) 
   60#define NET_CONTEXT_REMOTE_ADDR_SET  BIT(8) 
   63#define NET_CONTEXT_ACCEPTING_SOCK  BIT(9) 
   66#define NET_CONTEXT_CLOSING_SOCK  BIT(10) 
   69#define NET_CONTEXT_BOUND_TO_IFACE BIT(11) 
   95                                      union net_ip_header *ip_hdr,
 
   96                                      union net_proto_header *proto_hdr,
 
  176typedef struct k_mem_slab *(*net_pkt_get_slab_func_t)(void);
 
  189typedef struct net_buf_pool *(*net_pkt_get_pool_func_t)(void);
 
  193struct net_conn_handle;
 
  246#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) 
  256#if defined(CONFIG_NET_TCP) 
  261#if defined(CONFIG_NET_CONTEXT_SYNC_RECV) 
  265        struct k_sem recv_data_wait;
 
  268#if defined(CONFIG_NET_SOCKETS) 
  287#if defined(CONFIG_NET_OFFLOAD) 
  289        void *offload_context;
 
  292#if defined(CONFIG_NET_SOCKETS_CAN) 
  298#if defined(CONFIG_NET_CONTEXT_PRIORITY) 
  302#if defined(CONFIG_NET_CONTEXT_TXTIME) 
  305#if defined(CONFIG_SOCKS) 
  311#if defined(CONFIG_NET_CONTEXT_RCVTIMEO) 
  314#if defined(CONFIG_NET_CONTEXT_SNDTIMEO) 
  317#if defined(CONFIG_NET_CONTEXT_RCVBUF) 
  320#if defined(CONFIG_NET_CONTEXT_SNDBUF) 
  323#if defined(CONFIG_NET_CONTEXT_DSCP_ECN) 
  343#if defined(CONFIG_SOCKS) 
  391                context->
flags &= ~NET_CONTEXT_ACCEPTING_SOCK;
 
  423                context->
flags &= ~NET_CONTEXT_CLOSING_SOCK;
 
  427#define NET_CONTEXT_STATE_SHIFT 1 
  428#define NET_CONTEXT_STATE_MASK 0x03 
  559#if defined(CONFIG_NET_SOCKETS_CAN) 
  565        context->can_filter_id = filter_id;
 
  572        ARG_UNUSED(filter_id);
 
  585#if defined(CONFIG_NET_SOCKETS_CAN) 
  590        return context->can_filter_id;
 
  613        return context->
proto;
 
  629        context->
proto = proto;
 
  688#if defined(CONFIG_SOCKS) 
  692        context->proxy_enabled = enable;
 
  697        return context->proxy_enabled;
 
  789#if defined(CONFIG_NET_IPV4) 
  814#if defined(CONFIG_NET_IPV6) 
 1090                           const void *value, 
size_t len);
 
 1104                           void *value, 
size_t *len);
 
 1144#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) 
 1149        NET_ASSERT(context);
 
 1151        context->tx_slab = tx_slab;
 
 1152        context->data_pool = data_pool;
 
 1155#define net_context_setup_pools(context, tx_pool, data_pool) 
long atomic_t
Definition: atomic.h:22
 
ZTEST_BMEM int timeout
Definition: main.c:31
 
static ssize_t recv(int sock, void *buf, size_t max_len, int flags)
Definition: socket.h:744
 
unsigned short int sa_family_t
Definition: net_ip.h:164
 
#define AF_CAN
Definition: net_ip.h:56
 
#define AF_INET
Definition: net_ip.h:53
 
#define AF_INET6
Definition: net_ip.h:54
 
#define AF_PACKET
Definition: net_ip.h:55
 
net_sock_type
Definition: net_ip.h:84
 
size_t socklen_t
Definition: net_ip.h:168
 
#define AF_UNSPEC
Definition: net_ip.h:52
 
net_ip_protocol
Definition: net_ip.h:62
 
@ SOCK_DGRAM
Definition: net_ip.h:86
 
@ SOCK_RAW
Definition: net_ip.h:87
 
@ SOCK_STREAM
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:536
 
void(* net_context_cb_t)(struct net_context *context, void *user_data)
Callback used while iterating over network contexts.
Definition: net_context.h:1113
 
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:93
 
static void net_context_set_ipv6_hop_limit(struct net_context *context, uint8_t hop_limit)
Definition: net_context.h:682
 
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:658
 
static void net_context_set_ipv4_ttl(struct net_context *context, uint8_t ttl)
Definition: net_context.h:671
 
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:520
 
static bool net_context_is_accepting(struct net_context *context)
Is this context is accepting data now.
Definition: net_context.h:370
 
static sa_family_t net_context_get_family(struct net_context *context)
Get address family for this network context.
Definition: net_context.h:477
 
static bool net_context_is_bound_to_iface(struct net_context *context)
Definition: net_context.h:356
 
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:134
 
int net_context_listen(struct net_context *context, int backlog)
Mark the context as a listening one.
 
static bool net_context_is_used(struct net_context *context)
Definition: net_context.h:349
 
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:176
 
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:114
 
static enum net_context_state net_context_get_state(struct net_context *context)
Get state for this network context.
Definition: net_context.h:440
 
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:189
 
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:568
 
static bool net_context_is_proxy_enabled(struct net_context *context)
Definition: net_context.h:707
 
#define NET_CONTEXT_IN_USE
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:383
 
net_context_state
Definition: net_context.h:39
 
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:493
 
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:820
 
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:795
 
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:593
 
#define NET_CONTEXT_CLOSING_SOCK
Definition: net_context.h:66
 
static uint8_t net_context_get_ipv6_hop_limit(struct net_context *context)
Definition: net_context.h:677
 
static void net_context_set_closing(struct net_context *context, bool closing)
Set this context to closing.
Definition: net_context.h:415
 
static void net_context_set_proxy_enabled(struct net_context *context, bool enable)
Definition: net_context.h:700
 
static uint8_t net_context_get_ipv4_ttl(struct net_context *context)
Definition: net_context.h:666
 
#define NET_CONTEXT_BOUND_TO_IFACE
Definition: net_context.h:69
 
void(* net_context_connect_cb_t)(struct net_context *context, int status, void *user_data)
Connection callback.
Definition: net_context.h:161
 
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:457
 
net_context_option
Definition: net_context.h:1067
 
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.
 
#define NET_CONTEXT_STATE_MASK
Definition: net_context.h:428
 
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:402
 
#define NET_CONTEXT_FAMILY
Definition: net_context.h:54
 
#define NET_CONTEXT_TYPE
Definition: net_context.h:57
 
#define NET_CONTEXT_STATE_SHIFT
Definition: net_context.h:427
 
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:626
 
#define net_context_setup_pools(context, tx_pool, data_pool)
Set custom network buffer pools for context send operations.
Definition: net_context.h:1155
 
static uint16_t net_context_get_proto(struct net_context *context)
Get context IP protocol for this network context.
Definition: net_context.h:611
 
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
Definition: net_context.h:63
 
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.
 
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:643
 
@ NET_CONTEXT_CONNECTED
Definition: net_context.h:45
 
@ NET_CONTEXT_IDLE
Definition: net_context.h:40
 
@ NET_CONTEXT_CONNECTING
Definition: net_context.h:43
 
@ NET_CONTEXT_READY
Definition: net_context.h:44
 
@ NET_CONTEXT_UNCONNECTED
Definition: net_context.h:41
 
@ NET_CONTEXT_CONFIGURING
Definition: net_context.h:42
 
@ NET_CONTEXT_LISTENING
Definition: net_context.h:46
 
@ NET_OPT_SNDBUF
Definition: net_context.h:1074
 
@ NET_OPT_PRIORITY
Definition: net_context.h:1068
 
@ NET_OPT_RCVTIMEO
Definition: net_context.h:1071
 
@ NET_OPT_TXTIME
Definition: net_context.h:1069
 
@ NET_OPT_SNDTIMEO
Definition: net_context.h:1072
 
@ NET_OPT_SOCKS5
Definition: net_context.h:1070
 
@ NET_OPT_RCVBUF
Definition: net_context.h:1073
 
@ NET_OPT_DSCP_ECN
Definition: net_context.h:1075
 
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 API for network interface.
 
IPv6 and IPv4 definitions.
 
flags
Definition: parser.h:96
 
state
Definition: parser_state.h:29
 
static ZTEST_DMEM int flag
Definition: main.c:26
 
__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
 
Definition: kernel.h:2930
 
Definition: kernel.h:2310
 
Definition: kernel.h:2822
 
Kernel timeout type.
Definition: sys_clock.h:65
 
Network buffer pool representation.
Definition: buf.h:971
 
Definition: net_context.h:201
 
atomic_t refcount
Definition: net_context.h:212
 
void * user_data
Definition: net_context.h:208
 
void * fifo_reserved
Definition: net_context.h:204
 
uint16_t flags
Definition: net_context.h:332
 
net_context_send_cb_t send_cb
Definition: net_context.h:239
 
struct sockaddr remote
Definition: net_context.h:226
 
struct k_mutex lock
Definition: net_context.h:216
 
struct sockaddr_ptr local
Definition: net_context.h:221
 
struct net_context::@274 options
 
uint8_t ipv4_ttl
Definition: net_context.h:340
 
net_context_connect_cb_t connect_cb
Definition: net_context.h:244
 
struct net_conn_handle * conn_handler
Definition: net_context.h:229
 
uint16_t proto
Definition: net_context.h:329
 
int8_t iface
Definition: net_context.h:335
 
void * tcp
Definition: net_context.h:258
 
net_context_recv_cb_t recv_cb
Definition: net_context.h:234
 
uint8_t ipv6_hop_limit
Definition: net_context.h:339
 
Network Interface structure.
Definition: net_if.h:516
 
Network packet.
Definition: net_pkt.h:62
 
static const intptr_t user_data[5]
Definition: main.c:588