CESNET / libnetconf2

C NETCONF library
BSD 3-Clause "New" or "Revised" License
203 stars 147 forks source link

How to set the netconf server TCP parameter? #501

Closed rydy closed 3 months ago

rydy commented 3 months ago

Hi, I tried to modify the TCP keepalive of netconf server to configure the following parameters, but it did not work after configuration.

<keepalives>
    <idle-time>10</idle-time>
    <max-probes>2</max-probes>
    <probe-interval>3</probe-interval>
</keepalives>

Because the relevant macros(TCP_KEEPIDLE、TCP_KEEPINTVL、TCP_KEEPCNT) are not defined, The following code is not compiled.

int
nc_sock_configure_keepalive(int sock, struct nc_keepalives *ka)
{
    int opt;

    opt = ka->enabled;
    if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof opt) == -1) {
        ERR(NULL, "Could not set SO_KEEPALIVE option (%s).", strerror(errno));
        return -1;
    }
    if (!ka->enabled) {
        return 0;
    }

#ifdef TCP_KEEPIDLE
    opt = ka->idle_time;
    if (setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &opt, sizeof opt) == -1) {
        ERR(NULL, "Setsockopt failed (%s).", strerror(errno));
        return -1;
    }
#endif

#ifdef TCP_KEEPCNT
    opt = ka->max_probes;
    if (setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &opt, sizeof opt) == -1) {
        ERR(NULL, "Setsockopt failed (%s).", strerror(errno));
        return -1;
    }
#endif

#ifdef TCP_KEEPINTVL
    opt = ka->probe_interval;
    if (setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &opt, sizeof opt) == -1) {
        ERR(NULL, "Setsockopt failed (%s).", strerror(errno));
        return -1;
    }
#endif

I tried to change the code manually, but got an error: 'TCP_KEEPIDLE' is not declared.: 'TCP_KEEPIDLE' undeclared. how should I change it?

Thanks.

michalvasko commented 3 months ago

What version of libnetconf2 are you using? There was a problem with a missing include.

rydy commented 3 months ago

What version of libnetconf2 are you using? There was a problem with a missing include.

libnetconf2-3.0.17,I tried to add the following code to make it work. image

michalvasko commented 3 months ago

Just those 2 includes should be enough, fixed in libnetconf2 v3.0.19.

rydy commented 3 months ago

Just those 2 includes should be enough, fixed in libnetconf2 v3.0.19.

thanks.