Browse Source

feat: sniff options

v1.x.x
dnomd343 2 years ago
parent
commit
276ec004a0
  1. 1
      Dockerfile
  2. 19
      cmd/config/decode.go
  3. 8
      cmd/config/default.go
  4. 1
      cmd/config/main.go
  5. 1
      cmd/proxy/config.go
  6. 4
      cmd/proxy/main.go
  7. 2
      cmd/xproxy.go

1
Dockerfile

@ -45,4 +45,5 @@ FROM alpine:3.16
ENV XRAY_LOCATION_ASSET=/xproxy/assets
RUN apk add --no-cache iptables ip6tables
COPY --from=asset /asset/ /
WORKDIR /xproxy
CMD ["xproxy"]

19
cmd/config/decode.go

@ -12,15 +12,18 @@ type yamlNetConfig struct {
}
type yamlConfig struct {
Log string `yaml:"log"`
Custom []string `yaml:"custom"`
Update struct {
Cron string `yaml:"cron"`
Url map[string]string `yaml:"url"`
} `yaml:"update"`
Proxy struct {
Sniff bool `yaml:"sniff"`
Log string `yaml:"log"`
Sniff struct {
Enable bool `yaml:"enable"`
Redirect bool `yaml:"redirect"`
Exclude []string `yaml:"exclude"`
} `yaml:"sniff"`
Http map[string]int `yaml:"http"`
Socks map[string]int `yaml:"socks"`
AddOn []interface{} `yaml:"addon"`
@ -99,10 +102,12 @@ func decodeIPv6(rawConfig *yamlConfig) (string, string) {
}
func decodeProxy(rawConfig *yamlConfig, config *Config) {
config.EnableSniff = rawConfig.Proxy.Sniff
log.Debugf("Connection sniff -> %v", config.EnableSniff)
config.EnableRedirect = rawConfig.Proxy.Redirect
log.Debugf("Connection redirect -> %v", config.EnableRedirect)
config.EnableSniff = rawConfig.Proxy.Sniff.Enable
log.Debugf("Connection sniff -> %t", config.EnableSniff)
config.EnableRedirect = rawConfig.Proxy.Sniff.Redirect
log.Debugf("Connection redirect -> %t", config.EnableRedirect)
config.SniffExclude = rawConfig.Proxy.Sniff.Exclude
log.Debugf("Connection sniff exlcude -> %v", config.SniffExclude)
config.HttpInbounds = rawConfig.Proxy.Http
log.Debugf("Http inbounds -> %v", config.HttpInbounds)
config.SocksInbounds = rawConfig.Proxy.Socks
@ -127,7 +132,7 @@ func decodeCustom(rawConfig *yamlConfig) []string {
func decode(rawConfig yamlConfig) Config {
var config Config
config.LogLevel = rawConfig.Log
config.LogLevel = rawConfig.Proxy.Log
config.DNS = decodeDns(&rawConfig)
config.V4Bypass, config.V6Bypass = decodeBypass(&rawConfig)
config.V4Address, config.V4Gateway = decodeIPv4(&rawConfig)

8
cmd/config/default.go

@ -1,16 +1,10 @@
package config
var defaultConfig = `# default configure file for xproxy
log: debug
proxy:
sniff: true
redirect: true
log: warning
network:
dns: null
ipv4: null
ipv6: null
bypass:
- 169.254.0.0/16
- 224.0.0.0/3

1
cmd/config/main.go

@ -22,6 +22,7 @@ type Config struct {
EnableSniff bool
EnableRedirect bool
SniffExclude []string
HttpInbounds map[string]int
SocksInbounds map[string]int
AddOnInbounds []interface{}

1
cmd/proxy/config.go

@ -52,6 +52,7 @@ type sniffObject struct {
Enabled bool `json:"enabled"`
RouteOnly bool `json:"routeOnly"`
DestOverride []string `json:"destOverride"`
DomainsExcluded []string `json:"domainsExcluded"`
}
type inboundObject struct {

4
cmd/proxy/main.go

@ -10,6 +10,7 @@ type Config struct {
V4TProxyPort int
V6TProxyPort int
LogLevel string
SniffExclude []string
HttpInbounds map[string]int
SocksInbounds map[string]int
AddOnInbounds []interface{}
@ -24,7 +25,8 @@ func loadInbounds(config Config) string {
sniff := sniffObject{
Enabled: config.Sniff,
RouteOnly: !config.Redirect,
DestOverride: []string{"http", "tls"},
DestOverride: []string{"http", "tls", "quic"},
DomainsExcluded: config.SniffExclude,
}
var inbounds []interface{}
inbounds = append(inbounds, loadTProxyConfig("tproxy", config.V4TProxyPort, sniff))

2
cmd/xproxy.go

@ -41,7 +41,7 @@ func blockWait() {
func main() {
defer func() {
if err := recover(); err != nil {
log.Errorf("Unknown error -> %v", err)
log.Errorf("Panic exit -> %v", err)
}
}()

Loading…
Cancel
Save