OpenVPN 3 Core Library
Loading...
Searching...
No Matches
tcp.hpp
Go to the documentation of this file.
1
// OpenVPN -- An application to securely tunnel IP networks
2
// over a single port, with support for SSL/TLS-based
3
// session authentication and key exchange,
4
// packet encryption, packet authentication, and
5
// packet compression.
6
//
7
// Copyright (C) 2012- OpenVPN Inc.
8
//
9
// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10
//
11
12
#pragma once
13
14
#include <
openvpn/common/endian.hpp
>
15
#include <
openvpn/ip/ipcommon.hpp
>
16
17
namespace
openvpn
{
18
19
#pragma pack(push)
20
#pragma pack(1)
21
22
struct
TCPHeader
23
{
24
static
unsigned
int
length
(
const
std::uint8_t
doff_res
)
25
{
26
return
((
doff_res
) & 0xF0) >> 2;
27
}
28
29
std::uint16_t
source
;
30
std::uint16_t
dest
;
31
std::uint32_t
seq
;
32
std::uint32_t
ack_seq
;
33
std::uint8_t
doff_res
;
34
std::uint8_t
flags
;
35
std::uint16_t
window
;
36
std::uint16_t
check
;
37
std::uint16_t
urgent_p
;
38
39
// helper enum to parse options in TCP header
40
enum
41
{
42
OPT_EOL
= 0,
43
OPT_NOP
= 1,
44
OPT_MAXSEG
= 2,
45
OPTLEN_MAXSEG
= 4
46
};
47
48
enum
49
{
50
FLAG_SYN
= 1 << 1
51
};
52
};
53
54
#pragma pack(pop)
55
56
/*
57
* The following routine is used to update an
58
* internet checksum. "acc" is a 32-bit
59
* accumulation of all the changes to the
60
* checksum (adding in old 16-bit words and
61
* subtracting out new words), and "cksum"
62
* is the checksum value to be updated.
63
*/
64
inline
void
tcp_adjust_checksum
(
int
acc, std::uint16_t &cksum)
65
{
66
int
_acc = acc;
67
_acc += cksum;
68
if
(_acc < 0)
69
{
70
_acc = -_acc;
71
_acc = (_acc >> 16) + (_acc & 0xffff);
72
_acc += _acc >> 16;
73
cksum = (uint16_t)~_acc;
74
}
75
else
76
{
77
_acc = (_acc >> 16) + (_acc & 0xffff);
78
_acc += _acc >> 16;
79
cksum = (uint16_t)_acc;
80
}
81
}
82
}
// namespace openvpn
endian.hpp
ipcommon.hpp
openvpn
Support deferred server-side state creation when client connects.
Definition
ovpncli.cpp:95
openvpn::tcp_adjust_checksum
void tcp_adjust_checksum(int acc, std::uint16_t &cksum)
Definition
tcp.hpp:64
openvpn::TCPHeader
Definition
tcp.hpp:23
openvpn::TCPHeader::window
std::uint16_t window
Definition
tcp.hpp:35
openvpn::TCPHeader::dest
std::uint16_t dest
Definition
tcp.hpp:30
openvpn::TCPHeader::ack_seq
std::uint32_t ack_seq
Definition
tcp.hpp:32
openvpn::TCPHeader::source
std::uint16_t source
Definition
tcp.hpp:29
openvpn::TCPHeader::check
std::uint16_t check
Definition
tcp.hpp:36
openvpn::TCPHeader::length
static unsigned int length(const std::uint8_t doff_res)
Definition
tcp.hpp:24
openvpn::TCPHeader::urgent_p
std::uint16_t urgent_p
Definition
tcp.hpp:37
openvpn::TCPHeader::flags
std::uint8_t flags
Definition
tcp.hpp:34
openvpn::TCPHeader::seq
std::uint32_t seq
Definition
tcp.hpp:31
openvpn::TCPHeader::OPT_EOL
@ OPT_EOL
Definition
tcp.hpp:42
openvpn::TCPHeader::OPTLEN_MAXSEG
@ OPTLEN_MAXSEG
Definition
tcp.hpp:45
openvpn::TCPHeader::OPT_MAXSEG
@ OPT_MAXSEG
Definition
tcp.hpp:44
openvpn::TCPHeader::OPT_NOP
@ OPT_NOP
Definition
tcp.hpp:43
openvpn::TCPHeader::FLAG_SYN
@ FLAG_SYN
Definition
tcp.hpp:50
openvpn::TCPHeader::doff_res
std::uint8_t doff_res
Definition
tcp.hpp:33
openvpn
ip
tcp.hpp
Generated by
1.9.8