Skip to content

Commit

Permalink
gatekeeper: polish print_flow_err_msg() and convert_ip_to_str()
Browse files Browse the repository at this point in the history
  • Loading branch information
AltraMayor committed Jul 29, 2022
1 parent 31df1a0 commit 9a616fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
26 changes: 13 additions & 13 deletions lib/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,35 @@ print_flow_err_msg(const struct ip_flow *flow, const char *err_msg)
RTE_BUILD_BUG_ON(sizeof(dst) < sizeof(INVALID_IP_ADDR_STRING));

if (flow->proto == RTE_ETHER_TYPE_IPV4) {
if (inet_ntop(AF_INET, &flow->f.v4.src,
src, sizeof(src)) == NULL) {
G_LOG(ERR, "%s(): failed to convert source IPv4 address to a string errno=%i: %s\n",
if (unlikely(inet_ntop(AF_INET, &flow->f.v4.src,
src, sizeof(src)) == NULL)) {
G_LOG(ERR, "%s(): failed to convert source IPv4 address to a string (errno=%i): %s\n",
__func__, errno, strerror(errno));
strcpy(src, INVALID_IP_ADDR_STRING);
}

if (inet_ntop(AF_INET, &flow->f.v4.dst,
dst, sizeof(dst)) == NULL) {
G_LOG(ERR, "%s(): failed to convert destination IPv4 address to a string errno=%i: %s\n",
if (unlikely(inet_ntop(AF_INET, &flow->f.v4.dst,
dst, sizeof(dst)) == NULL)) {
G_LOG(ERR, "%s(): failed to convert destination IPv4 address to a string (errno=%i): %s\n",
__func__, errno, strerror(errno));
strcpy(dst, INVALID_IP_ADDR_STRING);
}
} else if (likely(flow->proto == RTE_ETHER_TYPE_IPV6)) {
if (inet_ntop(AF_INET6, flow->f.v6.src.s6_addr,
src, sizeof(src)) == NULL) {
G_LOG(ERR, "%s(): failed to convert source IPv6 address to a string errno=%i: %s\n",
if (unlikely(inet_ntop(AF_INET6, flow->f.v6.src.s6_addr,
src, sizeof(src)) == NULL)) {
G_LOG(ERR, "%s(): failed to convert source IPv6 address to a string (errno=%i): %s\n",
__func__, errno, strerror(errno));
strcpy(src, INVALID_IP_ADDR_STRING);
}

if (inet_ntop(AF_INET6, flow->f.v6.dst.s6_addr,
dst, sizeof(dst)) == NULL) {
G_LOG(ERR, "%s(): failed to convert destination IPv6 address to a string errno=%i: %s\n",
if (unlikely(inet_ntop(AF_INET6, flow->f.v6.dst.s6_addr,
dst, sizeof(dst)) == NULL)) {
G_LOG(ERR, "%s(): failed to convert destination IPv6 address to a string (errno=%i): %s\n",
__func__, errno, strerror(errno));
strcpy(dst, INVALID_IP_ADDR_STRING);
}
} else {
G_LOG(ERR,
G_LOG(CRIT,
"flow: %s; while trying to show flow data, an unknown flow type %hu was found\n",
err_msg, flow->proto);
return;
Expand Down
28 changes: 16 additions & 12 deletions lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,24 +747,28 @@ int
convert_ip_to_str(const struct ipaddr *ip_addr, char *res, int n)
{
if (ip_addr->proto == RTE_ETHER_TYPE_IPV4) {
if (inet_ntop(AF_INET, &ip_addr->ip.v4, res, n) == NULL) {
G_LOG(ERR, "net: %s: failed to convert a number to an IPv4 address (%s)\n",
__func__, strerror(errno));
if (unlikely(inet_ntop(AF_INET, &ip_addr->ip.v4, res, n)
== NULL)) {
G_LOG(ERR, "%s(): failed to convert an IPv4 address to string (errno=%i): %s\n",
__func__, errno, strerror(errno));
return -1;
}
} else if (likely(ip_addr->proto == RTE_ETHER_TYPE_IPV6)) {
if (inet_ntop(AF_INET6, &ip_addr->ip.v6, res, n) == NULL) {
G_LOG(ERR, "net: %s: failed to convert a number to an IPv6 address (%s)\n",
__func__, strerror(errno));
return 0;
}

if (likely(ip_addr->proto == RTE_ETHER_TYPE_IPV6)) {
if (unlikely(inet_ntop(AF_INET6, &ip_addr->ip.v6, res, n)
== NULL)) {
G_LOG(ERR, "%s(): failed to convert an IPv6 address to string (errno=%i): %s\n",
__func__, errno, strerror(errno));
return -1;
}
} else {
G_LOG(ERR, "net: unexpected condition at %s: unknown IP type %hu\n",
__func__, ip_addr->proto);
return -1;
return 0;
}

return 0;
G_LOG(ERR, "%s(): unexpected condition: unknown IP type %hu\n",
__func__, ip_addr->proto);
return -1;
}

static int
Expand Down

0 comments on commit 9a616fa

Please sign in to comment.