netlink: Better error handling.
Signed-off-by: Benjamin Cama <benoar@dolka.fr>
This commit is contained in:
parent
7bdb42fe54
commit
1df1b625a8
1 changed files with 22 additions and 7 deletions
29
l2tpns.c
29
l2tpns.c
|
|
@ -576,6 +576,16 @@ static ssize_t netlink_recv(void *buf, ssize_t len)
|
||||||
return recvmsg(nlfd, &msg, 0);
|
return recvmsg(nlfd, &msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// messages corresponding to different phases seq number
|
||||||
|
static char *tun_nl_phase_msg[] = {
|
||||||
|
"initialized",
|
||||||
|
"getting tun interface index",
|
||||||
|
"setting tun interface parameters",
|
||||||
|
"setting tun IPv4 address",
|
||||||
|
"setting tun LL IPv6 address",
|
||||||
|
"setting tun global IPv6 address",
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set up TUN interface
|
// Set up TUN interface
|
||||||
static void inittun(void)
|
static void inittun(void)
|
||||||
|
|
@ -798,9 +808,9 @@ static void inittun(void)
|
||||||
// if we get an error for seqnum < min_initok_nlseqnum,
|
// if we get an error for seqnum < min_initok_nlseqnum,
|
||||||
// we must exit as initialization went wrong
|
// we must exit as initialization went wrong
|
||||||
if (config->ipv6_prefix.s6_addr[0])
|
if (config->ipv6_prefix.s6_addr[0])
|
||||||
min_initok_nlseqnum = 3 + 1; // idx + if + addr
|
|
||||||
else
|
|
||||||
min_initok_nlseqnum = 5 + 1; // idx + if + addr + 2*addr6
|
min_initok_nlseqnum = 5 + 1; // idx + if + addr + 2*addr6
|
||||||
|
else
|
||||||
|
min_initok_nlseqnum = 3 + 1; // idx + if + addr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3886,13 +3896,18 @@ static void mainloop(void)
|
||||||
if (nh->nlmsg_type == NLMSG_ERROR)
|
if (nh->nlmsg_type == NLMSG_ERROR)
|
||||||
{
|
{
|
||||||
struct nlmsgerr *errmsg = NLMSG_DATA(nh);
|
struct nlmsgerr *errmsg = NLMSG_DATA(nh);
|
||||||
if (errmsg->error && errmsg->msg.nlmsg_seq < min_initok_nlseqnum)
|
if (errmsg->error)
|
||||||
{
|
{
|
||||||
LOG(0, 0, 0, "Got a fatal netlink error: seq %d flags %d code %d\n", nh->nlmsg_seq, nh->nlmsg_flags, errmsg->error);
|
if (errmsg->msg.nlmsg_seq < min_initok_nlseqnum)
|
||||||
exit(1);
|
{
|
||||||
|
LOG(0, 0, 0, "Got a fatal netlink error (while %s): %s\n", tun_nl_phase_msg[nh->nlmsg_seq], strerror(-errmsg->error));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
|
||||||
|
LOG(0, 0, 0, "Got a netlink error: %s\n", strerror(-errmsg->error));
|
||||||
}
|
}
|
||||||
else
|
// else it's a ack
|
||||||
LOG(1, 0, 0, "Got a netlink error: seq %d flags %d code %d\n", nh->nlmsg_seq, nh->nlmsg_flags, errmsg->error);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LOG(1, 0, 0, "Got a unknown netlink message: type %d seq %d flags %d\n", nh->nlmsg_type, nh->nlmsg_seq, nh->nlmsg_flags);
|
LOG(1, 0, 0, "Got a unknown netlink message: type %d seq %d flags %d\n", nh->nlmsg_type, nh->nlmsg_seq, nh->nlmsg_flags);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue