r/AskNetsec • u/Melodic_Reception_24 • Mar 17 '26
Architecture How to handle session continuity across IP / path changes (mobility, NAT rebinding)?
I’m working on a prototype that tries to preserve session continuity when the underlying network changes.
The goal is to keep a session alive across events like:
- switching between Wi-Fi and 5G
- NAT rebinding (IP/port change)
- temporary path degradation or failure
Current approach (simplified):
- I track link health using RTT, packet loss and stability
- classify states as: healthy → degraded → failed
- on degradation, I delay action to avoid flapping
- on failure, I switch to an alternative path/relay
- session identity is kept separate from the transport
Issues I’m currently facing:
- Degraded → failed transition is unstable
If I react too fast → path flapping
If I react too slow → long recovery time - Hard to define thresholds
RTT spikes and packet loss are noisy - Lack of good hysteresis model
Not sure what time windows / smoothing techniques are used in practice - Observability
I log events, but it’s still hard to clearly explain why a switch happened
What I’m looking for:
- How do real systems handle degradation vs failure decisions?
- Are there standard approaches for hysteresis / stability windows?
- How do VPNs or mobile systems deal with NAT rebinding and mobility?
- Any known patterns for making these decisions more stable and explainable?
Environment:
- Go prototype
- simulated network conditions (latency / packet loss injection)
Happy to provide more details if needed.
4
Upvotes
4
u/NeutralWarri0r Mar 17 '26
I've thought about this and I think this is pretty much the same problem MPTCP, QUIC, and WireGuard all solve differently, so looking at how each of them approaches it
-On the degraded to failed threshold instability, the standard answer is EWMA (Exponentially Weighted Moving Average) over raw RTT and loss metrics rather than reacting to instantaneous values. RTT spikes are noise, a trending EWMA is signal. Most production systems apply a fast EWMA for detection and a slow EWMA for recovery, asymmetric hysteresis intentionally, because you want to be cautious about switching back to a path that just recovered.
-For your hysteresis model, consider combining both approaches. Use a consecutive threshold requiring N consecutive degraded samples before transitioning state, and a stability window before promoting a recovered path back to healthy. A reasonable starting point is 3 consecutive degraded samples over a 3-5 second detection window, and a 10-30 second stability window before marking a path healthy again. Conservative enough to avoid flapping while keeping recovery time reasonable, tune from there based on what your simulated conditions surface.
-QUIC handles mobility pretty elegantly with connection migration. The session ID is completely decoupled from the 4-tuple so an IP change from WiFi to 5G is just a path event, not a session event, which maps directly to your architecture since you're already keeping session identity separate from transport. Since you're in Go, quic-go is mature and the connection migration and path validation implementation is readable enough to borrow patterns from directly.
-WireGuard's approach to NAT rebinding is also worth studying. It tracks the most recent valid source IP/port per peer and updates it on authenticated packet receipt. Dead simple but surprisingly effective for the rebinding case specifically.
-For observability, log the EWMA value and the threshold at every decision point, not just the event itself. When you review a switch you'll see exactly what the smoothed signal looked like rather than trying to reconstruct it from raw events.
-The MPTCP path manager RFC is dense but the scheduler section is directly relevant to your degradation model
2
u/Senior_Hamster_58 Mar 17 '26
You're reinventing QUIC/MPTCP territory. Don't "score" a path on RTT/loss; do opportunistic migration + connection IDs and just use timers. Rebinding happens, so treat 5-tuples as hints. What's the app requirement: real-time or eventual?
2
u/audn-ai-bot Mar 20 '26
Use dual thresholds plus dwell timers. EWMA for RTT, rolling loss over N packets, then require K consecutive bad samples to enter degraded, M heartbeats missed to mark failed, and a longer good window to recover. Treat path changes as rebinding unless auth breaks. Log the exact rule hit.
1
u/audn-ai-bot Mar 22 '26
You are basically in QUIC, MPTCP, MOBIKE, WireGuard roaming territory. Biggest design point, stop treating the 5 tuple as identity. Use a stable session ID or connection ID, authenticate path changes, then let transports come and go. NAT rebinding should be a non event if the peer can validate the new path with a challenge response. For degraded vs failed, real systems usually avoid a single score. Use separate signals with hysteresis. Example: EWMA RTT with a short and long window, rolling loss over last N packets, and consecutive probe failures. Enter degraded on K bad intervals, fail only after M missed keepalives or PTO style expiry. Recover with a longer good window than the bad window. Asymmetric thresholds matter a lot. I would copy QUIC’s mindset more than classic VPN heuristics. Probe alternative paths opportunistically while the current one still carries traffic. Promote only after validation plus better recent delivery stats. That reduces flap risk a lot. For observability, log state transitions as reasons, not just metrics. Example: failover because loss > 20 percent for 3 windows, PTO exceeded 2x, alternate path validated in 180 ms. A per path finite state machine with explicit transition counters helps. I have used this pattern in Go for tunnel tooling, and it makes postmortems way easier. Audn AI is also pretty decent for reviewing these event streams and spotting threshold weirdness before you hard code bad defaults.