First working implementation
- implemented update request processing - separated host and domain name in config (req. for DNS updates) - enhanced NFT update validation - cleaned up example user - cleand up logging in update request - moved appropriate config into user request struct
This commit is contained in:
		@@ -24,17 +24,18 @@ type UserConfig struct {
 | 
			
		||||
 | 
			
		||||
	UserName string
 | 
			
		||||
	PassWord string
 | 
			
		||||
	Domain   string
 | 
			
		||||
	Router   UserConfigRouter
 | 
			
		||||
	Others   []UserConfigOther
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type UserConfigRouter struct {
 | 
			
		||||
	DNS string
 | 
			
		||||
	NFT UserConfigNFT
 | 
			
		||||
	Hostname string
 | 
			
		||||
	NFT      UserConfigNFT
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type UserConfigOther struct {
 | 
			
		||||
	DNS        string
 | 
			
		||||
	Hostname   string
 | 
			
		||||
	V6IID      string
 | 
			
		||||
	RegisterV4 bool
 | 
			
		||||
	NFT        UserConfigNFT
 | 
			
		||||
@@ -119,44 +120,51 @@ func (uco *UserConfigOther) ConvertIIDToAddress(localNet *net.IPNet) net.IP {
 | 
			
		||||
	return out
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ucn *UserConfigNFT) ValidateSetNames() bool {
 | 
			
		||||
func (ucn *UserConfigNFT) ValidateSetNames() error {
 | 
			
		||||
	if ucn.Set4 == "" && ucn.Set6 == "" {
 | 
			
		||||
		return true
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return ucn.Set4 != ucn.Set6
 | 
			
		||||
	if ucn.Table == "" {
 | 
			
		||||
		return errors.New("NFT table name undefined")
 | 
			
		||||
	}
 | 
			
		||||
	if ucn.Set4 == ucn.Set6 {
 | 
			
		||||
		return errors.New("set4 and set6 are identical")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (uc *UserConfig) Validate() error {
 | 
			
		||||
	if !uc.Router.NFT.ValidateSetNames() {
 | 
			
		||||
		return errors.New("router NFT set names invalid (probably identical for v4 and v6)")
 | 
			
		||||
	if err := uc.Router.NFT.ValidateSetNames(); err != nil {
 | 
			
		||||
		return fmt.Errorf("router NFT validation failed: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	if uc.Router.DNS == "" {
 | 
			
		||||
		return errors.New("router record has no DNS")
 | 
			
		||||
	if uc.Router.Hostname == "" {
 | 
			
		||||
		return errors.New("router record has no Hostname")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	dnsnames := make(map[string]bool)
 | 
			
		||||
	dnsnames[uc.Router.DNS] = true
 | 
			
		||||
	dnsnames[uc.Router.Hostname] = true
 | 
			
		||||
 | 
			
		||||
	for i, other := range uc.Others {
 | 
			
		||||
		if other.DNS == "" {
 | 
			
		||||
			return fmt.Errorf("other record #%d has no DNS", i)
 | 
			
		||||
		if other.Hostname == "" {
 | 
			
		||||
			return fmt.Errorf("other record #%d has no Hostname", i)
 | 
			
		||||
		}
 | 
			
		||||
		if dnsnames[other.DNS] {
 | 
			
		||||
			return fmt.Errorf("the DNS FQDN %s is used twice", other.DNS)
 | 
			
		||||
		if dnsnames[other.Hostname] {
 | 
			
		||||
			return fmt.Errorf("the Hostname %s is used twice", other.Hostname)
 | 
			
		||||
		}
 | 
			
		||||
		dnsnames[other.DNS] = true
 | 
			
		||||
		if !other.NFT.ValidateSetNames() {
 | 
			
		||||
			return fmt.Errorf("other %s NFT set names invalid (probably identical for v4 and v6)", other.DNS)
 | 
			
		||||
		dnsnames[other.Hostname] = true
 | 
			
		||||
		if err := other.NFT.ValidateSetNames(); err != nil {
 | 
			
		||||
			return fmt.Errorf("other %s NFT validation failed: %v", other.Hostname, err)
 | 
			
		||||
		}
 | 
			
		||||
		if other.V6IID == "" {
 | 
			
		||||
			return fmt.Errorf("other record %s has no V6IID", other.DNS)
 | 
			
		||||
			return fmt.Errorf("other record %s has no V6IID", other.Hostname)
 | 
			
		||||
		}
 | 
			
		||||
		iidIP := net.ParseIP(other.V6IID)
 | 
			
		||||
		if iidIP == nil {
 | 
			
		||||
			return fmt.Errorf("other record %s has invalid V6IID %s", other.DNS, other.V6IID)
 | 
			
		||||
			return fmt.Errorf("other record %s has invalid V6IID %s", other.Hostname, other.V6IID)
 | 
			
		||||
		}
 | 
			
		||||
		if iidIP.To4() != nil {
 | 
			
		||||
			return fmt.Errorf("other record %s IID looks like an IPv4 Address", other.DNS)
 | 
			
		||||
			return fmt.Errorf("other record %s IID looks like an IPv4 Address", other.Hostname)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user