bazel stuff
This commit is contained in:
parent
f3fc03392a
commit
0325eb8536
|
@ -1,4 +1,4 @@
|
||||||
load("@bazel_gazelle//:def.bzl", "gazelle")
|
load("@bazel_gazelle//:def.bzl", "gazelle")
|
||||||
|
|
||||||
# gazelle:prefix git.wntrmute.dev/kyle/bladerunner
|
# gazelle:prefix git.wntrmute.dev/kyle/kdhcp
|
||||||
gazelle(name = "gazelle")
|
gazelle(name = "gazelle")
|
||||||
|
|
|
@ -31,6 +31,9 @@ load("//:deps.bzl", "go_dependencies")
|
||||||
|
|
||||||
# gazelle:repository_macro deps.bzl%go_dependencies
|
# gazelle:repository_macro deps.bzl%go_dependencies
|
||||||
go_dependencies()
|
go_dependencies()
|
||||||
|
|
||||||
go_rules_dependencies()
|
go_rules_dependencies()
|
||||||
|
|
||||||
go_register_toolchains(version = "1.20.3")
|
go_register_toolchains(version = "1.20.3")
|
||||||
|
|
||||||
gazelle_dependencies()
|
gazelle_dependencies()
|
|
@ -0,0 +1,15 @@
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "kdhcpd_lib",
|
||||||
|
srcs = ["main.go"],
|
||||||
|
importpath = "git.wntrmute.dev/kyle/kdhcp/cmd/kdhcpd",
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
deps = ["//server"],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_binary(
|
||||||
|
name = "kdhcpd",
|
||||||
|
embed = [":kdhcpd_lib"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,9 @@
|
||||||
|
load("@bazel_gazelle//:deps.bzl", "go_repository")
|
||||||
|
|
||||||
|
def go_dependencies():
|
||||||
|
go_repository(
|
||||||
|
name = "com_github_davecgh_go_spew",
|
||||||
|
importpath = "github.com/davecgh/go-spew",
|
||||||
|
sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=",
|
||||||
|
version = "v1.1.1",
|
||||||
|
)
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -1,3 +1,8 @@
|
||||||
module git.wntrmute.dev/kyle/kdhcp
|
module git.wntrmute.dev/kyle/kdhcp
|
||||||
|
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1
|
||||||
|
github.com/hashicorp/go-syslog v1.0.0
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE=
|
||||||
|
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
|
@ -0,0 +1,9 @@
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "server",
|
||||||
|
srcs = ["server.go"],
|
||||||
|
importpath = "git.wntrmute.dev/kyle/kdhcp/server",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@com_github_davecgh_go_spew//spew"],
|
||||||
|
)
|
|
@ -1,13 +1,21 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
// github.com/insomniacslk/dhcp
|
// github.com/insomniacslk/dhcp
|
||||||
|
|
||||||
|
type addr struct {
|
||||||
|
IP net.IP
|
||||||
|
ipn *net.IPNet
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Device string `yaml:"device"`
|
Device string `yaml:"device"`
|
||||||
}
|
}
|
||||||
|
@ -17,35 +25,47 @@ type Server struct {
|
||||||
l net.Listener
|
l net.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
func addrsForDevice(dev string) ([]net.IP, error) {
|
func addrsForDevice(dev string) ([]addr, error) {
|
||||||
netInterface, err := net.InterfaceByName(dev)
|
netInterface, err := net.InterfaceByName(dev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var addrs []net.IP
|
spew.Dump(netInterface)
|
||||||
|
|
||||||
|
var addrs []addr
|
||||||
devAddrs, err := netInterface.Addrs()
|
devAddrs, err := netInterface.Addrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range devAddrs {
|
for _, devAddr := range devAddrs {
|
||||||
ip := net.ParseIP(addr.String())
|
log.Printf("consider %s", devAddr.String())
|
||||||
|
ip, ipn, err := net.ParseCIDR(devAddr.String())
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
continue // address isn't an IP address
|
continue // address isn't an IP address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("found IP: %s", ip)
|
||||||
|
ip = ip.To4()
|
||||||
|
|
||||||
// DHCP should only listen on private addresses.
|
// DHCP should only listen on private addresses.
|
||||||
if !ip.IsPrivate() {
|
if !ip.IsPrivate() {
|
||||||
|
log.Println("skipping non-private")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// only support IPv4 for now
|
// only support IPv4 for now
|
||||||
if len(ip) != 4 {
|
if len(ip) != 4 {
|
||||||
|
log.Printf("%d IP, only supporting v4 right now", len(ip))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs = append(addrs, ip)
|
addrs = append(addrs, addr{ip, ipn})
|
||||||
}
|
}
|
||||||
|
|
||||||
return addrs, nil
|
return addrs, nil
|
||||||
|
|
Loading…
Reference in New Issue