mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-12 17:28:29 +03:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
212d1b108b | ||
|
|
2101c1a99f | ||
|
|
e1fe8be7a5 | ||
|
|
bbc8103a7d |
@@ -170,12 +170,6 @@ func NewAlwaysOnInboundHandler(ctx context.Context, tag string, receiverConfig *
|
|||||||
|
|
||||||
// Start implements common.Runnable.
|
// Start implements common.Runnable.
|
||||||
func (h *AlwaysOnInboundHandler) Start() error {
|
func (h *AlwaysOnInboundHandler) Start() error {
|
||||||
// for inbound without worker (TUN)
|
|
||||||
if run, ok := h.proxy.(common.Runnable); ok {
|
|
||||||
if err := run.Start(); err != nil {
|
|
||||||
return errors.New("failed to start proxy").Base(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, worker := range h.workers {
|
for _, worker := range h.workers {
|
||||||
if err := worker.Start(); err != nil {
|
if err := worker.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+11
-9
@@ -2,6 +2,8 @@ package tun
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/netip"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
@@ -40,11 +42,10 @@ type ConnectionHandler interface {
|
|||||||
// Handler implements ConnectionHandler
|
// Handler implements ConnectionHandler
|
||||||
var _ ConnectionHandler = (*Handler)(nil)
|
var _ ConnectionHandler = (*Handler)(nil)
|
||||||
|
|
||||||
// Handler implements common.Runnable
|
|
||||||
var _ common.Runnable = (*Handler)(nil)
|
|
||||||
|
|
||||||
// Init the Handler instance with necessary parameters
|
// Init the Handler instance with necessary parameters
|
||||||
func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routing.Dispatcher) error {
|
func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routing.Dispatcher) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
// Retrieve tag and sniffing config from context (set by AlwaysOnInboundHandler)
|
// Retrieve tag and sniffing config from context (set by AlwaysOnInboundHandler)
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
||||||
t.tag = inbound.Tag
|
t.tag = inbound.Tag
|
||||||
@@ -57,10 +58,6 @@ func (t *Handler) Init(ctx context.Context, pm policy.Manager, dispatcher routin
|
|||||||
t.policyManager = pm
|
t.policyManager = pm
|
||||||
t.dispatcher = dispatcher
|
t.dispatcher = dispatcher
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Handler) Start() error {
|
|
||||||
tunName := t.config.Name
|
tunName := t.config.Name
|
||||||
tunInterface, err := NewTun(t.config)
|
tunInterface, err := NewTun(t.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -85,6 +82,11 @@ func (t *Handler) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return c.Control(func(fd uintptr) {
|
return c.Control(func(fd uintptr) {
|
||||||
|
addrPort, _ := netip.ParseAddrPort(address)
|
||||||
|
// skip loopback
|
||||||
|
if addrPort.Addr().IsLoopback() || strings.HasPrefix(strings.ToLower(address), "localhost:") {
|
||||||
|
return
|
||||||
|
}
|
||||||
err := setinterface(network, address, fd, iface)
|
err := setinterface(network, address, fd, iface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.LogInfoInner(context.Background(), err, "[tun] falied to set interface")
|
errors.LogInfoInner(context.Background(), err, "[tun] falied to set interface")
|
||||||
@@ -97,7 +99,7 @@ func (t *Handler) Start() error {
|
|||||||
|
|
||||||
tunStackOptions := StackOptions{
|
tunStackOptions := StackOptions{
|
||||||
Tun: tunInterface,
|
Tun: tunInterface,
|
||||||
IdleTimeout: t.policyManager.ForLevel(t.config.UserLevel).Timeouts.ConnectionIdle,
|
IdleTimeout: pm.ForLevel(t.config.UserLevel).Timeouts.ConnectionIdle,
|
||||||
}
|
}
|
||||||
tunStack, err := NewStack(t.ctx, tunStackOptions, t)
|
tunStack, err := NewStack(t.ctx, tunStackOptions, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -172,7 +174,7 @@ func (t *Handler) HandleConnection(conn net.Conn, destination net.Destination) {
|
|||||||
|
|
||||||
// Close implements common.Closable.
|
// Close implements common.Closable.
|
||||||
func (t *Handler) Close() error {
|
func (t *Handler) Close() error {
|
||||||
return errors.Combine(common.CloseIfExists(t.stack), common.CloseIfExists(t.tun))
|
return errors.Combine(t.stack.Close(), t.tun.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network implements proxy.Inbound
|
// Network implements proxy.Inbound
|
||||||
|
|||||||
Reference in New Issue
Block a user