package main import ( "errors" ) func (s *OpenVpnMgt) isFree(ip string) bool { for _, remote := range s.clients { for _, c := range remote { if c.PrivIP == ip { return false } } } return true } // internal DHCP func (s *OpenVpnMgt) getIP(c *vpnSession) (string, error) { s.m.Lock() defer s.m.Unlock() ipmax := nextIP(s.ldap[c.Profile].ipMax).String() sip := s.ldap[c.Profile].ipMin.String() for ip := s.ldap[c.Profile].ipMin; sip != ipmax; ip = nextIP(ip) { sip = ip.String() if s.isFree(sip) { return sip, nil } } return "", errors.New("no more IP") }