メインコンテンツまでスキップ

制御 API v1alpha1

Diagram showing the Control API v1alpha1 local socket model from routerd main sockets and managed daemon sockets to status, events, commands, resource phases, and local-only client contracts

routerd と管理対象デーモンは、ローカルの Unix domain socket 上に HTTP+JSON API を公開します。 この API はリモート管理用ではなく、routerctl、routerd 本体、運用スクリプトが同じホスト上で状態を読むためのものです。

routerd 本体

routerd serve は次を待ち受けます。

/run/routerd/routerd.sock
/run/routerd/routerd-status.sock

主 control socket は権限を持つローカル client 向けで、apply や delete などの変更系 エンドポイントも公開します。読み取り専用 status socket は status 系エンドポイントだけを 公開し、一般ユーザーが状態確認に使えます。

主 control socket の読み取りエンドポイントは、状態、event、resource state を返します。 代表例は次の通りです。

Method + Path用途
GET /api/control.routerd.net/v1alpha1/statusrouterd 自身の状態
GET /api/control.routerd.net/v1alpha1/connectionsconntrack または pf state から得た現在のコネクション
GET /api/control.routerd.net/v1alpha1/dns-queriesDNS クエリー履歴
GET /api/control.routerd.net/v1alpha1/traffic-flows通信フロー履歴
GET /api/control.routerd.net/v1alpha1/firewall-logsファイアウォールログ

コントローラーの状態

Status.status.controllersControllers エンドポイントは、コントローラーの設定上の mode と、実行時の reconcile 状態を返します。runtime field には intervallastTriggerlastReconcileTimenextReconcileTimereconcileCountreconcileErrorCountconsecutiveErrorCountcurrentErrorlastDurationmaxDurationaverageDurationlastErrorlastErrorTimelastErrorClearedAt が含まれます。reconcileErrorCount は 累積値なので、現在失敗中かどうかは currentErrorconsecutiveErrorCount で 判定してください。これらは観測値なので、controller がまだ一度も実行されて いない場合は、field が無いものとして扱ってください。

管理対象デーモン

状態を持つデーモンは、それぞれ独自の socket を持ちます。

/run/routerd/dhcpv6-client/wan-pd.sock
/run/routerd/dhcpv4-client/wan.sock
/run/routerd/pppoe-client/wan-pppoe.sock
/run/routerd/healthcheck/internet.sock

FreeBSD では、対応するパスは /var/run/routerd/... です。

デーモン共通エンドポイント

Method + Path用途
GET /v1/healthzliveness check
GET /v1/statusデーモンの状態と、関連リソースの状態
GET /v1/eventsevent log。sincewaittopic を query で指定します
POST /v1/commands/reload設定の再読み込み
POST /v1/commands/renewデーモンごとの能動操作(DHCPv6 Renew、DHCPv4 のリース更新、即時の health probe など)
POST /v1/commands/stop安全に停止

renew の意味はデーモンごとに異なります。DHCPv6 は Renew の送信、DHCPv4 はリース更新、healthcheck は即時の probe です。

フェーズ語彙

ResourceStatus.phase は、リソース横断で共通の語彙を使います。

フェーズ意味
Pending必要な入力を待機中です
BoundDHCP などのリースを保持中です
Appliedホスト側へ適用済みです
Uptunnel または link が up しています
Installed経路または設定ファイルが入っています
Healthyhealth check が success threshold を満たしています
Unhealthyhealth check が failure threshold を満たしています
Error操作に失敗しました

各 phase には conditions 配列が付きます。client 側のコードでは、log 文字列ではなく phaseconditions で判定してください。

イベント

イベントは topic と attributes を持ちます。

{
"topic": "routerd.dhcpv6.client.prefix.renewed",
"attributes": {
"resource.kind": "DHCPv6PrefixDelegation",
"resource.name": "wan-pd"
}
}

routerd は event を SQLite に永続化します。 管理対象デーモンは、加えて自身の events.jsonl にも記録します。 EventRuleDerivedEvent は、このストリームを入力にして仮想 event を発行します。