Skip to content

Commit

Permalink
Latest changes
Browse files Browse the repository at this point in the history
- Add support for Mac OS
- Add support for Raspberry Pi
- Fix BoringSSL compilation: include <openssl/hmac.h> explicitly
  • Loading branch information
Dmitri Tikhonov committed Sep 26, 2017
1 parent 50aadb3 commit e019799
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 75 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
2017-09-26

- Add support for Mac OS
- Add support for Raspberry Pi
- Fix BoringSSL compilation: include <openssl/hmac.h> explicitly

2017-09-22

- Initial release
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ MESSAGE(STATUS "DEVEL_MODE: ${DEVEL_MODE}")
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wall -Wextra -Wno-unused-parameter")
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -fno-omit-frame-pointer")

IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.3)
SET(MY_CMAKE_FLAGS "${MY_CMAKE_FLAGS} -Wno-missing-field-initializers")
ENDIF()
IF(DEVEL_MODE EQUAL 1)
Expand Down Expand Up @@ -58,12 +58,15 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MY_CMAKE_FLAGS} $ENV{EXTRA_CFLAGS}")

MESSAGE(STATUS "Compiler flags: ${CMAKE_C_FLAGS}")

IF(NOT DEFINED BORINGSSL_INCLUDE)
include_directories( /usr/local/lib )
ENDIF()
IF(NOT DEFINED BORINGSSL_LIB)
link_directories( /usr/local/include )
ENDIF()

SET(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories( include )
include_directories( ${BORINGSSL_INCLUDE} )

link_directories( ${BORINGSSL_LIB} )

IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
# Find libevent on FreeBSD:
Expand All @@ -73,7 +76,7 @@ ENDIF()

add_executable(http_client test/http_client.c test/prog.c test/test_common.c test/test_cert.c)

target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a libdecrepit.a ${FIULIB} z m)
target_link_libraries(http_client lsquic event pthread libssl.a libcrypto.a ${FIULIB} z m)

add_subdirectory(src)

Expand Down
4 changes: 4 additions & 0 deletions EXAMPLES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Fetch Google's home page:

./http_client -H www.google.com -s 74.125.22.106:443 -p /

or even

./http_client -H www.google.co.uk -s 2a00:1450:4009:80c::2003:443 -p /

In the example above, -H specifies the domain; it is also used as the value
of SNI paramater in the handshake.

Expand Down
95 changes: 89 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,100 @@ Documentation

The documentation for this module is admittedly sparse. The API is
documented in include/lsquic.h. If you have doxygen, you can run
`doxygen dox.cfg' or `make docs'. The example program is
`doxygen dox.cfg` or `make docs`. The example program is
test/http_client.c: a bare-bones, but working, QUIC client. Have a look
in EXAMPLES.txt to see how it can be used.

Building
--------
Requirements
------------

To build LSQUIC, you need CMake and BoringSSL. The example program
uses libevent to provide the event loop. In short:
To build LSQUIC, you need CMake, zlib, and BoringSSL. The example program
uses libevent to provide the event loop.

cmake -DBORINGSSL_INCLUDE=/some/dir -DBORINGSSL_LIB=/some/other/dir .
Building BoringSSL
------------------

BoringSSL is not packaged; you have to build it yourself. The process is
straightforward. You will need `go` installed.

1. Clone BoringSSL by issuing the following command:

```
git clone https://boringssl.googlesource.com/boringssl
cd boringssl
```

2. Check out stable branch:

```
git co chromium-stable
```

3. Compile the library

```
cmake . && make
```

If you want to turn on optimizations, do

```
cmake -DCMAKE_BUILD_TYPE=Release . && make
```

4. Install the library

This is the manual step. You will need to copy library files manually.
LSQUIC client library needs two: `ssl/libssl.a` and `crypto/libcrypto.a`.
To install these in `/usr/local/lib`, you should do the following:

```
BORINGSSL_SOURCE=$PWD
cd /usr/local/lib
sudo cp $BORINGSSL_SOURCE/ssl/libssl.a
sudo cp $BORINGSSL_SOURCE/crypto/libcrypto.a
```

If you do not want to install the library (or do not have root), you
can do this instead:

```
BORINGSSL_SOURCE=$PWD
mkdir -p $HOME/tmp/boringssl-libs
cd $HOME/tmp/boringssl-libs
ln -s $BORINGSSL_SOURCE/ssl/libssl.a
ln -s $BORINGSSL_SOURCE/crypto/libcrypto.a
```

Building LSQUIC Client Library
------------------------------

LSQUIC's `http_client` and the tests link BoringSSL libraries statically.
Following previous section, you can build LSQUIC as follows:

```
cmake -DBORINGSSL_INCLUDE=$BORINGSSL_SOURCE/include \
-DBORINGSSL_LIB=$HOME/tmp/boringssl-libs .
make
```

Run tests:

```
make test
```

Platforms
---------

The client library has been tested on the following platforms:
- Linux
- x86_64
- ARM (Raspberry Pi 3)
- FreeBSD
- i386
- MacOS
- x86_64

Have fun,

Expand Down
1 change: 1 addition & 0 deletions src/liblsquic/lsquic_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <openssl/x509.h>
#include <openssl/rand.h>
#include <openssl/curve25519.h>
#include <openssl/hmac.h>

#include <zlib.h>

Expand Down
6 changes: 0 additions & 6 deletions src/liblsquic/lsquic_full_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1907,12 +1907,6 @@ process_stream_ready_to_send (struct full_conn *conn, lsquic_stream_t *stream,
{
if (LSQUIC_STREAM_HANDSHAKE == stream->id)
{
#if LSQUIC_STREAM_HANDSHAKE
/* Full connection implies that the server has completed the
* handshake:
*/
assert(0 == (conn->fc_flags & FC_SERVER));
#endif
/* Handshake messages are sent in brand-new packets. If handshake
* is not complete, the packet is zero-padded.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/liblsquic/lsquic_parse_gquic_be.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#define bswap_16 bswap16
#define bswap_32 bswap32
#define bswap_64 bswap64
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16 OSSwapInt16
#define bswap_32 OSSwapInt32
#define bswap_64 OSSwapInt64
#else
#include <byteswap.h>
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/liblsquic/lsquic_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ lsquic_stream_write_avail (const lsquic_stream_t *stream)
conn_avail = lsquic_conn_cap_avail(&stream->conn_pub->conn_cap);
if (conn_avail < stream_avail)
{
LSQ_DEBUG("stream %u write buffer is limited by connection: %jd",
stream->id, conn_avail);
LSQ_DEBUG("stream %u write buffer is limited by connection: "
"%"PRIu64, stream->id, conn_avail);
return conn_avail;
}
}

LSQ_DEBUG("stream %u write buffer is limited by stream: %jd",
LSQ_DEBUG("stream %u write buffer is limited by stream: %"PRIu64,
stream->id, stream_avail);
return stream_avail;
}
Expand Down
17 changes: 17 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE.

INCLUDE(CheckSymbolExists)

CHECK_SYMBOL_EXISTS(
IP_MTU_DISCOVER
"netinet/in.h"
HAVE_IP_MTU_DISCOVER
)

CHECK_SYMBOL_EXISTS(
IP_DONTFRAG
"netinet/in.h"
HAVE_IP_DONTFRAG
)


CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/test_config.h)


add_subdirectory(unittests)

Expand Down
5 changes: 5 additions & 0 deletions test/prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "../src/liblsquic/lsquic_hash.h"
#include "../src/liblsquic/lsquic_logger.h"

#include "test_config.h"
#include "test_cert.h"
#include "test_common.h"
#include "prog.h"
Expand Down Expand Up @@ -86,7 +87,9 @@ prog_print_common_options (const struct prog *prog, FILE *out)
" is used.\n"
" -i USEC Library will `tick' every USEC microseconds. The default\n"
" is %u\n"
#if LSQUIC_DONTFRAG_SUPPORTED
" -D Set `do not fragment' flag on outgoing UDP packets\n"
#endif
" -z BYTES Maximum size of outgoing UDP packets. The default is 1370\n"
" bytes for IPv4 socket and 1350 bytes for IPv6 socket\n"
" -L LEVEL Log level for all modules. Possible values are `debug',\n"
Expand Down Expand Up @@ -142,6 +145,7 @@ prog_set_opt (struct prog *prog, int opt, const char *arg)
case 'i':
prog->prog_period_usec = atoi(arg);
return 0;
#if LSQUIC_DONTFRAG_SUPPORTED
case 'D':
{
struct service_port *sport = TAILQ_LAST(prog->prog_sports, sport_head);
Expand All @@ -150,6 +154,7 @@ prog_set_opt (struct prog *prog, int opt, const char *arg)
sport->sp_flags |= SPORT_DONT_FRAGMENT;
}
return 0;
#endif
case 'm':
prog->prog_packout_max = atoi(arg);
return 0;
Expand Down
8 changes: 7 additions & 1 deletion test/prog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ prog_init (struct prog *, unsigned lsquic_engine_flags, struct sport_head *,
# define SENDMMSG_FLAG ""
#endif

#define PROG_OPTS "i:Dm:c:y:L:l:o:H:s:S:z:" SENDMMSG_FLAG
#if LSQUIC_DONTFRAG_SUPPORTED
# define IP_DONTFRAG_FLAG "D"
#else
# define IP_DONTFRAG_FLAG ""
#endif

#define PROG_OPTS "i:m:c:y:L:l:o:H:s:S:z:" SENDMMSG_FLAG IP_DONTFRAG_FLAG

/* Returns:
* 0 Applied
Expand Down
18 changes: 12 additions & 6 deletions test/test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(__APPLE__)
# define __APPLE_USE_RFC_3542 1
#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/queue.h>
Expand Down Expand Up @@ -447,8 +450,7 @@ sport_init_server (struct service_port *sport, struct lsquic_engine *engine,
return -1;
}

#if __linux__
#if !defined(IP_RECVORIGDSTADDR)
#if (__linux__ && !defined(IP_RECVORIGDSTADDR)) || __APPLE__
/* Need to set IP_PKTINFO for sending */
if (AF_INET == sa_local->sa_family)
{
Expand All @@ -462,7 +464,6 @@ sport_init_server (struct service_port *sport, struct lsquic_engine *engine,
return -1;
}
}
#endif
#elif IP_RECVDSTADDR != IP_SENDSRCADDR
/* On FreeBSD, IP_RECVDSTADDR is the same as IP_SENDSRCADDR, but I do not
* know about other BSD systems.
Expand Down Expand Up @@ -505,6 +506,7 @@ sport_init_server (struct service_port *sport, struct lsquic_engine *engine,
}
#endif

#if LSQUIC_DONTFRAG_SUPPORTED
if (sport->sp_flags & SPORT_DONT_FRAGMENT)
{
if (AF_INET == sa_local->sa_family)
Expand All @@ -526,6 +528,7 @@ sport_init_server (struct service_port *sport, struct lsquic_engine *engine,
}
}
}
#endif

if (sport->sp_flags & SPORT_SET_SNDBUF)
{
Expand Down Expand Up @@ -592,7 +595,7 @@ sport_init_client (struct service_port *sport, struct lsquic_engine *engine,
struct event_base *eb)
{
const struct sockaddr *sa_peer = (struct sockaddr *) &sport->sas;
int sockfd, saved_errno, flags, on, s;
int sockfd, saved_errno, flags, s;
socklen_t socklen;
union {
struct sockaddr_in sin;
Expand Down Expand Up @@ -646,10 +649,12 @@ sport_init_client (struct service_port *sport, struct lsquic_engine *engine,
return -1;
}

#if LSQUIC_DONTFRAG_SUPPORTED
if (sport->sp_flags & SPORT_DONT_FRAGMENT)
{
if (AF_INET == sa_local->sa_family)
{
int on;
#if __linux__
on = IP_PMTUDISC_DO;
s = setsockopt(sockfd, IPPROTO_IP, IP_MTU_DISCOVER, &on,
Expand All @@ -667,6 +672,7 @@ sport_init_client (struct service_port *sport, struct lsquic_engine *engine,
}
}
}
#endif

if (sport->sp_flags & SPORT_SET_SNDBUF)
{
Expand Down Expand Up @@ -733,7 +739,7 @@ setup_control_msg (struct msghdr *msg, const struct lsquic_out_spec *spec,
struct cmsghdr *cmsg;
struct sockaddr_in *local_sa;
struct sockaddr_in6 *local_sa6;
#if __linux__
#if __linux__ || __APPLE__
struct in_pktinfo info;
#endif
struct in6_pktinfo info6;
Expand All @@ -745,7 +751,7 @@ setup_control_msg (struct msghdr *msg, const struct lsquic_out_spec *spec,
if (AF_INET == spec->dest_sa->sa_family)
{
local_sa = (struct sockaddr_in *) spec->local_sa;
#if __linux__
#if __linux__ || __APPLE__
memset(&info, 0, sizeof(info));
info.ipi_spec_dst = local_sa->sin_addr;
cmsg->cmsg_level = IPPROTO_IP;
Expand Down
2 changes: 2 additions & 0 deletions test/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ struct prog;

enum sport_flags
{
#if LSQUIC_DONTFRAG_SUPPORTED
SPORT_DONT_FRAGMENT = (1 << 0),
#endif
SPORT_SET_SNDBUF = (1 << 1), /* SO_SNDBUF */
SPORT_SET_RCVBUF = (1 << 2), /* SO_RCVBUF */
SPORT_SERVER = (1 << 3),
Expand Down
9 changes: 9 additions & 0 deletions test/test_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef LSQUIC_CONFIG_H
#define LSQUIC_CONFIG_H

#cmakedefine HAVE_IP_DONTFRAG 1
#cmakedefine HAVE_IP_MTU_DISCOVER 1

#define LSQUIC_DONTFRAG_SUPPORTED (HAVE_IP_DONTFRAG || HAVE_IP_MTU_DISCOVER)

#endif
Loading

0 comments on commit e019799

Please sign in to comment.