networking

package
v2.10.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR_NO_IF                   = 0x1
	ERROR_INVALID_SETTINGS        = 0x2
	ERROR_SOCKET_ERROR            = 0x3
	ERROR_NETWORK_TIMEOUT         = 0x4
	ERROR_GENERAL_INTERFACE_ERROR = 0x5
	ERROR_NO_RESPONSE_TIMEOUT     = 0x7
	ERROR_DHCP_INVALID_LEASE      = 0xF01
)
View Source
const (
	IFA_F_DADFAILED   = 0x8
	IFA_F_DEPRECATED  = 0x20
	IFA_F_HOMEADDRESS = 0x10
	IFA_F_NODAD       = 0x2
	IFA_F_OPTIMISTIC  = 0x4
	IFA_F_PERMANENT   = 0x80
	IFA_F_SECONDARY   = 0x1
	IFA_F_TEMPORARY   = 0x1
	IFA_F_TENTATIVE   = 0x40
	IFA_MAX           = 0x7
	IFF_ALLMULTI      = 0x200
	IFF_AUTOMEDIA     = 0x4000
	IFF_BROADCAST     = 0x2
	IFF_DEBUG         = 0x4
	IFF_DYNAMIC       = 0x8000
	IFF_LOOPBACK      = 0x8
	IFF_MASTER        = 0x400
	IFF_MULTICAST     = 0x1000
	IFF_NOARP         = 0x80
	IFF_NOTRAILERS    = 0x20
	IFF_NO_PI         = 0x1000
	IFF_ONE_QUEUE     = 0x2000
	IFF_POINTOPOINT   = 0x10
	IFF_PORTSEL       = 0x2000
	IFF_PROMISC       = 0x100
	IFF_RUNNING       = 0x40
	IFF_SLAVE         = 0x800
	IFF_TAP           = 0x2
	IFF_TUN           = 0x1
	IFF_TUN_EXCL      = 0x8000
	IFF_UP            = 0x1
	IFF_VNET_HDR      = 0x4000
)

NOTE: these should be defined in newer go, in

View Source
const (
	DHCP_NETWORK_FAILURE_TIMEOUT_DURATION time.Duration = 30 * time.Second
	// used when an interface goes down, then back up, etc.
	DHCP_NET_TRANSITION_TIMEOUT time.Duration = 2 * time.Second

	// public event names
	INTERFACE_READY = 0x10F2
	INTERFACE_DOWN  = 0x10F3
)
View Source
const DDB_NETWORK_CONFIG_COMMIT_FLAG string = "MAESTRO_NETWORK_CONFIG_COMMIT_FLAG"
View Source
const DDB_NETWORK_CONFIG_CONFIG_GROUP_ID string = "netgroup"
View Source
const DDB_NETWORK_CONFIG_NAME string = "MAESTRO_NETWORK_CONFIG_ID"
View Source
const (
	LOG_PREFIX = "NetworkManager: "
)

Variables

View Source
var ErrNoInterface = errors.New("no interface")

ErrNoInterface is the error when no interface can be found by the reference data

Functions

func AddLTEInterface

func AddLTEInterface(ifName string, connectionName string, apn string) error

AddLTEInterface adds a network interface for the modem

func AppendDNSResolver

func AppendDNSResolver(ifconfig *maestroSpecs.NetIfConfigPayload, leaseinfo *DhcpLeaseInfo, dnsFileBuffer *dnsBuf, commentonly bool) (dnsset bool, primaryDNS string, err error)

AppendDNSResolver will find the resolver info, and append it to the dnsFileBuffer bytes.Buffer. If successful, dnsset will return true, primaryDNS will return the primary DNS server to use, and err will be nil. ifconfig data will take precedence over the DhcpLeaseInfo data. If ifconfig has no DNS information, then the leaseinfo data will be used, if available.

func AvailableModems

func AvailableModems() ([]string, error)

AvailableModems returns array of string names for all available modems

func BringUpModem

func BringUpModem(connectionName string) error

func ClearAllAddressesByLinkName

func ClearAllAddressesByLinkName(name string, exceptions []net.IP) (err error)

Clear all address on an interface, with exception of exception list

func ConfigApplyHandler

func ConfigApplyHandler(jobConfigApplyRequestChan <-chan bool)

This is the go routine which waits on jobConfigApplyRequestChan and when it receives an updated config it submits the config and sets up the interfaces based on new configuration

func ConfigChangeHandler

func ConfigChangeHandler(jobConfigChangeChan <-chan ConfigChangeInfo)

This is the go routine which waits on configChangeRequestChan and when it receives a message which is ConfigChangeInfo object, it calls corresponding process functions(see below) based on config group.

func ConnectModem

func ConnectModem(index string, serial string, connectionName string, apn string) error

func ConnectToWifi

func ConnectToWifi(ifname string, wifissid string, wifipassword string) (status string, ip string, errout error)

func DisconnectWifi

func DisconnectWifi(ifname string) (status string, errout error)

func GetInstance

func GetInstance() *networkManagerInstance

func GetInterfaceIndexAndName

func GetInterfaceIndexAndName(ifname string, ifindex int) (retifname string, retifindex int, err error)

GetInterfaceIndexAndName lets you pass in either an ifname string, with the network interface name, or a valid index. The function will return both the index and name, or error if such inteface does not exist. Prefers looking up by name first, if len(ifname) < 0 it will look up by index

func GetInterfaceLink(ifname string, ifindex int) (ret netlink.Link, err error)

GetInterfaceLink lets you pass in either an ifname string, with the network interface name, or a valid index. The function will return a netlink.Link, or error if such inteface does not exist. Prefers looking up by name first, if len(ifname) < 0 it will look up by index

func GetInterfaceMacAddress

func GetInterfaceMacAddress(ifname string) (macaddr net.HardwareAddr, ifindex int, err error)

func GetLastEventsForSubscriber

func GetLastEventsForSubscriber(id string) (output []*netevents.NetEventData, valid bool, err error)

GetLastEventsForSubscriber returns the latest events available for the subscriber ID if valid is false, then the subscriber is expired

func GetLinkStatusByName

func GetLinkStatusByName(name string) (ret *netlink.LinkAttrs, err error)

func GetNeteventsID

func GetNeteventsID() (ok bool, ret string)

GetNeteventsID returns the string ID used to reference network events in the event manager,

func InitNetworkManager

func InitNetworkManager(networkconfig *maestroSpecs.NetworkConfigPayload, ddbconfig *maestroConfig.DeviceDBConnConfig) error

InitNetworkManager be called on startup. NetworkConfigPayload will come from config file Storage should be started already.

func IsIPv4AddressSet

func IsIPv4AddressSet(ifname string, thisaddr *netlink.Addr) (response bool, err error)

func IsModemRegistered

func IsModemRegistered(index string) bool

IsModemRegistered returns whether SIM is recognized in the modem and it is registered to the network

func ReleaseFromServer

func ReleaseFromServer(ifname string, leasinfo *DhcpLeaseInfo) (ok bool, err error)

ReleaseFromServer will release the DHCP lease to the server for the given interface NOT IMPLEMENTED

func RemoveDefaultRoute

func RemoveDefaultRoute() (err error)

RemoveDefaultRoute removes the default route from the default routing table To understand "default table" - read more here: https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System

func SetInterfaceMacAddress

func SetInterfaceMacAddress(ifname string, ifindex int, macaddr string) (err error)

SetInterfaceMacAddress sets the mac address. ifname is preferred, if not provided (empty string) then ifindex is used MAC addresses should be formatted "aa:bb:cc:01:23:45" etc. 48 or 64 bit addresses can be stated, or whatever may be supported by the hardware such as a 20-octet IP for InifiniBand

func SetupDefaultRouteFromLease

func SetupDefaultRouteFromLease(ifconfig *maestroSpecs.NetIfConfigPayload, leaseinfo *DhcpLeaseInfo) (routeset bool, gw string, err error)

SetupDefaultRouteFromLease sets a default route based on the ifconfig information and/or the DhcpLeaseInfo If the ifconfig has a provided default gateway, this will be used, otherwise the DhcpLeaseInfo's default gateway will be provided. If neither have a setting, then no route will be set, 'routeset' will be fales and gw will return the zero value. leaseinfo may be nil, in which case it is ignored.

func SubscribeToNetEvents

func SubscribeToNetEvents(timeout int64) (id string, err error)

SubscribeToNetEvents let's you subscribe to all core network event. A timeout should be provided if your channel listener may stop listening to events in the futurer. timeout is in nanoseconds, and is the equivalent to time.Duration

Types

type CommitConfigChangeHook

type CommitConfigChangeHook struct {
}

//////////////////////////////////////////////////////////////////////////////////////// Monitor for ConfigChangeHook ////////////////////////////////////////////////////////////////////////////////////////

func (CommitConfigChangeHook) ChangesComplete

func (cfgHook CommitConfigChangeHook) ChangesComplete(configgroup string) (acceptallchanges bool)

ChangesComplete is called when all changes for a specific configgroup tagname If ChangesComplete returns true, then all changes in that group will be assigned to the current struct

func (CommitConfigChangeHook) ChangesStart

func (cfgHook CommitConfigChangeHook) ChangesStart(configgroup string)

ChangesStart is called before reporting any changes via multiple calls to SawChange. It will only be called if there is at least one change to report

func (CommitConfigChangeHook) SawChange

func (cfgHook CommitConfigChangeHook) SawChange(configgroup string, fieldchanged string, futvalue interface{}, curvalue interface{}, index int) (acceptchange bool)

SawChange is called whenever a field changes. It will be called only once for each field which is changed. It will always be called after ChangesStart is called If SawChange return true, then the value of futvalue will replace the value of current value

type ConfigChangeInfo

type ConfigChangeInfo struct {
	// contains filtered or unexported fields
}

type ConfigCommit

type ConfigCommit struct {
	// Set this flag to true for the changes to commit, if this flag is false
	// the changes to configuration on these structs will not acted upon
	// by network manager. For exmaple, this flag will be initially false
	// so that user can change the config object in DeviceDB and verify that the
	// intented changes are captured correctly. Once verified set this flag to true
	// so that the changes will be applied by maestro. Once maestro complete the
	// changes the flag will be set to false by maestro.
	ConfigCommitFlag bool `yaml:"config_commit" json:"config_commit" netgroup:"config_commit"`
	//Datetime of last update
	LastUpdateTimestamp string `yaml:"config_commit" json:"last_commit_timestamp" netgroup:"config_commit"`
	//Total number of updates from boot
	TotalCommitCountFromBoot int `yaml:"config_commit" json:"total_commit_count_from_boot" netgroup:"config_commit"`
}

type DhcpLeaseInfo

type DhcpLeaseInfo struct {
	CurrentIP     net.IP // current IP address
	CurrentMask   net.IPMask
	LeaseAcquired int64        // When we got the last packet giving us an IP - Unix epoch time
	LastAckPacket dhcp4.Packet // this is just a []byte, interpreted with dhcp package
	// contains filtered or unexported fields
}

func GetFreshDhcpLease

func GetFreshDhcpLease(ifname string, opts *dhcp4client.DhcpRequestOptions) (success int, outleaseinfo *DhcpLeaseInfo, err error)

GetFreshDhcpLease requests a new lease, without using any existing lease information.

func InitRebootDhcpLease

func InitRebootDhcpLease(ifname string, currentIP net.IP, opts *dhcp4client.DhcpRequestOptions) (success int, outleaseinfo *DhcpLeaseInfo, err error)

InitRebootDhcpLease asks the DHCP server to confirm it's IP and provide new options. This is is used during the INIT_REBOOT state in the DHCP RFC 2131. It's typically called if the network is disconnected, then reconnected.

func RenewFromServer

func RenewFromServer(ifname string, leaseinfo *DhcpLeaseInfo, opts *dhcp4client.DhcpRequestOptions) (ackval int, outleaseinfo *DhcpLeaseInfo, err error)

*

  • RenewFromServer renews from the server directy - a packet sent direct to the server, vs. a broadcast
  • @param {[type]} ifname string [description]
  • @param {[type]} leasinfo *DhcpLeaseInfo [description]
  • @param {[type]} opts *dhcp4client.DhcpRequestOptions) (outleaseinfo *DhcpLeaseInfo, err error [description]

func RequestOrRenewDhcpLease

func RequestOrRenewDhcpLease(ifname string, leaseinfo *DhcpLeaseInfo, opts *dhcp4client.DhcpRequestOptions) (success int, outleaseinfo *DhcpLeaseInfo, err error)

RequestOrRenewDhcpLease Gets a new DCHP address, based on an existing lease, if one exists. If one does not exist, it just gets a new address @param {[type]} ifname string [description]

func (*DhcpLeaseInfo) GetClientDomainName

func (this *DhcpLeaseInfo) GetClientDomainName() (ok bool, ret []byte)

should be called after parsedOptions is filled

func (*DhcpLeaseInfo) GetDHCPServer

func (this *DhcpLeaseInfo) GetDHCPServer() (ok bool, ret net.IP)

should be called after parsedOptions is filled

func (*DhcpLeaseInfo) GetDNS

func (this *DhcpLeaseInfo) GetDNS() (ok bool, ret []net.IP)

func (*DhcpLeaseInfo) GetGIADDR

func (this *DhcpLeaseInfo) GetGIADDR() (ok bool, ret net.IP)

func (*DhcpLeaseInfo) GetLeaseSubnetMask

func (this *DhcpLeaseInfo) GetLeaseSubnetMask() net.IPMask

should be called after parsedOptions is filled

func (*DhcpLeaseInfo) GetLocalDomain

func (this *DhcpLeaseInfo) GetLocalDomain() (ok bool, localdomain string)

func (*DhcpLeaseInfo) GetRouter

func (this *DhcpLeaseInfo) GetRouter() (ok bool, ret net.IP)

should be called after parsedOptions is filled

func (*DhcpLeaseInfo) GetSIADDR

func (this *DhcpLeaseInfo) GetSIADDR() (ok bool, ret net.IP)

func (*DhcpLeaseInfo) IsExpired

func (this *DhcpLeaseInfo) IsExpired() bool

func (*DhcpLeaseInfo) IsValid

func (this *DhcpLeaseInfo) IsValid() bool

func (*DhcpLeaseInfo) RemainOnLease

func (this *DhcpLeaseInfo) RemainOnLease() int64

type InterfaceStatus

type InterfaceStatus struct {
	// nil error means interface setup ok
	Err     error  `json:"err"`
	Up      bool   `json:"up"`
	IfName  string `json:"if_name"`
	IfIndex int    `json:"if_index"`
	IPV4    string `json:"ipv4"`
	IPV6    string `json:"ipv6"` // not implemented TODO
	// contains filtered or unexported fields
}

func SetupInterfaceFromLease

func SetupInterfaceFromLease(ifconfig *maestroSpecs.NetIfConfigPayload, leaseinfo *DhcpLeaseInfo) (result *InterfaceStatus, err error)

func SetupStaticInterfaces

func SetupStaticInterfaces(ifs []*maestroSpecs.NetIfConfigPayload) (results []InterfaceStatus, err error)

SetupStaticInterfaces sets up static interfaces

type NetlinkAddr

type NetlinkAddr netlink.Addr

func (*NetlinkAddr) MarshalJSON

func (addr *NetlinkAddr) MarshalJSON() ([]byte, error)

type NetworkAPIError

type NetworkAPIError struct {
	Errstring  string `json:"error"`
	Code       int    `json:"code"`
	IfName     string `json:"if_name"`
	IfIndex    int    `json:"if_index"`
	Underlying error  `json:"underlying"`
}

func (*NetworkAPIError) Error

func (this *NetworkAPIError) Error() string

type NetworkConfigChangeHook

type NetworkConfigChangeHook struct {
}

func (NetworkConfigChangeHook) ChangesComplete

func (cfgHook NetworkConfigChangeHook) ChangesComplete(configgroup string) (acceptallchanges bool)

ChangesComplete is called when all changes for a specific configgroup tagname If ChangesComplete returns true, then all changes in that group will be assigned to the current struct

func (NetworkConfigChangeHook) ChangesStart

func (cfgHook NetworkConfigChangeHook) ChangesStart(configgroup string)

ChangesStart is called before reporting any changes via multiple calls to SawChange. It will only be called if there is at least one change to report

func (NetworkConfigChangeHook) SawChange

func (cfgHook NetworkConfigChangeHook) SawChange(configgroup string, fieldchanged string, futvalue interface{}, curvalue interface{}, index int) (acceptchange bool)

SawChange is called whenever a field changes. It will be called only once for each field which is changed. It will always be called after ChangesStart is called If SawChange return true, then the value of futvalue will replace the value of current value

type NetworkInterfaceData

type NetworkInterfaceData struct {
	IfName string `json:"name"`
	// current set Address
	//	PrimaryAddress NetlinkAddr `json:"primary_addr"`
	CurrentIPv4Addr net.IP
	// not used yet
	CurrentIPv6Addr net.IP
	// the settings as they should be
	StoredIfconfig *maestroSpecs.NetIfConfigPayload
	// the settings as they are right now
	RunningIfconfig *maestroSpecs.NetIfConfigPayload

	// the last lease information
	DhcpLease *DhcpLeaseInfo

	// last time the interface config was changed
	// ms since Unix epoch
	LastUpdated int64
	// contains filtered or unexported fields
}

internal wrapper, used to store network settings

func (*NetworkInterfaceData) MarshalJSON

func (ifdata *NetworkInterfaceData) MarshalJSON() ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL