2023-01-23 18:54:21 +07:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2024-01-04 16:28:16 +07:00
|
|
|
* Copyright (c) 2022-2024, daeuniverse Organization <dae@v2raya.org>
|
2023-01-23 18:54:21 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
package consts
|
|
|
|
|
2023-02-11 20:34:49 +07:00
|
|
|
import (
|
|
|
|
"strconv"
|
2023-02-15 00:53:53 +07:00
|
|
|
"strings"
|
2023-04-23 12:27:29 +07:00
|
|
|
|
|
|
|
internal "github.com/daeuniverse/dae/pkg/ebpf_internal"
|
2023-02-11 20:34:49 +07:00
|
|
|
)
|
2023-02-01 00:34:50 +07:00
|
|
|
|
2023-01-23 18:54:21 +07:00
|
|
|
const (
|
2023-01-29 06:31:52 +07:00
|
|
|
BpfPinRoot = "/sys/fs/bpf"
|
2023-01-23 18:54:21 +07:00
|
|
|
|
2023-01-31 18:33:53 +07:00
|
|
|
TaskCommLen = 16
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
type ParamKey uint32
|
|
|
|
|
|
|
|
const (
|
2023-01-24 16:15:27 +07:00
|
|
|
ZeroKey ParamKey = iota
|
2023-01-23 18:54:21 +07:00
|
|
|
BigEndianTproxyPortKey
|
|
|
|
DisableL4TxChecksumKey
|
|
|
|
DisableL4RxChecksumKey
|
2023-02-11 12:34:12 +07:00
|
|
|
ControlPlanePidKey
|
|
|
|
ControlPlaneNatDirectKey
|
2023-02-25 01:38:21 +07:00
|
|
|
ControlPlaneDnsRoutingKey
|
2023-02-07 12:49:47 +07:00
|
|
|
|
|
|
|
OneKey ParamKey = 1
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
type DisableL4ChecksumPolicy uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
DisableL4ChecksumPolicy_EnableL4Checksum DisableL4ChecksumPolicy = iota
|
|
|
|
DisableL4ChecksumPolicy_Restore
|
|
|
|
DisableL4ChecksumPolicy_SetZero
|
|
|
|
)
|
|
|
|
|
2023-02-18 17:27:28 +07:00
|
|
|
type MatchType uint8
|
2023-01-23 18:54:21 +07:00
|
|
|
|
|
|
|
const (
|
2023-02-18 17:27:28 +07:00
|
|
|
MatchType_DomainSet MatchType = iota
|
2023-01-31 18:33:53 +07:00
|
|
|
MatchType_IpSet
|
|
|
|
MatchType_SourceIpSet
|
|
|
|
MatchType_Port
|
|
|
|
MatchType_SourcePort
|
|
|
|
MatchType_L4Proto
|
|
|
|
MatchType_IpVersion
|
|
|
|
MatchType_Mac
|
|
|
|
MatchType_ProcessName
|
2023-08-20 22:43:33 +07:00
|
|
|
MatchType_Dscp
|
2023-02-18 02:01:51 +07:00
|
|
|
MatchType_Fallback
|
2023-04-02 11:02:57 +07:00
|
|
|
MatchType_MustRules
|
2023-02-25 01:38:21 +07:00
|
|
|
|
|
|
|
MatchType_Upstream
|
|
|
|
MatchType_QType
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
type OutboundIndex uint8
|
|
|
|
|
|
|
|
const (
|
2023-02-25 01:38:21 +07:00
|
|
|
OutboundDirect OutboundIndex = iota
|
|
|
|
OutboundBlock
|
|
|
|
|
2023-07-15 11:23:36 +07:00
|
|
|
OutboundUserDefinedMin
|
|
|
|
|
2023-04-02 11:02:57 +07:00
|
|
|
OutboundMustRules OutboundIndex = 0xFC
|
2023-02-25 01:38:21 +07:00
|
|
|
OutboundControlPlaneRouting OutboundIndex = 0xFD
|
|
|
|
OutboundLogicalOr OutboundIndex = 0xFE
|
|
|
|
OutboundLogicalAnd OutboundIndex = 0xFF
|
|
|
|
OutboundLogicalMask OutboundIndex = 0xFE
|
2023-02-06 12:56:43 +07:00
|
|
|
|
2023-04-02 11:02:57 +07:00
|
|
|
OutboundUserDefinedMax = OutboundMustRules - 1
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
func (i OutboundIndex) String() string {
|
|
|
|
switch i {
|
2023-04-02 11:02:57 +07:00
|
|
|
case OutboundMustRules:
|
|
|
|
return "must_rules"
|
2023-01-23 18:54:21 +07:00
|
|
|
case OutboundDirect:
|
|
|
|
return "direct"
|
2023-01-27 01:10:27 +07:00
|
|
|
case OutboundBlock:
|
|
|
|
return "block"
|
2023-02-25 01:38:21 +07:00
|
|
|
case OutboundControlPlaneRouting:
|
|
|
|
return "<Control Plane Routing>"
|
2023-01-29 06:31:52 +07:00
|
|
|
case OutboundLogicalOr:
|
|
|
|
return "<OR>"
|
2023-01-23 18:54:21 +07:00
|
|
|
case OutboundLogicalAnd:
|
|
|
|
return "<AND>"
|
|
|
|
default:
|
2023-02-15 00:53:53 +07:00
|
|
|
return "<index: " + strconv.Itoa(int(i)) + ">"
|
2023-01-23 18:54:21 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-15 00:53:53 +07:00
|
|
|
func (i OutboundIndex) IsReserved() bool {
|
|
|
|
return !strings.HasPrefix(i.String(), "<index: ")
|
|
|
|
}
|
|
|
|
|
2023-03-14 12:54:43 +07:00
|
|
|
var (
|
|
|
|
MaxMatchSetLen_ = ""
|
2024-10-30 00:06:13 +07:00
|
|
|
MaxMatchSetLen = 32 * 32
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
|
|
|
|
2023-03-14 12:54:43 +07:00
|
|
|
func init() {
|
|
|
|
if MaxMatchSetLen_ != "" {
|
|
|
|
i, err := strconv.Atoi(MaxMatchSetLen_)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
MaxMatchSetLen = i
|
|
|
|
}
|
|
|
|
if MaxMatchSetLen%32 != 0 {
|
|
|
|
panic("MaxMatchSetLen should be a multiple of 32: " + strconv.Itoa(MaxMatchSetLen))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-24 23:31:20 +07:00
|
|
|
type L4ProtoType uint8
|
2023-01-23 18:54:21 +07:00
|
|
|
|
|
|
|
const (
|
2023-01-24 23:31:20 +07:00
|
|
|
L4ProtoType_TCP L4ProtoType = 1
|
|
|
|
L4ProtoType_UDP L4ProtoType = 2
|
|
|
|
L4ProtoType_TCP_UDP L4ProtoType = 3
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
|
|
|
|
2023-02-02 20:22:18 +07:00
|
|
|
type IpVersionType uint8
|
2023-01-23 18:54:21 +07:00
|
|
|
|
|
|
|
const (
|
2023-02-02 20:22:18 +07:00
|
|
|
IpVersion_4 IpVersionType = 1
|
|
|
|
IpVersion_6 IpVersionType = 2
|
|
|
|
IpVersion_X IpVersionType = 3
|
2023-01-23 18:54:21 +07:00
|
|
|
)
|
2023-02-01 00:34:50 +07:00
|
|
|
|
2023-06-29 21:30:33 +07:00
|
|
|
func (v IpVersionType) ToIpVersionStr() IpVersionStr {
|
|
|
|
switch v {
|
|
|
|
case IpVersion_4:
|
|
|
|
return IpVersionStr_4
|
|
|
|
case IpVersion_6:
|
|
|
|
return IpVersionStr_6
|
|
|
|
}
|
|
|
|
panic("unsupported ipversion")
|
|
|
|
}
|
|
|
|
|
2023-02-04 10:38:01 +07:00
|
|
|
var (
|
|
|
|
BasicFeatureVersion = internal.Version{5, 2, 0}
|
|
|
|
// Deprecated: Ftrace does not support arm64 yet (Linux 6.2).
|
2023-02-04 12:37:36 +07:00
|
|
|
FtraceFeatureVersion = internal.Version{5, 5, 0}
|
|
|
|
UserspaceBatchUpdateFeatureVersion = internal.Version{5, 6, 0}
|
|
|
|
CgSocketCookieFeatureVersion = internal.Version{5, 7, 0}
|
2023-02-06 12:56:43 +07:00
|
|
|
SkAssignFeatureVersion = internal.Version{5, 7, 0}
|
2023-02-04 12:37:36 +07:00
|
|
|
ChecksumFeatureVersion = internal.Version{5, 8, 0}
|
2023-04-02 16:43:50 +07:00
|
|
|
ProgTypeSkLookupFeatureVersion = internal.Version{5, 9, 0}
|
2024-03-31 12:03:20 +07:00
|
|
|
SockmapFeatureVersion = internal.Version{5, 10, 0}
|
2023-02-04 12:37:36 +07:00
|
|
|
UserspaceBatchUpdateLpmTrieFeatureVersion = internal.Version{5, 13, 0}
|
2024-04-08 21:23:55 +07:00
|
|
|
BpfTimerFeatureVersion = internal.Version{5, 15, 0}
|
2024-03-30 13:34:15 +07:00
|
|
|
HelperBpfGetFuncIpVersionFeatureVersion = internal.Version{5, 15, 0}
|
2024-10-30 00:06:13 +07:00
|
|
|
BpfLoopFeatureVersion = internal.Version{5, 17, 0}
|
2023-02-04 10:38:01 +07:00
|
|
|
)
|
2023-02-06 12:56:43 +07:00
|
|
|
|
|
|
|
const (
|
2024-01-11 19:25:29 +07:00
|
|
|
TproxyMark uint32 = 0x08000000
|
|
|
|
TproxyMarkString string = "0x08000000" // Should be aligned with nftables
|
|
|
|
Recognize uint16 = 0x2017
|
|
|
|
LoopbackIfIndex = 1
|
2023-02-06 12:56:43 +07:00
|
|
|
)
|
2023-02-12 20:50:15 +07:00
|
|
|
|
2023-02-13 11:54:04 +07:00
|
|
|
type LanWanFlag uint8
|
|
|
|
|
2023-07-16 17:26:20 +07:00
|
|
|
const (
|
2023-09-02 14:06:50 +07:00
|
|
|
LinkHdrLen_None uint32 = 0
|
|
|
|
LinkHdrLen_Ethernet uint32 = 14
|
2023-07-16 17:26:20 +07:00
|
|
|
)
|