From: Florian Westphal Date: Mon, 17 May 2021 05:10:10 +0000 (+0200) Subject: libgenl: make genl_add_mcast_grp set errno on error X-Git-Tag: v5.13.0~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3740fdc2671dd4039779cd7562c7f09cc1c6a48;p=thirdparty%2Fiproute2.git libgenl: make genl_add_mcast_grp set errno on error genl_add_mcast_grp doesn't set errno in all cases. On kernels that support mptcp but lack event support (all kernels <= 5.11) MPTCP_PM_EV_GRP_NAME won't be found and ip will exit with "can't subscribe to mptcp events: Success" Set errno to a meaningful value (ENOENT) when the group name isn't found and also cover other spots where it returns nonzero with errno unset. Fixes: ff619e4fd370 ("mptcp: add support for event monitoring") Signed-off-by: Florian Westphal Reviewed-by: David Ahern Signed-off-by: Stephen Hemminger --- diff --git a/lib/libgenl.c b/lib/libgenl.c index 4c51d47af..fca07f9fe 100644 --- a/lib/libgenl.c +++ b/lib/libgenl.c @@ -3,6 +3,7 @@ * libgenl.c GENL library */ +#include #include #include #include @@ -84,6 +85,7 @@ static int genl_parse_grps(struct rtattr *attr, const char *name, unsigned int * } } + errno = ENOENT; return -1; } @@ -108,17 +110,22 @@ int genl_add_mcast_grp(struct rtnl_handle *grth, __u16 fnum, const char *group) ghdr = NLMSG_DATA(answer); len = answer->nlmsg_len; - if (answer->nlmsg_type != GENL_ID_CTRL) + if (answer->nlmsg_type != GENL_ID_CTRL) { + errno = EINVAL; goto err_free; + } len -= NLMSG_LENGTH(GENL_HDRLEN); - if (len < 0) + if (len < 0) { + errno = EINVAL; goto err_free; + } attrs = (struct rtattr *) ((char *) ghdr + GENL_HDRLEN); parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); if (tb[CTRL_ATTR_MCAST_GROUPS] == NULL) { + errno = ENOENT; fprintf(stderr, "Missing mcast groups TLV\n"); goto err_free; }