util

package
v0.105.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package util contains various utilities.

TODO(a.garipov): Such packages are widely considered an antipattern. Remove this when we refactor our project structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanBindPort

func CanBindPort(port int) (bool, error)

CanBindPort - checks if we can bind to this port or not

func CheckPacketPortAvailable

func CheckPacketPortAvailable(host net.IP, port int) error

CheckPacketPortAvailable - check if UDP port is available

func CheckPortAvailable

func CheckPortAvailable(host net.IP, port int) error

CheckPortAvailable - check if TCP port is available

func ContainsString

func ContainsString(strs []string, str string) bool

ContainsString checks if string is in the slice of strings.

func DNSUnreverseAddr

func DNSUnreverseAddr(s string) net.IP

DNSUnreverseAddr - convert reversed ARPA address to a normal IP address

func ErrorIsAddrInUse

func ErrorIsAddrInUse(err error) bool

ErrorIsAddrInUse - check if error is "address already in use"

func FileExists

func FileExists(fn string) bool

FileExists returns true if file exists.

func GetInterfaceByIP

func GetInterfaceByIP(ip net.IP) string

GetInterfaceByIP returns the name of interface containing provided ip.

func GetSubnet

func GetSubnet(ifaceName string) *net.IPNet

GetSubnet returns pointer to net.IPNet for the specified interface or nil if the search fails.

func GetValidNetInterfaces

func GetValidNetInterfaces() ([]net.Interface, error)

GetValidNetInterfaces returns interfaces that are eligible for DNS and/or DHCP invalid interface is a ppp interface or the one that doesn't allow broadcasts

func InitTLSCiphers

func InitTLSCiphers() []uint16

InitTLSCiphers - the same as initDefaultCipherSuites() from src/crypto/tls/common.go

but with the difference that we don't use so many other default ciphers.

func IsOpenWRT

func IsOpenWRT() bool

IsOpenWRT checks if OS is OpenWRT.

func LoadSystemRootCAs

func LoadSystemRootCAs() *x509.CertPool

LoadSystemRootCAs - load root CAs from the system Return the x509 certificate pool object Return nil if nothing has been found.

This means that Go.crypto will use its default algorithm to find system root CA list.

https://github.com/AdguardTeam/AdGuardHome/internal/issues/1311

func RunCommand

func RunCommand(command string, arguments ...string) (int, string, error)

RunCommand runs shell command.

func SplitNext

func SplitNext(str *string, splitBy byte) string

SplitNext - split string by a byte and return the first chunk Skip empty chunks Whitespace is trimmed

Types

type AutoHosts

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

AutoHosts - automatic DNS records

func (*AutoHosts) Close

func (a *AutoHosts) Close()

Close - close module

func (*AutoHosts) Init

func (a *AutoHosts) Init(hostsFn string)

Init - initialize hostsFn: Override default name for the hosts-file (optional)

func (*AutoHosts) List

func (a *AutoHosts) List() (ipToHosts map[string][]string)

List returns an IP-to-hostnames table. It is safe for concurrent use.

func (*AutoHosts) Process

func (a *AutoHosts) Process(host string, qtype uint16) []net.IP

Process returns the list of IP addresses for the hostname or nil if nothing found.

func (*AutoHosts) ProcessReverse

func (a *AutoHosts) ProcessReverse(addr string, qtype uint16) (hosts []string)

ProcessReverse processes a PTR request. It returns nil if nothing is found.

func (*AutoHosts) SetOnChanged

func (a *AutoHosts) SetOnChanged(onChanged onChangedT)

SetOnChanged - set callback function that will be called when the data is changed

func (*AutoHosts) Start

func (a *AutoHosts) Start()

Start - start module

type NetInterface

type NetInterface struct {
	MTU          int              `json:"mtu"`
	Name         string           `json:"name"`
	HardwareAddr net.HardwareAddr `json:"hardware_address"`
	Flags        net.Flags        `json:"flags"`
	// Array with the network interface addresses.
	Addresses []net.IP `json:"ip_addresses,omitempty"`
	// Array with IP networks for this network interface.
	Subnets []*net.IPNet `json:"-"`
}

NetInterface represents an entry of network interfaces map.

func GetValidNetInterfacesForWeb

func GetValidNetInterfacesForWeb() ([]*NetInterface, error)

GetValidNetInterfacesForWeb returns interfaces that are eligible for DNS and WEB only we do not return link-local addresses here

func (*NetInterface) MarshalJSON added in v0.105.0

func (iface *NetInterface) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for *NetInterface.

Jump to

Keyboard shortcuts

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