dns: log error when adding an invalid record

This commit is contained in:
nadoo 2022-02-20 01:07:51 +08:00
parent 813c5fef94
commit cb698713ee
8 changed files with 34 additions and 35 deletions

View File

@ -25,15 +25,15 @@ jobs:
- name: Set Vars
run: |
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "GO_VERSION=$(grep -P "go \d+\." go.mod | cut -d " " -f2)" >> $GITHUB_ENV
echo "GO_MOD_VERSION=$(grep -P "go \d+\." go.mod | cut -d " " -f2)" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v2
with:
stable: false
check-latest: true
go-version: '1.18.0-beta2'
# go-version: ${{ env.GO_VERSION}}
go-version: '1.18.0-rc1'
# go-version: ${{ env.GO_MOD_VERSION}}
- name: Set up Cache
uses: actions/cache@v2

View File

@ -82,7 +82,9 @@ we can set up local listeners as proxy servers, and forward requests to internet
- Docker: `docker pull nadoo/glider`
- ArchLinux: `sudo pacman -S glider`
## Run
## Usage
**Run:**
```bash
glider -config CONFIG_PATH
@ -91,13 +93,8 @@ glider -config CONFIG_PATH
glider -verbose -listen :8443 -forward SCHEME://HOST:PORT
```
## Usage
**Show help:** `glider -help`
**Show help:**
```bash
glider -help
```
<details>
<summary>click to see details</summary>
@ -225,11 +222,8 @@ glider 0.16.0, https://github.com/nadoo/glider
</details>
**Show Schemes:**
**Show Schemes:** `glider -scheme all`
```bash
glider -scheme all
```
<details>
<summary>click to see details</summary>
@ -343,11 +337,7 @@ TLS and Websocket with a specified proxy protocol:
</details>
**Show Examples:**
```bash
glider -example
```
**Show Examples:** `glider -example`
<details>
<summary>click to see details</summary>

View File

@ -2,6 +2,7 @@ package dns
import (
"encoding/binary"
"errors"
"io"
"net"
"net/netip"
@ -52,7 +53,9 @@ func NewClient(proxy proxy.Proxy, config *Config) (*Client, error) {
// custom records
for _, record := range config.Records {
c.AddRecord(record)
if err := c.AddRecord(record); err != nil {
log.F("[dns] add record '%s' error: %s", record, err)
}
}
return c, nil
@ -283,8 +286,10 @@ func (c *Client) AddHandler(h AnswerHandler) {
// AddRecord adds custom record to dns cache, format:
// www.example.com/1.2.3.4 or www.example.com/2606:2800:220:1:248:1893:25c8:1946
func (c *Client) AddRecord(record string) error {
r := strings.Split(record, "/")
domain, ip := r[0], r[1]
domain, ip, found := strings.Cut(record, "/")
if !found {
return errors.New("wrong record format, must contain '/'")
}
m, err := MakeResponse(domain, ip, uint32(c.config.MaxTTL))
if err != nil {
log.F("[dns] add custom record error: %s", err)

2
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/dgryski/go-rc2 v0.0.0-20150621095337-8a9021637152
github.com/insomniacslk/dhcp v0.0.0-20220119180841-3c283ff8b7dd
github.com/nadoo/conflag v0.3.1
github.com/nadoo/ipset v0.4.1-0.20220214103201-761217ee1ee0
github.com/nadoo/ipset v0.4.1-0.20220218075046-ca3cdce74266
github.com/xtaci/kcp-go/v5 v5.6.1
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
golang.org/x/sys v0.0.0-20220209214540-3681064d5158

4
go.sum
View File

@ -67,8 +67,8 @@ github.com/mdlayher/raw v0.0.0-20211126142749-4eae47f3d54b/go.mod h1:7EpbotpCmVZ
github.com/mmcloughlin/avo v0.0.0-20200803215136-443f81d77104/go.mod h1:wqKykBG2QzQDJEzvRkcS8x6MiSJkF52hXZsXcjaB3ls=
github.com/nadoo/conflag v0.3.1 h1:4pHkLIz8PUsfg6ajNYRRSY3bt6m2LPsu6KOzn5uIXQw=
github.com/nadoo/conflag v0.3.1/go.mod h1:dzFfDUpXdr2uS2oV+udpy5N2vfNOu/bFzjhX1WI52co=
github.com/nadoo/ipset v0.4.1-0.20220214103201-761217ee1ee0 h1:i81BROp7xvMIkR1KpLwERTrRVgwwFAN0prz1kQmz9RE=
github.com/nadoo/ipset v0.4.1-0.20220214103201-761217ee1ee0/go.mod h1:rYF5DQLRGGoQ8ZSWeK+6eX5amAuPqwFkWjhQlEITGJQ=
github.com/nadoo/ipset v0.4.1-0.20220218075046-ca3cdce74266 h1:lv9VKGAyAQAyS3lQoznfWoXYJD2C8/PITORX5r7f5rk=
github.com/nadoo/ipset v0.4.1-0.20220218075046-ca3cdce74266/go.mod h1:rYF5DQLRGGoQ8ZSWeK+6eX5amAuPqwFkWjhQlEITGJQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View File

@ -63,6 +63,10 @@ func main() {
}
}
for _, r := range config.rules {
r.IP, r.CIDR, r.Domain = nil, nil, nil
}
// enable checkers
pxy.Check()

View File

@ -58,13 +58,14 @@ func NewTLS(s string, d proxy.Dialer, p proxy.Proxy) (*TLS, error) {
alpn: query["alpn"],
}
if t.addr != "" {
if _, port, _ := net.SplitHostPort(t.addr); port == "" {
t.addr = net.JoinHostPort(t.addr, "443")
}
if t.serverName == "" {
t.serverName = t.addr[:strings.LastIndex(t.addr, ":")]
}
}
return t, nil
}

View File

@ -66,10 +66,9 @@ func (*dpcpd) Run(args ...string) {
// static ips
for _, host := range args[4:] {
pair := strings.Split(host, "=")
if len(pair) == 2 {
if mac, err := net.ParseMAC(pair[0]); err == nil {
if ip, err := netip.ParseAddr(pair[1]); err == nil {
if mac, ip, ok := strings.Cut(host, "="); ok {
if mac, err := net.ParseMAC(mac); err == nil {
if ip, err := netip.ParseAddr(ip); err == nil {
pool.LeaseStaticIP(mac, ip)
}
}