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

110 Commits

Author SHA1 Message Date
Ben Pfaff
a8d819675f Remove stream, vconn, and rconn functions to get local/remote IPs/ports.
These functions don't have any ultimate users.  The in-band control code
used to use them, but not anymore, so we might as well delete them all.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-12-17 15:08:38 -08:00
Harold Lim
428b2eddc9 Rename NOT_REACHED to OVS_NOT_REACHED
This allows other libraries to use util.h that has already
defined NOT_REACHED.

Signed-off-by: Harold Lim <haroldl@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-12-17 13:16:39 -08: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
Justin Pettit
125b02910c ofproto: Define official OpenFlow port number.
Signed-off-by: Justin Pettit <jpettit@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2013-10-01 16:46:39 -07:00
Justin Pettit
ca843648e3 Don't differentiate between TCP and SSL ports for OpenFlow and OVSDB.
The OVS code has always made a distinction between the unencrypted (TCP)
and SSL port numbers for the OpenFlow and OVSDB protocols.  The default
port numbers for both protocols has changed, and there continues to be
no distinction between the unencrypted and SSL versions.  This
commit removes the distinction in port numbers.  A future patch will
recognize the change in default port number.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2013-10-01 16:18:45 -07:00
Ben Pfaff
10a89ef04d Replace all uses of strerror() by ovs_strerror(), for thread safety.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28 16:09:38 -07:00
Ben Pfaff
825da1c6d1 leak-checker: Remove because it cannot be made thread-safe.
The underlying glibc interface is deprecated because the interface itself
is not thread-safe.  That means that there's no way for a layer on top of
it to be thread-safe.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-06-17 15:33:15 -07:00
Andy Hill
ec9f40dce1 Fix misspellings in comments and docs.
Flagged with: https://github.com/lyda/misspell-check
Run with: git ls-files | misspellings -f -

Signed-off-by: Andy Hill <hillad@gmail.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-04 21:53:33 -07:00
Ben Pfaff
798e1352d0 ovsdb-server: Announce bound listening ports as status:bound_port.
The administrator can request that OVSDB bind any available TCP port, but
in that case there is no easy way to find out what port it has bound.  This
commit adds that information as the "bound_port" key in the "status"
column.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-04-18 16:43:15 -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
ed36537ebf packets: Change IP_ARGS interface to take an ovs_be32 instead of a pointer.
An ovs_be32 is a more obvious way to represent an IP address than a
pointer to one.  It is also more type-safe, especially since "sparse" is
able to check that the argument is in network byte order.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2012-12-12 15:26:21 -08:00
Isaku Yamahata
f89b7ce502 pstream: Add set_dscp method.
Introduce set_dscp method to pstream.
This will be used by dynamic dscp change of listening socket.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-09-26 21:24:19 -07:00
Ben Pfaff
1ee62357e9 stream-ssl: Change "bootstrap race" log message from ERR to INFO.
This situation can and will happen, and we handle it successfully, so it's
not an error.

Bug #12922.
Reported-by: Scott Hendricks <shendricks@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-13 10:54:31 -07:00
Ben Pfaff
b6d729adb5 stream-ssl: Avoid logging no-match error redundantly.
If we've already reported an error at this point, then we currently report
a no-match error also, but that doesn't add any useful information; it's
just noise in the log.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-09 14:19:29 -07:00
Ben Pfaff
47ebcf25ef stream-ssl: Seed OpenSSL if it fails to seed itself.
We occasionally see OpenSSL fail to seed its random number generator in
heavily loaded hypervisors.  I suspect the following scenario:

1. OpenSSL calls read() to get 32 bytes from /dev/urandom.
2. The kernel generates 10 bytes of randomness and copies it out.
3. A signal arrives (perhaps SIGALRM).
4. The kernel interrupts the system call to service the signal.
5. Userspace gets 10 bytes of entropy.
6. OpenSSL doesn't read again to get the final 22 bytes.  Therefore
   OpenSSL doesn't have enough entropy to consider itself initialized.
   It never tries again, so we're stuck forever.

The only part I'm not entirely sure about is #6, because the OpenSSL code
is so hard to read.

Thanks to Alex Yip for suggesting that this might be a startup problem.

Bug #10164.
Reported-by: Ram Jothikumar <ram@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-09 14:18:46 -07: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
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
Ethan Jackson
f1936eb651 stream: By default disable probing on unix sockets.
There isn't a lot of value in sending inactivity probes on unix
sockets.  This patch changes the default to disable them.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-04-12 00:43:22 -07:00
Mehak Mahajan
f125905cdd Allow configuring DSCP on controller and manager connections.
The changes allow the user to specify a separate dscp value for the
controller connection and the manager connection. The value will take
effect on resetting the connections. If no value is specified a default
value of 192 is chosen for each of the connections.

Feature #10074
Requested-by: Rajiv Ramanathan <rramanathan@nicira.com>
Signed-off-by: Mehak Mahajan <mmahajan@nicira.com>
2012-03-23 18:13:08 -07:00
Simon Horman
da327b18bd stream: Make classes const
The classes are never modified and may be declared constant.
2011-11-23 21:18:06 -08:00
Ben Pfaff
e6a8ca62a6 stream-ssl: Clear CAs for certificate verification before adding new ones.
If the CA certificate changed and OVS added the new CA certificate, the
change was ineffective.  Clearing the certificate store before adding the
new CA certificate fixes the problem.

I don't know exactly why this fixes the problem, but in my testing it does.

Bug #2921.
Reported-by: Dan Wendlandt <dan@nicira.com>
Reported-by: Pierre Ettori <pettori@nicira.com>
2011-06-17 10:50:23 -07:00
Ben Pfaff
932df1237b stream-ssl: Disable SSL session caching.
SSL session caching causes mysterious connection failure problems.

Bug #4448.
Bug #4501.
2011-06-06 09:43:48 -07:00
Ben Pfaff
e68f6dea54 stream-ssl: Log unexpected errors from 'stat'.
A user report possibly implicates problems reading the mtime of the CA
cert file.  Until now, nothing has logged these errors.  This commit adds
such logging.

NICS-9.
2011-05-24 11:26:00 -07:00
Ben Pfaff
f14848742a stream-ssl: Force CA cert file to be read when it appears during bootstrap.
A user report shows the message "reading CA cert
/etc/openvswitch/vswitchd.cacert created by another process" appearing
hundreds of times over a long period of time in the log.  The only way I
can see that this would happen is if update_ssl_config() returned false,
indicating that the CA cert does not need to be re-read because it has not
changed.  This commit should prevent that from happening.

We don't want to simply skip calling update_ssl_config() in this case,
because then the next call to stream_ssl_set_ca_cert_file() would usually
re-read the CA certificate, which is a waste of time.

Also, we might as well rate-limit the message.

NICS-9.
2011-05-24 11:26:00 -07:00
Ben Pfaff
c5530655f3 stream-ssl: Fix call to accept().
GCC and glibc conspire to allow struct sockaddr_in * to be passed in
place of struct sockaddr *, but that's non-standard and we're better
off not taking advantage of it.

Found by sparse.
2011-05-16 13:40:46 -07:00
Ben Pfaff
1d2c568dfd stream-ssl: Use out_of_memory() to abort due to lack of memory.
This matches what xmalloc() does.  It will be handled better by a monitor
process (created with --monitor), which will restart the child instead of
exiting.
2011-04-04 10:58:54 -07:00
Gaetano Catalli
bd6b75452e Fix compilation of openvswitch-1.1.0pre2 on FreeBSD-8.1 2011-03-30 09:43:28 -07:00
Ben Pfaff
aae3743bf2 stream-ssl: Only set SSL client session once.
Attempting to call SSL_set_session() on every trip through the SSL
connection state machine seems like it could cause the session to be
re-set to the cached one even after the server has told us which session
is actually to be used.

In testing, this change didn't make any difference, but it seems seems like
the right thing to do.

Bug #4448.
2011-03-01 14:50:09 -08:00
Ben Pfaff
246f5b5ede stream-ssl: Break interpretation of queued error into new function.
The following commit will introduce another user.
2011-03-01 14:50:09 -08:00
Ben Pfaff
f01eb73ccf stream-ssl: Only cache SSL sessions after they shut down.
A cached SSL session may only be used for new connections after the initial
connection has shut down.  As far as I can tell, nothing in the OpenSSL
documentation actually comes out and says this, but it is implied by
various examples found around the web and doing it this way makes caching
work much more reliably in my testing.

Bug #4448.
2011-01-25 17:10:48 -08:00
Ben Pfaff
b5beaca198 stream-ssl: Set a session context ID string on our SSL_CTX.
In the finest OpenSSL tradition of putting important documentation only in
code comments, ssl/ssl_sess.c in the OpenSSL tree has the following comment
inside ssl_get_prev_session():

   /* We can't be sure if this session is being used out of
    * context, which is especially important for SSL_VERIFY_PEER.
    * The application should have used SSL[_CTX]_set_session_id_context.
    *
    * For this error case, we generate an error instead of treating
    * the event like a cache miss (otherwise it would be easy for
    * applications to effectively disable the session cache by
    * accident without anyone noticing).
    */

This meant that ovs-controller couldn't effectively cache SSL server
sessions and we got a weird error whenever ovs-vswitchd tried.

Bug #4448.
CC: David Tsai <dtsai@nicira.com>
CC: Jeremy Stribling <strib@nicira.com>
2011-01-25 17:10:48 -08:00
Ethan Jackson
0fee489f84 stream-ssl: Fix compiler warning.
This commit fixes the following compiler warnings:
"format '%d' expects type 'int', but argument 4 has type 'size_t'"
2011-01-04 10:30:36 -08:00
Ben Pfaff
d76f09ea77 coverage: Make the coverage counters catalog program-specific.
Until now, the collection of coverage counters supported by a given OVS
program was not specific to that program.  That means that, for example,
even though ovs-dpctl does not have anything to do with mac_learning, it
still has a coverage counter for it.  This is confusing, at best.

This commit fixes the problem on some systems, in particular on ones that
use GCC and the GNU linker.  It uses the feature of the GNU linker
described in its manual as:

    If an orphaned section's name is representable as a C identifier then
    the linker will automatically see PROVIDE two symbols: __start_SECNAME
    and __end_SECNAME, where SECNAME is the name of the section.  These
    indicate the start address and end address of the orphaned section
    respectively.

Systems that don't support these features retain the earlier behavior.

This commit also fixes the annoyance that files that include coverage
counters must be listed on COVERAGE_FILES in lib/automake.mk.

This commit also fixes the annoyance that modifying any source file that
includes a coverage counter caused all programs that link against
libopenvswitch.a to relink, even programs that the source file was not
linked into.  For example, modifying ofproto/ofproto.c (which includes
coverage counters) caused tests/test-aes128 to relink, even though
test-aes128 does not link again ofproto.o.
2010-11-30 10:30:30 -08:00
Ben Pfaff
d98e600755 vlog: Make client supply semicolon for VLOG_DEFINE_THIS_MODULE.
It's kind of odd for VLOG_DEFINE_THIS_MODULE to supply its own semicolon,
so this commit switches to the more common form.
2010-10-29 09:48:47 -07:00
Ben Pfaff
444b381ed1 stream-ssl: Avoid warning with recent OpenSSL.
Reported-by: Ethan Jackson <ethan@nicira.com>
2010-10-14 15:13:33 -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
Ben Pfaff
3c7b5c2ddc stream-ssl: Use OPENSSL_free() to free memory from X509_NAME_oneline().
Reported-by: Tsvi Slonim <tsvi@toroki.com>
2010-08-27 13:30:31 -07:00
Ben Pfaff
f2f7be8696 stream-ssl: Enable SSL session caching. 2010-08-11 10:24:40 -07:00
Ben Pfaff
da61d5732e stream-ssl: Remove unused 'connect_error' member.
Never read, never written.
2010-08-11 10:03:05 -07:00
Ben Pfaff
6f1e91b1d7 stream-ssl: Make changing keys and certificate at runtime reliable.
OpenSSL is picky about the order in which keys and certificates are
changed: you have to change the certificate first, then the key.  It
doesn't document this, but deep in the source code, in a function that sets
a new certificate, it has this comment:

    /* don't fail for a cert/key mismatch, just free
     * current private key (when switching to a different
     * cert & key, first this function should be used,
     * then ssl_set_pkey */

Brilliant, guys, thanks a lot.

Bug #2921.
2010-08-05 09:24:00 -07:00
Ben Pfaff
5136ce492c vlog: Introduce VLOG_DEFINE_THIS_MODULE for declaring vlog module in use.
Adding a macro to define the vlog module in use adds a level of
indirection, which makes it easier to change how the vlog module must be
defined.  A followup commit needs to do that, so getting these widespread
changes out of the way first should make that commit easier to review.
2010-07-21 15:47:09 -07:00
Ben Pfaff
ff1760f1c7 stream-ssl: Log protocol details at DBG level.
Sometimes seeing a little bit of SSL protocol information can be valuable
in debugging connection problems.  With this commit, setting the stream_ssl
logging module to DBG level will cause basic SSL handshake information to
be logged for new connections.
2010-06-23 12:29:55 -07:00
Ben Pfaff
3d47699cdf stream-ssl: Flush OpenSSL error queue after calling SSL_shutdown().
The OpenSSL manpage for SSL_get_error() says this:

   In addition to ssl and ret, SSL_get_error() inspects the current
   thread's OpenSSL error queue.  Thus, SSL_get_error() must be used in
   the same thread that performed the TLS/SSL I/O operation, and no other
   OpenSSL function calls should appear in between.  The current thread's
   error queue must be empty before the TLS/SSL I/O operation is
   attempted, or SSL_get_error() will not work reliably.

We weren't taking this advice literally enough, which meant that this
would happen:

   1. Call SSL_shutdown() on one connection.
   2. Call SSL_read() on another connection, returning 0 bytes.  (This is
      normal.  It just means that no more data has arrived yet.)
   3. Call SSL_get_error() for that second connection to check whether
      the 0-byte return value was a real error.  (This should return
      SSL_ERROR_WANT_READ to indicate that more data is needed.)
   4. Actually get some other error indicating that the SSL_shutdown()
      call returned an error.

This commit fixes the problem by flushing the OpenSSL error queue after
calling SSL_shutdown().

Without this commit, starting an ovsdb-server with two active SSL remotes,
running two ovsdb-clients listening for connections from the ovsdb-server
remotes, then killing one of the ovsdb-clients (with e.g. Control+C), will
cause ovsdb-server to drop the other ovsdb-client connnection the next time
that SSL_read() is called on it.  With this commit, this scenario works
correctly (e.g. ovsdb-server keeps the remaining connection up).

CC: Jeremy Stribling <strib@nicira.com>
2010-05-13 16:08:14 -07:00
Ben Pfaff
1e3c004749 Diagnose attempts to connect the wrong protocol to a network port.
Sometimes, when a user asks me to help debug a problem, it turns out that
an SSL connection was being made on a TCP port, or vice versa, or that an
OpenFlow connection was being made on a JSON-RPC port, or vice versa, and
so on.  This commit adds log messages that diagnose this kind of problem,
e.g. "tcp:127.0.0.1:6633: received JSON-RPC data on OpenFlow channel".
2010-05-11 11:50:45 -07:00
Ben Pfaff
26efd2563b socket-util: Move get_mtime() here from stream-ssl.
An upcoming commit will add a new user for this function in another file,
so export it and move it to a common library file.
2010-04-26 11:29:32 -07:00
Ben Pfaff
2b1a27a1f8 stream-ssl: Avoid access-after-free error in update_ssl_config().
Commit b84f503d "stream-ssl: Read existing CA certificate more eagerly
during bootstrap" inadvertently introduced an access-after-free error:

  do_ca_cert_bootstrap() calls
    stream_ssl_set_ca_cert_file(ca_cert.file_name, true), which calls
      update_ssl_config(&ca_cert, file_name), which calls
        free(ca_cert.file_name) then xstrdup(ca_cert.file_name).

Fix the problem.

Reported-by: Cedric Hobbs <cedric@nicira.com>
Reported-by: Peter Balland <peter@nicira.com>
2010-04-14 16:02:45 -07:00
Ben Pfaff
ba104a1e39 stream-ssl: Make it possible to avoid checking peer SSL certificate.
In Citrix XenServer, the hosts have SSL private keys and certificates, but
those certificates are not signed by any certificate authority.  So we
must provide a way to avoid checking certificates against a CA if we want
other OVS tools to be able to talk to XenServer hosts over SSL.  This
commit makes that possible.
2010-04-12 11:03:32 -07:00
Ben Pfaff
b84f503d84 stream-ssl: Read existing CA certificate more eagerly during bootstrap.
When do_ca_cert_bootstrap() attempts to bootstrap a CA certificate from a
remote host, it gives up if the CA certificate file already exists.  It
knows that this file did not exist some time earlier (because it checked),
so it logged a warning and just returns.  The next time that
stream_ssl_set_ca_cert_file() gets called, it will read the new CA
certificate file and all will be well.

That works OK in ovsdb-server, which calls stream_ssl_set_ca_cert_file()
every time through its main loop.  It does not work well for ovs-vswitchd,
which only calls that function when it needs to reconfigure.  But it
should work fine to call it directly from do_ca_cert_bootstrap(), so this
commit changes it to do that.

Bug #2635.
2010-04-12 10:49:16 -07:00
Ben Pfaff
9cb0788702 stream-ssl: Only re-read certificates and keys if they change.
Commit 415f6c0b1 "stream-ssl: Make no-op reconfiguration cheap" caused
ovsdb-server to re-read its certificates and keys every 60 seconds just
in case they changed.  However, doing this causes OpenSSL to drop its
connections.  This commit solves the problem by making stream-ssl re-read
certificates and keys only if the files changed.

Bug #2535.
Reported-by: Ram Jothikumar <rjothikumar@nicira.com>
2010-03-24 16:52:07 -07:00