Depointerise headers
This commit is contained in:
parent
8a69986574
commit
7e1549607d
4 changed files with 27 additions and 27 deletions
24
aurp/aurp.go
24
aurp/aurp.go
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
// TrHeader represent an AURP-Tr packet header. It includes the domain header.
|
// TrHeader represent an AURP-Tr packet header. It includes the domain header.
|
||||||
type TrHeader struct {
|
type TrHeader struct {
|
||||||
*DomainHeader
|
DomainHeader
|
||||||
|
|
||||||
ConnectionID uint16
|
ConnectionID uint16
|
||||||
Sequence uint16 // Note: 65535 is succeeded by 1, not 0
|
Sequence uint16 // Note: 65535 is succeeded by 1, not 0
|
||||||
|
@ -20,17 +20,17 @@ type TrHeader struct {
|
||||||
// header.
|
// header.
|
||||||
func (h *TrHeader) WriteTo(w io.Writer) (int64, error) {
|
func (h *TrHeader) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(h.DomainHeader)
|
a.writeTo(&h.DomainHeader)
|
||||||
a.write16(h.ConnectionID)
|
a.write16(h.ConnectionID)
|
||||||
a.write16(h.Sequence)
|
a.write16(h.Sequence)
|
||||||
return a.ret()
|
return a.ret()
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTrHeader(p []byte) (*TrHeader, []byte, error) {
|
func parseTrHeader(p []byte) (TrHeader, []byte, error) {
|
||||||
if len(p) < 4 {
|
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]),
|
ConnectionID: binary.BigEndian.Uint16(p[:2]),
|
||||||
Sequence: binary.BigEndian.Uint16(p[2:4]),
|
Sequence: binary.BigEndian.Uint16(p[2:4]),
|
||||||
}, p[4:], nil
|
}, 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,
|
// Header represents an AURP packet header. It includes the AURP-Tr header,
|
||||||
// which includes the domain header.
|
// which includes the domain header.
|
||||||
type Header struct {
|
type Header struct {
|
||||||
*TrHeader
|
TrHeader
|
||||||
|
|
||||||
CommandCode CmdCode
|
CommandCode CmdCode
|
||||||
Flags RoutingFlag
|
Flags RoutingFlag
|
||||||
|
@ -48,17 +48,17 @@ type Header struct {
|
||||||
// WriteTo writes the encoded form of the header to w.
|
// WriteTo writes the encoded form of the header to w.
|
||||||
func (h *Header) WriteTo(w io.Writer) (int64, error) {
|
func (h *Header) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(h.TrHeader)
|
a.writeTo(&h.TrHeader)
|
||||||
a.write16(uint16(h.CommandCode))
|
a.write16(uint16(h.CommandCode))
|
||||||
a.write16(uint16(h.Flags))
|
a.write16(uint16(h.Flags))
|
||||||
return a.ret()
|
return a.ret()
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseHeader(p []byte) (*Header, []byte, error) {
|
func parseHeader(p []byte) (Header, []byte, error) {
|
||||||
if len(p) < 4 {
|
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])),
|
CommandCode: CmdCode(binary.BigEndian.Uint16(p[:2])),
|
||||||
Flags: RoutingFlag(binary.BigEndian.Uint16(p[2:4])),
|
Flags: RoutingFlag(binary.BigEndian.Uint16(p[2:4])),
|
||||||
}, p[4:], nil
|
}, p[4:], nil
|
||||||
|
@ -123,14 +123,14 @@ type Packet interface {
|
||||||
|
|
||||||
// AppleTalkPacket is for encapsulated AppleTalk traffic.
|
// AppleTalkPacket is for encapsulated AppleTalk traffic.
|
||||||
type AppleTalkPacket struct {
|
type AppleTalkPacket struct {
|
||||||
*DomainHeader // where PacketTypeAppleTalk
|
DomainHeader // where PacketTypeAppleTalk
|
||||||
|
|
||||||
Data []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AppleTalkPacket) WriteTo(w io.Writer) (int64, error) {
|
func (p *AppleTalkPacket) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(p.DomainHeader)
|
a.writeTo(&p.DomainHeader)
|
||||||
a.write(p.Data)
|
a.write(p.Data)
|
||||||
return a.ret()
|
return a.ret()
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,19 +39,19 @@ func (dh *DomainHeader) WriteTo(w io.Writer) (int64, error) {
|
||||||
|
|
||||||
// parseDomainHeader parses a domain header, returning the DH and the remainder
|
// 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.
|
// 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)
|
ddi, b, err := parseDomainIdentifier(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, b, err
|
return DomainHeader{}, b, err
|
||||||
}
|
}
|
||||||
sdi, b, err := parseDomainIdentifier(b)
|
sdi, b, err := parseDomainIdentifier(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, b, err
|
return DomainHeader{}, b, err
|
||||||
}
|
}
|
||||||
if len(b) < 6 { // sizeof(version + reserved + packettype)
|
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,
|
DestinationDI: ddi,
|
||||||
SourceDI: sdi,
|
SourceDI: sdi,
|
||||||
Version: binary.BigEndian.Uint16(b[:2]),
|
Version: binary.BigEndian.Uint16(b[:2]),
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
// OpenReq is used to open a one-way connection between AIRs.
|
// OpenReq is used to open a one-way connection between AIRs.
|
||||||
type OpenReqPacket struct {
|
type OpenReqPacket struct {
|
||||||
*Header
|
Header
|
||||||
|
|
||||||
Version uint16 // currently always 1
|
Version uint16 // currently always 1
|
||||||
Options Options
|
Options Options
|
||||||
|
@ -16,7 +16,7 @@ type OpenReqPacket struct {
|
||||||
|
|
||||||
func (p *OpenReqPacket) WriteTo(w io.Writer) (int64, error) {
|
func (p *OpenReqPacket) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(p.Header)
|
a.writeTo(&p.Header)
|
||||||
a.write16(p.Version)
|
a.write16(p.Version)
|
||||||
a.writeTo(p.Options)
|
a.writeTo(p.Options)
|
||||||
return a.ret()
|
return a.ret()
|
||||||
|
@ -38,7 +38,7 @@ func parseOpenReq(p []byte) (*OpenReqPacket, error) {
|
||||||
|
|
||||||
// OpenRsp is used to respond to Open-Req.
|
// OpenRsp is used to respond to Open-Req.
|
||||||
type OpenRspPacket struct {
|
type OpenRspPacket struct {
|
||||||
*Header
|
Header
|
||||||
|
|
||||||
RateOrErrCode int16
|
RateOrErrCode int16
|
||||||
Options Options
|
Options Options
|
||||||
|
@ -46,7 +46,7 @@ type OpenRspPacket struct {
|
||||||
|
|
||||||
func (p *OpenRspPacket) WriteTo(w io.Writer) (int64, error) {
|
func (p *OpenRspPacket) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(p.Header)
|
a.writeTo(&p.Header)
|
||||||
a.write16(uint16(p.RateOrErrCode))
|
a.write16(uint16(p.RateOrErrCode))
|
||||||
a.writeTo(p.Options)
|
a.writeTo(p.Options)
|
||||||
return a.ret()
|
return a.ret()
|
||||||
|
|
|
@ -7,18 +7,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type RIReqPacket struct {
|
type RIReqPacket struct {
|
||||||
*Header
|
Header
|
||||||
}
|
}
|
||||||
|
|
||||||
type RIRspPacket struct {
|
type RIRspPacket struct {
|
||||||
*Header
|
Header
|
||||||
|
|
||||||
Networks NetworkTuples
|
Networks NetworkTuples
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RIRspPacket) WriteTo(w io.Writer) (int64, error) {
|
func (p *RIRspPacket) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(p.Header)
|
a.writeTo(&p.Header)
|
||||||
a.writeTo(p.Networks)
|
a.writeTo(p.Networks)
|
||||||
return a.ret()
|
return a.ret()
|
||||||
}
|
}
|
||||||
|
@ -34,18 +34,18 @@ func parseRIRsp(p []byte) (*RIRspPacket, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RIAckPacket struct {
|
type RIAckPacket struct {
|
||||||
*Header
|
Header
|
||||||
}
|
}
|
||||||
|
|
||||||
type RIUpdPacket struct {
|
type RIUpdPacket struct {
|
||||||
*Header
|
Header
|
||||||
|
|
||||||
Events EventTuples
|
Events EventTuples
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *RIUpdPacket) WriteTo(w io.Writer) (int64, error) {
|
func (p *RIUpdPacket) WriteTo(w io.Writer) (int64, error) {
|
||||||
a := acc(w)
|
a := acc(w)
|
||||||
a.writeTo(p.Header)
|
a.writeTo(&p.Header)
|
||||||
a.writeTo(p.Events)
|
a.writeTo(p.Events)
|
||||||
return a.ret()
|
return a.ret()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue