forked from OpenVPN/ovpn-dco-win
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto.h
67 lines (55 loc) · 1.92 KB
/
proto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* ovpn-dco-win OpenVPN protocol accelerator for Windows
*
* Copyright (C) 2020-2021 OpenVPN Inc <[email protected]>
*
* Author: Lev Stipakov <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
enum {
// packet opcode (high 5 bits) and key-id (low 3 bits) are combined in one byte
OVPN_KEY_ID_MASK = 0x07,
OVPN_OPCODE_SHIFT = 3,
OVPN_OPCODE_MASK = 0x1F,
// packet opcodes of interest to us
OVPN_DATA_V2 = 9, /* data channel V2 packet */
/* size of initial packet opcode */
OVPN_OP_SIZE_V2 = 4
};
static inline unsigned int OvpnProtoOpCompose(const unsigned int opcode, const unsigned int keyId)
{
return (opcode << OVPN_OPCODE_SHIFT) | keyId;
}
static inline unsigned int OvpnProtoOp32Compose(const unsigned int opcode, const unsigned int keyId, const int opPeerId)
{
const unsigned int op8 = OvpnProtoOpCompose(opcode, keyId);
if (opcode == OVPN_DATA_V2)
return (op8 << 24) | (opPeerId & 0x00FFFFFF);
return op8;
}
static inline unsigned int OvpnProtoOpcodeExtract(const unsigned int op)
{
return op >> OVPN_OPCODE_SHIFT;
}
static inline unsigned int OvpnProtoKeyIdExtract(unsigned int op)
{
return op & OVPN_KEY_ID_MASK;
}
static inline bool OvpnProtoOpcodeIsDataV2(const unsigned int op)
{
const unsigned int opcode = OvpnProtoOpcodeExtract(op);
return opcode == OVPN_DATA_V2;
}