leases

package module
v0.0.0-...-27572b3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 8 Imported by: 0

README

GoDoc

Go module to parse dhcpd's lease file

This little library alllows for parsing dhcpd's lease files as given in man 5 dhcpd.leases. Its not elegant, but gets the job done.

It does not parse all the options that dhcpd can emit, but it solves the problem I had.

Usage

Basically do something like this:

    f, err := os.Open("/var/lib/dhcpd/dhcpd.leases")
    leases := Parse(f)
    ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lease

type Lease struct {
	//IP address given to the lease
	IP net.IP `json:"ip"`

	//Start time of the lease
	Starts time.Time `json:"starts"`

	//Time when the lease expires
	Ends time.Time `json:"ends"`

	//Tstp is specified if the failover protocol is being used, and indicates what time the peer has been told the lease expires.
	Tstp time.Time `json:"tstp"`

	//Tsfp is also specified if the failover protocol is being used, and indicates the lease expiry time that the peer has acknowledged
	Tsfp time.Time `json:"tsfp"`

	//Atsfp is the actual time sent from the failover partner
	Atsfp time.Time `json:"atsfp"`

	//Cltt is the client's last transaction time
	Cltt time.Time `json:"cllt"`

	/*The binding state statement declares the lease's binding state. When the DHCP server is
	not configured to use the failover protocol, a lease's binding state will be either
	active or free. The failover protocol adds some additional transitional states, as
	well as the backup state, which indicates that the lease is available for allocation
	by the failover secondary.*/
	BindingState string `json:"binding-state"`

	//The next binding state statement indicates what state the lease will move to when the current state expires. The time when the current state expires is specified in the ends statement.
	NextBindingState string `json:"next-binding-state"`

	//The hardware statement records the MAC address of the network interface on which the lease will be used. It is specified as a series of hexadecimal octets, separated by colons.
	Hardware struct {
		Hardware string           `json:"hardware"`
		MAC      string           `json:"mac"`
		MACAddr  net.HardwareAddr `json:"-"`
	} `json:"hardware"`

	//The uid statement records the client identifier used by the client to acquire the lease. Clients are not required to send client identifiers, and this statement only appears if the client did in fact send one. Client identifiers are normally an ARP type (1 for ethernet) followed by the MAC address, just like in the hardware statement, but this is not required.
	UID string `json:"uid"`

	//Clients provided hostname
	ClientHostname string `json:"client-hostname"`
}

Lease format specified in man(5) dhcpd.leases

- See https://linux.die.net/man/5/dhcpd.leases or similar

A Lease contains the data specified in the following format:

172.24.43.3 {
	starts 6 2019/04/27 03:24:45;
	ends 6 2019/04/27 03:34:45;
	tstp 6 2019/04/27 03:34:45;
	cltt 6 2019/04/27 03:24:45;
	binding state free;
	hardware ethernet 00:db:70:c3:11:d7;
	uid "\001\000\333p\303\021\327";
}

func Parse

func Parse(r io.Reader) []Lease

Parse reads from a dhcpd.leases file and returns a list of leases. Unknown fields are ignored

Jump to

Keyboard shortcuts

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