2023-05-02 23:33:14 +00:00
|
|
|
package dhcp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-05-03 02:57:04 +00:00
|
|
|
"fmt"
|
2023-05-02 23:33:14 +00:00
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OptionTag uint8
|
|
|
|
|
|
|
|
type Option func(req *BootRequest, r io.Reader) error
|
|
|
|
|
|
|
|
const (
|
|
|
|
OptionTagPadding OptionTag = 0
|
2023-05-03 02:57:04 +00:00
|
|
|
OptionTagHostName OptionTag = 12
|
|
|
|
OptionTagMessageType OptionTag = 53
|
|
|
|
OptionTagParameterRequestList OptionTag = 55
|
|
|
|
OptionTagEnd OptionTag = 255
|
2023-05-02 23:33:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var optionRegistry = map[OptionTag]Option{
|
2023-05-03 02:57:04 +00:00
|
|
|
OptionTagPadding: OptionPad,
|
2023-05-02 23:33:14 +00:00
|
|
|
OptionTagHostName: OptionHostName,
|
|
|
|
OptionTagMessageType: OptionMessageType,
|
|
|
|
OptionTagParameterRequestList: OptionParameterRequestList,
|
|
|
|
OptionTagEnd: OptionEnd,
|
|
|
|
}
|
|
|
|
|
|
|
|
func OptionPad(req *BootRequest, r io.Reader) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func OptionHostName(req *BootRequest, r io.Reader) error {
|
|
|
|
return errors.New("dhcp: option not implemented yet")
|
|
|
|
}
|
|
|
|
|
|
|
|
func OptionMessageType(req *BootRequest, r io.Reader) error {
|
|
|
|
return errors.New("dhcp: option not implemented yet")
|
|
|
|
}
|
|
|
|
|
|
|
|
func OptionParameterRequestList(req *BootRequest, r io.Reader) error {
|
|
|
|
return errors.New("dhcp: option not implemented yet")
|
|
|
|
}
|
|
|
|
|
|
|
|
func OptionEnd(req *BootRequest, r io.Reader) error {
|
|
|
|
return errors.New("dhcp: option not implemented yet")
|
|
|
|
}
|
2023-05-03 02:57:04 +00:00
|
|
|
|
|
|
|
func ReadOption(req *BootRequest, tag byte, r io.Reader) error {
|
|
|
|
opt := OptionTag(tag)
|
|
|
|
if f, ok := optionRegistry[opt]; ok {
|
|
|
|
return f(req, r)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("dhcp: unknown/unhandled option %d", opt)
|
|
|
|
}
|