net

package
v0.0.0-...-b79a0d8 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package net implements some network-related functions for recovery. These include enabling interfaces and acquiring addresses via DHCP, and downloading files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustDupDefaultRoutes

func AdjustDupDefaultRoutes(plat common.PlatInfoer, MetricForDuplicates uint64)

Remove duplicate routes if MetricForDuplicates is 0, else give them different priority by changing the metric. (high metric -> low prio)

func AssignIP

func AssignIP(device string, addr net.IPNet)

Assign the given IP to the given device. Call multiple times to assign multiple addresses.

func EnableNetworkingAny

func EnableNetworkingAny() bool

Enable any network interface, even DIAG if not hidden

func EnableNetworkingSkipDIAG

func EnableNetworkingSkipDIAG(diags []int, allowedPrefixes [][]byte) (success bool)

Enable any network interface except DIAG (only use if DIAG port(s) are not already hidden - if they are, usable ports will be skipped)

func EnableNic

func EnableNic(nic string) (success bool)

set state up, get addr via dhcp

func HasIpv4

func HasIpv4(netif *net.Interface) bool

HasIpv4 returns true if the given interface has an ipv4 address.

func WaitForIpv4

func WaitForIpv4(wait time.Duration, ifaces []nic.Nic) (success bool)

WaitForIpv4 waits until at least one of the given interfaces to gain an ipv4 address, or until the wait time has expired.

func WanDevice

func WanDevice(plat common.PlatInfoer) *nic.Nic

Determine the WAN device.

WARNING: assumes nics will not be disabled while this is running, by this or other process(es). Will return incorrect port as wan if that's not true.

Types

type IPNet

type IPNet struct {
	net.IPNet
}

IPNet is a wrapper around net.IPNet allowing us to extend the functionality.

func IPNetFromAddr

func IPNetFromAddr(a net.Addr) (IPNet, error)

func IPNetFromCIDR

func IPNetFromCIDR(cidr string) (IPNet, error)

IPNetFromCIDR converts an address string in CIDR notation into an IPNet. If you use net.ParseCIDR directly, the returned IPNet contains the subnet and mask, not the ip and mask.

func IPNetsFromIface

func IPNetsFromIface(iface string) ([]IPNet, error)

func (IPNet) Equal

func (l IPNet) Equal(r IPNet) bool

func (*IPNet) MarshalJSON

func (ip *IPNet) MarshalJSON() (data []byte, err error)

func (*IPNet) UnmarshalJSON

func (ip *IPNet) UnmarshalJSON(data []byte) error

type Route

type Route struct {
	Iface  string        `json:",omitempty"`
	Gw     net.IP        `json:",omitempty"`
	Proto  int           `json:",omitempty"`
	Metric uint64        `json:",omitempty"`
	Src    net.IP        `json:",omitempty"`
	Dest   IPNet         `json:",omitempty"`
	Scope  netlink.Scope `json:",omitempty"`
}

Route represents an IP route.

func GetDefaultRoutes

func GetDefaultRoutes() []Route

Returns all 'default via ...' routes.

func GetRouteThroughIface

func GetRouteThroughIface(iface, destip string) Route

GetRouteThroughIface gets a route to destip through iface.

func GetRoutes

func GetRoutes(onlyDefault bool) []Route

Returns routes.

func (*Route) Add

func (r *Route) Add() error

Add route via netlink, does not shell out to 'ip'.

func (Route) Equal

func (l Route) Equal(r Route) bool

func (*Route) Remove

func (r *Route) Remove()

func (*Route) String

func (r *Route) String() string

Renders the route in human-readable form like that of 'ip route'

Directories

Path Synopsis
Package xfer handles robust file transfers, primarily for use in mfg process.
Package xfer handles robust file transfers, primarily for use in mfg process.

Jump to

Keyboard shortcuts

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