diff --git a/.golangci.yml b/.golangci.yml index 04ed37d..0b7141f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,13 +12,10 @@ linters-settings: linters: disable-all: true enable: # see https://golangci-lint.run/usage/linters/ - - deadcode + - unused - staticcheck - govet - gofmt - goimports - gosec - misspell - -run: - deadline: 5m diff --git a/Makefile b/Makefile index 8965ad4..d5bf223 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ test: # code linting .golangci-bin: @echo "===> Installing Golangci-lint <===" - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.41.1 + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $@ v1.50.0 .PHONY: golangci golangci: .golangci-bin diff --git a/openflow13/action.go b/openflow13/action.go index 69921b3..8f718b6 100644 --- a/openflow13/action.go +++ b/openflow13/action.go @@ -276,7 +276,31 @@ func (a *ActionGroup) UnmarshalBinary(data []byte) error { type ActionMplsTtl struct { ActionHeader MplsTtl uint8 - pad []byte // 3bytes +} + +func (a *ActionMplsTtl) Len() uint16 { + return a.ActionHeader.Len() + 4 +} + +func (a *ActionMplsTtl) MarshalBinary() (data []byte, err error) { + data, err = a.ActionHeader.MarshalBinary() + if err != nil { + return + } + n := int(a.ActionHeader.Len()) + data[n] = a.MplsTtl + return +} + +func (a *ActionMplsTtl) UnmarshalBinary(data []byte) error { + n := 0 + err := a.ActionHeader.UnmarshalBinary(data[n:]) + if err != nil { + return err + } + n += int(a.ActionHeader.Len()) + a.MplsTtl = data[n] + return nil } type ActionDecNwTtl struct { @@ -315,13 +339,36 @@ func (a *ActionDecNwTtl) UnmarshalBinary(data []byte) error { type ActionNwTtl struct { ActionHeader NwTtl uint8 - pad []byte // 3bytes +} + +func (a *ActionNwTtl) Len() uint16 { + return a.ActionHeader.Len() + 4 +} + +func (a *ActionNwTtl) MarshalBinary() (data []byte, err error) { + data, err = a.ActionHeader.MarshalBinary() + if err != nil { + return + } + n := int(a.ActionHeader.Len()) + data[n] = a.NwTtl + return +} + +func (a *ActionNwTtl) UnmarshalBinary(data []byte) error { + n := 0 + err := a.ActionHeader.UnmarshalBinary(data[n:]) + if err != nil { + return err + } + n += int(a.ActionHeader.Len()) + a.NwTtl = data[n] + return nil } type ActionPush struct { ActionHeader EtherType uint16 - pad []byte // 2bytes } func NewActionPushVlan(etherType uint16) *ActionPush { @@ -362,7 +409,6 @@ func (a *ActionPush) UnmarshalBinary(data []byte) error { type ActionPopVlan struct { ActionHeader - pad []byte // 4bytes } func NewActionPopVlan() *ActionPopVlan { @@ -395,7 +441,6 @@ func (a *ActionPopVlan) UnmarshalBinary(data []byte) error { type ActionPopMpls struct { ActionHeader EtherType uint16 - pad []byte // 2bytes } func NewActionPopMpls(etherType uint16) *ActionPopMpls { diff --git a/openflow13/bundles.go b/openflow13/bundles.go index 9eb9ccc..dd4f800 100644 --- a/openflow13/bundles.go +++ b/openflow13/bundles.go @@ -165,7 +165,6 @@ func NewBundlePropertyExperimenter() *BundlePropertyExperimenter { // it, if the added messages are not wanted to realize on the switch. type BundleAdd struct { BundleID uint32 - pad [2]byte Flags uint16 Message util.Message Properties []BundlePropertyExperimenter @@ -173,7 +172,8 @@ type BundleAdd struct { func (b *BundleAdd) Len() (n uint16) { length := uint16(unsafe.Sizeof(b.BundleID) + unsafe.Sizeof(b.Flags)) - length += uint16(len(b.pad)) + // 2 bytes for padding + length += 2 length += b.Message.Len() if b.Properties != nil { for _, p := range b.Properties { diff --git a/openflow13/flowmod.go b/openflow13/flowmod.go index ea13658..c816b8f 100644 --- a/openflow13/flowmod.go +++ b/openflow13/flowmod.go @@ -27,8 +27,6 @@ type FlowMod struct { OutGroup uint32 Flags uint16 - pad []byte // 2bytes - Match Match // Fields to match Instructions []Instruction // Instruction set - 0 or more. } diff --git a/openflow13/match.go b/openflow13/match.go index faa1559..53d2492 100644 --- a/openflow13/match.go +++ b/openflow13/match.go @@ -127,7 +127,7 @@ func (m *MatchField) MarshalBinary() (data []byte, err error) { if m.HasMask { fld = (m.Field << 1) | 0x1 } else { - fld = (m.Field << 1) | 0x0 + fld = m.Field << 1 } data[n] = fld n += 1 @@ -477,7 +477,7 @@ func DecodeMatchField(class uint16, field uint8, length uint8, hasMask bool, dat return nil, nil } -// ofp_match_type 1.3 +// ofp_match_type 1.3 const ( MatchType_Standard = iota /* Deprecated. */ MatchType_OXM diff --git a/openflow13/meter.go b/openflow13/meter.go index 6f99c5f..a29cf93 100644 --- a/openflow13/meter.go +++ b/openflow13/meter.go @@ -81,7 +81,6 @@ func (m *MeterBandHeader) UnmarshalBinary(data []byte) error { type MeterBandDrop struct { MeterBandHeader /* Type: OFPMBT13_DROP. */ - pad [4]uint8 } func (m *MeterBandDrop) Len() (n uint16) { @@ -111,7 +110,6 @@ func (m *MeterBandDrop) UnmarshalBinary(data []byte) error { type MeterBandDSCP struct { MeterBandHeader /* Type: OFPMBT13_DSCP_REMARK. */ PrecLevel uint8 /* Number of drop precedence level to add. */ - pad [3]uint8 } func (m *MeterBandDSCP) Len() (n uint16) { diff --git a/openflow13/multipart.go b/openflow13/multipart.go index c2f1eec..bd3e124 100644 --- a/openflow13/multipart.go +++ b/openflow13/multipart.go @@ -15,7 +15,6 @@ type MultipartRequest struct { common.Header Type uint16 Flags uint16 - pad []byte // 4 bytes Body []util.Message } @@ -103,7 +102,6 @@ type MultipartReply struct { common.Header Type uint16 Flags uint16 - pad []byte // 4 bytes Body []util.Message } @@ -1324,7 +1322,6 @@ type OFPTableFeatures struct { Length uint16 TableID uint8 Command uint8 - pad [4]uint8 Name [32]byte MetadataMatch uint64 MetadataWrite uint64 @@ -1350,6 +1347,7 @@ func (f *OFPTableFeatures) MarshalBinary() (data []byte, err error) { n += 1 data[n] = f.Command n += 1 + // 4 bytes for padding n += 4 copy(data[n:], f.Name[:32]) n += 32 diff --git a/openflow13/nx_action.go b/openflow13/nx_action.go index d051932..7a275be 100644 --- a/openflow13/nx_action.go +++ b/openflow13/nx_action.go @@ -1218,11 +1218,9 @@ type NXActionLearn struct { Cookie uint64 Flags uint16 TableID uint8 - pad uint8 FinIdleTimeout uint16 FinHardTimeout uint16 LearnSpecs []*NXLearnSpec - pad2 []byte } func (a *NXActionLearn) Len() uint16 { @@ -1252,7 +1250,9 @@ func (a *NXActionLearn) MarshalBinary() (data []byte, err error) { binary.BigEndian.PutUint16(data[n:], a.Flags) n += 2 data[n] = a.TableID - n += 2 + n += 1 + // 1 byte for padding + n += 1 binary.BigEndian.PutUint16(data[n:], a.FinIdleTimeout) n += 2 binary.BigEndian.PutUint16(data[n:], a.FinHardTimeout) @@ -1364,7 +1364,6 @@ func NewNXActionNote() *NXActionNote { type NXActionRegLoad2 struct { *NXActionHeader DstField *MatchField - pad []byte } func NewNXActionRegLoad2(dstField *MatchField) *NXActionRegLoad2 { @@ -1417,7 +1416,6 @@ type NXActionController struct { MaxLen uint16 ControllerID uint16 Reason uint8 - pad uint8 } func (a *NXActionController) Len() uint16 { @@ -1487,7 +1485,6 @@ const ( type NXActionController2PropMaxLen struct { *PropHeader /* Type: NXAC2PT_MAX_LEN */ MaxLen uint16 - pad [2]uint8 } func (a *NXActionController2PropMaxLen) Len() uint16 { @@ -1539,7 +1536,6 @@ func NewMaxLen(maxLen uint16) *NXActionController2PropMaxLen { type NXActionController2PropControllerID struct { *PropHeader /* Type: NXAC2PT_CONTROLLER_ID */ ControllerID uint16 - pad [2]uint8 } func (a *NXActionController2PropControllerID) Len() uint16 { @@ -1591,7 +1587,6 @@ func NewControllerID(controllerID uint16) *NXActionController2PropControllerID { type NXActionController2PropReason struct { *PropHeader /* Type: NXAC2PT_REASON */ Reason uint8 - pad [3]uint8 } func (a *NXActionController2PropReason) Len() uint16 { @@ -1643,7 +1638,6 @@ func NewReason(reason uint8) *NXActionController2PropReason { type NXActionController2PropUserdata struct { *PropHeader /* Type: NXAC2PT_USERDATA */ Userdata []byte - pad []uint8 } func (a *NXActionController2PropUserdata) Len() uint16 { @@ -1695,7 +1689,6 @@ func NewUserdata(userdata []byte) *NXActionController2PropUserdata { type NXActionController2PropPause struct { *PropHeader /* Type: NXAC2PT_PAUSE */ - pad [4]uint8 } func (a *NXActionController2PropPause) Len() uint16 { @@ -1818,7 +1811,6 @@ func DecodeController2Prop(data []byte) (Property, error) { // NXActionController2 is NX action to output packet to the Controller set with a specified ID. type NXActionController2 struct { *NXActionHeader - pad [6]uint8 props []Property } @@ -1843,6 +1835,7 @@ func (a *NXActionController2) MarshalBinary() (data []byte, err error) { } copy(data[n:], b) n += int(a.NXActionHeader.Len()) + // 6 bytes for padding n += 6 for _, prop := range a.props { diff --git a/openflow13/nxt_message.go b/openflow13/nxt_message.go index 065f1fd..6e24d58 100644 --- a/openflow13/nxt_message.go +++ b/openflow13/nxt_message.go @@ -80,12 +80,11 @@ func NewSetPacketInFormet(format uint32) *VendorHeader { } type ControllerID struct { - pad [6]byte - ID uint16 + ID uint16 } func (c *ControllerID) Len() uint16 { - return uint16(len(c.pad) + 2) + return 8 } func (c *ControllerID) MarshalBinary() (data []byte, err error) { @@ -117,11 +116,10 @@ type TLVTableMap struct { OptType uint8 OptLength uint8 Index uint16 - pad [2]byte } func (t *TLVTableMap) Len() uint16 { - return uint16(len(t.pad) + 6) + return 8 } func (t *TLVTableMap) MarshalBinary() (data []byte, err error) { @@ -154,7 +152,6 @@ func (t *TLVTableMap) UnmarshalBinary(data []byte) error { type TLVTableMod struct { Command uint16 - pad [6]byte TlvMaps []*TLVTableMap } @@ -292,7 +289,6 @@ const ( type ContinuationPropBridge struct { *PropHeader /* Type: NXCPT_BRIDGE */ Bridge [4]uint32 - pad [4]uint8 } func (p *ContinuationPropBridge) Len() (n uint16) { @@ -341,7 +337,6 @@ func (p *ContinuationPropBridge) UnmarshalBinary(data []byte) error { type ContinuationPropStack struct { *PropHeader /* Type: NXCPT_STACK */ Stack []uint8 - pad []uint8 } func (p *ContinuationPropStack) Len() (n uint16) { @@ -430,7 +425,6 @@ func (p *ContinuationPropMirrors) UnmarshalBinary(data []byte) error { type ContinuationPropConntracked struct { *PropHeader /* Type: NXCPT_CONNTRACKED */ - pad [4]uint8 } func (p *ContinuationPropConntracked) Len() (n uint16) { @@ -469,7 +463,6 @@ func (p *ContinuationPropConntracked) UnmarshalBinary(data []byte) error { type ContinuationPropTableID struct { *PropHeader /* Type: NXCPT_TABLE_ID */ TableID uint8 - pad [3]uint8 } func (p *ContinuationPropTableID) Len() (n uint16) { @@ -511,7 +504,6 @@ func (p *ContinuationPropTableID) UnmarshalBinary(data []byte) error { type ContinuationPropCookie struct { *PropHeader /* Type: NXCPT_COOKIE */ - pad [4]uint8 Cookie uint64 } @@ -554,7 +546,6 @@ func (p *ContinuationPropCookie) UnmarshalBinary(data []byte) error { type ContinuationPropActions struct { *PropHeader /* Type: NXCPT_ACTIONS */ - pad [4]uint8 Actions []Action } @@ -617,7 +608,6 @@ func (p *ContinuationPropActions) UnmarshalBinary(data []byte) error { type ContinuationPropActionSet struct { *PropHeader /* Type: NXCPT_ACTION_SET */ - pad [4]uint8 ActionSet []Action } @@ -772,7 +762,6 @@ const ( type PacketIn2PropPacket struct { *PropHeader Packet protocol.Ethernet - pad []uint8 } func (p *PacketIn2PropPacket) Len() (n uint16) { @@ -908,7 +897,6 @@ func (p *PacketIn2PropBufferID) UnmarshalBinary(data []byte) error { type PacketIn2PropTableID struct { *PropHeader /* Type: NXPINT_TABLE_ID */ TableID uint8 - pad [3]uint8 } func (p *PacketIn2PropTableID) Len() (n uint16) { @@ -950,7 +938,6 @@ func (p *PacketIn2PropTableID) UnmarshalBinary(data []byte) error { type PacketIn2PropCookie struct { *PropHeader /* Type: NXPINT_COOKIE */ - pad [4]uint8 Cookie uint64 } @@ -996,7 +983,6 @@ func (p *PacketIn2PropCookie) UnmarshalBinary(data []byte) error { type PacketIn2PropReason struct { *PropHeader /* Type: NXPINT_COOKIE */ Reason uint8 - pad [3]uint8 } func (p *PacketIn2PropReason) Len() (n uint16) { @@ -1039,7 +1025,6 @@ func (p *PacketIn2PropReason) UnmarshalBinary(data []byte) error { type PacketIn2PropMetadata struct { *PropHeader /* Type: NXPINT_METADATA */ Fields []MatchField - pad []uint8 } func (p *PacketIn2PropMetadata) Len() (n uint16) { @@ -1104,7 +1089,6 @@ func (p *PacketIn2PropMetadata) UnmarshalBinary(data []byte) error { type PacketIn2PropUserdata struct { *PropHeader /* Type: NXPINT_USERDATA */ Userdata []uint8 - pad []uint8 } func (p *PacketIn2PropUserdata) Len() (n uint16) { @@ -1149,7 +1133,6 @@ func (p *PacketIn2PropUserdata) UnmarshalBinary(data []byte) error { type PacketIn2PropContinuation struct { *PropHeader /* Type: NXPINT_CONTINUATION */ Continuation []byte - pad []uint8 } func (p *PacketIn2PropContinuation) Len() (n uint16) { diff --git a/openflow15/action.go b/openflow15/action.go index 4dfd52e..559457e 100644 --- a/openflow15/action.go +++ b/openflow15/action.go @@ -304,7 +304,31 @@ func (a *ActionGroup) UnmarshalBinary(data []byte) error { type ActionMplsTtl struct { ActionHeader MplsTtl uint8 - pad []byte // 3bytes +} + +func (a *ActionMplsTtl) Len() uint16 { + return a.ActionHeader.Len() + 4 +} + +func (a *ActionMplsTtl) MarshalBinary() (data []byte, err error) { + data, err = a.ActionHeader.MarshalBinary() + if err != nil { + return + } + n := int(a.ActionHeader.Len()) + data[n] = a.MplsTtl + return +} + +func (a *ActionMplsTtl) UnmarshalBinary(data []byte) error { + n := 0 + err := a.ActionHeader.UnmarshalBinary(data[n:]) + if err != nil { + return err + } + n += int(a.ActionHeader.Len()) + a.MplsTtl = data[n] + return nil } type ActionDecNwTtl struct { @@ -343,13 +367,36 @@ func (a *ActionDecNwTtl) UnmarshalBinary(data []byte) error { type ActionNwTtl struct { ActionHeader NwTtl uint8 - pad []byte // 3bytes +} + +func (a *ActionNwTtl) Len() uint16 { + return a.ActionHeader.Len() + 4 +} + +func (a *ActionNwTtl) MarshalBinary() (data []byte, err error) { + data, err = a.ActionHeader.MarshalBinary() + if err != nil { + return + } + n := int(a.ActionHeader.Len()) + data[n] = a.NwTtl + return +} + +func (a *ActionNwTtl) UnmarshalBinary(data []byte) error { + n := 0 + err := a.ActionHeader.UnmarshalBinary(data[n:]) + if err != nil { + return err + } + n += int(a.ActionHeader.Len()) + a.NwTtl = data[n] + return nil } type ActionPush struct { ActionHeader EtherType uint16 - pad []byte // 2bytes } func NewActionPushVlan(etherType uint16) *ActionPush { @@ -393,7 +440,6 @@ func (a *ActionPush) UnmarshalBinary(data []byte) error { type ActionPopVlan struct { ActionHeader - pad []byte // 4bytes } func NewActionPopVlan() *ActionPopVlan { @@ -429,7 +475,6 @@ func (a *ActionPopVlan) UnmarshalBinary(data []byte) error { type ActionPopMpls struct { ActionHeader EtherType uint16 - pad []byte // 2bytes } func NewActionPopMpls(etherType uint16) *ActionPopMpls { diff --git a/openflow15/bundles.go b/openflow15/bundles.go index b194d38..9cc829c 100644 --- a/openflow15/bundles.go +++ b/openflow15/bundles.go @@ -168,7 +168,6 @@ func NewBundlePropertyExperimenter() *BundlePropertyExperimenter { // it, if the added messages are not wanted to realize on the switch. type BundleAdd struct { BundleID uint32 - pad [2]byte Flags uint16 Message util.Message Properties []BundlePropertyExperimenter @@ -176,7 +175,8 @@ type BundleAdd struct { func (b *BundleAdd) Len() (n uint16) { length := uint16(unsafe.Sizeof(b.BundleID) + unsafe.Sizeof(b.Flags)) - length += uint16(len(b.pad)) + // 2 bytes for padding + length += 2 length += b.Message.Len() if b.Properties != nil { for _, p := range b.Properties { diff --git a/openflow15/match.go b/openflow15/match.go index 004466b..244efb3 100644 --- a/openflow15/match.go +++ b/openflow15/match.go @@ -130,7 +130,7 @@ func (m *MatchField) MarshalBinary() (data []byte, err error) { if m.HasMask { fld = (m.Field << 1) | 0x1 } else { - fld = (m.Field << 1) | 0x0 + fld = m.Field << 1 } data[n] = fld n += 1 @@ -276,7 +276,7 @@ func (o *OxmId) MarshalBinary() (data []byte, err error) { if o.HasMask { fld = (o.Field << 1) | 0x1 } else { - fld = (o.Field << 1) | 0x0 + fld = o.Field << 1 } data[n] = fld n += 1 diff --git a/openflow15/meter.go b/openflow15/meter.go index a5ebb24..1a7455d 100644 --- a/openflow15/meter.go +++ b/openflow15/meter.go @@ -96,7 +96,6 @@ func (m *MeterBandHeader) UnmarshalBinary(data []byte) error { // ofp_meter_band_drop type MeterBandDrop struct { MeterBandHeader /* Type: OFPMBT_DROP. */ - pad [4]uint8 } func NewMeterBandDrop() *MeterBandDrop { @@ -135,7 +134,6 @@ func (m *MeterBandDrop) UnmarshalBinary(data []byte) error { type MeterBandDSCP struct { MeterBandHeader /* Type: OFPMBT_DSCP_REMARK. */ PrecLevel uint8 /* Number of drop precedence level to add. */ - pad [3]uint8 } func NewMeterBandDSCP() *MeterBandDSCP { diff --git a/openflow15/nx_action.go b/openflow15/nx_action.go index 7aad1d8..4f28461 100644 --- a/openflow15/nx_action.go +++ b/openflow15/nx_action.go @@ -1239,11 +1239,9 @@ type NXActionLearn struct { Cookie uint64 Flags uint16 TableID uint8 - pad uint8 FinIdleTimeout uint16 FinHardTimeout uint16 LearnSpecs []*NXLearnSpec - pad2 []byte } func (a *NXActionLearn) Len() uint16 { @@ -1386,7 +1384,6 @@ func NewNXActionNote() *NXActionNote { type NXActionRegLoad2 struct { *NXActionHeader DstField *MatchField - pad []byte } func NewNXActionRegLoad2(dstField *MatchField) *NXActionRegLoad2 { @@ -1444,7 +1441,6 @@ type NXActionController struct { MaxLen uint16 ControllerID uint16 Reason uint8 - pad uint8 } func (a *NXActionController) Len() uint16 { @@ -1514,7 +1510,6 @@ const ( type NXActionController2PropMaxLen struct { *PropHeader /* Type: NXAC2PT_MAX_LEN */ MaxLen uint16 - pad [2]uint8 } func (a *NXActionController2PropMaxLen) Len() uint16 { @@ -1566,7 +1561,6 @@ func NewMaxLen(maxLen uint16) *NXActionController2PropMaxLen { type NXActionController2PropControllerID struct { *PropHeader /* Type: NXAC2PT_CONTROLLER_ID */ ControllerID uint16 - pad [2]uint8 } func (a *NXActionController2PropControllerID) Len() uint16 { @@ -1618,7 +1612,6 @@ func NewControllerID(controllerID uint16) *NXActionController2PropControllerID { type NXActionController2PropReason struct { *PropHeader /* Type: NXAC2PT_REASON */ Reason uint8 - pad [3]uint8 } func (a *NXActionController2PropReason) Len() uint16 { @@ -1670,7 +1663,6 @@ func NewReason(reason uint8) *NXActionController2PropReason { type NXActionController2PropUserdata struct { *PropHeader /* Type: NXAC2PT_USERDATA */ Userdata []byte - pad []uint8 } func (a *NXActionController2PropUserdata) Len() uint16 { @@ -1722,7 +1714,6 @@ func NewUserdata(userdata []byte) *NXActionController2PropUserdata { type NXActionController2PropPause struct { *PropHeader /* Type: NXAC2PT_PAUSE */ - pad [4]uint8 } func (a *NXActionController2PropPause) Len() uint16 { @@ -1846,7 +1837,6 @@ func DecodeController2Prop(data []byte) (Property, error) { // NXActionController2 is NX action to output packet to the Controller set with a specified ID. type NXActionController2 struct { *NXActionHeader - pad [6]uint8 props []Property } diff --git a/openflow15/nxt_message.go b/openflow15/nxt_message.go index 497c841..dbb9b4b 100644 --- a/openflow15/nxt_message.go +++ b/openflow15/nxt_message.go @@ -82,16 +82,16 @@ func NewSetPacketInFormet(format uint32) *VendorHeader { } type ControllerID struct { - pad [6]byte - ID uint16 + ID uint16 } func (c *ControllerID) Len() uint16 { - return uint16(len(c.pad) + 2) + return 8 } func (c *ControllerID) MarshalBinary() (data []byte, err error) { data = make([]byte, int(c.Len())) + // 6 bytes for padding n := 6 binary.BigEndian.PutUint16(data[n:], c.ID) return data, nil @@ -119,11 +119,10 @@ type TLVTableMap struct { OptType uint8 OptLength uint8 Index uint16 - pad [2]byte } func (t *TLVTableMap) Len() uint16 { - return uint16(len(t.pad) + 6) + return 8 } func (t *TLVTableMap) MarshalBinary() (data []byte, err error) { @@ -156,7 +155,6 @@ func (t *TLVTableMap) UnmarshalBinary(data []byte) error { type TLVTableMod struct { Command uint16 - pad [6]byte TlvMaps []*TLVTableMap } @@ -173,6 +171,7 @@ func (t *TLVTableMod) MarshalBinary() (data []byte, err error) { n := 0 binary.BigEndian.PutUint16(data[n:], t.Command) n += 2 + // 6 bytes for padding n += 6 for _, tlvMap := range t.TlvMaps { tlvData, err := tlvMap.MarshalBinary() @@ -296,7 +295,6 @@ const ( type ContinuationPropBridge struct { *PropHeader /* Type: NXCPT_BRIDGE */ Bridge [4]uint32 - pad [4]uint8 } func (p *ContinuationPropBridge) Len() (n uint16) { @@ -345,7 +343,6 @@ func (p *ContinuationPropBridge) UnmarshalBinary(data []byte) error { type ContinuationPropStack struct { *PropHeader /* Type: NXCPT_STACK */ Stack []uint8 - pad []uint8 } func (p *ContinuationPropStack) Len() (n uint16) { @@ -434,7 +431,6 @@ func (p *ContinuationPropMirrors) UnmarshalBinary(data []byte) error { type ContinuationPropConntracked struct { *PropHeader /* Type: NXCPT_CONNTRACKED */ - pad [4]uint8 } func (p *ContinuationPropConntracked) Len() (n uint16) { @@ -473,7 +469,6 @@ func (p *ContinuationPropConntracked) UnmarshalBinary(data []byte) error { type ContinuationPropTableID struct { *PropHeader /* Type: NXCPT_TABLE_ID */ TableID uint8 - pad [3]uint8 } func (p *ContinuationPropTableID) Len() (n uint16) { @@ -515,7 +510,6 @@ func (p *ContinuationPropTableID) UnmarshalBinary(data []byte) error { type ContinuationPropCookie struct { *PropHeader /* Type: NXCPT_COOKIE */ - pad [4]uint8 Cookie uint64 } @@ -558,7 +552,6 @@ func (p *ContinuationPropCookie) UnmarshalBinary(data []byte) error { type ContinuationPropActions struct { *PropHeader /* Type: NXCPT_ACTIONS */ - pad [4]uint8 Actions []Action } @@ -622,7 +615,6 @@ func (p *ContinuationPropActions) UnmarshalBinary(data []byte) error { type ContinuationPropActionSet struct { *PropHeader /* Type: NXCPT_ACTION_SET */ - pad [4]uint8 ActionSet []Action } @@ -646,6 +638,7 @@ func (p *ContinuationPropActionSet) MarshalBinary() (data []byte, err error) { } copy(data[n:], b) n += int(p.PropHeader.Len()) + // 4 bytes for padding n += 4 for _, action := range p.ActionSet { @@ -779,7 +772,6 @@ const ( type PacketIn2PropPacket struct { *PropHeader Packet protocol.Ethernet - pad []uint8 } func (p *PacketIn2PropPacket) Len() (n uint16) { @@ -916,7 +908,6 @@ func (p *PacketIn2PropBufferID) UnmarshalBinary(data []byte) error { type PacketIn2PropTableID struct { *PropHeader /* Type: NXPINT_TABLE_ID */ TableID uint8 - pad [3]uint8 } func (p *PacketIn2PropTableID) Len() (n uint16) { @@ -958,7 +949,6 @@ func (p *PacketIn2PropTableID) UnmarshalBinary(data []byte) error { type PacketIn2PropCookie struct { *PropHeader /* Type: NXPINT_COOKIE */ - pad [4]uint8 Cookie uint64 } @@ -978,6 +968,7 @@ func (p *PacketIn2PropCookie) MarshalBinary() (data []byte, err error) { } copy(data[n:], b) n += int(p.PropHeader.Len()) + // 4 bytes for padding n += 4 binary.BigEndian.PutUint64(data[n:], p.Cookie) @@ -1004,7 +995,6 @@ func (p *PacketIn2PropCookie) UnmarshalBinary(data []byte) error { type PacketIn2PropReason struct { *PropHeader /* Type: NXPINT_COOKIE */ Reason uint8 - pad [3]uint8 } func (p *PacketIn2PropReason) Len() (n uint16) { @@ -1016,6 +1006,7 @@ func (p *PacketIn2PropReason) MarshalBinary() (data []byte, err error) { var b []byte n := 0 + // 1 byte for padding p.Length = p.PropHeader.Len() + 1 b, err = p.PropHeader.MarshalBinary() if err != nil { @@ -1047,7 +1038,6 @@ func (p *PacketIn2PropReason) UnmarshalBinary(data []byte) error { type PacketIn2PropMetadata struct { *PropHeader /* Type: NXPINT_METADATA */ Fields []MatchField - pad []uint8 } func (p *PacketIn2PropMetadata) Len() (n uint16) { @@ -1113,7 +1103,6 @@ func (p *PacketIn2PropMetadata) UnmarshalBinary(data []byte) error { type PacketIn2PropUserdata struct { *PropHeader /* Type: NXPINT_USERDATA */ Userdata []uint8 - pad []uint8 } func (p *PacketIn2PropUserdata) Len() (n uint16) { @@ -1158,7 +1147,6 @@ func (p *PacketIn2PropUserdata) UnmarshalBinary(data []byte) error { type PacketIn2PropContinuation struct { *PropHeader /* Type: NXPINT_CONTINUATION */ Continuation []byte - pad []uint8 } func (p *PacketIn2PropContinuation) Len() (n uint16) { diff --git a/openflow15/openflow15.go b/openflow15/openflow15.go index a75d544..6395486 100644 --- a/openflow15/openflow15.go +++ b/openflow15/openflow15.go @@ -827,7 +827,7 @@ const ( ACFC_EPERM ) -// ofp_flow_monitor_failed_code +// ofp_flow_monitor_failed_code const ( MOFC_UNKNOWN = iota MOFC_MONITOR_EXISTS @@ -1030,7 +1030,6 @@ type RoleRequest struct { common.Header Role uint32 Shortid uint16 - pad uint16 GenerationId uint64 } type RoleReply = RoleRequest diff --git a/openflow15/port.go b/openflow15/port.go index 20ca0ae..ebb7b94 100644 --- a/openflow15/port.go +++ b/openflow15/port.go @@ -17,7 +17,6 @@ type Port struct { Length uint16 Pad []byte // 2 bytes HWAddr net.HardwareAddr - pad2 []byte // 2 bytes for 64bit alignment Name []byte // Size 16 Config uint32 diff --git a/protocol/dhcp.go b/protocol/dhcp.go index 2300cfa..e79c7c1 100644 --- a/protocol/dhcp.go +++ b/protocol/dhcp.go @@ -77,7 +77,7 @@ const ( const ( DHCP_FLAG_BROADCAST uint16 = 0x80 -// FLAG_BROADCAST_MASK uint16 = (1 << FLAG_BROADCAST) +// FLAG_BROADCAST_MASK uint16 = (1 << FLAG_BROADCAST) ) func getRandomXID() (uint32, error) { diff --git a/protocol/icmpv6.go b/protocol/icmpv6.go index 88b4da7..c87b42e 100644 --- a/protocol/icmpv6.go +++ b/protocol/icmpv6.go @@ -41,14 +41,15 @@ const ( ICMPv6_ErrCode_Unknown_Option = 2 ) -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type | Code | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// + Message Body + -// | | +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type | Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// + Message Body + +// | | type ICMPv6Header struct { Type uint8 Code uint8 @@ -161,21 +162,22 @@ func NewICMPv6EchoReply(identifier, sequenceNumber uint16) *ICMPv6EchoReqRpl { type ICMPv6Error ICMPv6Header -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type | Code | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Maximum Response Delay | Reserved | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// + + -// | | -// + Multicast Address + -// | | -// + + -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type | Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Maximum Response Delay | Reserved | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// + + +// | | +// + Multicast Address + +// | | +// + + +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type MLD struct { ICMPv6Header MaxResponse uint16 @@ -242,50 +244,51 @@ func NewMLDDone(multicastIP net.IP) *MLD { } } -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type = 130 | Code | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Maximum Response Code | Reserved | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// * * -// | | -// * Multicast Address * -// | | -// * * -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Resv |S| QRV | QQIC | Number of Sources (N) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// * * -// | | -// * Source Address [1] * -// | | -// * * -// | | -// +- -+ -// | | -// * * -// | | -// * Source Address [2] * -// | | -// * * -// | | -// +- . -+ -// . . . -// . . . -// +- -+ -// | | -// * * -// | | -// * Source Address [N] * -// | | -// * * -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type = 130 | Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Maximum Response Code | Reserved | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// * * +// | | +// * Multicast Address * +// | | +// * * +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Resv |S| QRV | QQIC | Number of Sources (N) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// * * +// | | +// * Source Address [1] * +// | | +// * * +// | | +// +- -+ +// | | +// * * +// | | +// * Source Address [2] * +// | | +// * * +// | | +// +- . -+ +// . . . +// . . . +// +- -+ +// | | +// * * +// | | +// * Source Address [N] * +// | | +// * * +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type MLDQuery struct { ICMPv6Header MaxResponse uint16 @@ -404,35 +407,36 @@ func NewMLDv2Query(maxResponse uint16, multicastIP net.IP, queryInterval uint8, } } -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type = 143 | Reserved | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Reserved |Nr of Mcast Address Records (M)| -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Multicast Address Record [1] . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Multicast Address Record [2] . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | . | -// . . . -// | . | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Multicast Address Record [M] . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type = 143 | Reserved | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Reserved |Nr of Mcast Address Records (M)| +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Multicast Address Record [1] . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Multicast Address Record [2] . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | . | +// . . . +// | . | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Multicast Address Record [M] . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type MLDv2Report struct { ICMPv6Header Reserved2 uint16 @@ -507,51 +511,52 @@ func NewMLDv2Report(records []MLDv2Record) *MLDv2Report { } } -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Record Type | Aux Data Len | Number of Sources (N) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// * * -// | | -// * Multicast Address * -// | | -// * * -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// * * -// | | -// * Source Address [1] * -// | | -// * * -// | | -// +- -+ -// | | -// * * -// | | -// * Source Address [2] * -// | | -// * * -// | | -// +- -+ -// . . . -// . . . -// . . . -// +- -+ -// | | -// * * -// | | -// * Source Address [N] * -// | | -// * * -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Auxiliary Data . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// | Record Type | Aux Data Len | Number of Sources (N) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// * * +// | | +// * Multicast Address * +// | | +// * * +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// * * +// | | +// * Source Address [1] * +// | | +// * * +// | | +// +- -+ +// | | +// * * +// | | +// * Source Address [2] * +// | | +// * * +// | | +// +- -+ +// . . . +// . . . +// . . . +// +- -+ +// | | +// * * +// | | +// * Source Address [N] * +// | | +// * * +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Auxiliary Data . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type MLDv2Record struct { Type uint8 AuxDataLen uint8 // this may be 0 to indicate the absence of any auxiliary data. diff --git a/protocol/igmp.go b/protocol/igmp.go index 5d41e1c..6209bfa 100644 --- a/protocol/igmp.go +++ b/protocol/igmp.go @@ -27,22 +27,24 @@ type IGMPMessage interface { } // IGMPv1: -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// |Version| Type | Unused | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Group Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// |Version| Type | Unused | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Group Address | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // // IGMPv2: -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type | Max Resp Time | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Group Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type | Max Resp Time | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Group Address | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type IGMPv1or2 struct { Type uint8 MaxResponseTime uint8 // It is 0 for IGMPv1 message. @@ -113,24 +115,25 @@ func NewIGMPv2Leave(group net.IP) *IGMPv1or2 { } // IGMPv3Query: -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type = 0x11 | Max Resp Code | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Group Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Resv |S| QRV | QQIC | Number of Sources (N) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Source Address [1] | -// +- -+ -// | Source Address [2] | -// +- . -+ -// . . . -// . . . -// +- -+ -// | Source Address [N] | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type = 0x11 | Max Resp Code | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Group Address | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Resv |S| QRV | QQIC | Number of Sources (N) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Source Address [1] | +// +- -+ +// | Source Address [2] | +// +- . -+ +// . . . +// . . . +// +- -+ +// | Source Address [N] | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type IGMPv3Query struct { Type uint8 MaxResponseTime uint8 @@ -222,29 +225,30 @@ func NewIGMPv3Query(group net.IP, maxResponseTime uint8, queryInterval uint8, so } // IGMPv3GroupRecord: -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Record Type | Aux Data Len | Number of Sources (N) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Multicast Address | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Source Address [1] | -// +- -+ -// | Source Address [2] | -// +- -+ -// . . . -// . . . -// . . . -// +- -+ -// | Source Address [N] | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Auxiliary Data . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Record Type | Aux Data Len | Number of Sources (N) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Multicast Address | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Source Address [1] | +// +- -+ +// | Source Address [2] | +// +- -+ +// . . . +// . . . +// . . . +// +- -+ +// | Source Address [N] | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Auxiliary Data . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type IGMPv3GroupRecord struct { Type uint8 AuxDataLen uint8 // this should always be 0 as per IGMPv3 spec. @@ -317,35 +321,36 @@ func NewGroupRecord(recordType uint8, group net.IP, sources []net.IP) IGMPv3Grou } // IGMPv3MembershipReport: -// 0 1 2 3 -// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Type = 0x22 | Reserved | Checksum | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | Reserved | Number of Group Records (M) | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Group Record [1] . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Group Record [2] . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | . | -// . . . -// | . | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -// | | -// . . -// . Group Record [M] . -// . . -// | | -// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// +// 0 1 2 3 +// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Type = 0x22 | Reserved | Checksum | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | Reserved | Number of Group Records (M) | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Group Record [1] . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Group Record [2] . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | . | +// . . . +// | . | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +// | | +// . . +// . Group Record [M] . +// . . +// | | +// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ type IGMPv3MembershipReport struct { Type uint8 Reserved uint8