net/: Re-order the content of all address-family socket 'connection' structures so that they begin with a comomon prologue. This permits better use of logic for different address family types.

This commit is contained in:
Gregory Nutt 2019-09-01 08:47:01 -06:00
parent 19e1db3f97
commit 6266e067e9
13 changed files with 185 additions and 76 deletions

View File

@ -49,6 +49,7 @@
#include <stdbool.h>
#include <stdarg.h>
#include <semaphore.h>
#include <queue.h>
#ifdef CONFIG_MM_IOB
# include <nuttx/mm/iob.h>
@ -191,6 +192,29 @@ struct sock_intf_s
#endif
};
/* Each socket refers to a connection structure of type FAR void *. Each
* socket type will have a different connection structure type bound to its
* sockets. The fields at the the beginning of each connection type must
* begin the same content prologue as struct socket_conn_s and must be cast
* compatible with struct socket_conn_s. Connection-specific content may
* then follow the common prologue fields.
*/
struct devif_callback_s; /* Forward reference */
struct socket_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a doubly linked list */
/* This is a list of connection callbacks. Each callback represents a
* thread that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
};
/* This is the internal representation of a socket reference by a file
* descriptor.
*/
@ -216,7 +240,7 @@ struct socket
#endif
#endif
FAR void *s_conn; /* Connection: struct tcp_conn_s or udp_conn_s */
FAR void *s_conn; /* Connection inherits from struct socket_conn_s */
/* Socket interface */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/arp/arp.h
*
* Copyright (C) 2014-2016, 2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2014-2016, 2018-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -54,6 +54,7 @@
#include <stdint.h>
#include <semaphore.h>
#include <queue.h>
#include <errno.h>
#include <netinet/in.h>
@ -152,7 +153,19 @@ struct arp_send_s
struct arp_conn_s
{
/* Common prologue of all connection structures.
* NOTE: The 'node' field is not used by the ARP implementation.
*/
dq_entry_t node; /* Supports a doubly linked list */
/* This is a list of ARP callbacks. Each callback represents a thread
* that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list; /* ARP callbacks */
/* No ARP-specific content */
};
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/bluetooth/bluetooth.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2018-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -56,9 +56,9 @@
/* Allocate a new Bluetooth socket data callback */
#define bluetooth_callback_alloc(dev,conn) \
devif_callback_alloc(dev, &conn->list)
devif_callback_alloc(dev, &conn->bc_list)
#define bluetooth_callback_free(dev,conn,cb) \
devif_conn_callback_free(dev, cb, &conn->list)
devif_conn_callback_free(dev, cb, &conn->bc_list)
/* Memory Pools */
@ -90,7 +90,18 @@ struct devif_callback_s; /* Forward reference */
struct bluetooth_conn_s
{
dq_entry_t bc_node; /* Supports a double linked list */
/* Common prologue of all connection structures. */
dq_entry_t bc_node; /* Supports a doubly linked list */
/* This is a list of Bluetooth callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *bc_list; /* Bluetooth callbacks */
/* Bluetooth-specific content follows. */
bt_addr_t bc_laddr; /* Locally bound / source address.
* Necessary only to support multiple
* Bluetooth devices */
@ -105,12 +116,6 @@ struct bluetooth_conn_s
FAR struct bluetooth_container_s *bc_rxhead;
FAR struct bluetooth_container_s *bc_rxtail;
/* This is a list of Bluetooth callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
};
/****************************************************************************

View File

@ -2,7 +2,7 @@
* net/bluetooth/bluetooth_callback.c
* Forward events to waiting PF_BLUETOOTH sockets.
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2018-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -79,7 +79,7 @@ uint16_t bluetooth_callback(FAR struct radio_driver_s *radio,
{
/* Perform the callback */
flags = devif_conn_event(&radio->r_dev, conn, flags, conn->list);
flags = devif_conn_event(&radio->r_dev, conn, flags, conn->bc_list);
}
return flags;

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/icmp/icmp.h
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -77,7 +77,18 @@ struct devif_callback_s; /* Forward reference */
struct icmp_conn_s
{
dq_entry_t node; /* Supports a double linked list */
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a doubly linked list */
/* This is a list of ICMP callbacks. Each callback represents a thread
* that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
/* ICMP-specific content follows */
uint16_t id; /* ICMP ECHO request ID */
uint8_t nreqs; /* Number of requests with no response received */
uint8_t crefs; /* Reference counts on this instance */
@ -94,10 +105,6 @@ struct icmp_conn_s
struct iob_queue_s readahead; /* Read-ahead buffering */
#endif
/* Defines the list of ICMP callbacks */
FAR struct devif_callback_s *list;
};
#endif

View File

@ -78,7 +78,18 @@ struct devif_callback_s; /* Forward reference */
struct icmpv6_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a double linked list */
/* This is a list of ICMPV6 callbacks. Each callback represents a thread
* that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
/* ICMPv6-specific content follows */
uint16_t id; /* ICMPv6 ECHO request ID */
uint8_t nreqs; /* Number of requests with no response received */
uint8_t crefs; /* Reference counts on this instance */
@ -95,10 +106,6 @@ struct icmpv6_conn_s
struct iob_queue_s readahead; /* Read-ahead buffering */
#endif
/* Defines the list of ICMPV6 callbacks */
FAR struct devif_callback_s *list;
};
#endif

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/ieee802154/ieee802154.h
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2017, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -110,7 +110,18 @@ struct devif_callback_s; /* Forward reference */
struct ieee802154_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a double linked list */
/* This is a list of IEEE 802.15.4 callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
/* IEEE 802.15.4-specific content follows */
struct ieee802154_saddr_s laddr; /* Locally bound / source address */
struct ieee802154_saddr_s raddr; /* Connected remote address */
uint8_t crefs; /* Reference counts on this instance */
@ -122,12 +133,6 @@ struct ieee802154_conn_s
FAR struct ieee802154_container_s *rxhead;
FAR struct ieee802154_container_s *rxtail;
/* This is a list of IEEE 802.15.4 callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
};
/****************************************************************************

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/local/loal.h
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -126,8 +126,12 @@ enum local_state_s
* implemented.
*/
struct devif_callback_s; /* Forward reference */
struct local_conn_s
{
/* Common prologue of all connection structures. */
/* lc_node supports a doubly linked list: Listening SOCK_STREAM servers
* will be linked into a list of listeners; SOCK_STREAM clients will be
* linked to the lc_waiters and lc_conn lists.
@ -135,6 +139,16 @@ struct local_conn_s
dq_entry_t lc_node; /* Supports a doubly linked list */
/* This is a list of Local connection callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
* REVISIT: Here for commonality with other connection structures; not
* used in the current implementation.
*/
FAR struct devif_callback_s *lc_list;
/* Local-socket specific content follows */
/* Fields common to SOCK_STREAM and SOCK_DGRAM */
uint8_t lc_crefs; /* Reference counts on this instance */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/netlink/netlink.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2018-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -61,12 +61,20 @@
struct netlink_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a doubly linked list */
uint8_t crefs; /* Reference counts on this instance */
/* Defines the list of netlink callbacks */
/* This is a list of Netlink connection callbacks. Each callback
* represents a thread that is stalled, waiting for a device-specific
* event.
*/
FAR struct devif_callback_s *list;
FAR struct devif_callback_s *list; /* Netlink callbacks */
/* Netlink-specific content follows */
uint8_t crefs; /* Reference counts on this instance */
};
/****************************************************************************

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/pkt/pkt.h
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -68,15 +68,22 @@ struct devif_callback_s; /* Forward reference */
struct pkt_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a double linked list */
/* This is a list of Pkt connection callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
*/
struct devif_callback_s *list;
/* Pkt socket-specific content follows */
uint8_t lmac[6]; /* The local Ethernet address in network byte order */
uint8_t ifindex;
uint16_t proto;
uint8_t crefs; /* Reference counts on this instance */
/* Defines the list of packet callbacks */
struct devif_callback_s *list;
};
/****************************************************************************

View File

@ -1,7 +1,7 @@
/****************************************************************************
* net/tcp/tcp.h
*
* Copyright (C) 2014-2016, 2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2014-2016, 2018-2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -126,7 +126,38 @@ struct tcp_hdr_s; /* Forward reference */
struct tcp_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Implements a doubly linked list */
/* TCP callbacks:
*
* Data transfer events are retained in 'list'. Event handlers in 'list'
* are called for events specified in the flags set within struct
* devif_callback_s
*
* When an callback is executed from 'list', the input flags are normally
* returned, however, the implementation may set one of the following:
*
* TCP_CLOSE - Gracefully close the current connection
* TCP_ABORT - Abort (reset) the current connection on an error that
* prevents TCP_CLOSE from working.
*
* And/Or set/clear the following:
*
* TCP_NEWDATA - May be cleared to indicate that the data was consumed
* and that no further process of the new data should be
* attempted.
* TCP_SNDACK - If TCP_NEWDATA is cleared, then TCP_SNDACK may be set
* to indicate that an ACK should be included in the response.
* (In TCP_NEWDATA is cleared bu TCP_SNDACK is not set, then
* dev->d_len should also be cleared).
*/
FAR struct devif_callback_s *list;
/* TCP-specific content follows */
union ip_binding_u u; /* IP address binding */
uint8_t rcvseq[4]; /* The sequence number that we expect to
* receive next */
@ -221,32 +252,6 @@ struct tcp_conn_s
uint8_t keepretries; /* Number of retries attempted */
#endif
/* Application callbacks:
*
* Data transfer events are retained in 'list'. Event handlers in 'list'
* are called for events specified in the flags set within struct
* devif_callback_s
*
* When an callback is executed from 'list', the input flags are normally
* returned, however, the implementation may set one of the following:
*
* TCP_CLOSE - Gracefully close the current connection
* TCP_ABORT - Abort (reset) the current connection on an error that
* prevents TCP_CLOSE from working.
*
* And/Or set/clear the following:
*
* TCP_NEWDATA - May be cleared to indicate that the data was consumed
* and that no further process of the new data should be
* attempted.
* TCP_SNDACK - If TCP_NEWDATA is cleared, then TCP_SNDACK may be set
* to indicate that an ACK should be included in the response.
* (In TCP_NEWDATA is cleared bu TCP_SNDACK is not set, then
* dev->d_len should also be cleared).
*/
FAR struct devif_callback_s *list;
/* connevents is a list of callbacks for each socket the uses this
* connection (there can be more that one in the event that the the socket
* was dup'ed). It is used with the network monitor to handle

View File

@ -106,7 +106,18 @@ struct udp_hdr_s; /* Forward reference */
struct udp_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a doubly linked list */
/* This is a list of UDP connection callbacks. Each callback represents
* a thread that is stalled, waiting for a device-specific event.
*/
FAR struct devif_callback_s *list;
/* UDP-specific content follows */
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) */
@ -140,10 +151,6 @@ struct udp_conn_s
sq_queue_t write_q; /* Write buffering for UDP packets */
FAR struct net_driver_s *dev; /* Last device */
#endif
/* Defines the list of UDP callbacks */
FAR struct devif_callback_s *list;
};
/* This structure supports UDP write buffering. It is simply a container

View File

@ -88,7 +88,18 @@ enum usrsock_conn_state_e
struct usrsock_conn_s
{
/* Common prologue of all connection structures. */
dq_entry_t node; /* Supports a doubly linked list */
/* This is a list of usrsock callbacks. Each callback represents a thread
* that is stalled, waiting for a specific event.
*/
FAR struct devif_callback_s *list; /* Usersock callbacks */
/* usrsock-specific content follows */
uint8_t crefs; /* Reference counts on this instance */
enum usrsock_conn_state_e state; /* State of kernel<->daemon link for conn */
@ -115,10 +126,6 @@ struct usrsock_conn_s
size_t pos; /* Writer position on input buffer */
} datain;
} resp;
/* Defines the list of usrsock callbacks */
FAR struct devif_callback_s *list;
};
struct usrsock_reqstate_s