子网路由与运行数据

读取或维护子网路由,并查询用量和活动日志。 本页完整列出 5 个受支持操作的请求与响应契约。

路径均相对于 https://<nsd-host>。先设置 NSD_BASE_URL=https://<nsd-host>/api/v1 和 NSD_TOKEN;示例 ID 与数据均为虚构值。

列出子网路由

GET/api/v1/subnetsread-only / full

请求示例

curl --silent --show-error --fail-with-body -X GET \
  "$NSD_BASE_URL/subnets" \
  -H "Authorization: Bearer $NSD_TOKEN" \
  -H 'Accept: application/json'

响应状态

状态含义响应结构
200Subnet mappings for the caller's Network.array<MappingResponse>
401缺少或无效的 Bearer 令牌。ProblemDetails
500Subnet mapping authority unavailableProblemDetails

200 响应

字段类型必有说明
[].active_gateway_machine_idstring | null否Gateway currently publishing the mapping, absent while none is healthy.
[].display_labelstring是Operator-facing label derived from the mapping.
[].generationinteger是Mapping revision; advances when the mapping itself changes.
[].mapped_prefixstring是Overlay prefix this LAN is reachable at inside the Network.
[].real_cidrstring是Real IPv4 LAN CIDR, normalized to the network address.
[].selection_generationinteger是Active-gateway selection revision; advances on every failover.
[].standby_gateway_machine_idsarray<string>是Gateways that have joined the mapping and can take over.
[].subnet_idinteger是Stable subnet mapping ID within the Network.
[].withdrawnboolean是Whether the mapping was withdrawn. Its allocation is retained and never reused, so a withdrawn mapping still occupies its prefix.
[
  {
    "active_gateway_machine_id": "n-01K4NODE000000000000000",
    "display_label": "example",
    "generation": 1,
    "mapped_prefix": "100.96.10.0/24",
    "real_cidr": "192.168.10.0/24",
    "selection_generation": 1,
    "standby_gateway_machine_ids": [
      "n-01K4NODE000000000000000"
    ],
    "subnet_id": 1,
    "withdrawn": false
  }
]

错误响应均使用 Problem Details;调用方应判断 HTTP 状态和稳定的 code,不要解析 detail 文案。

创建或加入子网路由

POST/api/v1/subnetsfull

请求体

字段类型必填说明
gateway_machine_idstring是Registered gateway machine that publishes this mapping.
join_subnet_idinteger | null否Existing mapping to join; omitted creates an independent mapping.
real_cidrstring是Real IPv4 LAN CIDR. Host bits are normalized to the network address.
request.json
{
  "gateway_machine_id": "n-01K4NODE000000000000000",
  "join_subnet_id": 1,
  "real_cidr": "192.168.10.0/24"
}

请求示例

curl --silent --show-error --fail-with-body -X POST \
  "$NSD_BASE_URL/subnets" \
  -H "Authorization: Bearer $NSD_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data @request.json

响应状态

状态含义响应结构
201Mapping created, or the caller joined an existing oneMappingResponse
400Malformed IPv4 CIDR, gateway machine id, or subnet idProblemDetails
401缺少或无效的 Bearer 令牌。ProblemDetails
403Gateway is not a member of the caller's NetworkProblemDetails
409Join CIDR does not match the target mapping, or the Network address authority is missingProblemDetails
500Subnet mapping authority unavailableProblemDetails
503Address allocation retries exhausted; retryProblemDetails

201 响应

字段类型必有说明
active_gateway_machine_idstring | null否Gateway currently publishing the mapping, absent while none is healthy.
display_labelstring是Operator-facing label derived from the mapping.
generationinteger是Mapping revision; advances when the mapping itself changes.
mapped_prefixstring是Overlay prefix this LAN is reachable at inside the Network.
real_cidrstring是Real IPv4 LAN CIDR, normalized to the network address.
selection_generationinteger是Active-gateway selection revision; advances on every failover.
standby_gateway_machine_idsarray<string>是Gateways that have joined the mapping and can take over.
subnet_idinteger是Stable subnet mapping ID within the Network.
withdrawnboolean是Whether the mapping was withdrawn. Its allocation is retained and never reused, so a withdrawn mapping still occupies its prefix.
{
  "active_gateway_machine_id": "n-01K4NODE000000000000000",
  "display_label": "example",
  "generation": 1,
  "mapped_prefix": "100.96.10.0/24",
  "real_cidr": "192.168.10.0/24",
  "selection_generation": 1,
  "standby_gateway_machine_ids": [
    "n-01K4NODE000000000000000"
  ],
  "subnet_id": 1,
  "withdrawn": false
}

错误响应均使用 Problem Details;调用方应判断 HTTP 状态和稳定的 code,不要解析 detail 文案。

撤销子网路由

DELETE/api/v1/subnets/{subnet_id}full

参数

名称位置类型必填说明
subnet_idpathinteger是Stable subnet mapping ID.

请求示例

curl --silent --show-error --fail-with-body -X DELETE \
  "$NSD_BASE_URL/subnets/${SUBNET_ID}" \
  -H "Authorization: Bearer $NSD_TOKEN" \
  -H 'Accept: application/json'

响应状态

状态含义响应结构
204Mapping withdrawn; its allocation is retained and never reused—
400Malformed subnet idProblemDetails
401缺少或无效的 Bearer 令牌。ProblemDetails
404No such mapping in the caller's NetworkProblemDetails
500Subnet mapping authority unavailableProblemDetails

204 响应

成功,无响应体。

错误响应均使用 Problem Details;调用方应判断 HTTP 状态和稳定的 code,不要解析 detail 文案。

读取流量用量

GET/api/v1/usageread-only / full

参数

名称位置类型必填说明
fromqueryinteger | null否Count only reports whose window starts at or after this instant.
toqueryinteger | null否Count only reports whose window ends at or before this instant.

请求示例

curl --silent --show-error --fail-with-body -X GET \
  "$NSD_BASE_URL/usage" \
  -H "Authorization: Bearer $NSD_TOKEN" \
  -H 'Accept: application/json'

响应状态

状态含义响应结构
200Gateway-metered usage for the caller's realmUsageReadoutDto
401缺少或无效的 Bearer 令牌。ProblemDetails

200 响应

字段类型必有说明
by_patharray<UsageLineDto>是Stably ordered by (path_class, subject_kind, subject_id).
by_path[].connections_openedinteger | null否Connections opened, summed. Telemetry, never billed.
by_path[].connections_peakinteger | null否Peak concurrent connections — the MAX, never a sum.
by_path[].path_classstring是terminate | wg_relay | wss_relay | gateway_egress | gateway_exit | public_edge.
by_path[].rx_bytesstring是Bytes client → gateway, summed.
by_path[].subject_idstring | null否The machine or user id. Absent on a realm aggregate.
by_path[].subject_kindstring | null否machine | user. Absent on a realm aggregate.
by_path[].tx_bytesstring是Bytes gateway → client, summed.
frominteger | null否Echo of the requested lower bound.
org_idstring是Billing org that owns the realm.
realmstring是Realm the usage belongs to (the caller's).
tointeger | null否Echo of the requested upper bound.
totalUsageTotalsDto是Summed across every line in by_path.
total.rx_bytesstring是Total bytes client → gateway.
total.tx_bytesstring是Total bytes gateway → client.
{
  "by_path": [
    {
      "connections_opened": 1,
      "connections_peak": 1,
      "path_class": "example",
      "rx_bytes": "example",
      "subject_id": "01K4EXAMPLE0000000000000",
      "subject_kind": "example",
      "tx_bytes": "example"
    }
  ],
  "from": 1,
  "org_id": "01K4EXAMPLE0000000000000",
  "realm": "example",
  "to": 1,
  "total": {
    "rx_bytes": "example",
    "tx_bytes": "example"
  }
}

错误响应均使用 Problem Details;调用方应判断 HTTP 状态和稳定的 code,不要解析 detail 文案。

读取活动日志

GET/api/v1/audit-eventsread-only / full

参数

名称位置类型必填说明
limitqueryinteger | null否Maximum number of events to return per page.
cursorquerystring | null否Cursor pagination: last id of the previous page. The audit ledger is descending (newest first), so this anchors id < cursor.
sincequeryinteger | null否Server-side time lower bound (unix seconds): keep events with ts >=.
outcomequerystring | null否Server-side exact outcome filter (success | denied | error).
qquerystring | null否Server-side case-insensitive substring search on action / actor / resource.

请求示例

curl --silent --show-error --fail-with-body -X GET \
  "$NSD_BASE_URL/audit-events?limit=100" \
  -H "Authorization: Bearer $NSD_TOKEN" \
  -H 'Accept: application/json'

响应状态

状态含义响应结构
200Realm-scoped audit events (paginated; supports outcome and q query filters)ListAuditEventsResponse
401缺少或无效的 Bearer 令牌。ProblemDetails

200 响应

字段类型必有说明
itemsarray<AuditEventView>是Audit events in this page.
items[].actionstring是Action string.
items[].actor_idstring | null否Actor id.
items[].actor_labelstring是Actor label.
items[].actor_typestring是Actor type.
items[].error_detailstring | null否Error detail.
items[].idstring是Audit event ULID.
items[].ipstring | null否Source IP.
items[].outcomestring是Outcome.
items[].realm_idstring是Realm ULID.
items[].resource_idstring | null否Resource id.
items[].resource_labelstring | null否Resource label.
items[].resource_typestring是Resource type.
items[].tsstring是Timestamp.
next_cursorstring | null否Cursor for the next page, or null.
{
  "items": [
    {
      "action": "allow",
      "actor_id": "01K4EXAMPLE0000000000000",
      "actor_label": "example",
      "actor_type": "example",
      "error_detail": "example",
      "id": "01K4EXAMPLE0000000000000",
      "ip": "example",
      "outcome": "example",
      "realm_id": "01K4EXAMPLE0000000000000",
      "resource_id": "01K4EXAMPLE0000000000000",
      "resource_label": "example",
      "resource_type": "example",
      "ts": "example"
    }
  ],
  "next_cursor": "example"
}

错误响应均使用 Problem Details;调用方应判断 HTTP 状态和稳定的 code,不要解析 detail 文案。

返回 API 参考总览。