aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/osmo_client_core.c4
-rw-r--r--src/osmo_client_main.c9
-rw-r--r--src/osmo_client_network.c89
-rw-r--r--src/osmo_client_vty.c98
-rw-r--r--src/osmo_tls.c4
5 files changed, 103 insertions, 101 deletions
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index abef787..203e6a2 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -167,7 +167,7 @@ static int pcap_read_cb(struct osmo_fd *fd, unsigned int what)
if (!forward_packet(client, &hdr, data))
return 0;
- osmo_client_send_data(client, &hdr, data);
+ osmo_client_send_data(&client->conn, &hdr, data);
return 0;
}
@@ -315,7 +315,7 @@ int osmo_client_capture(struct osmo_pcap_client *client, const char *device)
client->pcap_stat_timer.cb = pcap_check_stats_cb;
pcap_check_stats_cb(client);
- osmo_client_send_link(client);
+ osmo_client_send_link(&client->conn);
if (client->filter_string) {
osmo_install_filter(client);
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index 0bbeb7a..694470e 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -218,12 +218,13 @@ int main(int argc, char **argv)
exit(1);
}
pcap_client->fd.fd = -1;
- pcap_client->tls_verify = true;
+ pcap_client->conn.tls_verify = true;
vty_client_init(pcap_client);
/* initialize the queue */
- osmo_wqueue_init(&pcap_client->wqueue, 10);
- pcap_client->wqueue.bfd.fd = -1;
+ pcap_client->conn.client = pcap_client;
+ osmo_wqueue_init(&pcap_client->conn.wqueue, 10);
+ pcap_client->conn.wqueue.bfd.fd = -1;
/* initialize the stats interface */
pcap_client->ctrg = rate_ctr_group_alloc(pcap_client, &pcap_client_ctr_group_desc, 0);
@@ -239,7 +240,7 @@ int main(int argc, char **argv)
}
/* attempt to connect to the remote */
- osmo_client_connect(pcap_client);
+ osmo_client_connect(&pcap_client->conn);
if (daemonize) {
rc = osmo_daemonize();
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index 1bd5898..3debfc0 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -41,10 +41,10 @@
static void _osmo_client_connect(void *_data)
{
- osmo_client_connect((struct osmo_pcap_client *) _data);
+ osmo_client_connect((struct osmo_pcap_client_conn *) _data);
}
-static void lost_connection(struct osmo_pcap_client *client)
+static void lost_connection(struct osmo_pcap_client_conn *client)
{
if (client->wqueue.bfd.fd >= 0) {
osmo_tls_release(&client->tls_session);
@@ -59,11 +59,11 @@ static void lost_connection(struct osmo_pcap_client *client)
osmo_timer_schedule(&client->timer, 2, 0);
}
-static void write_data(struct osmo_pcap_client *client, struct msgb *msg)
+static void write_data(struct osmo_pcap_client_conn *conn, struct msgb *msg)
{
- if (osmo_wqueue_enqueue(&client->wqueue, msg) != 0) {
+ if (osmo_wqueue_enqueue(&conn->wqueue, msg) != 0) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to enqueue.\n");
- rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_QERR]);
+ rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_QERR]);
msgb_free(msg);
return;
}
@@ -76,7 +76,7 @@ static int read_cb(struct osmo_fd *fd)
rc = read(fd->fd, buf, sizeof(buf));
if (rc <= 0) {
- struct osmo_pcap_client *client = fd->data;
+ struct osmo_pcap_client_conn *client = fd->data;
LOGP(DCLIENT, LOGL_ERROR, "Lost connection on read.\n");
lost_connection(client);
return -1;
@@ -91,10 +91,11 @@ static int write_cb(struct osmo_fd *fd, struct msgb *msg)
rc = write(fd->fd, msg->data, msg->len);
if (rc < 0) {
- struct osmo_pcap_client *client = fd->data;
- LOGP(DCLIENT, LOGL_ERROR, "Lost connection on write.\n");
- rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_WERR]);
- lost_connection(client);
+ struct osmo_pcap_client_conn *conn = fd->data;
+ LOGP(DCLIENT, LOGL_ERROR, "Lost connection on write to %s:%d.\n",
+ conn->srv_ip, conn->srv_port);
+ rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_WERR]);
+ lost_connection(conn);
return -1;
}
@@ -103,21 +104,21 @@ static int write_cb(struct osmo_fd *fd, struct msgb *msg)
static void handshake_done_cb(struct osmo_tls_session *session)
{
- struct osmo_pcap_client *client;
+ struct osmo_pcap_client_conn *client;
- client = container_of(session, struct osmo_pcap_client, tls_session);
+ client = container_of(session, struct osmo_pcap_client_conn, tls_session);
osmo_client_send_link(client);
}
static void tls_error_cb(struct osmo_tls_session *session)
{
- struct osmo_pcap_client *client;
+ struct osmo_pcap_client_conn *client;
- client = container_of(session, struct osmo_pcap_client, tls_session);
+ client = container_of(session, struct osmo_pcap_client_conn, tls_session);
lost_connection(client);
}
-void osmo_client_send_data(struct osmo_pcap_client *client,
+void osmo_client_send_data(struct osmo_pcap_client_conn *conn,
struct pcap_pkthdr *in_hdr, const uint8_t *data)
{
struct osmo_pcap_data *om_hdr;
@@ -127,14 +128,14 @@ void osmo_client_send_data(struct osmo_pcap_client *client,
if (in_hdr->caplen > 9000) {
LOGP(DCLIENT, LOGL_ERROR,
"Capture len too big %zu\n", in_hdr->caplen);
- rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_2BIG]);
+ rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_2BIG]);
return;
}
msg = msgb_alloc(9000 + sizeof(*om_hdr) + sizeof(*hdr), "data-data");
if (!msg) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to allocate.\n");
- rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_NOMEM]);
+ rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_NOMEM]);
return;
}
@@ -152,13 +153,13 @@ void osmo_client_send_data(struct osmo_pcap_client *client,
memcpy(msg->l3h, data, in_hdr->caplen);
om_hdr->len = htons(msgb_l2len(msg));
- rate_ctr_add(&client->ctrg->ctr[CLIENT_CTR_BYTES], hdr->caplen);
- rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_PKTS]);
+ rate_ctr_add(&conn->client->ctrg->ctr[CLIENT_CTR_BYTES], hdr->caplen);
+ rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_PKTS]);
- write_data(client, msg);
+ write_data(conn, msg);
}
-void osmo_client_send_link(struct osmo_pcap_client *client)
+void osmo_client_send_link(struct osmo_pcap_client_conn *conn)
{
struct pcap_file_header *hdr;
struct osmo_pcap_data *om_hdr;
@@ -182,59 +183,59 @@ void osmo_client_send_link(struct osmo_pcap_client *client)
hdr->thiszone = 0;
hdr->sigfigs = 0;
hdr->snaplen = UINT_MAX;
- hdr->linktype = pcap_datalink(client->handle);
+ hdr->linktype = pcap_datalink(conn->client->handle);
- write_data(client, msg);
+ write_data(conn, msg);
}
-void osmo_client_connect(struct osmo_pcap_client *client)
+void osmo_client_connect(struct osmo_pcap_client_conn *conn)
{
int fd;
- client->wqueue.read_cb = read_cb;
- client->wqueue.write_cb = write_cb;
- client->wqueue.bfd.when = BSC_FD_READ;
- osmo_wqueue_clear(&client->wqueue);
+ conn->wqueue.read_cb = read_cb;
+ conn->wqueue.write_cb = write_cb;
+ conn->wqueue.bfd.when = BSC_FD_READ;
+ osmo_wqueue_clear(&conn->wqueue);
fd = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
- client->srv_ip, client->srv_port, OSMO_SOCK_F_CONNECT);
+ conn->srv_ip, conn->srv_port, OSMO_SOCK_F_CONNECT);
if (fd < 0) {
LOGP(DCLIENT, LOGL_ERROR,
"Failed to connect to %s:%d\n",
- client->srv_ip, client->srv_port);
- lost_connection(client);
+ conn->srv_ip, conn->srv_port);
+ lost_connection(conn);
return;
}
- client->wqueue.bfd.fd = fd;
- if (osmo_fd_register(&client->wqueue.bfd) != 0) {
+ conn->wqueue.bfd.fd = fd;
+ if (osmo_fd_register(&conn->wqueue.bfd) != 0) {
LOGP(DCLIENT, LOGL_ERROR,
"Failed to register to BFD.\n");
- lost_connection(client);
+ lost_connection(conn);
return;
}
- rate_ctr_inc(&client->ctrg->ctr[CLIENT_CTR_CONNECT]);
+ rate_ctr_inc(&conn->client->ctrg->ctr[CLIENT_CTR_CONNECT]);
/*
* The write queue needs to work differently for GNUtls. Before we can
* send data we will need to complete handshake.
*/
- if (client->tls_on) {
- if (!osmo_tls_init_client_session(client)) {
- lost_connection(client);
+ if (conn->tls_on) {
+ if (!osmo_tls_init_client_session(conn)) {
+ lost_connection(conn);
return;
}
- client->tls_session.handshake_done = handshake_done_cb;
- client->tls_session.error = tls_error_cb;
+ conn->tls_session.handshake_done = handshake_done_cb;
+ conn->tls_session.error = tls_error_cb;
} else {
- client->wqueue.bfd.cb = osmo_wqueue_bfd_cb;
- client->wqueue.bfd.data = client;
- osmo_client_send_link(client);
+ conn->wqueue.bfd.cb = osmo_wqueue_bfd_cb;
+ conn->wqueue.bfd.data = conn;
+ osmo_client_send_link(conn);
}
}
-void osmo_client_reconnect(struct osmo_pcap_client *client)
+void osmo_client_reconnect(struct osmo_pcap_client_conn *client)
{
lost_connection(client);
}
diff --git a/src/osmo_client_vty.c b/src/osmo_client_vty.c
index a409cf4..9b89d10 100644
--- a/src/osmo_client_vty.c
+++ b/src/osmo_client_vty.c
@@ -62,33 +62,33 @@ static int config_write_client(struct vty *vty)
if (pcap_client->gprs_filtering)
vty_out(vty, " pcap add-filter gprs%s", VTY_NEWLINE);
- if (pcap_client->tls_on) {
+ if (pcap_client->conn.tls_on) {
vty_out(vty, " enable tls%s", VTY_NEWLINE);
- vty_out(vty, " tls hostname %s%s", pcap_client->tls_hostname, VTY_NEWLINE);
+ vty_out(vty, " tls hostname %s%s", pcap_client->conn.tls_hostname, VTY_NEWLINE);
vty_out(vty, " %stls verify-cert%s",
- pcap_client->tls_verify ? "" : "no ", VTY_NEWLINE);
- if (pcap_client->tls_capath)
- vty_out(vty, " tls capath %s%s", pcap_client->tls_capath, VTY_NEWLINE);
- if (pcap_client->tls_client_cert)
+ pcap_client->conn.tls_verify ? "" : "no ", VTY_NEWLINE);
+ if (pcap_client->conn.tls_capath)
+ vty_out(vty, " tls capath %s%s", pcap_client->conn.tls_capath, VTY_NEWLINE);
+ if (pcap_client->conn.tls_client_cert)
vty_out(vty, " tls client-cert %s%s",
- pcap_client->tls_client_cert, VTY_NEWLINE);
- if (pcap_client->tls_client_key)
+ pcap_client->conn.tls_client_cert, VTY_NEWLINE);
+ if (pcap_client->conn.tls_client_key)
vty_out(vty, " tls client-key %s%s",
- pcap_client->tls_client_key, VTY_NEWLINE);
- if (pcap_client->tls_priority)
+ pcap_client->conn.tls_client_key, VTY_NEWLINE);
+ if (pcap_client->conn.tls_priority)
vty_out(vty, " tls priority %s%s",
- pcap_client->tls_priority, VTY_NEWLINE);
+ pcap_client->conn.tls_priority, VTY_NEWLINE);
vty_out(vty, " tls log-level %d%s",
- pcap_client->tls_log_level, VTY_NEWLINE);
+ pcap_client->conn.tls_log_level, VTY_NEWLINE);
}
- if (pcap_client->srv_ip)
+ if (pcap_client->conn.srv_ip)
vty_out(vty, " server ip %s%s",
- pcap_client->srv_ip, VTY_NEWLINE);
+ pcap_client->conn.srv_ip, VTY_NEWLINE);
- if (pcap_client->srv_port > 0)
+ if (pcap_client->conn.srv_port > 0)
vty_out(vty, " server port %d%s",
- pcap_client->srv_port, VTY_NEWLINE);
+ pcap_client->conn.srv_port, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -159,12 +159,12 @@ DEFUN(cfg_enable_tls,
"enable tls",
"Enable\n" "Transport Layer Security\n")
{
- if (!pcap_client->tls_on) {
- if (pcap_client->wqueue.bfd.fd >= 0)
- osmo_client_reconnect(pcap_client);
+ if (!pcap_client->conn.tls_on) {
+ if (pcap_client->conn.wqueue.bfd.fd >= 0)
+ osmo_client_reconnect(&pcap_client->conn);
}
- pcap_client->tls_on = true;
+ pcap_client->conn.tls_on = true;
return CMD_SUCCESS;
}
@@ -173,10 +173,10 @@ DEFUN(cfg_disable_tls,
"disable tls",
"Disable\n" "Transport Layer Security\n")
{
- if (pcap_client->tls_on)
- osmo_client_reconnect(pcap_client);
+ if (pcap_client->conn.tls_on)
+ osmo_client_reconnect(&pcap_client->conn);
- pcap_client->tls_on = false;
+ pcap_client->conn.tls_on = false;
return CMD_SUCCESS;
}
@@ -185,8 +185,8 @@ DEFUN(cfg_tls_hostname,
"tls hostname NAME",
TLS_STR "hostname for certificate validation\n" "name\n")
{
- talloc_free(pcap_client->tls_hostname);
- pcap_client->tls_hostname = talloc_strdup(pcap_client, argv[0]);
+ talloc_free(pcap_client->conn.tls_hostname);
+ pcap_client->conn.tls_hostname = talloc_strdup(pcap_client, argv[0]);
return CMD_SUCCESS;
}
@@ -195,8 +195,8 @@ DEFUN(cfg_no_tls_hostname,
"no tls hostname",
NO_STR TLS_STR "hostname for certificate validation\n")
{
- talloc_free(pcap_client->tls_hostname);
- pcap_client->tls_hostname = NULL;
+ talloc_free(pcap_client->conn.tls_hostname);
+ pcap_client->conn.tls_hostname = NULL;
return CMD_SUCCESS;
}
@@ -205,7 +205,7 @@ DEFUN(cfg_tls_verify,
"tls verify-cert",
TLS_STR "Verify certificates\n")
{
- pcap_client->tls_verify = true;
+ pcap_client->conn.tls_verify = true;
return CMD_SUCCESS;
}
@@ -214,7 +214,7 @@ DEFUN(cfg_no_tls_verify,
"no tls verify-cert",
NO_STR TLS_STR "Verify certificates\n")
{
- pcap_client->tls_verify = false;
+ pcap_client->conn.tls_verify = false;
return CMD_SUCCESS;
}
@@ -223,8 +223,8 @@ DEFUN(cfg_tls_capath,
"tls capath .PATH",
TLS_STR "Trusted root certificates\n" "Filename\n")
{
- talloc_free(pcap_client->tls_capath);
- pcap_client->tls_capath = talloc_strdup(pcap_client, argv[0]);
+ talloc_free(pcap_client->conn.tls_capath);
+ pcap_client->conn.tls_capath = talloc_strdup(pcap_client, argv[0]);
return CMD_SUCCESS;
}
@@ -233,8 +233,8 @@ DEFUN(cfg_no_tls_capath,
"no tls capath",
NO_STR TLS_STR "Trusted root certificates\n")
{
- talloc_free(pcap_client->tls_capath);
- pcap_client->tls_capath = NULL;
+ talloc_free(pcap_client->conn.tls_capath);
+ pcap_client->conn.tls_capath = NULL;
return CMD_SUCCESS;
}
@@ -243,8 +243,8 @@ DEFUN(cfg_tls_client_cert,
"tls client-cert .PATH",
TLS_STR "Client certificate for authentication\n" "Filename\n")
{
- talloc_free(pcap_client->tls_client_cert);
- pcap_client->tls_client_cert = talloc_strdup(pcap_client, argv[0]);
+ talloc_free(pcap_client->conn.tls_client_cert);
+ pcap_client->conn.tls_client_cert = talloc_strdup(pcap_client, argv[0]);
return CMD_SUCCESS;
}
@@ -253,8 +253,8 @@ DEFUN(cfg_no_tls_client_cert,
"no tls client-cert",
NO_STR TLS_STR "Client certificate for authentication\n")
{
- talloc_free(pcap_client->tls_client_cert);
- pcap_client->tls_client_cert = NULL;
+ talloc_free(pcap_client->conn.tls_client_cert);
+ pcap_client->conn.tls_client_cert = NULL;
return CMD_SUCCESS;
}
@@ -263,8 +263,8 @@ DEFUN(cfg_tls_client_key,
"tls client-key .PATH",
TLS_STR "Client private key\n" "Filename\n")
{
- talloc_free(pcap_client->tls_client_key);
- pcap_client->tls_client_key = talloc_strdup(pcap_client, argv[0]);
+ talloc_free(pcap_client->conn.tls_client_key);
+ pcap_client->conn.tls_client_key = talloc_strdup(pcap_client, argv[0]);
return CMD_SUCCESS;
}
@@ -273,8 +273,8 @@ DEFUN(cfg_no_tls_client_key,
"no tls client-key",
NO_STR TLS_STR "Client private key\n")
{
- talloc_free(pcap_client->tls_client_key);
- pcap_client->tls_client_key = NULL;
+ talloc_free(pcap_client->conn.tls_client_key);
+ pcap_client->conn.tls_client_key = NULL;
return CMD_SUCCESS;
}
@@ -283,8 +283,8 @@ DEFUN(cfg_tls_priority,
"tls priority STR",
TLS_STR "Priority string for GNUtls\n" "Priority string\n")
{
- talloc_free(pcap_client->tls_priority);
- pcap_client->tls_priority = talloc_strdup(pcap_client, argv[0]);
+ talloc_free(pcap_client->conn.tls_priority);
+ pcap_client->conn.tls_priority = talloc_strdup(pcap_client, argv[0]);
return CMD_SUCCESS;
}
@@ -293,8 +293,8 @@ DEFUN(cfg_no_tls_priority,
"no tls priority",
NO_STR TLS_STR "Priority string for GNUtls\n")
{
- talloc_free(pcap_client->tls_priority);
- pcap_client->tls_priority = NULL;
+ talloc_free(pcap_client->conn.tls_priority);
+ pcap_client->conn.tls_priority = NULL;
return CMD_SUCCESS;
}
@@ -303,7 +303,7 @@ DEFUN(cfg_tls_log_level,
"tls log-level <0-255>",
TLS_STR "Log-level\n" "GNUtls debug level\n")
{
- pcap_client->tls_log_level = atoi(argv[0]);
+ pcap_client->conn.tls_log_level = atoi(argv[0]);
return CMD_SUCCESS;
}
@@ -312,8 +312,8 @@ DEFUN(cfg_server_ip,
"server ip A.B.C.D",
SERVER_STRING "IP Address of the server\n" "IP\n")
{
- talloc_free(pcap_client->srv_ip);
- pcap_client->srv_ip = talloc_strdup(pcap_client, argv[0]);
+ talloc_free(pcap_client->conn.srv_ip);
+ pcap_client->conn.srv_ip = talloc_strdup(pcap_client, argv[0]);
return CMD_SUCCESS;
}
@@ -322,7 +322,7 @@ DEFUN(cfg_server_port,
"server port <1-65535>",
SERVER_STRING "Port\n" "Number\n")
{
- pcap_client->srv_port = atoi(argv[0]);
+ pcap_client->conn.srv_port = atoi(argv[0]);
return CMD_SUCCESS;
}
diff --git a/src/osmo_tls.c b/src/osmo_tls.c
index aeecf6d..2cb1a87 100644
--- a/src/osmo_tls.c
+++ b/src/osmo_tls.c
@@ -281,7 +281,7 @@ int osmo_tls_client_bfd_cb(struct osmo_fd *fd, unsigned what)
return 0;
}
-static int load_keys(struct osmo_pcap_client *client)
+static int load_keys(struct osmo_pcap_client_conn *client)
{
struct osmo_tls_session *sess = &client->tls_session;
gnutls_datum_t data;
@@ -443,7 +443,7 @@ bool osmo_tls_init_server_session(struct osmo_pcap_conn *conn,
return true;
}
-bool osmo_tls_init_client_session(struct osmo_pcap_client *client)
+bool osmo_tls_init_client_session(struct osmo_pcap_client_conn *client)
{
struct osmo_tls_session *sess = &client->tls_session;
struct osmo_wqueue *wq = &client->wqueue;