Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1958 from /issues/1940-remove-proxy-attachrouter-dep
Browse files Browse the repository at this point in the history
Use netlink instead of shelling out to `weave attach-router`
  • Loading branch information
marccarre authored Apr 25, 2017
2 parents 1c6abbb + 4f7d476 commit 8227a3f
Show file tree
Hide file tree
Showing 19 changed files with 734 additions and 471 deletions.
7 changes: 3 additions & 4 deletions ipam/tracker/awsvpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/vishvananda/netlink"

"github.com/weaveworks/weave/common"
wnet "github.com/weaveworks/weave/net"
"github.com/weaveworks/weave/net/address"
)

Expand All @@ -42,7 +41,7 @@ type AWSVPCTracker struct {
}

// NewAWSVPCTracker creates and initialises AWS VPC based tracker.
func NewAWSVPCTracker() (*AWSVPCTracker, error) {
func NewAWSVPCTracker(bridgeName string) (*AWSVPCTracker, error) {
var (
err error
session = session.New()
Expand All @@ -69,9 +68,9 @@ func NewAWSVPCTracker() (*AWSVPCTracker, error) {
t.routeTableID = *routeTableID

// Detect Weave bridge link index
link, err := netlink.LinkByName(wnet.WeaveBridgeName)
link, err := netlink.LinkByName(bridgeName)
if err != nil {
return nil, fmt.Errorf("cannot find \"%s\" interface: %s", wnet.WeaveBridgeName, err)
return nil, fmt.Errorf("cannot find \"%s\" interface: %s", bridgeName, err)
}
t.linkIndex = link.Attrs().Index

Expand Down
11 changes: 3 additions & 8 deletions nameserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@ func (n *Nameserver) HandleHTTP(router *mux.Router, dockerCli *docker.Client) {
vars = mux.Vars(r)
container = vars["container"]
ipStr = vars["ip"]
hostname = dns.Fqdn(r.FormValue("fqdn"))
fqdn = r.FormValue("fqdn")
ip, err = address.ParseIP(ipStr)
)
if err != nil {
n.badRequest(w, err)
return
}

if !dns.IsSubDomain(n.domain, hostname) {
n.infof("Ignoring registration %s %s %s (not a subdomain of %s)", hostname, ipStr, container, n.domain)
return
}

n.AddEntry(hostname, container, n.ourName, ip)
n.AddEntryFQDN(fqdn, container, n.ourName, ip)

if r.FormValue("check-alive") == "true" && dockerCli != nil && dockerCli.IsContainerNotRunning(container) {
n.infof("container '%s' is not running: removing", container)
n.Delete(hostname, container, ipStr, ip)
n.Delete(dns.Fqdn(fqdn), container, ipStr, ip)
}

w.WriteHeader(204)
Expand Down
9 changes: 9 additions & 0 deletions nameserver/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func (n *Nameserver) AddEntry(hostname, containerid string, origin mesh.PeerName
n.broadcastEntries(entry)
}

func (n *Nameserver) AddEntryFQDN(fqdn, containerid string, origin mesh.PeerName, addr address.Address) {
hostname := dns.Fqdn(fqdn)
if !dns.IsSubDomain(n.domain, hostname) {
n.infof("Ignoring registration %s %s %s (not a subdomain of %s)", hostname, addr.String(), containerid, n.domain)
return
}
n.AddEntry(hostname, containerid, origin, addr)
}

func (n *Nameserver) Lookup(hostname string) []address.Address {
n.RLock()
defer n.RUnlock()
Expand Down
5 changes: 5 additions & 0 deletions net/address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (cidr CIDR) String() string {
return fmt.Sprintf("%s/%d", cidr.Addr.String(), cidr.PrefixLen)
}

func (cidr CIDR) IPNet() (r *net.IPNet) {
mask := net.CIDRMask(cidr.PrefixLen, 8*net.IPv4len)
return &net.IPNet{IP: cidr.Addr.IP4(), Mask: mask}
}

// FromIP4 converts an ipv4 address to our integer address type
func FromIP4(ip4 net.IP) (r Address) {
for _, b := range ip4.To4() {
Expand Down
13 changes: 13 additions & 0 deletions net/address/address_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package address

import (
"net"
"testing"
"testing/quick"

Expand Down Expand Up @@ -67,3 +68,15 @@ func TestCIDRStartAndEnd(t *testing.T) {
require.Equal(t, ip("10.0.0.0"), cidr.Start(), "")
require.Equal(t, ip("10.0.1.0"), cidr.End(), "")
}

func TestConversions(t *testing.T) {
addrStr := "10.2.3.0"
cidrStr := addrStr + "/24"
addr := ip(addrStr)
require.Equal(t, addr.String(), addrStr)
require.Equal(t, addr.IP4(), net.ParseIP(addrStr).To4())
cidr, _ := ParseCIDR(cidrStr)
require.Equal(t, cidr.String(), cidrStr)
_, ipnet, _ := net.ParseCIDR(cidrStr)
require.Equal(t, cidr.IPNet(), ipnet)
}
21 changes: 12 additions & 9 deletions net/arp.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package net

import "fmt"
import "io"
import "os"
import (
"fmt"
"io"
"os"
"path/filepath"
)

// Configure the ARP cache parameters for the given interface. This
// makes containers react more quickly to a change in the MAC address
// associated with an IP address.
func ConfigureARPCache(name string) error {
if err := sysctl(fmt.Sprintf("net/ipv4/neigh/%s/base_reachable_time", name), "5"); err != nil {
func ConfigureARPCache(procPath, name string) error {
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/base_reachable_time", name), "5"); err != nil {
return err
}
if err := sysctl(fmt.Sprintf("net/ipv4/neigh/%s/delay_first_probe_time", name), "2"); err != nil {
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/delay_first_probe_time", name), "2"); err != nil {
return err
}
if err := sysctl(fmt.Sprintf("net/ipv4/neigh/%s/ucast_solicit", name), "1"); err != nil {
if err := sysctl(procPath, fmt.Sprintf("net/ipv4/neigh/%s/ucast_solicit", name), "1"); err != nil {
return err
}
return nil
}

func sysctl(variable, value string) error {
f, err := os.OpenFile(fmt.Sprintf("/proc/sys/%s", variable), os.O_WRONLY, 0)
func sysctl(procPath, variable, value string) error {
f, err := os.OpenFile(filepath.Join(procPath, "/sys/", variable), os.O_WRONLY, 0)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 8227a3f

Please sign in to comment.