summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@kernel.org>2022-02-27 18:25:02 -0700
committerDavid Ahern <dsahern@kernel.org>2022-02-27 18:25:02 -0700
commit8cc6e4e72516bc2e1c83ee145e7f118c5edb1fdf (patch)
tree0d44446ed91aac8d3665d20c22ebb2abac0f100c /lib
parente8fd4d4b8448c1e1dfe56b260af50c191a3f4cdd (diff)
parent09c6a3d23fdcf52b4870dc7b45ceadfb92d4ec6b (diff)
downloadiproute2-8cc6e4e72516bc2e1c83ee145e7f118c5edb1fdf.tar.gz
Merge branch 'main' into next
Signed-off-by: David Ahern <dsahern@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libnetlink.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 7e977a67..6d1b1187 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -210,13 +210,13 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
if (setsockopt(rth->fd, SOL_SOCKET, SO_SNDBUF,
&sndbuf, sizeof(sndbuf)) < 0) {
perror("SO_SNDBUF");
- return -1;
+ goto err;
}
if (setsockopt(rth->fd, SOL_SOCKET, SO_RCVBUF,
&rcvbuf, sizeof(rcvbuf)) < 0) {
perror("SO_RCVBUF");
- return -1;
+ goto err;
}
/* Older kernels may no support extended ACK reporting */
@@ -230,25 +230,28 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions,
if (bind(rth->fd, (struct sockaddr *)&rth->local,
sizeof(rth->local)) < 0) {
perror("Cannot bind netlink socket");
- return -1;
+ goto err;
}
addr_len = sizeof(rth->local);
if (getsockname(rth->fd, (struct sockaddr *)&rth->local,
&addr_len) < 0) {
perror("Cannot getsockname");
- return -1;
+ goto err;
}
if (addr_len != sizeof(rth->local)) {
fprintf(stderr, "Wrong address length %d\n", addr_len);
- return -1;
+ goto err;
}
if (rth->local.nl_family != AF_NETLINK) {
fprintf(stderr, "Wrong address family %d\n",
rth->local.nl_family);
- return -1;
+ goto err;
}
rth->seq = time(NULL);
return 0;
+err:
+ rtnl_close(rth);
+ return -1;
}
int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions)