juicy j once said: fuck a PR, fuck a commit message
This commit is contained in:
parent
0c8eb52795
commit
ec9fded9ce
17
README.md
17
README.md
|
@ -1,24 +1,19 @@
|
|||
# tr4proutes-dhcp
|
||||
|
||||
|
||||
##### a bastardization of [coredhcp](https://git.tcp.direct/kayos/tr4proute-dhcp/)
|
||||
|
||||
Fast, multithreaded, modular and extensible DHCP server written in Go.
|
||||
|
||||
one piece of what will eventually be a nasty suite of daemons for gateways and server provisioning
|
||||
Fast, multithreaded, modular and extensible DHCP server written in Go.
|
||||
|
||||
one piece of what will eventually be a nasty suite of daemons for WAN gateway operation and server/bare metal provisioning
|
||||
|
||||
Features: fuck you (this likely doesn't work yet)
|
||||
|
||||
## Turned out
|
||||
|
||||
|
||||
* yaml fucking sucks - fuck yo config, he dead. switched to toml
|
||||
* logrus? gross - zerolog all up ins
|
||||
* dumb ass client test didn't work - its gone.
|
||||
* generator? i don't care if you can't figure out how to use this.
|
||||
|
||||
# How to write a plugin
|
||||
|
||||
idk read the fucking code?????
|
||||
|
||||
* generator? i don't care if you can't figure out how to use this. (removed)
|
||||
|
||||
### old coredhcp authors that i'm disappointing
|
||||
|
||||
|
|
|
@ -95,12 +95,12 @@ func parsePlugins(pluginList []interface{}) ([]PluginConfig, error) {
|
|||
for idx, val := range pluginList {
|
||||
conf := cast.ToStringMap(val)
|
||||
if conf == nil {
|
||||
return nil, ConfigErrorFromString("dhcpv6: plugin #%d is not a string map", idx)
|
||||
return nil, ConfigErrorFromString("plugin #%d is not a string map", idx)
|
||||
}
|
||||
// make sure that only one item is specified, since it's a
|
||||
// map name -> args
|
||||
if len(conf) != 1 {
|
||||
return nil, ConfigErrorFromString("dhcpv6: exactly one plugin per item can be specified")
|
||||
return nil, ConfigErrorFromString("exactly one plugin per item can be specified")
|
||||
}
|
||||
var (
|
||||
name string
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package bitcask
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/prologic/bitcask"
|
||||
|
@ -18,11 +14,14 @@ import (
|
|||
|
||||
var log = logger.GetLogger("plugins/bitcask")
|
||||
|
||||
var db4 *bitcask.Bitcask
|
||||
var db6 *bitcask.Bitcask
|
||||
|
||||
// Plugin wraps plugin registration information
|
||||
var Plugin = plugins.Plugin{
|
||||
Name: "bitcask",
|
||||
Setup6: setup6,
|
||||
Setup4: setup4,
|
||||
Name: "bitcask",
|
||||
Setup6: setup6,
|
||||
Setup4: setup4,
|
||||
}
|
||||
|
||||
// Handler6 handles DHCPv6 packets for the file plugin
|
||||
|
@ -43,14 +42,17 @@ func Handler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
|||
log.Warn().Msg("Could not find client MAC, passing")
|
||||
return resp, false
|
||||
}
|
||||
|
||||
log.Debug().Str("MAC", mac.String()).Msg("LOOKUP_IP")
|
||||
|
||||
ipaddr, ok := StaticRecords[mac.String()]
|
||||
if !ok {
|
||||
if !db6.Has(mac) {
|
||||
log.Warn().Str("MAC", mac.String()).Msg("MAC address unknown")
|
||||
return resp, false
|
||||
}
|
||||
log.Debug().Str("IP_ADDR", ipaddr).Str("MAC", mac.String()).Msg("IP_FOUND")
|
||||
|
||||
ipaddr, _ := db6.Get(mac)
|
||||
|
||||
log.Debug().IPAddr("IP_ADDR", ipaddr).Str("MAC", mac.String()).Msg("IP_FOUND")
|
||||
|
||||
resp.AddOption(&dhcpv6.OptIANA{
|
||||
IaId: m.Options.OneIANA().IaId,
|
||||
|
@ -67,35 +69,30 @@ func Handler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
|||
|
||||
// Handler4 handles DHCPv4 packets for the file plugin
|
||||
func Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
|
||||
ipaddr, ok := StaticRecords[req.ClientHWAddr.String()]
|
||||
if !ok {
|
||||
log.Warn().Str("MAC", mac.String()).Msg("UNKNOWN_MAC_ADDRESS")
|
||||
return resp, false
|
||||
}
|
||||
resp.YourIPAddr = ipaddr
|
||||
log.Debug().Str("MAC", req.ClientHWAddr.String()).Str("IP", ipaddr).Msg("FOUND_IP")
|
||||
return resp, true
|
||||
// placeholder
|
||||
}
|
||||
|
||||
func setup6(args ...string) (handler.Handler6, error) {
|
||||
h6, _, err := setupFile(true, args...)
|
||||
h6, _, err := setupBitcask(true, args...)
|
||||
return h6, err
|
||||
}
|
||||
|
||||
func setup4(args ...string) (handler.Handler4, error) {
|
||||
_, h4, err := setupFile(false, args...)
|
||||
_, h4, err := setupBitcask(false, args...)
|
||||
return h4, err
|
||||
}
|
||||
|
||||
func setupFile(v6 bool, args ...string) (handler.Handler6, handler.Handler4, error) {
|
||||
func setupBitcask(v6 bool, args ...string) (handler.Handler6, handler.Handler4, error) {
|
||||
var err error
|
||||
var records map[string]net.IP
|
||||
var db *bitcask.Bitcask
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to load DHCPv6 records: %v", err)
|
||||
switch v6 {
|
||||
case false:
|
||||
db4 = db.Open(datapath + "leasesv6")
|
||||
case true:
|
||||
db6 = db.Open(datapath + "leasesv4")
|
||||
}
|
||||
|
||||
StaticRecords = records
|
||||
log.Info().Int("count", len(records)).Str("filename", filename).Msg("successfully loaded leases from file")
|
||||
return Handler6, Handler4, nil
|
||||
}
|
||||
|
|
|
@ -106,20 +106,20 @@ func recordKey(d *dhcpv6.Duid) string {
|
|||
func (h *Handler) Handle(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
||||
msg, err := req.GetInnerMessage()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
log.Error().Err(err).Msg("ERR_DHCPv6_PREFIX")
|
||||
return nil, true
|
||||
}
|
||||
|
||||
client := msg.Options.ClientID()
|
||||
if client == nil {
|
||||
log.Error("Invalid packet received, no clientID")
|
||||
log.Error().Msg("Invalid packet received, no clientID")
|
||||
return nil, true
|
||||
}
|
||||
|
||||
// Each request IA_PD requires an IA_PD response
|
||||
for _, iapd := range msg.Options.IAPD() {
|
||||
if err != nil {
|
||||
log.Error().Msg("Malformed IAPD received: %v", err)
|
||||
log.Error().Err(err).Msg("Malformed IAPD received")
|
||||
resp.AddOption(&dhcpv6.OptStatusCode{StatusCode: dhcpIana.StatusMalformedQuery})
|
||||
return resp, true
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func (h *Handler) Handle(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
|||
}
|
||||
allocated, err := h.allocator.Allocate(*prefix.Prefix)
|
||||
if err != nil {
|
||||
log.Debugf("Nothing allocated for hinted prefix %s", prefix)
|
||||
log.Debug().Interface("prefix", prefix).Msg("Nothing allocated for hinted prefix")
|
||||
continue
|
||||
}
|
||||
l := lease{
|
||||
|
@ -229,7 +229,7 @@ func (h *Handler) Handle(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
|||
|
||||
addPrefix(iapdResp, l)
|
||||
newLeases = append(knownLeases, l)
|
||||
log.Debugf("Allocated %s to %s (IAID: %x)", &allocated, client, iapd.IaId)
|
||||
log.Debug().Msg(fmt.Sprintf("Allocated %s to %s (IAID: %x)", &allocated, client, iapd.IaId))
|
||||
}
|
||||
|
||||
if newLeases != nil {
|
||||
|
@ -238,7 +238,7 @@ func (h *Handler) Handle(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
|||
h.Unlock()
|
||||
|
||||
if len(iapdResp.Options.Options) == 0 {
|
||||
log.Debugf("No valid prefix to return for IAID %x", iapd.IaId)
|
||||
log.Debug().Msg(fmt.Sprintf("No valid prefix to return for IAID %x", iapd.IaId))
|
||||
iapdResp.Options.Add(&dhcpv6.OptStatusCode{
|
||||
StatusCode: dhcpIana.StatusNoPrefixAvail,
|
||||
})
|
||||
|
|
|
@ -87,7 +87,7 @@ func (p *PluginState) Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool)
|
|||
}
|
||||
resp.YourIPAddr = record.IP
|
||||
resp.Options.Update(dhcpv4.OptIPAddressLeaseTime(p.LeaseTime.Round(time.Second)))
|
||||
rlog.Info().Str("IP", record.IP).Msg("success: found IP")
|
||||
rlog.Info().Interface("IP", record.IP).Msg("success: found IP")
|
||||
return resp, false
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ func setup4(args ...string) (handler.Handler4, error) {
|
|||
}
|
||||
routers = append(routers, router)
|
||||
}
|
||||
log.Info()("loaded %d router IP addresses.", len(routers))
|
||||
log.Info().Int("count", len(routers)).Msg("successfully loaded router IP addresses")
|
||||
return Handler4, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ import (
|
|||
"github.com/insomniacslk/dhcp/dhcpv4"
|
||||
"github.com/insomniacslk/dhcp/dhcpv6"
|
||||
"github.com/insomniacslk/dhcp/rfc1035label"
|
||||
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var log = logger.GetLogger("plugins/searchdomains")
|
||||
|
@ -52,13 +54,13 @@ func copySlice(original []string) []string {
|
|||
|
||||
func setup6(args ...string) (handler.Handler6, error) {
|
||||
v6SearchList = args
|
||||
log.Info().Msg("Registered domain search list (DHCPv6) %s", v6SearchList)
|
||||
log.Info().Msg(fmt.Sprintf("Registered domain search list (DHCPv6) %s", v6SearchList))
|
||||
return domainSearchListHandler6, nil
|
||||
}
|
||||
|
||||
func setup4(args ...string) (handler.Handler4, error) {
|
||||
v4SearchList = args
|
||||
log.Info().Msg("Registered domain search list (DHCPv4) %s", v4SearchList)
|
||||
log.Info().Msg(fmt.Sprintf("Registered domain search list (DHCPv4) %s", v4SearchList))
|
||||
return domainSearchListHandler4, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ package serverid
|
|||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.tcp.direct/kayos/tr4proute-dhcp/handler"
|
||||
|
@ -42,7 +43,7 @@ func Handler6(req, resp dhcpv6.DHCPv6) (dhcpv6.DHCPv6, bool) {
|
|||
msg, err := req.GetInnerMessage()
|
||||
if err != nil {
|
||||
// BUG: this should already have failed in the main handler. Abort
|
||||
log.Error().Err(err).Msg("ERROR")
|
||||
log.Error().Err(err).Msg("ERROR_BUG")
|
||||
return nil, true
|
||||
}
|
||||
|
||||
|
@ -86,7 +87,7 @@ func Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
|
|||
!req.ServerIPAddr.Equal(net.IPv4zero) &&
|
||||
!req.ServerIPAddr.Equal(v4ServerID) {
|
||||
// This request is not for us, drop it.
|
||||
log.Info()("requested server ID does not match this server's ID. Got %v, want %v", req.ServerIPAddr, v4ServerID)
|
||||
log.Info().Msg(fmt.Sprintf("requested server ID does not match this server's ID. Got %v, want %v", req.ServerIPAddr, v4ServerID))
|
||||
return nil, true
|
||||
}
|
||||
resp.ServerIPAddr = make(net.IP, net.IPv4len)
|
||||
|
@ -96,7 +97,7 @@ func Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
|
|||
}
|
||||
|
||||
func setup4(args ...string) (handler.Handler4, error) {
|
||||
log.Info().Msg("loading `server_id` plugin for DHCPv4 with args: %v", args)
|
||||
log.Info().Strs("args", args).Msg("loading `server_id` plugin for DHCPv4")
|
||||
if len(args) < 1 {
|
||||
return nil, errors.New("need an argument")
|
||||
}
|
||||
|
@ -112,7 +113,7 @@ func setup4(args ...string) (handler.Handler4, error) {
|
|||
}
|
||||
|
||||
func setup6(args ...string) (handler.Handler6, error) {
|
||||
log.Info().Msg("loading `server_id` plugin for DHCPv6 with args: %v", args)
|
||||
log.Info().Strs("args", args).Msg("loading `server_id` plugin for DHCPv6")
|
||||
if len(args) < 2 {
|
||||
return nil, errors.New("need a DUID type and value")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue