base

package
v0.0.0-...-d91f73c Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DHCPPort   = 67
	InformPort = 10001
)

Variables

This section is empty.

Functions

func LocalAddressManager

func LocalAddressManager(addressChan chan address.InterfaceAddress, exit chan int)

func WritePacket

func WritePacket(out chan OutPacket, exit chan int, handler *PacketHandler)

Types

type DHCPDevice

type DHCPDevice struct {
	ServerIP    *net.IP
	NetworkMask *net.IPMask
	ClientIP    *net.IP
	Expiry      time.Time
}

type DHCPPacket

type DHCPPacket struct {
	Packet   gopacket.Packet
	Ethernet *layers.Ethernet
	IP       *layers.IPv4
	UDP      *layers.UDP
	DHCP     *layers.DHCPv4
}

type Device

type Device struct {
	MacAddress string
	Unifi      *UnifiDevice
	DHCP       *DHCPDevice
	Log        *log.Entry
	// contains filtered or unexported fields
}

func (*Device) IsBusy

func (d *Device) IsBusy() bool

IsBusy states whether or not this Device is ready to receive commands.

func (*Device) IsReady

func (d *Device) IsReady() bool

func (*Device) Provision

func (d *Device) Provision() error

Provision updates the system config on the remote device.

func (*Device) Reboot

func (d *Device) Reboot() error

Reboot issues a reboot on the device.

func (*Device) String

func (d *Device) String() string

type InformPacket

type InformPacket struct {
	Version uint8
	Tags    []*Tag
	// contains filtered or unexported fields
}

func ParseInformPacket

func ParseInformPacket(raw []byte) (*InformPacket, error)

ParsePacket tries to parse UPD packet data into a Packet

func (*InformPacket) Device

func (p *InformPacket) Device() *UnifiDevice

type OutPacket

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

func NewOutPacket

func NewOutPacket(data []byte) OutPacket

type PacketHandler

type PacketHandler struct {
	ARP    chan gopacket.Packet
	Inform chan gopacket.Packet
	DHCP   chan gopacket.Packet
	// contains filtered or unexported fields
}

ARP requests only : (arp[6:2] = 1) Our requests "((arp[6:2] = 1) or udp dst port 67 or udp dst port 10001) and not vlan"

func NewHandler

func NewHandler(iface *net.Interface) (*PacketHandler, error)

func (*PacketHandler) Close

func (handler *PacketHandler) Close()

func (*PacketHandler) Listen

func (handler *PacketHandler) Listen(stop chan int)

func (*PacketHandler) SetFilter

func (handler *PacketHandler) SetFilter(filter string) error

func (*PacketHandler) Write

func (handler *PacketHandler) Write(packet []byte) error

type SSHConfiguration

type SSHConfiguration struct {
	Usernames      []string        `yaml:"users"`
	SSHAuthMethods []sshAuthMethod `yaml:"methods"`
	// contains filtered or unexported fields
}

type Server

type Server struct {
	Interface string `yaml:"interface"`
	Iface     *net.Interface

	LogLevel      string `yaml:"log_level"`
	LogFile       string `yaml:"log_file"`
	LogFileWriter *os.File
	Log           *log.Entry

	MaxDevices int      `yaml:"max_devices"`
	MACPrefix  []string `yaml:"mac_prefixes"`

	Provision provisionConfiguration `yaml:"provision"`
	DHCP      dhcpConfiguration      `yaml:"dhcp"`

	Handler *PacketHandler

	NetManager address.Manager // RPC client to talk to the interface address manager
	ManageNet  chan address.InterfaceAddress
	StopNet    chan int

	WriteNet  chan OutPacket
	StopWrite chan int

	StopListen chan int

	StopClean   chan int
	CleanTicker *time.Ticker

	Cache *lru.Cache
}

func LoadConfig

func LoadConfig(fileName string) (c *Server, errs []error)

LoadConfig reads a YAML file and converts it to a Server object

func (*Server) AddDevice

func (server *Server) AddDevice(device Device) bool

func (*Server) DHCPServer

func (h *Server) DHCPServer()

func (*Server) GetDHCPNetwork

func (server *Server) GetDHCPNetwork() (*net.IPNet, error)

func (*Server) GetDevice

func (server *Server) GetDevice(mac string) (Device, bool)

func (*Server) HandleInform

func (server *Server) HandleInform(in chan gopacket.Packet)

func (*Server) HasDevice

func (server *Server) HasDevice(mac string) bool

func (*Server) LocalAddressCLeaner

func (server *Server) LocalAddressCLeaner()

func (*Server) NewProvisionDevice

func (server *Server) NewProvisionDevice(dev *Device) *UnifiProvision

func (*Server) RemoteAddressManager

func (server *Server) RemoteAddressManager(address chan address.InterfaceAddress, exit chan int)

func (*Server) Start

func (server *Server) Start() error

func (*Server) Stop

func (server *Server) Stop() error

func (*Server) ValidMAC

func (h *Server) ValidMAC(mac string) bool

type Tag

type Tag struct {
	ID TagID
	// contains filtered or unexported fields
}

Tag describes a key value pair

func ParseTag

func ParseTag(id TagID, n uint16, raw []byte) (*Tag, error)

ParseTag converts a byte stream (i.e. an UDP packet slice) into a Tag

func (*Tag) Description

func (t *Tag) Description() string

Description returns the long tag name

func (*Tag) Name

func (t *Tag) Name() string

Name returns the short tag name

func (*Tag) StringInto

func (t *Tag) StringInto(ref *string)

StringInto tries to update the given string reference with a type asserted value (it doesn't perform an update, if the type assertion fails)

type TagDescription

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

TagDescription annotates some meta information to a TagID

type TagID

type TagID uint8

TagID identifies tags

type UnifiDevice

type UnifiDevice struct {
	DeclaredMacAddress string
	Model              string
	Platform           string
	Hostname           string
	Firmware           string
	IPAddresses        map[string][]string
	UpSince            time.Time
	RebootedAt         time.Time
	Essid              string
	WirelessMode       string
	Provision          *UnifiProvision
}

type UnifiProvision

type UnifiProvision struct {
	IP            *net.IP
	Mask          *net.IPMask
	VLAN          int
	Gateway       string
	Iface         string
	Configuration *provisionConfiguration
}

Jump to

Keyboard shortcuts

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