This file is indexed.

/usr/share/gocode/src/github.com/docker/libnetwork/netutils/utils_solaris.go is in golang-github-docker-libnetwork-dev 0.8.0-dev.2+git20170202.599.45b4086-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
// +build solaris

package netutils

import (
	"fmt"
	"net"
	"os/exec"
	"strings"

	"github.com/docker/libnetwork/ipamutils"
	"github.com/vishvananda/netlink"
)

var (
	networkGetRoutesFct func(netlink.Link, int) ([]netlink.Route, error)
)

// CheckRouteOverlaps checks whether the passed network overlaps with any existing routes
func CheckRouteOverlaps(toCheck *net.IPNet) error {
	return nil
}

// ElectInterfaceAddresses looks for an interface on the OS with the specified name
// and returns returns all its IPv4 and IPv6 addresses in CIDR notation.
// If a failure in retrieving the addresses or no IPv4 address is found, an error is returned.
// If the interface does not exist, it chooses from a predefined
// list the first IPv4 address which does not conflict with other
// interfaces on the system.
func ElectInterfaceAddresses(name string) ([]*net.IPNet, []*net.IPNet, error) {
	var (
		v4Net *net.IPNet
	)

	out, err := exec.Command("/usr/sbin/ipadm", "show-addr",
		"-p", "-o", "addrobj,addr").Output()
	if err != nil {
		fmt.Println("failed to list interfaces on system")
		return nil, nil, err
	}
	alist := strings.Fields(string(out))
	for _, a := range alist {
		linkandaddr := strings.SplitN(a, ":", 2)
		if len(linkandaddr) != 2 {
			fmt.Println("failed to check interfaces on system: ", a)
			continue
		}
		gw := fmt.Sprintf("%s_gw0", name)
		link := strings.Split(linkandaddr[0], "/")[0]
		addr := linkandaddr[1]
		if gw != link {
			continue
		}
		_, ipnet, err := net.ParseCIDR(addr)
		if err != nil {
			fmt.Println("failed to parse address: ", addr)
			continue
		}
		v4Net = ipnet
		break
	}
	if v4Net == nil {
		v4Net, err = FindAvailableNetwork(ipamutils.PredefinedBroadNetworks)
		if err != nil {
			return nil, nil, err
		}
	}
	return []*net.IPNet{v4Net}, nil, nil
}

// FindAvailableNetwork returns a network from the passed list which does not
// overlap with existing interfaces in the system
func FindAvailableNetwork(list []*net.IPNet) (*net.IPNet, error) {
	out, err := exec.Command("/usr/sbin/ipadm", "show-addr",
		"-p", "-o", "addr").Output()

	if err != nil {
		fmt.Println("failed to list interfaces on system")
		return nil, err
	}
	ipaddrs := strings.Fields(string(out))
	inuse := []*net.IPNet{}
	for _, ip := range ipaddrs {
		_, ipnet, err := net.ParseCIDR(ip)
		if err != nil {
			fmt.Println("failed to check interfaces on system: ", ip)
			continue
		}
		inuse = append(inuse, ipnet)
	}
	for _, avail := range list {
		is_avail := true
		for _, ipnet := range inuse {
			if NetworkOverlaps(avail, ipnet) {
				is_avail = false
				break
			}
		}
		if is_avail {
			return avail, nil
		}
	}
	return nil, fmt.Errorf("no available network")
}