Debian Codegraph @

SPEC.md

raw
1 # Container Network Interface (CNI) Specification
2 - [Container Network Interface (CNI) Specification](#container-network-interface-cni-specification)
3 - [Version](#version)
4 - [Released versions](#released-versions)
5 - [Overview](#overview)
6 - [Summary](#summary)
7 - [Section 1: Network configuration format](#section-1-network-configuration-format)
8 - [Configuration format](#configuration-format)
9 - [Plugin configuration objects:](#plugin-configuration-objects)
10 - [Example configuration](#example-configuration)
11 - [Version considerations](#version-considerations)
12 - [Section 2: Execution Protocol](#section-2-execution-protocol)
13 - [Overview](#overview-1)
14 - [Parameters](#parameters)
15 - [Errors](#errors)
16 - [CNI operations](#cni-operations)
17 - [`ADD`: Add container to network, or apply modifications](#add-add-container-to-network-or-apply-modifications)
18 - [`DEL`: Remove container from network, or un-apply modifications](#del-remove-container-from-network-or-un-apply-modifications)
19 - [`CHECK`: Check container's networking is as expected](#check-check-containers-networking-is-as-expected)
20 - [`STATUS`: Check plugin status](#status-check-plugin-status)
21 - [`VERSION`: probe plugin version support](#version-probe-plugin-version-support)
22 - [`GC`: Clean up any stale resources](#gc-clean-up-any-stale-resources)
23 - [Section 3: Execution of Network Configurations](#section-3-execution-of-network-configurations)
24 - [Lifecycle \& Ordering](#lifecycle--ordering)
25 - [Attachment Parameters](#attachment-parameters)
26 - [Adding an attachment](#adding-an-attachment)
27 - [Deleting an attachment](#deleting-an-attachment)
28 - [Checking an attachment](#checking-an-attachment)
29 - [Garbage-collecting a network](#garbage-collecting-a-network)
30 - [Deriving request configuration from plugin configuration](#deriving-request-configuration-from-plugin-configuration)
31 - [Deriving `runtimeConfig`](#deriving-runtimeconfig)
32 - [Section 4: Plugin Delegation](#section-4-plugin-delegation)
33 - [Delegated Plugin protocol](#delegated-plugin-protocol)
34 - [Delegated plugin execution procedure](#delegated-plugin-execution-procedure)
35 - [Section 5: Result Types](#section-5-result-types)
36 - [ADD Success](#add-success)
37 - [Delegated plugins (IPAM)](#delegated-plugins-ipam)
38 - [VERSION Success](#version-success)
39 - [Error](#error)
40 - [Version](#version-1)
41 - [Appendix: Examples](#appendix-examples)
42 - [Add example](#add-example)
43 - [Check example](#check-example)
44 - [Delete example](#delete-example)
45
46 ## Version
47
48 This is CNI **spec** version **1.1.0**.
49
50 Note that this is **independent from the version of the CNI library and plugins** in this repository (e.g. the versions of [releases](https://github.com/containernetworking/cni/releases)).
51
52 #### Released versions
53
54 Released versions of the spec are available as Git tags.
55
56 | tag | spec permalink | major changes |
57 | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- | --------------------------------- |
58 | [`spec-v1.0.0`](https://github.com/containernetworking/cni/releases/tag/spec-v1.0.0) | [spec at v1.0.0](https://github.com/containernetworking/cni/blob/spec-v1.0.0/SPEC.md) | Removed non-list configurations; removed `version` field of `interfaces` array |
59 | [`spec-v0.4.0`](https://github.com/containernetworking/cni/releases/tag/spec-v0.4.0) | [spec at v0.4.0](https://github.com/containernetworking/cni/blob/spec-v0.4.0/SPEC.md) | Introduce the CHECK command and passing prevResult on DEL |
60 | [`spec-v0.3.1`](https://github.com/containernetworking/cni/releases/tag/spec-v0.3.1) | [spec at v0.3.1](https://github.com/containernetworking/cni/blob/spec-v0.3.1/SPEC.md) | none (typo fix only) |
61 | [`spec-v0.3.0`](https://github.com/containernetworking/cni/releases/tag/spec-v0.3.0) | [spec at v0.3.0](https://github.com/containernetworking/cni/blob/spec-v0.3.0/SPEC.md) | rich result type, plugin chaining |
62 | [`spec-v0.2.0`](https://github.com/containernetworking/cni/releases/tag/spec-v0.2.0) | [spec at v0.2.0](https://github.com/containernetworking/cni/blob/spec-v0.2.0/SPEC.md) | VERSION command |
63 | [`spec-v0.1.0`](https://github.com/containernetworking/cni/releases/tag/spec-v0.1.0) | [spec at v0.1.0](https://github.com/containernetworking/cni/blob/spec-v0.1.0/SPEC.md) | initial version |
64
65 *Do not rely on these tags being stable. In the future, we may change our mind about which particular commit is the right marker for a given historical spec version.*
66
67
68 ## Overview
69
70 This document proposes a generic plugin-based networking solution for application containers on Linux, the _Container Networking Interface_, or _CNI_.
71
72 For the purposes of this proposal, we define three terms very specifically:
73 - _container_ is a network isolation domain, though the actual isolation technology is not defined by the specification. This could be a [network namespace][namespaces] or a virtual machine, for example.
74 - _network_ refers to a group of endpoints that are uniquely addressable that can communicate amongst each other. This could be either an individual container (as specified above), a machine, or some other network device (e.g. a router). Containers can be conceptually _added to_ or _removed from_ one or more networks.
75 - _runtime_ is the program responsible for executing CNI plugins.
76 - _plugin_ is a program that applies a specified network configuration.
77
78 This document aims to specify the interface between "runtimes" and "plugins". The key words "must", "must not", "required", "shall", "shall not", "should", "should not", "recommended", "may" and "optional" are used as specified in [RFC 2119][rfc-2119].
79
80 [namespaces]: http://man7.org/linux/man-pages/man7/namespaces.7.html
81 [rfc-2119]: https://www.ietf.org/rfc/rfc2119.txt
82
83
84
85 ## Summary
86
87 The CNI specification defines:
88
89 1. A format for administrators to define network configuration.
90 2. A protocol for container runtimes to make requests to network plugins.
91 3. A procedure for executing plugins based on a supplied configuration.
92 4. A procedure for plugins to delegate functionality to other plugins.
93 5. Data types for plugins to return their results to the runtime.
94
95 ## Section 1: Network configuration format
96
97 CNI defines a network configuration format for administrators. It contains
98 directives for both the container runtime as well as the plugins to consume. At
99 plugin execution time, this configuration format is interpreted by the runtime and
100 transformed in to a form to be passed to the plugins.
101
102 In general, the network configuration is intended to be static. It can conceptually
103 be thought of as being "on disk", though the CNI specification does not actually
104 require this.
105
106 ### Configuration format
107
108 A network configuration consists of a JSON object with the following keys:
109
110 - `cniVersion` (string): [Semantic Version 2.0](https://semver.org) of CNI specification to which this configuration list and all the individual configurations conform. Currently "1.1.0"
111 - `cniVersions` (string list): List of all CNI versions which this configuration supports. See [version selection](#version-selection) below.
112 - `name` (string): Network name. This should be unique across all network configurations on a host (or other administrative domain). Must start with an alphanumeric character, optionally followed by any combination of one or more alphanumeric characters, underscore, dot (.) or hyphen (-). Must not contain characters disallowed in file paths.
113 - `disableCheck` (boolean): Either `true` or `false`. If `disableCheck` is `true`, runtimes must not call `CHECK` for this network configuration list. This allows an administrator to prevent `CHECK`ing where a combination of plugins is known to return spurious errors.
114 - `disableGC` (boolean): Either `true` or `false`. If `disableGC` is `true`, runtimes must not call `GC` for this network configuration list. This allows an administrator to prevent `GC`ing when it is known that garbage collection may have undesired effects (e.g. shared configuration between multiple runtimes).
115 - `loadOnlyInlinedPlugins` (boolean): Either `true` or `false`. If `false` (default), indicates [plugin configuration objects](#plugin-configuration-objects) can be aggregated from multiple sources. Any valid plugin configuration objects aggregated from other sources must be appended to the final list of `plugins` for that network name. If set to `true`, indicates that valid plugin configuration objects aggregated from sources other than the main network configuration will be ignored. If `plugins` is not present in the network configuration, `loadOnlyInlinedPlugins` cannot be set to `true`.
116 - `plugins` (list): A list of inlined [plugin configuration objects](#plugin-configuration-objects). If this key is populated with inlined plugin objects, and `loadOnlyInlinedPlugins` is true, the final set of plugins for a network must consist of all the plugin objects in this list, merged with all the plugins loaded from the sibling folder with the same name as the network.
117
118 #### Plugin configuration objects:
119 Runtimes may aggregate plugin configuration objects from multiple sources, and must unambiguously associate each loaded plugin configuration object with a single, valid network configuration. All aggregated plugin configuration objects must be validated, and each plugin with a valid configuration object must be invoked.
120
121 Plugin configuration objects may contain additional fields beyond the ones defined here. The runtime MUST pass through these fields, unchanged, to the invoked plugin, as defined in section 3.
122
123 **Required keys:**
124 - `type` (string): Matches the name of the CNI plugin binary on disk. Must not contain characters disallowed in file paths for the system (e.g. / or \\).
125
126 **Optional keys, used by the protocol:**
127 - `capabilities` (dictionary): Defined in [section 3](#Deriving-runtimeConfig)
128
129 **Reserved keys, used by the protocol:**
130 These keys are generated by the runtime at execution time, and thus should not be used in configuration.
131 - `runtimeConfig`
132 - `args`
133 - Any keys starting with `cni.dev/`
134
135 **Optional keys, well-known:**
136 These keys are not used by the protocol, but have a standard meaning to plugins.
137 Plugins that consume any of these configuration keys should respect their intended semantics.
138
139 - `ipMasq` (boolean): If supported by the plugin, sets up an IP masquerade on the host for this network. This is necessary if the host will act as a gateway to subnets that are not able to route to the IP assigned to the container.
140 - `ipam` (dictionary): Dictionary with IPAM (IP Address Management) specific values:
141 - `type` (string): Refers to the filename of the IPAM plugin executable. Must not contain characters disallowed in file paths for the system (e.g. / or \\).
142 - `dns` (dictionary, optional): Dictionary with DNS specific values:
143 - `nameservers` (list of strings, optional): list of a priority-ordered list of DNS nameservers that this network is aware of. Each entry in the list is a string containing either an IPv4 or an IPv6 address.
144 - `domain` (string, optional): the local domain used for short hostname lookups.
145 - `search` (list of strings, optional): list of priority ordered search domains for short hostname lookups. Will be preferred over `domain` by most resolvers.
146 - `options` (list of strings, optional): list of options that can be passed to the resolver
147
148 **Other keys:**
149 Plugins may define additional fields that they accept and may generate an error if called with unknown fields. Runtimes must preserve unknown fields in plugin configuration objects when transforming for execution.
150
151 #### Example configuration
152 The following is an example JSON representation of a network configuration `dbnet` with three plugin configurations (`bridge`, `tuning`, and `portmap`).
153 ```jsonc
154 {
155 "cniVersion": "1.1.0",
156 "cniVersions": ["0.3.1", "0.4.0", "1.0.0", "1.1.0"],
157 "name": "dbnet",
158 "plugins": [
159 {
160 "type": "bridge",
161 // plugin specific parameters
162 "bridge": "cni0",
163 "keyA": ["some more", "plugin specific", "configuration"],
164
165 "ipam": {
166 "type": "host-local",
167 // ipam specific
168 "subnet": "10.1.0.0/16",
169 "gateway": "10.1.0.1",
170 "routes": [
171 {"dst": "0.0.0.0/0"}
172 ]
173 },
174 "dns": {
175 "nameservers": [ "10.1.0.1" ]
176 }
177 },
178 {
179 "type": "tuning",
180 "capabilities": {
181 "mac": true
182 },
183 "sysctl": {
184 "net.core.somaxconn": "500"
185 }
186 },
187 {
188 "type": "portmap",
189 "capabilities": {"portMappings": true}
190 }
191 ]
192 }
193 ```
194
195 ### Version considerations
196
197 CNI runtimes, plugins, and network configurations may support multiple CNI specification versions independently. Plugins indicate their set of supported versions through the VERSION command, while network configurations indicate their set of supported versions through the `cniVersion` and `cniVersions` fields.
198
199 CNI runtimes MUST select the highest supported version from the set of network configuration versions given by the `cniVersion` and `cniVersions` fields. Runtimes MAY consider the set of supported plugin versions as reported by the VERSION command when determining available versions.
200
201
202 The CNI protocol follows Semantic Versioning principles, so the configuration format MUST remain backwards and forwards compatible within major versions.
203
204 ## Section 2: Execution Protocol
205
206 ### Overview
207
208 The CNI protocol is based on execution of binaries invoked by the container runtime. CNI defines the protocol between the plugin binary and the runtime.
209
210 A CNI plugin is responsible for configuring a container's network interface in some manner. Plugins fall in to two broad categories:
211 * "Interface" plugins, which create a network interface inside the container and ensure it has connectivity.
212 * "Chained" plugins, which adjust the configuration of an already-created interface (but may need to create more interfaces to do so).
213
214 The runtime passes parameters to the plugin via environment variables and configuration. It supplies configuration via stdin. The plugin returns
215 a [result](#Section-5-Result-Types) on stdout on success, or an error on stderr if the operation fails. Configuration and results are encoded in JSON.
216
217 Parameters define invocation-specific settings, whereas configuration is, with some exceptions, the same for any given network.
218
219 The runtime must execute the plugin in the runtime's networking domain. (For most cases, this means the root network namespace / `dom0`).
220
221 ### Parameters
222
223 Protocol parameters are passed to the plugins via OS environment variables.
224
225 - `CNI_COMMAND`: indicates the desired operation; `ADD`, `DEL`, `CHECK`, `GC`, or `VERSION`.
226 - `CNI_CONTAINERID`: Container ID. A unique plaintext identifier for a container, allocated by the runtime. Must not be empty. Must start with an alphanumeric character, optionally followed by any combination of one or more alphanumeric characters, underscore (), dot (.) or hyphen (-).
227 - `CNI_NETNS`: A reference to the container's "isolation domain". If using network namespaces, then a path to the network namespace (e.g. `/run/netns/[nsname]`)
228 - `CNI_IFNAME`: Name of the interface to create inside the container; if the plugin is unable to use this interface name it must return an error.
229 - `CNI_ARGS`: Extra arguments passed in by the user at invocation time. Alphanumeric key-value pairs separated by semicolons; for example, "FOO=BAR;ABC=123"
230 - `CNI_PATH`: List of paths to search for CNI plugin executables. Paths are separated by an OS-specific list separator; for example ':' on Linux and ';' on Windows
231
232 ### Errors
233 A plugin must exit with a return code of 0 on success, and non-zero on failure. If the plugin encounters an error, it should output an ["error" result structure](#Error) (see below).
234
235 ### CNI operations
236
237 CNI defines 5 operations: `ADD`, `DEL`, `CHECK`, `GC`, and `VERSION`. These are passed to the plugin via the `CNI_COMMAND` environment variable.
238
239 #### `ADD`: Add container to network, or apply modifications
240
241 A CNI plugin, upon receiving an `ADD` command, should either
242 - create the interface defined by `CNI_IFNAME` inside the container at `CNI_NETNS`, or
243 - adjust the configuration of the interface defined by `CNI_IFNAME` inside the container at `CNI_NETNS`.
244
245 If the CNI plugin is successful, it must output a [result structure](#Success) (see below) on standard out. If the plugin was supplied a `prevResult` as part of its input configuration, it MUST handle `prevResult` by either passing it through, or modifying it appropriately.
246
247 If an interface of the requested name already exists in the container, the CNI plugin MUST return with an error.
248
249 A runtime should not call `ADD` twice (without an intervening DEL) for the same `(CNI_CONTAINERID, CNI_IFNAME)` tuple. This implies that a given container ID may be added to a specific network more than once only if each addition is done with a different interface name.
250
251 **Input:**
252
253 The runtime will provide a JSON-serialized plugin configuration object (defined below) on standard in.
254
255 Required environment parameters:
256 - `CNI_COMMAND`
257 - `CNI_CONTAINERID`
258 - `CNI_NETNS`
259 - `CNI_IFNAME`
260
261 Optional environment parameters:
262 - `CNI_ARGS`
263 - `CNI_PATH`
264
265 #### `DEL`: Remove container from network, or un-apply modifications
266
267 A CNI plugin, upon receiving a `DEL` command, should either
268 - delete the interface defined by `CNI_IFNAME` inside the container at `CNI_NETNS`, or
269 - undo any modifications applied in the plugin's `ADD` functionality
270
271 Plugins should generally complete a `DEL` action without error even if some resources are missing. For example, an IPAM plugin should generally release an IP allocation and return success even if the container network namespace no longer exists, unless that network namespace is critical for IPAM management. While DHCP may usually send a 'release' message on the container network interface, since DHCP leases have a lifetime this release action would not be considered critical and no error should be returned if this action fails. For another example, the `bridge` plugin should delegate the DEL action to the IPAM plugin and clean up its own resources even if the container network namespace and/or container network interface no longer exist.
272
273 Plugins MUST accept multiple `DEL` calls for the same (`CNI_CONTAINERID`, `CNI_IFNAME`) pair, and return success if the interface in question, or any modifications added, are missing.
274
275 **Input:**
276
277 The runtime will provide a JSON-serialized plugin configuration object (defined below) on standard in.
278
279 Required environment parameters:
280 - `CNI_COMMAND`
281 - `CNI_CONTAINERID`
282 - `CNI_IFNAME`
283
284 Optional environment parameters:
285 - `CNI_NETNS`
286 - `CNI_ARGS`
287 - `CNI_PATH`
288
289
290 #### `CHECK`: Check container's networking is as expected
291 `CHECK` is a way for a runtime to probe the status of an existing container.
292
293 Plugin considerations:
294 - The plugin must consult the `prevResult` to determine the expected interfaces and addresses.
295 - The plugin must allow for a later chained plugin to have modified networking resources, e.g. routes, on `ADD`.
296 - The plugin should return an error if a resource included in the CNI Result type (interface, address or route) was created by the plugin, and is listed in `prevResult`, but is missing or in an invalid state.
297 - The plugin should return an error if other resources not tracked in the Result type such as the following are missing or are in an invalid state:
298 - Firewall rules
299 - Traffic shaping controls
300 - IP reservations
301 - External dependencies such as a daemon required for connectivity
302 - etc.
303 - The plugin should return an error if it is aware of a condition where the container is generally unreachable.
304 - The plugin must handle `CHECK` being called immediately after an `ADD`, and therefore should allow a reasonable convergence delay for any asynchronous resources.
305 - The plugin should call `CHECK` on any delegated (e.g. IPAM) plugins and pass any errors on to its caller.
306
307
308 Runtime considerations:
309 - A runtime must not call `CHECK` for a container that has not been `ADD`ed, or has been `DEL`eted after its last `ADD`.
310 - A runtime must not call `CHECK` if `disableCheck` is set to `true` in the [configuration](#configuration-format).
311 - A runtime must include a `prevResult` field in the network configuration containing the `Result` of the immediately preceding `ADD` for the container. The runtime may wish to use libcni's support for caching `Result`s.
312 - A runtime may choose to stop executing `CHECK` for a chain when a plugin returns an error.
313 - A runtime may execute `CHECK` from immediately after a successful `ADD`, up until the container is `DEL`eted from the network.
314 - A runtime may assume that a failed `CHECK` means the container is permanently in a misconfigured state.
315
316
317 **Input:**
318
319 The runtime will provide a json-serialized plugin configuration object (defined below) on standard in.
320
321 Required environment parameters:
322 - `CNI_COMMAND`
323 - `CNI_CONTAINERID`
324 - `CNI_NETNS`
325 - `CNI_IFNAME`
326
327 Optional environment parameters:
328 - `CNI_ARGS`
329 - `CNI_PATH`
330
331 All parameters, with the exception of `CNI_PATH`, must be the same as the corresponding `ADD` for this container.
332
333
334 #### `STATUS`: Check plugin status
335 `STATUS` is a way for a runtime to determine the readiness of a network plugin.
336
337 A plugin must exit with a zero (success) return code if the plugin is ready to service ADD requests. If the plugin knows that it is not able to service ADD requests, it must exit with a non-zero return code and output an error on standard out (see below).
338
339 For example, if a plugin relies on an external service or daemon, it should return an error to `STATUS` if that service is unavailable. Likewise, if a plugin has a limited number of resources (e.g. IP addresses, hardware queues), it should return an error if those resources are exhausted and no new `ADD` requests can be serviced.
340
341 The following error codes are defined in the context of `STATUS`:
342
343 - 50: The plugin is not available (i.e. cannot service `ADD` requests)
344 - 51: The plugin is not available, and existing containers in the network may have limited connectivity.
345
346 Plugin considerations:
347 - Status is purely informational. A plugin MUST NOT rely on `STATUS` being called.
348 - Plugins should always expect other CNI operations (like `ADD`, `DEL`, etc) even if `STATUS` returns an error. `STATUS` does not prevent other runtime requests.
349 - If a plugin relies on a delegated plugin (e.g. IPAM) to service `ADD` requests, it must also execute a `STATUS` request to that plugin when it receives a `STATUS` request for itself. If the delegated plugin return an error result, the executing plugin should return an error result.
350
351 **Input:**
352
353 The runtime will provide a json-serialized plugin configuration object (defined below) on standard in.
354
355 Optional environment parameters:
356 - `CNI_PATH`
357
358
359 #### `VERSION`: probe plugin version support
360 The plugin should output via standard-out a json-serialized version result object (see below).
361
362 **Input:**
363
364 A json-serialized object, with the following key:
365 - `cniVersion`: The version of the protocol in use.
366
367 Required environment parameters:
368 - `CNI_COMMAND`
369
370 #### `GC`: Clean up any stale resources
371
372 The GC command provides a way for runtimes to specify the expected set of attachments to a network.
373 The network plugin may then remove any resources related to attachments that do not exist in this set.
374
375 Resources may, for example, include:
376 - IPAM reservations
377 - Firewall rules
378
379 A plugin SHOULD remove as many stale resources as possible. For example, a plugin should remove any IPAM reservations associated with attachments not in the provided list. The plugin MAY assume that the isolation domain (e.g. network namespace) has been deleted, and thus any resources (e.g. network interfaces) therein have been removed.
380
381 Plugins should generally complete a `GC` action without error. If an error is encountered, a plugin should continue; removing as many resources as possible, and report the errors back to the runtime.
382
383 Plugins MUST, additionally, forward any GC calls to delegated plugins they are configured to use (see section 4).
384
385 The runtime MUST NOT use GC as a substitute for DEL. Plugins may be unable to clean up some resources from GC that they would have been able to clean up from DEL.
386
387 **Input:**
388
389 The runtime must provide a JSON-serialized plugin configuration object (defined below) on standard in. It contains an additional key;
390
391 - `cni.dev/valid-attachments` (array of objects): The list of **still valid** attachments to this network:
392 - `containerID` (string): the value of CNI_CONTAINERID as provided during the CNI ADD operation
393 - `ifname` (string): the value of CNI_IFNAME as provided during the CNI ADD operation
394
395 Required environment parameters:
396 - `CNI_COMMAND`
397 - `CNI_PATH`
398
399 **Output:**
400 No output on success, ["error" result structure](#Error) on error.
401
402
403 ## Section 3: Execution of Network Configurations
404
405 This section describes how a container runtime interprets a network configuration (as defined in section 1) and executes plugins accordingly. A runtime may wish to _add_, _delete_, or _check_ a network configuration in a container. This results in a series of plugin `ADD`, `DELETE`, or `CHECK` executions, correspondingly. This section also defines how a network configuration is transformed and provided to the plugin.
406
407 The operation of a network configuration on a container is called an _attachment_. An attachment may be uniquely identified by the `(CNI_CONTAINERID, CNI_IFNAME)` tuple.
408
409 ### Lifecycle & Ordering
410
411 - The container runtime must create a new network namespace for the container before invoking any plugins.
412 - The container runtime must not invoke parallel operations for the same container, but is allowed to invoke parallel operations for different containers. This includes across multiple attachments.
413 - **Exception**: The runtime must exclusively execute either _gc_ or _add_ and _delete_. The runtime must ensure that no _add_ or _delete_ operations are in progress before executing _gc_, and must wait for _gc_ to complete before issuing new _add_ or _delete_ commands.
414 - Plugins must handle being executed concurrently across different containers. If necessary, they must implement locking on shared resources (e.g. IPAM databases).
415 - The container runtime must ensure that _add_ is eventually followed by a corresponding _delete_. The only exception is in the event of catastrophic failure, such as node loss. A _delete_ must still be executed even if the _add_ fails.
416 - _delete_ may be followed by additional _deletes_.
417 - The network configuration should not change between _add_ and _delete_.
418 - The network configuration should not change between _attachments_.
419 - The container runtime is responsible for cleanup of the container's network namespace.
420
421 ### Attachment Parameters
422 While a network configuration should not change between _attachments_, there are certain parameters supplied by the container runtime that are per-attachment. They are:
423
424 - **Container ID:** A unique plaintext identifier for a container, allocated by the runtime. Must not be empty. Must start with an alphanumeric character, optionally followed by any combination of one or more alphanumeric characters, underscore (), dot (.) or hyphen (-). During execution, always set as the `CNI_CONTAINERID` parameter.
425 - **Namespace**: A reference to the container's "isolation domain". If using network namespaces, then a path to the network namespace (e.g. `/run/netns/[nsname]`). During execution, always set as the `CNI_NETNS` parameter.
426 - **Container interface name**: Name of the interface to create inside the container. During execution, always set as the `CNI_IFNAME` parameter.
427 - **Generic Arguments**: Extra arguments, in the form of key-value string pairs, that are relevant to a specific attachment. During execution, always set as the `CNI_ARGS` parameter.
428 - **Capability Arguments**: These are also key-value pairs. The key is a string, whereas the value is any JSON-serializable type. The keys and values are defined by [convention](CONVENTIONS.md).
429
430 Furthermore, the runtime must be provided a list of paths to search for CNI plugins. This must also be provided to plugins during execution via the `CNI_PATH` environment variable.
431
432 ### Adding an attachment
433 For every configuration defined in the `plugins` key of the network configuration,
434 1. Look up the executable specified in the `type` field. If this does not exist, then this is an error.
435 2. Derive request configuration from the plugin configuration, with the following parameters:
436 - If this is the first plugin in the list, no previous result is provided,
437 - For all additional plugins, the previous result is the result of the previous plugins.
438 3. Execute the plugin binary, with `CNI_COMMAND=ADD`. Provide parameters defined above as environment variables. Supply the derived configuration via standard in.
439 4. If the plugin returns an error, halt execution and return the error to the caller.
440
441 The runtime must store the result returned by the final plugin persistently, as it is required for _check_ and _delete_ operations.
442
443 ### Deleting an attachment
444 Deleting a network attachment is much the same as adding, with a few key differences:
445 - The list of plugins is executed in **reverse order**
446 - The previous result provided is always the final result of the _add_ operation.
447
448 For every plugin defined in the `plugins` key of the network configuration, *in reverse order*,
449 1. Look up the executable specified in the `type` field. If this does not exist, then this is an error.
450 2. Derive request configuration from the plugin configuration, with the previous result from the initial _add_ operation.
451 3. Execute the plugin binary, with `CNI_COMMAND=DEL`. Provide parameters defined above as environment variables. Supply the derived configuration via standard in.
452 4. If the plugin returns an error, halt execution and return the error to the caller.
453
454 If all plugins return success, return success to the caller.
455
456 ### Checking an attachment
457 The runtime may also ask every plugin to confirm that a given attachment is still functional. The runtime must use the same attachment parameters as it did for the _add_ operation.
458
459 Checking is similar to add with two exceptions:
460 - the previous result provided is always the final result of the _add_ operation.
461 - If the network configuration defines `disableCheck`, then always return success to the caller.
462
463 For every plugin defined in the `plugins` key of the network configuration,
464 1. Look up the executable specified in the `type` field. If this does not exist, then this is an error.
465 2. Derive request configuration from the plugin configuration, with the previous result from the initial _add_ operation.
466 3. Execute the plugin binary, with `CNI_COMMAND=CHECK`. Provide parameters defined above as environment variables. Supply the derived configuration via standard in.
467 4. If the plugin returns an error, halt execution and return the error to the caller.
468
469 If all plugins return success, return success to the caller.
470
471 ### Garbage-collecting a network
472 The runtime may also ask every plugin in a network configuration to clean up any stale resources via the _GC_ command.
473
474 When garbage-collecting a configuration, there are no [Attachment Parameters](#attachment-parameters).
475
476 For every plugin defined in the `plugins` key of the network configuration,
477 1. Look up the executable specified in the `type` field. If this does not exist, then this is an error.
478 2. Derive request configuration from the plugin configuration.
479 3. Execute the plugin binary, with `CNI_COMMAND=GC`. Supply the derived configuration via standard in.
480 4. If the plugin returns an error, **continue** with execution, returning all errors to the caller.
481
482 If all plugins return success, return success to the caller.
483
484 ### Deriving request configuration from plugin configuration
485 The network configuration format (which is a list of plugin configurations to execute) must be transformed to a format understood by the plugin (which is a single plugin configuration). This section describes that transformation.
486
487 The request configuration for a single plugin invocation is also JSON. It consists of the plugin configuration, primarily unchanged except for the specified additions and removals.
488
489 The following fields are always to be inserted into the request configuration by the runtime:
490 - `cniVersion`: the protocol version selected by the runtime - the string "1.1.0"
491 - `name`: taken from the `name` field of the network configuration
492
493
494 For attachment-specific operations (ADD, DEL, CHECK), additional field requirements apply:
495 - `runtimeConfig`: the runtime must insert an object consisting of the union of capabilities provided by the plugin and requested by the runtime (more details below).
496 - `prevResult`: the runtime must insert consisting of the result type returned by the "previous" plugin. The meaning of "previous" is defined by the specific operation (_add_, _delete_, or _check_). This field must not be set for the first _add_ in a chain.
497 - `capabilities`: must not be set
498
499 For GC operations:
500 - `cni.dev/valid-attachments`: as specified in section 2.
501
502 All other fields not prefixed with `cni.dev/` should be passed through unaltered.
503
504 #### Deriving `runtimeConfig`
505
506 Whereas CNI_ARGS are provided to all plugins, with no indication if they are going to be consumed, _Capability arguments_ need to be declared explicitly in configuration. The runtime, thus, can determine if a given network configuration supports a specific _capability_. Capabilities are not defined by the specification - rather, they are documented [conventions](CONVENTIONS.md).
507
508 As defined in section 1, the plugin configuration includes an optional key, `capabilities`. This example shows a plugin that supports the `portMapping` capability:
509
510 ```json
511 {
512 "type": "myPlugin",
513 "capabilities": {
514 "portMappings": true
515 }
516 }
517 ```
518
519 The `runtimeConfig` parameter is derived from the `capabilities` in the network configuration and the _capability arguments_ generated by the runtime. Specifically, any capability supported by the plugin configuration and provided by the runtime should be inserted in the `runtimeConfig`.
520
521 Thus, the above example could result in the following being passed to the plugin as part of the execution configuration:
522 ```json
523 {
524 "type": "myPlugin",
525 "runtimeConfig": {
526 "portMappings": [ { "hostPort": 8080, "containerPort": 80, "protocol": "tcp" } ]
527 }
528 ...
529 }
530 ```
531
532 ## Section 4: Plugin Delegation
533
534 There are some operations that, for whatever reason, cannot reasonably be implemented as a discrete chained plugin. Rather, a CNI plugin may wish to delegate some functionality to another plugin. One common example of this is IP address management.
535
536 As part of its operation, a CNI plugin is expected to assign (and maintain) an IP address to the interface and install any necessary routes relevant for that interface. This gives the CNI plugin great flexibility but also places a large burden on it. Many CNI plugins would need to have the same code to support several IP management schemes that users may desire (e.g. dhcp, host-local). A CNI plugin may choose to delegate IP management to another plugin.
537
538 To lessen the burden and make IP management strategy be orthogonal to the type of CNI plugin, we define a third type of plugin -- IP Address Management Plugin (IPAM plugin), as well as a protocol for plugins to delegate functionality to other plugins.
539
540 It is however the responsibility of the CNI plugin, rather than the runtime, to invoke the IPAM plugin at the proper moment in its execution. The IPAM plugin must determine the interface IP/subnet, Gateway and Routes and return this information to the "main" plugin to apply. The IPAM plugin may obtain the information via a protocol (e.g. dhcp), data stored on a local filesystem, the "ipam" section of the Network Configuration file, etc.
541
542
543 ### Delegated Plugin protocol
544
545 Like CNI plugins, delegated plugins are invoked by running an executable. The executable is searched for in a predefined list of paths, indicated to the CNI plugin via `CNI_PATH`. The delegated plugin must receive all the same environment variables that were passed in to the CNI plugin. Just like the CNI plugin, delegated plugins receive the network configuration via stdin and output results via stdout.
546
547 Delegated plugins are provided the *complete network configuration* passed to the "upper" plugin. In other words, in the IPAM case, not just the `ipam` section of the configuration.
548
549 Success is indicated by a zero return code and a _Success_ result type output to stdout.
550
551 ### Delegated plugin execution procedure
552
553 When a plugin executes a delegated plugin, it should:
554 - Look up the plugin binary by searching the directories provided in `CNI_PATH` environment variable.
555 - Execute that plugin with the same environment and configuration that it received.
556 - Ensure that the delegated plugin's stderr is output to the calling plugin's stderr.
557
558 If a plugin is executed with `CNI_COMMAND=CHECK`, `DEL`, or `GC`, it must also execute any delegated plugins. If any of the delegated plugins return error, error should be returned by the upper plugin.
559
560 If, on `ADD`, a delegated plugin fails, the "upper" plugin should execute again with `DEL` before returning failure.
561
562 ## Section 5: Result Types
563
564 For certain operations, plugins must output result information. The output should be serialized as JSON on standard out.
565
566 ### ADD Success
567
568 Plugins must output a JSON object with the following keys upon a successful `ADD` operation:
569
570 - `cniVersion`: The same version supplied on input - the string "1.1.0"
571 - `interfaces`: An array of all interfaces created by the attachment, including any host-level interfaces:
572 - `name` (string): The name of the interface.
573 - `mac` (string): The hardware address of the interface (if applicable).
574 - `mtu`: (uint) The MTU of the interface (if applicable).
575 - `sandbox` (string): The isolation domain reference (e.g. path to network namespace) for the interface, or empty if on the host. For interfaces created inside the container, this should be the value passed via `CNI_NETNS`.
576 - `socketPath` (string, optional): An absolute path to a socket file corresponding to this interface, if applicable.
577 - `pciID` (string, optional): The platform-specific identifier of the PCI device corresponding to this interface, if applicable.
578 - `ips`: IPs assigned by this attachment. Plugins may include IPs assigned external to the container.
579 - `address` (string): an IP address in CIDR notation (eg "192.168.1.3/24").
580 - `gateway` (string): the default gateway for this subnet, if one exists.
581 - `interface` (uint): the index into the `interfaces` list for a [CNI Plugin Result](#result) indicating which interface this IP configuration should be applied to.
582 - `routes`: Routes created by this attachment:
583 - `dst`: The destination of the route, in CIDR notation
584 - `gw`: The next hop address. If unset, a value in `gateway` in the `ips` array may be used.
585 - `mtu` (uint): The MTU (Maximum transmission unit) along the path to the destination.
586 - `advmss` (uint): The MSS (Maximal Segment Size) to advertise to these destinations when establishing TCP connections.
587 - `priority` (uint): The priority of route, lower is higher.
588 - `table` (uint): The table to add the route to.
589 - `scope` (uint): The scope of the destinations covered by the route prefix (global (0), link (253), host (254)).
590 - `dns`: a dictionary consisting of DNS configuration information
591 - `nameservers` (list of strings): list of a priority-ordered list of DNS nameservers that this network is aware of. Each entry in the list is a string containing either an IPv4 or an IPv6 address.
592 - `domain` (string): the local domain used for short hostname lookups.
593 - `search` (list of strings): list of priority ordered search domains for short hostname lookups. Will be preferred over `domain` by most resolvers.
594 - `options` (list of strings): list of options that can be passed to the resolver.
595
596 Plugins provided a `prevResult` key as part of their request configuration must output it as their result, with any possible modifications made by that plugin included. If a plugin makes no changes that would be reflected in the _Success result_ type, then it must output a result equivalent to the provided `prevResult`.
597
598 #### Delegated plugins (IPAM)
599 Delegated plugins may omit irrelevant sections.
600
601 Delegated IPAM plugins must return an abbreviated _Success_ object. Specifically, it is missing the `interfaces` array, as well as the `interface` entry in `ips`.
602
603
604 ### VERSION Success
605
606 Plugins must output a JSON object with the following keys upon a `VERSION` operation:
607
608 - `cniVersion`: The value of `cniVersion` specified on input
609 - `supportedVersions`: A list of supported specification versions
610
611 Example:
612 ```json
613 {
614 "cniVersion": "1.0.0",
615 "supportedVersions": [ "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0" ]
616 }
617 ```
618
619 ### Error
620
621 Plugins should output a JSON object with the following keys if they encounter an error:
622
623 - `cniVersion`: The protocol version in use - "1.1.0"
624 - `code`: A numeric error code, see below for reserved codes.
625 - `msg`: A short message characterizing the error.
626 - `details`: A longer message describing the error.
627
628 Example:
629
630 ```json
631 {
632 "cniVersion": "1.1.0",
633 "code": 7,
634 "msg": "Invalid Configuration",
635 "details": "Network 192.168.0.0/31 too small to allocate from."
636 }
637 ```
638
639 Error codes 0-99 are reserved for well-known errors. Values of 100+ can be freely used for plugin specific errors.
640
641 Error Code|Error Description
642 ---|---
643 `1`|Incompatible CNI version
644 `2`|Unsupported field in network configuration. The error message must contain the key and value of the unsupported field.
645 `3`|Container unknown or does not exist. This error implies the runtime does not need to perform any container network cleanup (for example, calling the `DEL` action on the container).
646 `4`|Invalid necessary environment variables, like CNI_COMMAND, CNI_CONTAINERID, etc. The error message must contain the names of invalid variables.
647 `5`|I/O failure. For example, failed to read network config bytes from stdin.
648 `6`|Failed to decode content. For example, failed to unmarshal network config from bytes or failed to decode version info from string.
649 `7`|Invalid network config. If some validations on network configs do not pass, this error will be raised.
650 `11`|Try again later. If the plugin detects some transient condition that should clear up, it can use this code to notify the runtime it should re-try the operation later.
651
652 In addition, stderr can be used for unstructured output such as logs.
653
654 ### Version
655
656 Plugins must output a JSON object with the following keys upon a `VERSION` operation:
657
658 - `cniVersion`: The value of `cniVersion` specified on input
659 - `supportedVersions`: A list of supported specification versions
660
661 Example:
662 ```json
663 {
664 "cniVersion": "1.1.0",
665 "supportedVersions": [ "0.1.0", "0.2.0", "0.3.0", "0.3.1", "0.4.0", "1.0.0", "1.1.0" ]
666 }
667 ```
668
669
670 ## Appendix: Examples
671 We assume the network configuration [shown above](#Example-configuration) in section 1. For this attachment, the runtime produces `portmap` and `mac` capability args, along with the generic argument "argA=foo".
672 The examples uses `CNI_IFNAME=eth0`.
673
674 ### Add example
675
676 The container runtime would perform the following steps for the `add` operation.
677
678
679 1) Call the `bridge` plugin with the following JSON, `CNI_COMMAND=ADD`:
680
681 ```json
682 {
683 "cniVersion": "1.1.0",
684 "name": "dbnet",
685 "type": "bridge",
686 "bridge": "cni0",
687 "keyA": ["some more", "plugin specific", "configuration"],
688 "ipam": {
689 "type": "host-local",
690 "subnet": "10.1.0.0/16",
691 "gateway": "10.1.0.1"
692 },
693 "dns": {
694 "nameservers": [ "10.1.0.1" ]
695 }
696 }
697 ```
698
699 The bridge plugin, as it delegates IPAM to the `host-local` plugin, would execute the `host-local` binary with the exact same input, `CNI_COMMAND=ADD`.
700
701 The `host-local` plugin returns the following result:
702
703 ```json
704 {
705 "ips": [
706 {
707 "address": "10.1.0.5/16",
708 "gateway": "10.1.0.1"
709 }
710 ],
711 "routes": [
712 {
713 "dst": "0.0.0.0/0"
714 }
715 ],
716 "dns": {
717 "nameservers": [ "10.1.0.1" ]
718 }
719 }
720 ```
721
722 The bridge plugin returns the following result, configuring the interface according to the delegated IPAM configuration:
723
724 ```json
725 {
726 "ips": [
727 {
728 "address": "10.1.0.5/16",
729 "gateway": "10.1.0.1",
730 "interface": 2
731 }
732 ],
733 "routes": [
734 {
735 "dst": "0.0.0.0/0"
736 }
737 ],
738 "interfaces": [
739 {
740 "name": "cni0",
741 "mac": "00:11:22:33:44:55"
742 },
743 {
744 "name": "veth3243",
745 "mac": "55:44:33:22:11:11"
746 },
747 {
748 "name": "eth0",
749 "mac": "99:88:77:66:55:44",
750 "sandbox": "/var/run/netns/blue"
751 }
752 ],
753 "dns": {
754 "nameservers": [ "10.1.0.1" ]
755 }
756 }
757 ```
758
759 2) Next, call the `tuning` plugin, with `CNI_COMMAND=ADD`. Note that `prevResult` is supplied, along with the `mac` capability argument. The request configuration passed is:
760
761 ```json
762 {
763 "cniVersion": "1.1.0",
764 "name": "dbnet",
765 "type": "tuning",
766 "sysctl": {
767 "net.core.somaxconn": "500"
768 },
769 "runtimeConfig": {
770 "mac": "00:11:22:33:44:66"
771 },
772 "prevResult": {
773 "ips": [
774 {
775 "address": "10.1.0.5/16",
776 "gateway": "10.1.0.1",
777 "interface": 2
778 }
779 ],
780 "routes": [
781 {
782 "dst": "0.0.0.0/0"
783 }
784 ],
785 "interfaces": [
786 {
787 "name": "cni0",
788 "mac": "00:11:22:33:44:55"
789 },
790 {
791 "name": "veth3243",
792 "mac": "55:44:33:22:11:11"
793 },
794 {
795 "name": "eth0",
796 "mac": "99:88:77:66:55:44",
797 "sandbox": "/var/run/netns/blue"
798 }
799 ],
800 "dns": {
801 "nameservers": [ "10.1.0.1" ]
802 }
803 }
804 }
805 ```
806
807 The plugin returns the following result. Note that the **mac** has changed.
808
809 ```json
810 {
811 "ips": [
812 {
813 "address": "10.1.0.5/16",
814 "gateway": "10.1.0.1",
815 "interface": 2
816 }
817 ],
818 "routes": [
819 {
820 "dst": "0.0.0.0/0"
821 }
822 ],
823 "interfaces": [
824 {
825 "name": "cni0",
826 "mac": "00:11:22:33:44:55"
827 },
828 {
829 "name": "veth3243",
830 "mac": "55:44:33:22:11:11"
831 },
832 {
833 "name": "eth0",
834 "mac": "00:11:22:33:44:66",
835 "sandbox": "/var/run/netns/blue"
836 }
837 ],
838 "dns": {
839 "nameservers": [ "10.1.0.1" ]
840 }
841 }
842 ```
843
844 3) Finally, call the `portmap` plugin, with `CNI_COMMAND=ADD`. Note that `prevResult` matches that returned by `tuning`:
845
846 ```json
847 {
848 "cniVersion": "1.1.0",
849 "name": "dbnet",
850 "type": "portmap",
851 "runtimeConfig": {
852 "portMappings" : [
853 { "hostPort": 8080, "containerPort": 80, "protocol": "tcp" }
854 ]
855 },
856 "prevResult": {
857 "ips": [
858 {
859 "address": "10.1.0.5/16",
860 "gateway": "10.1.0.1",
861 "interface": 2
862 }
863 ],
864 "routes": [
865 {
866 "dst": "0.0.0.0/0"
867 }
868 ],
869 "interfaces": [
870 {
871 "name": "cni0",
872 "mac": "00:11:22:33:44:55"
873 },
874 {
875 "name": "veth3243",
876 "mac": "55:44:33:22:11:11"
877 },
878 {
879 "name": "eth0",
880 "mac": "00:11:22:33:44:66",
881 "sandbox": "/var/run/netns/blue"
882 }
883 ],
884 "dns": {
885 "nameservers": [ "10.1.0.1" ]
886 }
887 }
888 }
889 ```
890
891 The `portmap` plugin outputs the exact same result as that returned by `bridge`, as the plugin has not modified anything that would change the result (i.e. it only created iptables rules).
892
893
894 ### Check example
895
896 Given the previous _Add_, the container runtime would perform the following steps for the _Check_ action:
897
898 1) First call the `bridge` plugin with the following request configuration, including the `prevResult` field containing the final JSON response from the _Add_ operation, **including the changed mac**. `CNI_COMMAND=CHECK`
899
900 ```json
901 {
902 "cniVersion": "1.1.0",
903 "name": "dbnet",
904 "type": "bridge",
905 "bridge": "cni0",
906 "keyA": ["some more", "plugin specific", "configuration"],
907 "ipam": {
908 "type": "host-local",
909 "subnet": "10.1.0.0/16",
910 "gateway": "10.1.0.1"
911 },
912 "dns": {
913 "nameservers": [ "10.1.0.1" ]
914 },
915 "prevResult": {
916 "ips": [
917 {
918 "address": "10.1.0.5/16",
919 "gateway": "10.1.0.1",
920 "interface": 2
921 }
922 ],
923 "routes": [
924 {
925 "dst": "0.0.0.0/0"
926 }
927 ],
928 "interfaces": [
929 {
930 "name": "cni0",
931 "mac": "00:11:22:33:44:55"
932 },
933 {
934 "name": "veth3243",
935 "mac": "55:44:33:22:11:11"
936 },
937 {
938 "name": "eth0",
939 "mac": "00:11:22:33:44:66",
940 "sandbox": "/var/run/netns/blue"
941 }
942 ],
943 "dns": {
944 "nameservers": [ "10.1.0.1" ]
945 }
946 }
947 }
948 ```
949
950 The `bridge` plugin, as it delegates IPAM, calls `host-local`, `CNI_COMMAND=CHECK`. It returns no error.
951
952 Assuming the `bridge` plugin is satisfied, it produces no output on standard out and exits with a 0 return code.
953
954 2) Next call the `tuning` plugin with the following request configuration:
955
956 ```json
957 {
958 "cniVersion": "1.1.0",
959 "name": "dbnet",
960 "type": "tuning",
961 "sysctl": {
962 "net.core.somaxconn": "500"
963 },
964 "runtimeConfig": {
965 "mac": "00:11:22:33:44:66"
966 },
967 "prevResult": {
968 "ips": [
969 {
970 "address": "10.1.0.5/16",
971 "gateway": "10.1.0.1",
972 "interface": 2
973 }
974 ],
975 "routes": [
976 {
977 "dst": "0.0.0.0/0"
978 }
979 ],
980 "interfaces": [
981 {
982 "name": "cni0",
983 "mac": "00:11:22:33:44:55"
984 },
985 {
986 "name": "veth3243",
987 "mac": "55:44:33:22:11:11"
988 },
989 {
990 "name": "eth0",
991 "mac": "00:11:22:33:44:66",
992 "sandbox": "/var/run/netns/blue"
993 }
994 ],
995 "dns": {
996 "nameservers": [ "10.1.0.1" ]
997 }
998 }
999 }
1000 ```
1001
1002 Likewise, the `tuning` plugin exits indicating success.
1003
1004 3) Finally, call `portmap` with the following request configuration:
1005
1006 ```json
1007 {
1008 "cniVersion": "1.1.0",
1009 "name": "dbnet",
1010 "type": "portmap",
1011 "runtimeConfig": {
1012 "portMappings" : [
1013 { "hostPort": 8080, "containerPort": 80, "protocol": "tcp" }
1014 ]
1015 },
1016 "prevResult": {
1017 "ips": [
1018 {
1019 "address": "10.1.0.5/16",
1020 "gateway": "10.1.0.1",
1021 "interface": 2
1022 }
1023 ],
1024 "routes": [
1025 {
1026 "dst": "0.0.0.0/0"
1027 }
1028 ],
1029 "interfaces": [
1030 {
1031 "name": "cni0",
1032 "mac": "00:11:22:33:44:55"
1033 },
1034 {
1035 "name": "veth3243",
1036 "mac": "55:44:33:22:11:11"
1037 },
1038 {
1039 "name": "eth0",
1040 "mac": "00:11:22:33:44:66",
1041 "sandbox": "/var/run/netns/blue"
1042 }
1043 ],
1044 "dns": {
1045 "nameservers": [ "10.1.0.1" ]
1046 }
1047 }
1048 }
1049 ```
1050
1051
1052 ### Delete example
1053
1054 Given the same network configuration JSON list, the container runtime would perform the following steps for the _Delete_ action.
1055 Note that plugins are executed in reverse order from the _Add_ and _Check_ actions.
1056
1057 1) First, call `portmap` with the following request configuration, `CNI_COMMAND=DEL`:
1058
1059 ```json
1060 {
1061 "cniVersion": "1.1.0",
1062 "name": "dbnet",
1063 "type": "portmap",
1064 "runtimeConfig": {
1065 "portMappings" : [
1066 { "hostPort": 8080, "containerPort": 80, "protocol": "tcp" }
1067 ]
1068 },
1069 "prevResult": {
1070 "ips": [
1071 {
1072 "address": "10.1.0.5/16",
1073 "gateway": "10.1.0.1",
1074 "interface": 2
1075 }
1076 ],
1077 "routes": [
1078 {
1079 "dst": "0.0.0.0/0"
1080 }
1081 ],
1082 "interfaces": [
1083 {
1084 "name": "cni0",
1085 "mac": "00:11:22:33:44:55"
1086 },
1087 {
1088 "name": "veth3243",
1089 "mac": "55:44:33:22:11:11"
1090 },
1091 {
1092 "name": "eth0",
1093 "mac": "00:11:22:33:44:66",
1094 "sandbox": "/var/run/netns/blue"
1095 }
1096 ],
1097 "dns": {
1098 "nameservers": [ "10.1.0.1" ]
1099 }
1100 }
1101 }
1102 ```
1103
1104
1105 2) Next, call the `tuning` plugin with the following request configuration, `CNI_COMMAND=DEL`:
1106
1107 ```json
1108 {
1109 "cniVersion": "1.1.0",
1110 "name": "dbnet",
1111 "type": "tuning",
1112 "sysctl": {
1113 "net.core.somaxconn": "500"
1114 },
1115 "runtimeConfig": {
1116 "mac": "00:11:22:33:44:66"
1117 },
1118 "prevResult": {
1119 "ips": [
1120 {
1121 "address": "10.1.0.5/16",
1122 "gateway": "10.1.0.1",
1123 "interface": 2
1124 }
1125 ],
1126 "routes": [
1127 {
1128 "dst": "0.0.0.0/0"
1129 }
1130 ],
1131 "interfaces": [
1132 {
1133 "name": "cni0",
1134 "mac": "00:11:22:33:44:55"
1135 },
1136 {
1137 "name": "veth3243",
1138 "mac": "55:44:33:22:11:11"
1139 },
1140 {
1141 "name": "eth0",
1142 "mac": "00:11:22:33:44:66",
1143 "sandbox": "/var/run/netns/blue"
1144 }
1145 ],
1146 "dns": {
1147 "nameservers": [ "10.1.0.1" ]
1148 }
1149 }
1150 }
1151 ```
1152
1153 3) Finally, call `bridge`:
1154
1155 ```json
1156 {
1157 "cniVersion": "1.1.0",
1158 "name": "dbnet",
1159 "type": "bridge",
1160 "bridge": "cni0",
1161 "keyA": ["some more", "plugin specific", "configuration"],
1162 "ipam": {
1163 "type": "host-local",
1164 "subnet": "10.1.0.0/16",
1165 "gateway": "10.1.0.1"
1166 },
1167 "dns": {
1168 "nameservers": [ "10.1.0.1" ]
1169 },
1170 "prevResult": {
1171 "ips": [
1172 {
1173 "address": "10.1.0.5/16",
1174 "gateway": "10.1.0.1",
1175 "interface": 2
1176 }
1177 ],
1178 "routes": [
1179 {
1180 "dst": "0.0.0.0/0"
1181 }
1182 ],
1183 "interfaces": [
1184 {
1185 "name": "cni0",
1186 "mac": "00:11:22:33:44:55"
1187 },
1188 {
1189 "name": "veth3243",
1190 "mac": "55:44:33:22:11:11"
1191 },
1192 {
1193 "name": "eth0",
1194 "mac": "00:11:22:33:44:66",
1195 "sandbox": "/var/run/netns/blue"
1196 }
1197 ],
1198 "dns": {
1199 "nameservers": [ "10.1.0.1" ]
1200 }
1201 }
1202 }
1203 ```
1204
1205 The bridge plugin executes the `host-local` delegated plugin with `CNI_COMMAND=DEL` before returning.