summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-09-05 10:35:20 -0700
committerBen Pfaff <blp@nicira.com>2012-09-05 10:35:20 -0700
commit341c4e59f50a842a2974d06e448a57af372a7edd (patch)
tree35f92730f035ab655e76334bdb19f771c042d10a /ovsdb
parentc22c56bd746352f5c70a0d99bb3f548d03cfd105 (diff)
downloadopenvswitch-341c4e59f50a842a2974d06e448a57af372a7edd.tar.gz
ovsdb: Enforce immutability of immutable columns.
OVSDB has always had the ability to mark a column as "immutable", so that its value cannot be changed in a given row after that row is initially inserted. However, we discovered recently that ovsdb-server has never enforced this constraint. This commit implements enforcement. Reported-by: Paul Ingram <paul@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Kyle Mestery <kmestery@cisco.com>
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/execution.c18
-rw-r--r--ovsdb/mutation.c8
-rwxr-xr-xovsdb/ovsdb-idlc.in5
3 files changed, 29 insertions, 2 deletions
diff --git a/ovsdb/execution.c b/ovsdb/execution.c
index 1aff0c51e..300c247a3 100644
--- a/ovsdb/execution.c
+++ b/ovsdb/execution.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -435,6 +435,22 @@ ovsdb_execute_update(struct ovsdb_execution *x, struct ovsdb_parser *parser,
error = parse_row(row_json, table, x->symtab, &row, &columns);
}
if (!error) {
+ size_t i;
+
+ for (i = 0; i < columns.n_columns; i++) {
+ const struct ovsdb_column *column = columns.columns[i];
+
+ if (!column->mutable) {
+ error = ovsdb_syntax_error(parser->json,
+ "constraint violation",
+ "Cannot update immutable column %s "
+ "in table %s.",
+ column->name, table->schema->name);
+ break;
+ }
+ }
+ }
+ if (!error) {
error = ovsdb_condition_from_json(table->schema, where, x->symtab,
&condition);
}
diff --git a/ovsdb/mutation.c b/ovsdb/mutation.c
index 0dcd16fec..5fd983a4b 100644
--- a/ovsdb/mutation.c
+++ b/ovsdb/mutation.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,6 +95,12 @@ ovsdb_mutation_from_json(const struct ovsdb_table_schema *ts,
"No column %s in table %s.",
column_name, ts->name);
}
+ if (!m->column->mutable) {
+ return ovsdb_syntax_error(json, "constraint violation",
+ "Cannot mutate immutable column %s in "
+ "table %s.", column_name, ts->name);
+ }
+
ovsdb_type_clone(&m->type, &m->column->type);
mutator_name = json_string(array->elems[1]);
diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index 0b1933b35..478109af6 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -577,11 +577,16 @@ static void\n%s_columns_init(void)
for columnName, column in sorted(table.columns.iteritems()):
cs = "%s_col_%s" % (structName, columnName)
d = {'cs': cs, 'c': columnName, 's': structName}
+ if column.mutable:
+ mutable = "true"
+ else:
+ mutable = "false"
print
print " /* Initialize %(cs)s. */" % d
print " c = &%(cs)s;" % d
print " c->name = \"%(c)s\";" % d
print column.type.cInitType(" ", "c->type")
+ print " c->mutable = %s;" % mutable
print " c->parse = %(s)s_parse_%(c)s;" % d
print " c->unparse = %(s)s_unparse_%(c)s;" % d
print "}"