flow_table.c (6b798d70d07a38e9ba0a32316f76495f9dcfc343) flow_table.c (12eb18f7115884b0c1513dda31b0051121116b3a)
1/*
2 * Copyright (c) 2007-2014 Nicira, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but

--- 93 unchanged lines hidden (view full) ---

102 RCU_INIT_POINTER(flow->stats[node], NULL);
103
104 return flow;
105err:
106 kmem_cache_free(flow_cache, flow);
107 return ERR_PTR(-ENOMEM);
108}
109
1/*
2 * Copyright (c) 2007-2014 Nicira, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but

--- 93 unchanged lines hidden (view full) ---

102 RCU_INIT_POINTER(flow->stats[node], NULL);
103
104 return flow;
105err:
106 kmem_cache_free(flow_cache, flow);
107 return ERR_PTR(-ENOMEM);
108}
109
110int ovs_flow_tbl_count(struct flow_table *table)
110int ovs_flow_tbl_count(const struct flow_table *table)
111{
112 return table->count;
113}
114
115static struct flex_array *alloc_buckets(unsigned int n_buckets)
116{
117 struct flex_array *buckets;
118 int i, err;

--- 277 unchanged lines hidden (view full) ---

396static bool flow_cmp_masked_key(const struct sw_flow *flow,
397 const struct sw_flow_key *key,
398 int key_start, int key_end)
399{
400 return cmp_key(&flow->key, key, key_start, key_end);
401}
402
403bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
111{
112 return table->count;
113}
114
115static struct flex_array *alloc_buckets(unsigned int n_buckets)
116{
117 struct flex_array *buckets;
118 int i, err;

--- 277 unchanged lines hidden (view full) ---

396static bool flow_cmp_masked_key(const struct sw_flow *flow,
397 const struct sw_flow_key *key,
398 int key_start, int key_end)
399{
400 return cmp_key(&flow->key, key, key_start, key_end);
401}
402
403bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
404 struct sw_flow_match *match)
404 const struct sw_flow_match *match)
405{
406 struct sw_flow_key *key = match->key;
407 int key_start = flow_key_start(key);
408 int key_end = match->range.end;
409
410 return cmp_key(&flow->unmasked_key, key, key_start, key_end);
411}
412
413static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
414 const struct sw_flow_key *unmasked,
405{
406 struct sw_flow_key *key = match->key;
407 int key_start = flow_key_start(key);
408 int key_end = match->range.end;
409
410 return cmp_key(&flow->unmasked_key, key, key_start, key_end);
411}
412
413static struct sw_flow *masked_flow_lookup(struct table_instance *ti,
414 const struct sw_flow_key *unmasked,
415 struct sw_flow_mask *mask)
415 const struct sw_flow_mask *mask)
416{
417 struct sw_flow *flow;
418 struct hlist_head *head;
419 int key_start = mask->range.start;
420 int key_end = mask->range.end;
421 u32 hash;
422 struct sw_flow_key masked_key;
423

--- 31 unchanged lines hidden (view full) ---

455 const struct sw_flow_key *key)
456{
457 u32 __always_unused n_mask_hit;
458
459 return ovs_flow_tbl_lookup_stats(tbl, key, &n_mask_hit);
460}
461
462struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
416{
417 struct sw_flow *flow;
418 struct hlist_head *head;
419 int key_start = mask->range.start;
420 int key_end = mask->range.end;
421 u32 hash;
422 struct sw_flow_key masked_key;
423

--- 31 unchanged lines hidden (view full) ---

455 const struct sw_flow_key *key)
456{
457 u32 __always_unused n_mask_hit;
458
459 return ovs_flow_tbl_lookup_stats(tbl, key, &n_mask_hit);
460}
461
462struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
463 struct sw_flow_match *match)
463 const struct sw_flow_match *match)
464{
465 struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
466 struct sw_flow_mask *mask;
467 struct sw_flow *flow;
468
469 /* Always called under ovs-mutex. */
470 list_for_each_entry(mask, &tbl->mask_list, list) {
471 flow = masked_flow_lookup(ti, match->key, mask);

--- 86 unchanged lines hidden (view full) ---

558 return m;
559 }
560
561 return NULL;
562}
563
564/* Add 'mask' into the mask list, if it is not already there. */
565static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
464{
465 struct table_instance *ti = rcu_dereference_ovsl(tbl->ti);
466 struct sw_flow_mask *mask;
467 struct sw_flow *flow;
468
469 /* Always called under ovs-mutex. */
470 list_for_each_entry(mask, &tbl->mask_list, list) {
471 flow = masked_flow_lookup(ti, match->key, mask);

--- 86 unchanged lines hidden (view full) ---

558 return m;
559 }
560
561 return NULL;
562}
563
564/* Add 'mask' into the mask list, if it is not already there. */
565static int flow_mask_insert(struct flow_table *tbl, struct sw_flow *flow,
566 struct sw_flow_mask *new)
566 const struct sw_flow_mask *new)
567{
568 struct sw_flow_mask *mask;
569 mask = flow_mask_find(tbl, new);
570 if (!mask) {
571 /* Allocate a new mask if none exsits. */
572 mask = mask_alloc();
573 if (!mask)
574 return -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

581 }
582
583 flow->mask = mask;
584 return 0;
585}
586
587/* Must be called with OVS mutex held. */
588int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
567{
568 struct sw_flow_mask *mask;
569 mask = flow_mask_find(tbl, new);
570 if (!mask) {
571 /* Allocate a new mask if none exsits. */
572 mask = mask_alloc();
573 if (!mask)
574 return -ENOMEM;

--- 6 unchanged lines hidden (view full) ---

581 }
582
583 flow->mask = mask;
584 return 0;
585}
586
587/* Must be called with OVS mutex held. */
588int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
589 struct sw_flow_mask *mask)
589 const struct sw_flow_mask *mask)
590{
591 struct table_instance *new_ti = NULL;
592 struct table_instance *ti;
593 int err;
594
595 err = flow_mask_insert(table, flow, mask);
596 if (err)
597 return err;

--- 53 unchanged lines hidden ---
590{
591 struct table_instance *new_ti = NULL;
592 struct table_instance *ti;
593 int err;
594
595 err = flow_mask_insert(table, flow, mask);
596 if (err)
597 return err;

--- 53 unchanged lines hidden ---