Пример #1
0
// StartDHCP ListenAndServe for dhcp on port 67, binds on interface=ifName if it's
// not empty
func StartDHCP(ifName string, serverIP net.IP, datasource datasource.DataSource) error {
	handler := &Handler{
		ifName:      ifName,
		serverIP:    serverIP,
		datasource:  datasource,
		bootMessage: fmt.Sprintf("Blacksmith (%s)", datasource.SelfInfo().Version),
	}

	log.WithFields(log.Fields{
		"where":  "dhcp.StartDHCP",
		"action": "announce",
	}).Infof("Listening on %s:67 (interface: %s)", serverIP.String(), ifName)

	var err error
	if ifName != "" {
		err = dhcp4.ListenAndServeIf(ifName, handler)
	} else {
		err = dhcp4.ListenAndServe(handler)
	}

	// https://groups.google.com/forum/#!topic/coreos-user/Qbn3OdVtrZU
	if len(datasource.ClusterName()) > 50 { // 63 - 12(mac) - 1(.)
		log.WithField("where", "dhcp.StartDHCP").Warn(
			"Warning: ClusterName is too long. It may break the behaviour of the DHCP clients")
	}

	rand.Seed(time.Now().UTC().UnixNano())

	return err
}
Пример #2
0
func ServeDHCP(settings *DHCPSetting, leasePool *LeasePool) error {
	handler, err := newDHCPHandler(settings, leasePool)
	if err != nil {
		logging.Debug("DHCP", "Error in connecting etcd - %s", err.Error())
		return err
	}
	logging.Log("DHCP", "Listening on :67 - with server IP %s", settings.ServerIP.String())
	if settings.IFName != "" {
		err = dhcp4.ListenAndServeIf(settings.IFName, handler)
	} else {
		err = dhcp4.ListenAndServe(handler)
	}
	if err != nil {
		logging.Debug("DHCP", "Error in server - %s", err.Error())
	}
	return err
}
Пример #3
0
Файл: s.go Проект: u-root/u-root
// Example using DHCP with a single network interface device
func ExampleHandler() {
	serverIP := net.IP{127, 0, 0, 1}
	handler := &DHCPHandler{
		ip:            serverIP,
		leaseDuration: 2 * time.Hour,
		start:         net.IP{127, 0, 0, 1},
		leaseRange:    50,
		leases:        make(map[int]lease, 10),
		options: dhcp.Options{
			dhcp.OptionSubnetMask:       []byte{255, 255, 255, 0},
			dhcp.OptionRouter:           []byte(serverIP), // Presuming Server is also your router
			dhcp.OptionDomainNameServer: []byte(serverIP), // Presuming Server is also your DNS server
		},
	}
	log.Fatal(dhcp.ListenAndServe(handler))
	// log.Fatal(dhcp.ListenAndServeIf("eth0",handler)) // Select interface on multi interface device
}
Пример #4
0
func ServeDHCP(settings *DHCPSetting, datasource datasource.DataSource) error {
	handler, err := newDHCPHandler(settings, datasource)
	if err != nil {
		logging.Debug("DHCP", "Error in connecting etcd - %s", err.Error())
		return err
	}
	logging.Log("DHCP", "Listening on %s:67 (interface: %s)",
		settings.ServerIP.String(), settings.IFName)
	if settings.IFName != "" {
		err = dhcp4.ListenAndServeIf(settings.IFName, handler)
	} else {
		err = dhcp4.ListenAndServe(handler)
	}
	if err != nil {
		logging.Debug("DHCP", "Error in server - %s", err.Error())
	}

	rand.Seed(time.Now().UTC().UnixNano())

	return err
}