aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-08-05 18:02:47 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-08-05 18:02:47 +0200
commitd5cbb675a9f0c5f56d01401870e5eceb3eb3a6d8 (patch)
tree0d35263e379c1743036d6372e5adf24045a180b2 /src
parent0e945484846a7be80aa6ab4711b0374d994ad98c (diff)
pcap-client: Hacks to compile with an old libosmocorezecke/old-libosmocore
We are running a system where we do not want to upgrade libosmocore right now. Compile the osmo-pcap-client with a libosmocore from around January.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/osmo_client_core.c8
-rw-r--r--src/osmo_client_main.c48
-rw-r--r--src/osmo_client_network.c110
-rw-r--r--src/osmo_client_vty.c2
-rw-r--r--src/osmo_common.c2
6 files changed, 145 insertions, 31 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 402da22..30d6da6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,12 +2,12 @@ INCLUDES = $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/
AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(PCAP_CFLAGS)
AM_LDFLAGS = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
-bin_PROGRAMS = osmo_pcap_client osmo_pcap_server
+bin_PROGRAMS = osmo_pcap_client
osmo_pcap_client_SOURCES = osmo_client_main.c osmo_common.c \
osmo_client_core.c osmo_client_vty.c \
osmo_client_network.c
osmo_pcap_client_LDADD = $(PCAP_LIBS)
-osmo_pcap_server_SOURCES = osmo_server_main.c osmo_common.c \
- osmo_server_vty.c osmo_server_network.c
+#osmo_pcap_server_SOURCES = osmo_server_main.c osmo_common.c \
+# osmo_server_vty.c osmo_server_network.c
diff --git a/src/osmo_client_core.c b/src/osmo_client_core.c
index c8bd8bd..28f8a7e 100644
--- a/src/osmo_client_core.c
+++ b/src/osmo_client_core.c
@@ -23,7 +23,7 @@
#include <osmo-pcap/osmo_pcap_client.h>
#include <osmo-pcap/common.h>
-#include <osmocom/core/talloc.h>
+#include <osmocore/talloc.h>
#include <limits.h>
@@ -32,7 +32,7 @@
#endif
-static int pcap_read_cb(struct osmo_fd *fd, unsigned int what)
+static int pcap_read_cb(struct bsc_fd *fd, unsigned int what)
{
struct osmo_pcap_client *client = fd->data;
struct pcap_pkthdr hdr;
@@ -86,7 +86,7 @@ static void free_all(struct osmo_pcap_client *client)
pcap_freecode(&client->bpf);
if (client->fd.fd >= 0) {
- osmo_fd_unregister(&client->fd);
+ bsc_unregister_fd(&client->fd);
client->fd.fd = -1;
}
@@ -127,7 +127,7 @@ int osmo_client_capture(struct osmo_pcap_client *client, const char *device)
client->fd.when = BSC_FD_READ;
client->fd.cb = pcap_read_cb;
client->fd.data = client;
- if (osmo_fd_register(&client->fd) != 0) {
+ if (bsc_register_fd(&client->fd) != 0) {
LOGP(DCLIENT, LOGL_ERROR,
"Failed to register the fd.\n");
client->fd.fd = -1;
diff --git a/src/osmo_client_main.c b/src/osmo_client_main.c
index 9ea0b66..91cfb0c 100644
--- a/src/osmo_client_main.c
+++ b/src/osmo_client_main.c
@@ -23,11 +23,10 @@
#include <osmo-pcap/common.h>
#include <osmo-pcap/osmo_pcap_client.h>
-#include <osmocom/core/application.h>
-#include <osmocom/core/process.h>
-#include <osmocom/core/rate_ctr.h>
-#include <osmocom/core/select.h>
-#include <osmocom/core/talloc.h>
+#include <osmocore/process.h>
+#include <osmocore/rate_ctr.h>
+#include <osmocore/select.h>
+#include <osmocore/talloc.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/telnet_interface.h>
@@ -43,14 +42,39 @@
#include "osmopcapconfig.h"
+
static const char *config_file = "osmo-pcap-client.cfg";
static int daemonize = 0;
+static struct log_target *stderr_target = NULL;
void *tall_bsc_ctx;
struct osmo_pcap_client *pcap_client;
extern void *tall_msgb_ctx;
extern void *tall_ctr_ctx;
+
+/* drop in */
+static void osmo_init_ignore_signals(void)
+{
+ /* Signals that by default would terminate */
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGALRM, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ signal(SIGIO, SIG_IGN);
+}
+
+static int osmo_init_logging(const struct log_info *log_info)
+{
+ log_init(log_info);
+ stderr_target = log_target_create_stderr();
+ if (!stderr_target)
+ return -1;
+
+ log_add_target(stderr_target);
+ log_set_all_filter(stderr_target, 1);
+ return 0;
+}
+
static struct vty_app_info vty_info = {
.name = "OsmoPCAPClient",
.version = PACKAGE_VERSION,
@@ -104,16 +128,16 @@ static void handle_options(int argc, char **argv)
daemonize = 1;
break;
case 'd':
- log_parse_category_mask(osmo_stderr_target, optarg);
+ log_parse_category_mask(stderr_target, optarg);
break;
case 's':
- log_set_use_color(osmo_stderr_target, 0);
+ log_set_use_color(stderr_target, 0);
break;
case 'T':
- log_set_print_timestamp(osmo_stderr_target, 1);
+ log_set_print_timestamp(stderr_target, 1);
break;
case 'e':
- log_set_log_level(osmo_stderr_target, atoi(optarg));
+ log_set_log_level(stderr_target, atoi(optarg));
break;
case 'c':
config_file = strdup(optarg);
@@ -161,7 +185,7 @@ int main(int argc, char **argv)
vty_info.copyright = osmopcap_copyright;
vty_init(&vty_info);
- logging_vty_add_cmds(&log_info);
+ logging_vty_add_cmds();
/* parse options */
handle_options(argc, argv);
@@ -188,7 +212,7 @@ int main(int argc, char **argv)
vty_client_init(pcap_client);
/* initialize the queue */
- osmo_wqueue_init(&pcap_client->wqueue, 10);
+ write_queue_init(&pcap_client->wqueue, 10);
pcap_client->wqueue.bfd.fd = -1;
@@ -210,7 +234,7 @@ int main(int argc, char **argv)
}
while (1) {
- osmo_select_main(0);
+ bsc_select_main(0);
}
return(0);
diff --git a/src/osmo_client_network.c b/src/osmo_client_network.c
index bd1b9db..f6ada12 100644
--- a/src/osmo_client_network.c
+++ b/src/osmo_client_network.c
@@ -24,9 +24,8 @@
#include <osmo-pcap/common.h>
#include <osmo-pcap/wireformat.h>
-#include <osmocom/core/msgb.h>
-#include <osmocom/core/select.h>
-#include <osmocom/core/socket.h>
+#include <osmocore/msgb.h>
+#include <osmocore/select.h>
#include <arpa/inet.h>
@@ -37,6 +36,97 @@
#include <string.h>
#include <unistd.h>
+
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+
+#define OSMO_SOCK_F_CONNECT (1 << 0)
+#define OSMO_SOCK_F_BIND (1 << 1)
+#define OSMO_SOCK_F_NONBLOCK (1 << 2)
+int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
+ const char *host, uint16_t port, unsigned int flags)
+{
+ struct addrinfo hints, *result, *rp;
+ int sfd, rc, on = 1;
+ char portbuf[16];
+
+ if ((flags & (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT)) ==
+ (OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT))
+ return -EINVAL;
+
+ sprintf(portbuf, "%u", port);
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = family;
+ hints.ai_socktype = type;
+ hints.ai_flags = 0;
+ hints.ai_protocol = proto;
+
+ if (flags & OSMO_SOCK_F_BIND)
+ hints.ai_flags |= AI_PASSIVE;
+
+ rc = getaddrinfo(host, portbuf, &hints, &result);
+ if (rc != 0) {
+ perror("getaddrinfo returned NULL");
+ return -EINVAL;
+ }
+
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
+ sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (sfd == -1)
+ continue;
+ if (flags & OSMO_SOCK_F_NONBLOCK) {
+ if (ioctl(sfd, FIONBIO, (unsigned char *)&on) < 0) {
+ perror("cannot set this socket unblocking");
+ close(sfd);
+ return -EINVAL;
+ }
+ }
+ if (flags & OSMO_SOCK_F_CONNECT) {
+ rc = connect(sfd, rp->ai_addr, rp->ai_addrlen);
+ if (rc != -1 || (rc == -1 && errno == EINPROGRESS))
+ break;
+ } else {
+ rc = setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR,
+ &on, sizeof(on));
+ if (rc < 0) {
+ perror("cannot setsockopt socket");
+ break;
+ }
+ if (bind(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
+ break;
+ }
+ close(sfd);
+ }
+ freeaddrinfo(result);
+
+ if (rp == NULL) {
+ perror("unable to connect/bind socket");
+ return -ENODEV;
+ }
+
+ setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+
+ /* Make sure to call 'listen' on a bound, connection-oriented sock */
+ if (flags & OSMO_SOCK_F_BIND) {
+ switch (type) {
+ case SOCK_STREAM:
+ case SOCK_SEQPACKET:
+ listen(sfd, 10);
+ break;
+ }
+ }
+ return sfd;
+}
+
+
static void _osmo_client_connect(void *_data)
{
osmo_client_connect((struct osmo_pcap_client *) _data);
@@ -45,7 +135,7 @@ static void _osmo_client_connect(void *_data)
static void lost_connection(struct osmo_pcap_client *client)
{
if (client->wqueue.bfd.fd >= 0) {
- osmo_fd_unregister(&client->wqueue.bfd);
+ bsc_unregister_fd(&client->wqueue.bfd);
close(client->wqueue.bfd.fd);
client->wqueue.bfd.fd = -1;
}
@@ -53,19 +143,19 @@ static void lost_connection(struct osmo_pcap_client *client)
client->timer.cb = _osmo_client_connect;
client->timer.data = client;
- osmo_timer_schedule(&client->timer, 2, 0);
+ bsc_schedule_timer(&client->timer, 2, 0);
}
static void write_data(struct osmo_pcap_client *client, struct msgb *msg)
{
- if (osmo_wqueue_enqueue(&client->wqueue, msg) != 0) {
+ if (write_queue_enqueue(&client->wqueue, msg) != 0) {
LOGP(DCLIENT, LOGL_ERROR, "Failed to enqueue.\n");
msgb_free(msg);
return;
}
}
-static int read_cb(struct osmo_fd *fd)
+static int read_cb(struct bsc_fd *fd)
{
char buf[4096];
int rc;
@@ -81,7 +171,7 @@ static int read_cb(struct osmo_fd *fd)
return 0;
}
-static int write_cb(struct osmo_fd *fd, struct msgb *msg)
+static int write_cb(struct bsc_fd *fd, struct msgb *msg)
{
int rc;
@@ -160,7 +250,7 @@ void osmo_client_connect(struct osmo_pcap_client *client)
client->wqueue.write_cb = write_cb;
client->wqueue.bfd.when = BSC_FD_READ;
client->wqueue.bfd.data = client;
- osmo_wqueue_clear(&client->wqueue);
+ write_queue_clear(&client->wqueue);
fd = osmo_sock_init(AF_INET, SOCK_STREAM, IPPROTO_TCP,
client->srv_ip, client->srv_port, OSMO_SOCK_F_CONNECT);
@@ -173,7 +263,7 @@ void osmo_client_connect(struct osmo_pcap_client *client)
}
client->wqueue.bfd.fd = fd;
- if (osmo_fd_register(&client->wqueue.bfd) != 0) {
+ if (bsc_register_fd(&client->wqueue.bfd) != 0) {
LOGP(DCLIENT, LOGL_ERROR,
"Failed to register to BFD.\n");
lost_connection(client);
diff --git a/src/osmo_client_vty.c b/src/osmo_client_vty.c
index 0b30eb7..bcf2e47 100644
--- a/src/osmo_client_vty.c
+++ b/src/osmo_client_vty.c
@@ -23,7 +23,7 @@
#include <osmo-pcap/osmo_pcap_client.h>
#include <osmo-pcap/common.h>
-#include <osmocom/core/talloc.h>
+#include <osmocore/talloc.h>
#include <stdlib.h>
diff --git a/src/osmo_common.c b/src/osmo_common.c
index b97394e..852be54 100644
--- a/src/osmo_common.c
+++ b/src/osmo_common.c
@@ -22,7 +22,7 @@
#include <osmo-pcap/common.h>
-#include <osmocom/core/utils.h>
+#include <osmocore/utils.h>
static const struct log_info_cat default_categories[] = {
[DPCAP] = {