Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions openflow15/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ func (a *ActionPush) MarshalBinary() (data []byte, err error) {
}

func (a *ActionPush) UnmarshalBinary(data []byte) error {
a.ActionHeader.UnmarshalBinary(data[:4])
err := a.ActionHeader.UnmarshalBinary(data[:4])
if err != nil {
return err
}
a.EtherType = binary.BigEndian.Uint16(data[4:])
return nil
}
Expand Down Expand Up @@ -414,8 +417,7 @@ func (a *ActionPopVlan) MarshalBinary() (data []byte, err error) {
}

func (a *ActionPopVlan) UnmarshalBinary(data []byte) error {
a.ActionHeader.UnmarshalBinary(data[:4])
return nil
return a.ActionHeader.UnmarshalBinary(data[:4])
}

type ActionPopMpls struct {
Expand Down Expand Up @@ -452,7 +454,10 @@ func (a *ActionPopMpls) MarshalBinary() (data []byte, err error) {
}

func (a *ActionPopMpls) UnmarshalBinary(data []byte) error {
a.ActionHeader.UnmarshalBinary(data[:4])
err := a.ActionHeader.UnmarshalBinary(data[:4])
if err != nil {
return err
}
a.EtherType = binary.BigEndian.Uint16(data[4:])
return nil
}
Expand Down
10 changes: 8 additions & 2 deletions openflow15/flowmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ func (f *FlowMod) MarshalBinary() (data []byte, err error) {

func (f *FlowMod) UnmarshalBinary(data []byte) error {
n := 0
f.Header.UnmarshalBinary(data[n:])
err := f.Header.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(f.Header.Len())

f.Cookie = binary.BigEndian.Uint64(data[n:])
Expand Down Expand Up @@ -158,7 +161,10 @@ func (f *FlowMod) UnmarshalBinary(data []byte) error {
f.Importance = binary.BigEndian.Uint16(data[n:])
n += 2

f.Match.UnmarshalBinary(data[n:])
err = f.Match.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(f.Match.Len())

for n < int(f.Header.Length) {
Expand Down
26 changes: 22 additions & 4 deletions openflow15/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"errors"

"antrea.io/libOpenflow/util"

log "github.com/sirupsen/logrus"
)

// ofp_instruction_type 1.5
Expand Down Expand Up @@ -70,6 +72,9 @@ func DecodeInstr(data []byte) Instruction {
case InstrType_DEPRECATED:
case InstrType_STAT_TRIGGER:
case InstrType_EXPERIMENTER:
default:
log.Warningf("Unknown Instrheader type: %v", t)
return nil
}

a.UnmarshalBinary(data)
Expand Down Expand Up @@ -98,7 +103,10 @@ func (instr *InstrGotoTable) MarshalBinary() (data []byte, err error) {
}

func (instr *InstrGotoTable) UnmarshalBinary(data []byte) error {
instr.InstrHeader.UnmarshalBinary(data[:4])
err := instr.InstrHeader.UnmarshalBinary(data[:4])
if err != nil {
return err
}

instr.TableId = data[4]
copy(instr.pad, data[5:8])
Expand Down Expand Up @@ -145,7 +153,10 @@ func (instr *InstrWriteMetadata) MarshalBinary() (data []byte, err error) {
}

func (instr *InstrWriteMetadata) UnmarshalBinary(data []byte) error {
instr.InstrHeader.UnmarshalBinary(data[:4])
err := instr.InstrHeader.UnmarshalBinary(data[:4])
if err != nil {
return err
}

copy(instr.pad, data[4:8])
instr.Metadata = binary.BigEndian.Uint64(data[8:16])
Expand Down Expand Up @@ -202,7 +213,10 @@ func (instr *InstrActions) MarshalBinary() (data []byte, err error) {
}

func (instr *InstrActions) UnmarshalBinary(data []byte) error {
instr.InstrHeader.UnmarshalBinary(data[:4])
err := instr.InstrHeader.UnmarshalBinary(data[:4])
if err != nil {
return err
}

n := 8
for n < int(instr.Length) {
Expand Down Expand Up @@ -294,7 +308,11 @@ func (instr *InstrStatTrigger) MarshalBinary() (data []byte, err error) {
}

func (instr *InstrStatTrigger) UnmarshalBinary(data []byte) error {
instr.InstrHeader.UnmarshalBinary(data[:4])
var err error
err = instr.InstrHeader.UnmarshalBinary(data[:4])
if err != nil {
return err
}
instr.Flags = binary.BigEndian.Uint32(data[4:8])
instr.Thresholds.UnmarshalBinary(data[8:])

Expand Down
6 changes: 5 additions & 1 deletion openflow15/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"encoding/binary"
"errors"
"fmt"
"log"
"net"

log "github.com/sirupsen/logrus"

"antrea.io/libOpenflow/util"
)

Expand Down Expand Up @@ -607,6 +608,9 @@ func DecodeMatchField(class uint16, field uint8, length uint8, hasMask bool, dat
val = new(TcpFlagsField)
case OXM_FIELD_ACTSET_OUTPUT:
val = new(ActsetOutputField)
default:
log.Errorf("Unhandled Field: %d in Packet Register Class: %d", field, class)
return nil, fmt.Errorf("Bad pkt class: %v field: %v", class, field)
}
err := val.UnmarshalBinary(data)
if err != nil {
Expand Down
19 changes: 16 additions & 3 deletions openflow15/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package openflow15

import (
"encoding/binary"
"fmt"

log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -124,7 +125,10 @@ func (m *MeterBandDrop) MarshalBinary() (data []byte, err error) {

func (m *MeterBandDrop) UnmarshalBinary(data []byte) error {
n := 0
m.MeterBandHeader.UnmarshalBinary(data[n:])
err := m.MeterBandHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(m.MeterBandHeader.Len())

return nil
Expand Down Expand Up @@ -279,7 +283,10 @@ func (m *MeterMod) MarshalBinary() (data []byte, err error) {

func (m *MeterMod) UnmarshalBinary(data []byte) error {
n := 0
m.Header.UnmarshalBinary(data[n:])
err := m.Header.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(m.Header.Len())

m.Command = binary.BigEndian.Uint16(data[n:])
Expand All @@ -291,7 +298,10 @@ func (m *MeterMod) UnmarshalBinary(data []byte) error {

for n < int(m.Header.Length) {
mbh := new(MeterBandHeader)
mbh.UnmarshalBinary(data[n:])
err = mbh.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(mbh.Len())
switch mbh.Type {
case MBT_DROP:
Expand All @@ -308,6 +318,9 @@ func (m *MeterMod) UnmarshalBinary(data []byte) error {
mbExp.MeterBandHeader = *mbh
mbExp.Experimenter = binary.BigEndian.Uint32(data[n:])
m.MeterBands = append(m.MeterBands, mbExp)
default:
log.Warningf("Unknown MeterBandHeader type : %v", mbh.Type)
return fmt.Errorf("Unknown MeterBandHeader type : %v", mbh.Type)
}
n += 4
}
Expand Down
17 changes: 16 additions & 1 deletion openflow15/multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func (s *MultipartRequest) UnmarshalBinary(data []byte) error {
// The request body is ofp_bundle_features_request.
req = new(BundleFeaturesRequest)
case MultipartType_Experimenter:
default:
err = fmt.Errorf("Received unknown multipart type: %v", s.Type);
return err
}

if req != nil {
Expand Down Expand Up @@ -279,6 +282,9 @@ func (s *MultipartReply) UnmarshalBinary(data []byte) error {
repl = NewBundleFeatures()
case MultipartType_Experimenter:
break
default:
err = fmt.Errorf("Received unknown multipart type: %v", s.Type);
return err
}

err = repl.UnmarshalBinary(data[n:])
Expand Down Expand Up @@ -568,6 +574,9 @@ func (s *FlowStatsRequest) UnmarshalBinary(data []byte) error {
n += 8

err := s.Match.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(s.Match.Len())

return err
Expand Down Expand Up @@ -728,7 +737,10 @@ func (s *AggregateStatsRequest) UnmarshalBinary(data []byte) error {
s.CookieMask = binary.BigEndian.Uint64(data[n:])
n += 8

s.Match.UnmarshalBinary(data[n:])
err := s.Match.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(s.Match.Len())
return nil
}
Expand Down Expand Up @@ -2025,6 +2037,8 @@ func (f *TableFeatures) UnmarshalBinary(data []byte) error {
fallthrough
case TFPT_EXPERIMENTER_MISS:
p = new(TableExperimenterProperty)
default:
return fmt.Errorf("Unknown TFPT %v", t)
}
err := p.UnmarshalBinary(data[n:])
if err != nil {
Expand Down Expand Up @@ -2759,6 +2773,7 @@ func (m *MeterDesc) UnmarshalBinary(data []byte) (err error) {
case MBT_EXPERIMENTER:
p = new(MeterBandExperimenter)
default:
return fmt.Errorf("unknown MBT: %v", binary.BigEndian.Uint16(data[n:]))
}
err = p.UnmarshalBinary(data[n:])
if err != nil {
Expand Down
29 changes: 29 additions & 0 deletions openflow15/nx_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package openflow15
import (
"encoding/binary"
"errors"
"fmt"
"net"

log "github.com/sirupsen/logrus"
)

// NX Action constants
Expand Down Expand Up @@ -176,6 +179,8 @@ func DecodeNxAction(data []byte) Action {
case NXAST_RAW_ENCAP:
case NXAST_RAW_DECAP:
case NXAST_DEC_NSH_TTL:
default:
log.Warningf("unknown NXActionHeader subtype: %v", data)
}
return a
}
Expand Down Expand Up @@ -225,6 +230,9 @@ func (a *NXActionConjunction) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionConjunction message")
Expand Down Expand Up @@ -290,6 +298,9 @@ func (a *NXActionConnTrack) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionConnTrack message")
Expand Down Expand Up @@ -544,6 +555,9 @@ func (a *NXActionResubmit) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionConjunction message")
Expand Down Expand Up @@ -619,6 +633,9 @@ func (a *NXActionResubmitTable) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionResubmitTable message")
Expand Down Expand Up @@ -792,6 +809,9 @@ func (a *NXActionCTNAT) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionCTNAT message")
Expand Down Expand Up @@ -942,6 +962,9 @@ func (a *NXActionDecTTL) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionDecTTL message")
Expand Down Expand Up @@ -995,6 +1018,9 @@ func (a *NXActionDecTTLCntIDs) UnmarshalBinary(data []byte) error {
n := 0
a.NXActionHeader = new(NXActionHeader)
err := a.NXActionHeader.UnmarshalBinary(data[n:])
if err != nil {
return err
}
n += int(a.NXActionHeader.Len())
if len(data) < int(a.Len()) {
return errors.New("the []byte is too short to unmarshal a full NXActionDecTTLCntIDs message")
Expand Down Expand Up @@ -1807,6 +1833,9 @@ func DecodeController2Prop(data []byte) (Property, error) {
p = new(NXActionController2PropPause)
case NXAC2PT_METER_ID:
p = new(NXActionController2PropMeterId)
default:
err := fmt.Errorf("Unknown DecodeController2Prop type %v", data)
return nil, err
}
err := p.UnmarshalBinary(data)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions openflow15/nxext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func TestNXActionLearn(t *testing.T) {
if err != nil {
t.Fatalf("Failed to UnMarshal message: %v", err)
}
if err = nsLearnEquals(oriAction, newAction); err != nil {
if err = nxLearnEquals(oriAction, newAction); err != nil {
t.Error(err)
}
}
Expand Down Expand Up @@ -676,7 +676,7 @@ func prepareLearnSpecs() []*NXLearnSpec {
}
}

func nsLearnEquals(oriAction, newAction *NXActionLearn) error {
func nxLearnEquals(oriAction, newAction *NXActionLearn) error {
if oriAction.IdleTimeout != newAction.IdleTimeout {
return errors.New("learn idleTimeout not equal")
}
Expand Down
Loading