MCPcopy Create free account
hub / github.com/SamNet-dev/snix / runEngine

Function runEngine

cmd/snix/engine_linux.go:29–109  ·  view source on GitHub ↗

runEngine is the platform-specific entry point invoked by `snix start`. It opens the Linux NFQUEUE backend, spawns the bypass engine, and runs a pass-through TCP relay on profile.Listen.

(ctx context.Context, out io.Writer, p *config.Profile)

Source from the content-addressed store, hash-verified

27// It opens the Linux NFQUEUE backend, spawns the bypass engine, and runs
28// a pass-through TCP relay on profile.Listen.
29func runEngine(ctx context.Context, out io.Writer, p *config.Profile) error {
30 remoteAddr, err := resolveIPv4(p.Connect.Host)
31 if err != nil {
32 return fmt.Errorf("resolve %s: %w", p.Connect.Host, err)
33 }
34 localIP, err := defaultIfaceIPv4(remoteAddr)
35 if err != nil {
36 return fmt.Errorf("local iface: %w", err)
37 }
38 sniPool := p.EffectiveSNIPool()
39 fmt.Fprintf(out, "snix: local=%s remote=%s:%d sni_pool=%v strategy=%s\n",
40 localIP, remoteAddr, p.Connect.Port, sniPool, p.Spoof.Strategy)
41 if p.Spoof.RandomizeTiming || p.Spoof.RandomizePadding || len(p.Spoof.StrategyRotation) > 0 {
42 fmt.Fprintf(out, "snix: randomization active timing=%v padding=%v rotation=%v id_delta_range=%d\n",
43 p.Spoof.RandomizeTiming, p.Spoof.RandomizePadding,
44 p.Spoof.StrategyRotation, p.Spoof.IPIDDeltaRange)
45 }
46
47 scope := platform.Scope{
48 LocalIP: localIP,
49 RemoteIP: remoteAddr,
50 RemotePort: p.Connect.Port,
51 }
52
53 be := linuxbe.New(linuxbe.Config{})
54 if err := be.Open(ctx, scope); err != nil {
55 return fmt.Errorf("backend open: %w", err)
56 }
57 fmt.Fprintf(out, "snix: iptables rules installed, NFQUEUE active\n")
58 defer func() {
59 if err := be.Close(); err != nil {
60 fmt.Fprintf(out, "snix: close: %v\n", err)
61 } else {
62 fmt.Fprintf(out, "snix: iptables rules removed\n")
63 }
64 }()
65
66 // Spin up the bypass engine with all anti-fingerprinting knobs from config.
67 eng, err := engine.New(engine.Config{
68 Strategy: p.Spoof.Strategy,
69 SNIPool: sniPool,
70 Scope: scope,
71 Log: stdoutLogger{w: out},
72 Knobs: fingerprint.Knobs{
73 RandomizeTiming: p.Spoof.RandomizeTiming,
74 MinDelay: p.Spoof.MinDelay,
75 MaxDelay: p.Spoof.MaxDelay,
76 RandomizePadding: p.Spoof.RandomizePadding,
77 MinExtraPad: p.Spoof.MinExtraPad,
78 MaxExtraPad: p.Spoof.MaxExtraPad,
79 IPIDDeltaRange: p.Spoof.IPIDDeltaRange,
80 StrategyRotation: p.Spoof.StrategyRotation,
81 SNISelection: p.Spoof.SNISelection,
82 },
83 }, be)
84 if err != nil {
85 return fmt.Errorf("engine: %w", err)
86 }

Callers 1

newStartCmdFunction · 0.70

Calls 9

NewFunction · 0.92
EffectiveSNIPoolMethod · 0.80
RunMethod · 0.80
AcceptMethod · 0.80
resolveIPv4Function · 0.70
defaultIfaceIPv4Function · 0.70
handleConnFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected