varnish / varnish-modules

Collection of Varnish Cache modules (vmods) by Varnish Software
Other
182 stars 86 forks source link

tcpinfo issue on docker alpine linux 3.4 #45

Closed brunorossi closed 7 years ago

brunorossi commented 7 years ago

When i try to use the following docker file using a clone of your master branch and I build it with "docker build .":

FROM alpine:3.4
MAINTAINER Bruno Rossi <brunorossiweb@gmail.com>

ENV VARNISH_CACHE_SIZE=128m \
    BACKEND_PORT=80

WORKDIR /opt

COPY varnish.vcl start ./

RUN apk update && \
    apk add git && \
    apk add build-base && \
    apk add automake && \
    apk add autoconf && \
    apk add libtool && \
    apk add python && \
    apk add py-docutils && \
    apk add varnish && \
    apk add varnish-libs && \
    apk add varnish-dev && \
    apk add varnish-geoip 

COPY varnish-modules varnish-modules    

WORKDIR /opt/varnish-modules

RUN chmod +x bootstrap && \
    ./bootstrap && \   
    ./configure && \
    make && \ 
    make install 

WORKDIR /opt

RUN chmod +x start

EXPOSE 80   

CMD ./start

I have the following output

vmod_tcp.c: In function 'vmod_dump_info':
vmod_tcp.c:64:18: error: storage size of 'tcpinfo' isn't known
  struct tcp_info tcpinfo;
                  ^
vmod_tcp.c:65:26: error: invalid application of 'sizeof' to incomplete type 'struct tcp_info'
  socklen_t tlen = sizeof(struct tcp_info);
                          ^
vmod_tcp.c:64:18: error: unused variable 'tcpinfo' [-Werror=unused-variable]
  struct tcp_info tcpinfo;
                  ^
vmod_tcp.c: In function 'vmod_get_estimated_rtt':
vmod_tcp.c:99:18: error: storage size of 'tcpinfo' isn't known
  struct tcp_info tcpinfo;
                  ^
vmod_tcp.c:100:26: error: invalid application of 'sizeof' to incomplete type 'struct tcp_info'
  socklen_t tlen = sizeof(struct tcp_info);
                          ^
vmod_tcp.c:99:18: error: unused variable 'tcpinfo' [-Werror=unused-variable]
  struct tcp_info tcpinfo;
                  ^
vmod_tcp.c:110:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1: all warnings being treated as errors
make[2]: *** [vmod_tcp.lo] Error 1
Makefile:578: recipe for target 'vmod_tcp.lo' failed
make[2]: Leaving directory '/opt/varnish-modules/src'
Makefile:484: recipe for target 'all-recursive' failed
make[1]: Leaving directory '/opt/varnish-modules'
Makefile:395: recipe for target 'all' failed
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

to solve the problem i strip out code into the following functions of the file /src/vmod_tcp.c

void vmod_dump_info(const struct vrt_ctx *ctx) {

    CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
    if (ctx->req == NULL) {
        return;
    }
    CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
    CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);
    AN(ctx->req->sp->fd);

    /* 
    struct tcp_info tcpinfo;
    socklen_t tlen = sizeof(struct tcp_info);
    if (getsockopt(ctx->req->sp->fd, SOL_TCP, TCP_INFO,
        (void*)&tcpinfo, &tlen) < 0) {
        VSLb(ctx->vsl, SLT_VCL_Error, "getsockopt() failed");
        return;
    }

    VSLb(ctx->vsl, SLT_VCL_Log,
        "tcpi: snd_mss=%i rcv_mss=%i lost=%i retrans=%i",
        tcpinfo.tcpi_snd_mss, tcpinfo.tcpi_rcv_mss,
        tcpinfo.tcpi_lost, tcpinfo.tcpi_retrans);

    VSLb(ctx->vsl, SLT_VCL_Log,
        "tcpi2: pmtu=%i rtt=%i rttvar=%i snd_cwnd=%i advmss=%i reordering=%i",
        tcpinfo.tcpi_pmtu, tcpinfo.tcpi_rtt, tcpinfo.tcpi_rttvar,
        tcpinfo.tcpi_snd_cwnd, tcpinfo.tcpi_advmss, tcpinfo.tcpi_reordering);
    */

    return;
}
VCL_REAL vmod_get_estimated_rtt(const struct vrt_ctx *ctx) {
    CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
    if (ctx->req == NULL) {
        return(0.0);
    }

    CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
    CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);
    AN(ctx->req->sp->fd);

    /*
    struct tcp_info tcpinfo;
    socklen_t tlen = sizeof(struct tcp_info);
    if (getsockopt(ctx->req->sp->fd, SOL_TCP, TCP_INFO,
        (void*)&tcpinfo, &tlen) < 0) {
        VSLb(ctx->vsl, SLT_VCL_Error, "getsockopt() failed");
        return(0.0);
    }
    */

    return(0.0);
}
dridi commented 7 years ago

I can take this one, I have another ongoing change involving vmod-tcp.

lkarsten commented 7 years ago

Most likely this is that Alpine doesn't have TCP_INFO in its reduced libc.

I was planning to remove the functionality in a future major bump of varnish-modules, as I don't think anyone is using it. I do believe that building out of the box on Alpine is something we should try to get fixed.

ddeboer commented 7 years ago

By ‘the functionality’ do you mean vmod_tcp? If so, I can open a PR where that module was removed (by which I could successfully build the other modules on Alpine).

lkarsten commented 7 years ago

@ddeboer "the functionality" was the stats logging function in vmod-tcp. It doesn't really do much good.

As I'm not working on this any more, someone else should answer your question about a pull request.