2023-01-23 18:54:21 +07:00
|
|
|
//go:build linux
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
* Copyright (c) since 2022, mzz2017 (mzz@tuta.io). All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-01-24 13:25:21 +07:00
|
|
|
"github.com/sirupsen/logrus"
|
2023-01-23 19:01:24 +07:00
|
|
|
"github.com/v2rayA/dae/component/control"
|
|
|
|
"github.com/v2rayA/dae/pkg/logger"
|
2023-01-23 18:54:21 +07:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
const (
|
|
|
|
tproxyPort = 12345
|
|
|
|
ifname = "docker0"
|
|
|
|
)
|
2023-01-24 13:25:21 +07:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2023-01-23 18:54:21 +07:00
|
|
|
log := logger.NewLogger(2)
|
|
|
|
log.Println("Running")
|
|
|
|
t, err := control.NewControlPlane(log, `
|
|
|
|
default:proxy
|
2023-01-24 23:31:20 +07:00
|
|
|
#sip(172.17.0.2)->proxy
|
|
|
|
#mac("02:42:ac:11:00:02")->proxy
|
|
|
|
#ipversion(4)->proxy
|
|
|
|
#l4proto(tcp)->proxy
|
2023-01-24 15:27:19 +07:00
|
|
|
ip(119.29.29.29) -> proxy
|
|
|
|
ip(223.5.5.5) -> direct
|
2023-01-23 18:54:21 +07:00
|
|
|
ip(geoip:cn) -> direct
|
2023-01-24 23:31:20 +07:00
|
|
|
domain(geosite:cn, suffix:"ip.sb") -> direct
|
2023-01-23 18:54:21 +07:00
|
|
|
ip("91.105.192.0/23","91.108.4.0/22","91.108.8.0/21","91.108.16.0/21","91.108.56.0/22","95.161.64.0/20","149.154.160.0/20","185.76.151.0/24")->proxy
|
2023-01-24 13:25:21 +07:00
|
|
|
domain(geosite:category-scholar-!cn, geosite:category-scholar-cn)->direct
|
2023-01-23 18:54:21 +07:00
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err = t.BindLink(ifname); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGILL)
|
|
|
|
go func() {
|
|
|
|
if err := t.ListenAndServe(tproxyPort); err != nil {
|
|
|
|
log.Errorln("ListenAndServe:", err)
|
|
|
|
sigs <- nil
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
<-sigs
|
|
|
|
if e := t.Close(); e != nil {
|
|
|
|
log.Errorln("Close control plane:", err)
|
|
|
|
}
|
|
|
|
}
|