Depointerise headers

This commit is contained in:
Josh Deprez 2024-03-17 13:31:26 +11:00
parent 8a69986574
commit 7e1549607d
Signed by: josh
SSH key fingerprint: SHA256:zZji7w1Ilh2RuUpbQcqkLPrqmRwpiCSycbF2EfKm6Kw
4 changed files with 27 additions and 27 deletions

View file

@ -10,7 +10,7 @@ import (
// TrHeader represent an AURP-Tr packet header. It includes the domain header.
type TrHeader struct {
*DomainHeader
DomainHeader
ConnectionID uint16
Sequence uint16 // Note: 65535 is succeeded by 1, not 0
@ -20,17 +20,17 @@ type TrHeader struct {
// header.
func (h *TrHeader) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(h.DomainHeader)
a.writeTo(&h.DomainHeader)
a.write16(h.ConnectionID)
a.write16(h.Sequence)
return a.ret()
}
func parseTrHeader(p []byte) (*TrHeader, []byte, error) {
func parseTrHeader(p []byte) (TrHeader, []byte, error) {
if len(p) < 4 {
return nil, p, fmt.Errorf("insufficient input length %d for tr header", len(p))
return TrHeader{}, p, fmt.Errorf("insufficient input length %d for tr header", len(p))
}
return &TrHeader{
return TrHeader{
ConnectionID: binary.BigEndian.Uint16(p[:2]),
Sequence: binary.BigEndian.Uint16(p[2:4]),
}, p[4:], nil
@ -39,7 +39,7 @@ func parseTrHeader(p []byte) (*TrHeader, []byte, error) {
// Header represents an AURP packet header. It includes the AURP-Tr header,
// which includes the domain header.
type Header struct {
*TrHeader
TrHeader
CommandCode CmdCode
Flags RoutingFlag
@ -48,17 +48,17 @@ type Header struct {
// WriteTo writes the encoded form of the header to w.
func (h *Header) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(h.TrHeader)
a.writeTo(&h.TrHeader)
a.write16(uint16(h.CommandCode))
a.write16(uint16(h.Flags))
return a.ret()
}
func parseHeader(p []byte) (*Header, []byte, error) {
func parseHeader(p []byte) (Header, []byte, error) {
if len(p) < 4 {
return nil, p, fmt.Errorf("insufficient input length %d for header", len(p))
return Header{}, p, fmt.Errorf("insufficient input length %d for header", len(p))
}
return &Header{
return Header{
CommandCode: CmdCode(binary.BigEndian.Uint16(p[:2])),
Flags: RoutingFlag(binary.BigEndian.Uint16(p[2:4])),
}, p[4:], nil
@ -123,14 +123,14 @@ type Packet interface {
// AppleTalkPacket is for encapsulated AppleTalk traffic.
type AppleTalkPacket struct {
*DomainHeader // where PacketTypeAppleTalk
DomainHeader // where PacketTypeAppleTalk
Data []byte
}
func (p *AppleTalkPacket) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(p.DomainHeader)
a.writeTo(&p.DomainHeader)
a.write(p.Data)
return a.ret()
}

View file

@ -39,19 +39,19 @@ func (dh *DomainHeader) WriteTo(w io.Writer) (int64, error) {
// parseDomainHeader parses a domain header, returning the DH and the remainder
// of the input slice. It does not validate the version or packet type fields.
func parseDomainHeader(b []byte) (*DomainHeader, []byte, error) {
func parseDomainHeader(b []byte) (DomainHeader, []byte, error) {
ddi, b, err := parseDomainIdentifier(b)
if err != nil {
return nil, b, err
return DomainHeader{}, b, err
}
sdi, b, err := parseDomainIdentifier(b)
if err != nil {
return nil, b, err
return DomainHeader{}, b, err
}
if len(b) < 6 { // sizeof(version + reserved + packettype)
return nil, b, fmt.Errorf("insufficient remaining input length %d < 6", len(b))
return DomainHeader{}, b, fmt.Errorf("insufficient remaining input length %d < 6", len(b))
}
return &DomainHeader{
return DomainHeader{
DestinationDI: ddi,
SourceDI: sdi,
Version: binary.BigEndian.Uint16(b[:2]),

View file

@ -8,7 +8,7 @@ import (
// OpenReq is used to open a one-way connection between AIRs.
type OpenReqPacket struct {
*Header
Header
Version uint16 // currently always 1
Options Options
@ -16,7 +16,7 @@ type OpenReqPacket struct {
func (p *OpenReqPacket) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(p.Header)
a.writeTo(&p.Header)
a.write16(p.Version)
a.writeTo(p.Options)
return a.ret()
@ -38,7 +38,7 @@ func parseOpenReq(p []byte) (*OpenReqPacket, error) {
// OpenRsp is used to respond to Open-Req.
type OpenRspPacket struct {
*Header
Header
RateOrErrCode int16
Options Options
@ -46,7 +46,7 @@ type OpenRspPacket struct {
func (p *OpenRspPacket) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(p.Header)
a.writeTo(&p.Header)
a.write16(uint16(p.RateOrErrCode))
a.writeTo(p.Options)
return a.ret()

View file

@ -7,18 +7,18 @@ import (
)
type RIReqPacket struct {
*Header
Header
}
type RIRspPacket struct {
*Header
Header
Networks NetworkTuples
}
func (p *RIRspPacket) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(p.Header)
a.writeTo(&p.Header)
a.writeTo(p.Networks)
return a.ret()
}
@ -34,18 +34,18 @@ func parseRIRsp(p []byte) (*RIRspPacket, error) {
}
type RIAckPacket struct {
*Header
Header
}
type RIUpdPacket struct {
*Header
Header
Events EventTuples
}
func (p *RIUpdPacket) WriteTo(w io.Writer) (int64, error) {
a := acc(w)
a.writeTo(p.Header)
a.writeTo(&p.Header)
a.writeTo(p.Events)
return a.ret()
}