fix(traffic,server,sandbox): fix TCP/53 false positives, add error-traffic storage toggle, and fix spawn_task/sandbox polling

- Route external TCP/53 through netstack deferred handshake and real-target DNS inspection (RFC 7766 single-write framing) instead of hijacking to host DNS.
- Preserve explicit targetServer in ProcessDNSQueryToTarget under upstream proxy so external UDP/53 probes never fall back to host DNSUpstream.
- Default error traffic storage (net_flows/dns_queries action=error) to off with hot-toggle controls synced across gateway, Proxy & Egress, and Traffic pages.
- Restore json.Unmarshal in spawn_task orchestration tool and poll live sandbox container state in chat/task controls.
This commit is contained in:
ji ruo committed 2026-12-02 15:17:42 +08:00
1 parent 07309e4530
commit d5926d6420
22 files changed
+1189 -101

No files matched your search

+28 -8
View File
@@ -33,8 +33,9 @@ type ContainerProxyRoute struct {
// GatewaySettings persists transparent gateway runtime policy knobs.
type GatewaySettings struct {
UDPPolicy string `json:"udp_policy"`
DNSUpstream string `json:"dns_upstream"`
UDPPolicy string `json:"udp_policy"`
DNSUpstream string `json:"dns_upstream"`
StoreErrorTraffic bool `json:"store_error_traffic"`
}
type proxyRouteRuntime struct {
@@ -93,10 +94,18 @@ func (s *Server) initProxyRoutesAndGateway() {
gs := rt.gwSettings
rt.mu.RUnlock()
s.m.traffic.SetGatewaySettings(gs.UDPPolicy, gs.DNSUpstream)
s.m.traffic.SetStoreErrorTraffic(gs.StoreErrorTraffic)
s.m.traffic.SetUpstreamResolver(s.resolveContainerUpstream)
}
}
func (s *Server) storeErrorTrafficEnabled() bool {
rt := s.ensureRouteRuntime()
rt.mu.RLock()
defer rt.mu.RUnlock()
return rt.gwSettings.StoreErrorTraffic
}
func (s *Server) resolvePoolEntryRawURL(poolID string) string {
poolID = strings.TrimSpace(poolID)
if poolID == "" {
@@ -325,6 +334,7 @@ func (s *Server) getProxyRoutes(w http.ResponseWriter, r *http.Request) {
"last_seen": lastSeenStr,
"udp_policy": traffic.NormalizeUDPPolicy(gs.UDPPolicy),
"dns_upstream": gs.DNSUpstream,
"store_error_traffic": gs.StoreErrorTraffic,
},
})
}
@@ -442,19 +452,28 @@ func (s *Server) deleteProxyRoute(w http.ResponseWriter, r *http.Request) {
// PUT /api/proxy/gateway/settings
func (s *Server) updateGatewaySettings(w http.ResponseWriter, r *http.Request) {
var req struct {
UDPPolicy string `json:"udp_policy"`
DNSUpstream string `json:"dns_upstream"`
UDPPolicy *string `json:"udp_policy"`
DNSUpstream *string `json:"dns_upstream"`
StoreErrorTraffic *bool `json:"store_error_traffic"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeErr(w, http.StatusBadRequest, "invalid JSON body")
return
}
gs := GatewaySettings{
UDPPolicy: traffic.NormalizeUDPPolicy(req.UDPPolicy),
DNSUpstream: strings.TrimSpace(req.DNSUpstream),
}
rt := s.ensureRouteRuntime()
rt.mu.Lock()
gs := rt.gwSettings
if req.UDPPolicy != nil {
gs.UDPPolicy = traffic.NormalizeUDPPolicy(*req.UDPPolicy)
} else {
gs.UDPPolicy = traffic.NormalizeUDPPolicy(gs.UDPPolicy)
}
if req.DNSUpstream != nil {
gs.DNSUpstream = strings.TrimSpace(*req.DNSUpstream)
}
if req.StoreErrorTraffic != nil {
gs.StoreErrorTraffic = *req.StoreErrorTraffic
}
rt.gwSettings = gs
rt.mu.Unlock()
if s.m.pg != nil {
@@ -464,6 +483,7 @@ func (s *Server) updateGatewaySettings(w http.ResponseWriter, r *http.Request) {
}
if s.m.traffic != nil {
s.m.traffic.SetGatewaySettings(gs.UDPPolicy, gs.DNSUpstream)
s.m.traffic.SetStoreErrorTraffic(gs.StoreErrorTraffic)
}
writeJSON(w, 200, gs)
}