Browse Source

feat: sniff options

v1.x.x
dnomd343 2 years ago
parent
commit
276ec004a0
  1. 1
      Dockerfile
  2. 27
      cmd/config/decode.go
  3. 8
      cmd/config/default.go
  4. 1
      cmd/config/main.go
  5. 7
      cmd/proxy/config.go
  6. 8
      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 ENV XRAY_LOCATION_ASSET=/xproxy/assets
RUN apk add --no-cache iptables ip6tables RUN apk add --no-cache iptables ip6tables
COPY --from=asset /asset/ / COPY --from=asset /asset/ /
WORKDIR /xproxy
CMD ["xproxy"] CMD ["xproxy"]

27
cmd/config/decode.go

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

8
cmd/config/default.go

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

1
cmd/config/main.go

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

7
cmd/proxy/config.go

@ -49,9 +49,10 @@ type inboundsObject struct {
} }
type sniffObject struct { type sniffObject struct {
Enabled bool `json:"enabled"` Enabled bool `json:"enabled"`
RouteOnly bool `json:"routeOnly"` RouteOnly bool `json:"routeOnly"`
DestOverride []string `json:"destOverride"` DestOverride []string `json:"destOverride"`
DomainsExcluded []string `json:"domainsExcluded"`
} }
type inboundObject struct { type inboundObject struct {

8
cmd/proxy/main.go

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

2
cmd/xproxy.go

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

Loading…
Cancel
Save