func configNetwork(updateConfig *config.Config, network *dockerclient.Network) error {
	if Options.RouteNetwork != "" && network.Name != Options.RouteNetwork {
		return nil
	}
	var route = config.Route{
		IPVSMethod: Options.RouteIPVSMethod,
	}
	for _, networkConfig := range network.IPAM.Config {
		if ip, ipnet, _ := net.ParseCIDR(networkConfig.Subnet); ipnet == nil {
			log.Printf("configNetwork %v: ignore subnet: %#v", network.ID, networkConfig.Subnet)
			continue
		} else if ip4 := ip.To4(); ip4 != nil {
			route.Prefix = ipnet.String()
			route.Gateway = Options.RouteGateway4
		} else if ip16 := ip.To16(); ip16 != nil {
			route.Prefix = ipnet.String()
			route.Gateway = Options.RouteGateway6
		}
		updateConfig.Routes[network.ID] = route
	}
	return nil
}
Translate a docker network into route configs
package main
import (
	"fmt"
	dockerclient "github.com/fsouza/go-dockerclient"
	"github.com/qmsk/clusterf/config"
	docker "github.com/qmsk/clusterf/docker"  
	"log"
	"net"
	"strings"
)
func configContainer(updateConfig *config.Config, container *dockerclient.Container) error {
	labels := container.Config.Labels
	exposedPorts := container.Config.ExposedPorts
	backendName := container.ID
	for _, serviceName := range strings.Fields(labels["net.qmsk.clusterf.service"]) {
		var backend config.ServiceBackend
		backend.IPv4 = container.NetworkSettings.IPAddress
		backend.IPv6 = container.NetworkSettings.GlobalIPv6Address
		portLabels := []struct {
			proto string
			label string
		}{
			{"tcp", "net.qmsk.clusterf.backend.tcp"},
			{"udp", "net.qmsk.clusterf.backend.udp"},
			{"tcp", fmt.Sprintf("net.qmsk.clusterf.backend:%s.tcp", serviceName)},
			{"udp", fmt.Sprintf("net.qmsk.clusterf.backend:%s.udp", serviceName)},
		}
		for _, portLabel := range portLabels {
			portName, labelFound := labels[portLabel.label]
			if !labelFound {
				continue
			}
			dockerPort := dockerclient.Port(fmt.Sprintf("%s/%s", portName, portLabel.proto))
			_, portFound := exposedPorts[dockerPort]
			if !portFound {
				log.Printf("configContainer %v: service %v %s port %s is not exposed\n", container.ID, serviceName, portLabel.proto, dockerPort)
				continue
			}
			var port uint16
			if _, err := fmt.Sscanf(dockerPort.Port(), "%d", &port); err != nil {
				log.Printf("configContainer %v: service %v %v port invalid: %#v", container.ID, serviceName, portLabel.proto, dockerPort.Port())
				continue
			}
			switch dockerPort.Proto() {
			case "tcp":
				backend.TCP = port
			case "udp":
				backend.UDP = port
			}
			if container.State.Running {
				backend.Weight = config.ServiceBackendWeight
			} else {
				backend.Weight = 0
			}
		}
		if backend.IPv4 == "" && backend.IPv6 == "" {
			continue
		}
		if backend.TCP == 0 && backend.UDP == 0 {
			continue
		}
		if service, serviceExists := updateConfig.Services[serviceName]; !serviceExists {
			updateConfig.Services[serviceName] = config.Service{
				Backends: map[string]config.ServiceBackend{
					backendName: backend,
				},
			}
		} else if serviceBackend, backendExists := service.Backends[backendName]; !backendExists {
			service.Backends[backendName] = backend
		} else {
			log.Printf("configContainer %v: service %v backend %v collision: %v", serviceName, backendName, serviceBackend)
		}
	}
	return nil
}