1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef CLAT_CONSTANTS_H
16#define CLAT_CONSTANTS_H
17
18#include <string>
19
20namespace OHOS {
21namespace NetManagerStandard {
22enum Nat464UpdateFlag {
23    NAT464_SERVICE_CONTINUE,
24    NAT464_SERVICE_STOP,
25};
26
27enum Nat464ServiceState {
28    NAT464_SERVICE_STATE_IDLE,
29    NAT464_SERVICE_STATE_DISCOVERING,
30    NAT464_SERVICE_STATE_RUNNING,
31};
32
33enum ClatdConvertType {
34    CONVERT_FROM_V6_TO_V4,
35    CONVERT_FROM_V4_TO_V6,
36};
37
38enum ClatdPacketPosition {
39    CLATD_TUNHDR,
40    CLATD_IPHDR,
41    CLATD_FRAGHDR,
42    CLATD_TPHDR,
43    CLATD_ICMP_IPHDR,
44    CLATD_ICMP_FRAGHDR,
45    CLATD_ICMP_TPHDR,
46    CLATD_PAYLOAD,
47    CLATD_MAX
48};
49
50static constexpr size_t IP_TP_PACKET_POSITION_DELTA = 2; // packet position delta between CLATD_IPHDR and CLATD_TPHDR
51
52static constexpr size_t TCP_HDR_MIN_LEN = 20;
53static constexpr size_t TCP_HDR_MAX_LEN = 60;
54static constexpr int IPV4_HDR_MIN_LEN = 20;
55static constexpr int IPV6_HDR_LEN = 40;
56static constexpr int FRAG_HDR_LEN = 8;
57static constexpr int MTU_DELTA = IPV6_HDR_LEN - IPV4_HDR_MIN_LEN + FRAG_HDR_LEN;
58static constexpr int CLAT_MAX_MTU = 65536 + MTU_DELTA;
59static constexpr int CLAT_DATA_LINK_HDR_LEN = 22; // 14 bytes ethernet header + at most 8 bytes VLAN Tag
60
61static constexpr int CLAT_IPV6_MIN_MTU = 1280;
62static constexpr uint16_t TP_CSUM_UNNECESSARY = 1;
63
64static constexpr const char *CLAT_PREFIX = "tunv4-";
65static constexpr int CLAT_PREFIX_BYTE_LEN = 12;
66static constexpr int CLAT_SUFFIX_OFFSET_IN_32 = 3; // 96-bit prefix + 32-bit suffix, the suffix is the 4th 32-bit word
67
68static constexpr int WORD_32BIT_IN_BYTE_UNIT = 4; // 4-bytes unit for tcphdr->doff and iphdr->ihl
69
70static constexpr uint8_t IPV6_VERSION_FLAG = 0x60;
71static constexpr int V4ADDR_BIT_LEN = 32;
72static constexpr int V6ADDR_BIT_LEN = 128;
73static constexpr const char *INIT_V4ADDR_STRING = "192.0.0.0"; // Reserved ip addr in RFC 5736
74static constexpr int INIT_V4ADDR_PREFIX_BIT_LEN = 29;
75
76static constexpr size_t CLAT_V6ADDR_RANDOMIZE_OFFSET = 8;
77static constexpr size_t CLAT_V6ADDR_RANDOMIZE_BIT_LENGTH = 8;
78static constexpr size_t CLAT_V6ADDR_NEUTRALIZE_OFFSET = 3;
79
80static constexpr uint16_t WKN_DNS_PORT = 53;
81static constexpr const char *DEFAULT_V4_ADDR = "0.0.0.0/0";
82
83static constexpr const char *SOLICITED_NODE_PREFIX = "ff02::1:ff00:0000"; // Solicited-Node Address in RFC 4291
84static constexpr size_t SOLICITED_NODE_SUFFIX_OFFSET = 13;
85
86static constexpr uint16_t IPV6_FRAG_OFFSET_BIT_SUPPLEMENTARY = 3; // offset field in ipv6 fragment header is top 13 bit
87
88static constexpr int INVALID_IFINDEX = 0;
89
90static constexpr const char *IFACE_LINK_UP = "up";
91
92static constexpr size_t IPV6_SRC_OFFSET = 8;
93static constexpr uint8_t NDP_NOUNCE_OPT = 14;
94
95static constexpr const char *IPV4_ONLY_HOST = "ipv4only.arpa.";
96
97static constexpr uint32_t INITIAL_DISCOVERY_CYCLE_MS = 100;
98
99static constexpr uint32_t MAX_DISCOVERY_CYCLE_MS = 100000;
100
101static constexpr uint32_t DISCOVERY_CYCLE_MULTIPLIER = 2;
102
103static constexpr uint32_t CLATD_TIMER_CYCLE_MS = 5000;
104
105} // namespace NetManagerStandard
106} // namespace OHOS
107#endif