Skip to content

Commit 122e4ce

Browse files
authored
Merge pull request #623 from NetSys/fix_roundrobin_crash
Fix RoundRobin crash with zero output gate
2 parents ffb486f + f8c3a7c commit 122e4ce

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

core/modules/round_robin.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,24 @@ CommandResponse RoundRobin::CommandSetGates(
101101
void RoundRobin::ProcessBatch(bess::PacketBatch *batch) {
102102
gate_idx_t out_gates[bess::PacketBatch::kMaxBurst];
103103

104+
if (ngates_ <= 0) {
105+
bess::Packet::Free(batch);
106+
return;
107+
}
108+
104109
if (per_packet_) {
105110
for (int i = 0; i < batch->cnt(); i++) {
106111
out_gates[i] = gates_[current_gate_];
107-
current_gate_ = (current_gate_ + 1) % ngates_;
112+
if (++current_gate_ >= ngates_) {
113+
current_gate_ = 0;
114+
}
108115
}
109116
RunSplit(out_gates, batch);
110117
} else {
111118
gate_idx_t gate = gates_[current_gate_];
112-
current_gate_ = (current_gate_ + 1) % ngates_;
119+
if (++current_gate_ >= ngates_) {
120+
current_gate_ = 0;
121+
}
113122
RunChooseModule(gate, batch);
114123
}
115124
}

0 commit comments

Comments
 (0)