go fmt
This commit is contained in:
parent
89f642d6ff
commit
6acc13e010
16
addr.go
16
addr.go
|
@ -1,19 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"github.com/vishvananda/netlink"
|
||||
"fmt"
|
||||
"log"
|
||||
"github.com/vishvananda/netlink"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
type AddrSet struct {
|
||||
linkAttrs netlink.LinkAttrs
|
||||
linkChan chan netlink.LinkUpdate
|
||||
addrChan chan netlink.AddrUpdate
|
||||
linkAttrs netlink.LinkAttrs
|
||||
linkChan chan netlink.LinkUpdate
|
||||
addrChan chan netlink.AddrUpdate
|
||||
|
||||
addrs map[string]net.IP
|
||||
addrs map[string]net.IP
|
||||
}
|
||||
|
||||
func (addrs *AddrSet) String() string {
|
||||
|
@ -21,7 +21,7 @@ func (addrs *AddrSet) String() string {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
|
7
dns.go
7
dns.go
|
@ -1,18 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/miekg/dns"
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/miekg/dns"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
const TSIG_FUDGE_SECONDS = 300
|
||||
|
||||
type TSIGAlgorithm string
|
||||
|
||||
func (t *TSIGAlgorithm) UnmarshalFlag(value string) error {
|
||||
switch (value) {
|
||||
switch value {
|
||||
case "hmac-md5", "md5":
|
||||
*t = dns.HmacMD5
|
||||
case "hmac-sha1", "sha1":
|
||||
|
|
31
main.go
31
main.go
|
@ -8,24 +8,25 @@ import (
|
|||
)
|
||||
|
||||
type Options struct {
|
||||
Verbose bool `long:"verbose" short:"v"`
|
||||
Watch bool `long:"watch" description:"Watch for interface changes"`
|
||||
Verbose bool `long:"verbose" short:"v"`
|
||||
Watch bool `long:"watch" description:"Watch for interface changes"`
|
||||
|
||||
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"`
|
||||
// Netlink Interface
|
||||
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"`
|
||||
Timeout time.Duration `long:"timeout" value-name:"DURATION" default:"10s" description:"Timeout for sever queries"`
|
||||
Retry time.Duration `long:"retry" value-name:"DURATION" default:"30s" description:"Retry interval, increased for each retry attempt"`
|
||||
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"`
|
||||
// DNS Update
|
||||
Server string `long:"server" value-name:"HOST[:PORT]" description:"Server for UPDATE query, default is discovered from zone SOA"`
|
||||
Timeout time.Duration `long:"timeout" value-name:"DURATION" default:"10s" description:"Timeout for sever queries"`
|
||||
Retry time.Duration `long:"retry" value-name:"DURATION" default:"30s" description:"Retry interval, increased for each retry attempt"`
|
||||
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."`
|
||||
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"`
|
||||
TTL time.Duration `long:"ttl" value-name:"DURATION" default:"60s" description:"TTL for updated records"`
|
||||
|
||||
Args struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
|
@ -38,7 +39,7 @@ func main() {
|
|||
}
|
||||
|
||||
var update = Update{
|
||||
ttl: int(options.TTL.Seconds()),
|
||||
ttl: int(options.TTL.Seconds()),
|
||||
timeout: options.Timeout,
|
||||
retry: options.Retry,
|
||||
verbose: options.Verbose,
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/vishvananda/netlink"
|
||||
"fmt"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
// zero value is unspec=all
|
||||
type Family int
|
||||
|
||||
func (f *Family) UnmarshalFlag(value string) error {
|
||||
switch (value) {
|
||||
switch value {
|
||||
case "unspec", "all":
|
||||
*f = netlink.FAMILY_ALL
|
||||
case "inet", "ipv4":
|
||||
|
@ -22,5 +22,3 @@ func (f *Family) UnmarshalFlag(value string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
|
36
update.go
36
update.go
|
@ -1,31 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/miekg/dns"
|
||||
"time"
|
||||
"fmt"
|
||||
"net"
|
||||
"github.com/miekg/dns"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type updateState struct {
|
||||
updateZone string
|
||||
removeNames []dns.RR
|
||||
inserts []dns.RR
|
||||
updateZone string
|
||||
removeNames []dns.RR
|
||||
inserts []dns.RR
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
ttl int
|
||||
timeout time.Duration
|
||||
retry time.Duration
|
||||
verbose bool
|
||||
ttl int
|
||||
timeout time.Duration
|
||||
retry time.Duration
|
||||
verbose bool
|
||||
|
||||
zone string
|
||||
name string
|
||||
zone string
|
||||
name string
|
||||
|
||||
tsig map[string]string
|
||||
tsig map[string]string
|
||||
tsigAlgo TSIGAlgorithm
|
||||
server string
|
||||
server string
|
||||
|
||||
updateChan chan updateState
|
||||
doneChan chan error
|
||||
|
@ -77,7 +77,7 @@ func (u *Update) buildAddr(ip net.IP) dns.RR {
|
|||
if ip4 := ip.To4(); ip4 != nil {
|
||||
return &dns.A{
|
||||
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) {
|
||||
state.updateZone = u.zone
|
||||
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))
|
||||
})
|
||||
|
||||
|
@ -173,7 +173,7 @@ func (u *Update) run() {
|
|||
var updateChan = u.updateChan
|
||||
var updateError error
|
||||
|
||||
defer func(){u.doneChan <-updateError}()
|
||||
defer func() { u.doneChan <- updateError }()
|
||||
|
||||
for {
|
||||
select {
|
||||
|
|
Loading…
Reference in New Issue