Exemplo n.º 1
0
Arquivo: daemon.go Projeto: tdr130/oz
func BridgeInit(bridgeMAC string, nmIgnoreFile string, log *logging.Logger) (*HostNetwork, error) {
	if os.Getpid() == 1 {
		panic(errors.New("Cannot use BridgeInit from child."))
	}

	htn := &HostNetwork{
		BridgeMAC: bridgeMAC,
	}

	if nmIgnoreFile != "" {
		if _, err := os.Stat(nmIgnoreFile); os.IsNotExist(err) {
			log.Warning("Warning! Network Manager may not properly configured to ignore the bridge interface! This may result in management conflicts!")
		}
	}

	br, err := tenus.BridgeFromName(ozDefaultInterfaceBridge)
	if err != nil {
		log.Info("Bridge not found, attempting to create a new one")

		br, err = tenus.NewBridgeWithName(ozDefaultInterfaceBridge)
		if err != nil {
			return nil, fmt.Errorf("Unable to create bridge %+v", err)
		}
	}
	htn.Interface = br

	if err := htn.configureBridgeInterface(log); err != nil {
		return nil, err
	}

	brL := br.NetInterface()
	addrs, err := brL.Addrs()
	if err != nil {
		return nil, fmt.Errorf("Unable to get bridge interface addresses: %+v", err)
	}

	// Build the ip range which we will use for the network
	if err := htn.buildBridgeNetwork(addrs); err != nil {
		return nil, err
	}

	return htn, nil
}
Exemplo n.º 2
0
Arquivo: daemon.go Projeto: tdr130/oz
func (htn *HostNetwork) BridgeReconfigure(log *logging.Logger) (*HostNetwork, error) {
	if os.Getpid() == 1 {
		panic(errors.New("Cannot use BridgeReconfigure from child."))
	}

	newhtn := &HostNetwork{
		BridgeMAC: htn.BridgeMAC,
	}

	if err := htn.Interface.UnsetLinkIp(htn.Gateway, htn.GatewayNet); err != nil {
		log.Warning("Unable to remove old IP address from bridge: %+v", err)
	}

	br, err := tenus.BridgeFromName(ozDefaultInterfaceBridge)
	if err != nil {
		return nil, err
	}
	newhtn.Interface = br

	if err := newhtn.configureBridgeInterface(log); err != nil {
		return nil, err
	}

	brL := newhtn.Interface.NetInterface()
	addrs, err := brL.Addrs()
	if err != nil {
		return nil, fmt.Errorf("Unable to get bridge interface addresses: %+v", err)
	}

	// Build the ip range which we will use for the network
	if err := newhtn.buildBridgeNetwork(addrs); err != nil {
		return nil, err
	}

	return newhtn, nil
}