2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-26 03:47:27 +00:00

33 Commits

Author SHA1 Message Date
Ilya Maximets
823d4f6bc8 dynamic-string: Add function for a sparse hex dump.
New function to dump large and sparsely populated data structures
like struct flow.

Reviewed-by: Roi Dayan <roid@nvidia.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-08-04 14:18:05 +02:00
Dumitru Ceara
336d7dd7cc dynamic-string: Fix undefined behavior due to offsetting null pointer.
When compiled with clang and '-fsanitize=undefined' set, running
'ovsdb-client --timestamp monitor Open_vSwitch' in a sandbox triggers
the following undefined behavior (flagged by UBSan):

  lib/dynamic-string.c:207:38: runtime error: applying zero offset to null pointer
      #0 0x4ebc18 in ds_put_strftime_msec lib/dynamic-string.c:207:38
      #1 0x4ebd04 in xastrftime_msec lib/dynamic-string.c:225:5
      #2 0x552e6a in table_format_timestamp__ lib/table.c:226:12
      #3 0x552852 in table_print_timestamp__ lib/table.c:233:27
      #4 0x5506f3 in table_print_table__ lib/table.c:254:5
      #5 0x550633 in table_format lib/table.c:601:9
      #6 0x5524f3 in table_print lib/table.c:633:5
      #7 0x44dc5e in monitor_print_table ovsdb/ovsdb-client.c:1019:5
      #8 0x44c650 in monitor_print ovsdb/ovsdb-client.c:1040:13
      #9 0x44ac56 in do_monitor__ ovsdb/ovsdb-client.c:1500:21
      #10 0x44636e in do_monitor ovsdb/ovsdb-client.c:1575:5
      #11 0x442c41 in main ovsdb/ovsdb-client.c:283:5

Reported-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-05-26 11:43:53 +02:00
Dumitru Ceara
471babb811 treewide: Avoid offsetting NULL pointers.
This is undefined behavior and was reported by UB Sanitizer:
  lib/meta-flow.c:3445:16: runtime error:
    member access within null pointer of type 'struct vl_mf_field'
      0 0x6aad0f in mf_get_vl_mff lib/meta-flow.c:3445
      1 0x6d96d7 in mf_from_oxm_header lib/nx-match.c:260
      2 0x6d9e2e in nx_pull_header__ lib/nx-match.c:341
      3 0x6daafa in nx_pull_header lib/nx-match.c:488
      4 0x6abcb6 in mf_vl_mff_nx_pull_header lib/meta-flow.c:3605
      5 0x73b9be in decode_NXAST_RAW_REG_MOVE lib/ofp-actions.c:2652
      6 0x764ccd in ofpact_decode lib/ofp-actions.inc2:4681
      [...]
  lib/sset.c:315:12: runtime error: applying zero offset to null pointer
      0 0xcc2e6a in sset_at_position lib/sset.c:315:12
      1 0x5734b3 in port_dump_next ofproto/ofproto-dpif.c:4083:20
      [...]
  lib/ovsdb-data.c:2194:56:
  runtime error: applying zero offset to null pointer
      0 0x5e9530 in ovsdb_datum_added_removed lib/ovsdb-data.c:2194:56
      1 0x4d6258 in update_row_ref_count ovsdb/transaction.c:335:17
      2 0x4c360b in for_each_txn_row ovsdb/transaction.c:1572:33
      [...]
  lib/ofpbuf.c:440:30:
  runtime error: applying zero offset to null pointer
      0 0x75066d in ofpbuf_push_uninit lib/ofpbuf.c:440
      1 0x46ac8a in ovnacts_parse lib/actions.c:4190
      2 0x46ad91 in ovnacts_parse_string lib/actions.c:4208
      3 0x4106d1 in test_parse_actions tests/test-ovn.c:1324
      [...]
  lib/ofp-actions.c:3205:22:
  runtime error: applying non-zero offset 2 to null pointer
      0 0x6e1641 in set_field_split_str lib/ofp-actions.c:3205:22
      [...]
  lib/tnl-ports.c:74:12:
  runtime error: applying zero offset to null pointer
      0 0xceffe7 in tnl_port_cast lib/tnl-ports.c:74:12
      1 0xcf14c3 in map_insert lib/tnl-ports.c:116:13
      [...]
  ofproto/ofproto.c:8905:16:
  runtime error: applying zero offset to null pointer
      0 0x556795 in eviction_group_hash_rule ofproto/ofproto.c:8905:16
      1 0x503f8d in eviction_group_add_rule ofproto/ofproto.c:9022:42
      [...]

Also, it's valid to have an empty ofpact list and we should be able to
try to iterate through it.

UB Sanitizer report:
  include/openvswitch/ofp-actions.h:222:12:
  runtime error: applying zero offset to null pointer
      0 0x665d69 in ofpact_end ./include/openvswitch/ofp-actions.h:222:12
      1 0x66b2cf in ofpacts_put_openflow_actions lib/ofp-actions.c:8861:5
      2 0x6ffdd1 in ofputil_encode_flow_mod lib/ofp-flow.c:447:9
      [...]

Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-05-17 23:08:13 +02:00
Sriharsha Basavapatna
0363891d10 dynamic-string: Fix a crash in ds_clone().
ds_clone() crashes while trying to clone an empty dynamic string.
It happens because it doesn't check if memory was allocated and
tries to read from the NULL pointer.  ds_init() doesn't allocate
any memory.

For example:
In netdev_offload_dpdk_flow_create() when an offload request fails,
dump_flow() is called to log a warning message. The 's_tnl' string
in flow_patterns gets initialized in vport_to_rte_tunnel() conditionally
via ds_put_format(). If it is not initialized, it crashes later in
dump_flow_attr()->ds_clone()->memcpy() while dereferencing this string.

To fix this, check if memory for the src string has been allocated,
before copying it to the dst string.

Fixes: fa44a4a3ff7b ("ovn-controller: Persist desired conntrack groups.")
Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2021-08-16 19:25:43 +02:00
Ryan Moats
fa44a4a3ff ovn-controller: Persist desired conntrack groups.
With incremental processing of logical flows desired conntrack groups
are not being persisted.  This patch adds this capability, with the
side effect of adding a ds_clone method that this capability leverages.

Signed-off-by: Ryan Moats <rmoats@us.ibm.com>
Reported-by: Guru Shetty <guru@ovn.org>
Reported-at: http://openvswitch.org/pipermail/dev/2016-July/076320.html
Fixes: 70c7cfe ("ovn-controller: Add incremental processing to lflow_run and physical_run")
Acked-by: Flavio Fernandes <flavio@flaviof.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-08-10 13:54:07 -07:00
Ben Warren
3e8a2ad145 Move lib/dynamic-string.h to include/openvswitch directory
Signed-off-by: Ben Warren <ben@skyportsystems.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2016-03-19 10:02:12 -07:00
Ben Pfaff
29100ef2ba dynamic-string: Make ds_chomp() return true if it removed a character.
This will be used in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jarno@ovn.org>
2016-02-19 00:02:16 -08:00
Jesse Gross
e7ae59f990 util: Library routines for printing and scanning large hex integers.
Geneve options are variable length and up to 124 bytes long, which means
that they can't be easily manipulated by the integer string functions
like we do for other fields. This adds a few helper routines to make
these operations easier.

Signed-off-by: Jesse Gross <jesse@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2015-05-28 18:34:21 -07:00
Alin Serdean
34582733d9 Avoid printf type modifiers not supported by MSVC C runtime library.
The MSVC C library printf() implementation does not support the 'z', 't',
'j', or 'hh' format specifiers.  This commit changes the Open vSwitch code
to avoid those format specifiers, switching to standard macros from
<inttypes.h> where available and inventing new macros resembling them
where necessary.  It also updates CodingStyle to specify the macros' use
and adds a Makefile rule to report violations.

Signed-off-by: Alin Serdean <aserdean@cloudbasesolutions.com>
Co-authored-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-11-25 23:38:59 -08:00
Paul Ingram
2b31d8e713 vlog: Report timestamps in millisecond resolution in log messages.
To make debugging easier.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Paul Ingram <pingram@nicira.com>
2013-09-13 09:11:46 -07:00
Ben Pfaff
bdda5aca7b ofp-parse: Do not exit() upon a parse error.
Until now, failure to parse a flow in the ofp-parse module has caused the
program to abort immediately with a fatal error.  This makes it hard to
use these functions from any long-lived program.  This commit fixes the
problem.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-08 10:15:00 -07:00
Ben Pfaff
aaa4b65b23 Do not include trailing whitespace in hexdump.
Reported-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Tested-by: Simon Horman <horms@verge.net.au>
2013-05-16 11:23:09 -07:00
Ben Pfaff
9aba74cef5 dynamic-string: Fix style of ds_put_hex_dump().
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Kyle Mestery <kmestery@cisco.com>
Tested-by: Simon Horman <horms@verge.net.au>
2013-05-16 10:51:12 -07:00
Ben Pfaff
3e78870d0b Always check return value of strftime().
strftime() returns 0 and leaves the contents of the output buffer
unspecified if the output buffer is not big enough.  Thus, one should
check strftime()'s return value.  Until now, OVS has had a few invocations
of strftime() that did not check the return value.  This commit fixes
those.  I believe that the buffers were always large enough in each case,
but it's better to be safe.

Reported-by: Andy Zhou <azhou@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-05-08 10:53:07 -07:00
Ben Pfaff
9b6937eb1f Use gmtime_r() and localtime_r() instead of non-thread-safe versions.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-05-02 15:49:36 -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
Ben Pfaff
06d7ae7d9b dynamic-string: New function ds_get_test_line().
This eliminates some code duplication.   An upcoming commit will add
another user.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-10 11:44:05 -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
541bc79f73 dynamic-string: Document a few functions.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-02-27 10:07:47 -08:00
Gurucharan Shetty
b5d29991cc vlog: Change the default timestamp structure.
Change the default timestamp for console and file logs to
UTC in a format that satisfies timestamp requirements in RFC 5424.

Also, add the ability for ovs-appctl to log timestamps in UTC.

Bug #9052.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
2012-01-27 16:56:12 -08:00
Ben Pfaff
dd8101bc53 dynamic-string: New function ds_get_preprocessed_line().
This commit adds one user.  It will be useful elsewhere in an upcoming
commit.
2011-03-16 14:53:16 -07:00
Ben Pfaff
2a022368f4 Avoid shadowing local variable names.
All of these changes avoid using the same name for two local variables
within a same function.  None of them are actual bugs as far as I can tell,
but any of them could be confusing to the casual reader.

The one in lib/ovsdb-idl.c is particularly brilliant: inner and outer
loops both using (different) variables named 'i'.

Found with GCC -Wshadow.
2010-09-20 09:39:54 -07:00
Joe Perches
d295e8e97a treewide: Remove trailing whitespace
Signed-off-by: Joe Perches <joe@perches.com>
Acked-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Jesse Gross <jesse@nicira.com>
2010-08-30 13:23:08 -07:00
Jesse Gross
c73814a3e6 timeval: Use monotonic time where appropriate.
Most of the timekeeping needs of OVS are simply to measure intervals,
which means that it is sensitive to changes in the clock.  This commit
replaces the existing clocks with monotonic timers.  An additional set
of wall clock timers are added and used in locations that need absolute
time.

Bug #1858
2010-06-08 18:01:25 -07:00
Ben Pfaff
36c501fe78 dynamic-string: Optimize ds_put_char().
A qprof profile showed ds_put_char() and ds_put_uninit() as 4% of total
runtime.  This commit inlines the common case, which reduces them to 1%
total.
2010-05-05 14:00:50 -07:00
Ben Pfaff
e83fd21330 dynamic-string: New function ds_swap(). 2010-01-28 16:06:31 -08:00
Ben Pfaff
5f98eed4eb dynamic-string: New function ds_cstr_ro(). 2009-12-16 11:28:13 -08:00
Ben Pfaff
1fd13cde12 jsonrpc: Add logging for messages sent and received, at DBG level.
This made it much easier to see problems while developing some
ovsdb-server features.
2009-11-17 16:02:46 -08:00
Ben Pfaff
f38b84ea2b Implement JSON parsing and serialization.
This will be used by the upcoming Open vSwitch configuration database.
2009-11-04 15:24:40 -08:00
Ben Pfaff
4871855420 New function ds_steal_cstr(). 2009-07-16 09:17:06 -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