diff --git a/README.md b/README.md index fc68971..99a99f1 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,5 @@ See [example.dae](https://github.com/v2rayA/dae/blob/main/example.dae). 1. DisableL4Checksum by link. 1. Handle the case that nodes do not support UDP. 1. L4Checksum problem. -1. Config support list like: `wan_interface: [wlp5s0, eth0]`. 1. MACv2 extension extraction. 1. ... diff --git a/cmd/run.go b/cmd/run.go index 9adfcc2..d5595bd 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -11,6 +11,7 @@ import ( "github.com/v2rayA/dae/pkg/logger" "os" "os/signal" + "strings" "syscall" ) @@ -81,13 +82,19 @@ func Run() (err error) { // Bind to links. if param.Global.LanInterface != "" { - if err = t.BindLan(param.Global.LanInterface); err != nil { - return fmt.Errorf("BindLan: %v: %w", param.Global.LanInterface, err) + ifnames := strings.Split(param.Global.LanInterface, ",") + for _, ifname := range ifnames { + if err = t.BindLan(ifname); err != nil { + return fmt.Errorf("BindLan: %v: %w", ifname, err) + } } } if param.Global.WanInterface != "" { - if err = t.BindWan(param.Global.WanInterface); err != nil { - return fmt.Errorf("BindWan: %v: %w", param.Global.WanInterface, err) + ifnames := strings.Split(param.Global.WanInterface, ",") + for _, ifname := range ifnames { + if err = t.BindWan(ifname); err != nil { + return fmt.Errorf("BindWan: %v: %w", ifname, err) + } } } diff --git a/example.dae b/example.dae index 4642a25..49f2515 100644 --- a/example.dae +++ b/example.dae @@ -11,14 +11,13 @@ global { # The request to dns upstream follows routing defined below. dns_upstream: '1.1.1.1:53' - # The LAN interface to bind. - # Use it if you only want to proxy LAN instead of localhost. - # Now only support one interface. - # Require Linux kernel >= 5.2 + # The LAN interface to bind. Use it if you only want to proxy LAN instead of localhost. + # Multiple interfaces split by ",". + # Require Linux kernel >= 5.2. # lan_interface: docker0 - # The WAN interface to bind. - # Use it if you want to proxy localhost. + # The WAN interface to bind. Use it if you want to proxy localhost + # Multiple interfaces split by "," # Require Linux kernel >= 5.5 wan_interface: wlp5s0 } diff --git a/go.mod b/go.mod index ca5de67..a415c82 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/mzz2017/softwind v0.0.0-20230127172609-05c5264aa6a4 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.6.1 - github.com/v2rayA/dae-config-dist/go/dae_config v0.0.0-20230129030458-867b50f6cc67 + github.com/v2rayA/dae-config-dist/go/dae_config v0.0.0-20230201041341-1758ee5161c1 github.com/v2rayA/shadowsocksR v1.0.4 github.com/vishvananda/netlink v1.1.0 golang.org/x/net v0.5.0 diff --git a/go.sum b/go.sum index 9cd696e..47f9bda 100644 --- a/go.sum +++ b/go.sum @@ -76,8 +76,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/v2rayA/dae-config-dist/go/dae_config v0.0.0-20230129030458-867b50f6cc67 h1:BKYTwtvnzg/QQG5uQmWNHDu07KmkrfdpZ98pAOvZf0g= -github.com/v2rayA/dae-config-dist/go/dae_config v0.0.0-20230129030458-867b50f6cc67/go.mod h1:JiTWeZybOkBfCqv/fy5jbFhXTxuLlyrI76gRNazz2sU= +github.com/v2rayA/dae-config-dist/go/dae_config v0.0.0-20230201041341-1758ee5161c1 h1:Ke91ZtZItOO8/SK8nhZ1tXfXcUxj4Meq5pET/L9bHII= +github.com/v2rayA/dae-config-dist/go/dae_config v0.0.0-20230201041341-1758ee5161c1/go.mod h1:JiTWeZybOkBfCqv/fy5jbFhXTxuLlyrI76gRNazz2sU= github.com/v2rayA/shadowsocksR v1.0.4 h1:65Ltdy+I/DnlkQTJj+R+X85zhZ63ORE1Roy+agAcF/s= github.com/v2rayA/shadowsocksR v1.0.4/go.mod h1:CyOhDLy8/AKedsi16xRYAMmkxSCH1ukJPaacaTdRfQg= github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0= diff --git a/pkg/config_parser/walker.go b/pkg/config_parser/walker.go index dcdbc28..320a44c 100644 --- a/pkg/config_parser/walker.go +++ b/pkg/config_parser/walker.go @@ -11,6 +11,7 @@ import ( "github.com/sirupsen/logrus" "github.com/v2rayA/dae-config-dist/go/dae_config" "strconv" + "strings" ) type Walker struct { @@ -132,15 +133,29 @@ func (w *Walker) declarationFunctionVerifier(function *Function, ctx interface{} return true } +type literalExpressionParser struct { + literals []string +} + +func (p *literalExpressionParser) Parse(ctx *dae_config.LiteralExpressionContext) { + children := ctx.GetChildren() + p.literals = append(p.literals, getValueFromLiteral(children[0].(*dae_config.LiteralContext))) + if len(children) == 1 { + return + } + p.Parse(children[2].(*dae_config.LiteralExpressionContext)) +} + func (w *Walker) parseDeclaration(ctx dae_config.IDeclarationContext) *Param { children := ctx.GetChildren() key := children[0].(*antlr.TerminalNodeImpl).GetText() switch valueCtx := children[2].(type) { - case *dae_config.LiteralContext: - value := getValueFromLiteral(valueCtx) + case *dae_config.LiteralExpressionContext: + parser := literalExpressionParser{} + parser.Parse(valueCtx) return &Param{ Key: key, - Val: value, + Val: strings.Join(parser.literals, ","), // TODO: Do we just check grammar and trim spaces and put it back? } case *dae_config.FunctionPrototypeExpressionContext: andFunctions := w.parseFunctionPrototypeExpression(valueCtx, w.declarationFunctionVerifier)