pespin has submitted this change. (
https://gerrit.osmocom.org/c/osmo-pcap/+/39167?usp=email )
Change subject: pcap-client: Alloc default client conn similarly to other ones
......................................................................
pcap-client: Alloc default client conn similarly to other ones
Allocate the 1st default conn the same way as the other ones.
The only real difference between the 1st one and the subsequent ones is
how is it represented in the VTY tree.
Change-Id: I4ead7b1b04a97a329cd1a299bde9de18b5f643a7
---
M include/osmo-pcap/osmo_pcap_client.h
M src/osmo_client_core.c
M src/osmo_client_main.c
M src/osmo_client_vty.c
4 files changed, 18 insertions(+), 24 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, but someone else must approve
fixeria: Looks good to me, approved
diff --git a/include/osmo-pcap/osmo_pcap_client.h b/include/osmo-pcap/osmo_pcap_client.h
index 5bc203a..159e6ae 100644
--- a/include/osmo-pcap/osmo_pcap_client.h
+++ b/include/osmo-pcap/osmo_pcap_client.h
@@ -99,7 +99,7 @@
int snaplen;
struct osmo_fd fd;
- struct osmo_pcap_client_conn conn;
+ struct osmo_pcap_client_conn *conn;
struct llist_head conns;
/* statistics */
@@ -126,4 +126,4 @@
struct osmo_pcap_client_conn *osmo_client_find_or_create_conn(struct osmo_pcap_client *,
const char *name);
struct osmo_pcap_client_conn *osmo_client_find_conn(struct osmo_pcap_client *, const char
*name);
-void osmo_client_conn_init(struct osmo_pcap_client_conn *conn, struct osmo_pcap_client
*client);
+struct osmo_pcap_client_conn *osmo_client_conn_alloc(struct osmo_pcap_client *client,
const char *name);
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index f858e17..931dd98 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -168,7 +168,6 @@
if (!can_forward_packet(client, &hdr, data))
return 0;
- osmo_client_send_data(&client->conn, &hdr, data);
llist_for_each_entry(conn, &client->conns, entry)
osmo_client_send_data(conn, &hdr, data);
return 0;
@@ -318,7 +317,6 @@
client->pcap_stat_timer.cb = pcap_check_stats_cb;
pcap_check_stats_cb(client);
- osmo_client_send_link(&client->conn);
llist_for_each_entry(conn, &client->conns, entry)
osmo_client_send_link(conn);
@@ -336,15 +334,6 @@
return osmo_install_filter(client);
}
-void osmo_client_conn_init(struct osmo_pcap_client_conn *conn,
- struct osmo_pcap_client *client)
-{
- conn->client = client;
- conn->tls_verify = true;
- osmo_wqueue_init(&conn->wqueue, WQUEUE_MAXLEN_DEFAULT);
- conn->wqueue.bfd.fd = -1;
-}
-
struct osmo_pcap_client *osmo_pcap_client_alloc(void *tall_ctx)
{
struct osmo_pcap_client *client;
@@ -391,7 +380,11 @@
conn->name = talloc_strdup(conn, name);
OSMO_ASSERT(conn->name);
- osmo_client_conn_init(conn, client);
+ conn->client = client;
+ conn->tls_verify = true;
+ osmo_wqueue_init(&conn->wqueue, WQUEUE_MAXLEN_DEFAULT);
+ conn->wqueue.bfd.fd = -1;
+
llist_add_tail(&conn->entry, &client->conns);
return conn;
}
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index c523df3..d8d7a07 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -261,10 +261,6 @@
exit(1);
}
- /* initialize the queue */
- osmo_client_conn_init(&pcap_client->conn, pcap_client);
- pcap_client->conn.name = "default";
-
/* initialize the stats interface */
pcap_client->ctrg = rate_ctr_group_alloc(pcap_client,
&pcap_client_ctr_group_desc, 0);
if (!pcap_client->ctrg) {
@@ -272,6 +268,9 @@
exit(1);
}
+ /* Default conn, always present. */
+ pcap_client->conn = osmo_client_conn_alloc(pcap_client, "default");
+
if (vty_read_config_file(config_file, NULL) < 0) {
LOGP(DCLIENT, LOGL_ERROR,
"Failed to parse the config file: %s\n", config_file);
@@ -286,8 +285,8 @@
/* attempt to connect to the remote */
- if (pcap_client->conn.srv_ip && pcap_client->conn.srv_port > 0)
- osmo_client_connect(&pcap_client->conn);
+ if (pcap_client->conn->srv_ip && pcap_client->conn->srv_port >
0)
+ osmo_client_connect(pcap_client->conn);
if (daemonize) {
rc = osmo_daemonize();
diff --git a/src/osmo_client_vty.c b/src/osmo_client_vty.c
index 8e21d67..8888e66 100644
--- a/src/osmo_client_vty.c
+++ b/src/osmo_client_vty.c
@@ -40,7 +40,7 @@
static struct osmo_pcap_client_conn *get_conn(struct vty *vty)
{
if (vty->node == CLIENT_NODE)
- return &pcap_client->conn;
+ return pcap_client->conn;
return vty->index;
}
@@ -115,6 +115,8 @@
struct osmo_pcap_client_conn *conn;
llist_for_each_entry(conn, &pcap_client->conns, entry) {
+ if (conn == pcap_client->conn)
+ continue;
vty_out(vty, " pcap-store-connection %s%s", conn->name, VTY_NEWLINE);
write_client_conn_data(vty, conn, " ");
vty_out(vty, " connect%s", VTY_NEWLINE);
@@ -141,7 +143,7 @@
vty_out(vty, " pcap add-filter gprs%s", VTY_NEWLINE);
- write_client_conn_data(vty, &pcap_client->conn, "");
+ write_client_conn_data(vty, pcap_client->conn, "");
return CMD_SUCCESS;
}
@@ -445,7 +447,7 @@
{
struct osmo_pcap_client_conn *conn;
conn = osmo_client_find_or_create_conn(pcap_client, argv[0]);
- if (!conn) {
+ if (!conn || conn == pcap_client->conn) {
vty_out(vty, "%%Failed to find/create conection %s%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
@@ -463,7 +465,7 @@
{
struct osmo_pcap_client_conn *conn;
conn = osmo_client_find_conn(pcap_client, argv[0]);
- if (!conn) {
+ if (!conn || conn == pcap_client->conn) {
vty_out(vty, "%%Failed to find connection %s%ss",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
--
To view, visit
https://gerrit.osmocom.org/c/osmo-pcap/+/39167?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-pcap
Gerrit-Branch: master
Gerrit-Change-Id: I4ead7b1b04a97a329cd1a299bde9de18b5f643a7
Gerrit-Change-Number: 39167
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>