[2/2] net: sockets -- Don't spam log with known errors

Submitted by Cyrill Gorcunov on Oct. 9, 2018, 1:49 p.m.

Details

Message ID 20181009134919.15472-3-gorcunov@gmail.com
State New
Series "sockets: Placate logger when diag modules are missing"
Headers show

Commit Message

Cyrill Gorcunov Oct. 9, 2018, 1:49 p.m.
For example if diag module is not built then we should
not spam with error message but we will print an error
if only a particular socket is really used.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 criu/include/libnetlink.h |  2 +-
 criu/libnetlink.c         | 10 ++---
 criu/sockets.c            | 88 ++++++++++++++++++---------------------
 3 files changed, 47 insertions(+), 53 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/libnetlink.h b/criu/include/libnetlink.h
index bf2eb24740b0..f21a0e750337 100644
--- a/criu/include/libnetlink.h
+++ b/criu/include/libnetlink.h
@@ -6,7 +6,7 @@ 
 struct ns_id;
 extern int do_rtnl_req(int nl, void *req, int size,
 		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
-		int (*error_callback)(int err, void *), struct ns_id *ns, void *);
+		int (*error_callback)(int err, struct ns_id *ns, void *), struct ns_id *ns, void *);
 
 extern int addattr_l(struct nlmsghdr *n, int maxlen, int type,
 		const void *data, int alen);
diff --git a/criu/libnetlink.c b/criu/libnetlink.c
index 2ce4a38262d4..60e98e3460dc 100644
--- a/criu/libnetlink.c
+++ b/criu/libnetlink.c
@@ -12,7 +12,7 @@ 
 
 static int nlmsg_receive(char *buf, int len,
 		int (*cb)(struct nlmsghdr *, struct ns_id *ns, void *),
-		int (*err_cb)(int, void *), struct ns_id *ns, void *arg)
+		int (*err_cb)(int, struct ns_id *, void *), struct ns_id *ns, void *arg)
 {
 	struct nlmsghdr *hdr;
 
@@ -22,7 +22,7 @@  static int nlmsg_receive(char *buf, int len,
 		if (hdr->nlmsg_type == NLMSG_DONE) {
 			int *len = (int *)NLMSG_DATA(hdr);
 			if (*len < 0)
-				return err_cb(*len, arg);
+				return err_cb(*len, ns, arg);
 			return 0;
 		}
 		if (hdr->nlmsg_type == NLMSG_ERROR) {
@@ -36,7 +36,7 @@  static int nlmsg_receive(char *buf, int len,
 			if (err->error == 0)
 				return 0;
 
-			return err_cb(err->error, arg);
+			return err_cb(err->error, ns, arg);
 		}
 		if (cb(hdr, ns, arg))
 			return -1;
@@ -45,7 +45,7 @@  static int nlmsg_receive(char *buf, int len,
 	return 1;
 }
 
-static int rtnl_return_err(int err, void *arg)
+static int rtnl_return_err(int err, struct ns_id *ns, void *arg)
 {
 	errno = -err;
 	pr_perror("ERROR %d reported by netlink", err);
@@ -54,7 +54,7 @@  static int rtnl_return_err(int err, void *arg)
 
 int do_rtnl_req(int nl, void *req, int size,
 		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
-		int (*error_callback)(int err, void *), struct ns_id *ns, void *arg)
+		int (*error_callback)(int err, struct ns_id *ns, void *arg), struct ns_id *ns, void *arg)
 {
 	struct msghdr msg;
 	struct sockaddr_nl nladdr;
diff --git a/criu/sockets.c b/criu/sockets.c
index dd40a777eb6a..45bf7b2a03ae 100644
--- a/criu/sockets.c
+++ b/criu/sockets.c
@@ -213,7 +213,7 @@  static int probe_recv_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
 	return -1;
 }
 
-static int probe_err(int err, void *arg)
+static int probe_err(int err, struct ns_id *ns, void *arg)
 {
 	int expected_err = *(int *)arg;
 
@@ -717,18 +717,34 @@  static int inet_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
 
 static int do_collect_req(int nl, struct sock_diag_req *req, int size,
 		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
+		int (*error_callback)(int err, struct ns_id *ns, void *),
 		struct ns_id *ns, void *arg)
 {
-	int tmp;
-
-	tmp = do_rtnl_req(nl, req, size, receive_callback, NULL, ns, arg);
-
+	int tmp = do_rtnl_req(nl, req, size, receive_callback, error_callback, ns, arg);
 	if (tmp == 0)
 		set_collect_bit(req->r.n.sdiag_family, req->r.n.sdiag_protocol);
-
 	return tmp;
 }
 
+static int collect_err(int err, struct ns_id *ns, void *arg)
+{
+	struct sock_diag_greq *gr = arg;
+	char family[32], proto[32];
+
+	/* Fedora 19 hack */
+	if (gr->family == AF_PACKET || gr->family == AF_NETLINK) {
+		if (err == -ENOENT)
+			return 0;
+	}
+
+	pr_info("Sockects collect procedure family %s proto %s: %s\n",
+		socket_family_name(gr->family, family, sizeof(family)),
+		socket_proto_name(gr->protocol, proto, sizeof(proto)),
+		strerror(-err));
+
+	return err;
+}
+
 int collect_sockets(struct ns_id *ns)
 {
 	int err = 0, tmp;
@@ -747,7 +763,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.u.udiag_show	= UDIAG_SHOW_NAME | UDIAG_SHOW_VFS |
 				  UDIAG_SHOW_PEER | UDIAG_SHOW_ICONS |
 				  UDIAG_SHOW_RQLEN;
-	tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, ns, NULL);
+	tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, collect_err, ns, &req.r.u);
 	if (tmp)
 		err = tmp;
 
@@ -760,7 +776,7 @@  int collect_sockets(struct ns_id *ns)
 					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
 					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
 					(1 << TCP_CLOSING) | (1 << TCP_SYN_SENT);
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -769,7 +785,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDP;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -778,7 +794,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDPLITE;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -787,17 +803,9 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_RAW;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	if (kdat.has_sk_diag_packet < 2) {
-		tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
-		if (tmp == -ENOENT)
-			kdat.has_sk_diag_packet = 2;
-	} else
-		tmp = -ENOENT;
-	if (tmp) {
-		pr_warn("The current kernel doesn't support ipv4 raw_diag module\n");
-		if (tmp != -ENOENT)
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
+	if (tmp)
+		err = tmp;
 
 	/* Collect IPv6 TCP sockets */
 	req.r.i.sdiag_family	= AF_INET6;
@@ -808,7 +816,7 @@  int collect_sockets(struct ns_id *ns)
 					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
 					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
 					(1 << TCP_CLOSING) | (1 << TCP_SYN_SENT);
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -817,7 +825,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDP;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -826,7 +834,7 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_UDPLITE;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
 	if (tmp)
 		err = tmp;
 
@@ -835,38 +843,24 @@  int collect_sockets(struct ns_id *ns)
 	req.r.i.sdiag_protocol	= IPPROTO_RAW;
 	req.r.i.idiag_ext	= 0;
 	req.r.i.idiag_states	= -1; /* All */
-	if (kdat.has_sk_diag_packet < 2) {
-		tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
-		if (tmp == -ENOENT)
-			kdat.has_sk_diag_packet = 2;
-	} else
-		tmp = -ENOENT;
-	if (tmp) {
-		pr_warn("The current kernel doesn't support ipv6 raw_diag module\n");
-		if (tmp != -ENOENT)
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
+	if (tmp)
+		err = tmp;
 
 	req.r.p.sdiag_family	= AF_PACKET;
 	req.r.p.sdiag_protocol	= 0;
 	req.r.p.pdiag_show	= PACKET_SHOW_INFO | PACKET_SHOW_MCLIST |
 					PACKET_SHOW_FANOUT | PACKET_SHOW_RING_CFG;
-	tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, ns, NULL);
-	if (tmp) {
-		pr_warn("The current kernel doesn't support packet_diag\n");
-		if (tmp != -ENOENT) /* Fedora 19 */
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, collect_err, ns, &req.r.p);
+	if (tmp)
+		err = tmp;
 
 	req.r.n.sdiag_family	= AF_NETLINK;
 	req.r.n.sdiag_protocol	= NDIAG_PROTO_ALL;
 	req.r.n.ndiag_show	= NDIAG_SHOW_GROUPS;
-	tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, ns, NULL);
-	if (tmp) {
-		pr_warn("The current kernel doesn't support netlink_diag\n");
-		if (ns->ns_pid == 0 || tmp != -ENOENT) /* Fedora 19 */
-			err = tmp;
-	}
+	tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, collect_err, ns, &req.r.n);
+	if (tmp)
+		err = tmp;
 
 	/* don't need anymore */
 	close(nl);

Comments

Andrei Vagin Oct. 10, 2018, 6:26 a.m.
On Tue, Oct 09, 2018 at 04:49:19PM +0300, Cyrill Gorcunov wrote:
> For example if diag module is not built then we should
> not spam with error message but we will print an error
> if only a particular socket is really used.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
> ---
>  criu/include/libnetlink.h |  2 +-
>  criu/libnetlink.c         | 10 ++---
>  criu/sockets.c            | 88 ++++++++++++++++++---------------------
>  3 files changed, 47 insertions(+), 53 deletions(-)
> 
> diff --git a/criu/include/libnetlink.h b/criu/include/libnetlink.h
> index bf2eb24740b0..f21a0e750337 100644
> --- a/criu/include/libnetlink.h
> +++ b/criu/include/libnetlink.h
> @@ -6,7 +6,7 @@
>  struct ns_id;
>  extern int do_rtnl_req(int nl, void *req, int size,
>  		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
> -		int (*error_callback)(int err, void *), struct ns_id *ns, void *);
> +		int (*error_callback)(int err, struct ns_id *ns, void *), struct ns_id *ns, void *);

How we are going to use ns in error_callback()?

>  
>  extern int addattr_l(struct nlmsghdr *n, int maxlen, int type,
>  		const void *data, int alen);
> diff --git a/criu/libnetlink.c b/criu/libnetlink.c
> index 2ce4a38262d4..60e98e3460dc 100644
> --- a/criu/libnetlink.c
> +++ b/criu/libnetlink.c
> @@ -12,7 +12,7 @@
>  
>  static int nlmsg_receive(char *buf, int len,
>  		int (*cb)(struct nlmsghdr *, struct ns_id *ns, void *),
> -		int (*err_cb)(int, void *), struct ns_id *ns, void *arg)
> +		int (*err_cb)(int, struct ns_id *, void *), struct ns_id *ns, void *arg)
>  {
>  	struct nlmsghdr *hdr;
>  
> @@ -22,7 +22,7 @@ static int nlmsg_receive(char *buf, int len,
>  		if (hdr->nlmsg_type == NLMSG_DONE) {
>  			int *len = (int *)NLMSG_DATA(hdr);
>  			if (*len < 0)
> -				return err_cb(*len, arg);
> +				return err_cb(*len, ns, arg);
>  			return 0;
>  		}
>  		if (hdr->nlmsg_type == NLMSG_ERROR) {
> @@ -36,7 +36,7 @@ static int nlmsg_receive(char *buf, int len,
>  			if (err->error == 0)
>  				return 0;
>  
> -			return err_cb(err->error, arg);
> +			return err_cb(err->error, ns, arg);
>  		}
>  		if (cb(hdr, ns, arg))
>  			return -1;
> @@ -45,7 +45,7 @@ static int nlmsg_receive(char *buf, int len,
>  	return 1;
>  }
>  
> -static int rtnl_return_err(int err, void *arg)
> +static int rtnl_return_err(int err, struct ns_id *ns, void *arg)
>  {
>  	errno = -err;
>  	pr_perror("ERROR %d reported by netlink", err);
> @@ -54,7 +54,7 @@ static int rtnl_return_err(int err, void *arg)
>  
>  int do_rtnl_req(int nl, void *req, int size,
>  		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
> -		int (*error_callback)(int err, void *), struct ns_id *ns, void *arg)
> +		int (*error_callback)(int err, struct ns_id *ns, void *arg), struct ns_id *ns, void *arg)
>  {
>  	struct msghdr msg;
>  	struct sockaddr_nl nladdr;
> diff --git a/criu/sockets.c b/criu/sockets.c
> index dd40a777eb6a..45bf7b2a03ae 100644
> --- a/criu/sockets.c
> +++ b/criu/sockets.c
> @@ -213,7 +213,7 @@ static int probe_recv_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
>  	return -1;
>  }
>  
> -static int probe_err(int err, void *arg)
> +static int probe_err(int err, struct ns_id *ns, void *arg)
>  {
>  	int expected_err = *(int *)arg;
>  
> @@ -717,18 +717,34 @@ static int inet_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
>  
>  static int do_collect_req(int nl, struct sock_diag_req *req, int size,
>  		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
> +		int (*error_callback)(int err, struct ns_id *ns, void *),
>  		struct ns_id *ns, void *arg)
>  {
> -	int tmp;
> -
> -	tmp = do_rtnl_req(nl, req, size, receive_callback, NULL, ns, arg);
> -
> +	int tmp = do_rtnl_req(nl, req, size, receive_callback, error_callback, ns, arg);
>  	if (tmp == 0)
>  		set_collect_bit(req->r.n.sdiag_family, req->r.n.sdiag_protocol);
> -
>  	return tmp;
>  }
>  
> +static int collect_err(int err, struct ns_id *ns, void *arg)
> +{
> +	struct sock_diag_greq *gr = arg;
> +	char family[32], proto[32];
> +
> +	/* Fedora 19 hack */

Pls write more detailed comment here. Fedora 19 is dead for a long time

> +	if (gr->family == AF_PACKET || gr->family == AF_NETLINK) {
> +		if (err == -ENOENT)
> +			return 0;
> +	}
> +
> +	pr_info("Sockects collect procedure family %s proto %s: %s\n",
> +		socket_family_name(gr->family, family, sizeof(family)),
> +		socket_proto_name(gr->protocol, proto, sizeof(proto)),
> +		strerror(-err));
> +
> +	return err;
> +}
> +
>  int collect_sockets(struct ns_id *ns)
>  {
>  	int err = 0, tmp;
> @@ -747,7 +763,7 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.u.udiag_show	= UDIAG_SHOW_NAME | UDIAG_SHOW_VFS |
>  				  UDIAG_SHOW_PEER | UDIAG_SHOW_ICONS |
>  				  UDIAG_SHOW_RQLEN;
> -	tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, ns, NULL);
> +	tmp = do_collect_req(nl, &req, sizeof(req), unix_receive_one, collect_err, ns, &req.r.u);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -760,7 +776,7 @@ int collect_sockets(struct ns_id *ns)
>  					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
>  					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
>  					(1 << TCP_CLOSING) | (1 << TCP_SYN_SENT);
> -	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -769,7 +785,7 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.i.sdiag_protocol	= IPPROTO_UDP;
>  	req.r.i.idiag_ext	= 0;
>  	req.r.i.idiag_states	= -1; /* All */
> -	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -778,7 +794,7 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.i.sdiag_protocol	= IPPROTO_UDPLITE;
>  	req.r.i.idiag_ext	= 0;
>  	req.r.i.idiag_states	= -1; /* All */
> -	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -787,17 +803,9 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.i.sdiag_protocol	= IPPROTO_RAW;
>  	req.r.i.idiag_ext	= 0;
>  	req.r.i.idiag_states	= -1; /* All */
> -	if (kdat.has_sk_diag_packet < 2) {
> -		tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> -		if (tmp == -ENOENT)
> -			kdat.has_sk_diag_packet = 2;
> -	} else
> -		tmp = -ENOENT;
> -	if (tmp) {
> -		pr_warn("The current kernel doesn't support ipv4 raw_diag module\n");
> -		if (tmp != -ENOENT)
> -			err = tmp;
> -	}
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
> +	if (tmp)
> +		err = tmp;
>  
>  	/* Collect IPv6 TCP sockets */
>  	req.r.i.sdiag_family	= AF_INET6;
> @@ -808,7 +816,7 @@ int collect_sockets(struct ns_id *ns)
>  					(1 << TCP_FIN_WAIT1) | (1 << TCP_FIN_WAIT2) |
>  					(1 << TCP_CLOSE_WAIT) | (1 << TCP_LAST_ACK) |
>  					(1 << TCP_CLOSING) | (1 << TCP_SYN_SENT);
> -	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -817,7 +825,7 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.i.sdiag_protocol	= IPPROTO_UDP;
>  	req.r.i.idiag_ext	= 0;
>  	req.r.i.idiag_states	= -1; /* All */
> -	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -826,7 +834,7 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.i.sdiag_protocol	= IPPROTO_UDPLITE;
>  	req.r.i.idiag_ext	= 0;
>  	req.r.i.idiag_states	= -1; /* All */
> -	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
>  	if (tmp)
>  		err = tmp;
>  
> @@ -835,38 +843,24 @@ int collect_sockets(struct ns_id *ns)
>  	req.r.i.sdiag_protocol	= IPPROTO_RAW;
>  	req.r.i.idiag_ext	= 0;
>  	req.r.i.idiag_states	= -1; /* All */
> -	if (kdat.has_sk_diag_packet < 2) {
> -		tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, ns, &req.r.i);
> -		if (tmp == -ENOENT)
> -			kdat.has_sk_diag_packet = 2;
> -	} else
> -		tmp = -ENOENT;
> -	if (tmp) {
> -		pr_warn("The current kernel doesn't support ipv6 raw_diag module\n");
> -		if (tmp != -ENOENT)
> -			err = tmp;
> -	}
> +	tmp = do_collect_req(nl, &req, sizeof(req), inet_receive_one, collect_err, ns, &req.r.i);
> +	if (tmp)
> +		err = tmp;
>  
>  	req.r.p.sdiag_family	= AF_PACKET;
>  	req.r.p.sdiag_protocol	= 0;
>  	req.r.p.pdiag_show	= PACKET_SHOW_INFO | PACKET_SHOW_MCLIST |
>  					PACKET_SHOW_FANOUT | PACKET_SHOW_RING_CFG;
> -	tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, ns, NULL);
> -	if (tmp) {
> -		pr_warn("The current kernel doesn't support packet_diag\n");
> -		if (tmp != -ENOENT) /* Fedora 19 */
> -			err = tmp;
> -	}
> +	tmp = do_collect_req(nl, &req, sizeof(req), packet_receive_one, collect_err, ns, &req.r.p);
> +	if (tmp)
> +		err = tmp;
>  
>  	req.r.n.sdiag_family	= AF_NETLINK;
>  	req.r.n.sdiag_protocol	= NDIAG_PROTO_ALL;
>  	req.r.n.ndiag_show	= NDIAG_SHOW_GROUPS;
> -	tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, ns, NULL);
> -	if (tmp) {
> -		pr_warn("The current kernel doesn't support netlink_diag\n");
> -		if (ns->ns_pid == 0 || tmp != -ENOENT) /* Fedora 19 */
> -			err = tmp;
> -	}
> +	tmp = do_collect_req(nl, &req, sizeof(req), netlink_receive_one, collect_err, ns, &req.r.n);
> +	if (tmp)
> +		err = tmp;
>  
>  	/* don't need anymore */
>  	close(nl);
> -- 
> 2.17.1
>
Cyrill Gorcunov Oct. 10, 2018, 6:54 a.m.
On Tue, Oct 09, 2018 at 11:26:24PM -0700, Andrey Vagin wrote:
> > diff --git a/criu/include/libnetlink.h b/criu/include/libnetlink.h
> > index bf2eb24740b0..f21a0e750337 100644
> > --- a/criu/include/libnetlink.h
> > +++ b/criu/include/libnetlink.h
> > @@ -6,7 +6,7 @@
> >  struct ns_id;
> >  extern int do_rtnl_req(int nl, void *req, int size,
> >  		int (*receive_callback)(struct nlmsghdr *h, struct ns_id *ns, void *),
> > -		int (*error_callback)(int err, void *), struct ns_id *ns, void *);
> > +		int (*error_callback)(int err, struct ns_id *ns, void *), struct ns_id *ns, void *);
> 
> How we are going to use ns in error_callback()?
> 

Well, it is leftover from previous attempts. I'll cleanup.

> > +static int collect_err(int err, struct ns_id *ns, void *arg)
> > +{
> > +	struct sock_diag_greq *gr = arg;
> > +	char family[32], proto[32];
> > +
> > +	/* Fedora 19 hack */
> 
> Pls write more detailed comment here. Fedora 19 is dead for a long time

Hard to tell, I took this code from existing our code base. Probably
we simply should just rip off this comment completely.