dhcp4d: add HostnameOverride field

This can be used to permanently override a hostname, regardless of whether the
lease is static or not. We use a separate field because we want devices to be
able to change their hostname themselves, until we override it.
This commit is contained in:
Michael Stapelberg 2019-08-30 09:06:21 +02:00
parent 4cde5ec6fc
commit fa82132962
2 changed files with 21 additions and 7 deletions

View File

@ -106,7 +106,7 @@ th {
padding-top: 1em; padding-top: 1em;
text-align: left; text-align: left;
} }
span.active, span.expired, span.static { span.active, span.expired, span.static, span.hostname-override {
min-width: 5em; min-width: 5em;
display: inline-block; display: inline-block;
text-align: center; text-align: center;
@ -119,6 +119,10 @@ span.active {
span.expired { span.expired {
background-color: #f00000; background-color: #f00000;
} }
span.hostname-override {
min-width: 1em;
background-color: orange;
}
.ipaddr, .hwaddr { .ipaddr, .hwaddr {
font-family: monospace; font-family: monospace;
} }
@ -139,7 +143,12 @@ tr:nth-child(even) {
{{ range $idx, $l := . }} {{ range $idx, $l := . }}
<tr> <tr>
<td class="ipaddr">{{$l.Addr}}</td> <td class="ipaddr">{{$l.Addr}}</td>
<td>{{$l.Hostname}}</td> <td>
{{$l.Hostname}}
{{ if (ne $l.HostnameOverride "") }}
<span class="hostname-override">!</span>
{{ end }}
</td>
<td class="hwaddr">{{$l.HardwareAddr}}</td> <td class="hwaddr">{{$l.HardwareAddr}}</td>
<td>{{$l.Vendor}}</td> <td>{{$l.Vendor}}</td>
<td title="{{ timefmt $l.Expiry }}"> <td title="{{ timefmt $l.Expiry }}">

View File

@ -35,6 +35,7 @@ type Lease struct {
Addr net.IP `json:"addr"` Addr net.IP `json:"addr"`
HardwareAddr string `json:"hardware_addr"` HardwareAddr string `json:"hardware_addr"`
Hostname string `json:"hostname"` Hostname string `json:"hostname"`
HostnameOverride string `json:"hostname_override"`
Expiry time.Time `json:"expiry"` Expiry time.Time `json:"expiry"`
} }
@ -277,6 +278,10 @@ func (h *Handler) serveDHCP(p dhcp4.Packet, msgType dhcp4.MessageType, options d
lease.Expiry = time.Time{} lease.Expiry = time.Time{}
lease.Hostname = l.Hostname lease.Hostname = l.Hostname
} }
if l.HostnameOverride != "" {
lease.Hostname = l.HostnameOverride
lease.HostnameOverride = l.HostnameOverride
}
// Release any old leases for this client // Release any old leases for this client
delete(h.leasesIP, l.Num) delete(h.leasesIP, l.Num)