networking

package module
v0.0.0-...-242cc53 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

copied from gokrazy

Functions for setting up resolv.conf

https://go.dev/src/net/dnsconfig_unix.go

on initramfs systems /etc/resolv.conf is memory based. no need to safewrite/copy and fsync tricks

this is only way how resolv.conf is edited

Index

Constants

View Source
const RESOLVCONFFILE = "/etc/resolv.conf"

Variables

This section is empty.

Functions

func Carrier

func Carrier(interfacename string) (bool, error)

func GetDhcpLease

func GetDhcpLease(ifi *net.Interface, hostname string) (*dhcp4.Lease, error)

func GetInterfaceByName

func GetInterfaceByName(interfacename string, timeout time.Duration) (*net.Interface, error)

func HaveInterface

func HaveInterface(interfacename string) (bool, error)
func Link(interfacename string) (bool, error)

func ListInterfaceNames

func ListInterfaceNames() ([]string, error)

func PrintoutNetInterface

func PrintoutNetInterface(interfacename string) string

TODO MOVE THIS!

func SetAddress

func SetAddress(interfName string, addrWithMask string) error

func SetLinkUp

func SetLinkUp(interfacename string, up bool) error

func SetRoute

func SetRoute(interfacename string, gatewayIp net.IP, priority int) error

func WaitCarrier

func WaitCarrier(interfacename string, timeout time.Duration, interval time.Duration) error

WaitCarrier, helper function for polling carrier

func WaitInterface

func WaitInterface(interfacename string, timeout time.Duration, interval time.Duration) error

Types

type IpSettings

type IpSettings struct {
	Gateway    net.IP //Goes to route
	Address    string
	DnsServers []net.IP
	LeaseTime  time.Duration //Stays same
	Expire     time.Time     //If leased from DHCP
}

func GetDHCP

func GetDHCP(hostname string, interfacename string) (IpSettings, error)

func (*IpSettings) ApplyToInterface

func (p *IpSettings) ApplyToInterface(interfacename string, priority int) error

func (IpSettings) String

func (a IpSettings) String() string

type ResolvConf

type ResolvConf struct {
	CommentTitle string       //One supported
	Nameserver   []netip.Addr // netip.IP is more modern, https://www.papercall.io/speakers/mdlayher/speaker_talks/222197-net-netip-introducing-go-s-new-ip-address-package
	Domain       string
	Search       string
	Unparsed     []string //Extra options etc... pack at end of file
}

Resolv.conf parsing. Better than https://go.dev/src/net/dnsconfig.go Only supported features

func ReadResolvConf

func ReadResolvConf(fname string) (ResolvConf, error)

ReadResolvConf if file does not exist then return default resolv conf

func (*ResolvConf) AddNameservers

func (p *ResolvConf) AddNameservers(iplist []net.IP) error

AddNameservers adds nameservers without duplicates

func (ResolvConf) Save

func (a ResolvConf) Save(fname string) error

func (ResolvConf) String

func (a ResolvConf) String() string

Jump to

Keyboard shortcuts

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