Add time and vendor information to leases

This commit is contained in:
lordwelch 2022-03-04 13:49:50 -08:00
parent 67711ee2c7
commit c5a72342f2
2 changed files with 15 additions and 6 deletions

View File

@ -155,6 +155,8 @@ form {
<th>Hostname</th> <th>Hostname</th>
<th>MAC address</th> <th>MAC address</th>
<th>Vendor</th> <th>Vendor</th>
<th>VendorIdentifier</th>
<th>Start</th>
<th>Expiry</th> <th>Expiry</th>
</tr> </tr>
{{ range $idx, $l := . }} {{ range $idx, $l := . }}
@ -171,6 +173,8 @@ form {
</td> </td>
<td class="hwaddr">{{$l.HardwareAddr}}</td> <td class="hwaddr">{{$l.HardwareAddr}}</td>
<td>{{$l.Vendor}}</td> <td>{{$l.Vendor}}</td>
<td>{{$l.VendorIdentifier}}</td>
<td>{{$l.Start}}</td>
<td title="{{ timefmt $l.Expiry }}"> <td title="{{ timefmt $l.Expiry }}">
{{ if $l.Expired }} {{ if $l.Expired }}
{{ since $l.Expiry }} {{ since $l.Expiry }}
@ -183,6 +187,7 @@ form {
<span class="active">active</span> <span class="active">active</span>
{{ end }} {{ end }}
{{ end }} {{ end }}
</td> </td>
</tr> </tr>
{{ end }} {{ end }}

View File

@ -43,6 +43,8 @@ type Lease struct {
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
HostnameOverride string `json:"hostname_override"` HostnameOverride string `json:"hostname_override"`
Expiry time.Time `json:"expiry"` Expiry time.Time `json:"expiry"`
Start time.Time `json:"start"`
VendorIdentifier string `json:"vendor"`
} }
func (l *Lease) Expired(at time.Time) bool { func (l *Lease) Expired(at time.Time) bool {
@ -335,13 +337,15 @@ func (h *Handler) serveDHCP(p dhcp4.Packet, msgType dhcp4.MessageType, options d
if leaseNum == -1 { if leaseNum == -1 {
return dhcp4.ReplyPacket(p, dhcp4.NAK, h.serverIP, nil, 0, nil) return dhcp4.ReplyPacket(p, dhcp4.NAK, h.serverIP, nil, 0, nil)
} }
now := h.timeNow()
lease := &Lease{ lease := &Lease{
Num: leaseNum, Num: leaseNum,
Addr: make([]byte, 4), Addr: make([]byte, 4),
HardwareAddr: hwAddr, HardwareAddr: hwAddr,
Expiry: h.timeNow().Add(h.leasePeriodForDevice(hwAddr)), Expiry: now.Add(h.leasePeriodForDevice(hwAddr)),
Hostname: string(options[dhcp4.OptionHostName]), Hostname: string(options[dhcp4.OptionHostName]),
Start: now,
VendorIdentifier: string(options[dhcp4.OptionVendorClassIdentifier]),
} }
copy(lease.Addr, reqIP.To4()) copy(lease.Addr, reqIP.To4())