2022-09-05 09:06:35 +02:00
|
|
|
package routemanager
|
|
|
|
|
2023-04-17 11:15:37 +02:00
|
|
|
import (
|
|
|
|
"context"
|
2024-06-13 13:24:24 +02:00
|
|
|
"errors"
|
2024-04-08 18:56:52 +02:00
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"net/netip"
|
|
|
|
"net/url"
|
2023-04-17 11:15:37 +02:00
|
|
|
"runtime"
|
|
|
|
"sync"
|
2024-06-13 13:24:24 +02:00
|
|
|
"time"
|
2023-04-17 11:15:37 +02:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2023-12-08 10:48:21 +01:00
|
|
|
firewall "github.com/netbirdio/netbird/client/firewall/manager"
|
2023-11-02 19:04:33 +01:00
|
|
|
"github.com/netbirdio/netbird/client/internal/listener"
|
2023-04-17 11:15:37 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/peer"
|
2024-07-15 10:40:57 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/notifier"
|
2024-06-13 13:24:24 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/systemops"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/vars"
|
2024-04-23 14:42:53 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routeselector"
|
2023-04-17 11:15:37 +02:00
|
|
|
"github.com/netbirdio/netbird/iface"
|
2024-09-08 12:06:14 +02:00
|
|
|
relayClient "github.com/netbirdio/netbird/relay/client"
|
2023-04-17 11:15:37 +02:00
|
|
|
"github.com/netbirdio/netbird/route"
|
2024-04-12 16:53:11 +02:00
|
|
|
nbnet "github.com/netbirdio/netbird/util/net"
|
2023-04-17 11:15:37 +02:00
|
|
|
"github.com/netbirdio/netbird/version"
|
|
|
|
)
|
2022-09-05 09:06:35 +02:00
|
|
|
|
|
|
|
// Manager is a route manager interface
|
|
|
|
type Manager interface {
|
2024-06-17 09:47:17 +02:00
|
|
|
Init() (nbnet.AddHookFunc, nbnet.RemoveHookFunc, error)
|
2024-05-06 14:47:49 +02:00
|
|
|
UpdateRoutes(updateSerial uint64, newRoutes []*route.Route) (map[route.ID]*route.Route, route.HAMap, error)
|
|
|
|
TriggerSelection(route.HAMap)
|
2024-04-23 14:42:53 +02:00
|
|
|
GetRouteSelector() *routeselector.RouteSelector
|
2023-11-02 19:04:33 +01:00
|
|
|
SetRouteChangeListener(listener listener.NetworkChangeListener)
|
2023-06-12 14:43:55 +02:00
|
|
|
InitialRouteRange() []string
|
2023-12-08 10:48:21 +01:00
|
|
|
EnableServerRouter(firewall firewall.Manager) error
|
2022-09-05 09:06:35 +02:00
|
|
|
Stop()
|
|
|
|
}
|
2023-04-17 11:15:37 +02:00
|
|
|
|
|
|
|
// DefaultManager is the default instance of a route manager
|
|
|
|
type DefaultManager struct {
|
2024-06-13 13:24:24 +02:00
|
|
|
ctx context.Context
|
|
|
|
stop context.CancelFunc
|
|
|
|
mux sync.Mutex
|
|
|
|
clientNetworks map[route.HAUniqueID]*clientNetwork
|
|
|
|
routeSelector *routeselector.RouteSelector
|
|
|
|
serverRouter serverRouter
|
|
|
|
sysOps *systemops.SysOps
|
|
|
|
statusRecorder *peer.Status
|
2024-09-08 12:06:14 +02:00
|
|
|
relayMgr *relayClient.Manager
|
2024-08-29 21:31:19 +02:00
|
|
|
wgInterface iface.IWGIface
|
2024-06-13 13:24:24 +02:00
|
|
|
pubKey string
|
2024-07-15 10:40:57 +02:00
|
|
|
notifier *notifier.Notifier
|
2024-06-13 13:24:24 +02:00
|
|
|
routeRefCounter *refcounter.RouteRefCounter
|
|
|
|
allowedIPsRefCounter *refcounter.AllowedIPsRefCounter
|
|
|
|
dnsRouteInterval time.Duration
|
2023-04-17 11:15:37 +02:00
|
|
|
}
|
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
func NewManager(
|
|
|
|
ctx context.Context,
|
|
|
|
pubKey string,
|
|
|
|
dnsRouteInterval time.Duration,
|
2024-08-29 21:31:19 +02:00
|
|
|
wgInterface iface.IWGIface,
|
2024-06-13 13:24:24 +02:00
|
|
|
statusRecorder *peer.Status,
|
2024-09-08 12:06:14 +02:00
|
|
|
relayMgr *relayClient.Manager,
|
2024-06-13 13:24:24 +02:00
|
|
|
initialRoutes []*route.Route,
|
|
|
|
) *DefaultManager {
|
2023-08-12 11:42:36 +02:00
|
|
|
mCTX, cancel := context.WithCancel(ctx)
|
2024-07-15 10:40:57 +02:00
|
|
|
notifier := notifier.NewNotifier()
|
|
|
|
sysOps := systemops.NewSysOps(wgInterface, notifier)
|
2024-06-13 13:24:24 +02:00
|
|
|
|
2023-05-31 18:25:24 +02:00
|
|
|
dm := &DefaultManager{
|
2024-06-13 13:24:24 +02:00
|
|
|
ctx: mCTX,
|
|
|
|
stop: cancel,
|
|
|
|
dnsRouteInterval: dnsRouteInterval,
|
|
|
|
clientNetworks: make(map[route.HAUniqueID]*clientNetwork),
|
2024-09-08 12:06:14 +02:00
|
|
|
relayMgr: relayMgr,
|
2024-06-13 13:24:24 +02:00
|
|
|
routeSelector: routeselector.NewRouteSelector(),
|
|
|
|
sysOps: sysOps,
|
|
|
|
statusRecorder: statusRecorder,
|
|
|
|
wgInterface: wgInterface,
|
|
|
|
pubKey: pubKey,
|
2024-07-15 10:40:57 +02:00
|
|
|
notifier: notifier,
|
2023-05-31 18:25:24 +02:00
|
|
|
}
|
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
dm.routeRefCounter = refcounter.New(
|
|
|
|
func(prefix netip.Prefix, _ any) (any, error) {
|
|
|
|
return nil, sysOps.AddVPNRoute(prefix, wgInterface.ToInterface())
|
|
|
|
},
|
|
|
|
func(prefix netip.Prefix, _ any) error {
|
|
|
|
return sysOps.RemoveVPNRoute(prefix, wgInterface.ToInterface())
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
dm.allowedIPsRefCounter = refcounter.New(
|
|
|
|
func(prefix netip.Prefix, peerKey string) (string, error) {
|
|
|
|
// save peerKey to use it in the remove function
|
|
|
|
return peerKey, wgInterface.AddAllowedIP(peerKey, prefix.String())
|
|
|
|
},
|
|
|
|
func(prefix netip.Prefix, peerKey string) error {
|
|
|
|
if err := wgInterface.RemoveAllowedIP(peerKey, prefix.String()); err != nil {
|
|
|
|
if !errors.Is(err, iface.ErrPeerNotFound) && !errors.Is(err, iface.ErrAllowedIPNotFound) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.Tracef("Remove allowed IPs %s for %s: %v", prefix, peerKey, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2023-05-31 18:25:24 +02:00
|
|
|
if runtime.GOOS == "android" {
|
|
|
|
cr := dm.clientRoutes(initialRoutes)
|
2024-07-15 10:40:57 +02:00
|
|
|
dm.notifier.SetInitialClientRoutes(cr)
|
2023-04-17 11:15:37 +02:00
|
|
|
}
|
2023-05-31 18:25:24 +02:00
|
|
|
return dm
|
2023-04-17 11:15:37 +02:00
|
|
|
}
|
|
|
|
|
2024-04-08 18:56:52 +02:00
|
|
|
// Init sets up the routing
|
2024-06-17 09:47:17 +02:00
|
|
|
func (m *DefaultManager) Init() (nbnet.AddHookFunc, nbnet.RemoveHookFunc, error) {
|
2024-04-12 16:53:11 +02:00
|
|
|
if nbnet.CustomRoutingDisabled() {
|
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
if err := m.sysOps.CleanupRouting(); err != nil {
|
2024-04-08 18:56:52 +02:00
|
|
|
log.Warnf("Failed cleaning up routing: %v", err)
|
|
|
|
}
|
|
|
|
|
2024-09-08 12:06:14 +02:00
|
|
|
initialAddresses := []string{m.statusRecorder.GetManagementState().URL, m.statusRecorder.GetSignalState().URL}
|
|
|
|
if m.relayMgr != nil {
|
|
|
|
initialAddresses = append(initialAddresses, m.relayMgr.ServerURLs()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
ips := resolveURLsToIPs(initialAddresses)
|
2024-04-08 18:56:52 +02:00
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
beforePeerHook, afterPeerHook, err := m.sysOps.SetupRouting(ips)
|
2024-04-08 18:56:52 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("setup routing: %w", err)
|
|
|
|
}
|
|
|
|
log.Info("Routing setup complete")
|
|
|
|
return beforePeerHook, afterPeerHook, nil
|
|
|
|
}
|
|
|
|
|
2023-12-08 10:48:21 +01:00
|
|
|
func (m *DefaultManager) EnableServerRouter(firewall firewall.Manager) error {
|
|
|
|
var err error
|
2024-03-12 19:06:16 +01:00
|
|
|
m.serverRouter, err = newServerRouter(m.ctx, m.wgInterface, firewall, m.statusRecorder)
|
2023-12-08 10:48:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-04-17 11:15:37 +02:00
|
|
|
// Stop stops the manager watchers and clean firewall rules
|
|
|
|
func (m *DefaultManager) Stop() {
|
|
|
|
m.stop()
|
2023-08-12 11:42:36 +02:00
|
|
|
if m.serverRouter != nil {
|
|
|
|
m.serverRouter.cleanUp()
|
|
|
|
}
|
2024-04-12 16:53:11 +02:00
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
if m.routeRefCounter != nil {
|
|
|
|
if err := m.routeRefCounter.Flush(); err != nil {
|
|
|
|
log.Errorf("Error flushing route ref counter: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if m.allowedIPsRefCounter != nil {
|
|
|
|
if err := m.allowedIPsRefCounter.Flush(); err != nil {
|
|
|
|
log.Errorf("Error flushing allowed IPs ref counter: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-12 16:53:11 +02:00
|
|
|
if !nbnet.CustomRoutingDisabled() {
|
2024-06-13 13:24:24 +02:00
|
|
|
if err := m.sysOps.CleanupRouting(); err != nil {
|
2024-04-12 16:53:11 +02:00
|
|
|
log.Errorf("Error cleaning up routing: %v", err)
|
|
|
|
} else {
|
|
|
|
log.Info("Routing cleanup complete")
|
|
|
|
}
|
2024-04-08 18:56:52 +02:00
|
|
|
}
|
2024-04-12 16:53:11 +02:00
|
|
|
|
2024-04-08 18:56:52 +02:00
|
|
|
m.ctx = nil
|
2023-04-17 11:15:37 +02:00
|
|
|
}
|
|
|
|
|
2024-04-08 18:56:52 +02:00
|
|
|
// UpdateRoutes compares received routes with existing routes and removes, updates or adds them to the client and server maps
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *DefaultManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Route) (map[route.ID]*route.Route, route.HAMap, error) {
|
2023-04-17 11:15:37 +02:00
|
|
|
select {
|
|
|
|
case <-m.ctx.Done():
|
|
|
|
log.Infof("not updating routes as context is closed")
|
2024-04-23 14:42:53 +02:00
|
|
|
return nil, nil, m.ctx.Err()
|
2023-04-17 11:15:37 +02:00
|
|
|
default:
|
|
|
|
m.mux.Lock()
|
|
|
|
defer m.mux.Unlock()
|
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
newServerRoutesMap, newClientRoutesIDMap := m.classifyRoutes(newRoutes)
|
2023-04-17 11:15:37 +02:00
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
filteredClientRoutes := m.routeSelector.FilterSelected(newClientRoutesIDMap)
|
|
|
|
m.updateClientNetworks(updateSerial, filteredClientRoutes)
|
2024-07-15 10:40:57 +02:00
|
|
|
m.notifier.OnNewRoutes(filteredClientRoutes)
|
2023-08-12 11:42:36 +02:00
|
|
|
|
|
|
|
if m.serverRouter != nil {
|
|
|
|
err := m.serverRouter.updateRoutes(newServerRoutesMap)
|
|
|
|
if err != nil {
|
2024-04-23 14:42:53 +02:00
|
|
|
return nil, nil, fmt.Errorf("update routes: %w", err)
|
2023-08-12 11:42:36 +02:00
|
|
|
}
|
2023-04-17 11:15:37 +02:00
|
|
|
}
|
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
return newServerRoutesMap, newClientRoutesIDMap, nil
|
2023-04-17 11:15:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-15 10:40:57 +02:00
|
|
|
// SetRouteChangeListener set RouteListener for route change Notifier
|
2023-11-02 19:04:33 +01:00
|
|
|
func (m *DefaultManager) SetRouteChangeListener(listener listener.NetworkChangeListener) {
|
2024-07-15 10:40:57 +02:00
|
|
|
m.notifier.SetListener(listener)
|
2023-05-31 18:25:24 +02:00
|
|
|
}
|
|
|
|
|
2023-06-12 14:43:55 +02:00
|
|
|
// InitialRouteRange return the list of initial routes. It used by mobile systems
|
|
|
|
func (m *DefaultManager) InitialRouteRange() []string {
|
2024-07-15 10:40:57 +02:00
|
|
|
return m.notifier.GetInitialRouteRanges()
|
2023-06-12 14:43:55 +02:00
|
|
|
}
|
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
// GetRouteSelector returns the route selector
|
|
|
|
func (m *DefaultManager) GetRouteSelector() *routeselector.RouteSelector {
|
|
|
|
return m.routeSelector
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetClientRoutes returns the client routes
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *DefaultManager) GetClientRoutes() map[route.HAUniqueID]*clientNetwork {
|
2024-04-23 14:42:53 +02:00
|
|
|
return m.clientNetworks
|
|
|
|
}
|
|
|
|
|
|
|
|
// TriggerSelection triggers the selection of routes, stopping deselected watchers and starting newly selected ones
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *DefaultManager) TriggerSelection(networks route.HAMap) {
|
2024-04-23 14:42:53 +02:00
|
|
|
m.mux.Lock()
|
|
|
|
defer m.mux.Unlock()
|
|
|
|
|
|
|
|
networks = m.routeSelector.FilterSelected(networks)
|
2024-05-10 10:47:16 +02:00
|
|
|
|
2024-07-15 10:40:57 +02:00
|
|
|
m.notifier.OnNewRoutes(networks)
|
2024-05-10 10:47:16 +02:00
|
|
|
|
2024-04-23 14:42:53 +02:00
|
|
|
m.stopObsoleteClients(networks)
|
|
|
|
|
|
|
|
for id, routes := range networks {
|
|
|
|
if _, found := m.clientNetworks[id]; found {
|
|
|
|
// don't touch existing client network watchers
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
clientNetworkWatcher := newClientNetworkWatcher(m.ctx, m.dnsRouteInterval, m.wgInterface, m.statusRecorder, routes[0], m.routeRefCounter, m.allowedIPsRefCounter)
|
2024-04-23 14:42:53 +02:00
|
|
|
m.clientNetworks[id] = clientNetworkWatcher
|
|
|
|
go clientNetworkWatcher.peersStateAndUpdateWatcher()
|
|
|
|
clientNetworkWatcher.sendUpdateToClientNetworkWatcher(routesUpdate{routes: routes})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// stopObsoleteClients stops the client network watcher for the networks that are not in the new list
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *DefaultManager) stopObsoleteClients(networks route.HAMap) {
|
2023-04-17 11:15:37 +02:00
|
|
|
for id, client := range m.clientNetworks {
|
2024-04-23 14:42:53 +02:00
|
|
|
if _, ok := networks[id]; !ok {
|
|
|
|
log.Debugf("Stopping client network watcher, %s", id)
|
2024-06-13 13:24:24 +02:00
|
|
|
client.cancel()
|
2023-04-17 11:15:37 +02:00
|
|
|
delete(m.clientNetworks, id)
|
|
|
|
}
|
|
|
|
}
|
2024-04-23 14:42:53 +02:00
|
|
|
}
|
|
|
|
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *DefaultManager) updateClientNetworks(updateSerial uint64, networks route.HAMap) {
|
2024-04-23 14:42:53 +02:00
|
|
|
// removing routes that do not exist as per the update from the Management service.
|
|
|
|
m.stopObsoleteClients(networks)
|
2023-04-17 11:15:37 +02:00
|
|
|
|
|
|
|
for id, routes := range networks {
|
|
|
|
clientNetworkWatcher, found := m.clientNetworks[id]
|
|
|
|
if !found {
|
2024-06-13 13:24:24 +02:00
|
|
|
clientNetworkWatcher = newClientNetworkWatcher(m.ctx, m.dnsRouteInterval, m.wgInterface, m.statusRecorder, routes[0], m.routeRefCounter, m.allowedIPsRefCounter)
|
2023-04-17 11:15:37 +02:00
|
|
|
m.clientNetworks[id] = clientNetworkWatcher
|
|
|
|
go clientNetworkWatcher.peersStateAndUpdateWatcher()
|
|
|
|
}
|
|
|
|
update := routesUpdate{
|
|
|
|
updateSerial: updateSerial,
|
|
|
|
routes: routes,
|
|
|
|
}
|
|
|
|
clientNetworkWatcher.sendUpdateToClientNetworkWatcher(update)
|
|
|
|
}
|
|
|
|
}
|
2023-05-31 18:25:24 +02:00
|
|
|
|
2024-05-06 14:47:49 +02:00
|
|
|
func (m *DefaultManager) classifyRoutes(newRoutes []*route.Route) (map[route.ID]*route.Route, route.HAMap) {
|
|
|
|
newClientRoutesIDMap := make(route.HAMap)
|
|
|
|
newServerRoutesMap := make(map[route.ID]*route.Route)
|
|
|
|
ownNetworkIDs := make(map[route.HAUniqueID]bool)
|
2023-05-31 18:25:24 +02:00
|
|
|
|
|
|
|
for _, newRoute := range newRoutes {
|
2024-06-13 13:24:24 +02:00
|
|
|
haID := newRoute.GetHAUniqueID()
|
2023-05-31 18:25:24 +02:00
|
|
|
if newRoute.Peer == m.pubKey {
|
2024-05-06 14:47:49 +02:00
|
|
|
ownNetworkIDs[haID] = true
|
2023-05-31 18:25:24 +02:00
|
|
|
// only linux is supported for now
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
log.Warnf("received a route to manage, but agent doesn't support router mode on %s OS", runtime.GOOS)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
newServerRoutesMap[newRoute.ID] = newRoute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, newRoute := range newRoutes {
|
2024-06-13 13:24:24 +02:00
|
|
|
haID := newRoute.GetHAUniqueID()
|
2024-05-06 14:47:49 +02:00
|
|
|
if !ownNetworkIDs[haID] {
|
2024-06-13 13:24:24 +02:00
|
|
|
if !isRouteSupported(newRoute) {
|
2023-05-31 18:25:24 +02:00
|
|
|
continue
|
|
|
|
}
|
2024-05-06 14:47:49 +02:00
|
|
|
newClientRoutesIDMap[haID] = append(newClientRoutesIDMap[haID], newRoute)
|
2023-05-31 18:25:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newServerRoutesMap, newClientRoutesIDMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *DefaultManager) clientRoutes(initialRoutes []*route.Route) []*route.Route {
|
2024-04-23 14:42:53 +02:00
|
|
|
_, crMap := m.classifyRoutes(initialRoutes)
|
2024-06-18 15:31:40 +02:00
|
|
|
rs := make([]*route.Route, 0, len(crMap))
|
2023-05-31 18:25:24 +02:00
|
|
|
for _, routes := range crMap {
|
|
|
|
rs = append(rs, routes...)
|
|
|
|
}
|
|
|
|
return rs
|
|
|
|
}
|
2024-04-08 18:56:52 +02:00
|
|
|
|
2024-06-13 13:24:24 +02:00
|
|
|
func isRouteSupported(route *route.Route) bool {
|
|
|
|
if !nbnet.CustomRoutingDisabled() || route.IsDynamic() {
|
2024-05-07 12:28:30 +02:00
|
|
|
return true
|
2024-04-08 18:56:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If prefix is too small, lets assume it is a possible default prefix which is not yet supported
|
|
|
|
// we skip this prefix management
|
2024-06-13 13:24:24 +02:00
|
|
|
if route.Network.Bits() <= vars.MinRangeBits {
|
2024-04-08 18:56:52 +02:00
|
|
|
log.Warnf("This agent version: %s, doesn't support default routes, received %s, skipping this prefix",
|
2024-06-13 13:24:24 +02:00
|
|
|
version.NetbirdVersion(), route.Network)
|
2024-04-08 18:56:52 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolveURLsToIPs takes a slice of URLs, resolves them to IP addresses and returns a slice of IPs.
|
|
|
|
func resolveURLsToIPs(urls []string) []net.IP {
|
|
|
|
var ips []net.IP
|
|
|
|
for _, rawurl := range urls {
|
|
|
|
u, err := url.Parse(rawurl)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Failed to parse url %s: %v", rawurl, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ipAddrs, err := net.LookupIP(u.Hostname())
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Failed to resolve host %s: %v", u.Hostname(), err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ips = append(ips, ipAddrs...)
|
|
|
|
}
|
|
|
|
return ips
|
|
|
|
}
|