mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-08 05:19:53 +00:00
chore(tun): enable ForwarderBindInterface
This commit is contained in:
parent
38d9248acd
commit
92ed8f5e6a
@ -7,6 +7,8 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing/common/control"
|
||||||
|
|
||||||
"github.com/apernet/hysteria/core/client"
|
"github.com/apernet/hysteria/core/client"
|
||||||
tun "github.com/apernet/sing-tun"
|
tun "github.com/apernet/sing-tun"
|
||||||
"github.com/sagernet/sing/common/buf"
|
"github.com/sagernet/sing/common/buf"
|
||||||
@ -66,6 +68,8 @@ func (s *Server) Serve() error {
|
|||||||
tag: "tun-stack",
|
tag: "tun-stack",
|
||||||
zapLogger: s.Logger,
|
zapLogger: s.Logger,
|
||||||
},
|
},
|
||||||
|
ForwarderBindInterface: true,
|
||||||
|
InterfaceFinder: &interfaceFinder{},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create tun stack: %w", err)
|
return fmt.Errorf("failed to create tun stack: %w", err)
|
||||||
@ -190,3 +194,23 @@ func (t *tunHandler) NewPacketConnection(ctx context.Context, conn network.Packe
|
|||||||
func (t *tunHandler) NewError(ctx context.Context, err error) {
|
func (t *tunHandler) NewError(ctx context.Context, err error) {
|
||||||
// unused
|
// unused
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type interfaceFinder struct{}
|
||||||
|
|
||||||
|
var _ control.InterfaceFinder = (*interfaceFinder)(nil)
|
||||||
|
|
||||||
|
func (f *interfaceFinder) InterfaceIndexByName(name string) (int, error) {
|
||||||
|
ifce, err := net.InterfaceByName(name)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
return ifce.Index, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *interfaceFinder) InterfaceNameByIndex(index int) (string, error) {
|
||||||
|
ifce, err := net.InterfaceByIndex(index)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return ifce.Name, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user