Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_context.h File Reference

Network context definitions. More...

Go to the source code of this file.

Data Structures

struct  net_context
 Note that we do not store the actual source IP address in the context because the address is already be set in the network interface struct. More...
 

Macros

#define NET_CONTEXT_IN_USE   BIT(0)
 Is this context used or not.
 
#define NET_CONTEXT_FAMILY   (BIT(3) | BIT(4) | BIT(5))
 The address family, connection type and IP protocol are stored into a bit field to save space.
 
#define NET_CONTEXT_TYPE   (BIT(6) | BIT(7))
 Type of the connection (datagram / stream / raw)
 
#define NET_CONTEXT_REMOTE_ADDR_SET   BIT(8)
 Remote address set.
 
#define NET_CONTEXT_ACCEPTING_SOCK   BIT(9)
 Is the socket accepting connections.
 
#define NET_CONTEXT_CLOSING_SOCK   BIT(10)
 Is the socket closing / closed.
 
#define NET_CONTEXT_BOUND_TO_IFACE   BIT(11)
 Context is bound to a specific interface.
 
#define net_context_setup_pools(context, tx_pool, data_pool)
 Set custom network buffer pools for context send operations.
 

Typedefs

typedef 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.
 
typedef void(* net_context_send_cb_t) (struct net_context *context, int status, void *user_data)
 Network data send callback.
 
typedef void(* net_tcp_accept_cb_t) (struct net_context *new_context, struct sockaddr *addr, socklen_t addrlen, int status, void *user_data)
 Accept callback.
 
typedef void(* net_context_connect_cb_t) (struct net_context *context, int status, void *user_data)
 Connection callback.
 
typedef 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.
 
typedef 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.
 
typedef void(* net_context_cb_t) (struct net_context *context, void *user_data)
 Callback used while iterating over network contexts.
 

Enumerations

enum  net_context_option {
  NET_OPT_PRIORITY = 1 , NET_OPT_TXTIME = 2 , NET_OPT_SOCKS5 = 3 , NET_OPT_RCVTIMEO = 4 ,
  NET_OPT_SNDTIMEO = 5 , NET_OPT_RCVBUF = 6 , NET_OPT_SNDBUF = 7 , NET_OPT_DSCP_ECN = 8 ,
  NET_OPT_REUSEADDR = 9 , NET_OPT_REUSEPORT = 10 , NET_OPT_IPV6_V6ONLY = 11 , NET_OPT_RECV_PKTINFO = 12 ,
  NET_OPT_MCAST_TTL = 13 , NET_OPT_MCAST_HOP_LIMIT = 14 , NET_OPT_UNICAST_HOP_LIMIT = 15 , NET_OPT_TTL = 16 ,
  NET_OPT_ADDR_PREFERENCES = 17 , NET_OPT_TIMESTAMPING = 18
}
 Network context options. More...
 

Functions

static bool net_context_is_used (struct net_context *context)
 Is this context used or not.
 
static bool net_context_is_bound_to_iface (struct net_context *context)
 Is this context bound to a network interface.
 
static bool net_context_is_accepting (struct net_context *context)
 Is this context is accepting data now.
 
static void net_context_set_accepting (struct net_context *context, bool accepting)
 Set this context to accept data now.
 
static bool net_context_is_closing (struct net_context *context)
 Is this context closing.
 
static void net_context_set_closing (struct net_context *context, bool closing)
 Set this context to closing.
 
static enum net_context_state net_context_get_state (struct net_context *context)
 Get state for this network context.
 
static void net_context_set_state (struct net_context *context, enum net_context_state state)
 Set state for this network context.
 
static sa_family_t net_context_get_family (struct net_context *context)
 Get address family for this network context.
 
static void net_context_set_family (struct net_context *context, sa_family_t family)
 Set address family for this network context.
 
static enum net_sock_type net_context_get_type (struct net_context *context)
 Get context type for this network context.
 
static void net_context_set_type (struct net_context *context, enum net_sock_type type)
 Set context type for this network context.
 
static void net_context_set_can_filter_id (struct net_context *context, int filter_id)
 Set CAN filter id for this network context.
 
static int net_context_get_can_filter_id (struct net_context *context)
 Get CAN filter id for this network context.
 
static uint16_t net_context_get_proto (struct net_context *context)
 Get context IP protocol for this network context.
 
static void net_context_set_proto (struct net_context *context, uint16_t proto)
 Set context IP protocol for this network context.
 
static struct net_ifnet_context_get_iface (struct net_context *context)
 Get network interface for this context.
 
static void net_context_set_iface (struct net_context *context, struct net_if *iface)
 Set network interface for this context.
 
static void net_context_bind_iface (struct net_context *context, struct net_if *iface)
 Bind network interface to this context.
 
static uint8_t net_context_get_ipv4_ttl (struct net_context *context)
 Get IPv4 TTL (time-to-live) value for this context.
 
static void net_context_set_ipv4_ttl (struct net_context *context, uint8_t ttl)
 Set IPv4 TTL (time-to-live) value for this context.
 
static uint8_t net_context_get_ipv4_mcast_ttl (struct net_context *context)
 Get IPv4 multicast TTL (time-to-live) value for this context.
 
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.
 
static uint8_t net_context_get_ipv6_hop_limit (struct net_context *context)
 Get IPv6 hop limit value for this context.
 
static void net_context_set_ipv6_hop_limit (struct net_context *context, uint8_t hop_limit)
 Set IPv6 hop limit value for this context.
 
static uint8_t net_context_get_ipv6_mcast_hop_limit (struct net_context *context)
 Get IPv6 multicast hop limit 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.
 
static void net_context_set_proxy_enabled (struct net_context *context, bool enable)
 Enable or disable socks proxy support for this context.
 
static bool net_context_is_proxy_enabled (struct net_context *context)
 Is socks proxy support enabled or disabled for this context.
 
int net_context_get (sa_family_t family, enum net_sock_type type, uint16_t ip_proto, struct net_context **context)
 Get network context.
 
int net_context_put (struct net_context *context)
 Close and unref a network context.
 
int net_context_ref (struct net_context *context)
 Take a reference count to a net_context, preventing destruction.
 
int net_context_unref (struct net_context *context)
 Decrement the reference count to a network context.
 
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.
 
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.
 
int net_context_bind (struct net_context *context, const struct sockaddr *addr, socklen_t addrlen)
 Assign a socket a local address.
 
int net_context_listen (struct net_context *context, int backlog)
 Mark the context as a listening one.
 
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.
 
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_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.
 
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.
 
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_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.
 
int net_context_update_recv_wnd (struct net_context *context, int32_t delta)
 Update TCP receive window for 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_get_option (struct net_context *context, enum net_context_option option, void *value, size_t *len)
 Get connection option value for this 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.
 
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)
 

Detailed Description

Network context definitions.

An API for applications to define a network connection.