api: Add consts for predefined networks
Related to:

- https://github.com/docker/cli/pull/4493#discussion_r1298609663
- https://github.com/moby/moby/issues/19421

**- What I did**

Constants for both platform-specific and platform-independent networks are added to the api/network package.

**- A picture of a cute animal (not mandatory but encouraged)**

![](https://cdn.cdnparenting.com/articles/2019/06/01154838/Parrot-Facts-for-Kids-1115777186.webp)
api/types/container/hostconfig_windows.go
package container // import "github.com/docker/docker/api/types/container"

// IsBridge indicates whether container uses the bridge network stack
// in windows it is given the name NAT
func (n NetworkMode) IsBridge() bool {
	return n == "nat"
}

// IsHost indicates whether container uses the host network stack.
// returns false as this is not supported by windows
func (n NetworkMode) IsHost() bool {
	return false
}

// IsUserDefined indicates user-created network
func (n NetworkMode) IsUserDefined() bool {
	return !n.IsDefault() && !n.IsNone() && !n.IsBridge() && !n.IsContainer()
}

// IsValid indicates if an isolation technology is valid
func (i Isolation) IsValid() bool {
	return i.IsDefault() || i.IsHyperV() || i.IsProcess()
}

// NetworkName returns the name of the network stack.
func (n NetworkMode) NetworkName() string {
	if n.IsDefault() {
		return "default"
	} else if n.IsBridge() {
		return "nat"
	} else if n.IsNone() {
		return "none"
	} else if n.IsContainer() {
		return "container"
	} else if n.IsUserDefined() {
		return n.UserDefined()
	}

	return ""
}

package container // import "github.com/docker/docker/api/types/container"

import "github.com/docker/docker/api/types/network"

// IsBridge indicates whether container uses the bridge network stack
// in windows it is given the name NAT
func (n NetworkMode) IsBridge() bool {
	return n == network.NetworkNat
}

// IsHost indicates whether container uses the host network stack.
// returns false as this is not supported by windows
func (n NetworkMode) IsHost() bool {
	return false
}

// IsUserDefined indicates user-created network
func (n NetworkMode) IsUserDefined() bool {
	return !n.IsDefault() && !n.IsNone() && !n.IsBridge() && !n.IsContainer()
}

// IsValid indicates if an isolation technology is valid
func (i Isolation) IsValid() bool {
	return i.IsDefault() || i.IsHyperV() || i.IsProcess()
}

// NetworkName returns the name of the network stack.
func (n NetworkMode) NetworkName() string {
	if n.IsDefault() {
		return network.NetworkDefault
	} else if n.IsBridge() {
		return network.NetworkNat
	} else if n.IsNone() {
		return network.NetworkNone
	} else if n.IsContainer() {
		return "container"
	} else if n.IsUserDefined() {
		return n.UserDefined()
	}

	return ""
}

> Are you still on the fence on that?

Yeah, probably shouldn't block the PR though.

It's just very messy because

- we conflated "mode" and "network-names" (which was intentional, but implementation of that wasn't great in hindsight)
- "default" is horrible, or more specifically, horrible because it's used in some places, but may not work in other places, which also relates to the above (does `docker network create --driver=default` work?)
- for places where we're currently checking for "names" ("modes"), we should more look at _properties_ of the network (is this network "attachable", does it support "x", can it be "created" / instantiated?)
- we still need to look at making some checks platform-independent; i.e. we should probably not allow creating a network named `bridge` on Windows, or vice-versa, a network named `transparent` (or `nat`) on Linux. We currently define some reserved names based on the platform the daemon is running on, but I think we should make those a general "reserved names" (or something like that)

> (does `docker network create --driver=default` work?)

Answering myself: it doesn't

```bash
docker network create --driver=default hellonetwork
Error response from daemon: plugin "default" not found
```