示例#1
0
文件: client.go 项目: kjplatz/vic
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
}
示例#2
0
文件: lease.go 项目: blablacar/dgr
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),
	)
}
示例#3
0
文件: client.go 项目: kjplatz/vic
func (c *client) newClient(ack *dhcp.Packet) (*dhcp4client.Client, error) {
	conn, err := dhcp4client.NewInetSock(dhcp4client.SetRemoteAddr(net.UDPAddr{IP: ack.ServerIP(), Port: 67}))
	if err != nil {
		return nil, err
	}

	cl, err := dhcp4client.New(dhcp4client.Connection(conn), dhcp4client.Timeout(c.timeout))
	if err != nil {
		return nil, err
	}

	return cl, nil
}
示例#4
0
文件: client.go 项目: vmware/vic
func (c *client) newClient() (*dhcp4client.Client, error) {
	defer trace.End(trace.Begin(""))

	ack := dhcp.NewPacket(c.ack)
	conn, err := dhcp4client.NewInetSock(dhcp4client.SetRemoteAddr(net.UDPAddr{IP: ack.ServerIP(), Port: 67}))
	if err != nil {
		return nil, err
	}

	cl, err := dhcp4client.New(dhcp4client.Connection(conn), dhcp4client.Timeout(c.timeout))
	if err != nil {
		return nil, err
	}

	return cl, nil
}
示例#5
0
文件: client.go 项目: 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
}