Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated TcpOptionType #1615

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 0 additions & 148 deletions Packet++/header/TcpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "TLVData.h"
#include <string.h>

#define PCPP_DEPRECATED_TCP_OPTION_TYPE \
PCPP_DEPRECATED("enum TcpOptionType is deprecated; Use enum class TcpOptionEnumType instead")

/// @file

/**
Expand Down Expand Up @@ -86,63 +83,6 @@ namespace pcpp
};
#pragma pack(pop)

/**
* TCP options types
*/
enum TcpOptionType : uint8_t
{
/** Padding */
PCPP_TCPOPT_NOP = 1,
/** End of options */
PCPP_TCPOPT_EOL = 0,
/** Segment size negotiating */
TCPOPT_MSS = 2,
/** Window scaling */
PCPP_TCPOPT_WINDOW = 3,
/** SACK Permitted */
TCPOPT_SACK_PERM = 4,
/** SACK Block */
PCPP_TCPOPT_SACK = 5,
/** Echo (obsoleted by option TcpOptionType::PCPP_TCPOPT_TIMESTAMP) */
TCPOPT_ECHO = 6,
/** Echo Reply (obsoleted by option TcpOptionType::PCPP_TCPOPT_TIMESTAMP) */
TCPOPT_ECHOREPLY = 7,
/** TCP Timestamps */
PCPP_TCPOPT_TIMESTAMP = 8,
/** CC (obsolete) */
TCPOPT_CC = 11,
/** CC.NEW (obsolete) */
TCPOPT_CCNEW = 12,
/** CC.ECHO(obsolete) */
TCPOPT_CCECHO = 13,
/** MD5 Signature Option */
TCPOPT_MD5 = 19,
/** Multipath TCP */
TCPOPT_MPTCP = 0x1e,
/** SCPS Capabilities */
TCPOPT_SCPS = 20,
/** SCPS SNACK */
TCPOPT_SNACK = 21,
/** SCPS Record Boundary */
TCPOPT_RECBOUND = 22,
/** SCPS Corruption Experienced */
TCPOPT_CORREXP = 23,
/** Quick-Start Response */
TCPOPT_QS = 27,
/** User Timeout Option (also, other known unauthorized use) */
TCPOPT_USER_TO = 28,
/** RFC3692-style Experiment 1 (also improperly used for shipping products) */
TCPOPT_EXP_FD = 0xfd,
/** RFC3692-style Experiment 2 (also improperly used for shipping products) */
TCPOPT_EXP_FE = 0xfe,
/** Riverbed probe option, non IANA registered option number */
TCPOPT_RVBD_PROBE = 76,
/** Riverbed transparency option, non IANA registered option number */
TCPOPT_RVBD_TRPY = 78,
/** Unknown option */
TCPOPT_Unknown = 255
};

/**
* TCP options types
*/
Expand Down Expand Up @@ -269,15 +209,6 @@ namespace pcpp
*/
~TcpOption() override = default;

/**
* @deprecated This method is deprecated, please use getTcpOptionEnumType()
*/
PCPP_DEPRECATED("Use getTcpOptionEnumType instead")
TcpOptionType getTcpOptionType() const
{
return getTcpOptionType(m_Data);
}

/**
* @return TCP option type casted as pcpp::TcpOptionEnumType enum. If the data is null a value
* of TcpOptionEnumType::Unknown is returned
Expand Down Expand Up @@ -336,14 +267,6 @@ namespace pcpp
}

private:
static TcpOptionType getTcpOptionType(const TLVRawData* optionRawData)
{
if (optionRawData == nullptr)
return TcpOptionType::TCPOPT_Unknown;

return static_cast<TcpOptionType>(optionRawData->recordType);
}

static TcpOptionEnumType getTcpOptionEnumType(const TLVRawData* optionRawData)
{
if (optionRawData == nullptr)
Expand All @@ -362,17 +285,6 @@ namespace pcpp
{

public:
/**
* An enum to describe NOP and EOL TCP options. Used in one of this class's c'tors
*/
enum NopEolOptionTypes : uint8_t
{
/** NOP TCP option */
NOP,
/** EOL TCP option */
EOL
};

/**
* An enum to describe NOP and EOL TCP options. Used in one of this class's c'tors
*/
Expand All @@ -384,14 +296,6 @@ namespace pcpp
Eol
};

/**
* @deprecated This method is deprecated, please use constructor with TcpOptionEnumType
*/
PCPP_DEPRECATED_TCP_OPTION_TYPE
TcpOptionBuilder(TcpOptionType optionType, const uint8_t* optionValue, uint8_t optionValueLen)
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue, optionValueLen)
{}

/**
* A c'tor for building TCP options which their value is a byte array. The TcpOption object can be later
* retrieved by calling build()
Expand All @@ -404,14 +308,6 @@ namespace pcpp
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue, optionValueLen)
{}

/**
* @deprecated This method is deprecated, please use constructor with TcpOptionEnumType
*/
PCPP_DEPRECATED_TCP_OPTION_TYPE
TcpOptionBuilder(TcpOptionType optionType, uint8_t optionValue)
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue)
{}

/**
* A c'tor for building TCP options which have a 1-byte value. The TcpOption object can be later retrieved
* by calling build()
Expand All @@ -422,14 +318,6 @@ namespace pcpp
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue)
{}

/**
* @deprecated This method is deprecated, please use constructor with TcpOptionEnumType
*/
PCPP_DEPRECATED_TCP_OPTION_TYPE
TcpOptionBuilder(TcpOptionType optionType, uint16_t optionValue)
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue)
{}

/**
* A c'tor for building TCP options which have a 2-byte value. The TcpOption object can be later retrieved
* by calling build()
Expand All @@ -440,14 +328,6 @@ namespace pcpp
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue)
{}

/**
* @deprecated This method is deprecated, please use constructor with TcpOptionEnumType
*/
PCPP_DEPRECATED_TCP_OPTION_TYPE
TcpOptionBuilder(TcpOptionType optionType, uint32_t optionValue)
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue)
{}

/**
* A c'tor for building TCP options which have a 4-byte value. The TcpOption object can be later retrieved
* by calling build()
Expand All @@ -458,12 +338,6 @@ namespace pcpp
: TLVRecordBuilder(static_cast<uint8_t>(optionType), optionValue)
{}

/**
* @deprecated This method is deprecated, please use constructor with NopEolOptionEnumType
*/
PCPP_DEPRECATED("enum NopEolOptionTypes is deprecated; Use enum class NopEolOptionEnumType instead")
explicit TcpOptionBuilder(NopEolOptionTypes optionType);

/**
* A c'tor for building TCP NOP and EOL options. These option types are special in that they contain only 1 byte
* which is the TCP option type (NOP or EOL). The TcpOption object can be later retrieved
Expand Down Expand Up @@ -540,12 +414,6 @@ namespace pcpp
*/
uint16_t getDstPort() const;

/**
* @deprecated This method is deprecated, please use getTcpOption(TcpOptionEnumType option)
*/
PCPP_DEPRECATED_TCP_OPTION_TYPE
TcpOption getTcpOption(TcpOptionType option) const;

/**
* Get a TCP option by type
* @param[in] option TCP option type to retrieve
Expand Down Expand Up @@ -583,14 +451,6 @@ namespace pcpp
*/
TcpOption addTcpOption(const TcpOptionBuilder& optionBuilder);

/**
* @deprecated This method is deprecated, please use insertTcpOptionAfter(const TcpOptionBuilder& optionBuilder,
* TcpOptionEnumType prevOptionType = TcpOptionEnumType::Unknown)
*/
PCPP_DEPRECATED("Use insertTcpOptionAfter instead")
TcpOption addTcpOptionAfter(const TcpOptionBuilder& optionBuilder,
TcpOptionType prevOptionType = TcpOptionType::TCPOPT_Unknown);

/**
* Insert a new TCP option after an existing one
* @param[in] optionBuilder A TcpOptionBuilder object that contains the requested TCP option data to be inserted
Expand All @@ -604,12 +464,6 @@ namespace pcpp
TcpOption insertTcpOptionAfter(const TcpOptionBuilder& optionBuilder,
TcpOptionEnumType prevOptionType = TcpOptionEnumType::Unknown);

/**
* @deprecated This method is deprecated, please use removeTcpOption(TcpOptionEnumType)
*/
PCPP_DEPRECATED_TCP_OPTION_TYPE
bool removeTcpOption(TcpOptionType optionType);

/**
* Remove an existing TCP option from the layer. TCP option is found by type
* @param[in] optionType The TCP option type to remove
Expand Down Expand Up @@ -692,5 +546,3 @@ namespace pcpp
&& dataLen >= hdr->dataOffset * sizeof(uint32_t);
}
} // namespace pcpp

#undef PCPP_DEPRECATED_TCP_OPTION_TYPE
84 changes: 0 additions & 84 deletions Packet++/src/TcpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ namespace pcpp
/// TcpOptionBuilder
/// ~~~~~~~~~~~~~~~~

TcpOptionBuilder::TcpOptionBuilder(NopEolOptionTypes optionType)
{
switch (optionType)
{
case EOL:
init(static_cast<uint8_t>(PCPP_TCPOPT_EOL), nullptr, 0);
break;
case NOP:
default:
init(static_cast<uint8_t>(PCPP_TCPOPT_NOP), nullptr, 0);
break;
}
}

TcpOptionBuilder::TcpOptionBuilder(const NopEolOptionEnumType optionType)
{
switch (optionType)
Expand Down Expand Up @@ -459,74 +445,4 @@ namespace pcpp

return result;
}

/// ~~~~~~~~
/// TcpLayer Deprecated Code
/// ~~~~~~~~

DISABLE_WARNING_PUSH
DISABLE_WARNING_DEPRECATED
TcpOption TcpLayer::addTcpOptionAfter(const TcpOptionBuilder& optionBuilder, TcpOptionType prevOptionType)
{
int offset = 0;

if (prevOptionType == TcpOptionType::TCPOPT_Unknown)
{
offset = sizeof(tcphdr);
}
else
{
TcpOption prevOpt = getTcpOption(prevOptionType);
if (prevOpt.isNull())
{
PCPP_LOG_ERROR("Previous option of type " << static_cast<int>(prevOptionType)
<< " not found, cannot add a new TCP option");
return TcpOption(nullptr);
}

offset = prevOpt.getRecordBasePtr() + prevOpt.getTotalSize() - m_Data;
}

return addTcpOptionAt(optionBuilder, offset);
}

TcpOption TcpLayer::getTcpOption(TcpOptionType option) const
{
return m_OptionReader.getTLVRecord(static_cast<uint8_t>(option), getOptionsBasePtr(),
getHeaderLen() - sizeof(tcphdr));
}

bool TcpLayer::removeTcpOption(TcpOptionType optionType)
{
TcpOption opt = getTcpOption(optionType);
if (opt.isNull())
{
return false;
}

// calculate total TCP option size
TcpOption curOpt = getFirstTcpOption();
size_t totalOptSize = 0;
while (!curOpt.isNull())
{
totalOptSize += curOpt.getTotalSize();
curOpt = getNextTcpOption(curOpt);
}
totalOptSize -= opt.getTotalSize();

int offset = opt.getRecordBasePtr() - m_Data;

if (!shortenLayer(offset, opt.getTotalSize()))
{
return false;
}

adjustTcpOptionTrailer(totalOptSize);

m_OptionReader.changeTLVRecordCount(-1);

return true;
}
DISABLE_WARNING_POP

} // namespace pcpp
Loading
Loading