# Link lifecycle SDK / 接口生命周期 SDK

These APIs are available in the source checkout after 0.1.1; they are not part of
the already published 0.1.1 archive. The first creation type is `dummy`.

这些 API 位于 0.1.1 之后的源码中，不包含于已发布的 0.1.1 归档。
首个支持创建的接口类型为 `dummy`。

```mbt
client.create_dummy("dummy0")
let link = client.get_link_by_name("dummy0")
client.set_link_mtu(link.index, 1400)
client.set_link_up(link.index)
client.delete_link(link.index)
```

Calls are asynchronous and use the existing serialized request gate, ACK handling,
timeout and mutation-attempt counter. Creation sends RTM_NEWLINK with REQUEST,
ACK, CREATE and EXCL, an exact IFLA_IFNAME and nested IFLA_LINKINFO/KIND=dummy.
The kernel selects the index and starts the interface administratively DOWN.
Duplicate creation fails without replacing the existing interface. Query again
after ACK to obtain its index and observed attributes.

调用为异步，复用现有串行请求门、ACK处理、超时及修改尝试计数。创建发送带
REQUEST、ACK、CREATE、EXCL 的 RTM_NEWLINK，包含精确 IFLA_IFNAME 和嵌套
IFLA_LINKINFO/KIND=dummy。内核分配索引，接口初始管理状态为 DOWN；同名创建
失败且不替换已有接口。ACK 后应重新查询以取得索引及实际属性。

Creation names obey the existing UTF-16/NUL/15 UTF-8 byte checks. This exact-name
API additionally rejects dot/dot-dot, controls, space, slash, colon and percent
(including kernel auto-allocation templates). Validation raises LinkQueryError
or LinkCreateError before sending. Other failures preserve the kernel errno and
extended diagnostics. CAP_NET_ADMIN in the caller's network namespace is required.

创建名称遵守已有 UTF-16、NUL 和15字节UTF-8限制；精确名称 API 另拒绝点、双点、
控制字符、空格、斜杠、冒号及百分号（包括内核自动分配模板）。校验在发送前抛出
LinkQueryError 或 LinkCreateError。其他失败保留内核errno及扩展诊断。
调用者需要所在网络命名空间的 CAP_NET_ADMIN。

`delete_link` sends RTM_DELLINK for a positive index and can delete interface types
beyond dummy when the kernel permits it. Query the index immediately before use;
indices can be reused after deletion. Deleting a veth end also removes its peer.
These are direct SDK mutations without planning/dry-run/loopback protections.
Do not automatically retry an uncertain timeout: observe actual state first.
DesiredState creation/deletion, veth/bridge creation and automatic lifecycle
compensation are not implemented by this slice.

`delete_link` 对正索引发送 RTM_DELLINK，内核允许时也可删除非dummy类型。
使用前应立即查询索引；接口删除后索引可能复用。删除veth一端也会移除另一端。
这是直接SDK修改，不附带规划、预演或回环保护。超时结果未确定时，不应自动重试，
应先观测实际状态。本切片不包含 DesiredState 接口创建/删除、veth/bridge创建
或生命周期自动补偿。

```sh
bash .ci/validate-create-dummy.sh
```

The entry point requires a fresh user/network namespace, runs the public SDK
example with explicit `--yes`, checks initial DOWN and observed kind, duplicate
errno, MTU/UP, deletion and missing-link failure, then checks client reuse. The
namespace removes any leftovers even if the example fails. Existing CI and release
acceptance loops automatically include this script. Protocol definitions follow
the [Linux rt-link specification](https://kernel.org/doc/html/latest/netlink/specs/rt-link.html).

入口要求新建用户/网络命名空间，显式传入 `--yes` 运行公开SDK样例，验证初始DOWN、
接口类型、重复创建errno、MTU/UP、删除、重复删除失败及客户端复用。即使样例失败，
命名空间销毁也会清理残留。现有CI与发布验收循环自动包含该脚本。协议依据为
[Linux rt-link规范](https://kernel.org/doc/html/latest/netlink/specs/rt-link.html)。
