From ed07a3fc1c058521542ea8e762871432c4cde39f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 15 Jun 2010 18:47:10 +0800 Subject: [PATCH] nat: Start using a write_queue for the BSC connection We are still writing to the BSC directly and don't make real use of this feature right now but we will need to do it. --- openbsc/include/openbsc/bsc_nat.h | 3 ++- openbsc/src/nat/bsc_nat.c | 26 +++++++++++++------------- openbsc/src/nat/bsc_nat_vty.c | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index d42e489e7..5ac60df87 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -28,6 +28,7 @@ #include #include #include +#include #define DIR_BSC 1 #define DIR_MSC 2 @@ -77,7 +78,7 @@ struct bsc_connection { int authenticated; /* the fd we use to communicate */ - struct bsc_fd bsc_fd; + struct write_queue write_queue; /* the LAC assigned to this connection */ unsigned int lac; diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c index 63263fa9d..0972208fa 100644 --- a/openbsc/src/nat/bsc_nat.c +++ b/openbsc/src/nat/bsc_nat.c @@ -44,7 +44,6 @@ #include #include -#include #include @@ -315,7 +314,7 @@ static int forward_sccp_to_bts(struct msgb *msg) return -1; } - return write(bsc->bsc_fd.fd, msg->data, msg->len); + return write(bsc->write_queue.bfd.fd, msg->data, msg->len); send_to_all: /* @@ -349,7 +348,7 @@ send_to_all: if (!bsc->authenticated || _lac != bsc->lac) continue; - rc = write(bsc->bsc_fd.fd, msg->data, msg->len); + rc = write(bsc->write_queue.bfd.fd, msg->data, msg->len); if (rc < msg->len) LOGP(DNAT, LOGL_ERROR, "Failed to write message to BTS: %d\n", rc); @@ -363,7 +362,7 @@ send_to_all: if (!bsc->authenticated) continue; - rc = write(bsc->bsc_fd.fd, msg->data, msg->len); + rc = write(bsc->write_queue.bfd.fd, msg->data, msg->len); /* try the next one */ if (rc < msg->len) @@ -434,8 +433,8 @@ static int ipaccess_msc_write_cb(struct bsc_fd *bfd, struct msgb *msg) static void remove_bsc_connection(struct bsc_connection *connection) { struct sccp_connections *sccp_patch, *tmp; - bsc_unregister_fd(&connection->bsc_fd); - close(connection->bsc_fd.fd); + bsc_unregister_fd(&connection->write_queue.bfd); + close(connection->write_queue.bfd.fd); llist_del(&connection->list_entry); /* stop the timeout timer */ @@ -564,7 +563,7 @@ exit2: return -1; } -static int ipaccess_bsc_cb(struct bsc_fd *bfd, unsigned int what) +static int ipaccess_bsc_read_cb(struct bsc_fd *bfd) { int error; struct msgb *msg = ipaccess_read_msg(bfd, &error); @@ -620,11 +619,12 @@ static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what) } bsc->nat = nat; - bsc->bsc_fd.data = bsc; - bsc->bsc_fd.fd = ret; - bsc->bsc_fd.cb = ipaccess_bsc_cb; - bsc->bsc_fd.when = BSC_FD_READ; - if (bsc_register_fd(&bsc->bsc_fd) < 0) { + write_queue_init(&bsc->write_queue, 100); + bsc->write_queue.bfd.data = bsc; + bsc->write_queue.bfd.fd = ret; + bsc->write_queue.read_cb = ipaccess_bsc_read_cb; + bsc->write_queue.bfd.when = BSC_FD_READ; + if (bsc_register_fd(&bsc->write_queue.bfd) < 0) { LOGP(DNAT, LOGL_ERROR, "Failed to register BSC fd.\n"); close(ret); talloc_free(bsc); @@ -633,7 +633,7 @@ static int ipaccess_listen_bsc_cb(struct bsc_fd *bfd, unsigned int what) LOGP(DNAT, LOGL_INFO, "Registered new BSC\n"); llist_add(&bsc->list_entry, &nat->bsc_connections); - ipaccess_send_id_ack(bsc->bsc_fd.fd); + ipaccess_send_id_ack(bsc->write_queue.bfd.fd); ipaccess_send_id_req(ret); /* diff --git a/openbsc/src/nat/bsc_nat_vty.c b/openbsc/src/nat/bsc_nat_vty.c index 5430670c9..695903775 100644 --- a/openbsc/src/nat/bsc_nat_vty.c +++ b/openbsc/src/nat/bsc_nat_vty.c @@ -89,7 +89,7 @@ DEFUN(show_bsc, show_bsc_cmd, "show connections bsc", struct bsc_connection *con; llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { vty_out(vty, "BSC lac: %d auth: %d fd: %d%s", - con->lac, con->authenticated, con->bsc_fd.fd, VTY_NEWLINE); + con->lac, con->authenticated, con->write_queue.bfd.fd, VTY_NEWLINE); } return CMD_SUCCESS;