Skip to content

Commit

Permalink
Add check for bad table_id.
Browse files Browse the repository at this point in the history
Changed some error messages to a more suited type.
  • Loading branch information
ederlf committed Jun 4, 2013
1 parent bceb230 commit 420b87a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/openflow/openflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#define OFP_TCP_PORT 6633
#define OFP_SSL_PORT 6633
#define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
/* Number of tables in the pipeline */
#define PIPELINE_TABLES 64

/* Header on all OpenFlow packets. */
struct ofp_header {
Expand Down
2 changes: 1 addition & 1 deletion oflib/ofl-actions-unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ ofl_actions_unpack(struct ofp_action_header *src, size_t *len, struct ofl_action
OFL_LOG_WARN(LOG_MODULE, "Received GROUP action has invalid group id (%s).", gs);
free(gs);
}
return ofl_error(OFPET_BAD_ACTION, OFPBAC_BAD_ARGUMENT);
return ofl_error(OFPET_BAD_ACTION, OFPBAC_BAD_OUT_GROUP);
}

da = (struct ofl_action_group *)malloc(sizeof(struct ofl_action_group));
Expand Down
29 changes: 22 additions & 7 deletions oflib/ofl-messages-unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,16 @@ ofl_msg_unpack_packet_in(struct ofp_header *src, uint8_t* buf, size_t *len, stru
OFL_LOG_WARN(LOG_MODULE, "Received PACKET_IN message has invalid in_port (%s).", ps);
free(ps);
}
return ofl_error(OFPET_BAD_REQUEST, OFPBAC_BAD_ARGUMENT);
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_PORT);
}*/

if (sp->table_id == 0xff) {
if (sp->table_id == PIPELINE_TABLES) {
if (OFL_LOG_IS_WARN_ENABLED(LOG_MODULE)) {
char *ts = ofl_table_to_string(sp->table_id);
OFL_LOG_WARN(LOG_MODULE, "Received PACKET_IN has invalid table_id (%s).", ts);
free(ts);
}
return ofl_error(OFPET_BAD_REQUEST, OFPBAC_BAD_ARGUMENT);
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_TABLE_ID);
}
*len -= sizeof(struct ofp_packet_in) - sizeof(struct ofp_match);
dp = (struct ofl_msg_packet_in *)malloc(sizeof(struct ofl_msg_packet_in));
Expand Down Expand Up @@ -279,13 +279,13 @@ ofl_msg_unpack_flow_removed(struct ofp_header *src,uint8_t *buf, size_t *len, st

sr = (struct ofp_flow_removed *)src ;

if (sr->table_id == 0xff) {
if (sr->table_id == PIPELINE_TABLES) {
if (OFL_LOG_IS_WARN_ENABLED(LOG_MODULE)) {
char *ts = ofl_table_to_string(sr->table_id);
OFL_LOG_WARN(LOG_MODULE, "Received FLOW_REMOVED message has invalid table_id (%s).", ts);
free(ts);
}
return ofl_error(OFPET_BAD_REQUEST, OFPBAC_BAD_ARGUMENT);
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_TABLE_ID);
}
*len -= sizeof(struct ofp_flow_removed) - sizeof(struct ofp_match) ;

Expand Down Expand Up @@ -367,7 +367,7 @@ ofl_msg_unpack_packet_out(struct ofp_header *src, size_t *len, struct ofl_msg_he
OFL_LOG_WARN(LOG_MODULE, "Received PACKET_OUT message with invalid in_port (%s).", ps);
free(ps);
}
return ofl_error(OFPET_BAD_REQUEST, OFPBAC_BAD_ARGUMENT);
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_PORT);
}*/

if (ntohl(sp->buffer_id) != 0xffffffff &&
Expand Down Expand Up @@ -435,11 +435,17 @@ ofl_msg_unpack_flow_mod(struct ofp_header *src,uint8_t* buf, size_t *len, struct
OFL_LOG_WARN(LOG_MODULE, "Received FLOW_MOD message has invalid length (%zu).", *len);
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
}

*len -= (sizeof(struct ofp_flow_mod) - sizeof(struct ofp_match));

sm = (struct ofp_flow_mod *)src;
dm = (struct ofl_msg_flow_mod *)malloc(sizeof(struct ofl_msg_flow_mod));

if (sm->table_id >= PIPELINE_TABLES) {
OFL_LOG_WARN(LOG_MODULE, "Received FLOW_MOD message has invalid table id (%zu).", sm->table_id );
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_TABLE_ID);
}

dm->cookie = ntoh64(sm->cookie);
dm->cookie_mask = ntoh64(sm->cookie_mask);
dm->table_id = sm->table_id;
Expand Down Expand Up @@ -640,7 +646,7 @@ ofl_msg_unpack_port_mod(struct ofp_header *src, size_t *len, struct ofl_msg_head
OFL_LOG_WARN(LOG_MODULE, "Received PORT_MOD message has invalid in_port (%s).", ps);
free(ps);
}
return ofl_error(OFPET_BAD_REQUEST, OFPBAC_BAD_ARGUMENT);
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_PORT);
}*/
*len -= sizeof(struct ofp_port_mod);

Expand Down Expand Up @@ -669,6 +675,10 @@ ofl_msg_unpack_table_mod(struct ofp_header *src, size_t *len, struct ofl_msg_hea

sm = (struct ofp_table_mod *)src;
dm = (struct ofl_msg_table_mod *)malloc(sizeof(struct ofl_msg_table_mod));
if (sm->table_id >= PIPELINE_TABLES) {
OFL_LOG_WARN(LOG_MODULE, "Received FLOW_MOD message has invalid table id (%zu).", sm->table_id );
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_TABLE_ID);
}

dm->table_id = sm->table_id;
dm->config = ntohl(sm->config);
Expand All @@ -695,6 +705,11 @@ ofl_msg_unpack_multipart_request_flow(struct ofp_multipart_request *os, uint8_t*
sm = (struct ofp_flow_stats_request *)os->body;
dm = (struct ofl_msg_multipart_request_flow *) malloc(sizeof(struct ofl_msg_multipart_request_flow));

if (sm->table_id >= PIPELINE_TABLES) {
OFL_LOG_WARN(LOG_MODULE, "Received FLOW_MOD message has invalid table id (%zu).", sm->table_id );
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_TABLE_ID);
}

dm->table_id = sm->table_id;
dm->out_port = ntohl(sm->out_port);
dm->out_group = ntohl(sm->out_group);
Expand Down
2 changes: 1 addition & 1 deletion oflib/ofl-structs-unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ ofl_structs_flow_stats_unpack(struct ofp_flow_stats *src, uint8_t *buf, size_t *
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_BAD_LEN);
}

if (src->table_id == 0xff) {
if (src->table_id >= PIPELINE_TABLES) {
if (OFL_LOG_IS_WARN_ENABLED(LOG_MODULE)) {
char *ts = ofl_table_to_string(src->table_id);
OFL_LOG_WARN(LOG_MODULE, "Received flow stats has invalid table_id (%s).", ts);
Expand Down
2 changes: 0 additions & 2 deletions udatapath/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
#include "oflib/ofl.h"
#include "oflib/ofl-messages.h"

/* Number of tables in the pipeline */
#define PIPELINE_TABLES 64

struct sender;

Expand Down

0 comments on commit 420b87a

Please sign in to comment.