{
rculist_init(&rule->node);
*CONST_CAST(int *, &rule->priority) = priority;
- rule->cls_match = NULL;
+ ovsrcu_init(&rule->cls_match, NULL);
}
/* Initializes 'rule' to match packets specified by 'match' at the given
cls_rule_destroy(struct cls_rule *rule)
OVS_NO_THREAD_SAFETY_ANALYSIS
{
- ovs_assert(!rule->cls_match); /* Must not be in a classifier. */
+ /* Must not be in a classifier. */
+ ovs_assert(!get_cls_match_protected(rule));
/* Check that the rule has been properly removed from the classifier. */
ovs_assert(rule->node.prev == RCULIST_POISON
minimatch_destroy(CONST_CAST(struct minimatch *, &rule->match));
}
+/* This may only be called by the exclusive writer. */
void
cls_rule_set_conjunctions(struct cls_rule *cr,
const struct cls_conjunction *conj, size_t n)
{
- struct cls_match *match = cr->cls_match;
+ struct cls_match *match = get_cls_match_protected(cr);
struct cls_conjunction_set *old
= ovsrcu_get_protected(struct cls_conjunction_set *, &match->conj_set);
struct cls_conjunction *old_conj = old ? old->conj : NULL;
/* Makes 'rule' invisible in 'remove_version'. Once that version is used in
* lookups, the caller should remove 'rule' via ovsrcu_postpone().
*
- * 'rule' must be in a classifier. */
+ * 'rule' must be in a classifier.
+ * This may only be called by the exclusive writer. */
void
cls_rule_make_invisible_in_version(const struct cls_rule *rule,
cls_version_t remove_version)
{
- ovs_assert(remove_version >= rule->cls_match->add_version);
+ struct cls_match *cls_match = get_cls_match_protected(rule);
+
+ ovs_assert(remove_version >= cls_match->add_version);
- cls_match_set_remove_version(rule->cls_match, remove_version);
+ cls_match_set_remove_version(cls_match, remove_version);
}
/* This undoes the change made by cls_rule_make_invisible_in_version().
*
- * 'rule' must be in a classifier. */
+ * 'rule' must be in a classifier.
+ * This may only be called by the exclusive writer. */
void
cls_rule_restore_visibility(const struct cls_rule *rule)
{
- cls_match_set_remove_version(rule->cls_match, CLS_NOT_REMOVED_VERSION);
+ cls_match_set_remove_version(get_cls_match_protected(rule),
+ CLS_NOT_REMOVED_VERSION);
}
/* Return true if 'rule' is visible in 'version'.
bool
cls_rule_visible_in_version(const struct cls_rule *rule, cls_version_t version)
{
- return cls_match_visible_in_version(rule->cls_match, version);
+ struct cls_match *cls_match = get_cls_match(rule);
+
+ return cls_match && cls_match_visible_in_version(cls_match, version);
}
\f
/* Initializes 'cls' as a classifier that initially contains no classification
/* 'new' is initially invisible to lookups. */
new = cls_match_alloc(rule, version, conjs, n_conjs);
-
- CONST_CAST(struct cls_rule *, rule)->cls_match = new;
+ ovsrcu_set(&CONST_CAST(struct cls_rule *, rule)->cls_match, new);
subtable = find_subtable(cls, rule->match.mask);
if (!subtable) {
ovsrcu_postpone(free, conj_set);
}
+ ovsrcu_set(&old->cls_match, NULL); /* Marks old rule as removed
+ * from the classifier. */
ovsrcu_postpone(cls_match_free_cb, iter);
- old->cls_match = NULL;
/* No change in subtable's max priority or max count. */
size_t n_rules;
unsigned int i;
- rule = cls_rule->cls_match;
+ rule = get_cls_match_protected(cls_rule);
if (!rule) {
return NULL;
}
/* Mark as removed. */
- CONST_CAST(struct cls_rule *, cls_rule)->cls_match = NULL;
+ ovsrcu_set(&CONST_CAST(struct cls_rule *, cls_rule)->cls_match, NULL);
/* Remove 'cls_rule' from the subtable's rules list. */
rculist_remove(CONST_CAST(struct rculist *, &cls_rule->node));
if (rule->priority == target->priority
&& miniflow_equal_in_minimask(target->match.flow,
rule->match.flow, &m.mask)
- && cls_match_visible_in_version(rule->cls_match, version)) {
+ && cls_rule_visible_in_version(rule, version)) {
return true;
}
}
cls_version_t version)
{
/* Rule may only match a target if it is visible in target's version. */
- return cls_match_visible_in_version(rule->cls_match, version)
+ return cls_rule_visible_in_version(rule, version)
&& (!target || miniflow_equal_in_minimask(rule->match.flow,
target->match.flow,
target->match.mask));
assert(tr0->aux == tr1->aux);
/* Make sure the rule should have been visible. */
- assert(cr0->cls_match);
- assert(cls_match_visible_in_version(cr0->cls_match, version));
+ assert(cls_rule_visible_in_version(cr0, version));
}
cr2 = classifier_lookup(cls, version, &flow, NULL);
assert(cr2 == cr0);
found_rule = classifier_find_rule_exactly(cls, rule->cls_rule,
rule_version);
if (found_rule && found_rule != rule->cls_rule) {
+ struct cls_match *cls_match;
+ cls_match = get_cls_match_protected(found_rule);
assert(found_rule->priority == rule->priority);
/* Found rule may not have a lower version. */
- assert(found_rule->cls_match->add_version >= rule_version);
+ assert(cls_match->add_version >= rule_version);
/* This rule must not be visible in the found rule's
* version. */
assert(!cls_match_visible_in_version(
- rule, found_rule->cls_match->add_version));
+ rule, cls_match->add_version));
}
if (rule->priority == prev_priority) {
version);
if (versioned && removable_rule) {
+ struct cls_match *cls_match =
+ get_cls_match_protected(removable_rule);
+
/* Removable rule is no longer visible. */
- assert(removable_rule->cls_match);
- assert(!cls_match_visible_in_version(
- removable_rule->cls_match, version));
+ assert(cls_match);
+ assert(!cls_match_visible_in_version(cls_match, version));
classifier_remove(&cls, removable_rule);
n_invisible_rules--;
}