2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-28 12:58:00 +00:00

35 Commits

Author SHA1 Message Date
James Raphael Tiovalen
bc79a7bf03 treewide: Add ovs_assert to check for null pointers.
This patch adds an assortment of `ovs_assert` statements to check for
null pointers. We use assertions since it should be impossible for any
of these pointers to be NULL.

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2023-09-01 22:15:05 +02:00
James Raphael Tiovalen
62f5aa42aa shash, simap, smap: Add assertions to *_count functions.
This commit adds assertions in the functions `shash_count`,
`simap_count`, and `smap_count` to ensure that the corresponding input
struct pointer is not NULL.

This ensures that if the return values of `shash_sort`, `simap_sort`,
or `smap_sort` are NULL, then the following for loops would not attempt
to access the pointer, which might result in segmentation faults or
undefined behavior.

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Signed-off-by: James Raphael Tiovalen <jamestiotio@gmail.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2023-07-13 17:29:32 +02:00
Adrian Moreno
9e56549c2b hmap: use short version of safe loops if possible.
Using SHORT version of the *_SAFE loops makes the code cleaner and less
error prone. So, use the SHORT version and remove the extra variable
when possible for hmap and all its derived types.

In order to be able to use both long and short versions without changing
the name of the macro for all the clients, overload the existing name
and select the appropriate version depending on the number of arguments.

Acked-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-03-30 16:59:02 +02:00
Ben Pfaff
828129d927 json: Avoid extra memory allocation and string copy parsing object members.
Until now, every time the JSON parser added an object member, it made an
extra copy of the member name and then freed the original copy.  This is
wasteful, so this commit eliminates the extra copy.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-03-31 12:22:58 -07:00
Ben Pfaff
500db308e2 util: Document and rely on ovs_assert() always evaluating its argument.
The ovs_assert() macro always evaluates its argument, even when NDEBUG is
defined so that failure is ignored.  This behavior wasn't documented, and
thus a lot of code didn't rely on it.  This commit documents the behavior
and simplifies bits of code that heretofore didn't rely on it.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-02-01 11:21:34 -08:00
Terry Wilson
ee89ea7b47 json: Move from lib to include/openvswitch.
To easily allow both in- and out-of-tree building of the Python
wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to
include/openvswitch. This also requires moving lib/{hmap,shash}.h.

Both hmap.h and shash.h were #include-ing "util.h" even though the
headers themselves did not use anything from there, but rather from
include/openvswitch/util.h. Fixing that required including util.h
in several C files mostly due to OVS_NOT_REACHED and things like
xmalloc.

Signed-off-by: Terry Wilson <twilson@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-07-22 17:09:17 -07:00
Ben Pfaff
cb22974d77 Replace most uses of assert by ovs_assert.
This is a straight search-and-replace, except that I also removed #include
<assert.h> from each file where there were no assert calls left.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:03:37 -08:00
Ben Pfaff
ebc56baa41 util: New macro CONST_CAST.
Casts are sometimes necessary.  One common reason that they are necessary
is for discarding a "const" qualifier.  However, this can impede
maintenance: if the type of the expression being cast changes, then the
presence of the cast can hide a necessary change in the code that does the
cast.  Using CONST_CAST, instead of a bare cast, makes these changes
visible.

Inspired by my own work elsewhere:
http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-03 13:33:13 -07:00
Ethan Jackson
79f1cbe9f8 lib: New data structure - smap.
A smap is a string to string hash map.  It has a cleaner interface
than shash's which were traditionally used for the same purpose.
This patch implements the data structure, and changes netdev and
its providers to use it.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-06-14 15:09:31 -07:00
Raju Subramanian
e0edde6fee Global replace of Nicira Networks.
Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc.

Feature #10593
Signed-off-by: Raju Subramanian <rsubramanian@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-02 17:08:02 -07:00
Ben Pfaff
e74a239deb shash: New function shash_find_len().
This will acquire a user in an upcoming commit that uses it in parsing
without modifying the text being parsed or copying it.
2011-11-17 10:11:53 -08:00
Ben Pfaff
c56d226f8d shash: New "smap" functions for working with string-to-string maps.
An shash always has string keys and sometimes it hash string values as
well.  Usually the general-purpose shash functions are fine for working
with string-to-string maps, but this commit introduces a few more
specialized functions that only work with string-to-string maps.  It's not
clear yet to me whether this should actually be a new data structure, so
for now the new functions just work on shashes.

This commit also converts one user of shash_destroy() to use smap_destroy().
This is the only existing user of these functions that I spotted as a
trivial conversion candidate while grepping.

These new functions will see more use in the following commit.

Reviewed by Justin Pettit.
2011-01-27 09:26:06 -08:00
Ben Pfaff
4e8e4213a8 Switch many macros from using CONTAINER_OF to using OBJECT_CONTAINING.
These macros require one fewer argument by switching, which makes code
that uses them shorter and more readable.
2010-10-01 10:25:29 -07:00
Ben Pfaff
4f2226487d shash: New function shash_steal(). 2010-09-23 11:45:34 -07:00
Ben Pfaff
f2f7be8696 stream-ssl: Enable SSL session caching. 2010-08-11 10:24:40 -07:00
Ben Pfaff
79903dd171 shash: New function shash_replace().
To be used in an upcoming commit.
2010-06-30 16:49:01 -07:00
Ben Pfaff
1c6d8802c2 shash: Refactor shash_add_nocopy(), shash_find().
By breaking out the hash calculation we can enable operations that need
to do both to avoid duplicating the hash calculations.  A following commit
will add such an operation.
2010-06-30 16:49:00 -07:00
Ben Pfaff
a90b56b770 shash: New functions shash_destroy_free_data() and shash_clear_free_data(). 2010-06-17 10:30:19 -07:00
Ben Pfaff
ce5a3e38da ovs-vsctl: Support references among records at creation time.
This makes it easy to create a bunch of records that are all related to
each other in a single ovs-vsctl invocation.  It adds an example to the
ovs-vsctl manpage.
2010-06-17 10:30:18 -07:00
Ben Pfaff
4a1ee6ae82 bridge: Optimize iface_lookup() and port_lookup_iface() with a hash.
Before this commit and the following one, with 1000 interfaces strcmp()
took 36% and port_lookup() took 8% of total runtime when reconfiguring
bridges.  With these two commits the percentage is reduced to 3% and 0%,
respectively.
2010-05-05 14:00:47 -07:00
Ben Pfaff
baa8f41b24 New functions hmap_moved(), shash_moved().
To be used in ovs-vsctl in an upcoming commit.
2010-01-28 16:06:31 -08:00
Ben Pfaff
37e7f42772 Reimplement port mirroring configuration for database.
Tested only to the extent that it doesn't obviously break anything else.
2010-01-19 10:40:36 -08:00
Ben Pfaff
7634353824 vswitchd: Initial conversion to database-based configuration.
This has seen very little testing, so some features are almost certainly
busted.  Port mirroring is not yet converted, so it will definitely not
work.
2009-12-03 11:28:40 -08:00
Ben Pfaff
55213fd581 shash: Make it more convenient to store "const" objects in an shash. 2009-11-20 15:39:07 -08:00
Ben Pfaff
07423999f1 shash: New function shash_sort(). 2009-11-04 15:01:02 -08:00
Ben Pfaff
c01da22964 shash: New function shash_count(). 2009-11-04 15:01:02 -08:00
Ben Pfaff
837e80977c shash: New function shash_find_and_delete(). 2009-11-04 15:01:02 -08:00
Ben Pfaff
4d678233e9 Merge "citrix" branch into "master. 2009-10-05 10:29:07 -07:00
Ben Pfaff
d855aeadfd shash: Fix memory leak in shash_destroy().
hmap_destroy() has to be called so that sh->map.buckets gets freed.
2009-09-24 10:23:22 -07:00
Ben Pfaff
fd30311c87 shash: Introduce new macros SHASH_FOR_EACH, SHASH_FOR_EACH_SAFE.
This is both more convenient and cleaner than using HMAP_FOR_EACH(_SAFE)
directly.
2009-07-30 16:07:13 -07:00
Ben Pfaff
78299b0a68 shash: Make shash_add() return the new node. 2009-07-30 16:07:13 -07:00
Ben Pfaff
7efc68eb07 shash: New function shash_first(). 2009-07-06 09:07:23 -07:00
Ben Pfaff
732dcb37a8 shash: New function shash_is_empty(). 2009-07-06 09:07:23 -07:00
Ben Pfaff
a14bc59fb8 Update primary code license to Apache 2.0. 2009-06-15 15:11:30 -07:00
Ben Pfaff
064af42167 Import from old repository commit 61ef2b42a9c4ba8e1600f15bb0236765edc2ad45. 2009-07-08 13:19:16 -07:00