0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-19 19:52:15 +02:00
openvpn3/openvpn/reliable/relcommon.hpp
Arne Schwabe c78aaecad7 Differentiate Packet ID types into data channel and control channel ids
Data channel packet ids (in the formats that OpenVPN 3.x supports)
are plain 32 or 64 bit ids while control channel is a 32 bit time + 32
bit counter id. Seperate these more clearly and let CBC mode use the
same Packet ID implementation that AEAD mode uses.

Also add more unit tests related to data channel tests packets by
adapting the control channel test where applicable and add a few more
related to packet id wrapping

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2024-09-11 13:23:31 +00:00

78 lines
1.8 KiB
C++

// OpenVPN -- An application to securely tunnel IP networks
// over a single port, with support for SSL/TLS-based
// session authentication and key exchange,
// packet encryption, packet authentication, and
// packet compression.
//
// Copyright (C) 2012-2022 OpenVPN Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License Version 3
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program in the COPYING file.
// If not, see <http://www.gnu.org/licenses/>.
// Common reliability layer classes
#ifndef OPENVPN_RELIABLE_RELCOMMON_H
#define OPENVPN_RELIABLE_RELCOMMON_H
#include <openvpn/crypto/packet_id_control.hpp>
namespace openvpn {
namespace reliable {
typedef std::uint32_t id_t;
constexpr static std::size_t id_size = sizeof(id_t);
} // namespace reliable
template <typename PACKET>
class ReliableMessageBase
{
public:
typedef reliable::id_t id_t;
ReliableMessageBase()
: id_(0), erased_(false)
{
}
bool defined() const
{
return bool(packet);
}
bool erased() const
{
return erased_;
}
void erase()
{
id_ = id_t(0);
packet.reset();
erased_ = true;
}
id_t id() const
{
return id_;
}
PACKET packet;
protected:
id_t id_;
bool erased_;
};
} // namespace openvpn
#endif // OPENVPN_RELIABLE_RELCOMMON_H