Documentation ¶
Index ¶
- Constants
- func DirectoryFor(thing string) string
- func Execute(cmd *exec.Cmd) int
- func ExecuteWithOutput(cmd *exec.Cmd) (exitCode int, output string)
- func FileExists(path string) bool
- func GenerateCertificate() error
- func GenerateConfigFile(content interface{}) ([]byte, error)
- func GetDarwinMajor() (m int, err error)
- func InstallDirectory() string
- func IsBigSurMin() bool
- func IsRoot() bool
- func MatchPattern(regexpPattern string, content string) (map[string]string, error)
- func NamePatternResults(matches, names []string) (result map[string]string)
- func RootOwned(checkPath string, andOperated bool) bool
- func WriteConfigFile(file string, content interface{}) (err error)
- type CertificatePaths
- type Device
- type DhcpEntry
- type DhcpLeaseFile
- type DhcpReservation
- type InterfacesGetter
- type NatEntry
- type NatFile
- type NatFileMock
- type NatSection
- type NetworkInterface
- type NetworkingFile
- type NetworkingFileMock
- func (n *NetworkingFileMock) AddDhcpReservation(device int, mac, address string) error
- func (n *NetworkingFileMock) AddPortFwd(fwd *PortFwd) error
- func (n *NetworkingFileMock) CreateDevice(params ...string) *Device
- func (n *NetworkingFileMock) GetDeviceByName(devName string) (foundDevice *Device)
- func (n *NetworkingFileMock) GetDeviceBySlot(slotNumber int) (foundDevice *Device)
- func (n *NetworkingFileMock) GetDevices() []*Device
- func (n *NetworkingFileMock) GetPath() string
- func (n *NetworkingFileMock) GetPortFwds() []*PortFwd
- func (n *NetworkingFileMock) HostPortFwd(port int, protocol string) *PortFwd
- func (n *NetworkingFileMock) Load() error
- func (n *NetworkingFileMock) LookupDhcpReservation(device int, mac string) (addr string, err error)
- func (n *NetworkingFileMock) Merge(netF NetworkingFile) error
- func (n *NetworkingFileMock) MergeFwds(fwds []*PortFwd) error
- func (n *NetworkingFileMock) PortfwdExists(fwd *PortFwd) bool
- func (n *NetworkingFileMock) RemoveDeviceByName(devName string) error
- func (n *NetworkingFileMock) RemoveDeviceBySlot(slotNumber int) error
- func (n *NetworkingFileMock) RemovePortFwd(fwd *PortFwd) error
- func (n *NetworkingFileMock) Save() (string, error)
- type PortFwd
- type RoutingDevice
- type RoutingTable
- type VMWareNatFile
- type VMWareNetworkingFile
- func (n *VMWareNetworkingFile) AddDhcpReservation(device int, mac, address string) error
- func (n *VMWareNetworkingFile) AddPortFwd(fwd *PortFwd) error
- func (n *VMWareNetworkingFile) CreateDevice(params ...string) *Device
- func (n *VMWareNetworkingFile) GetDeviceByName(devName string) (foundDevice *Device)
- func (n *VMWareNetworkingFile) GetDeviceBySlot(slotNumber int) (foundDevice *Device)
- func (n *VMWareNetworkingFile) GetDevices() []*Device
- func (n *VMWareNetworkingFile) GetPath() string
- func (n *VMWareNetworkingFile) GetPortFwds() []*PortFwd
- func (n *VMWareNetworkingFile) HostPortFwd(port int, protocol string) *PortFwd
- func (n *VMWareNetworkingFile) Load() error
- func (n *VMWareNetworkingFile) LookupDhcpReservation(device int, mac string) (addr string, err error)
- func (n *VMWareNetworkingFile) Merge(netF NetworkingFile) error
- func (n *VMWareNetworkingFile) MergeFwds(fwds []*PortFwd) error
- func (n *VMWareNetworkingFile) PortfwdExists(fwd *PortFwd) bool
- func (n *VMWareNetworkingFile) RemoveDeviceByName(devName string) error
- func (n *VMWareNetworkingFile) RemoveDeviceBySlot(slotNumber int) error
- func (n *VMWareNetworkingFile) RemovePortFwd(fwd *PortFwd) error
- func (n *VMWareNetworkingFile) Save() (string, error)
- type VmwarePaths
Constants ¶
const ADAPTER_PATTERN = `(?i)^answer\s+VNET_(?P<slot_number>\d+)_(?P<key>[a-z0-9_]+)\s+(?P<value>.+?)$`
const CERTIFICATE_EXPIRES_IN = 10
number of years until certificate expiry
const DHCP_RES_PATTERN = `(?i)^add_dhcp_mac_to_ip (?P<device>\d+)\s+(?P<mac>[^\s]+)\s+(?P<address>.+?)$`
const MACOS_END_PATTERN = `` // No time in lease
const MACOS_HOSTNAME_PATTERN = `(?im)name=(?P<hostname>[^\s]+)`
const MACOS_LEASE_PATTERN = `(?ims)^\{(?P<info>.+?ip_address=(?P<address>\d+.\d+.\d+.\d+).+?)\}`
const MACOS_MAC_PATTERN = `(?im)hw_address=.*,(?P<mac>[^\s]+)`
const MACOS_START_PATTERN = `` // No time in lease
const MACOS_TIME_FORMAT = `2006/01/02 15:04:05` // This isn't used, no time information in leases
Patterns used for macOS provided networking + dhcpd
const PORTFWD_PATTERN = `` /* 159-byte string literal not displayed */
const VMWARE_END_PATTERN = `(?im)^\s+ends\s+(?P<end_weekday>\d)\s+(?P<end_date>[^;]+);\s*`
const VMWARE_HOSTNAME_PATTERN = `(?im)^\s+client-hostname\s+"(?P<hostname>[^"]+)";`
const VMWARE_LEASE_FILE_PREFIX = "/var/db/vmware"
Path prefix for where VMware DHCP file is located
const VMWARE_LEASE_PATTERN = `(?ims)^\s*lease\s+(?P<address>\d+.\d+.\d+.\d+)\s*\{(?P<info>.+?)\}`
const VMWARE_MAC_PATTERN = `(?im)^\s+hardware\s+ethernet\s+(?P<mac>[^;]+);\s*`
const VMWARE_START_PATTERN = `(?im)^\s+starts\s+(?P<start_weekday>\d)\s+(?P<start_date>[^;]+);\s*`
const VMWARE_TIME_FORMAT = `2006/01/02 15:04:05`
Patterns used for VMware provided networking + dhcpd
Variables ¶
This section is empty.
Functions ¶
func DirectoryFor ¶
func ExecuteWithOutput ¶
Runs the given command and returns combined stdout/stderr output
func FileExists ¶
func GenerateCertificate ¶
func GenerateCertificate() error
func GenerateConfigFile ¶
func GetDarwinMajor ¶
func InstallDirectory ¶
func InstallDirectory() string
func IsBigSurMin ¶
func IsBigSurMin() bool
func MatchPattern ¶
func NamePatternResults ¶
func RootOwned ¶
Check if a given file is owned by the root user, with write access restricted to the root user, and optionally if the given path is executable by root.
func WriteConfigFile ¶
Types ¶
type CertificatePaths ¶
type CertificatePaths struct { Certificate string PrivateKey string ClientCertificate string ClientKey string }
func GetCertificatePaths ¶
func GetCertificatePaths() (*CertificatePaths, error)
Paths are based on platform. If the platform can't be detected then we just use the executable's directory as the base and create a certificate directory within.
type DhcpEntry ¶
type DhcpEntry struct { Address string Mac string Hostname string Created time.Time Expires time.Time }
func (*DhcpEntry) NormalizeMac ¶
func (d *DhcpEntry) NormalizeMac()
type DhcpLeaseFile ¶
type DhcpLeaseFile struct { Path string Entries []*DhcpEntry // contains filtered or unexported fields }
func LoadDhcpLeaseFile ¶
func LoadDhcpLeaseFile(path string, logger hclog.Logger) (leaseFile *DhcpLeaseFile, err error)
func (*DhcpLeaseFile) AddEntry ¶
func (d *DhcpLeaseFile) AddEntry(entry *DhcpEntry) error
func (*DhcpLeaseFile) Load ¶
func (d *DhcpLeaseFile) Load() error
type DhcpReservation ¶
type InterfacesGetter ¶
type InterfacesGetter func() ([]NetworkInterface, error)
type NatFile ¶
type NatFile interface { Load() error Save() error GetSection(name string) NatSection }
type NatFileMock ¶
type NatFileMock struct { Path string Sections []*NatSection }
func LoadNatFileMock ¶
func LoadNatFileMock(path string, sections []*NatSection) *NatFileMock
func (*NatFileMock) GetSection ¶
func (n *NatFileMock) GetSection(name string) *NatSection
func (*NatFileMock) Load ¶
func (n *NatFileMock) Load() error
func (*NatFileMock) Save ¶
func (n *NatFileMock) Save() error
type NatSection ¶
func (*NatSection) DeleteEntry ¶
func (s *NatSection) DeleteEntry(entry *NatEntry) error
Remove NAT entry from NAT section
func (*NatSection) DeleteEntryAt ¶
func (s *NatSection) DeleteEntryAt(idx int) error
Remove NAT entry from NAT section by index
type NetworkInterface ¶
type NetworkInterface struct {
// contains filtered or unexported fields
}
func (*NetworkInterface) Addrs ¶
func (ni *NetworkInterface) Addrs() []net.Addr
func (*NetworkInterface) Name ¶
func (ni *NetworkInterface) Name() string
type NetworkingFile ¶
type NetworkingFile interface { AddDhcpReservation(device int, mac, address string) error AddPortFwd(fwd *PortFwd) error CreateDevice(params ...string) *Device GetDeviceByName(devName string) (foundDevice *Device) GetDeviceBySlot(slotNumber int) (foundDevice *Device) GetPath() string GetPortFwds() []*PortFwd GetDevices() []*Device HostPortFwd(port int, protocol string) *PortFwd Load() error LookupDhcpReservation(device int, mac string) (addr string, err error) Merge(netF NetworkingFile) error MergeFwds(fwds []*PortFwd) error PortfwdExists(fwd *PortFwd) bool RemovePortFwd(fwd *PortFwd) error RemoveDeviceByName(devName string) error RemoveDeviceBySlot(slotNumber int) error Save() (string, error) }
type NetworkingFileMock ¶
type NetworkingFileMock struct { Path string Devices []*Device DhcpReservations []*DhcpReservation PortFwds []*PortFwd }
func LoadNetworkingFileMock ¶
func LoadNetworkingFileMock(path string, devices []*Device, dhcp []*DhcpReservation, portfwds []*PortFwd) (*NetworkingFileMock, error)
Loads the networking file at the given path and parses the network adapters defined within the file
func (*NetworkingFileMock) AddDhcpReservation ¶
func (n *NetworkingFileMock) AddDhcpReservation(device int, mac, address string) error
func (*NetworkingFileMock) AddPortFwd ¶
func (n *NetworkingFileMock) AddPortFwd(fwd *PortFwd) error
Add a new port forward
func (*NetworkingFileMock) CreateDevice ¶
func (n *NetworkingFileMock) CreateDevice(params ...string) *Device
func (*NetworkingFileMock) GetDeviceByName ¶
func (n *NetworkingFileMock) GetDeviceByName(devName string) (foundDevice *Device)
Find defined adapter with given name
func (*NetworkingFileMock) GetDeviceBySlot ¶
func (n *NetworkingFileMock) GetDeviceBySlot(slotNumber int) (foundDevice *Device)
Find defined adapter with given slot number
func (*NetworkingFileMock) GetDevices ¶
func (n *NetworkingFileMock) GetDevices() []*Device
func (*NetworkingFileMock) GetPath ¶
func (n *NetworkingFileMock) GetPath() string
func (*NetworkingFileMock) GetPortFwds ¶
func (n *NetworkingFileMock) GetPortFwds() []*PortFwd
func (*NetworkingFileMock) HostPortFwd ¶
func (n *NetworkingFileMock) HostPortFwd(port int, protocol string) *PortFwd
func (*NetworkingFileMock) Load ¶
func (n *NetworkingFileMock) Load() error
func (*NetworkingFileMock) LookupDhcpReservation ¶
func (n *NetworkingFileMock) LookupDhcpReservation(device int, mac string) (addr string, err error)
func (*NetworkingFileMock) Merge ¶
func (n *NetworkingFileMock) Merge(netF NetworkingFile) error
func (*NetworkingFileMock) MergeFwds ¶
func (n *NetworkingFileMock) MergeFwds(fwds []*PortFwd) error
func (*NetworkingFileMock) PortfwdExists ¶
func (n *NetworkingFileMock) PortfwdExists(fwd *PortFwd) bool
func (*NetworkingFileMock) RemoveDeviceByName ¶
func (n *NetworkingFileMock) RemoveDeviceByName(devName string) error
Remove a defined adapter with given name
func (*NetworkingFileMock) RemoveDeviceBySlot ¶
func (n *NetworkingFileMock) RemoveDeviceBySlot(slotNumber int) error
Remove a defined adapter with given slot number
func (*NetworkingFileMock) RemovePortFwd ¶
func (n *NetworkingFileMock) RemovePortFwd(fwd *PortFwd) error
Remove a port forward
func (*NetworkingFileMock) Save ¶
func (n *NetworkingFileMock) Save() (string, error)
type RoutingDevice ¶
func (*RoutingDevice) Match ¶
func (r *RoutingDevice) Match(network string) bool
type RoutingTable ¶
type RoutingTable struct { Devices []*RoutingDevice // contains filtered or unexported fields }
func LoadRoutingTable ¶
func LoadRoutingTable(igetter InterfacesGetter, logger hclog.Logger) (table *RoutingTable, err error)
func (*RoutingTable) DeviceByName ¶
func (r *RoutingTable) DeviceByName(name string) *RoutingDevice
func (*RoutingTable) Load ¶
func (r *RoutingTable) Load() error
type VMWareNatFile ¶
type VMWareNatFile struct { Path string Sections []*NatSection // contains filtered or unexported fields }
func LoadNatFile ¶
func LoadNatFile(path string, logger hclog.Logger) (*VMWareNatFile, error)
Load and parse the nat.conf file
func (*VMWareNatFile) GetSection ¶
func (n *VMWareNatFile) GetSection(name string) *NatSection
Get NAT configuration section by name
type VMWareNetworkingFile ¶
type VMWareNetworkingFile struct { Path string Devices []*Device DhcpReservations []*DhcpReservation PortFwds []*PortFwd // contains filtered or unexported fields }
func LoadNetworkingFile ¶
func LoadNetworkingFile(path string, logger hclog.Logger) (*VMWareNetworkingFile, error)
Loads the networking file at the given path and parses the network adapters defined within the file
func (*VMWareNetworkingFile) AddDhcpReservation ¶
func (n *VMWareNetworkingFile) AddDhcpReservation(device int, mac, address string) error
Add a new DHCP reservation
func (*VMWareNetworkingFile) AddPortFwd ¶
func (n *VMWareNetworkingFile) AddPortFwd(fwd *PortFwd) error
Add a new port forward
func (*VMWareNetworkingFile) CreateDevice ¶
func (n *VMWareNetworkingFile) CreateDevice(params ...string) *Device
Creates a new virtual network adapter. If the adapter should be host only two parameters can be provided to configure: HostonlyNetmask - Ex: "255.255.255.0" HostonlySubnet - Ex: "172.32.3.0"
func (*VMWareNetworkingFile) GetDeviceByName ¶
func (n *VMWareNetworkingFile) GetDeviceByName(devName string) (foundDevice *Device)
Find defined adapter with given name
func (*VMWareNetworkingFile) GetDeviceBySlot ¶
func (n *VMWareNetworkingFile) GetDeviceBySlot(slotNumber int) (foundDevice *Device)
Find defined adapter with given slot number
func (*VMWareNetworkingFile) GetDevices ¶
func (n *VMWareNetworkingFile) GetDevices() []*Device
func (*VMWareNetworkingFile) GetPath ¶
func (n *VMWareNetworkingFile) GetPath() string
func (*VMWareNetworkingFile) GetPortFwds ¶
func (n *VMWareNetworkingFile) GetPortFwds() []*PortFwd
func (*VMWareNetworkingFile) HostPortFwd ¶
func (n *VMWareNetworkingFile) HostPortFwd(port int, protocol string) *PortFwd
func (*VMWareNetworkingFile) Load ¶
func (n *VMWareNetworkingFile) Load() error
Parses the defined networking configuration file. This can also be used to "reload" if the file may have changed.
func (*VMWareNetworkingFile) LookupDhcpReservation ¶
func (n *VMWareNetworkingFile) LookupDhcpReservation(device int, mac string) (addr string, err error)
Lookup a DHCP reservation
func (*VMWareNetworkingFile) Merge ¶
func (n *VMWareNetworkingFile) Merge(netF NetworkingFile) error
This merges a networking file into the current networking file. Useful in places like Linux with Workstation where we lose all metadata within the actual networking file when settings are updated. NOTE: This only merges in port forward directives
func (*VMWareNetworkingFile) MergeFwds ¶
func (n *VMWareNetworkingFile) MergeFwds(fwds []*PortFwd) error
func (*VMWareNetworkingFile) PortfwdExists ¶
func (n *VMWareNetworkingFile) PortfwdExists(fwd *PortFwd) bool
Check if a port forward has already been added
func (*VMWareNetworkingFile) RemoveDeviceByName ¶
func (n *VMWareNetworkingFile) RemoveDeviceByName(devName string) error
Remove a defined adapter with given name
func (*VMWareNetworkingFile) RemoveDeviceBySlot ¶
func (n *VMWareNetworkingFile) RemoveDeviceBySlot(slotNumber int) error
Remove a defined adapter with given slot number
func (*VMWareNetworkingFile) RemovePortFwd ¶
func (n *VMWareNetworkingFile) RemovePortFwd(fwd *PortFwd) error
Remove a port forward
func (*VMWareNetworkingFile) Save ¶
func (n *VMWareNetworkingFile) Save() (string, error)
Saves the current configuration to the networking file at defined path
type VmwarePaths ¶
type VmwarePaths struct { BridgePid string `json:"bridge_pid"` DhcpLease string `json:"dhcp_lease"` InstallDir string `json:"install_dir"` NatConf string `json:"nat_conf"` Networking string `json:"networking"` Services string `json:"services"` VmnetCli string `json:"vmnet_cli"` Vnetlib string `json:"vnetlib"` Vmx string `json:"vmx"` Vmrun string `json:"vmrun"` Vmrest string `json:"vmrest"` Vdiskmanager string `json:"vdiskmanager"` // contains filtered or unexported fields }
func LoadVmwarePaths ¶
func LoadVmwarePaths(logger hclog.Logger) (*VmwarePaths, error)
func (*VmwarePaths) DhcpLeaseFile ¶
func (v *VmwarePaths) DhcpLeaseFile(device string) string
func (*VmwarePaths) Load ¶
func (v *VmwarePaths) Load() (err error)
func (*VmwarePaths) NatConfFile ¶
func (v *VmwarePaths) NatConfFile(device string) string
func (*VmwarePaths) UpdateVmwareDhcpLeasePath ¶
func (v *VmwarePaths) UpdateVmwareDhcpLeasePath(version string) error