Esempio n. 1
0
func (c *client) Request(id ID) (*dhcp.Packet, error) {
	log.Debugf("id: %+v", id)
	// send the request over a raw socket
	raw, err := dhcp4client.NewPacketSock(id.IfIndex)
	if err != nil {
		return nil, err
	}

	rawc, err := dhcp4client.New(dhcp4client.Connection(raw), dhcp4client.Timeout(c.timeout), dhcp4client.HardwareAddr(id.HardwareAddr))
	if err != nil {
		return nil, err
	}
	defer rawc.Close()

	success := false
	var p *dhcp.Packet
	err = withRetry(func() error {
		var err error
		success, p, err = c.request(id, rawc)
		return err
	})

	if err != nil {
		return nil, err
	}

	if !success {
		return nil, fmt.Errorf("failed dhcp request")
	}

	log.Debugf("%+v", p)
	return p, nil
}
Esempio n. 2
0
func newDHCPClient(link netlink.Link) (*dhcp4client.Client, error) {
	pktsock, err := dhcp4client.NewPacketSock(link.Attrs().Index)
	if err != nil {
		return nil, err
	}

	return dhcp4client.New(
		dhcp4client.HardwareAddr(link.Attrs().HardwareAddr),
		dhcp4client.Timeout(5*time.Second),
		dhcp4client.Broadcast(false),
		dhcp4client.Connection(pktsock),
	)
}
Esempio n. 3
0
File: client.go Progetto: vmware/vic
func (c *client) Request() error {
	defer trace.End(trace.Begin(""))

	log.Debugf("id: %+v", c.id)
	// send the request over a raw socket
	raw, err := dhcp4client.NewPacketSock(c.id.IfIndex)
	if err != nil {
		return err
	}

	rawc, err := dhcp4client.New(
		dhcp4client.Connection(raw),
		dhcp4client.Timeout(c.timeout),
		dhcp4client.HardwareAddr(c.id.HardwareAddr))
	if err != nil {
		return err
	}
	defer rawc.Close()

	success := false
	var p dhcp4.Packet
	err = withRetry(func() error {
		var err error
		success, p, err = c.request(rawc)
		return err
	})

	if err != nil {
		return err
	}

	if !success {
		return fmt.Errorf("failed dhcp request")
	}

	log.Debugf("%+v", p)
	c.ack = p
	return nil
}