feat: add config_parser

This commit is contained in:
mzz2017
2023-01-27 02:10:27 +08:00
parent 916a55d480
commit edbce81e88
53 changed files with 6696 additions and 733 deletions

View File

@ -20,8 +20,6 @@ const (
BigEndianTproxyPortKey
DisableL4TxChecksumKey
DisableL4RxChecksumKey
EpochKey
RoutingsLenKey
)
type DisableL4ChecksumPolicy uint32
@ -50,6 +48,7 @@ type OutboundIndex uint8
const (
OutboundDirect OutboundIndex = 0
OutboundBlock OutboundIndex = 1
OutboundControlPlaneDirect OutboundIndex = 0xFE
OutboundLogicalAnd OutboundIndex = 0xFF
)
@ -58,6 +57,8 @@ func (i OutboundIndex) String() string {
switch i {
case OutboundDirect:
return "direct"
case OutboundBlock:
return "block"
case OutboundControlPlaneDirect:
return "<Control Plane Direct>"
case OutboundLogicalAnd:

View File

@ -19,4 +19,6 @@ const (
Function_Mac = "mac"
Function_L4Proto = "l4proto"
Function_IpVersion = "ipversion"
Declaration_Final = "final"
)

28
common/debug.go Normal file
View File

@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2023, mzz2017 (mzz@tuta.io). All rights reserved.
*/
package common
import (
"github.com/sirupsen/logrus"
"os"
"path/filepath"
"strconv"
"strings"
)
func ReportMemory(tag string) {
if !logrus.IsLevelEnabled(logrus.DebugLevel) {
return
}
b, err := os.ReadFile(filepath.Join("/proc", strconv.Itoa(os.Getpid()), "status"))
if err != nil {
panic(err)
}
str := strings.TrimSpace(string(b))
_, after, _ := strings.Cut(str, "VmHWM:")
usage, _, _ := strings.Cut(after, "\n")
logrus.Debugln(tag+": memory usage:", strings.TrimSpace(usage))
}