mirror of
https://github.com/daeuniverse/dae.git
synced 2025-02-02 04:14:31 +07:00
feat: support multiple lan and wan interfaces to bind
This commit is contained in:
parent
268a52a934
commit
0b85d99571
@ -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. ...
|
||||
|
15
cmd/run.go
15
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
11
example.dae
11
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
|
||||
}
|
||||
|
2
go.mod
2
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
|
||||
|
4
go.sum
4
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=
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user