prepare SubTLV handling in PacketDecoder

This commit is contained in:
Johannes Kimmel 2021-12-14 05:47:41 +01:00
parent b110db1f5e
commit 9bc7c59221
2 changed files with 11 additions and 1 deletions

View File

@ -90,7 +90,6 @@ func run(opt options) error {
var s tlv.PacketDecoder
s.Reset(b, src)
for s.Scan() {
var subtlv []byte
switch t := s.TLV().(type) {
case tlv.NextHop:
fmt.Printf("%12s %s\n", t.T(), t.Address)
@ -122,6 +121,7 @@ func run(opt options) error {
fmt.Println("got nil TLV")
}
}
subtlv := s.SubTLV()
for len(subtlv) > 0 {
switch tlv.SubType(subtlv[0]) {
case tlv.SubTypeSourcePrefix:

View File

@ -36,6 +36,10 @@ type TLV interface {
type SubType uint8
func (s SubType) IsMandatory() bool {
return s >= 128
}
const (
SubTypePad1 = SubType(0)
SubTypePadN = SubType(1)
@ -244,6 +248,12 @@ func (s *PacketDecoder) TLV() TLV {
}
return s.tlv
}
func (s *PacketDecoder) SubTLV() []byte {
if s.err != nil {
return nil
}
return s.subtlv
}
func (s *PacketDecoder) Err() error {
return s.err
}