From patchwork Tue Jul 21 14:23:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 498252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (tmp.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id D7599140E10 for ; Wed, 22 Jul 2015 00:25:02 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 8AA30852D; Tue, 21 Jul 2015 14:25:01 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.us.es (mail.us.es [193.147.175.20]) by lists.osmocom.org (Postfix) with ESMTP id 1E8B3848E for ; Tue, 21 Jul 2015 14:24:46 +0000 (UTC) Received: (qmail 7873 invoked from network); 21 Jul 2015 16:18:06 +0200 Received: from unknown (HELO us.es) (192.168.2.13) by us.es with SMTP; 21 Jul 2015 16:18:06 +0200 Received: (qmail 29865 invoked by uid 507); 21 Jul 2015 14:18:06 -0000 X-Qmail-Scanner-Diagnostics: from 127.0.0.1 by antivirus3 (envelope-from , uid 501) with qmail-scanner-2.10 (clamdscan: 0.98.7/20703. spamassassin: 3.4.0. Clear:RC:1(127.0.0.1):SA:0(-103.2/7.5):. Processed in 5.005131 secs); 21 Jul 2015 14:18:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on antivirus3 X-Spam-Level: X-Spam-Status: No, score=-103.2 required=7.5 tests=BAYES_50,SMTPAUTH_US, USER_IN_WHITELIST autolearn=disabled version=3.4.0 X-Spam-ASN: AS12715 87.216.0.0/16 X-Envelope-From: pablo@gnumonks.org Received: from unknown (HELO antivirus3) (127.0.0.1) by us.es with SMTP; 21 Jul 2015 14:18:01 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus3 (F-Secure/fsigk_smtp/412/antivirus3); Tue, 21 Jul 2015 16:18:01 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/412/antivirus3) Received: (qmail 12757 invoked from network); 21 Jul 2015 16:18:00 +0200 Received: from 129.166.216.87.static.jazztel.es (HELO salvia.here) (pneira@us.es@87.216.166.129) by mail.us.es with SMTP; 21 Jul 2015 16:18:00 +0200 From: pablo@gnumonks.org To: openbsc@lists.osmocom.org Subject: [PATCH libosmo-netif 08/18] osmux: introduce osmux_xfrm_input_close_circuit() Date: Tue, 21 Jul 2015 16:23:23 +0200 Message-Id: <1437488613-3943-9-git-send-email-pablo@gnumonks.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437488613-3943-1-git-send-email-pablo@gnumonks.org> References: <1437488613-3943-1-git-send-email-pablo@gnumonks.org> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Pablo Neira Ayuso Add this new function to explicitly remove an existing circuit. Thus, the client application (openbsc) is in full control to release circuits. Before this patch, the circuit object was added when the first RTP messages was seen, and it was removed when transforming the list of pending RTP messages to the Osmux message (once the timer expired). Moreover, check circuit->nmsgs to account bytes that are consumed by the osmux header, given that !circuit doesn't mean "this is the first packet" anymore. --- include/osmocom/netif/osmux.h | 2 ++ src/osmux.c | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/osmocom/netif/osmux.h b/include/osmocom/netif/osmux.h index 0f6f5c9..14c967f 100644 --- a/include/osmocom/netif/osmux.h +++ b/include/osmocom/netif/osmux.h @@ -84,6 +84,8 @@ int osmux_snprintf(char *buf, size_t size, struct msgb *msg); void osmux_xfrm_input_init(struct osmux_in_handle *h); void osmux_xfrm_input_fini(struct osmux_in_handle *h); +void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid); + int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid); void osmux_xfrm_input_deliver(struct osmux_in_handle *h); diff --git a/src/osmux.c b/src/osmux.c index 82ec56e..4451b5a 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -289,7 +289,7 @@ static struct msgb *osmux_build_batch(struct osmux_batch *batch, uint32_t batch_size) { struct msgb *batch_msg; - struct osmux_circuit *circuit, *next; + struct osmux_circuit *circuit; #ifdef DEBUG_MSG LOGP(DLMIB, LOGL_DEBUG, "Now building batch\n"); @@ -301,7 +301,7 @@ static struct msgb *osmux_build_batch(struct osmux_batch *batch, return NULL; } - llist_for_each_entry_safe(circuit, next, &batch->circuit_list, head) { + llist_for_each_entry(circuit, &batch->circuit_list, head) { struct msgb *cur, *tmp; int ctr = 0; @@ -336,8 +336,6 @@ static struct msgb *osmux_build_batch(struct osmux_batch *batch, ctr++; batch->nmsgs--; } - llist_del(&circuit->head); - talloc_free(circuit); } return batch_msg; } @@ -487,6 +485,18 @@ osmux_batch_add_circuit(struct osmux_batch *batch, int ccid) return circuit; } +static void osmux_batch_del_circuit(struct osmux_batch *batch, int ccid) +{ + struct osmux_circuit *circuit; + + circuit = osmux_batch_find_circuit(batch, ccid); + if (circuit == NULL) + return; + + llist_del(&circuit->head); + talloc_free(circuit); +} + static int osmux_batch_add(struct osmux_batch *batch, int batch_factor, struct msgb *msg, struct rtp_hdr *rtph, int ccid) @@ -502,7 +512,7 @@ osmux_batch_add(struct osmux_batch *batch, int batch_factor, struct msgb *msg, /* First check if there is room for this message in the batch */ bytes += amr_payload_len; - if (!circuit) + if (!circuit || circuit->nmsgs == 0) bytes += sizeof(struct osmux_hdr); /* No room, sorry. You'll have to retry */ @@ -645,6 +655,13 @@ void osmux_xfrm_input_init(struct osmux_in_handle *h) LOGP(DLMIB, LOGL_DEBUG, "initialized osmux input converter\n"); } +void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid) +{ + struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; + + osmux_batch_del_circuit(batch, ccid); +} + void osmux_xfrm_input_fini(struct osmux_in_handle *h) { struct osmux_batch *batch = (struct osmux_batch *)h->internal_data;