github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/libpod/network/config.go (about) 1 package network 2 3 import ( 4 "encoding/json" 5 "net" 6 7 "github.com/containers/storage/pkg/lockfile" 8 ) 9 10 // TODO once the containers.conf file stuff is worked out, this should be modified 11 // to honor defines in the containers.conf as well as overrides? 12 13 const ( 14 // CNIConfigDir is the path where CNI config files exist 15 CNIConfigDir = "/etc/cni/net.d" 16 // CNIDeviceName is the default network device name and in 17 // reality should have an int appended to it (cni-podman4) 18 CNIDeviceName = "cni-podman" 19 // DefaultPodmanDomainName is used for the dnsname plugin to define 20 // a localized domain name for a created network 21 DefaultPodmanDomainName = "dns.podman" 22 // LockFileName is used for obtaining a lock and is appended 23 // to libpod's tmpdir in practice 24 LockFileName = "cni.lock" 25 ) 26 27 // CNILock is for preventing name collision and 28 // unpredictable results when doing some CNI operations. 29 type CNILock struct { 30 lockfile.Locker 31 } 32 33 // GetDefaultPodmanNetwork outputs the default network for podman 34 func GetDefaultPodmanNetwork() (*net.IPNet, error) { 35 _, n, err := net.ParseCIDR("10.88.1.0/24") 36 return n, err 37 } 38 39 // CNIPlugins is a way of marshalling a CNI network configuration to disk 40 type CNIPlugins interface { 41 Bytes() ([]byte, error) 42 } 43 44 // HostLocalBridge describes a configuration for a bridge plugin 45 // https://github.com/containernetworking/plugins/tree/master/plugins/main/bridge#network-configuration-reference 46 type HostLocalBridge struct { 47 PluginType string `json:"type"` 48 BrName string `json:"bridge,omitempty"` 49 IsGW bool `json:"isGateway"` 50 IsDefaultGW bool `json:"isDefaultGateway,omitempty"` 51 ForceAddress bool `json:"forceAddress,omitempty"` 52 IPMasq bool `json:"ipMasq,omitempty"` 53 MTU int `json:"mtu,omitempty"` 54 HairpinMode bool `json:"hairpinMode,omitempty"` 55 PromiscMode bool `json:"promiscMode,omitempty"` 56 Vlan int `json:"vlan,omitempty"` 57 IPAM IPAMHostLocalConf `json:"ipam"` 58 } 59 60 // Bytes outputs []byte 61 func (h *HostLocalBridge) Bytes() ([]byte, error) { 62 return json.MarshalIndent(h, "", "\t") 63 } 64 65 // IPAMHostLocalConf describes an IPAM configuration 66 // https://github.com/containernetworking/plugins/tree/master/plugins/ipam/host-local#network-configuration-reference 67 type IPAMHostLocalConf struct { 68 PluginType string `json:"type"` 69 Routes []IPAMRoute `json:"routes,omitempty"` 70 ResolveConf string `json:"resolveConf,omitempty"` 71 DataDir string `json:"dataDir,omitempty"` 72 Ranges [][]IPAMLocalHostRangeConf `json:"ranges,omitempty"` 73 } 74 75 // IPAMLocalHostRangeConf describes the new style IPAM ranges 76 type IPAMLocalHostRangeConf struct { 77 Subnet string `json:"subnet"` 78 RangeStart string `json:"rangeStart,omitempty"` 79 RangeEnd string `json:"rangeEnd,omitempty"` 80 Gateway string `json:"gateway,omitempty"` 81 } 82 83 // Bytes outputs the configuration as []byte 84 func (i IPAMHostLocalConf) Bytes() ([]byte, error) { 85 return json.MarshalIndent(i, "", "\t") 86 } 87 88 // IPAMRoute describes a route in an ipam config 89 type IPAMRoute struct { 90 Dest string `json:"dst"` 91 } 92 93 // PortMapConfig describes the default portmapping config 94 type PortMapConfig struct { 95 PluginType string `json:"type"` 96 Capabilities map[string]bool `json:"capabilities"` 97 } 98 99 // Bytes outputs the configuration as []byte 100 func (p PortMapConfig) Bytes() ([]byte, error) { 101 return json.MarshalIndent(p, "", "\t") 102 } 103 104 // IPAMDHCP describes the ipamdhcp config 105 type IPAMDHCP struct { 106 DHCP string `json:"type"` 107 } 108 109 // MacVLANConfig describes the macvlan config 110 type MacVLANConfig struct { 111 PluginType string `json:"type"` 112 Master string `json:"master"` 113 IPAM IPAMDHCP `json:"ipam"` 114 } 115 116 // Bytes outputs the configuration as []byte 117 func (p MacVLANConfig) Bytes() ([]byte, error) { 118 return json.MarshalIndent(p, "", "\t") 119 } 120 121 // FirewallConfig describes the firewall plugin 122 type FirewallConfig struct { 123 PluginType string `json:"type"` 124 Backend string `json:"backend"` 125 } 126 127 // Bytes outputs the configuration as []byte 128 func (f FirewallConfig) Bytes() ([]byte, error) { 129 return json.MarshalIndent(f, "", "\t") 130 } 131 132 // TuningConfig describes the tuning plugin 133 type TuningConfig struct { 134 PluginType string `json:"type"` 135 } 136 137 // Bytes outputs the configuration as []byte 138 func (f TuningConfig) Bytes() ([]byte, error) { 139 return json.MarshalIndent(f, "", "\t") 140 } 141 142 // DNSNameConfig describes the dns container name resolution plugin config 143 type DNSNameConfig struct { 144 PluginType string `json:"type"` 145 DomainName string `json:"domainName"` 146 Capabilities map[string]bool `json:"capabilities"` 147 } 148 149 // Bytes outputs the configuration as []byte 150 func (d DNSNameConfig) Bytes() ([]byte, error) { 151 return json.MarshalIndent(d, "", "\t") 152 }