Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datapath/connector: remove unused funcs #13374

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions daemon/cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"sync"

"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/datapath/connector"
"github.com/cilium/cilium/pkg/endpoint"
"github.com/cilium/cilium/pkg/k8s"
"github.com/cilium/cilium/pkg/k8s/watchers"
Expand All @@ -34,6 +33,7 @@ import (
"github.com/cilium/cilium/pkg/option"

"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
)

Expand All @@ -43,6 +43,12 @@ type endpointRestoreState struct {
toClean []*endpoint.Endpoint
}

// checkLink returns an error if a link with linkName does not exist.
func checkLink(linkName string) error {
_, err := netlink.LinkByName(linkName)
return err
}

// validateEndpoint attempts to determine that the restored endpoint is valid, ie it
// still exists in k8s, its datapath devices are present, and Cilium is
// responsible for its workload, etc.
Expand Down Expand Up @@ -78,7 +84,7 @@ func (d *Daemon) validateEndpoint(ep *endpoint.Endpoint) (valid bool, err error)
ep.RunMetadataResolver(d.fetchK8sLabelsAndAnnotations)
}

if err := ep.ValidateConnectorPlumbing(connector.CheckLink); err != nil {
if err := ep.ValidateConnectorPlumbing(checkLink); err != nil {
return false, err
}

Expand Down
93 changes: 0 additions & 93 deletions pkg/datapath/connector/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ package connector
import (
"crypto/sha256"
"fmt"
"net"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/rand"
"github.com/cilium/cilium/pkg/sysctl"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -71,92 +67,3 @@ func truncateString(epID string, maxLen uint) string {
func DisableRpFilter(ifName string) error {
return sysctl.Disable(fmt.Sprintf("net.ipv4.conf.%s.rp_filter", ifName))
}

// GetNetInfoFromPID returns the index of the interface parent, the MAC address
// and IP address of the first interface that contains an IP address with global
// scope.
func GetNetInfoFromPID(pid int) (int, string, net.IP, error) {
netNs, err := ns.GetNS(fmt.Sprintf("/proc/%d/ns/net", pid))
if err != nil {
return 0, "", nil, err
}
defer netNs.Close()

var (
lxcMAC string
parentIndex int
ip net.IP
)

err = netNs.Do(func(_ ns.NetNS) error {
links, err := netlink.LinkList()
if err != nil {
return err
}
for _, l := range links {
addrs, err := netlink.AddrList(l, netlink.FAMILY_V4)
if err != nil {
return err
}
for _, addr := range addrs {
if addr.IP.IsGlobalUnicast() {
ip = addr.IP
lxcMAC = l.Attrs().HardwareAddr.String()
parentIndex = l.Attrs().ParentIndex
log.Debugf("link found: %+v", l.Attrs())
return nil
}
}
}
return nil
})
return parentIndex, lxcMAC, ip, err
}

// GetVethInfo populates the given endpoint with the arguments provided where
// * nodeIfName - Node Interface Name
// * parentIdx - Interface Index of the container veth pair in the host side.
// * netNSMac - MAC address of the veth pair in the container side.
func GetVethInfo(nodeIfName string, parentIdx int, netNSMac string, ep *models.EndpointChangeRequest) error {
nodeVet, err := netlink.LinkByName(nodeIfName)
if err != nil {
return fmt.Errorf("unable to lookup veth just created: %s", err)
}
l, err := netlink.LinkByIndex(parentIdx)
if err != nil {
return err
}
ep.Mac = netNSMac
ep.HostMac = nodeVet.Attrs().HardwareAddr.String()
ep.InterfaceIndex = int64(parentIdx)
ep.InterfaceName = l.Attrs().Name
return nil
}

func DeriveEndpointFrom(hostDevice, containerID string, pid int) (*models.EndpointChangeRequest, error) {
parentIdx, lxcMAC, ip, err := GetNetInfoFromPID(pid)
if err != nil {
return nil, fmt.Errorf("unable to get net info from PID %d: %s", pid, err)
}
if parentIdx == 0 {
return nil, fmt.Errorf("unable to find master index interface for %s: %s", ip, err)
}
// _, ip6, err := ipam.AllocateNext("ipv6")
// if err != nil {
// return nil, fmt.Errorf("unable to allocate IPv6 address: %s", err)
// }
epModel := &models.EndpointChangeRequest{
Addressing: &models.AddressPair{
IPV4: ip.String(),
// IPV6: ip6.String(),
},
ContainerID: containerID,
State: models.EndpointStateWaitingForIdentity,
}
err = GetVethInfo(hostDevice, parentIdx, lxcMAC, epModel)
if err != nil {
return nil, fmt.Errorf("unable to get veth info: %s", err)

}
return epModel, nil
}
6 changes: 0 additions & 6 deletions pkg/datapath/connector/veth.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,3 @@ func SetupVethWithNames(lxcIfName, tmpIfName string, mtu int, ep *models.Endpoin

return veth, &peer, nil
}

// CheckLink returns an error if a link with linkName does not exist.
func CheckLink(linkName string) error {
_, err := netlink.LinkByName(linkName)
return err
}