Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
netlink: prepare for removal of genl_family_attrbuf in 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
zx2c4 committed Dec 5, 2019
1 parent 1a59e5f commit 5eb87fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/compat/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,24 @@ static inline void skb_mark_not_on_list(struct sk_buff *skb)
#define cpu_have_named_feature(name) (elf_hwcap & (HWCAP_ ## name))
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0)
#include <linux/stddef.h>
#ifndef offsetofend
#define offsetofend(TYPE, MEMBER) (offsetof(TYPE, MEMBER) + sizeof(((TYPE *)0)->MEMBER))
#endif
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
#define genl_dumpit_info(cb) ({ \
struct { struct nlattr **attrs; } *a = (void *)((u8 *)cb->args + offsetofend(struct dump_ctx, next_allowedip)); \
BUILD_BUG_ON(sizeof(cb->args) < offsetofend(struct dump_ctx, next_allowedip) + sizeof(*a)); \
a->attrs = genl_family_attrbuf(&genl_family); \
if (nlmsg_parse(cb->nlh, GENL_HDRLEN + genl_family.hdrsize, a->attrs, genl_family.maxattr, device_policy, NULL) < 0) \
memset(a->attrs, 0, (genl_family.maxattr + 1) * sizeof(struct nlattr *)); \
a; \
})
#endif

#if defined(ISUBUNTU1604)
#include <linux/siphash.h>
#ifndef _WG_LINUX_SIPHASH_H
Expand Down
10 changes: 2 additions & 8 deletions src/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ static int get_allowedips(struct sk_buff *skb, const u8 *ip, u8 cidr,
struct dump_ctx {
struct wg_device *wg;
struct wg_peer *next_peer;
struct allowedips_node *next_allowedip;
u64 allowedips_seq;
struct allowedips_node *next_allowedip;
};

#define DUMP_CTX(cb) ((struct dump_ctx *)(cb)->args)
Expand Down Expand Up @@ -196,15 +196,9 @@ get_peer(struct wg_peer *peer, struct sk_buff *skb, struct dump_ctx *ctx)

static int wg_get_device_start(struct netlink_callback *cb)
{
struct nlattr **attrs = genl_family_attrbuf(&genl_family);
struct wg_device *wg;
int ret;

ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + genl_family.hdrsize, attrs,
genl_family.maxattr, device_policy, NULL);
if (ret < 0)
return ret;
wg = lookup_interface(attrs, cb->skb);
wg = lookup_interface(genl_dumpit_info(cb)->attrs, cb->skb);
if (IS_ERR(wg))
return PTR_ERR(wg);
DUMP_CTX(cb)->wg = wg;
Expand Down

0 comments on commit 5eb87fb

Please sign in to comment.