Skip to content

Commit

Permalink
dco_linux: extend netlink error cb with extra info
Browse files Browse the repository at this point in the history
A netlink error may contain more specific attributes: i.e.
missing attributes or missing neted objects.

Parse and print this information too.

Note that we are re-defining some enum entries that exist
in netlink.h starting with linux-6.1.
Since we do support distros not shipping an up-to-date
netlink.h, we had to re-define the entries we need for
this patch.

Change-Id: I9e27ff335d892429334137d028f8503da4e4ca5b
Signed-off-by: Antonio Quartulli <[email protected]>
Acked-by: Frank Lichtenheld <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg30658.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
ordex authored and cron2 committed Jan 28, 2025
1 parent 40518dc commit edad5fa
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/openvpn/dco_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,25 @@ ovpn_nl_cb_finish(struct nl_msg (*msg) __attribute__ ((unused)), void *arg)
return NL_SKIP;
}

/* The following enum members exist in netlink.h since linux-6.1.
* However, some distro we support still ship an old header, thus
* failing the OpenVPN compilation.
*
* For the time being we add the needed defines manually.
* We will drop this definition once we stop supporting those old
* distros.
*
* @NLMSGERR_ATTR_MISS_TYPE: type of a missing required attribute,
* %NLMSGERR_ATTR_MISS_NEST will not be present if the attribute was
* missing at the message level
* @NLMSGERR_ATTR_MISS_NEST: offset of the nest where attribute was missing
*/
enum ovpn_nlmsgerr_attrs {
OVPN_NLMSGERR_ATTR_MISS_TYPE = 5,
OVPN_NLMSGERR_ATTR_MISS_NEST = 6,
OVPN_NLMSGERR_ATTR_MAX = 6,
};

/* This function is used as error callback on the netlink socket.
* When something goes wrong and the kernel returns an error, this function is
* invoked.
Expand All @@ -304,7 +323,7 @@ ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
struct nlmsgerr *err, void *arg)
{
struct nlmsghdr *nlh = (struct nlmsghdr *)err - 1;
struct nlattr *tb_msg[NLMSGERR_ATTR_MAX + 1];
struct nlattr *tb_msg[OVPN_NLMSGERR_ATTR_MAX + 1];
int len = nlh->nlmsg_len;
struct nlattr *attrs;
int *ret = arg;
Expand All @@ -330,7 +349,7 @@ ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
attrs = (void *)((unsigned char *)nlh + ack_len);
len -= ack_len;

nla_parse(tb_msg, NLMSGERR_ATTR_MAX, attrs, len, NULL);
nla_parse(tb_msg, OVPN_NLMSGERR_ATTR_MAX, attrs, len, NULL);
if (tb_msg[NLMSGERR_ATTR_MSG])
{
len = strnlen((char *)nla_data(tb_msg[NLMSGERR_ATTR_MSG]),
Expand All @@ -339,6 +358,18 @@ ovpn_nl_cb_error(struct sockaddr_nl (*nla) __attribute__ ((unused)),
(char *)nla_data(tb_msg[NLMSGERR_ATTR_MSG]));
}

if (tb_msg[OVPN_NLMSGERR_ATTR_MISS_NEST])
{
msg(M_WARN, "kernel error: missing required nesting type %u\n",
nla_get_u32(tb_msg[OVPN_NLMSGERR_ATTR_MISS_NEST]));
}

if (tb_msg[OVPN_NLMSGERR_ATTR_MISS_TYPE])
{
msg(M_WARN, "kernel error: missing required attribute type %u\n",
nla_get_u32(tb_msg[OVPN_NLMSGERR_ATTR_MISS_TYPE]));
}

return NL_STOP;
}

Expand Down

0 comments on commit edad5fa

Please sign in to comment.