Skip to content

Commit

Permalink
Merge pull request #5 from vinted/feature/add_ability_to_specify_ip_list
Browse files Browse the repository at this point in the history
rest-dhcpd: add ability to specify ip lists
  • Loading branch information
Seitanas authored Mar 1, 2023
2 parents 49cf204 + 1fc522c commit 22b661e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/dhcpd/dhcpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/vinted/rest-dhcpd/pkg/rest"
"log"
"net"
"reflect"
"strconv"
"time"
)
Expand Down Expand Up @@ -55,7 +56,13 @@ func BuildOptions(options interface{}) dhcp.Options {
var val []byte
id, _ := strconv.Atoi(key)
if data_type[id] == "IP" {
val = []byte(net.ParseIP(fmt.Sprint(value)).To4())
if reflect.ValueOf(value).Kind() == reflect.Slice {
for _, ip := range value.([]interface{}) {
val = append(val, []byte(net.ParseIP(fmt.Sprint(ip)).To4())...)
}
} else {
val = []byte(net.ParseIP(fmt.Sprint(value)).To4())
}
} else {
val = []byte(fmt.Sprint(value))
}
Expand Down
1 change: 0 additions & 1 deletion pkg/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/vinted/rest-dhcpd/pkg/configdb"
"log"
"net/http"
//"sync"
)

func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand Down
2 changes: 1 addition & 1 deletion rest-dhcpd-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"Options": {
"1": "255.255.255.0",
"3": "192.168.100.1",
"6": "10.32.0.3"
"6": ["1.1.1.1", "8.8.8.8"]
}
}

0 comments on commit 22b661e

Please sign in to comment.