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)
| 27 | // It opens the Linux NFQUEUE backend, spawns the bypass engine, and runs |
| 28 | // a pass-through TCP relay on profile.Listen. |
| 29 | func 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 | } |
no test coverage detected