Attention is currently required from: laforge, fixeria, msuraev.
Hello Jenkins Builder, laforge, fixeria, msuraev,
I'd like you to do a code review. Please visit
https://gerrit.osmocom.org/c/libosmocore/+/29122
to review the following change.
Change subject: Revert "Add function to guess AF_UNSPEC address"
......................................................................
Revert "Add function to guess AF_UNSPEC address"
This reverts commit a4063efa7deb6632c228037c47effca22ad0f781.
Reason for revert: It is not possible to guess the IP address
family from uninitialized memory. This function simply glorifies
random noise into an IPv6 address. It makes no sense to have it.
Change-Id: Ifadd614604cf9d0c2ed1a405493c1c3fcb37ae23
---
M include/osmocom/core/sockaddr_str.h
M src/sockaddr_str.c
2 files changed, 2 insertions(+), 35 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/22/29122/1
diff --git a/include/osmocom/core/sockaddr_str.h b/include/osmocom/core/sockaddr_str.h
index a46ad59..f474fa0 100644
--- a/include/osmocom/core/sockaddr_str.h
+++ b/include/osmocom/core/sockaddr_str.h
@@ -41,7 +41,6 @@
*/
int osmo_ip_str_type(const char *ip);
-unsigned osmo_sockaddr_guess_unspec(const struct sockaddr *src);
struct osmo_sockaddr_str {
/*! AF_INET for IPv4 address, or AF_INET6 for IPv6 address. */
diff --git a/src/sockaddr_str.c b/src/sockaddr_str.c
index 70927a7..9f1e897 100644
--- a/src/sockaddr_str.c
+++ b/src/sockaddr_str.c
@@ -184,38 +184,6 @@
return AF_UNSPEC;
}
-/*! Guess whether struct sockaddr with AF_UNSPEC family has valid IPv4 or IPv6 address.
- * The IPv6 is tried first to take into account "IPv4 mapped addresses".
- * \param[in] src Generic struct sockaddr pointer.
- * \return AF_INET or AF_INET6, AF_UNSPEC or original sa_family which are unsigned type according to <sys/socket.h>.
- */
-unsigned osmo_sockaddr_guess_unspec(const struct sockaddr *src)
-{
- int rc;
- struct osmo_sockaddr_str sa;
- struct osmo_sockaddr_str *tmp = &sa;
- const struct sockaddr_in6 *src6 = (const struct sockaddr_in6 *)src;
- const struct sockaddr_in *src4 = (const struct sockaddr_in *)src;
-
- if (!src)
- return AF_UNSPEC;
-
- if (src->sa_family != AF_UNSPEC)
- return src->sa_family;
-
- /* IPv6? */
- rc = osmo_sockaddr_str_from_in6_addr(tmp, &src6->sin6_addr, osmo_ntohs(src6->sin6_port));
- if (rc == 0 && osmo_ip_str_type(tmp->ip) == AF_INET6)
- return AF_INET6;
-
- /* IPv4? */
- rc = osmo_sockaddr_str_from_in_addr(tmp, &src4->sin_addr, osmo_ntohs(src4->sin_port));
- if (rc == 0 && osmo_ip_str_type(tmp->ip) == AF_INET)
- return AF_INET;
-
- return AF_UNSPEC;
-}
-
/*! Safely copy the given ip string to sockaddr_str, classify to AF_INET or AF_INET6.
* Data will be written to sockaddr_str even if an error is returned.
* \param[out] sockaddr_str The instance to copy to.
@@ -349,7 +317,7 @@
return -ENOSPC;
if (!src)
return -EINVAL;
- if (src->sin_family != AF_INET && osmo_sockaddr_guess_unspec((const struct sockaddr *)src) != AF_INET)
+ if (src->sin_family != AF_INET)
return -EINVAL;
return osmo_sockaddr_str_from_in_addr(sockaddr_str, &src->sin_addr, osmo_ntohs(src->sin_port));
}
@@ -365,7 +333,7 @@
return -ENOSPC;
if (!src)
return -EINVAL;
- if (src->sin6_family != AF_INET6 && osmo_sockaddr_guess_unspec((const struct sockaddr *)src) != AF_INET6)
+ if (src->sin6_family != AF_INET6)
return -EINVAL;
return osmo_sockaddr_str_from_in6_addr(sockaddr_str, &src->sin6_addr, osmo_ntohs(src->sin6_port));
}
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/29122
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ifadd614604cf9d0c2ed1a405493c1c3fcb37ae23
Gerrit-Change-Number: 29122
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: msuraev <msuraev(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Attention: msuraev <msuraev(a)sysmocom.de>
Gerrit-MessageType: newchange
Attention is currently required from: msuraev.
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/28994 )
Change subject: Add function to guess AF_UNSPEC address
......................................................................
Patch Set 5:
(1 comment)
Patchset:
PS5:
I'm sorry that I am late for code review here.
As Pau has explained, this function has a flaw in principles, and it makes no sense to have it.
I would welcome if we could revert this commit before the next release.
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/28994
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I1c90c56ce832f53b65e0d18d3cea94621c02a69a
Gerrit-Change-Number: 28994
Gerrit-PatchSet: 5
Gerrit-Owner: msuraev <msuraev(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: msuraev <msuraev(a)sysmocom.de>
Gerrit-CC: neels <nhofmeyr(a)sysmocom.de>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: msuraev <msuraev(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 17 Aug 2022 00:55:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: pespin, msuraev, dexter.
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/28995 )
Change subject: Make osmo_sockaddr_str_from_sockaddr() less picky
......................................................................
Patch Set 8: Code-Review-2
(1 comment)
Patchset:
PS8:
AF_UNSPEC is not valid and should return an error rc. Do not turn uninitialized memory into an IPv6 address representation!
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/28995
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I36f20701663c3c7eae7fedc6551da44800b325bf
Gerrit-Change-Number: 28995
Gerrit-PatchSet: 8
Gerrit-Owner: msuraev <msuraev(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: dexter <pmaier(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: msuraev <msuraev(a)sysmocom.de>
Gerrit-Attention: dexter <pmaier(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 17 Aug 2022 00:52:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: msuraev.
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/28993 )
Change subject: Use osmo_sockaddr_strs_to_str() for multiaddr helper
......................................................................
Patch Set 8: Code-Review-1
(3 comments)
Patchset:
PS8:
the code added in https://gerrit.osmocom.org/c/libosmocore/+/28992 should move to this function, as indicated below
File src/socket.c:
https://gerrit.osmocom.org/c/libosmocore/+/28993/comment/dda0b532_5a697daa
PS8, Line 208: * buf_len >= 2: (hostA|hostB|...|...)
(this doc is wrong)
https://gerrit.osmocom.org/c/libosmocore/+/28993/comment/16eeb34d_42c05fa7
PS8, Line 211: {
if you use an implementation like this here, we don't need to add osmo_sockaddr_strs_to_str() at all and save a lot of dynamic allocations:
struct osmo_strbuf sb = { ... };
if (i != 1)
OSMO_STRBUF_PRINTF(sb, "(");
for (...) {
struct osmo_sockaddr_str ss;
if (i)
OSMO_STRBUF_PRINTF(sb, "|");
osmo_sockaddr_str_from_str2(&ss, hosts[i]);
OSMO_STRBUF_PRINTF(sb, OSMO_SOCKADDR_STR_FMT, OSMO_SOCKADDR_STR_FMT_ARGS(&ss));
}
if (i != 1)
OSMO_STRBUF_PRINTF(sb, ")");
return sb.chars_needed;
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/28993
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Icef53fe4b6e51563d97a1bc48001d67679b3b6e9
Gerrit-Change-Number: 28993
Gerrit-PatchSet: 8
Gerrit-Owner: msuraev <msuraev(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: msuraev <msuraev(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 17 Aug 2022 00:48:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: msuraev.
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/28992 )
Change subject: Add osmo_sockaddr_strs_to_str()
......................................................................
Patch Set 8:
(9 comments)
Patchset:
PS8:
I'm sorry that I'm late for this patch review.
This patch has a number of rough edges,
I would welcome if we could revert it and get some more review cycles.
File src/sockaddr_str.c:
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/6219adc6_145bfcb8
PS8, Line 547: * buf_len >= 2: (hostA|hostB|...|...)
buf_len is the buffer size of the output string buffer *buf.
A buf_len == 0 cannot return any "()" string, it has zero size.
buf_len == 1 cannot contain "hostA".
Did you mean sa_str_count?
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/d27293a9_acbb2b9e
PS8, Line 555: int osmo_sockaddr_strs_to_str(char *buf, size_t buf_len, const struct osmo_sockaddr_str **sa_str, size_t sa_str_count)
i find it odd that you want to pass an array of osmo_sockaddr_str POINTERS,
instead of an array of osmo_sockaddr_str instances.
i.e. i would expect an arg like 'const struct osmo_sockaddr_str *sa_strs',
not '**'.
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/316d840f_674d4fd8
PS8, Line 562: return -ENOMEM;
this check should not be here. The idea is to always return the nr of characters needed to output the full string, regardless of the underlying buffer length. If you return -ENOMEM on some specific buffer lengths, you destroy the ability of finding a sufficient buffer length from the return value. The OSMO_STRBUF macros deal with all cases of insufficient buffer length, just let it play through to the end, so that the proper sb.chars_needed is returned.
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/fdcd0fdd_b3bde8dc
PS8, Line 567: for (i = 0; i < sa_str_count; i++) {
for (...) {
if (i)
OSMO_STRBUF_PRINTF(sb, "|");
if (sa_str[i])
OSMO_STRBUF_PRINTF(sb, OSMO_SOCKADDR_STR_NO_PORT_FMT,
OSMO_SOCKADDR_STR_NO_PORT_FMT_ARGS(sa_str[i]));
}
if (sa_str_count != 1)
OSMO_STRBUF_PRINTF(sb, ")");
File tests/sockaddr_str/sockaddr_str_test.c:
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/078d4d8b_e4da2349
PS8, Line 28: #include <osmocom/core/logging.h>
why add application and logging?
there should be no select loop.
nothing about osmo_sockaddr_str should ever cause osmocom logging.
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/a57e7473_891bec86
PS8, Line 268: struct osmo_sockaddr_str *sa_strs[OSMO_SOCK_MAX_ADDRS];
(...and here just a struct osmo_sockaddr_str sa_strs[N], no need to talloc instances below)
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/998f5771_bdf3e063
PS8, Line 271: for (i = 0, j = 0; j < count && i < OSMO_SOCK_MAX_ADDRS; j++) {//ARRAY_SIZE(oip_data)
can we drop the // comments?
https://gerrit.osmocom.org/c/libosmocore/+/28992/comment/146c54fa_9c1e2c65
PS8, Line 290: };
why add logging infrastructure??
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/28992
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ic0d7c08f669994e37a2314555ecac85d28c42c89
Gerrit-Change-Number: 28992
Gerrit-PatchSet: 8
Gerrit-Owner: msuraev <msuraev(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: msuraev <msuraev(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Attention: msuraev <msuraev(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 17 Aug 2022 00:34:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment