2021-05-11 17:10:51 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"net"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var ErrTargetIPNotFound = errors.New("target IP address not found")
|
|
|
|
|
|
2021-08-17 14:08:53 +00:00
|
|
|
func GetTargetIPOpenVPNConnection(connections []models.OpenVPNConnection,
|
2021-05-11 17:10:51 +00:00
|
|
|
targetIP net.IP) (connection models.OpenVPNConnection, err error) {
|
|
|
|
|
for _, connection := range connections {
|
|
|
|
|
if targetIP.Equal(connection.IP) {
|
|
|
|
|
return connection, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return connection, fmt.Errorf("%w: in %d filtered connections",
|
|
|
|
|
ErrTargetIPNotFound, len(connections))
|
|
|
|
|
}
|