2015-02-22 20:58:52 -05:00
|
|
|
package bridge
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/vishvananda/netlink"
|
|
|
|
)
|
|
|
|
|
2015-03-04 16:25:43 -05:00
|
|
|
var bridgeIPv6 *net.IPNet
|
2015-02-22 20:58:52 -05:00
|
|
|
|
2015-03-04 16:25:43 -05:00
|
|
|
const bridgeIPv6Str = "fe80::1/64"
|
2015-02-22 20:58:52 -05:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
// We allow ourselves to panic in this special case because we indicate a
|
|
|
|
// failure to parse a compile-time define constant.
|
2015-03-04 16:25:43 -05:00
|
|
|
if ip, netw, err := net.ParseCIDR(bridgeIPv6Str); err == nil {
|
|
|
|
bridgeIPv6 = &net.IPNet{IP: ip, Mask: netw.Mask}
|
2015-02-22 20:58:52 -05:00
|
|
|
} else {
|
2015-03-04 16:25:43 -05:00
|
|
|
panic(fmt.Sprintf("Cannot parse default bridge IPv6 address %q: %v", bridgeIPv6Str, err))
|
2015-02-22 20:58:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:51:26 -04:00
|
|
|
func setupBridgeIPv6(config *NetworkConfiguration, i *bridgeInterface) error {
|
2015-02-22 20:58:52 -05:00
|
|
|
// Enable IPv6 on the bridge
|
2015-04-15 01:25:42 -04:00
|
|
|
procFile := "/proc/sys/net/ipv6/conf/" + config.BridgeName + "/disable_ipv6"
|
2015-02-22 20:58:52 -05:00
|
|
|
if err := ioutil.WriteFile(procFile, []byte{'0', '\n'}, 0644); err != nil {
|
|
|
|
return fmt.Errorf("Unable to enable IPv6 addresses on bridge: %v", err)
|
|
|
|
}
|
2015-02-27 12:11:53 -05:00
|
|
|
|
2015-04-28 01:57:36 -04:00
|
|
|
_, addrsv6, err := i.addresses()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-05-12 19:35:15 -04:00
|
|
|
// Add the default link local ipv6 address if it doesn't exist
|
|
|
|
if !findIPv6Address(netlink.Addr{IPNet: bridgeIPv6}, addrsv6) {
|
2015-04-28 01:57:36 -04:00
|
|
|
if err := netlink.AddrAdd(i.Link, &netlink.Addr{IPNet: bridgeIPv6}); err != nil {
|
|
|
|
return &IPv6AddrAddError{ip: bridgeIPv6, err: err}
|
|
|
|
}
|
2015-02-27 12:11:53 -05:00
|
|
|
}
|
|
|
|
|
2015-04-24 18:13:44 -04:00
|
|
|
// Store bridge network and default gateway
|
2015-04-10 12:02:25 -04:00
|
|
|
i.bridgeIPv6 = bridgeIPv6
|
2015-04-24 18:13:44 -04:00
|
|
|
i.gatewayIPv6 = i.bridgeIPv6.IP
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:51:26 -04:00
|
|
|
func setupGatewayIPv6(config *NetworkConfiguration, i *bridgeInterface) error {
|
2015-04-24 18:13:44 -04:00
|
|
|
if config.FixedCIDRv6 == nil {
|
|
|
|
return ErrInvalidContainerSubnet
|
|
|
|
}
|
|
|
|
if !config.FixedCIDRv6.Contains(config.DefaultGatewayIPv6) {
|
|
|
|
return ErrInvalidGateway
|
|
|
|
}
|
|
|
|
if _, err := ipAllocator.RequestIP(config.FixedCIDRv6, config.DefaultGatewayIPv6); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store requested default gateway
|
|
|
|
i.gatewayIPv6 = config.DefaultGatewayIPv6
|
2015-04-10 12:02:25 -04:00
|
|
|
|
2015-02-27 12:11:53 -05:00
|
|
|
return nil
|
2015-02-22 20:58:52 -05:00
|
|
|
}
|