github.com/AbhinandanKurakure/podman/v3@v3.4.10/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         IPAMConfig `json:"ipam"`
    58  }
    59  
    60  // Bytes outputs []byte
    61  func (h *HostLocalBridge) Bytes() ([]byte, error) {
    62  	return json.MarshalIndent(h, "", "\t")
    63  }
    64  
    65  // IPAMConfig describes an IPAM configuration
    66  // https://github.com/containernetworking/plugins/tree/master/plugins/ipam/host-local#network-configuration-reference
    67  type IPAMConfig 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 IPAMConfig) 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  // MacVLANConfig describes the macvlan config
   105  type MacVLANConfig struct {
   106  	PluginType string     `json:"type"`
   107  	Master     string     `json:"master"`
   108  	IPAM       IPAMConfig `json:"ipam"`
   109  	MTU        int        `json:"mtu,omitempty"`
   110  }
   111  
   112  // Bytes outputs the configuration as []byte
   113  func (p MacVLANConfig) Bytes() ([]byte, error) {
   114  	return json.MarshalIndent(p, "", "\t")
   115  }
   116  
   117  // FirewallConfig describes the firewall plugin
   118  type FirewallConfig struct {
   119  	PluginType string `json:"type"`
   120  	Backend    string `json:"backend"`
   121  }
   122  
   123  // Bytes outputs the configuration as []byte
   124  func (f FirewallConfig) Bytes() ([]byte, error) {
   125  	return json.MarshalIndent(f, "", "\t")
   126  }
   127  
   128  // TuningConfig describes the tuning plugin
   129  type TuningConfig struct {
   130  	PluginType string `json:"type"`
   131  }
   132  
   133  // Bytes outputs the configuration as []byte
   134  func (f TuningConfig) Bytes() ([]byte, error) {
   135  	return json.MarshalIndent(f, "", "\t")
   136  }
   137  
   138  // DNSNameConfig describes the dns container name resolution plugin config
   139  type DNSNameConfig struct {
   140  	PluginType   string          `json:"type"`
   141  	DomainName   string          `json:"domainName"`
   142  	Capabilities map[string]bool `json:"capabilities"`
   143  }
   144  
   145  //  PodmanMachineConfig enables port handling on the host OS
   146  type PodmanMachineConfig struct {
   147  	PluginType   string          `json:"type"`
   148  	Capabilities map[string]bool `json:"capabilities"`
   149  }
   150  
   151  // Bytes outputs the configuration as []byte
   152  func (d DNSNameConfig) Bytes() ([]byte, error) {
   153  	return json.MarshalIndent(d, "", "\t")
   154  }
   155  
   156  // Bytes outputs the configuration as []byte
   157  func (p PodmanMachineConfig) Bytes() ([]byte, error) {
   158  	return json.MarshalIndent(p, "", "\t")
   159  }