NXBRC_NXM_BAD_PREREQ = 0x104,
/* A given nxm_type was specified more than once. */
- NXBRC_NXM_DUP_TYPE = 0x105
+ NXBRC_NXM_DUP_TYPE = 0x105,
+
+/* Other errors. */
+
+ /* A request specified a nonexistent table ID. (But NXFMFC_BAD_TABLE_ID is
+ * used instead, when it is appropriate, because that is such a special
+ * case.) */
+ NXBRC_BAD_TABLE_ID = 0x200,
};
/* Additional "code" values for OFPET_FLOW_MOD_FAILED. */
*nsec = (msecs % 1000) * (1000 * 1000);
}
+/* Checks whether 'table_id' is 0xff or a valid table ID in 'ofproto'. Returns
+ * 0 if 'table_id' is OK, otherwise an OpenFlow error code. */
+static int
+check_table_id(const struct ofproto *ofproto, uint8_t table_id)
+{
+ return (table_id == 0xff || table_id < ofproto->n_tables
+ ? 0
+ : ofp_mkerr_nicira(OFPET_BAD_REQUEST, NXBRC_BAD_TABLE_ID));
+
+}
+
static struct classifier *
first_matching_table(struct ofproto *ofproto, uint8_t table_id)
{
} else if (table_id < ofproto->n_tables) {
return &ofproto->tables[table_id];
} else {
- /* It would probably be better to reply with an error but there doesn't
- * seem to be any appropriate value, so that might just be
- * confusing. */
- VLOG_WARN_RL(&rl, "controller asked for invalid table %"PRIu8,
- table_id);
return NULL;
}
}
* - If TABLE_ID is the number of a table in OFPROTO, then the loop iterates
* only once, for that table.
*
- * - Otherwise, TABLE_ID isn't valid for OFPROTO, so ofproto logs a warning
- * and does not enter the loop at all.
+ * - Otherwise, TABLE_ID isn't valid for OFPROTO, so the loop won't be
+ * entered at all. (Perhaps you should have validated TABLE_ID with
+ * check_table_id().)
*
* All parameters are evaluated multiple times.
*/
struct list *rules)
{
struct classifier *cls;
+ int error;
+
+ error = check_table_id(ofproto, table_id);
+ if (error) {
+ return error;
+ }
list_init(rules);
FOR_EACH_MATCHING_TABLE (cls, table_id, ofproto) {
struct list *rules)
{
struct classifier *cls;
+ int error;
+
+ error = check_table_id(ofproto, table_id);
+ if (error) {
+ return error;
+ }
list_init(rules);
FOR_EACH_MATCHING_TABLE (cls, table_id, ofproto) {
struct rule *rule;
int error;
+ error = check_table_id(ofproto, fm->table_id);
+ if (error) {
+ return error;
+ }
+
/* Pick table. */
if (fm->table_id == 0xff) {
uint8_t table_id;