diff --git a/.goreleaser.yml b/.goreleaser.yml index 6cf287d..df6d13e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -52,6 +52,8 @@ archives: builds: - default name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}" + replacements: + darwin: mac wrap_in_directory: true format: tar.gz format_overrides: diff --git a/README.md b/README.md index e1385a1..b206777 100644 --- a/README.md +++ b/README.md @@ -307,8 +307,8 @@ Forwarder option scheme: FORWARD_URL#OPTIONS vmess://[security:]uuid@host:port?alterID=num#priority=200&interface=eth0 Services: - dhcpd: service=dhcpd,INTERFACE,START_IP,END_IP - e.g.,service=dhcpd,eth1,192.168.50.100,192.168.50.199 + dhcpd: service=dhcpd,INTERFACE,START_IP,END_IP,LEASE_MINUTES[,MAC=IP,MAC=IP...] + e.g.,service=dhcpd,eth1,192.168.1.100,192.168.1.199,720 Config file format(see `./glider.conf.example` as an example): # COMMENT LINE diff --git a/config.go b/config.go index 4eaa168..038fae9 100644 --- a/config.go +++ b/config.go @@ -303,8 +303,8 @@ func usage() { fmt.Fprintf(w, "\n") fmt.Fprintf(w, "Services:\n") - fmt.Fprintf(w, " dhcpd: service=dhcpd,INTERFACE,START_IP,END_IP\n") - fmt.Fprintf(w, " e.g.,service=dhcpd,eth1,192.168.50.100,192.168.50.199\n") + fmt.Fprintf(w, " dhcpd: service=dhcpd,INTERFACE,START_IP,END_IP,LEASE_MINUTES[,MAC=IP,MAC=IP...]\n") + fmt.Fprintf(w, " e.g.,service=dhcpd,eth1,192.168.1.100,192.168.1.199,720\n") fmt.Fprintf(w, "\n") fmt.Fprintf(w, "Config file format(see `"+app+".conf.example` as an example):\n") diff --git a/feature.go b/feature.go index 21b49fc..9289089 100644 --- a/feature.go +++ b/feature.go @@ -3,6 +3,7 @@ package main import ( // comment out the services you don't need to make the compiled binary smaller. // _ "github.com/nadoo/glider/service/xxx" + _ "github.com/nadoo/glider/service/dhcpd" // comment out the protocols you don't need to make the compiled binary smaller. _ "github.com/nadoo/glider/proxy/http" diff --git a/feature_linux.go b/feature_linux.go index cc254ae..d3a7804 100644 --- a/feature_linux.go +++ b/feature_linux.go @@ -2,7 +2,7 @@ package main import ( // comment out the services you don't need to make the compiled binary smaller. - _ "github.com/nadoo/glider/service/dhcpd" + // _ "github.com/nadoo/glider/service/xxx" // comment out the protocols you don't need to make the compiled binary smaller. _ "github.com/nadoo/glider/proxy/redir" diff --git a/go.mod b/go.mod index cc9f8ac..1378aec 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,12 @@ require ( github.com/dgryski/go-camellia v0.0.0-20191119043421-69a8a13fb23d github.com/dgryski/go-idea v0.0.0-20170306091226-d2fb45a411fb github.com/dgryski/go-rc2 v0.0.0-20150621095337-8a9021637152 - github.com/insomniacslk/dhcp v0.0.0-20210621130208-1cac67f12b1e + github.com/insomniacslk/dhcp v0.0.0-20210812084645-decc701b3665 github.com/nadoo/conflag v0.2.3 github.com/nadoo/ipset v0.3.0 github.com/xtaci/kcp-go/v5 v5.6.1 golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 - golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 + golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e ) require ( diff --git a/go.sum b/go.sum index 99129b8..e8c037e 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/hugelgupf/socketpair v0.0.0-20190730060125-05d35a94e714 h1:/jC7qQFrv8CrSJVmaolDVOxTfS9kc36uB6H40kdbQq8= github.com/hugelgupf/socketpair v0.0.0-20190730060125-05d35a94e714/go.mod h1:2Goc3h8EklBH5mspfHFxBnEoURQCGzQQH1ga9Myjvis= -github.com/insomniacslk/dhcp v0.0.0-20210621130208-1cac67f12b1e h1:sgh63o+pm5kcdrgyYaCIoeD7mccyL6MscVmy+DvY6C4= -github.com/insomniacslk/dhcp v0.0.0-20210621130208-1cac67f12b1e/go.mod h1:h+MxyHxRg9NH3terB1nfRIUaQEcI0XOVkdR9LNBlp8E= +github.com/insomniacslk/dhcp v0.0.0-20210812084645-decc701b3665 h1:skMK5bGMStbk2T6am4JEOtm4KWiRB6/bLSeUHPzf88Y= +github.com/insomniacslk/dhcp v0.0.0-20210812084645-decc701b3665/go.mod h1:h+MxyHxRg9NH3terB1nfRIUaQEcI0XOVkdR9LNBlp8E= github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4/go.mod h1:WGuG/smIU4J/54PblvSbh+xvCZmpJnFgr3ds6Z55XMQ= github.com/jsimonetti/rtnetlink v0.0.0-20201009170750-9c6f07d100c1/go.mod h1:hqoO/u39cqLeBLebZ8fWdE96O7FxrAsRYhnVOdgHxok= @@ -156,8 +156,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 h1:siQdpVirKtzPhKl3lZWozZraCFObP8S1v6PRp0bLrtU= -golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/ipset/ipset_other.go b/ipset/ipset_other.go index 91445ad..43290c3 100644 --- a/ipset/ipset_other.go +++ b/ipset/ipset_other.go @@ -1,3 +1,4 @@ +//go:build !linux // +build !linux package ipset diff --git a/proxy/redir/redir_linux_other.go b/proxy/redir/redir_linux_other.go index a2677b9..d02c54a 100644 --- a/proxy/redir/redir_linux_other.go +++ b/proxy/redir/redir_linux_other.go @@ -1,3 +1,4 @@ +//go:build linux && !386 // +build linux,!386 package redir diff --git a/service/dhcpd/cilent_linux.go b/service/dhcpd/cilent_linux.go new file mode 100644 index 0000000..0fb6ede --- /dev/null +++ b/service/dhcpd/cilent_linux.go @@ -0,0 +1,27 @@ +package dhcpd + +import ( + "context" + "time" + + "github.com/insomniacslk/dhcp/dhcpv4/nclient4" + + "github.com/nadoo/glider/log" +) + +func existsServer(iface string) (exists bool) { + client, err := nclient4.New(iface) + if err != nil { + log.F("[dhcpd] failed in dhcp client creation: %s", err) + return + } + defer client.Close() + + ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) + _, err = client.Request(ctx) + if err != nil { + return + } + + return true +} diff --git a/service/dhcpd/client_others.go b/service/dhcpd/client_others.go new file mode 100644 index 0000000..2d58100 --- /dev/null +++ b/service/dhcpd/client_others.go @@ -0,0 +1,8 @@ +//go:build !linux +// +build !linux + +package dhcpd + +func existsServer(iface string) (exists bool) { + return false +} diff --git a/service/dhcpd/dhcpd.go b/service/dhcpd/dhcpd.go index 1ab8b2d..5d90511 100644 --- a/service/dhcpd/dhcpd.go +++ b/service/dhcpd/dhcpd.go @@ -1,7 +1,6 @@ package dhcpd import ( - "context" "errors" "net" "strconv" @@ -9,7 +8,6 @@ import ( "time" "github.com/insomniacslk/dhcp/dhcpv4" - "github.com/insomniacslk/dhcp/dhcpv4/nclient4" "github.com/insomniacslk/dhcp/dhcpv4/server4" "github.com/nadoo/glider/log" @@ -137,23 +135,6 @@ func handleDHCP(serverIP net.IP, mask net.IPMask, pool *Pool) server4.Handler { } } -func existsServer(iface string) (exists bool) { - client, err := nclient4.New(iface) - if err != nil { - log.F("[dhcpd] failed in dhcp client creation: %s", err) - return - } - defer client.Close() - - ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) - _, err = client.Request(ctx) - if err != nil { - return - } - - return true -} - func ifaceAddr(iface string) (net.IP, net.IPMask, net.HardwareAddr, error) { intf, err := net.InterfaceByName(iface) if err != nil {