Skip to content

Commit 5b3f549

Browse files
Merge pull request #6430 from kareem-wolfssl/memcached
Add memcached support.
2 parents 7036c84 + e175410 commit 5b3f549

12 files changed

Lines changed: 228 additions & 71 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
uses: ./.github/workflows/krb5.yml
4141
packaging:
4242
uses: ./.github/workflows/packaging.yml
43+
memcached:
44+
uses: ./.github/workflows/memcached.yml
4345
# TODO: Currently this test fails. Enable it once it becomes passing.
4446
# haproxy:
4547
# uses: ./.github/workflows/haproxy.yml

.github/workflows/memcached.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: memcached Tests
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build_wolfssl:
8+
name: Build wolfSSL
9+
# Just to keep it the same as the testing target
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Build wolfSSL
13+
uses: wolfSSL/actions-build-autotools-project@v1
14+
with:
15+
path: wolfssl
16+
configure: --enable-memcached
17+
install: true
18+
19+
- name: Upload built lib
20+
uses: actions/upload-artifact@v3
21+
with:
22+
name: wolf-install-memcached
23+
path: build-dir
24+
retention-days: 1
25+
26+
memcached_check:
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
# List of releases to test
31+
include:
32+
- ref: 1.6.22
33+
name: ${{ matrix.ref }}
34+
runs-on: ubuntu-latest
35+
needs: build_wolfssl
36+
steps:
37+
- name: Download lib
38+
uses: actions/download-artifact@v3
39+
with:
40+
name: wolf-install-memcached
41+
path: build-dir
42+
43+
- name: Checkout OSP
44+
uses: actions/checkout@v3
45+
with:
46+
repository: wolfssl/osp
47+
path: osp
48+
49+
- name: Install dependencies
50+
run: |
51+
export DEBIAN_FRONTEND=noninteractive
52+
sudo apt-get update
53+
sudo apt-get install -y libevent-dev libevent-2.1-7 automake pkg-config make libio-socket-ssl-perl
54+
55+
- name: Checkout memcached
56+
uses: actions/checkout@v3
57+
with:
58+
repository: memcached/memcached
59+
ref: 1.6.22
60+
path: memcached
61+
62+
- name: Configure and build memcached
63+
run: |
64+
cd $GITHUB_WORKSPACE/memcached/
65+
patch -p1 < $GITHUB_WORKSPACE/osp/memcached/memcached_1.6.22.patch
66+
./autogen.sh
67+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
68+
PKG_CONFIG_PATH=$GITHUB_WORKSPACE/build-dir/lib/pkgconfig ./configure --enable-wolfssl
69+
make -j$(nproc)
70+
71+
- name: Confirm memcached built with wolfSSL
72+
working-directory: ./memcached
73+
run: |
74+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
75+
ldd memcached | grep wolfssl
76+
77+
- name: Run memcached tests
78+
working-directory: ./memcached
79+
run: |
80+
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build-dir/lib:$LD_LIBRARY_PATH
81+
make -j$(nproc) test_tls

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,7 @@ AC_ARG_ENABLE([mcast],
16011601
# strongSwan (--enable-strongswan)
16021602
# OpenLDAP (--enable-openldap)
16031603
# hitch (--enable-hitch)
1604+
# memcached (--enable-memcached)
16041605

16051606
# Bind DNS compatibility Build
16061607
AC_ARG_ENABLE([bind],
@@ -1811,6 +1812,13 @@ AC_ARG_ENABLE([hitch],
18111812
[ ENABLED_HITCH=no ]
18121813
)
18131814

1815+
# memcached support
1816+
AC_ARG_ENABLE([memcached],
1817+
[AS_HELP_STRING([--enable-memcached],[Enable memcached support (default: disabled)])],
1818+
[ ENABLED_MEMCACHED=$enableval ],
1819+
[ ENABLED_MEMCACHED=no ]
1820+
)
1821+
18141822
# OpenSSL Coexist
18151823
AC_ARG_ENABLE([opensslcoexist],
18161824
[AS_HELP_STRING([--enable-opensslcoexist],[Enable coexistence of wolfssl/openssl (default: disabled)])],
@@ -6391,6 +6399,12 @@ then
63916399
AM_CFLAGS="$AM_CFLAGS -DOPENSSL_COMPATIBLE_DEFAULTS -DWOLFSSL_CIPHER_INTERNALNAME"
63926400
fi
63936401

6402+
if test "$ENABLED_MEMCACHED" = "yes"
6403+
then
6404+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SESSION_ID_CTX"
6405+
AM_CFLAGS="$AM_CFLAGS -DHAVE_EXT_CACHE -DHAVE_MEMCACHED"
6406+
fi
6407+
63946408

63956409
if test "$ENABLED_NGINX" = "yes"|| test "x$ENABLED_HAPROXY" = "xyes" || test "x$ENABLED_LIGHTY" = "xyes"
63966410
then
@@ -9682,6 +9696,7 @@ echo " * chrony: $ENABLED_CHRONY"
96829696
echo " * strongSwan: $ENABLED_STRONGSWAN"
96839697
echo " * OpenLDAP: $ENABLED_OPENLDAP"
96849698
echo " * hitch: $ENABLED_HITCH"
9699+
echo " * memcached: $ENABLED_MEMCACHED"
96859700
echo " * ERROR_STRINGS: $ENABLED_ERROR_STRINGS"
96869701
echo " * DTLS: $ENABLED_DTLS"
96879702
echo " * DTLS v1.3: $ENABLED_DTLS13"

src/internal.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7321,10 +7321,12 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
73217321
ssl->alert_history.last_tx.code = -1;
73227322
ssl->alert_history.last_tx.level = -1;
73237323

7324-
#ifdef OPENSSL_EXTRA
7324+
#ifdef WOLFSSL_SESSION_ID_CTX
73257325
/* copy over application session context ID */
73267326
ssl->sessionCtxSz = ctx->sessionCtxSz;
73277327
XMEMCPY(ssl->sessionCtx, ctx->sessionCtx, ctx->sessionCtxSz);
7328+
#endif
7329+
#ifdef OPENSSL_EXTRA
73287330
ssl->cbioFlag = ctx->cbioFlag;
73297331

73307332
ssl->protoMsgCb = ctx->protoMsgCb;
@@ -10359,6 +10361,8 @@ void ShrinkInputBuffer(WOLFSSL* ssl, int forcedFree)
1035910361

1036010362
int SendBuffered(WOLFSSL* ssl)
1036110363
{
10364+
int retryLimit = WOLFSSL_MODE_AUTO_RETRY_ATTEMPTS;
10365+
1036210366
if (ssl->CBIOSend == NULL && !WOLFSSL_IS_QUIC(ssl)) {
1036310367
WOLFSSL_MSG("Your IO Send callback is null, please set");
1036410368
return SOCKET_ERROR_E;
@@ -10379,15 +10383,22 @@ int SendBuffered(WOLFSSL* ssl)
1037910383
#endif
1038010384

1038110385
while (ssl->buffers.outputBuffer.length > 0) {
10382-
int sent = ssl->CBIOSend(ssl,
10383-
(char*)ssl->buffers.outputBuffer.buffer +
10384-
ssl->buffers.outputBuffer.idx,
10385-
(int)ssl->buffers.outputBuffer.length,
10386-
ssl->IOCB_WriteCtx);
10386+
int sent = 0;
10387+
retry:
10388+
sent = ssl->CBIOSend(ssl,
10389+
(char*)ssl->buffers.outputBuffer.buffer +
10390+
ssl->buffers.outputBuffer.idx,
10391+
(int)ssl->buffers.outputBuffer.length,
10392+
ssl->IOCB_WriteCtx);
1038710393
if (sent < 0) {
1038810394
switch (sent) {
1038910395

1039010396
case WOLFSSL_CBIO_ERR_WANT_WRITE: /* would block */
10397+
if (retryLimit > 0 && ssl->ctx->autoRetry &&
10398+
!ssl->options.handShakeDone && !ssl->options.dtls) {
10399+
retryLimit--;
10400+
goto retry;
10401+
}
1039110402
return WANT_WRITE;
1039210403

1039310404
case WOLFSSL_CBIO_ERR_CONN_RST: /* connection reset */

0 commit comments

Comments
 (0)