From 1894f586fc02b404dceb92acf43cbb355b7bbb91 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 17 Jan 2015 13:07:48 -0600 Subject: Networking: Save the IP domain in the connection structure --- nuttx/include/nuttx/net/net.h | 2 +- nuttx/net/socket/socket.c | 4 ++-- nuttx/net/tcp/tcp.h | 3 ++- nuttx/net/tcp/tcp_conn.c | 9 +++++++-- nuttx/net/udp/udp.h | 17 +++++++++-------- nuttx/net/udp/udp_conn.c | 19 ++++++++++--------- 6 files changed, 31 insertions(+), 23 deletions(-) (limited to 'nuttx') diff --git a/nuttx/include/nuttx/net/net.h b/nuttx/include/nuttx/net/net.h index dcec612aa..27a8e2148 100644 --- a/nuttx/include/nuttx/net/net.h +++ b/nuttx/include/nuttx/net/net.h @@ -97,7 +97,7 @@ struct devif_callback_s; /* Forward reference */ struct socket { int16_t s_crefs; /* Reference count on the socket */ - uint8_t s_domain; /* Domain: PF_INET, PF_INET6, or PF_PACKET */ + uint8_t s_domain; /* IP domain: PF_INET, PF_INET6, or PF_PACKET */ uint8_t s_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */ uint8_t s_flags; /* See _SF_* definitions */ diff --git a/nuttx/net/socket/socket.c b/nuttx/net/socket/socket.c index 6dadf79d3..cd24018a4 100644 --- a/nuttx/net/socket/socket.c +++ b/nuttx/net/socket/socket.c @@ -192,7 +192,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) * socket instance. */ - FAR struct tcp_conn_s *conn = tcp_alloc(); + FAR struct tcp_conn_s *conn = tcp_alloc(domain); if (!conn) { /* Failed to reserve a connection structure */ @@ -219,7 +219,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) * socket instance. */ - FAR struct udp_conn_s *conn = udp_alloc(); + FAR struct udp_conn_s *conn = udp_alloc(domain); if (!conn) { /* Failed to reserve a connection structure */ diff --git a/nuttx/net/tcp/tcp.h b/nuttx/net/tcp/tcp.h index e5469d60f..8c1181d8b 100644 --- a/nuttx/net/tcp/tcp.h +++ b/nuttx/net/tcp/tcp.h @@ -112,6 +112,7 @@ struct tcp_conn_s * receive next */ uint8_t sndseq[4]; /* The sequence number that was last sent by us */ uint8_t crefs; /* Reference counts on this instance */ + uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ uint8_t sa; /* Retransmission time-out calculation state * variable */ uint8_t sv; /* Retransmission time-out calculation state @@ -290,7 +291,7 @@ void tcp_initialize(void); * ****************************************************************************/ -FAR struct tcp_conn_s *tcp_alloc(void); +FAR struct tcp_conn_s *tcp_alloc(uint8_t domain); /**************************************************************************** * Name: tcp_free diff --git a/nuttx/net/tcp/tcp_conn.c b/nuttx/net/tcp/tcp_conn.c index 6756fa6fb..1cc45cca2 100644 --- a/nuttx/net/tcp/tcp_conn.c +++ b/nuttx/net/tcp/tcp_conn.c @@ -277,7 +277,7 @@ void tcp_initialize(void) * ****************************************************************************/ -FAR struct tcp_conn_s *tcp_alloc(void) +FAR struct tcp_conn_s *tcp_alloc(uint8_t domain) { FAR struct tcp_conn_s *conn; net_lock_t flags; @@ -374,6 +374,7 @@ FAR struct tcp_conn_s *tcp_alloc(void) { memset(conn, 0, sizeof(struct tcp_conn_s)); conn->tcpstateflags = TCP_ALLOCATED; + conn->domain = domain; } return conn; @@ -587,7 +588,11 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev, FAR struct net_iphdr_s *ip = IPv4; FAR struct tcp_conn_s *conn; - conn = tcp_alloc(); +#ifdef CONFIG_NET_IPv4 + conn = tcp_alloc(PF_INET); +#else + conn = tcp_alloc(PF_INET6); +#endif if (conn) { /* Fill in the necessary fields for the new connection. */ diff --git a/nuttx/net/udp/udp.h b/nuttx/net/udp/udp.h index cf6948a83..d67b0f6e8 100644 --- a/nuttx/net/udp/udp.h +++ b/nuttx/net/udp/udp.h @@ -70,6 +70,7 @@ struct udp_conn_s union ip_binding_u u; /* IP address binding */ uint16_t lport; /* Bound local port number (network byte order) */ uint16_t rport; /* Remote port number (network byte order) */ + uint8_t domain; /* IP domain: PF_INET or PF_INET6 */ uint8_t ttl; /* Default time-to-live */ uint8_t crefs; /* Reference counts on this instance */ @@ -99,7 +100,7 @@ struct udp_iphdr_s; /* Forward reference */ /* Defined in udp_conn.c ****************************************************/ /**************************************************************************** - * Name: udp_initialize() + * Name: udp_initialize * * Description: * Initialize the UDP connection structures. Called once and only from @@ -110,7 +111,7 @@ struct udp_iphdr_s; /* Forward reference */ void udp_initialize(void); /**************************************************************************** - * Name: udp_alloc() + * Name: udp_alloc * * Description: * Allocate a new, uninitialized UDP connection structure. This is @@ -118,10 +119,10 @@ void udp_initialize(void); * ****************************************************************************/ -FAR struct udp_conn_s *udp_alloc(void); +FAR struct udp_conn_s *udp_alloc(uint8_t domain); /**************************************************************************** - * Name: udp_free() + * Name: udp_free * * Description: * Free a UDP connection structure that is no longer in use. This should be @@ -132,7 +133,7 @@ FAR struct udp_conn_s *udp_alloc(void); void udp_free(FAR struct udp_conn_s *conn); /**************************************************************************** - * Name: udp_active() + * Name: udp_active * * Description: * Find a connection structure that is the appropriate @@ -147,7 +148,7 @@ FAR struct udp_conn_s *udp_active(FAR struct net_driver_s *dev, FAR struct udp_hdr_s *udp); /**************************************************************************** - * Name: udp_nextconn() + * Name: udp_nextconn * * Description: * Traverse the list of allocated UDP connections @@ -160,7 +161,7 @@ FAR struct udp_conn_s *udp_active(FAR struct net_driver_s *dev, FAR struct udp_conn_s *udp_nextconn(FAR struct udp_conn_s *conn); /**************************************************************************** - * Name: udp_bind() + * Name: udp_bind * * Description: * This function implements the low-level parts of the standard UDP bind() @@ -178,7 +179,7 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in *addr); #endif /**************************************************************************** - * Name: udp_connect() + * Name: udp_connect * * Description: * This function sets up a new UDP connection. The function will diff --git a/nuttx/net/udp/udp_conn.c b/nuttx/net/udp/udp_conn.c index c1b3e5ecb..d2ccb9a5f 100644 --- a/nuttx/net/udp/udp_conn.c +++ b/nuttx/net/udp/udp_conn.c @@ -242,7 +242,7 @@ static uint16_t udp_select_port(void) ****************************************************************************/ /**************************************************************************** - * Name: udp_initialize() + * Name: udp_initialize * * Description: * Initialize the UDP connection structures. Called once and only from @@ -272,7 +272,7 @@ void udp_initialize(void) } /**************************************************************************** - * Name: udp_alloc() + * Name: udp_alloc * * Description: * Allocate a new, uninitialized UDP connection structure. This is @@ -280,7 +280,7 @@ void udp_initialize(void) * ****************************************************************************/ -FAR struct udp_conn_s *udp_alloc(void) +FAR struct udp_conn_s *udp_alloc(uint8_t domain) { FAR struct udp_conn_s *conn; @@ -294,7 +294,8 @@ FAR struct udp_conn_s *udp_alloc(void) { /* Make sure that the connection is marked as uninitialized */ - conn->lport = 0; + conn->domain = domain; + conn->lport = 0; /* Enqueue the connection into the active list */ @@ -306,7 +307,7 @@ FAR struct udp_conn_s *udp_alloc(void) } /**************************************************************************** - * Name: udp_free() + * Name: udp_free * * Description: * Free a UDP connection structure that is no longer in use. This should be @@ -336,7 +337,7 @@ void udp_free(FAR struct udp_conn_s *conn) } /**************************************************************************** - * Name: udp_active() + * Name: udp_active * * Description: * Find a connection structure that is the appropriate @@ -402,7 +403,7 @@ FAR struct udp_conn_s *udp_active(FAR struct net_driver_s *dev, } /**************************************************************************** - * Name: udp_nextconn() + * Name: udp_nextconn * * Description: * Traverse the list of allocated UDP connections @@ -426,7 +427,7 @@ FAR struct udp_conn_s *udp_nextconn(FAR struct udp_conn_s *conn) } /**************************************************************************** - * Name: udp_bind() + * Name: udp_bind * * Description: * This function implements the low level parts of the standard UDP @@ -509,7 +510,7 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in *addr) } /**************************************************************************** - * Name: udp_connect() + * Name: udp_connect * * Description: * This function simply assigns a remote address to UDP "connection" -- cgit v1.2.3