git: 629d9219d931 - main - netlink: make netlink_snl(3) c++ friendly.

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Sun, 12 Feb 2023 11:46:49 UTC
The branch main has been updated by melifaro:

URL: https://cgit.FreeBSD.org/src/commit/?id=629d9219d931e63dc49ef046332b2a360e42a5f6

commit 629d9219d931e63dc49ef046332b2a360e42a5f6
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-02-10 20:19:09 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-02-12 11:46:38 +0000

    netlink: make netlink_snl(3) c++ friendly.
---
 sys/netlink/netlink_snl.h       | 22 +++++++++++++---------
 sys/netlink/netlink_snl_route.h |  6 +++++-
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h
index 6e2c4b89a7c4..586cab391046 100644
--- a/sys/netlink/netlink_snl.h
+++ b/sys/netlink/netlink_snl.h
@@ -44,6 +44,7 @@
 #include <sys/socket.h>
 #include <netlink/netlink.h>
 
+__BEGIN_DECLS
 
 #define _roundup2(x, y)         (((x)+((y)-1))&(~((y)-1)))
 
@@ -83,7 +84,7 @@ lb_allocz(struct linear_buffer *lb, int len)
 		return (NULL);
 	void *data = (void *)(lb->base + lb->offset);
 	lb->offset += len;
-	return (data);
+	return ((char *)data);
 }
 
 static inline void
@@ -132,10 +133,10 @@ struct snl_hdr_parser {
 #define	SNL_DECLARE_PARSER(_name, _t, _fp, _np)		\
 static const struct snl_hdr_parser _name = {		\
 	.hdr_off = sizeof(_t),				\
-	.fp = &((_fp)[0]),				\
-	.np = &((_np)[0]),				\
 	.fp_size = NL_ARRAY_LEN(_fp),			\
 	.np_size = NL_ARRAY_LEN(_np),			\
+	.fp = &((_fp)[0]),				\
+	.np = &((_np)[0]),				\
 }
 
 #define	SNL_DECLARE_ATTR_PARSER(_name, _np)		\
@@ -175,14 +176,14 @@ snl_init(struct snl_state *ss, int netlink_family)
 	}
 
 	ss->bufsize = rcvbuf;
-	ss->buf = malloc(ss->bufsize);
+	ss->buf = (char *)malloc(ss->bufsize);
 	if (ss->buf == NULL) {
 		snl_free(ss);
 		return (false);
 	}
 
 	ss->lb.size = SCRATCH_BUFFER_SIZE;
-	ss->lb.base = calloc(1, ss->lb.size);
+	ss->lb.base = (char *)calloc(1, ss->lb.size);
 	if (ss->lb.base == NULL) {
 		snl_free(ss);
 		return (false);
@@ -360,7 +361,7 @@ snl_attr_get_uint16(struct snl_state *ss __unused, struct nlattr *nla,
     const void *arg __unused, void *target)
 {
 	if (NLA_DATA_LEN(nla) == sizeof(uint16_t)) {
-		*((uint16_t *)target) = *((const uint16_t *)NLA_DATA_CONST(nla));
+		*((uint16_t *)target) = *((const uint16_t *)NL_RTA_DATA_CONST(nla));
 		return (true);
 	}
 	return (false);
@@ -371,7 +372,7 @@ snl_attr_get_uint32(struct snl_state *ss __unused, struct nlattr *nla,
     const void *arg __unused, void *target)
 {
 	if (NLA_DATA_LEN(nla) == sizeof(uint32_t)) {
-		*((uint32_t *)target) = *((const uint32_t *)NLA_DATA_CONST(nla));
+		*((uint32_t *)target) = *((const uint32_t *)NL_RTA_DATA_CONST(nla));
 		return (true);
 	}
 	return (false);
@@ -396,7 +397,7 @@ snl_attr_get_stringn(struct snl_state *ss, struct nlattr *nla,
 {
 	int maxlen = NLA_DATA_LEN(nla);
 
-	char *buf = snl_allocz(ss, maxlen + 1);
+	char *buf = (char *)snl_allocz(ss, maxlen + 1);
 	if (buf == NULL)
 		return (false);
 	buf[maxlen] = '\0';
@@ -416,7 +417,8 @@ snl_attr_get_nested(struct snl_state *ss, struct nlattr *nla, const void *arg, v
 }
 
 static inline bool
-snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla, void *target)
+snl_attr_get_nla(struct snl_state *ss __unused, struct nlattr *nla,
+    const void *arg __unused, void *target)
 {
 	*((struct nlattr **)target) = nla;
 	return (true);
@@ -440,4 +442,6 @@ snl_field_get_uint32(struct snl_state *ss __unused, void *src, void *target)
 	*((uint32_t *)target) = *((uint32_t *)src);
 }
 
+__END_DECLS
+
 #endif
diff --git a/sys/netlink/netlink_snl_route.h b/sys/netlink/netlink_snl_route.h
index 4adb3d697ecd..19841bdd2f50 100644
--- a/sys/netlink/netlink_snl_route.h
+++ b/sys/netlink/netlink_snl_route.h
@@ -31,6 +31,8 @@
 #include <netlink/netlink_route.h>
 #include <netinet/in.h>
 
+__BEGIN_DECLS
+
 /*
  * Simple Netlink Library - NETLINK_ROUTE helpers
  */
@@ -100,7 +102,7 @@ snl_attr_get_ip(struct snl_state *ss, struct nlattr *nla,
 static inline struct sockaddr *
 parse_rta_via(struct snl_state *ss, struct rtattr *rta, int *perror)
 {
-	struct rtvia *via = NL_RTA_DATA(rta);
+	struct rtvia *via = (struct rtvia *)NL_RTA_DATA(rta);
 
 	switch (via->rtvia_family) {
 	case AF_INET:
@@ -127,4 +129,6 @@ snl_attr_get_ipvia(struct snl_state *ss, struct nlattr *nla,
 	return (false);
 }
 
+__END_DECLS
+
 #endif