From 6266e067e99e96a7bbc979fd70d44b5c5fcab16a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Sep 2019 08:47:01 -0600 Subject: [PATCH] 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. --- include/nuttx/net/net.h | 26 ++++++++++++- net/arp/arp.h | 15 +++++++- net/bluetooth/bluetooth.h | 25 ++++++++----- net/bluetooth/bluetooth_callback.c | 4 +- net/icmp/icmp.h | 19 +++++++--- net/icmpv6/icmpv6.h | 15 ++++++-- net/ieee802154/ieee802154.h | 19 ++++++---- net/local/local.h | 16 +++++++- net/netlink/netlink.h | 16 ++++++-- net/pkt/pkt.h | 17 ++++++--- net/tcp/tcp.h | 59 ++++++++++++++++-------------- net/udp/udp.h | 15 ++++++-- net/usrsock/usrsock.h | 15 ++++++-- 13 files changed, 185 insertions(+), 76 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 3d467a7e4d..e383386d54 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -49,6 +49,7 @@ #include #include #include +#include #ifdef CONFIG_MM_IOB # include @@ -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 */ diff --git a/net/arp/arp.h b/net/arp/arp.h index 498670b7b2..16678cd728 100644 --- a/net/arp/arp.h +++ b/net/arp/arp.h @@ -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 * * Redistribution and use in source and binary forms, with or without @@ -54,6 +54,7 @@ #include #include +#include #include #include @@ -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 diff --git a/net/bluetooth/bluetooth.h b/net/bluetooth/bluetooth.h index 3e42a600c6..f947c5c351 100644 --- a/net/bluetooth/bluetooth.h +++ b/net/bluetooth/bluetooth.h @@ -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 * * 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; }; /**************************************************************************** diff --git a/net/bluetooth/bluetooth_callback.c b/net/bluetooth/bluetooth_callback.c index 1855ff4203..5695b20c31 100644 --- a/net/bluetooth/bluetooth_callback.c +++ b/net/bluetooth/bluetooth_callback.c @@ -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 * * 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; diff --git a/net/icmp/icmp.h b/net/icmp/icmp.h index 75e6aab7dd..024ced215d 100644 --- a/net/icmp/icmp.h +++ b/net/icmp/icmp.h @@ -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 * * 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 diff --git a/net/icmpv6/icmpv6.h b/net/icmpv6/icmpv6.h index 087b1e0051..1a9feaf521 100644 --- a/net/icmpv6/icmpv6.h +++ b/net/icmpv6/icmpv6.h @@ -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 diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h index 53868c8d1c..b0fec37aa2 100644 --- a/net/ieee802154/ieee802154.h +++ b/net/ieee802154/ieee802154.h @@ -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 * * 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; }; /**************************************************************************** diff --git a/net/local/local.h b/net/local/local.h index 3b1cceeab6..944f02ff72 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -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 * * 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 */ diff --git a/net/netlink/netlink.h b/net/netlink/netlink.h index 971047f628..fdf2d6de56 100644 --- a/net/netlink/netlink.h +++ b/net/netlink/netlink.h @@ -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 * * 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 */ }; /**************************************************************************** diff --git a/net/pkt/pkt.h b/net/pkt/pkt.h index 8ef88c3fa7..721d287e32 100644 --- a/net/pkt/pkt.h +++ b/net/pkt/pkt.h @@ -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 * * 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; }; /**************************************************************************** diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 67f668b32f..f52363e11d 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -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 * * 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 diff --git a/net/udp/udp.h b/net/udp/udp.h index 1e80ebdae9..0dd327cec7 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -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 diff --git a/net/usrsock/usrsock.h b/net/usrsock/usrsock.h index e640a7d153..b2f0722662 100644 --- a/net/usrsock/usrsock.h +++ b/net/usrsock/usrsock.h @@ -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