kdhcp/dhcp/options.go

58 lines
1.4 KiB
Go

package dhcp
import (
"errors"
"fmt"
"io"
)
type OptionTag uint8
type Option func(req *BootRequest, r io.Reader) error
const (
OptionTagPadding OptionTag = 0
OptionTagHostName OptionTag = 12
OptionTagMessageType OptionTag = 53
OptionTagParameterRequestList OptionTag = 55
OptionTagEnd OptionTag = 255
)
var optionRegistry = map[OptionTag]Option{
OptionTagPadding: OptionPad,
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")
}
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)
}