Initial import.
This commit is contained in:
commit
f3fc03392a
|
@ -0,0 +1,4 @@
|
||||||
|
load("@bazel_gazelle//:def.bzl", "gazelle")
|
||||||
|
|
||||||
|
# gazelle:prefix git.wntrmute.dev/kyle/bladerunner
|
||||||
|
gazelle(name = "gazelle")
|
|
@ -0,0 +1,36 @@
|
||||||
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "io_bazel_rules_go",
|
||||||
|
sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f",
|
||||||
|
urls = [
|
||||||
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
|
||||||
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "bazel_gazelle",
|
||||||
|
sha256 = "ecba0f04f96b4960a5b250c8e8eeec42281035970aa8852dda73098274d14a1d",
|
||||||
|
urls = [
|
||||||
|
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
|
||||||
|
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.29.0/bazel-gazelle-v0.29.0.tar.gz",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||||
|
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
||||||
|
|
||||||
|
############################################################
|
||||||
|
# Define your own dependencies here using go_repository.
|
||||||
|
# Else, dependencies declared by rules_go/gazelle will be used.
|
||||||
|
# The first declaration of an external repository "wins".
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
load("//:deps.bzl", "go_dependencies")
|
||||||
|
|
||||||
|
# gazelle:repository_macro deps.bzl%go_dependencies
|
||||||
|
go_dependencies()
|
||||||
|
go_rules_dependencies()
|
||||||
|
go_register_toolchains(version = "1.20.3")
|
||||||
|
gazelle_dependencies()
|
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.wntrmute.dev/kyle/kdhcp/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg := &server.Config{}
|
||||||
|
flag.StringVar(&cfg.Device, "i", "eth0", "network `interface` to listen on")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
_, err := server.NewServer(cfg)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -euxo pipefail
|
||||||
|
|
||||||
|
BAZEL="bazel"
|
||||||
|
if [ -z "$(command -v ${BAZEL})" ]
|
||||||
|
then
|
||||||
|
BAZEL="bazelisk"
|
||||||
|
fi
|
||||||
|
|
||||||
|
$BAZEL run //:gazelle
|
||||||
|
$BAZEL run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
|
||||||
|
$BAZEL run //:gazelle
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// github.com/insomniacslk/dhcp
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Device string `yaml:"device"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
addrs []net.IP
|
||||||
|
l net.Listener
|
||||||
|
}
|
||||||
|
|
||||||
|
func addrsForDevice(dev string) ([]net.IP, error) {
|
||||||
|
netInterface, err := net.InterfaceByName(dev)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var addrs []net.IP
|
||||||
|
devAddrs, err := netInterface.Addrs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, addr := range devAddrs {
|
||||||
|
ip := net.ParseIP(addr.String())
|
||||||
|
if ip == nil {
|
||||||
|
continue // address isn't an IP address
|
||||||
|
}
|
||||||
|
|
||||||
|
// DHCP should only listen on private addresses.
|
||||||
|
if !ip.IsPrivate() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// only support IPv4 for now
|
||||||
|
if len(ip) != 4 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
addrs = append(addrs, ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
return addrs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewServer(cfg *Config) (*Server, error) {
|
||||||
|
addrs, err := addrsForDevice(cfg.Device)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("server IP list: ", addrs)
|
||||||
|
return nil, errors.New("not implemented")
|
||||||
|
}
|
Loading…
Reference in New Issue