commit: 16e4b11f358512e8c7c7d2e67d0a0853c18f8966
parent f45e57f9bd216739fb3c425a1aefbca4386c0a52
Author: Michael Forney <mforney@mforney.org>
Date: Sat, 10 Aug 2019 22:20:27 -0700
libnl: Fix some portability issues
Diffstat:
10 files changed, 487 insertions(+), 1 deletion(-)
diff --git a/pkg/libnl/patch/0002-Avoid-pointer-arithmetic-on-void.patch b/pkg/libnl/patch/0002-Avoid-pointer-arithmetic-on-void.patch
@@ -0,0 +1,139 @@
+From 02a03be66ad59503e43be9d7915ae18161007e6f Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 04:49:07 +0000
+Subject: [PATCH] Avoid pointer arithmetic on `void *`
+
+ISO C requires that the pointer operand to the binary + operator be to
+a complete object type[0].
+
+[0] http://port70.net/~nsz/c/c11/n1570.html#6.5.6p2
+---
+ lib/attr.c | 8 ++++----
+ lib/data.c | 2 +-
+ lib/genl/genl.c | 4 ++--
+ lib/msg.c | 6 +++---
+ lib/object.c | 2 +-
+ 5 files changed, 11 insertions(+), 11 deletions(-)
+
+diff --git a/lib/attr.c b/lib/attr.c
+index 0dca3ec..7c0ac4d 100644
+--- a/lib/attr.c
++++ b/lib/attr.c
+@@ -477,7 +477,7 @@ struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
+ NL_DBG(2, "msg %p: attr <%p> %d: Reserved %d (%d) bytes at offset +%td "
+ "nlmsg_len=%d\n", msg, nla, nla->nla_type,
+ nla_total_size(attrlen), attrlen,
+- (void *) nla - nlmsg_data(msg->nm_nlh),
++ (char *) nla - (char *) nlmsg_data(msg->nm_nlh),
+ msg->nm_nlh->nlmsg_len);
+
+ return nla;
+@@ -513,7 +513,7 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
+ memcpy(nla_data(nla), data, datalen);
+ NL_DBG(2, "msg %p: attr <%p> %d: Wrote %d bytes at offset +%td\n",
+ msg, nla, nla->nla_type, datalen,
+- (void *) nla - nlmsg_data(msg->nm_nlh));
++ (char *) nla - (char *) nlmsg_data(msg->nm_nlh));
+ }
+
+ return 0;
+@@ -925,7 +925,7 @@ int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
+ {
+ size_t pad, len;
+
+- len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) start;
++ len = (char *) nlmsg_tail(msg->nm_nlh) - (char *) start;
+
+ if (len == NLA_HDRLEN || len > USHRT_MAX) {
+ /*
+@@ -974,7 +974,7 @@ void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr)
+ {
+ ssize_t len;
+
+- len = (void *) nlmsg_tail(msg->nm_nlh) - (void *) attr;
++ len = (char *) nlmsg_tail(msg->nm_nlh) - (char *) attr;
+ if (len < 0)
+ BUG();
+ else if (len > 0) {
+diff --git a/lib/data.c b/lib/data.c
+index 83ecd03..0123170 100644
+--- a/lib/data.c
++++ b/lib/data.c
+@@ -111,7 +111,7 @@ struct nl_data *nl_data_clone(const struct nl_data *src)
+ int nl_data_append(struct nl_data *data, const void *buf, size_t size)
+ {
+ if (size > 0) {
+- void *d_data = realloc(data->d_data, data->d_size + size);
++ char *d_data = realloc(data->d_data, data->d_size + size);
+ if (!d_data)
+ return -NLE_NOMEM;
+
+diff --git a/lib/genl/genl.c b/lib/genl/genl.c
+index a663ad8..30e8c8b 100644
+--- a/lib/genl/genl.c
++++ b/lib/genl/genl.c
+@@ -259,7 +259,7 @@ void *genlmsg_user_hdr(const struct genlmsghdr *gnlh)
+ */
+ void *genlmsg_user_data(const struct genlmsghdr *gnlh, const int hdrlen)
+ {
+- return genlmsg_user_hdr(gnlh) + NLMSG_ALIGN(hdrlen);
++ return (char *) genlmsg_user_hdr(gnlh) + NLMSG_ALIGN(hdrlen);
+ }
+
+ /**
+@@ -363,7 +363,7 @@ void *genlmsg_put(struct nl_msg *msg, uint32_t port, uint32_t seq, int family,
+ NL_DBG(2, "msg %p: Added generic netlink header cmd=%d version=%d\n",
+ msg, cmd, version);
+
+- return nlmsg_data(nlh) + GENL_HDRLEN;
++ return (char *) nlmsg_data(nlh) + GENL_HDRLEN;
+ }
+
+ /** @} */
+diff --git a/lib/msg.c b/lib/msg.c
+index 3e27d4e..0ce5887 100644
+--- a/lib/msg.c
++++ b/lib/msg.c
+@@ -407,7 +407,7 @@ struct nl_msg *nlmsg_convert(struct nlmsghdr *hdr)
+ */
+ void *nlmsg_reserve(struct nl_msg *n, size_t len, int pad)
+ {
+- void *buf = n->nm_nlh;
++ char *buf = (char *) n->nm_nlh;
+ size_t nlmsg_len = n->nm_nlh->nlmsg_len;
+ size_t tlen;
+
+@@ -835,7 +835,7 @@ static void print_genl_hdr(FILE *ofd, void *start)
+ static void *print_genl_msg(struct nl_msg *msg, FILE *ofd, struct nlmsghdr *hdr,
+ struct nl_cache_ops *ops, int *payloadlen)
+ {
+- void *data = nlmsg_data(hdr);
++ char *data = nlmsg_data(hdr);
+
+ if (*payloadlen < GENL_HDRLEN)
+ return data;
+@@ -898,7 +898,7 @@ static void dump_attrs(FILE *ofd, struct nlattr *attrs, int attrlen,
+ prefix_line(ofd, prefix);
+ fprintf(ofd, " [PADDING] %d octets\n",
+ padlen);
+- dump_hex(ofd, nla_data(nla) + alen,
++ dump_hex(ofd, (char *) nla_data(nla) + alen,
+ padlen, prefix);
+ }
+ }
+diff --git a/lib/object.c b/lib/object.c
+index 64e3b07..aeb4307 100644
+--- a/lib/object.c
++++ b/lib/object.c
+@@ -131,7 +131,7 @@ struct nl_object *nl_object_clone(struct nl_object *obj)
+ new->ce_mask = obj->ce_mask;
+
+ if (size)
+- memcpy((void *)new + doff, (void *)obj + doff, size);
++ memcpy((char *)new + doff, (char *)obj + doff, size);
+
+ if (ops->oo_clone) {
+ if (ops->oo_clone(new, obj) < 0) {
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0003-Don-t-return-expression-in-function-returning-void.patch b/pkg/libnl/patch/0003-Don-t-return-expression-in-function-returning-void.patch
@@ -0,0 +1,39 @@
+From befefcc3c3fef5d7d15713ae9dfb82108c331d56 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 04:50:32 +0000
+Subject: [PATCH] Don't return expression in function returning void
+
+---
+ lib/cache.c | 2 +-
+ lib/object.c | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/lib/cache.c b/lib/cache.c
+index 427f5df..badf91c 100644
+--- a/lib/cache.c
++++ b/lib/cache.c
+@@ -421,7 +421,7 @@ void nl_cache_free(struct nl_cache *cache)
+
+ void nl_cache_put(struct nl_cache *cache)
+ {
+- return nl_cache_free(cache);
++ nl_cache_free(cache);
+ }
+
+ /** @} */
+diff --git a/lib/object.c b/lib/object.c
+index aeb4307..f0c73da 100644
+--- a/lib/object.c
++++ b/lib/object.c
+@@ -300,7 +300,7 @@ void nl_object_dump_buf(struct nl_object *obj, char *buf, size_t len)
+ .dp_buflen = len,
+ };
+
+- return nl_object_dump(obj, &dp);
++ nl_object_dump(obj, &dp);
+ }
+
+ /**
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0004-Don-t-omit-second-operand-to-operator.patch b/pkg/libnl/patch/0004-Don-t-omit-second-operand-to-operator.patch
@@ -0,0 +1,25 @@
+From aea1d02c2700adec3a5c67cfa2d74bb812d95725 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 04:57:33 +0000
+Subject: [PATCH] Don't omit second operand to `?` operator
+
+---
+ lib/nl.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lib/nl.c b/lib/nl.c
+index 1b4355b..9065389 100644
+--- a/lib/nl.c
++++ b/lib/nl.c
+@@ -681,7 +681,7 @@ int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
+ if (page_size == 0)
+ page_size = getpagesize() * 4;
+
+- iov.iov_len = sk->s_bufsize ? : page_size;
++ iov.iov_len = sk->s_bufsize ? sk->s_bufsize : page_size;
+ iov.iov_base = malloc(iov.iov_len);
+
+ if (!iov.iov_base) {
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0005-Use-static-inline-functions-for-min-and-max.patch b/pkg/libnl/patch/0005-Use-static-inline-functions-for-min-and-max.patch
@@ -0,0 +1,123 @@
+From e9dc83c59917fc86d3bd684a6b1d31e1619bc07e Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 05:05:09 +0000
+Subject: [PATCH] Use static inline functions for min and max
+
+These generic macros were only ever used with type `int`, and making
+them inline functions avoids the use of non-standard statement
+expressions.
+---
+ include/netlink-private/netlink.h | 27 +++++++++++----------------
+ lib/attr.c | 2 +-
+ lib/msg.c | 2 +-
+ lib/route/cls/ematch_syntax.y | 2 +-
+ lib/route/link/inet.c | 2 +-
+ lib/route/link/inet6.c | 2 +-
+ 6 files changed, 16 insertions(+), 21 deletions(-)
+
+diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
+index 728ca5c..d9a3597 100644
+--- a/include/netlink-private/netlink.h
++++ b/include/netlink-private/netlink.h
+@@ -159,22 +159,17 @@ static inline int nl_cb_call(struct nl_cb *cb, enum nl_cb_type type, struct nl_m
+ #undef __deprecated
+ #define __deprecated __attribute__ ((deprecated))
+
+-#define min(x,y) ({ \
+- typeof(x) _x = (x); \
+- typeof(y) _y = (y); \
+- (void) (&_x == &_y); \
+- _x < _y ? _x : _y; })
+-
+-#define max(x,y) ({ \
+- typeof(x) _x = (x); \
+- typeof(y) _y = (y); \
+- (void) (&_x == &_y); \
+- _x > _y ? _x : _y; })
+-
+-#define min_t(type,x,y) \
+- ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+-#define max_t(type,x,y) \
+- ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
++static inline int
++min(int x, int y)
++{
++ return x < y ? x : y;
++}
++
++static inline int
++max(int x, int y)
++{
++ return x > y ? x : y;
++}
+
+ extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
+ struct nlmsghdr *, struct nl_parser_param *);
+diff --git a/lib/attr.c b/lib/attr.c
+index 7c0ac4d..9382b7f 100644
+--- a/lib/attr.c
++++ b/lib/attr.c
+@@ -357,7 +357,7 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
+ if (!src)
+ return 0;
+
+- minlen = min_t(int, count, nla_len(src));
++ minlen = min(count, nla_len(src));
+ memcpy(dest, nla_data(src), minlen);
+
+ return minlen;
+diff --git a/lib/msg.c b/lib/msg.c
+index 0ce5887..226a1d2 100644
+--- a/lib/msg.c
++++ b/lib/msg.c
+@@ -154,7 +154,7 @@ struct nlattr *nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
+ */
+ int nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
+ {
+- return max_t(int, nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
++ return max(nlmsg_len(nlh) - NLMSG_ALIGN(hdrlen), 0);
+ }
+
+ /** @} */
+diff --git a/lib/route/cls/ematch_syntax.y b/lib/route/cls/ematch_syntax.y
+index a0ca4bb..d730511 100644
+--- a/lib/route/cls/ematch_syntax.y
++++ b/lib/route/cls/ematch_syntax.y
+@@ -411,7 +411,7 @@ pattern:
+ if (nl_addr_parse($1, AF_UNSPEC, &addr) == 0) {
+ $$.len = nl_addr_get_len(addr);
+
+- $$.index = min_t(int, $$.len, nl_addr_get_prefixlen(addr)/8);
++ $$.index = min($$.len, nl_addr_get_prefixlen(addr)/8);
+
+ if (!($$.data = calloc(1, $$.len))) {
+ nl_addr_put(addr);
+diff --git a/lib/route/link/inet.c b/lib/route/link/inet.c
+index 6651bc3..e33a3fe 100644
+--- a/lib/route/link/inet.c
++++ b/lib/route/link/inet.c
+@@ -110,7 +110,7 @@ static int inet_parse_af(struct rtnl_link *link, struct nlattr *attr, void *data
+
+ if (tb[IFLA_INET_CONF]) {
+ int i;
+- int len = min_t(int, IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
++ int len = min(IPV4_DEVCONF_MAX, nla_len(tb[IFLA_INET_CONF]) / 4);
+
+ for (i = 0; i < len; i++)
+ id->i_confset[i] = 1;
+diff --git a/lib/route/link/inet6.c b/lib/route/link/inet6.c
+index e638d06..8f403ce 100644
+--- a/lib/route/link/inet6.c
++++ b/lib/route/link/inet6.c
+@@ -197,7 +197,7 @@ static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
+ map_stat_id = map_stat_id_from_IPSTATS_MIB_v1;
+ }
+
+- len = min_t(int, __IPSTATS_MIB_MAX, len);
++ len = min(__IPSTATS_MIB_MAX, len);
+ for (i = 1; i < len; i++) {
+ memcpy(&stat, &cnt[i * sizeof(stat)], sizeof(stat));
+ rtnl_link_set_stat(link, map_stat_id[i], stat);
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0006-Avoid-statement-expression-in-nl_container_of.patch b/pkg/libnl/patch/0006-Avoid-statement-expression-in-nl_container_of.patch
@@ -0,0 +1,28 @@
+From caff6ac158a66ecf0688ee00a58e30e67971125c Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 05:14:48 +0000
+Subject: [PATCH] Avoid statement expression in nl_container_of
+
+---
+ include/netlink/list.h | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/include/netlink/list.h b/include/netlink/list.h
+index fcfb826..a5ce74f 100644
+--- a/include/netlink/list.h
++++ b/include/netlink/list.h
+@@ -59,9 +59,8 @@ static inline int nl_list_empty(struct nl_list_head *head)
+ return head->next == head;
+ }
+
+-#define nl_container_of(ptr, type, member) ({ \
+- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+- (type *)( (char *)__mptr - (offsetof(type, member)));})
++#define nl_container_of(ptr, type, member) ( \
++ (type *)( (char *)(ptr) - (offsetof(type, member))))
+
+ #define nl_list_entry(ptr, type, member) \
+ nl_container_of(ptr, type, member)
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0007-Use-__typeof__-instead-of-typeof.patch b/pkg/libnl/patch/0007-Use-__typeof__-instead-of-typeof.patch
@@ -0,0 +1,37 @@
+From 334b5121a678ef1ec200c5b83855b46f6d238756 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 05:15:37 +0000
+Subject: [PATCH] Use __typeof__ instead of typeof
+
+---
+ include/netlink/list.h | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/include/netlink/list.h b/include/netlink/list.h
+index a5ce74f..f116126 100644
+--- a/include/netlink/list.h
++++ b/include/netlink/list.h
+@@ -78,15 +78,15 @@ static inline int nl_list_empty(struct nl_list_head *head)
+ nl_list_entry((head)->next, type, member)
+
+ #define nl_list_for_each_entry(pos, head, member) \
+- for (pos = nl_list_entry((head)->next, typeof(*pos), member); \
++ for (pos = nl_list_entry((head)->next, __typeof__(*pos), member); \
+ &(pos)->member != (head); \
+- (pos) = nl_list_entry((pos)->member.next, typeof(*(pos)), member))
++ (pos) = nl_list_entry((pos)->member.next, __typeof__(*(pos)), member))
+
+ #define nl_list_for_each_entry_safe(pos, n, head, member) \
+- for (pos = nl_list_entry((head)->next, typeof(*pos), member), \
+- n = nl_list_entry(pos->member.next, typeof(*pos), member); \
++ for (pos = nl_list_entry((head)->next, __typeof__(*pos), member), \
++ n = nl_list_entry(pos->member.next, __typeof__(*pos), member); \
+ &(pos)->member != (head); \
+- pos = n, n = nl_list_entry(n->member.next, typeof(*n), member))
++ pos = n, n = nl_list_entry(n->member.next, __typeof__(*n), member))
+
+ #define nl_init_list_head(head) \
+ do { (head)->next = (head); (head)->prev = (head); } while (0)
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0008-Avoid-initialization-of-flexible-array-member.patch b/pkg/libnl/patch/0008-Avoid-initialization-of-flexible-array-member.patch
@@ -0,0 +1,39 @@
+From 90733be9145ba1d977ec23f21eae45b062dc8bcf Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 21:55:54 +0000
+Subject: [PATCH] Avoid initialization of flexible array member
+
+---
+ include/netlink-private/cache-api.h | 2 +-
+ include/netlink-private/netlink.h | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/include/netlink-private/cache-api.h b/include/netlink-private/cache-api.h
+index c684e79..82be310 100644
+--- a/include/netlink-private/cache-api.h
++++ b/include/netlink-private/cache-api.h
+@@ -259,7 +259,7 @@ struct nl_cache_ops
+ struct genl_ops * co_genl;
+
+ /* Message type definition */
+- struct nl_msgtype co_msgtypes[];
++ struct nl_msgtype *co_msgtypes;
+ };
+
+ /** @} */
+diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
+index d9a3597..531940f 100644
+--- a/include/netlink-private/netlink.h
++++ b/include/netlink-private/netlink.h
+@@ -201,7 +201,7 @@ static inline const char *nl_cache_name(struct nl_cache *cache)
+ }
+
+ #define GENL_FAMILY(id, name) \
+- { \
++ (struct nl_msgtype[]){ \
+ { id, NL_ACT_UNSPEC, name }, \
+ END_OF_MSGTYPES_LIST, \
+ }
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0009-Avoid-statement-expression-in-ATTR_DIFF-macro.patch b/pkg/libnl/patch/0009-Avoid-statement-expression-in-ATTR_DIFF-macro.patch
@@ -0,0 +1,28 @@
+From 84eb9f312cc183e98d97805eda9d5e5bef7542b6 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Aug 2019 21:57:03 +0000
+Subject: [PATCH] Avoid statement expression in ATTR_DIFF macro
+
+---
+ include/netlink-private/object-api.h | 5 +----
+ 1 file changed, 1 insertion(+), 4 deletions(-)
+
+diff --git a/include/netlink-private/object-api.h b/include/netlink-private/object-api.h
+index 517e672..269cd4b 100644
+--- a/include/netlink-private/object-api.h
++++ b/include/netlink-private/object-api.h
+@@ -260,10 +260,7 @@ struct nl_object
+ * @endcode
+ */
+ #define ATTR_DIFF(LIST, ATTR, A, B, EXPR) \
+-({ uint64_t diff = 0; \
+- if (((LIST) & (ATTR)) && ATTR_MISMATCH(A, B, ATTR, EXPR)) \
+- diff = ATTR; \
+- diff; })
++ ((uint64_t)(((LIST) & (ATTR)) && ATTR_MISMATCH(A, B, ATTR, EXPR) ? (ATTR) : 0))
+
+ /**
+ * Object Operations
+--
+2.22.0
+
diff --git a/pkg/libnl/patch/0010-Fallback-to-alloca-when-VLAs-aren-t-available.patch b/pkg/libnl/patch/0010-Fallback-to-alloca-when-VLAs-aren-t-available.patch
@@ -0,0 +1,28 @@
+From 672da355b5beb5bc2729f968318f87eb7795572b Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 12 Aug 2019 02:22:15 +0000
+Subject: [PATCH] Fallback to alloca when VLAs aren't available
+
+---
+ lib/genl/mngt.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/lib/genl/mngt.c b/lib/genl/mngt.c
+index ebfe85e..dda661f 100644
+--- a/lib/genl/mngt.c
++++ b/lib/genl/mngt.c
+@@ -61,7 +61,11 @@ static int cmd_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
+ if (cmd->c_msg_parser == NULL)
+ err = -NLE_OPNOTSUPP;
+ else {
++#ifndef __STDC_NO_VLA__
+ struct nlattr *tb[cmd->c_maxattr + 1];
++#else
++ struct nlattr **tb = alloca((cmd->c_maxattr + 1) * sizeof(tb[0]));
++#endif
+ struct genl_info info = {
+ .who = who,
+ .nlh = nlh,
+--
+2.22.0
+
diff --git a/pkg/libnl/ver b/pkg/libnl/ver
@@ -1 +1 @@
-3.4.0 r0
+3.4.0 r1