49 typedef std::uint32_t
id_t;
56 static constexpr size_t size()
74 template <
typename BufType>
80 buf.read((
unsigned char *)&net_id,
sizeof(net_id));
83 buf.read((
unsigned char *)&net_time,
sizeof(net_time));
84 time = ntohl(net_time);
89 const id_t net_id = htonl(
id);
90 const net_time_t net_time = htonl(
static_cast<uint32_t
>(
time & 0x00000000FFFFFFFF));
96 buf.
prepend((
unsigned char *)&net_time,
sizeof(net_time));
97 buf.
prepend((
unsigned char *)&net_id,
sizeof(net_id));
101 buf.
write((
unsigned char *)&net_id,
sizeof(net_id));
102 buf.
write((
unsigned char *)&net_time,
sizeof(net_time));
108 std::ostringstream os;
109 os << std::hex <<
"[0x" <<
time <<
", 0x" <<
id <<
"]";
153 pid.
write(buf, prepend);
176template <
unsigned int REPLAY_WINDOW_ORDER,
177 unsigned int PKTID_RECV_EXPIRE>
191 void init(
const char *name_arg,
234 throw packet_id_not_initialized();
239 expire = now + PKTID_RECV_EXPIRE;
282 const unsigned int delta = pin.
id -
id_high;
290 for (
unsigned i = 1; i < delta; ++i)
293 history[newbase / 8] &=
static_cast<uint8_t
>(~(1 << (newbase % 8)));
308 const unsigned int delta =
id_high - pin.
id;
316 std::uint8_t *p = &
history[ri / 8];
317 const std::uint8_t mask =
static_cast<uint8_t
>(1 << (ri % 8));
337 throw packet_id_not_initialized();
345 std::ostringstream os;
void prepend(const T *data, const size_t size)
Prepend data to the buffer.
void write(const T *data, const size_t size)
Write data to the buffer.
static constexpr unsigned int REPLAY_WINDOW_BYTES
std::uint8_t history[REPLAY_WINDOW_BYTES]
Error::Type do_test_add(const PacketIDControl &pin, const PacketIDControl::time_t now, const bool mod)
unsigned int max_backtrack
PacketIDControl::id_t id_floor
void init(const char *name_arg, const int unit_arg, const SessionStats::Ptr &stats_arg)
static constexpr unsigned int REPLAY_WINDOW_SIZE
PacketIDControl read_next(Buffer &buf) const
bool test_add(const PacketIDControl &pin, const PacketIDControl::time_t now, const bool mod)
PacketIDControl::id_t id_high
PacketIDControl::time_t expire
OPENVPN_SIMPLE_EXCEPTION(packet_id_not_initialized)
unsigned int REPLAY_INDEX(const int i) const
PacketIDControlReceiveType()
PacketIDControl::time_t time_high
void init(PacketIDControl::id_t start_at=0)
OPENVPN_SIMPLE_EXCEPTION(packet_id_wrap)
void write_next(Buffer &buf, const bool prepend, const PacketIDControl::time_t now)
PacketIDControl next(const PacketIDControl::time_t now)
PacketIDControlSend(PacketIDControl::id_t start_at=PacketIDControl::id_t(0))
virtual void error(const size_t type, const std::string *text=nullptr)
Support deferred server-side state creation when client connects.
PacketIDControlReceiveType< 8, 30 > PacketIDControlReceive
static constexpr size_t size()
static constexpr size_t idsize
void write(Buffer &buf, const bool prepend) const