Skip to content

Commit

Permalink
Fix agent crash at FlowStatsCollector::FlowExport
Browse files Browse the repository at this point in the history
We were accessing invalid index from map. Provided accessor function
to retrive entries from map. The accessor function validates the index.
Closes-Bug: #1523059

Change-Id: Idd6a85b967aaab766ba54e84d13d6738613d7d58
  • Loading branch information
ashoksr committed Dec 5, 2015
1 parent c48b582 commit f30bb93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/vnsw/agent/pkt/flow_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const std::map<uint16_t, const char*>
"SHORT_LINKLOCAL_SRC_NAT")
((uint16_t)SHORT_FAILED_VROUTER_INSTALL,
"SHORT_FAILED_VROUTER_INST")
((uint16_t)SHORT_INVALID_L2_FLOW, "SHORT_INVALID_L2_FLOW")
((uint16_t)DROP_POLICY, "DROP_POLICY")
((uint16_t)DROP_OUT_POLICY, "DROP_OUT_POLICY")
((uint16_t)DROP_SG, "DROP_SG")
Expand Down Expand Up @@ -153,6 +154,16 @@ FlowEntry::~FlowEntry() {
alloc_count_.fetch_and_decrement();
}

std::string FlowEntry::DropReasonStr(uint16_t reason) {
std::map<uint16_t, const char*>::const_iterator it =
FlowDropReasonStr.find(reason);
if (it != FlowDropReasonStr.end()) {
return string(it->second);
}
return "UNKNOWN";
}


void FlowEntry::GetSourceRouteInfo(const AgentRoute *rt) {
const AgentPath *path = NULL;
if (rt) {
Expand Down
5 changes: 5 additions & 0 deletions src/vnsw/agent/pkt/flow_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ struct FlowData {

class FlowEntry {
public:
/* Please update FlowEntry::FlowDropReasonStr whenever entries are added
* to the below enum */
enum FlowShortReason {
SHORT_UNKNOWN = 0,
SHORT_UNAVIALABLE_INTERFACE,
Expand All @@ -285,6 +287,8 @@ class FlowEntry {
SHORT_MAX
};

/* Please update FlowEntry::FlowDropReasonStr whenever entries are added
* to the below enum */
enum FlowDropReason {
DROP_UNKNOWN = 0,
DROP_POLICY = SHORT_MAX,
Expand Down Expand Up @@ -336,6 +340,7 @@ class FlowEntry {
FlowEntry(const FlowKey &k);
virtual ~FlowEntry();

static std::string DropReasonStr(uint16_t reason);
bool ActionRecompute();
void UpdateKSync(FlowTable* table, bool update);
int GetRefCount() { return refcount_; }
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/vrouter/flow_stats/flow_stats_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void FlowStatsCollector::FlowExport(FlowEntry *flow, uint64_t diff_bytes,
s_flow.set_sg_rule_uuid(flow->sg_rule_uuid());
s_flow.set_nw_ace_uuid(flow->nw_ace_uuid());
s_flow.set_drop_reason
(FlowEntry::FlowDropReasonStr.at(flow->data().drop_reason));
(FlowEntry::DropReasonStr(flow->data().drop_reason));
if (flow->intf_entry() != NULL) {
s_flow.set_vmi_uuid(UuidToString(flow->intf_entry()->GetUuid()));
}
Expand Down

0 comments on commit f30bb93

Please sign in to comment.