Networking: Save the IP domain in the connection structure

This commit is contained in:
Gregory Nutt
2015-01-17 13:07:48 -06:00
parent 4a0eb1f0b1
commit 94f9312150
6 changed files with 31 additions and 23 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ struct devif_callback_s; /* Forward reference */
struct socket struct socket
{ {
int16_t s_crefs; /* Reference count on the 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_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */
uint8_t s_flags; /* See _SF_* definitions */ uint8_t s_flags; /* See _SF_* definitions */
+2 -2
View File
@@ -192,7 +192,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock)
* socket instance. * socket instance.
*/ */
FAR struct tcp_conn_s *conn = tcp_alloc(); FAR struct tcp_conn_s *conn = tcp_alloc(domain);
if (!conn) if (!conn)
{ {
/* Failed to reserve a connection structure */ /* 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. * socket instance.
*/ */
FAR struct udp_conn_s *conn = udp_alloc(); FAR struct udp_conn_s *conn = udp_alloc(domain);
if (!conn) if (!conn)
{ {
/* Failed to reserve a connection structure */ /* Failed to reserve a connection structure */
+2 -1
View File
@@ -112,6 +112,7 @@ struct tcp_conn_s
* receive next */ * receive next */
uint8_t sndseq[4]; /* The sequence number that was last sent by us */ uint8_t sndseq[4]; /* The sequence number that was last sent by us */
uint8_t crefs; /* Reference counts on this instance */ 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 uint8_t sa; /* Retransmission time-out calculation state
* variable */ * variable */
uint8_t sv; /* Retransmission time-out calculation state 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 * Name: tcp_free
+7 -2
View File
@@ -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; FAR struct tcp_conn_s *conn;
net_lock_t flags; net_lock_t flags;
@@ -374,6 +374,7 @@ FAR struct tcp_conn_s *tcp_alloc(void)
{ {
memset(conn, 0, sizeof(struct tcp_conn_s)); memset(conn, 0, sizeof(struct tcp_conn_s));
conn->tcpstateflags = TCP_ALLOCATED; conn->tcpstateflags = TCP_ALLOCATED;
conn->domain = domain;
} }
return conn; 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 net_iphdr_s *ip = IPv4;
FAR struct tcp_conn_s *conn; 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) if (conn)
{ {
/* Fill in the necessary fields for the new connection. */ /* Fill in the necessary fields for the new connection. */
+9 -8
View File
@@ -70,6 +70,7 @@ struct udp_conn_s
union ip_binding_u u; /* IP address binding */ union ip_binding_u u; /* IP address binding */
uint16_t lport; /* Bound local port number (network byte order) */ uint16_t lport; /* Bound local port number (network byte order) */
uint16_t rport; /* Remote 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 ttl; /* Default time-to-live */
uint8_t crefs; /* Reference counts on this instance */ uint8_t crefs; /* Reference counts on this instance */
@@ -99,7 +100,7 @@ struct udp_iphdr_s; /* Forward reference */
/* Defined in udp_conn.c ****************************************************/ /* Defined in udp_conn.c ****************************************************/
/**************************************************************************** /****************************************************************************
* Name: udp_initialize() * Name: udp_initialize
* *
* Description: * Description:
* Initialize the UDP connection structures. Called once and only from * Initialize the UDP connection structures. Called once and only from
@@ -110,7 +111,7 @@ struct udp_iphdr_s; /* Forward reference */
void udp_initialize(void); void udp_initialize(void);
/**************************************************************************** /****************************************************************************
* Name: udp_alloc() * Name: udp_alloc
* *
* Description: * Description:
* Allocate a new, uninitialized UDP connection structure. This is * 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: * Description:
* Free a UDP connection structure that is no longer in use. This should be * 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); void udp_free(FAR struct udp_conn_s *conn);
/**************************************************************************** /****************************************************************************
* Name: udp_active() * Name: udp_active
* *
* Description: * Description:
* Find a connection structure that is the appropriate * 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); FAR struct udp_hdr_s *udp);
/**************************************************************************** /****************************************************************************
* Name: udp_nextconn() * Name: udp_nextconn
* *
* Description: * Description:
* Traverse the list of allocated UDP connections * 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); FAR struct udp_conn_s *udp_nextconn(FAR struct udp_conn_s *conn);
/**************************************************************************** /****************************************************************************
* Name: udp_bind() * Name: udp_bind
* *
* Description: * Description:
* This function implements the low-level parts of the standard UDP bind() * 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 #endif
/**************************************************************************** /****************************************************************************
* Name: udp_connect() * Name: udp_connect
* *
* Description: * Description:
* This function sets up a new UDP connection. The function will * This function sets up a new UDP connection. The function will
+10 -9
View File
@@ -242,7 +242,7 @@ static uint16_t udp_select_port(void)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: udp_initialize() * Name: udp_initialize
* *
* Description: * Description:
* Initialize the UDP connection structures. Called once and only from * 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: * Description:
* Allocate a new, uninitialized UDP connection structure. This is * 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; 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 */ /* 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 */ /* 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: * Description:
* Free a UDP connection structure that is no longer in use. This should be * 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: * Description:
* Find a connection structure that is the appropriate * 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: * Description:
* Traverse the list of allocated UDP connections * 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: * Description:
* This function implements the low level parts of the standard UDP * 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: * Description:
* This function simply assigns a remote address to UDP "connection" * This function simply assigns a remote address to UDP "connection"