traffic: add per-app runtime app routing via cgroup marks
This commit is contained in:
@@ -120,6 +120,24 @@ class TrafficInterfaces:
|
||||
iface_reason: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TrafficAppMarksStatus:
|
||||
vpn_count: int
|
||||
direct_count: int
|
||||
message: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TrafficAppMarksResult:
|
||||
ok: bool
|
||||
message: str
|
||||
op: str = ""
|
||||
target: str = ""
|
||||
cgroup: str = ""
|
||||
cgroup_id: int = 0
|
||||
timeout_sec: int = 0
|
||||
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TrafficCandidateSubnet:
|
||||
@@ -790,6 +808,49 @@ class ApiClient:
|
||||
uids=uids,
|
||||
)
|
||||
|
||||
def traffic_appmarks_status(self) -> TrafficAppMarksStatus:
|
||||
data = cast(
|
||||
Dict[str, Any],
|
||||
self._json(self._request("GET", "/api/v1/traffic/appmarks")) or {},
|
||||
)
|
||||
return TrafficAppMarksStatus(
|
||||
vpn_count=int(data.get("vpn_count", 0) or 0),
|
||||
direct_count=int(data.get("direct_count", 0) or 0),
|
||||
message=str(data.get("message") or ""),
|
||||
)
|
||||
|
||||
def traffic_appmarks_apply(
|
||||
self,
|
||||
*,
|
||||
op: str,
|
||||
target: str,
|
||||
cgroup: str = "",
|
||||
timeout_sec: int = 0,
|
||||
) -> TrafficAppMarksResult:
|
||||
payload: Dict[str, Any] = {
|
||||
"op": str(op or "").strip().lower(),
|
||||
"target": str(target or "").strip().lower(),
|
||||
}
|
||||
if cgroup:
|
||||
payload["cgroup"] = str(cgroup).strip()
|
||||
if int(timeout_sec or 0) > 0:
|
||||
payload["timeout_sec"] = int(timeout_sec)
|
||||
|
||||
data = cast(
|
||||
Dict[str, Any],
|
||||
self._json(self._request("POST", "/api/v1/traffic/appmarks", json_body=payload))
|
||||
or {},
|
||||
)
|
||||
return TrafficAppMarksResult(
|
||||
ok=bool(data.get("ok", False)),
|
||||
message=str(data.get("message") or ""),
|
||||
op=str(data.get("op") or payload["op"]),
|
||||
target=str(data.get("target") or payload["target"]),
|
||||
cgroup=str(data.get("cgroup") or payload.get("cgroup") or ""),
|
||||
cgroup_id=int(data.get("cgroup_id", 0) or 0),
|
||||
timeout_sec=int(data.get("timeout_sec", 0) or 0),
|
||||
)
|
||||
|
||||
|
||||
# DNS / SmartDNS
|
||||
def dns_upstreams_get(self) -> DnsUpstreams:
|
||||
|
||||
Reference in New Issue
Block a user