vip

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GarbageCollect

func GarbageCollect(adapter, address string) (found bool, err error)

func GenerateMac

func GenerateMac() (mac string)

func GetDefaultGatewayInterface

func GetDefaultGatewayInterface() (*net.Interface, error)

GetDefaultGatewayInterface return default gateway interface link

func GetFullMask

func GetFullMask(address string) (string, error)

GetFullMask returns /32 for an IPv4 address and /128 for an IPv6 address

func GetIPs

func GetIPs(vip string) []string

func IsIP

func IsIP(address string) bool

IsIP returns if address is an IP or not

func IsIPv4

func IsIPv4(address string) bool

IsIPv4 returns true only if address is a valid IPv4 address

func IsIPv6

func IsIPv6(address string) bool

IsIPv6 returns true only if address is a valid IPv6 address

func ListRoutes

func ListRoutes(table, protocol int) ([]netlink.Route, error)

ListRoutes returns all routes from selected table with selected protocol

func ListRoutesByDst

func ListRoutesByDst(table int, dst *net.IPNet) ([]netlink.Route, error)

ListRoutesByDst returns all routes from selected table with selected destination IP

func LookupHost

func LookupHost(dnsName, dnsMode string) ([]string, error)

LookupHost resolves dnsName and return an IP or an error

func MonitorDefaultInterface

func MonitorDefaultInterface(ctx context.Context, defaultIF *net.Interface) error

MonitorDefaultInterface monitor the default interface and catch the event of the default route

Types

type DHCPClient

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

DHCPClient is responsible for maintaining ipv4 lease for one specified interface

func NewDHCPClient

func NewDHCPClient(iface *net.Interface, initRebootFlag bool, requestedIP string) *DHCPClient

NewDHCPClient returns a new DHCP Client.

func (*DHCPClient) ErrorChannel

func (c *DHCPClient) ErrorChannel() chan error

Gets the ErrorChannel for consumption

func (*DHCPClient) IPChannel

func (c *DHCPClient) IPChannel() chan string

Gets the IPChannel for consumption

func (*DHCPClient) Start

func (c *DHCPClient) Start()

Start state-transition process of dhcp client

--------                               -------

| | +-------------------------->| |<-------------------+ | INIT- | | +-------------------->| INIT | | | REBOOT |DHCPNAK/ +---------->| |<---+ | | |Restart| | ------- | |

--------  |  DHCPNAK/     |               |                        |
   |      Discard offer   |      -/Send DHCPDISCOVER               |

-/Send DHCPREQUEST | | |

   |      |     |      DHCPACK            v        |               |
-----------     |   (not accept.)/   -----------   |               |

| | | Send DHCPDECLINE | | | | REBOOTING | | | | SELECTING |<----+ | | | | / | | |DHCPOFFER/ |

-----------     |       /            -----------   |  |Collect     |
   |            |      /                  |   |       |  replies   |

DHCPACK/ | / +----------------+ +-------+ | Record lease, set| | v Select offer/ | timers T1, T2 ------------ send DHCPREQUEST | |

  |   +----->|            |             DHCPNAK, Lease expired/   |
  |   |      | REQUESTING |                  Halt network         |
  DHCPOFFER/ |            |                       |               |
  Discard     ------------                        |               |
  |   |        |        |                   -----------           |
  |   +--------+     DHCPACK/              |           |          |
  |              Record lease, set    -----| REBINDING |          |
  |                timers T1, T2     /     |           |          |
  |                     |        DHCPACK/   -----------           |
  |                     v     Record lease, set   ^               |
  +----------------> -------      /timers T1,T2   |               |
             +----->|       |<---+                |               |
             |      | BOUND |<---+                |               |
DHCPOFFER, DHCPACK, |       |    |            T2 expires/   DHCPNAK/
 DHCPNAK/Discard     -------     |             Broadcast  Halt network
             |       | |         |            DHCPREQUEST         |
             +-------+ |        DHCPACK/          |               |
                  T1 expires/   Record lease, set |               |
               Send DHCPREQUEST timers T1, T2     |               |
               to leasing server |                |               |
                       |   ----------             |               |
                       |  |          |------------+               |
                       +->| RENEWING |                            |
                          |          |----------------------------+
                           ----------
        Figure: State-transition diagram for DHCP clients

func (*DHCPClient) Stop

func (c *DHCPClient) Stop()

Stop state-transition process and close dhcp client

func (*DHCPClient) WithHostName

func (c *DHCPClient) WithHostName(hostname string) *DHCPClient

type Network

type Network interface {
	AddIP() error
	AddRoute() error
	DeleteIP() error
	DeleteRoute() error
	UpdateRoutes() (bool, error)
	IsSet() (bool, error)
	IP() string
	PrepareRoute() *netlink.Route
	SetIP(ip string) error
	Interface() string
	IsDADFAIL() bool
	IsDNS() bool
	IsDDNS() bool
	DDNSHostName() string
	DNSName() string
}

Network is an interface that enable managing operations for a given IP

func NewConfig

func NewConfig(address string, iface string, subnet string, isDDNS bool, tableID int, tableType int, routingProtocol int, dnsMode string) ([]Network, error)

NewConfig will attempt to provide an interface to the kernel network configuration

Jump to

Keyboard shortcuts

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