Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-25 Thread neels
neels has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp()
..


Patch Set 7:

(1 comment)

(submitting old comments that I forgot to submit)

https://gerrit.osmocom.org/c/libosmocore/+/15961/6/src/sockaddr_str.c
File src/sockaddr_str.c:

https://gerrit.osmocom.org/c/libosmocore/+/15961/6/src/sockaddr_str.c@117
PS6, Line 117: if (cmp)
 :  return cmp;
 :  return 0;
> Why this instead of simply "return cmp"?
(patch rework artifact, thx)



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 7
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-Reviewer: osmith 
Gerrit-CC: pespin 
Gerrit-Comment-Date: Mon, 25 Nov 2019 21:58:47 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: osmith 
Gerrit-MessageType: comment


Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-21 Thread neels
neels has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp()
..

add osmo_sockaddr_str_cmp()

Currently planned user: for Distributed GSM in osmo-hlr: setting per-MSC
service addresses in VTY: replace/remove existing entries.

osmo_sockaddr_str_cmp() is useful to catch identical resulting IP addresses,
regardless of differing strings (e.g. '0::' and '::' are equal but differ in
strings).

Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
---
M include/osmocom/core/sockaddr_str.h
M include/osmocom/core/utils.h
M src/sockaddr_str.c
M tests/sockaddr_str/sockaddr_str_test.c
M tests/sockaddr_str/sockaddr_str_test.ok
5 files changed, 678 insertions(+), 0 deletions(-)

Approvals:
  Jenkins Builder: Verified
  neels: Looks good to me, approved



diff --git a/include/osmocom/core/sockaddr_str.h 
b/include/osmocom/core/sockaddr_str.h
index 6dd428c..d7a8cdf 100644
--- a/include/osmocom/core/sockaddr_str.h
+++ b/include/osmocom/core/sockaddr_str.h
@@ -70,6 +70,7 @@

 bool osmo_sockaddr_str_is_set(const struct osmo_sockaddr_str *sockaddr_str);
 bool osmo_sockaddr_str_is_nonzero(const struct osmo_sockaddr_str 
*sockaddr_str);
+int osmo_sockaddr_str_cmp(const struct osmo_sockaddr_str *a, const struct 
osmo_sockaddr_str *b);

 int osmo_sockaddr_str_from_str(struct osmo_sockaddr_str *sockaddr_str, const 
char *ip, uint16_t port);

diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h
index 601bb56..c4e6f5f 100644
--- a/include/osmocom/core/utils.h
+++ b/include/osmocom/core/utils.h
@@ -21,6 +21,8 @@
 #define OSMO_MAX(a, b) ((a) >= (b) ? (a) : (b))
 /*! Return the minimum of two specified values */
 #define OSMO_MIN(a, b) ((a) >= (b) ? (b) : (a))
+/*! Return a typical cmp result for comparable entities a and b. */
+#define OSMO_CMP(a, b) ((a) < (b)? -1 : ((a) > (b)? 1 : 0))
 /*! Stringify the name of a macro x, e.g. an FSM event name.
  * Note: if nested within another preprocessor macro, this will
  * stringify the value of x instead of its name. */
diff --git a/src/sockaddr_str.c b/src/sockaddr_str.c
index f523050..5c548b4 100644
--- a/src/sockaddr_str.c
+++ b/src/sockaddr_str.c
@@ -95,6 +95,80 @@
}
 }

+/*! Compare two osmo_sockaddr_str instances by string comparison.
+ * Compare by strcmp() for the address and compare port numbers, ignore the 
AF_INET/AF_INET6 value.
+ * \param[in] a  left side of comparison.
+ * \param[in] b  right side of comparison.
+ * \return -1 if a < b, 0 if a == b, 1 if a > b.
+ */
+static int osmo_sockaddr_str_cmp_by_string(const struct osmo_sockaddr_str *a, 
const struct osmo_sockaddr_str *b)
+{
+   int cmp;
+   if (a == b)
+   return 0;
+   if (!a)
+   return -1;
+   if (!b)
+   return 1;
+   cmp = strncmp(a->ip, b->ip, sizeof(a->ip));
+   if (cmp)
+   return cmp;
+   return OSMO_CMP(a->port, b->port);
+}
+
+/*! Compare two osmo_sockaddr_str instances by resulting IP address.
+ * Compare IP versions (AF_INET vs AF_INET6), compare resulting IP address 
bytes and compare port numbers.
+ * If the IP address strings cannot be parsed successfully / if the 'af' is 
neither AF_INET nor AF_INET6, fall back to
+ * pure string comparison of the ip address.
+ * \param[in] a  left side of comparison.
+ * \param[in] b  right side of comparison.
+ * \return -1 if a < b, 0 if a == b, 1 if a > b.
+ */
+int osmo_sockaddr_str_cmp(const struct osmo_sockaddr_str *a, const struct 
osmo_sockaddr_str *b)
+{
+   int cmp;
+   uint32_t ipv4_a, ipv4_b;
+   struct in6_addr ipv6_a = {}, ipv6_b = {};
+
+   if (a == b)
+   return 0;
+   if (!a)
+   return -1;
+   if (!b)
+   return 1;
+   cmp = OSMO_CMP(a->af, b->af);
+   if (cmp)
+   return cmp;
+   switch (a->af) {
+   case AF_INET:
+   if (osmo_sockaddr_str_to_32(a, &ipv4_a)
+   || osmo_sockaddr_str_to_32(b, &ipv4_b))
+   goto fallback_to_strcmp;
+   cmp = OSMO_CMP(ipv4_a, ipv4_b);
+   break;
+
+   case AF_INET6:
+   if (osmo_sockaddr_str_to_in6_addr(a, &ipv6_a)
+   || osmo_sockaddr_str_to_in6_addr(b, &ipv6_b))
+   goto fallback_to_strcmp;
+   cmp = memcmp(&ipv6_a, &ipv6_b, sizeof(ipv6_a));
+   break;
+
+   default:
+   goto fallback_to_strcmp;
+   }
+   if (cmp)
+   return cmp;
+
+   cmp = OSMO_CMP(a->port, b->port);
+   if (cmp)
+   return cmp;
+   return 0;
+
+fallback_to_strcmp:
+   return osmo_sockaddr_str_cmp_by_string(a, b);
+}
+
 /*! Distinguish between valid IPv4 and IPv6 strings.
  * This does not verify whether the string is a valid IP address; it assumes 
that the input is a valid IP address, and
  * on that premise return

Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-21 Thread neels
neels has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp()
..


Patch Set 7: Code-Review+2

re-apply earlier CR: there were 2 +1s, the new patch set just fixes a typo and 
does a simpler "return rc" as from review comments.


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 7
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-Reviewer: osmith 
Gerrit-CC: pespin 
Gerrit-Comment-Date: Thu, 21 Nov 2019 21:12:36 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-21 Thread neels
Hello laforge, osmith, Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/libosmocore/+/15961

to look at the new patch set (#7).

Change subject: add osmo_sockaddr_str_cmp()
..

add osmo_sockaddr_str_cmp()

Currently planned user: for Distributed GSM in osmo-hlr: setting per-MSC
service addresses in VTY: replace/remove existing entries.

osmo_sockaddr_str_cmp() is useful to catch identical resulting IP addresses,
regardless of differing strings (e.g. '0::' and '::' are equal but differ in
strings).

Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
---
M include/osmocom/core/sockaddr_str.h
M include/osmocom/core/utils.h
M src/sockaddr_str.c
M tests/sockaddr_str/sockaddr_str_test.c
M tests/sockaddr_str/sockaddr_str_test.ok
5 files changed, 678 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/61/15961/7
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 7
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-Reviewer: osmith 
Gerrit-CC: pespin 
Gerrit-MessageType: newpatchset


Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-18 Thread laforge
laforge has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp()
..


Patch Set 6: Code-Review+1


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 6
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge 
Gerrit-Reviewer: neels 
Gerrit-Reviewer: osmith 
Gerrit-CC: pespin 
Gerrit-Comment-Date: Tue, 19 Nov 2019 00:53:49 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-12 Thread osmith
osmith has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp()
..


Patch Set 6: Code-Review+1

(3 comments)

LGTM, only cosmetics.

https://gerrit.osmocom.org/c/libosmocore/+/15961/6/src/sockaddr_str.c
File src/sockaddr_str.c:

https://gerrit.osmocom.org/c/libosmocore/+/15961/6/src/sockaddr_str.c@99
PS6, Line 99: ingore
(ignore)


https://gerrit.osmocom.org/c/libosmocore/+/15961/6/src/sockaddr_str.c@117
PS6, Line 117: if (cmp)
 :  return cmp;
 :  return 0;
Why this instead of simply "return cmp"?


https://gerrit.osmocom.org/c/libosmocore/+/15961/6/tests/sockaddr_str/sockaddr_str_test.c
File tests/sockaddr_str/sockaddr_str_test.c:

https://gerrit.osmocom.org/c/libosmocore/+/15961/6/tests/sockaddr_str/sockaddr_str_test.c@257
PS6, Line 257: 0?
(missing space)



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 6
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: neels 
Gerrit-Reviewer: osmith 
Gerrit-CC: pespin 
Gerrit-Comment-Date: Tue, 12 Nov 2019 08:24:27 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in libosmocore[master]: add osmo_sockaddr_str_cmp()

2019-11-11 Thread neels
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/libosmocore/+/15961

to look at the new patch set (#5).

Change subject: add osmo_sockaddr_str_cmp()
..

add osmo_sockaddr_str_cmp()

Currently planned user: for Distributed GSM in osmo-hlr: setting per-MSC
service addresses in VTY: replace/remove existing entries.

osmo_sockaddr_str_cmp() is useful to catch identical resulting IP addresses,
regardless of differing strings (e.g. '0::' and '::' are equal but differ in
strings).

Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
---
M include/osmocom/core/sockaddr_str.h
M include/osmocom/core/utils.h
M src/sockaddr_str.c
M tests/sockaddr_str/sockaddr_str_test.c
M tests/sockaddr_str/sockaddr_str_test.ok
5 files changed, 681 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/61/15961/5
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 5
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: neels 
Gerrit-CC: pespin 
Gerrit-MessageType: newpatchset


Change in libosmocore[master]: add osmo_sockaddr_str_cmp() and _str_ip_cmp()

2019-11-11 Thread neels
neels has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp() and _str_ip_cmp()
..


Patch Set 4:

(1 comment)

https://gerrit.osmocom.org/c/libosmocore/+/15961/4/src/sockaddr_str.c
File src/sockaddr_str.c:

https://gerrit.osmocom.org/c/libosmocore/+/15961/4/src/sockaddr_str.c@104
PS4, Line 104: int osmo_sockaddr_str_cmp(const struct osmo_sockaddr_str *a, 
const struct osmo_sockaddr_str *b)
> It's not clear to me why do you want to have this one as a public API having 
> the other. […]
This patch first had only this one, and later I figured it would be very useful 
to also compare by actual resulting IP address.

I figured, to sort a list of addresses by the string representation chosen by 
the user, then this cmp() would be more desirable, so I was just going to keep 
this.

indeed I don't currently have a caller for it...

I'm slightly reluctant, but fair enough then. In that case I'll just have one 
osmo_sockaddr_str_cmp() that compares resulting IP addresses and keep the pure 
string variant static. If we need it later it can be called 
osmo_sockaddr_str_cmp_by_string() or something.



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: neels 
Gerrit-CC: pespin 
Gerrit-Comment-Date: Mon, 11 Nov 2019 18:43:05 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin 
Gerrit-MessageType: comment


Change in libosmocore[master]: add osmo_sockaddr_str_cmp() and _str_ip_cmp()

2019-11-05 Thread pespin
pespin has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/15961 )

Change subject: add osmo_sockaddr_str_cmp() and _str_ip_cmp()
..


Patch Set 4:

(1 comment)

https://gerrit.osmocom.org/c/libosmocore/+/15961/4/src/sockaddr_str.c
File src/sockaddr_str.c:

https://gerrit.osmocom.org/c/libosmocore/+/15961/4/src/sockaddr_str.c@104
PS4, Line 104: int osmo_sockaddr_str_cmp(const struct osmo_sockaddr_str *a, 
const struct osmo_sockaddr_str *b)
It's not clear to me why do you want to have this one as a public API having 
the other. I'd keep it as static until there's a case for it.



--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-CC: pespin 
Gerrit-Comment-Date: Tue, 05 Nov 2019 15:30:27 +
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment


Change in libosmocore[master]: add osmo_sockaddr_str_cmp() and _str_ip_cmp()

2019-11-04 Thread neels
Hello Jenkins Builder,

I'd like you to reexamine a change. Please visit

https://gerrit.osmocom.org/c/libosmocore/+/15961

to look at the new patch set (#4).

Change subject: add osmo_sockaddr_str_cmp() and _str_ip_cmp()
..

add osmo_sockaddr_str_cmp() and _str_ip_cmp()

Currently planned user: for Distributed GSM in osmo-hlr: setting per-MSC
service addresses in VTY: replace/remove existing entries.

osmo_sockaddr_str_cmp() is useful to sort existing entries, while showing
possible duplicates evaluating to the same actual IP address bytes.

osmo_sockaddr_str_ip_cmp() is useful to catch identical resulting IP addresses,
regardless of differing strings (e.g. '0::' and '::' are equal but differ in
strings).

Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
---
M include/osmocom/core/sockaddr_str.h
M include/osmocom/core/utils.h
M src/sockaddr_str.c
M tests/sockaddr_str/sockaddr_str_test.c
M tests/sockaddr_str/sockaddr_str_test.ok
5 files changed, 1,263 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/61/15961/4
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15961
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I0dbc1cf707098dcda75f8e07c1b936951f9f9501
Gerrit-Change-Number: 15961
Gerrit-PatchSet: 4
Gerrit-Owner: neels 
Gerrit-Reviewer: Jenkins Builder
Gerrit-MessageType: newpatchset