Change in osmo-sysmon[master]: Add generic host config and related helpers

2019-02-01 Thread Pau Espin Pedrol
Pau Espin Pedrol has posted comments on this change. ( 
https://gerrit.osmocom.org/12761 )

Change subject: Add generic host config and related helpers
..


Patch Set 5: Code-Review-1

(6 comments)

Without looking at next patches, I have the feeling most of these APIs are so 
simple they are really not needed. Having the struct would be enough. Also I 
don't like this way of splitting between commits where a bunch of APIs not 
being used anywhere are added in one commit.

https://gerrit.osmocom.org/#/c/12761/5/contrib/jenkins.sh
File contrib/jenkins.sh:

https://gerrit.osmocom.org/#/c/12761/5/contrib/jenkins.sh@27
PS5, Line 27: export PATH="$inst/bin:$PATH"
why is this line needed?


https://gerrit.osmocom.org/#/c/12761/5/src/client.c
File src/client.c:

https://gerrit.osmocom.org/#/c/12761/5/src/client.c@34
PS5, Line 34: #define MATCH(a, b) (strcmp(a, b) != 0) ? false : true
can be simplified: #define MATCH(a, b) (strcmp(a,b) == 0)

which makes me think if we really need this MATCH statement...


https://gerrit.osmocom.org/#/c/12761/5/src/client.c@38
PS5, Line 38:   bool m_name = MATCH(match, cfg->name), m_host = MATCH(match, 
cfg->remote_host);
separate lines please.


https://gerrit.osmocom.org/#/c/12761/5/src/client.c@56
PS5, Line 56: struct host_cfg *make_config(void *ctx, const char *name, const 
char *host, uint16_t port)
This is basically a constructor/allocator, so better name it like we usually 
do, like talloc_host_cfg or host_cfg_alloc.


https://gerrit.osmocom.org/#/c/12761/5/src/client.c@79
PS5, Line 79: char *get_authority(void *ctx, const struct host_cfg *cfg)
It's allocating something and the method is not const, so I'd better name it 
"create_authority" or "make_authority".


https://gerrit.osmocom.org/#/c/12761/5/src/client.c@81
PS5, Line 81:   if (!cfg->remote_host)
Is this really needed?



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

Gerrit-Project: osmo-sysmon
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ie321655a92cdbefbfaa056ac0d583397c83beccb
Gerrit-Change-Number: 12761
Gerrit-PatchSet: 5
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Reviewer: Pau Espin Pedrol 
Gerrit-Comment-Date: Fri, 01 Feb 2019 16:06:44 +
Gerrit-HasComments: Yes
Gerrit-HasLabels: Yes


Change in osmo-sysmon[master]: Add generic host config and related helpers

2019-01-31 Thread Max
Max has posted comments on this change. ( https://gerrit.osmocom.org/12761 )

Change subject: Add generic host config and related helpers
..


Patch Set 5:

This change is ready for review.


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

Gerrit-Project: osmo-sysmon
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Ie321655a92cdbefbfaa056ac0d583397c83beccb
Gerrit-Change-Number: 12761
Gerrit-PatchSet: 5
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)
Gerrit-Reviewer: Max 
Gerrit-Comment-Date: Thu, 31 Jan 2019 22:30:06 +
Gerrit-HasComments: No
Gerrit-HasLabels: No


Change in osmo-sysmon[master]: Add generic host config and related helpers

2019-01-31 Thread Max
Hello Jenkins Builder,

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

https://gerrit.osmocom.org/12761

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

Change subject: Add generic host config and related helpers
..

Add generic host config and related helpers

This will be used in follow-up patches as a generic way to store remote
host related configuration data by several TCP-based probes.

Change-Id: Ie321655a92cdbefbfaa056ac0d583397c83beccb
---
M configure.ac
M src/Makefile.am
A src/client.c
A src/client.h
4 files changed, 131 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-sysmon refs/changes/61/12761/2
--
To view, visit https://gerrit.osmocom.org/12761
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sysmon
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ie321655a92cdbefbfaa056ac0d583397c83beccb
Gerrit-Change-Number: 12761
Gerrit-PatchSet: 2
Gerrit-Owner: Max 
Gerrit-Reviewer: Jenkins Builder (102)


Change in osmo-sysmon[master]: Add generic host config and related helpers

2019-01-31 Thread Max
Max has uploaded this change for review. ( https://gerrit.osmocom.org/12761


Change subject: Add generic host config and related helpers
..

Add generic host config and related helpers

This will be used in follow-up patches as a generic way to store remote
host related configuration data by several TCP-based probes.

Change-Id: Ie321655a92cdbefbfaa056ac0d583397c83beccb
---
M src/Makefile.am
A src/client.c
A src/client.h
3 files changed, 130 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sysmon refs/changes/61/12761/1

diff --git a/src/Makefile.am b/src/Makefile.am
index d0d6a22..e38b70e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@
-Wall \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOGSM_CFLAGS) \
+   $(LIBOSMONETIF_CFLAGS) \
$(NULL)

 AM_LDFLAGS = \
@@ -21,8 +22,8 @@
$(NULL)

 noinst_LTLIBRARIES = libintern.la
-libintern_la_SOURCES = simple_ctrl.c
-libintern_la_LIBADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS)
+libintern_la_SOURCES = simple_ctrl.c client.c
+libintern_la_LIBADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) 
$(LIBOSMONETIF_LIBS)

 osmo_sysmon_CFLAGS = $(LIBMNL_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOPING_CFLAGS) 
$(AM_CFLAGS)

@@ -44,6 +45,7 @@

 noinst_HEADERS = \
osysmon.h \
+   client.h \
simple_ctrl.h \
value_node.h \
$(NULL)
diff --git a/src/client.c b/src/client.c
new file mode 100644
index 000..25db885
--- /dev/null
+++ b/src/client.c
@@ -0,0 +1,96 @@
+/* Generic client structure and related helpers */
+
+/* (C) 2018 by Harald Welte 
+ * (C) 2019 by sysmocom - s.f.m.c. GmbH.
+ * All Rights Reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA  02110-1301, USA.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "client.h"
+
+#define MATCH(a, b) (strcmp(a, b) != 0) ? false : true
+
+bool match_config(const struct host_cfg *cfg, const char *match, enum 
match_kind k)
+{
+   bool m_name = MATCH(match, cfg->name), m_host = MATCH(match, 
cfg->remote_host);
+
+   switch (k) {
+   case MATCH_NAME:
+   return m_name;
+   case MATCH_HOST:
+   return m_host;
+   case MATCH_EITHER:
+   return m_name | m_host;
+   case MATCH_BOTH:
+   return m_name & m_host;
+   default:
+   return false;
+   }
+
+   return false;
+}
+
+struct host_cfg *make_config(void *ctx, const char *name, const char *host, 
uint16_t port)
+{
+   struct host_cfg *cfg = talloc_zero(ctx, struct host_cfg);
+   if (!cfg)
+   return NULL;
+
+   cfg->name = talloc_strdup(cfg, name);
+   cfg->remote_host = talloc_strdup(cfg, host);
+   cfg->remote_port = port;
+
+   return cfg;
+}
+
+void update_name(struct host_cfg *cfg, const char *new_name)
+{
+   osmo_talloc_replace_string(cfg, (char **)&cfg->name, new_name);
+}
+
+void update_host(struct host_cfg *cfg, const char *new_host)
+{
+   osmo_talloc_replace_string(cfg, (char **)&cfg->remote_host, new_host);
+}
+
+char *get_authority(void *ctx, const struct host_cfg *cfg)
+{
+   if (!cfg->remote_host)
+   return NULL;
+
+   return talloc_asprintf(ctx, "%s:%u", cfg->remote_host, 
cfg->remote_port);
+}
+
+struct osmo_stream_cli *make_tcp_client(struct host_cfg *cfg)
+{
+   struct osmo_stream_cli *cl = osmo_stream_cli_create(cfg);
+   if (cl) {
+   osmo_stream_cli_set_addr(cl, cfg->remote_host);
+   osmo_stream_cli_set_port(cl, cfg->remote_port);
+   }
+
+   return cl;
+}
diff --git a/src/client.h b/src/client.h
new file mode 100644
index 000..9e69fef
--- /dev/null
+++ b/src/client.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include 
+#include 
+
+enum match_kind {
+   MATCH_NAME,
+   MATCH_HOST,
+   MATCH_BOTH,
+   MATCH_EITHER,
+};
+
+/* a client config */
+struct host_cfg {
+   /* name of this client */
+   const char *name;
+   /* remote host/IP */
+   const char *remote_host;
+   /* remote port */
+   uint16_t remote_port;
+};
+
+struct host_cfg *make_config(void *ctx, const char *name, const char *host, 
uint16_t port);
+bool m