lua

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNameIP         = "TYPE_IP"
	TypeNameIPList     = "TYPE_IP_LIST"
	TypeNameString     = "TYPE_STRING"
	TypeNameStringList = "TYPE_STRING_LIST"
)

Type names for known types

Variables

View Source
var (
	// TypeIP represents an IP type
	TypeIP = &KnownType{StringFactory(ipOption), ipToLua}

	// TypeIPList represents a list of IP addresses
	TypeIPList = &KnownType{StringListFactory(ipListOption), ipListToLua}

	// TypeString represents a String type
	TypeString = &KnownType{StringFactory(stringOption), stringToLua}

	// TypeStringList represents a list of strings
	TypeStringList = &KnownType{StringListFactory(stringListOption), stringsToLua}
)

Functions

func GetBuiltinOptionNames

func GetBuiltinOptionNames() map[string]dhcpv4.OptionCode

GetBuiltinOptionNames returns a map of option name to option-code

func GetBuiltinOptionTypes

func GetBuiltinOptionTypes() map[dhcpv4.OptionCode]*KnownType

GetBuiltinOptionTypes returns a map of dhcpv4 option-code to KnownType

Types

type KnownType

type KnownType struct {
	ToValue   interface{}
	FromValue ToLuaFunc
}

KnownType defines a Lua-to-OptionValue and an OptionValue-to-Lua conversion function

func (KnownType) FromLuaValue

func (k KnownType) FromLuaValue(L *lua.LState, value lua.LValue) (dhcpv4.OptionValue, error)

FromLuaValue converts the value to it's DHCP option representation. Note that value is automatically converted to the go-type expected by the configured KnownType factory function. An error is returned if value is not convertible to the expected type

type NumberFactory

type NumberFactory func(x float64) (dhcpv4.OptionValue, error)

NumberFactory converts a number to an option

type NumberListFactory

type NumberListFactory func(x []float64) (dhcpv4.OptionValue, error)

NumberListFactory converts a number slice to an option

type OptionModule

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

OptionModule keeps track of well-known and user-defined DHCPv4 options and how to covert them between their DHCPv4 wire and lua representation.

func NewOptionModule

func NewOptionModule(names map[string]dhcpv4.OptionCode, types map[dhcpv4.OptionCode]*KnownType) *OptionModule

NewOptionModule creates a new option module with support for the named DHCP options configured in names. Each entry must have a dedicated KnownType entry in the types map. Any type registered by the lua rc file will be added to those maps so access to them should by synchronized with the options module

func (*OptionModule) DeclareOption

func (opts *OptionModule) DeclareOption(name string, code uint8, typeName string) error

DeclareOption declares a new DHCPv4 option

func (*OptionModule) Setup

func (opts *OptionModule) Setup(L *lua.LState) error

Setup configures the lua state L and adds global symbols to interact with the options module

func (*OptionModule) TypeForName

func (opts *OptionModule) TypeForName(name string) (*KnownType, dhcpv4.OptionCode, bool)

TypeForName returns the a KnownType definition for the given name

type PluginConfig

type PluginConfig struct {
	// Name is the name of the plugin
	Name string

	// Path holds the file path to the plugins .so file
	Path string

	// Config holds additional configuration values for the plugin
	Config map[string]interface{}
}

PluginConfig describes the configuration of a loadable plugin

type PluginManager

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

PluginManager allows configuration of loadable

func (*PluginManager) Plugins

func (mng *PluginManager) Plugins() []PluginConfig

Plugins returns a list of registered plugins

func (*PluginManager) Setup

func (mng *PluginManager) Setup(L *lua.LState) error

Setup initializes the given lua.LState by configuring global plugin related functions

type Runner

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

Runner is cool :) TODO(ppacher): fix comment

func NewFromFile

func NewFromFile(filepath string) (*Runner, error)

NewFromFile creates and returns a new Runner from the given input configuration file

func NewFromReader

func NewFromReader(input io.Reader) (*Runner, error)

NewFromReader creates and returns a new lua runner from the given input reader

func (*Runner) Plugins

func (r *Runner) Plugins() []PluginConfig

Plugins returns all registred plugins

func (*Runner) Subnets

func (r *Runner) Subnets() []Subnet

Subnets returns all registered subnets

type StringFactory

type StringFactory func(s string) (dhcpv4.OptionValue, error)

StringFactory converts a string to an option

type StringListFactory

type StringListFactory func(s []string) (dhcpv4.OptionValue, error)

StringListFactory converts a string slice to an option

type Subnet

type Subnet struct {
	// IP is the IP address to listen on
	IP net.IP

	// Network is the IP network that is served by this declaration
	Network net.IPNet

	// SubnetConfig embedds additional configuration values
	SubnetConfig
}

Subnet defines a subnet to be served

type SubnetConfig

type SubnetConfig struct {
	// Database is the lease database to use. Defaults to internal
	Database string `mapstructure:"database"`

	// DatabaseOptions may holds additional database options passed to lease.Open()
	DatabaseOptions map[string]interface{} `mapstructure:"databaseArgs"`

	// Ranges of IP address that can be leased to clients on this subnet
	Ranges [][]string `mapstructure:"ranges"`

	// Options holds additional DHCP options for clients on this subnet
	Options map[string]interface{} `mapstructure:"options"`

	// LeaseTime is the default lease time for new IP address leases
	LeaseTime string `mapstructure:"leaseTime"` // TODO(ppacher) use DecodeHook and make time.Duration?

	// Offer is a callback function to modify a lease offer before it is sent
	// to a client
	Offer *lua.LFunction `mapstructure:"offer"`
}

SubnetConfig holds the configuration for a subnet

type SubnetManager

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

SubnetManager allows subnets to be declared via lua code

func (*SubnetManager) Setup

func (mng *SubnetManager) Setup(L *lua.LState) error

Setup configures the provided lua VM and exposes subnet related configuration functions

func (*SubnetManager) Subnets

func (mng *SubnetManager) Subnets() []Subnet

Subnets returns a list of all registered subnets

type ToLuaFunc

type ToLuaFunc func(*lua.LState, dhcpv4.OptionValue) (lua.LValue, error)

ToLuaFunc is a function coverting a dhcpv4.OptionValue to a string representation

Jump to

Keyboard shortcuts

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