+ dhcp custom options

Squashed commit of the following:

commit 140ac16568383cab2270e5d5ba895959902dd943
Merge: d5ed73b5 cb6ca3b0
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Tue Aug 25 13:46:34 2020 +0300

    Merge remote-tracking branch 'origin/master' into 1585-dhcp-options

commit d5ed73b5e4f068b823fe97ab1161753670d10387
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Fri Aug 21 18:16:41 2020 +0300

    minor

commit f5208a0b050c2dd462b32edee0379758cc6e5003
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Mon Jun 1 14:09:39 2020 +0300

    + dhcpv4 custom options
This commit is contained in:
Simon Zolin
2020-08-25 14:07:11 +03:00
parent cb6ca3b0c4
commit 9c999f98fb
6 changed files with 130 additions and 10 deletions

View File

@@ -1,11 +1,15 @@
package dhcpd
import (
"encoding/hex"
"net"
"net/http"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/AdguardTeam/AdGuardHome/util"
"github.com/AdguardTeam/golibs/log"
)
@@ -214,3 +218,43 @@ func (s *Server) FindMACbyIP(ip net.IP) net.HardwareAddr {
func (s *Server) AddStaticLease(lease Lease) error {
return s.srv4.AddStaticLease(lease)
}
// Parse option string
// Format:
// CODE TYPE VALUE
func parseOptionString(s string) (uint8, []byte) {
s = strings.TrimSpace(s)
scode := util.SplitNext(&s, ' ')
t := util.SplitNext(&s, ' ')
sval := util.SplitNext(&s, ' ')
code, err := strconv.Atoi(scode)
if err != nil || code <= 0 || code > 255 {
return 0, nil
}
var val []byte
switch t {
case "hex":
val, err = hex.DecodeString(sval)
if err != nil {
return 0, nil
}
case "ip":
ip := net.ParseIP(sval)
if ip == nil {
return 0, nil
}
val = ip
if ip.To4() != nil {
val = ip.To4()
}
default:
return 0, nil
}
return uint8(code), val
}