* [PATCH] ipvsadm: catch the original errno from netlink answer
@ 2017-08-05 11:38 Julian Anastasov
2017-08-11 13:50 ` Jesper Dangaard Brouer
0 siblings, 1 reply; 2+ messages in thread
From: Julian Anastasov @ 2017-08-05 11:38 UTC (permalink / raw)
To: Jesper Dangaard Brouer; +Cc: Simon Horman, lvs-devel, lvs-users, Emanuele Rocca
nl_recvmsgs_default() returns NLE_* error codes and not
errno values. As result, attempt to delete virtual service
returns NLE_OBJ_NOTFOUND (12) which matches the ENOMEM value.
Problem as reported by Emanuele Rocca:
ipvsadm -D -t example.org:80
Memory allocation problem
Fix it by providing generic error handler to catch the errno
value as returned in netlink answer. By this way all netlink
commands will get proper error string. The problem is present
only when ipvsadm is compiled with libnl.
ipvsadm -D -t example.org:80
No such service
Reported-by: Emanuele Rocca <ema@wikimedia.org>
Signed-off-by: Julian Anastasov <ja@ssi.bg>
---
libipvs/libipvs.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/libipvs/libipvs.c b/libipvs/libipvs.c
index 180ea42..1cc46b9 100644
--- a/libipvs/libipvs.c
+++ b/libipvs/libipvs.c
@@ -74,9 +74,23 @@ static int ipvs_nl_noop_cb(struct nl_msg *msg, void *arg)
return NL_OK;
}
+struct cb_err_data {
+ int err;
+};
+
+static int ipvs_nl_err_cb(struct sockaddr_nl *nla, struct nlmsgerr *nlerr,
+ void *arg)
+{
+ struct cb_err_data *data = arg;
+
+ data->err = nlerr->error;
+ return -nl_syserr2nlerr(nlerr->error);
+}
+
int ipvs_nl_send_message(struct nl_msg *msg, nl_recvmsg_msg_cb_t func, void *arg)
{
int err = EINVAL;
+ struct cb_err_data err_data = { .err = 0 };
sock = nl_socket_alloc();
if (!sock) {
@@ -100,12 +114,18 @@ int ipvs_nl_send_message(struct nl_msg *msg, nl_recvmsg_msg_cb_t func, void *arg
if (nl_socket_modify_cb(sock, NL_CB_VALID, NL_CB_CUSTOM, func, arg) != 0)
goto fail_genl;
+ if (nl_socket_modify_err_cb(sock, NL_CB_CUSTOM, ipvs_nl_err_cb,
+ &err_data) != 0)
+ goto fail_genl;
if (nl_send_auto_complete(sock, msg) < 0)
goto fail_genl;
- if ((err = -nl_recvmsgs_default(sock)) > 0)
+ if (nl_recvmsgs_default(sock) < 0) {
+ if (err_data.err)
+ err = -err_data.err;
goto fail_genl;
+ }
nlmsg_free(msg);
--
2.9.4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] ipvsadm: catch the original errno from netlink answer
2017-08-05 11:38 [PATCH] ipvsadm: catch the original errno from netlink answer Julian Anastasov
@ 2017-08-11 13:50 ` Jesper Dangaard Brouer
0 siblings, 0 replies; 2+ messages in thread
From: Jesper Dangaard Brouer @ 2017-08-11 13:50 UTC (permalink / raw)
To: Julian Anastasov
Cc: Simon Horman, lvs-devel, lvs-users, Emanuele Rocca, brouer
On Sat, 5 Aug 2017 14:38:28 +0300
Julian Anastasov <ja@ssi.bg> wrote:
> nl_recvmsgs_default() returns NLE_* error codes and not
> errno values. As result, attempt to delete virtual service
> returns NLE_OBJ_NOTFOUND (12) which matches the ENOMEM value.
>
> Problem as reported by Emanuele Rocca:
>
> ipvsadm -D -t example.org:80
> Memory allocation problem
>
> Fix it by providing generic error handler to catch the errno
> value as returned in netlink answer. By this way all netlink
> commands will get proper error string. The problem is present
> only when ipvsadm is compiled with libnl.
>
> ipvsadm -D -t example.org:80
> No such service
>
> Reported-by: Emanuele Rocca <ema@wikimedia.org>
> Signed-off-by: Julian Anastasov <ja@ssi.bg>
I've gone through the full call path from the kernel via netlink, and I
was going to claim that we also needed to handle errno "-EEXIST" in the
ipvsadm translation function ipvs_strerror(). Note, this fix uses the
errno "-ESRCH".
As kernel function ip_vs_del_service() return -EEXIST (if svc==NULL)
http://elixir.free-electrons.com/linux/v4.12.5/source/net/netfilter/ipvs/ip_vs_ctl.c#L1480
BUT a closer look shows that -EEXIST will never get returned by
ip_vs_del_service() as all callers of this function does a svc==NULL
check and return "-ESRCH" instead.
Thus, this patch is correct, but the kernel code is confusing ;-)
Applied:
https://git.kernel.org/pub/scm/utils/kernel/ipvsadm/ipvsadm.git/commit/?id=f8cff0808a24b
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-11 13:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-05 11:38 [PATCH] ipvsadm: catch the original errno from netlink answer Julian Anastasov
2017-08-11 13:50 ` Jesper Dangaard Brouer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).