aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-10-08 03:06:47 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-08 03:14:52 +0200
commit205dd46aae8dd53f2c196d6a5af2fdbafd6b2b19 (patch)
treef2e36e45a597c47718279de8d78461ef4b5f748f
parentqemu: kill after 20 minutes (diff)
downloadwireguard-monolithic-historical-205dd46aae8dd53f2c196d6a5af2fdbafd6b2b19.tar.xz
wireguard-monolithic-historical-205dd46aae8dd53f2c196d6a5af2fdbafd6b2b19.zip
netlink: do not stuff index into nla type
It's not used for anything, and LKML doesn't like the type being used as an index value. Suggested-by: Eugene Syromiatnikov <esyr@redhat.com>
-rw-r--r--contrib/examples/embeddable-wg-library/wireguard.c9
-rw-r--r--src/netlink.c29
-rw-r--r--src/tools/ipc.c9
-rw-r--r--src/uapi/wireguard.h12
4 files changed, 25 insertions, 34 deletions
diff --git a/contrib/examples/embeddable-wg-library/wireguard.c b/contrib/examples/embeddable-wg-library/wireguard.c
index 6d4ddd8..a32fd50 100644
--- a/contrib/examples/embeddable-wg-library/wireguard.c
+++ b/contrib/examples/embeddable-wg-library/wireguard.c
@@ -1074,7 +1074,6 @@ cleanup:
int wg_set_device(wg_device *dev)
{
int ret = 0;
- size_t i, j;
wg_peer *peer = NULL;
wg_allowedip *allowedip = NULL;
struct nlattr *peers_nest, *peer_nest, *allowedips_nest, *allowedip_nest;
@@ -1107,10 +1106,10 @@ again:
goto send;
peers_nest = peer_nest = allowedips_nest = allowedip_nest = NULL;
peers_nest = mnl_attr_nest_start(nlh, WGDEVICE_A_PEERS);
- for (i = 0, peer = peer ? peer : dev->first_peer; peer; peer = peer->next_peer) {
+ for (peer = peer ? peer : dev->first_peer; peer; peer = peer->next_peer) {
uint32_t flags = 0;
- peer_nest = mnl_attr_nest_start_check(nlh, MNL_SOCKET_BUFFER_SIZE, i++);
+ peer_nest = mnl_attr_nest_start_check(nlh, MNL_SOCKET_BUFFER_SIZE, 0);
if (!peer_nest)
goto toobig_peers;
if (!mnl_attr_put_check(nlh, MNL_SOCKET_BUFFER_SIZE, WGPEER_A_PUBLIC_KEY, sizeof(peer->public_key), peer->public_key))
@@ -1146,8 +1145,8 @@ again:
allowedips_nest = mnl_attr_nest_start_check(nlh, MNL_SOCKET_BUFFER_SIZE, WGPEER_A_ALLOWEDIPS);
if (!allowedips_nest)
goto toobig_allowedips;
- for (j = 0; allowedip; allowedip = allowedip->next_allowedip) {
- allowedip_nest = mnl_attr_nest_start_check(nlh, MNL_SOCKET_BUFFER_SIZE, j++);
+ for (; allowedip; allowedip = allowedip->next_allowedip) {
+ allowedip_nest = mnl_attr_nest_start_check(nlh, MNL_SOCKET_BUFFER_SIZE, 0);
if (!allowedip_nest)
goto toobig_allowedips;
if (!mnl_attr_put_u16_check(nlh, MNL_SOCKET_BUFFER_SIZE, WGALLOWEDIP_A_FAMILY, allowedip->family))
diff --git a/src/netlink.c b/src/netlink.c
index 17aa575..6e9af95 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -69,37 +69,31 @@ static struct wireguard_device *lookup_interface(struct nlattr **attrs,
return netdev_priv(dev);
}
-struct allowedips_ctx {
- struct sk_buff *skb;
- unsigned int i;
-};
-
static int get_allowedips(void *ctx, const u8 *ip, u8 cidr, int family)
{
- struct allowedips_ctx *actx = ctx;
+ struct sk_buff *skb = ctx;
struct nlattr *allowedip_nest;
- allowedip_nest = nla_nest_start(actx->skb, actx->i++);
+ allowedip_nest = nla_nest_start(skb, 0);
if (!allowedip_nest)
return -EMSGSIZE;
- if (nla_put_u8(actx->skb, WGALLOWEDIP_A_CIDR_MASK, cidr) ||
- nla_put_u16(actx->skb, WGALLOWEDIP_A_FAMILY, family) ||
- nla_put(actx->skb, WGALLOWEDIP_A_IPADDR, family == AF_INET6 ?
+ if (nla_put_u8(skb, WGALLOWEDIP_A_CIDR_MASK, cidr) ||
+ nla_put_u16(skb, WGALLOWEDIP_A_FAMILY, family) ||
+ nla_put(skb, WGALLOWEDIP_A_IPADDR, family == AF_INET6 ?
sizeof(struct in6_addr) : sizeof(struct in_addr), ip)) {
- nla_nest_cancel(actx->skb, allowedip_nest);
+ nla_nest_cancel(skb, allowedip_nest);
return -EMSGSIZE;
}
- nla_nest_end(actx->skb, allowedip_nest);
+ nla_nest_end(skb, allowedip_nest);
return 0;
}
-static int get_peer(struct wireguard_peer *peer, unsigned int index,
+static int get_peer(struct wireguard_peer *peer,
struct allowedips_cursor *rt_cursor, struct sk_buff *skb)
{
- struct nlattr *allowedips_nest, *peer_nest = nla_nest_start(skb, index);
- struct allowedips_ctx ctx = { .skb = skb };
+ struct nlattr *allowedips_nest, *peer_nest = nla_nest_start(skb, 0);
bool fail;
if (!peer_nest)
@@ -151,7 +145,7 @@ static int get_peer(struct wireguard_peer *peer, unsigned int index,
if (!allowedips_nest)
goto err;
if (wg_allowedips_walk_by_peer(&peer->device->peer_allowedips,
- rt_cursor, peer, get_allowedips, &ctx,
+ rt_cursor, peer, get_allowedips, skb,
&peer->device->device_update_lock)) {
nla_nest_end(skb, allowedips_nest);
nla_nest_end(skb, peer_nest);
@@ -195,7 +189,6 @@ static int wg_get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
struct wireguard_peer *peer, *next_peer_cursor, *last_peer_cursor;
struct allowedips_cursor *rt_cursor;
struct wireguard_device *wg;
- unsigned int peer_idx = 0;
struct nlattr *peers_nest;
int ret = -EMSGSIZE;
bool done = true;
@@ -256,7 +249,7 @@ static int wg_get_device_dump(struct sk_buff *skb, struct netlink_callback *cb)
lockdep_assert_held(&wg->device_update_lock);
peer = list_prepare_entry(last_peer_cursor, &wg->peer_list, peer_list);
list_for_each_entry_continue (peer, &wg->peer_list, peer_list) {
- if (get_peer(peer, peer_idx++, rt_cursor, skb)) {
+ if (get_peer(peer, rt_cursor, skb)) {
done = false;
break;
}
diff --git a/src/tools/ipc.c b/src/tools/ipc.c
index bc89f02..c64e332 100644
--- a/src/tools/ipc.c
+++ b/src/tools/ipc.c
@@ -547,7 +547,6 @@ cleanup:
static int kernel_set_device(struct wgdevice *dev)
{
int ret = 0;
- size_t i, j;
struct wgpeer *peer = NULL;
struct wgallowedip *allowedip = NULL;
struct nlattr *peers_nest, *peer_nest, *allowedips_nest, *allowedip_nest;
@@ -580,10 +579,10 @@ again:
goto send;
peers_nest = peer_nest = allowedips_nest = allowedip_nest = NULL;
peers_nest = mnl_attr_nest_start(nlh, WGDEVICE_A_PEERS);
- for (i = 0, peer = peer ? peer : dev->first_peer; peer; peer = peer->next_peer) {
+ for (peer = peer ? peer : dev->first_peer; peer; peer = peer->next_peer) {
uint32_t flags = 0;
- peer_nest = mnl_attr_nest_start_check(nlh, SOCKET_BUFFER_SIZE, i++);
+ peer_nest = mnl_attr_nest_start_check(nlh, SOCKET_BUFFER_SIZE, 0);
if (!peer_nest)
goto toobig_peers;
if (!mnl_attr_put_check(nlh, SOCKET_BUFFER_SIZE, WGPEER_A_PUBLIC_KEY, sizeof(peer->public_key), peer->public_key))
@@ -619,8 +618,8 @@ again:
allowedips_nest = mnl_attr_nest_start_check(nlh, SOCKET_BUFFER_SIZE, WGPEER_A_ALLOWEDIPS);
if (!allowedips_nest)
goto toobig_allowedips;
- for (j = 0; allowedip; allowedip = allowedip->next_allowedip) {
- allowedip_nest = mnl_attr_nest_start_check(nlh, SOCKET_BUFFER_SIZE, j++);
+ for (; allowedip; allowedip = allowedip->next_allowedip) {
+ allowedip_nest = mnl_attr_nest_start_check(nlh, SOCKET_BUFFER_SIZE, 0);
if (!allowedip_nest)
goto toobig_allowedips;
if (!mnl_attr_put_u16_check(nlh, SOCKET_BUFFER_SIZE, WGALLOWEDIP_A_FAMILY, allowedip->family))
diff --git a/src/uapi/wireguard.h b/src/uapi/wireguard.h
index ab72766..0203f2c 100644
--- a/src/uapi/wireguard.h
+++ b/src/uapi/wireguard.h
@@ -43,13 +43,13 @@
* WGALLOWEDIP_A_FAMILY: NLA_U16
* WGALLOWEDIP_A_IPADDR: struct in_addr or struct in6_addr
* WGALLOWEDIP_A_CIDR_MASK: NLA_U8
- * 1: NLA_NESTED
+ * 0: NLA_NESTED
* ...
- * 2: NLA_NESTED
+ * 0: NLA_NESTED
* ...
* ...
* WGPEER_A_PROTOCOL_VERSION: NLA_U32
- * 1: NLA_NESTED
+ * 0: NLA_NESTED
* ...
* ...
*
@@ -99,9 +99,9 @@
* WGALLOWEDIP_A_FAMILY: NLA_U16
* WGALLOWEDIP_A_IPADDR: struct in_addr or struct in6_addr
* WGALLOWEDIP_A_CIDR_MASK: NLA_U8
- * 1: NLA_NESTED
+ * 0: NLA_NESTED
* ...
- * 2: NLA_NESTED
+ * 0: NLA_NESTED
* ...
* ...
* WGPEER_A_PROTOCOL_VERSION: NLA_U32, should not be set or used at
@@ -109,7 +109,7 @@
* most recent protocol will be used when
* this is unset. Otherwise, must be set
* to 1.
- * 1: NLA_NESTED
+ * 0: NLA_NESTED
* ...
* ...
*