add router handler & connector

This commit is contained in:
ginuerzh
2025-02-07 15:44:31 +08:00
parent 379d9a73ad
commit 355c72477a
25 changed files with 1265 additions and 110 deletions
+1
View File
@@ -93,6 +93,7 @@ func (l *quicListener) Init(md md.Metadata) (err error) {
quic.Version2,
},
MaxIncomingStreams: int64(l.md.maxStreams),
EnableDatagrams: l.md.enableDatagram,
}
tlsCfg := l.options.TLSConfig
+2
View File
@@ -17,6 +17,7 @@ type metadata struct {
handshakeTimeout time.Duration
maxIdleTimeout time.Duration
maxStreams int
enableDatagram bool
cipherKey []byte
backlog int
@@ -52,6 +53,7 @@ func (l *quicListener) parseMetadata(md mdata.Metadata) (err error) {
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
l.md.maxStreams = mdutil.GetInt(md, maxStreams)
l.md.enableDatagram = mdutil.GetBool(md, "quic.enableDatagram", "enableDatagram")
return
}
+13 -11
View File
@@ -67,34 +67,36 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
}
for _, s := range strings.Split(mdutil.GetString(md, route), ",") {
_, ipNet, _ := net.ParseCIDR(strings.TrimSpace(s))
if ipNet == nil {
continue
gw := ""
if config.Gateway != nil {
gw = config.Gateway.String()
}
if route := xrouter.ParseRoute(strings.TrimSpace(s), gw); route != nil {
l.routes = append(l.routes, route)
}
l.routes = append(l.routes, &router.Route{
Net: ipNet,
Gateway: config.Gateway,
})
}
for _, s := range mdutil.GetStrings(md, routes) {
ss := strings.SplitN(s, " ", 2)
if len(ss) == 2 {
var route router.Route
_, ipNet, _ := net.ParseCIDR(strings.TrimSpace(ss[0]))
if ipNet == nil {
continue
}
route.Net = ipNet
gw := net.ParseIP(ss[1])
if gw == nil {
gw = config.Gateway
}
gateway := ""
if gw != nil {
gateway = gw.String()
}
l.routes = append(l.routes, &router.Route{
Net: ipNet,
Gateway: gw,
Dst: ipNet.String(),
Gateway: gateway,
})
}
}
+9 -1
View File
@@ -49,9 +49,17 @@ func (l *tunListener) createTun() (dev io.ReadWriteCloser, name string, ip net.I
func (l *tunListener) addRoutes(ifce *net.Interface) error {
for _, route := range l.routes {
if route.Net == nil {
continue
}
gw := net.ParseIP(route.Gateway)
if gw == nil {
continue
}
r := netlink.Route{
Dst: route.Net,
Gw: route.Gateway,
Gw: gw,
}
if r.Gw == nil {
r.LinkIndex = ifce.Index