Skip to content

Commit

Permalink
Remove some dead Inet code
Browse files Browse the repository at this point in the history
#### Problem

`src/inet` has some unused code inherited from Weave, which complicates
maintenance. (Specifically, this is on the path to project-chip#7715 _Virtualize
System and Inet interfaces_.)

#### Change overview

- Remove some unused code from `Inet::EndPointBasis`
- Remove some unused `#include`s
- Remove unused `INET_CONFIG_WILL_OVERRIDE_PLATFORM_XTOR_FUNCS`
- Remove `src/inet/InetUtils.cpp`
- Remove `src/system/SystemLayerPrivate.h`
- Convert LwIPEndPointType to `enum class`

#### Testing

CI; no functional changes.
  • Loading branch information
kpschoedel authored and andy31415 committed Oct 5, 2021
1 parent 899a5c1 commit 5513fdf
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 717 deletions.
1 change: 0 additions & 1 deletion src/inet/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static_library("inet") {
"InetLayer.h",
"InetLayerBasis.h",
"InetLayerEvents.h",
"InetUtils.cpp",
"arpa-inet-compatibility.h",
]

Expand Down
8 changes: 4 additions & 4 deletions src/inet/EndPointBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ void EndPointBasis::InitEndPointBasis(InetLayer & aInetLayer, void * aAppState)
InitInetLayerBasis(aInetLayer, aAppState);

#if CHIP_SYSTEM_CONFIG_USE_LWIP
mLwIPEndPointType = kLwIPEndPointType_Unknown;
mLwIPEndPointType = LwIPEndPointType::Unknown;
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
mSocket = INET_INVALID_SOCKET_FD;
mSocket = kInvalidSocketFd;
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
}

#if CHIP_SYSTEM_CONFIG_USE_LWIP
void EndPointBasis::DeferredFree(chip::System::Object::ReleaseDeferralErrorTactic aTactic)
void EndPointBasis::DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic)
{
if (!CHIP_SYSTEM_CONFIG_USE_SOCKETS || IsLWIPEndPoint())
if (!CHIP_SYSTEM_CONFIG_USE_SOCKETS || (mVoid != nullptr))
{
DeferredRelease(static_cast<System::LayerLwIP *>(Layer().SystemLayer()), aTactic);
}
Expand Down
107 changes: 15 additions & 92 deletions src/inet/EndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

#include <inet/InetConfig.h>

#include "inet/IANAConstants.h"
#include "inet/InetLayerBasis.h"
#include <inet/InetError.h>
#include <inet/InetInterface.h>
#include <inet/InetLayerEvents.h>
#include <inet/IPAddress.h>
#include <inet/InetLayerBasis.h>

#include <lib/support/DLLUtil.h>

Expand All @@ -42,58 +39,29 @@
#include <Network/Network.h>
#endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

//--- Declaration of LWIP protocol control buffer structure names
#if CHIP_SYSTEM_CONFIG_USE_LWIP
#if INET_CONFIG_ENABLE_UDP_ENDPOINT
struct udp_pcb;
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
struct tcp_pcb;
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

namespace chip {
namespace Inet {

/**
* @class EndPointBasis
*
* @brief Basis of internet transport endpoint classes
* Basis of internet transport endpoint classes.
*/
class DLL_EXPORT EndPointBasis : public InetLayerBasis
{
public:
/** Common state codes */
enum
{
kBasisState_Closed = 0 /**< Encapsulated descriptor is not valid. */
};

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
/** Test whether endpoint is a Network.framework endpoint */
bool IsNetworkFrameworkEndPoint(void) const;
#endif

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
/** Test whether endpoint is a POSIX socket */
bool IsSocketsEndPoint() const;
#endif

#if CHIP_SYSTEM_CONFIG_USE_LWIP
/** Test whether endpoint is a LwIP protocol control buffer */
bool IsLWIPEndPoint(void) const;
#endif

/** Test whether endpoint has a valid descriptor. */
bool IsOpenEndPoint() const;

protected:
void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr);

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
nw_parameters_t mParameters;
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
#endif

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
static constexpr int kInvalidSocketFd = -1;
int mSocket; /**< Encapsulated socket descriptor. */
IPAddressType mAddrType; /**< Protocol family, i.e. IPv4 or IPv6. */
System::SocketWatchToken mWatch; /**< Socket event watcher */
Expand All @@ -112,63 +80,18 @@ class DLL_EXPORT EndPointBasis : public InetLayerBasis
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
};

enum
enum class LwIPEndPointType : uint8_t
{
kLwIPEndPointType_Unknown = 0,

kLwIPEndPointType_Raw = 1,
kLwIPEndPointType_UDP = 2,
kLwIPEndPointType_UCP = 3,
kLwIPEndPointType_TCP = 4
};

uint8_t mLwIPEndPointType;

void DeferredFree(chip::System::Object::ReleaseDeferralErrorTactic aTactic);
Unknown = 0,
Raw = 1,
UDP = 2,
UCP = 3,
TCP = 4
} mLwIPEndPointType;

void DeferredFree(System::Object::ReleaseDeferralErrorTactic aTactic);
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

void InitEndPointBasis(InetLayer & aInetLayer, void * aAppState = nullptr);
};

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
inline bool EndPointBasis::IsNetworkFrameworkEndPoint(void) const
{
return mParameters != NULL;
}
#endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
inline bool EndPointBasis::IsSocketsEndPoint() const
{
return mSocket != INET_INVALID_SOCKET_FD;
}
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

#if CHIP_SYSTEM_CONFIG_USE_LWIP
inline bool EndPointBasis::IsLWIPEndPoint(void) const
{
return mVoid != NULL;
}
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

inline bool EndPointBasis::IsOpenEndPoint() const
{
bool lResult = false;

#if CHIP_SYSTEM_CONFIG_USE_LWIP
lResult = (lResult || IsLWIPEndPoint());
#endif // CHIP_SYSTEM_CONFIG_USE_LWIP

#if CHIP_SYSTEM_CONFIG_USE_SOCKETS
lResult = (lResult || IsSocketsEndPoint());
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS

#if CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK
lResult = (lResult || IsNetworkFrameworkEndPoint());
#endif // CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK

return lResult;
}

} // namespace Inet
} // namespace chip
6 changes: 3 additions & 3 deletions src/inet/IPEndPointBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ CHIP_ERROR IPEndPointBasis::SetMulticastLoopback(IPVersion aIPVersion, bool aLoo
{

#if INET_CONFIG_ENABLE_UDP_ENDPOINT
case kLwIPEndPointType_UDP:
case LwIPEndPointType::UDP:
udp_set_flags(mUDP, UDP_FLAGS_MULTICAST_LOOP);
break;
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
Expand All @@ -361,7 +361,7 @@ CHIP_ERROR IPEndPointBasis::SetMulticastLoopback(IPVersion aIPVersion, bool aLoo
{

#if INET_CONFIG_ENABLE_UDP_ENDPOINT
case kLwIPEndPointType_UDP:
case LwIPEndPointType::UDP:
udp_clear_flags(mUDP, UDP_FLAGS_MULTICAST_LOOP);
break;
#endif // INET_CONFIG_ENABLE_UDP_ENDPOINT
Expand Down Expand Up @@ -907,7 +907,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System:

CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int aProtocol)
{
if (mSocket == INET_INVALID_SOCKET_FD)
if (mSocket == kInvalidSocketFd)
{
const int one = 1;
int family;
Expand Down
18 changes: 6 additions & 12 deletions src/inet/IPEndPointBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <inet/EndPointBasis.h>

#include <inet/InetInterface.h>
#include <inet/InetLayerEvents.h>
#include <system/SystemPacketBuffer.h>

#if CHIP_SYSTEM_CONFIG_USE_LWIP
Expand Down Expand Up @@ -61,21 +63,13 @@ class DLL_EXPORT IPEndPointBasis : public EndPointBasis
* state after binding to a local interface address, then proceed to the
* "listening" state when they have continuations registered for handling
* events for reception of ICMP messages.
*
* @note
* The \c kBasisState_Closed state enumeration is mapped to \c
* kState_Ready for historical binary-compatibility reasons. The
* existing \c kState_Closed exists to identify separately the
* distinction between "not opened yet" and "previously opened
* now closed" that existed previously in the \c kState_Ready and
* \c kState_Closed states.
*/
enum
{
kState_Ready = kBasisState_Closed, /**< Endpoint initialized, but not open. */
kState_Bound = 1, /**< Endpoint bound, but not listening. */
kState_Listening = 2, /**< Endpoint receiving datagrams. */
kState_Closed = 3 /**< Endpoint closed, ready for release. */
kState_Ready = 0, /**< Endpoint initialized, but not open. */
kState_Bound = 1, /**< Endpoint bound, but not listening. */
kState_Listening = 2, /**< Endpoint receiving datagrams. */
kState_Closed = 3 /**< Endpoint closed, ready for release. */
} mState;

/**
Expand Down
13 changes: 0 additions & 13 deletions src/inet/InetConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@
#define INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS 0
#endif // INET_CONFIG_WILL_OVERRIDE_LWIP_ERROR_FUNCS

/**
* @def INET_CONFIG_WILL_OVERRIDE_PLATFORM_XTOR_FUNCS
*
* @brief
* This defines whether (1) or not (0) your platform will override
* the platform- and system-specific InetLayer WillInit, DidInit,
* WillShutdown, and DidShutdown.
*
*/
#ifndef INET_CONFIG_WILL_OVERRIDE_PLATFORM_XTOR_FUNCS
#define INET_CONFIG_WILL_OVERRIDE_PLATFORM_XTOR_FUNCS 0
#endif // INET_CONFIG_WILL_OVERRIDE_PLATFORM_XTOR_FUNCS

/**
* @def INET_CONFIG_MAX_DROPPABLE_EVENTS
*
Expand Down
Loading

0 comments on commit 5513fdf

Please sign in to comment.