Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #41 from nabla-containers/fix-network
Browse files Browse the repository at this point in the history
temporary fix for /32 CIDR networking issue
  • Loading branch information
ricarkol authored Oct 26, 2018
2 parents 8b81a69 + fab7db1 commit 4b1eb80
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

language: go
go:
- 1.8.x
- 1.11.x
- tip

matrix:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.9
FROM golang:1.11
RUN go get -u github.com/golang/dep/cmd/dep
RUN apt update
RUN apt install -y genisoimage
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ sudo docker run --rm --runtime=runnc nablact/nabla-node-base:latest

There are many. Some are fixable and being worked on, some are fixable but harder and will take some time, and some others are ones that we don't really know how to fix (or possibly not worth fixing).

Container runtime limitations:
- Unable to properly handle /32 IP address assignments. Current hack converts cidr from 32 to 1

Here are some missing features that we are currently working on:
- a golang base image
- MirageOS and IncludeOS base images
Expand Down
46 changes: 28 additions & 18 deletions nabla-lib/network/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,52 +251,53 @@ func CreateMacvtapInterfaceDocker(tapName *string, master string) (
return masterIP, gwAddr, masterMask, tapMac, nil
}

func getMasterDetails(masterLink netlink.Link) (masterAddr *netlink.Addr, masterIP net.IP, masterMask net.IPMask, gwAddr net.IP, err error) {
func getMasterDetails(masterLink netlink.Link) (masterAddr *netlink.Addr, masterIP net.IP, masterMask net.IPMask, gwAddr net.IP, mac string, err error) {
addrs, err := netlink.AddrList(masterLink, netlink.FAMILY_V4)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, nil, "", err
}
if len(addrs) == 0 {
return nil, nil, nil, nil, fmt.Errorf("master should have an IP")
return nil, nil, nil, nil, "", fmt.Errorf("master should have an IP")
}
masterAddr = &addrs[0]
masterIP = addrs[0].IPNet.IP
masterMask = addrs[0].IPNet.Mask

routes, err := netlink.RouteList(masterLink, netlink.FAMILY_V4)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, nil, "", err
}
if len(routes) == 0 {
return nil, nil, nil, nil,
return nil, nil, nil, nil, "",
fmt.Errorf("master should have at least one route")
}
// XXX: is the "gateway" always the first route?
gwAddr = routes[0].Gw

return masterAddr, masterIP, masterMask, gwAddr, nil
macAddr := masterLink.Attrs().HardwareAddr.String()
return masterAddr, masterIP, masterMask, gwAddr, macAddr, nil
}

// CreateTapInterfaceDocker creates a new TAP interface and a bridge, adds both
// the TAP and the master link (usually eth0) to the bridge, and unsets the IP
// of the master link to be used by the unikernel NIC. Returns the assigned
// IP/mask and gateway IP.
func CreateTapInterfaceDocker(tapName string, master string) (
net.IP, net.IP, net.IPMask, error) {
net.IP, net.IP, net.IPMask, string, error) {

masterLink, err := netlink.LinkByName(master)
if err != nil {
return nil, nil, nil,
return nil, nil, nil, "",
fmt.Errorf("no master interface: %v", err)
}
masterAddr, masterIP, masterMask, gwAddr, err := getMasterDetails(masterLink)
masterAddr, masterIP, masterMask, gwAddr, mac, err := getMasterDetails(masterLink)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

err = SetupTunDev()
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

// ip tuntap add tap100 mode tap
Expand All @@ -305,24 +306,34 @@ func CreateTapInterfaceDocker(tapName string, master string) (
Mode: netlink.TUNTAP_MODE_TAP}
err = netlink.LinkAdd(tap)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

// ip link set dev tap100 up'
err = netlink.LinkSetUp(tap)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

// ip addr del $INET_STR dev master
err = netlink.AddrDel(masterLink, masterAddr)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

genmac, err := net.ParseMAC("aa:aa:aa:aa:bb:cc")
if err != nil {
return nil, nil, nil, "", err
}

err = netlink.LinkSetHardwareAddr(masterLink, genmac)
if err != nil {
return nil, nil, nil, "", err
}

br0, err := CreateBridge("br0")
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

netlink.LinkSetMaster(masterLink, br0)
Expand All @@ -331,10 +342,9 @@ func CreateTapInterfaceDocker(tapName string, master string) (
// ip link set dev br0 up'
err = netlink.LinkSetUp(br0)
if err != nil {
return nil, nil, nil, err
return nil, nil, nil, "", err
}

return masterIP, gwAddr, masterMask, nil
return masterIP, gwAddr, masterMask, mac, nil
}

// SetupTunDev sets up the /dev/net/tun device if it doesn't exists
Expand Down
11 changes: 10 additions & 1 deletion runnc-cont/rumprun.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,22 @@ func CreateRumprunArgs(ip net.IP, mask net.IPMask, gw net.IP,
mountPoint string, envVars []string, cwd string,
unikernel string, cmdargs string) (string, error) {

// XXX: Due to bug in: https://github.com/nabla-containers/runnc/issues/40
// If we detect a /32 mask, we set it to 1 as a "fix", and hope we are in
// the same subnet... (working on a fix for mask:0)
cidr := strconv.Itoa(network.MaskCIDR(mask))
if cidr == "32" {
fmt.Printf("WARNING: Changing CIDR from 32 to 1 due to Issue https://github.com/nabla-containers/runnc/issues/40\n")
cidr = "1"
}

net := rumpArgsNetwork{
If: "ukvmif0",
Cloner: "True",
Type: "inet",
Method: "static",
Addr: ip.String(),
Mask: strconv.Itoa(network.MaskCIDR(mask)),
Mask: cidr,
Gw: gw.String(),
}

Expand Down
2 changes: 1 addition & 1 deletion runnc-cont/runnc_cont.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func run(nablarun string, unikernel string, tapName string,
// container veth pair.
// XXX: This is a workaround due to an error with MacvTap, error was :
// Could not create /dev/tap8863: open /sys/devices/virtual/net/macvtap8863/tap8863/dev: no such file or directory
ip, gw, mask, err = network.CreateTapInterfaceDocker(tapName, "eth0")
ip, gw, mask, mac, err = network.CreateTapInterfaceDocker(tapName, "eth0")
if err != nil {
fmt.Fprintf(os.Stderr, "Could not create %s: %v\n", tapName, err)
return 1
Expand Down

0 comments on commit 4b1eb80

Please sign in to comment.