Commit 289f3163 authored by Joanne Hugé's avatar Joanne Hugé

Compile extended ack reporting only for kernel >= 4.12

parent c6c00908
......@@ -39,6 +39,7 @@ THE SOFTWARE.
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/version.h>
#include <net/if_arp.h>
/* From <linux/if_bridge.h> */
......@@ -73,6 +74,12 @@ THE SOFTWARE.
memcpy(d, RTA_DATA(rta), 16); \
} while(0)
/* extended ACK reporting was introduced in Linux by commit
2d4bc93368f5a0ddb57c8c885cdad9c9b7a10ed5 first released as 4.12 */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
#define EXTENDED_ACK_REPORTING
#endif
int export_table = -1, import_tables[MAX_IMPORT_TABLES], import_table_count = 0;
struct sysctl_setting {
......@@ -319,10 +326,12 @@ netlink_socket(struct netlink *nl, uint32_t groups)
}
}
#ifdef EXTENDED_ACK_REPORTING
rc = setsockopt(nl->sock, SOL_NETLINK, NETLINK_EXT_ACK,
&one, sizeof(one));
if(rc < 0)
perror("Warning: couldn't enable netlink extended acks");
#endif
rc = bind(nl->sock, (struct sockaddr *)&nl->sockaddr, nl->socklen);
if(rc < 0)
......@@ -344,6 +353,7 @@ netlink_socket(struct netlink *nl, uint32_t groups)
}
}
#ifdef EXTENDED_ACK_REPORTING
#define NLA_OK(nla,len) ((len) >= (int)sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \
(nla)->nla_len <= (len))
......@@ -380,6 +390,7 @@ static int netlink_get_extack(struct nlmsghdr *nh, int len, int done)
return 0;
}
#endif
static int
netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
......@@ -467,13 +478,17 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
nh->nlmsg_pid, nl->sockaddr.nl_pid);
continue;
} else if(nh->nlmsg_type == NLMSG_DONE) {
#ifdef EXTENDED_ACK_REPORTING
netlink_get_extack(nh, len, 1);
#endif
kdebugf("(done)\n");
done = 1;
break;
} else if(nh->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nh);
#ifdef EXTENDED_ACK_REPORTING
netlink_get_extack(nh, len, 0);
#endif
if(err->error == 0) {
kdebugf("(ACK)\n");
return 0;
......
  • No, detect at run-time rather than at compile-time. There's already a kernel_older_than function that you can use to set a global flag.

  • Compilation fails on OBS for debian 9 because NETLINK_EXT_ACK for example is not defined so this is why I am detecting at compile-time.

  • You mean define the macros that don't exist ? There is NETLINK_EXT_ACK, NLMSGERR_ATTR_MSG and NLM_F_ACK_TLVS, so we could define these three and then detect kernel verison at run-time

  • Ok, this conditionally revert d5369ea2: can you mention this in the commit message ?

    I think you can simplify a little in 2 ways:

    #define EXTENDED_ACK_REPORTING (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0))
    ...
    #if EXTENDED_ACK_REPORTING
    ...

    and have an empty netlink_get_extack when < 4.2:

    static int netlink_get_extack(struct nlmsghdr *nh, int len, int done)
    {
    #if EXTENDED_ACK_REPORTING
    ...
    #endif
        return 0;
    }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment