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. ...@@ -39,6 +39,7 @@ THE SOFTWARE.
#include <sys/socket.h> #include <sys/socket.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include <linux/version.h>
#include <net/if_arp.h> #include <net/if_arp.h>
/* From <linux/if_bridge.h> */ /* From <linux/if_bridge.h> */
...@@ -73,6 +74,12 @@ THE SOFTWARE. ...@@ -73,6 +74,12 @@ THE SOFTWARE.
memcpy(d, RTA_DATA(rta), 16); \ memcpy(d, RTA_DATA(rta), 16); \
} while(0) } 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; int export_table = -1, import_tables[MAX_IMPORT_TABLES], import_table_count = 0;
struct sysctl_setting { struct sysctl_setting {
...@@ -319,10 +326,12 @@ netlink_socket(struct netlink *nl, uint32_t groups) ...@@ -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, rc = setsockopt(nl->sock, SOL_NETLINK, NETLINK_EXT_ACK,
&one, sizeof(one)); &one, sizeof(one));
if(rc < 0) if(rc < 0)
perror("Warning: couldn't enable netlink extended acks"); perror("Warning: couldn't enable netlink extended acks");
#endif
rc = bind(nl->sock, (struct sockaddr *)&nl->sockaddr, nl->socklen); rc = bind(nl->sock, (struct sockaddr *)&nl->sockaddr, nl->socklen);
if(rc < 0) if(rc < 0)
...@@ -344,6 +353,7 @@ netlink_socket(struct netlink *nl, uint32_t groups) ...@@ -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) && \ #define NLA_OK(nla,len) ((len) >= (int)sizeof(struct nlattr) && \
(nla)->nla_len >= sizeof(struct nlattr) && \ (nla)->nla_len >= sizeof(struct nlattr) && \
(nla)->nla_len <= (len)) (nla)->nla_len <= (len))
...@@ -380,6 +390,7 @@ static int netlink_get_extack(struct nlmsghdr *nh, int len, int done) ...@@ -380,6 +390,7 @@ static int netlink_get_extack(struct nlmsghdr *nh, int len, int done)
return 0; return 0;
} }
#endif
static int static int
netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer, 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, ...@@ -467,13 +478,17 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
nh->nlmsg_pid, nl->sockaddr.nl_pid); nh->nlmsg_pid, nl->sockaddr.nl_pid);
continue; continue;
} else if(nh->nlmsg_type == NLMSG_DONE) { } else if(nh->nlmsg_type == NLMSG_DONE) {
#ifdef EXTENDED_ACK_REPORTING
netlink_get_extack(nh, len, 1); netlink_get_extack(nh, len, 1);
#endif
kdebugf("(done)\n"); kdebugf("(done)\n");
done = 1; done = 1;
break; break;
} else if(nh->nlmsg_type == NLMSG_ERROR) { } else if(nh->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nh); struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nh);
#ifdef EXTENDED_ACK_REPORTING
netlink_get_extack(nh, len, 0); netlink_get_extack(nh, len, 0);
#endif
if(err->error == 0) { if(err->error == 0) {
kdebugf("(ACK)\n"); kdebugf("(ACK)\n");
return 0; 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