2024-09-14 04:21:14 +00:00
|
|
|
package types
|
|
|
|
|
2024-09-24 20:43:54 +00:00
|
|
|
import "strings"
|
2024-09-14 04:21:14 +00:00
|
|
|
|
2024-09-24 23:10:39 +00:00
|
|
|
// Identifier as defined by the kea database entries. Values are hardcoded from
|
|
|
|
// a running instance of schema version 22.1
|
2024-09-24 22:58:42 +00:00
|
|
|
type Identifier int
|
|
|
|
|
|
|
|
func (i Identifier) Int() int {
|
|
|
|
return int(i)
|
|
|
|
}
|
|
|
|
|
2024-09-24 23:10:39 +00:00
|
|
|
//go:generate stringer -linecomment -type=Identifier
|
2024-09-24 22:58:42 +00:00
|
|
|
const (
|
2024-09-24 23:10:39 +00:00
|
|
|
HwAddress Identifier = 0 // hwaddr
|
|
|
|
DuID Identifier = 1 // duid
|
|
|
|
CircuitId Identifier = 2 // circuit-id
|
|
|
|
ClientId Identifier = 3 // client-id
|
|
|
|
FlexId Identifier = 4 // flex-id
|
|
|
|
Invalid Identifier = 255 // invalid
|
2024-09-24 22:58:42 +00:00
|
|
|
)
|
|
|
|
|
2024-09-24 23:10:39 +00:00
|
|
|
// TODO: is there a generator that can create the lookup table for me?
|
2024-09-24 22:58:42 +00:00
|
|
|
var types = map[string]Identifier{
|
|
|
|
"macaddr": HwAddress,
|
|
|
|
"hwaddr": HwAddress,
|
|
|
|
"duid": DuID,
|
|
|
|
"circuit-id": CircuitId,
|
|
|
|
"client-id": ClientId,
|
|
|
|
"flex-id": FlexId,
|
|
|
|
"invalid": Invalid,
|
2024-09-24 20:43:54 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 23:10:39 +00:00
|
|
|
func LookupIdentifier(rtype string) Identifier {
|
2024-09-24 20:43:54 +00:00
|
|
|
rtype = strings.ToLower(rtype)
|
|
|
|
if t, ok := types[rtype]; ok == true {
|
|
|
|
return t
|
|
|
|
}
|
2024-09-24 22:58:42 +00:00
|
|
|
return Invalid
|
2024-09-24 20:43:54 +00:00
|
|
|
}
|