ip: move get_failed blocks

Rather than doing goto back into the middle of an earlier
if() statement. Move the error returns to the end of the functions
to follow kernel coding practice.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Stephen Hemminger 2023-11-17 09:16:14 -08:00
parent 2c3ebb2ae0
commit e6e5f774f4
6 changed files with 42 additions and 42 deletions

View File

@ -109,13 +109,8 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
const struct rtattr *rta;
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
fprintf(stderr,
"Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
if (rtnl_talk(&rth, &req.n, &answer) < 0)
goto get_failed;
len = answer->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
@ -423,6 +418,11 @@ get_failed:
addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
return 0;
get_failed:
fprintf(stderr, "Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])

View File

@ -111,13 +111,8 @@ static int gre_parse_opt(struct link_util *lu, int argc, char **argv,
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
const struct rtattr *rta;
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
fprintf(stderr,
"Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
if (rtnl_talk(&rth, &req.n, &answer) < 0)
goto get_failed;
len = answer->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
@ -441,6 +436,11 @@ get_failed:
addattr16(n, 1024, IFLA_GRE_ENCAP_DPORT, htons(encapdport));
return 0;
get_failed:
fprintf(stderr, "Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])

View File

@ -97,13 +97,8 @@ static int ip6tunnel_parse_opt(struct link_util *lu, int argc, char **argv,
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
const struct rtattr *rta;
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
fprintf(stderr,
"Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
if (rtnl_talk(&rth, &req.n, &answer) < 0)
goto get_failed;
len = answer->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
@ -326,6 +321,11 @@ get_failed:
addattr16(n, 1024, IFLA_IPTUN_ENCAP_DPORT, htons(encapdport));
return 0;
get_failed:
fprintf(stderr, "Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])

View File

@ -101,13 +101,8 @@ static int iptunnel_parse_opt(struct link_util *lu, int argc, char **argv,
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
const struct rtattr *rta;
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
fprintf(stderr,
"Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
if (rtnl_talk(&rth, &req.n, &answer) < 0)
goto get_failed;
len = answer->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
@ -350,6 +345,11 @@ get_failed:
}
return 0;
get_failed:
fprintf(stderr, "Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])

View File

@ -65,13 +65,8 @@ static int vti_parse_opt(struct link_util *lu, int argc, char **argv,
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
const struct rtattr *rta;
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
fprintf(stderr,
"Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
if (rtnl_talk(&rth, &req.n, &answer) < 0)
goto get_failed;
len = answer->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
@ -157,6 +152,11 @@ get_failed:
addattr32(n, 1024, IFLA_VTI_LINK, link);
return 0;
get_failed:
fprintf(stderr, "Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])

View File

@ -67,13 +67,8 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv,
if (!(n->nlmsg_flags & NLM_F_CREATE)) {
const struct rtattr *rta;
if (rtnl_talk(&rth, &req.n, &answer) < 0) {
get_failed:
fprintf(stderr,
"Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
if (rtnl_talk(&rth, &req.n, &answer) < 0)
goto get_failed;
len = answer->nlmsg_len;
len -= NLMSG_LENGTH(sizeof(*ifi));
@ -159,6 +154,11 @@ get_failed:
addattr32(n, 1024, IFLA_VTI_LINK, link);
return 0;
get_failed:
fprintf(stderr, "Failed to get existing tunnel info.\n");
free(answer);
return -1;
}
static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])