go fmt
This commit is contained in:
parent
89f642d6ff
commit
6acc13e010
16
addr.go
16
addr.go
|
@ -1,19 +1,19 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"github.com/vishvananda/netlink"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddrSet struct {
|
type AddrSet struct {
|
||||||
linkAttrs netlink.LinkAttrs
|
linkAttrs netlink.LinkAttrs
|
||||||
linkChan chan netlink.LinkUpdate
|
linkChan chan netlink.LinkUpdate
|
||||||
addrChan chan netlink.AddrUpdate
|
addrChan chan netlink.AddrUpdate
|
||||||
|
|
||||||
addrs map[string]net.IP
|
addrs map[string]net.IP
|
||||||
}
|
}
|
||||||
|
|
||||||
func (addrs *AddrSet) String() string {
|
func (addrs *AddrSet) String() string {
|
||||||
|
@ -21,7 +21,7 @@ func (addrs *AddrSet) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (addrs *AddrSet) testFlag(flag net.Flags) bool {
|
func (addrs *AddrSet) testFlag(flag net.Flags) bool {
|
||||||
return addrs.linkAttrs.Flags & flag != 0
|
return addrs.linkAttrs.Flags&flag != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (addrs *AddrSet) Up() bool {
|
func (addrs *AddrSet) Up() bool {
|
||||||
|
|
7
dns.go
7
dns.go
|
@ -1,18 +1,19 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/miekg/dns"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"github.com/miekg/dns"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const TSIG_FUDGE_SECONDS = 300
|
const TSIG_FUDGE_SECONDS = 300
|
||||||
|
|
||||||
type TSIGAlgorithm string
|
type TSIGAlgorithm string
|
||||||
|
|
||||||
func (t *TSIGAlgorithm) UnmarshalFlag(value string) error {
|
func (t *TSIGAlgorithm) UnmarshalFlag(value string) error {
|
||||||
switch (value) {
|
switch value {
|
||||||
case "hmac-md5", "md5":
|
case "hmac-md5", "md5":
|
||||||
*t = dns.HmacMD5
|
*t = dns.HmacMD5
|
||||||
case "hmac-sha1", "sha1":
|
case "hmac-sha1", "sha1":
|
||||||
|
|
31
main.go
31
main.go
|
@ -8,24 +8,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Verbose bool `long:"verbose" short:"v"`
|
Verbose bool `long:"verbose" short:"v"`
|
||||||
Watch bool `long:"watch" description:"Watch for interface changes"`
|
Watch bool `long:"watch" description:"Watch for interface changes"`
|
||||||
|
|
||||||
Interface string `long:"interface" short:"i" value-name:"IFACE" description:"Use address from interface"`
|
// Netlink Interface
|
||||||
InterfaceFamily Family `long:"interface-family" value-name:"ipv4|ipv6|all" description:"Limit to interface addreses of given family"`
|
Interface string `long:"interface" short:"i" value-name:"IFACE" description:"Use address from interface"`
|
||||||
|
InterfaceFamily Family `long:"interface-family" value-name:"ipv4|ipv6|all" description:"Limit to interface addreses of given family"`
|
||||||
|
|
||||||
Server string `long:"server" value-name:"HOST[:PORT]" description:"Server for UPDATE query, default is discovered from zone SOA"`
|
// DNS Update
|
||||||
Timeout time.Duration `long:"timeout" value-name:"DURATION" default:"10s" description:"Timeout for sever queries"`
|
Server string `long:"server" value-name:"HOST[:PORT]" description:"Server for UPDATE query, default is discovered from zone SOA"`
|
||||||
Retry time.Duration `long:"retry" value-name:"DURATION" default:"30s" description:"Retry interval, increased for each retry attempt"`
|
Timeout time.Duration `long:"timeout" value-name:"DURATION" default:"10s" description:"Timeout for sever queries"`
|
||||||
TSIGName string `long:"tsig-name" value-name:"FQDN"`
|
Retry time.Duration `long:"retry" value-name:"DURATION" default:"30s" description:"Retry interval, increased for each retry attempt"`
|
||||||
TSIGSecret string `long:"tsig-secret" value-name:"BASE-64" env:"TSIG_SECRET" description:"base64-encoded shared TSIG secret key"`
|
TSIGName string `long:"tsig-name" value-name:"FQDN"`
|
||||||
|
TSIGSecret string `long:"tsig-secret" value-name:"BASE-64" env:"TSIG_SECRET" description:"base64-encoded shared TSIG secret key"`
|
||||||
TSIGAlgorithm TSIGAlgorithm `long:"tsig-algorithm" value-name:"hmac-{md5,sha1,sha256,sha512}" default:"hmac-sha1."`
|
TSIGAlgorithm TSIGAlgorithm `long:"tsig-algorithm" value-name:"hmac-{md5,sha1,sha256,sha512}" default:"hmac-sha1."`
|
||||||
|
Zone string `long:"zone" value-name:"FQDN" description:"Zone to update, default is derived from name"`
|
||||||
|
TTL time.Duration `long:"ttl" value-name:"DURATION" default:"60s" description:"TTL for updated records"`
|
||||||
|
|
||||||
Zone string `long:"zone" value-name:"FQDN" description:"Zone to update, default is derived from name"`
|
Args struct {
|
||||||
TTL time.Duration `long:"ttl" value-name:"DURATION" default:"60s" description:"TTL for updated records"`
|
Name string `value-name:"FQDN" description:"DNS Name to update"`
|
||||||
|
|
||||||
Args struct {
|
|
||||||
Name string `value-name:"FQDN" description:"DNS Name to update"`
|
|
||||||
} `positional-args:"yes"`
|
} `positional-args:"yes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var update = Update{
|
var update = Update{
|
||||||
ttl: int(options.TTL.Seconds()),
|
ttl: int(options.TTL.Seconds()),
|
||||||
timeout: options.Timeout,
|
timeout: options.Timeout,
|
||||||
retry: options.Retry,
|
retry: options.Retry,
|
||||||
verbose: options.Verbose,
|
verbose: options.Verbose,
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/vishvananda/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
// zero value is unspec=all
|
// zero value is unspec=all
|
||||||
type Family int
|
type Family int
|
||||||
|
|
||||||
func (f *Family) UnmarshalFlag(value string) error {
|
func (f *Family) UnmarshalFlag(value string) error {
|
||||||
switch (value) {
|
switch value {
|
||||||
case "unspec", "all":
|
case "unspec", "all":
|
||||||
*f = netlink.FAMILY_ALL
|
*f = netlink.FAMILY_ALL
|
||||||
case "inet", "ipv4":
|
case "inet", "ipv4":
|
||||||
|
@ -22,5 +22,3 @@ func (f *Family) UnmarshalFlag(value string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
36
update.go
36
update.go
|
@ -1,31 +1,31 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/miekg/dns"
|
|
||||||
"time"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"github.com/miekg/dns"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type updateState struct {
|
type updateState struct {
|
||||||
updateZone string
|
updateZone string
|
||||||
removeNames []dns.RR
|
removeNames []dns.RR
|
||||||
inserts []dns.RR
|
inserts []dns.RR
|
||||||
}
|
}
|
||||||
|
|
||||||
type Update struct {
|
type Update struct {
|
||||||
ttl int
|
ttl int
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
retry time.Duration
|
retry time.Duration
|
||||||
verbose bool
|
verbose bool
|
||||||
|
|
||||||
zone string
|
zone string
|
||||||
name string
|
name string
|
||||||
|
|
||||||
tsig map[string]string
|
tsig map[string]string
|
||||||
tsigAlgo TSIGAlgorithm
|
tsigAlgo TSIGAlgorithm
|
||||||
server string
|
server string
|
||||||
|
|
||||||
updateChan chan updateState
|
updateChan chan updateState
|
||||||
doneChan chan error
|
doneChan chan error
|
||||||
|
@ -77,7 +77,7 @@ func (u *Update) buildAddr(ip net.IP) dns.RR {
|
||||||
if ip4 := ip.To4(); ip4 != nil {
|
if ip4 := ip.To4(); ip4 != nil {
|
||||||
return &dns.A{
|
return &dns.A{
|
||||||
Hdr: dns.RR_Header{Name: u.name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: uint32(u.ttl)},
|
Hdr: dns.RR_Header{Name: u.name, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: uint32(u.ttl)},
|
||||||
A: ip4,
|
A: ip4,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +93,10 @@ func (u *Update) buildAddr(ip net.IP) dns.RR {
|
||||||
func (u *Update) buildState(addrs *AddrSet) (state updateState, err error) {
|
func (u *Update) buildState(addrs *AddrSet) (state updateState, err error) {
|
||||||
state.updateZone = u.zone
|
state.updateZone = u.zone
|
||||||
state.removeNames = []dns.RR{
|
state.removeNames = []dns.RR{
|
||||||
&dns.RR_Header{Name:u.name},
|
&dns.RR_Header{Name: u.name},
|
||||||
}
|
}
|
||||||
|
|
||||||
addrs.Each(func(ip net.IP){
|
addrs.Each(func(ip net.IP) {
|
||||||
state.inserts = append(state.inserts, u.buildAddr(ip))
|
state.inserts = append(state.inserts, u.buildAddr(ip))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ func (u *Update) run() {
|
||||||
var updateChan = u.updateChan
|
var updateChan = u.updateChan
|
||||||
var updateError error
|
var updateError error
|
||||||
|
|
||||||
defer func(){u.doneChan <-updateError}()
|
defer func() { u.doneChan <- updateError }()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Reference in New Issue