From holger at freyther.de Sun Aug 12 10:19:59 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Sun, 12 Aug 2012 12:19:59 +0200 Subject: libosmo-sccp and static archives In-Reply-To: <4FF57335.7010809@flameeyes.eu> References: <4FF433D8.3030900@flameeyes.eu> <20120705104900.GD18088@sangmingze.sysmocom.de> <4FF57335.7010809@flameeyes.eu> Message-ID: <20120812101959.GG3540@localhost> On Thu, Jul 05, 2012 at 12:57:57PM +0200, Diego Elio Petten? wrote: > Do you have more details on which issues it is? I've seen many problems > related to DSO before, but most of the time they are relatively easy to > fix, so if I can be of help I'd gladly do so. "issues" is really not technical here. For some cases it is easier to deploy one binary than to make sure the dependencies are present and at the right place (or ld.so.conf has the right path or...) > > > Habbit, for WebKit copying 3GB in .o files into the .a because > > one file changed.. lead me to create multipe libs. It is certainly > > overkill for libosmo-sccp and having a single .a file would be okay. > > Sounds good then ? do you want me to send patches to set that one up, > with libtool or something? sure, libtool sounds fine. From holger at freyther.de Sun Aug 12 10:20:49 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Sun, 12 Aug 2012 12:20:49 +0200 Subject: [libosmo-sccp PATCH 2/7] m2ua: remove unset talloc context. In-Reply-To: <4FF573E2.9070305@flameeyes.eu> References: <1341437889-626462-1-git-send-email-flameeyes@flameeyes.eu> <1341437889-626462-2-git-send-email-flameeyes@flameeyes.eu> <20120705105626.GE18088@sangmingze.sysmocom.de> <4FF573E2.9070305@flameeyes.eu> Message-ID: <20120812102049.GH3540@localhost> On Thu, Jul 05, 2012 at 01:00:50PM +0200, Diego Elio Petten? wrote: > It's not for the bytes themselves (since it's uninitialised it's mapped > to the zero page, which means that it doesn't really use up space). It's > more about having code that seems to do one thing but is actually doing > another.. True, I will try to get my act together and initialize the talloc context. > From pauldart at gmail.com Wed Aug 1 09:49:40 2012 From: pauldart at gmail.com (Paul Dart) Date: Wed, 1 Aug 2012 10:49:40 +0100 Subject: EMFCamp - A UK Hackcamp this summer! Message-ID: Hello ! Although not entirely on topic, Harold is happy for me to post to these lists about an event I've been involved in. Electromagnetic Field is a UK hacker/maker camp that is occurring in just under a months time. In case you haven't, here's the gist: Electromagnetic Field is a non-profit three day camping festival for people with an inquisitive mind or an interest in making things: hackers, geeks, scientists, engineers, artists, and craftspeople. It's taking place in Milton Keynes between the 31st August and the 2nd September and is inspired by European camps such as the Chaos Communication Camp and Hacking At Random, which means that we have an absurd internet connection to a field, and power to every tent. There will be talks and workshops on everything from genetic modification to lockpicking, blacksmithing to high-energy physics, reverse engineering to electronic engineering, quadcopters to beer brewing and crocheting to carpentry. If you decide to talk about something, there's space for you to do so, and plenty of people who want to listen. The campsite will be littered with interesting things to play with and explore, from ride-on tanks to giant dinosaurs. And more lasers than you can shake a laser-covered stick at. Attendees are encouraged to form villages and put on activities for other people around the camp, and we're going to have villages covering everything from gaming to 3D printing. If you'd like to form a village, get in touch! https://www.emfcamp.org/tickets Your ticket will give you the following things: * A secure place to camp for three days. * Power to your tent. * Very fast internet access (both wired and wireless). * Access to running water and hot showers. * A whole pile of awesome talks and workshops by amazing people. * A full bar. * One fully programmable camp badge, equipped with wireless communications. * A campsite equipped with weird and wonderful things to play with. * A weekend unlike any other in the UK. If we've still not sold you, maybe you should read our website and blog, which have exhaustive information about the camp: https://www.emfcamp.org http://blog.emfcamp.org If you've got any questions feel free to email me or the team! Paul From chithanh at gentoo.org Thu Aug 2 00:01:49 2012 From: chithanh at gentoo.org (=?UTF-8?B?Q2jDrS1UaGFuaCBDaHJpc3RvcGhlciBOZ3V54buFbg==?=) Date: Thu, 02 Aug 2012 02:01:49 +0200 Subject: [PATCH] Add missing includes to timer_test.c and osmo-auc-gen.c Message-ID: <5019C36D.8070008@gentoo.org> This fixes the build with -Werror-implicit-function-declaration. --- tests/timer/timer_test.c | 1 + utils/osmo-auc-gen.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) diff --git a/tests/timer/timer_test.c b/tests/timer/timer_test.c index 61079bd..ba3127d 100644 --- a/tests/timer/timer_test.c +++ b/tests/timer/timer_test.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include diff --git a/utils/osmo-auc-gen.c b/utils/osmo-auc-gen.c index 266d0d6..1a78477 100644 --- a/utils/osmo-auc-gen.c +++ b/utils/osmo-auc-gen.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include -- 1.7.8.6 From laforge at gnumonks.org Thu Aug 2 06:49:43 2012 From: laforge at gnumonks.org (Harald Welte) Date: Thu, 2 Aug 2012 08:49:43 +0200 Subject: [PATCH] Add missing includes to timer_test.c and osmo-auc-gen.c In-Reply-To: <5019C36D.8070008@gentoo.org> References: <5019C36D.8070008@gentoo.org> Message-ID: <20120802064943.GH28252@prithivi.gnumonks.org> Hi Christopher, On Thu, Aug 02, 2012 at 02:01:49AM +0200, Ch?-Thanh Christopher Nguy?n wrote: > This fixes the build with -Werror-implicit-function-declaration. thanks for your patch. I wanted to apply it, but it was seriously broken/malformatted. For some reason, the empty lines of the source files had been removed from your patch, causing it to be malformed and rejected both by patch itself, as well as by 'git am'. I've manually added the #include to the two files now. Please never copy+paste patches into regular mail user agents, they often break formatting (whitespace) and break lines into multiple lines, causing patches to fail. It's best to use 'git send-email' directly to avoid this problem. Regards, Harald -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From holger at freyther.de Thu Aug 2 19:36:16 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 2 Aug 2012 21:36:16 +0200 Subject: [PATCH] Add missing includes to timer_test.c and osmo-auc-gen.c In-Reply-To: <5019C36D.8070008@gentoo.org> References: <5019C36D.8070008@gentoo.org> Message-ID: <20120802193616.GJ24345@sangmingze.sysmocom.de> On Thu, Aug 02, 2012 at 02:01:49AM +0200, Ch?-Thanh Christopher Nguy?n wrote: > This fixes the build with -Werror-implicit-function-declaration. Hi, from the OBS build I am seeing the following other issues. You might have the time to look into the other -Werror warnings? [ 78s] I: Program is using implicit definitions of functions getting [ 78s] pointers or implemented by macros. These functions need to use their [ 78s] correct prototypes to allow correct argument passing on e.g. x86_64 . [ 78s] - Implicit memory/string functions need #include . [ 78s] - Implicit *printf functions need #include . [ 78s] - Implicit *printf functions need #include . [ 78s] - Implicit *read* functions need #include . [ 78s] - Implicit *recv* functions need #include . [ 78s] W: libosmocore implicit-pointer-decl osmo-auc-gen.c:215 [ 78s] [ 78s] I: Program is likely to break with new gcc. Try -fno-strict-aliasing. [ 78s] W: libosmocore strict-aliasing-punning gprs_bssgp.c:109, 110, 128, 129, 152, 153, 176, 177, 198, 199, 238, 295, 303, 312, 320, 321, 333, 341, 349, 357, 358, 366, 369, 371, 376, 382, 383, 389, 401, 422, 431, 433, 443, 466, 476, 479, 508, 538, 539, 547, 555, 626, 629, 716, 717, 721, 730, 733, 738, 741, 751, 772, 773, 842, 868, 869 [ 78s] W: libosmocore strict-aliasing-punning gprs_bssgp_bss.c:53, 54, 76, 77, 101, 102, 123, 124, 199, 200, 225, 226, 249, 250, 269, 270, 289, 290, 329, 330, 343, 350 [ 78s] W: libosmocore strict-aliasing-punning gprs_bssgp_util.c:85, 86, 104, 105, 114 [ 78s] W: libosmocore strict-aliasing-punning gprs_ns.c:558, 560, 562, 610, 611, 809 [ 78s] W: libosmocore strict-aliasing-punning osmo-auc-gen.c:216, 217, 218, 219 [ 78s] E: libosmocore 64bit-portability-issue gprs_bssgp.c:470 From thus0.petrus at gmail.com Thu Aug 2 06:57:15 2012 From: thus0.petrus at gmail.com (Thus0 Petrus) Date: Thu, 2 Aug 2012 08:57:15 +0200 Subject: HLR and EAP-SIM integration Message-ID: Hello everybody, I'm trying to make a testbed for EAP-SIM with freeradius to authenticate on a WLAN network. it works well thanks to the patch provided by seek-for-android : you can see the details here : http://code.google.com/p/seek-for-android/wiki/EapSimAka but you need to store IMSI, RAND, SRES, KC in a flat file as by default, we don't have the Ki of SIM cards and don't have a HLR so we need to precalculate these values. For our testbed, we're using some MagicSIM we've programmed with our own Ki. So I wonder if anybody has already done some integration of freeradius with openbsc HLR to do EAP-SIM ? Or is there a tool to calculate the triplets (RAND, SRES, KC) with input the IMSI (and Ki stored in the database) ? If not, could someone points me where to start to write my own tool ? I don't think pysim can do it... I found an entry about A3/A8 authentication here http://openbsc.osmocom.org/trac/changeset/3606cc576502b95d4973fac2af76d1b9bdc4705b int get_authtuple_by_subscr(struct gsm_auth_tuple *atuple, struct gsm_subscriber *subscr) ...but I want to calculate gsm_auth_tuple, not retreive it from the database... Thanks for any information :) -- Thus0 -------------- next part -------------- An HTML attachment was scrubbed... URL: From laforge at gnumonks.org Thu Aug 2 07:39:34 2012 From: laforge at gnumonks.org (Harald Welte) Date: Thu, 2 Aug 2012 09:39:34 +0200 Subject: HLR and EAP-SIM integration In-Reply-To: References: Message-ID: <20120802073934.GA16661@prithivi.gnumonks.org> Hi Thus0, On Thu, Aug 02, 2012 at 08:57:15AM +0200, Thus0 Petrus wrote: > I'm trying to make a testbed for EAP-SIM with freeradius to authenticate on > a WLAN network. > it works well thanks to the patch provided by seek-for-android : you can > see the details here : > http://code.google.com/p/seek-for-android/wiki/EapSimAka > but you need to store IMSI, RAND, SRES, KC in a flat file as by default, we > don't have the Ki of SIM cards > and don't have a HLR so we need to precalculate these values. I see. But then, why is that a problem or an insufficient solution? Without the Ki, you _need_ to use precomputed values, there's no other chance. > For our testbed, we're using some MagicSIM we've programmed with our own Ki. > So I wonder if anybody has already done some integration of freeradius with > openbsc HLR to do EAP-SIM ? The OpenBSC "HLR" is an integral part of OsmoNITB itself. At the moment, we don't have any interfaces by which external applications can query it. Separating it out from OsmoNITB is on the TODO list for some time now, but it hasn't happened yet. > Or is there a tool to calculate the triplets (RAND, SRES, KC) with input > the IMSI (and Ki stored in the database) ? Please check osmo-auc-gen from the tools subdirectory of libosmocore. It uses the authentication framework of libosmocore and user-provided Ki to compute RAND,SRES and Kc. However, it is just a stand-alone command-line program, and doesn't interface with any database. > If not, could someone points me where to start to write my own tool ? I > don't think pysim can do it... I'd suggest to base off the auth.c api of libosmocore, i.e. exactly the same functions that osmo-auc-gen utilize. Regards, Harald -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From laforge at gnumonks.org Mon Aug 6 07:44:46 2012 From: laforge at gnumonks.org (Harald Welte) Date: Mon, 6 Aug 2012 09:44:46 +0200 Subject: August 8, 8pm / Osmocom meeting in Berlin Message-ID: <20120806074446.GL26533@prithivi.gnumonks.org> Hi all! This is the announcement for the next Osmocom Berlin meeting. Aug 08, 8pm @ CCC Berlin, Marienstr. 11, 10113 Berlin Harald will be giving a short presentation on contemporary smartphone hardware architecture. Furthermore, updates and discussions on various current developments will be exchanged, such as * Demo of OsmoPCU on sysmoBTS * Status of new SMSC * Planning phase of custom calypso board If you are interested to show up, feel free to do so. There is no registration required. The meeting is free as in "free beer", despite no actual free beer being around. Updates and the blog post can be found here: http://openbsc.osmocom.org/trac/blog/osmug-20120808 -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From laforge at gnumonks.org Tue Aug 7 08:48:51 2012 From: laforge at gnumonks.org (Harald Welte) Date: Tue, 7 Aug 2012 10:48:51 +0200 Subject: August 8, 8pm / Osmocom meeting in Berlin In-Reply-To: <50203467.9000905@freenet.de> References: <20120806074446.GL26533@prithivi.gnumonks.org> <50203467.9000905@freenet.de> Message-ID: <20120807084851.GR26533@prithivi.gnumonks.org> Hi Matihas, On Mon, Aug 06, 2012 at 11:17:27PM +0200, Mathias K. wrote: > Where is the conference number? ;-). It would be nice to meet this > event virtually for none berlin citizens. Sorry, I don't really like the idea of having an unknown number of people listening in on conversations we have face to face. > Maybe there is some planning, maybe there is no reason/possibility to > do that. But there are some interesting topics that i want to hear, > maybe discuss. I suggest that you post any comments / questions / topics to the respective mailing lists. -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From spaar at mirider.augusta.de Tue Aug 7 09:27:54 2012 From: spaar at mirider.augusta.de (Dieter Spaar) Date: Tue, 07 Aug 2012 09:27:54 CEST Subject: Any interest for Osmocom meetings in Bavaria ? Message-ID: <5020df9b.mirider@mirider.augusta.de> I would like to ask if there is interest to have some kind of Osmocom meetings in Bavaria. Suggested location is here at my place in the south-east of Bavaria near Pfarrkirchen. There are no large cities close, but the location is still in reach with a car, some examples (single distance): - from Munich: 130 km - from Passau: 55 km - from Salzburg: 90 km - from Linz: 140 km Why at my place ? There is some GSM/3G/TETRA equipment and RF measurement gear around which could be demonstrated. It is not yet decided when and how (regular or "on demand") this meeting should take place. Before that I want to find out if there is interest at all and how many people are interested. So please write to the list what you think. Best regards, Dieter -- Dieter Spaar, Germany spaar at mirider.augusta.de From spaar at mirider.augusta.de Wed Aug 8 18:31:20 2012 From: spaar at mirider.augusta.de (Dieter Spaar) Date: Wed, 08 Aug 2012 18:31:20 CEST Subject: Any interest for Osmocom meetings in Bavaria ? Message-ID: <5022b079.mirider@mirider.augusta.de> As a quick follow up: The proposal for the meeting is intended for everyone interested in the various Osmocom projects (e.g. OpenBSC, OsmocomBB, TETRA, SimTrace, OsmoSDR). The meeting is not limited to only those who are actively participating. I will wait until next week to see how many people are interested, so far I am aware of two persons. Best regards, Dieter -- Dieter Spaar, Germany spaar at mirider.augusta.de From alexander.chemeris at gmail.com Wed Aug 8 16:44:12 2012 From: alexander.chemeris at gmail.com (Alexander Chemeris) Date: Wed, 8 Aug 2012 20:44:12 +0400 Subject: Any interest for Osmocom meetings in Bavaria ? In-Reply-To: <5022b079.mirider@mirider.augusta.de> References: <5022b079.mirider@mirider.augusta.de> Message-ID: I'd love to join, but it strongly depends on the exact dates of the meeting. I have very tight travel schedule in the next months. On Wed, Aug 8, 2012 at 7:31 PM, Dieter Spaar wrote: > As a quick follow up: The proposal for the meeting is intended > for everyone interested in the various Osmocom projects (e.g. > OpenBSC, OsmocomBB, TETRA, SimTrace, OsmoSDR). The meeting is > not limited to only those who are actively participating. > > I will wait until next week to see how many people are > interested, so far I am aware of two persons. > > Best regards, > Dieter > -- > Dieter Spaar, Germany spaar at mirider.augusta.de > -- Regards, Alexander Chemeris. CEO, Fairwaves LLC / ??? ??????? http://fairwaves.ru From spaar at mirider.augusta.de Wed Aug 8 19:06:47 2012 From: spaar at mirider.augusta.de (Dieter Spaar) Date: Wed, 08 Aug 2012 19:06:47 CEST Subject: Any interest for Osmocom meetings in Bavaria ? Message-ID: <5022b8c7.mirider@mirider.augusta.de> Hello Alexander, On Wed, 8 Aug 2012 20:44:12 +0400, "Alexander Chemeris" wrote: > > I'd love to join, but it strongly depends on the exact dates of the > meeting. I have very tight travel schedule in the next months. Just to avoid any misunderstanding: Those meetings are not supposed to be something similar to the Osmocom Developer Conference earlier this year. The idea is to have a regular or "on demand" oportunity to meet with people for a few hours and demonstrate or talk about the Osmocom projects or share new ideas. Its comparable to the regular Berlin meetings, you can get an idea of what goes on there: http://openbsc.osmocom.org/trac/blog/osmug-20120808 Of course you can attend, if you are close (Munich airport is 120 km away) but I would expect that Berlin is more convenient if you come from really far away and Berlin already has regular meetings. Best regards, Dieter -- Dieter Spaar, Germany spaar at mirider.augusta.de From spaar at mirider.augusta.de Thu Aug 16 14:20:24 2012 From: spaar at mirider.augusta.de (Dieter Spaar) Date: Thu, 16 Aug 2012 14:20:24 CEST Subject: Any interest for Osmocom meetings in Bavaria ? Message-ID: <502d01a9.mirider@mirider.augusta.de> So far three persons have indicated their interest to join a meeting at my place. Considering the time it takes to drive to my place, it probably makes sense to have the meeting at the weekend (either Saturday or Sunday) so that there is more time for the meeting itself. I can suggest one of the following dates for the first meeting, somewhere between 10:00 to 18:00 on each day: 25.8. (Sa) or 26.8. (Su) 1.9. (Sa) or 2.9. (Su) 8.9. (Sa) or 9.9. (Su) So please let me know when you have time and also make suggestions in which Osmocom topic you are interested in so that we can have some sort of agenda for the meeting to make best use of the time. Best regards, Dieter -- Dieter Spaar, Germany spaar at mirider.augusta.de From osmocom at blombo.de Thu Aug 16 19:21:20 2012 From: osmocom at blombo.de (Martin Auer) Date: Thu, 16 Aug 2012 21:21:20 +0200 Subject: Any interest for Osmocom meetings in Bavaria ? In-Reply-To: <502d01a9.mirider@mirider.augusta.de> References: <502d01a9.mirider@mirider.augusta.de> Message-ID: <0C6708D1-91C7-42AC-98AC-D71306323358@blombo.de> Am 16.08.2012 um 14:20 schrieb "Dieter Spaar" : > So far three persons have indicated their interest to join > a meeting at my place. > Perfect > Considering the time it takes to drive to my place, it > probably makes sense to have the meeting at the weekend > (either Saturday or Sunday) so that there is more time > for the meeting itself. I can suggest one of the following > dates for the first meeting, somewhere between 10:00 to > 18:00 on each day: > Sounds good to me. > 25.8. (Sa) or 26.8. (Su) both possible or me > 1.9. (Sa) or 2.9. (Su) I prefer Sa, Su not possible > 8.9. (Sa) or 9.9. (Su) > I prefer Sa, Su might also work > So please let me know when you have time and also make > suggestions in which Osmocom topic you are interested > in so that we can have some sort of agenda for the > meeting to make best use of the time. As I was only playing around with osmocom.bb and having basic knowledge in GSM and other 3GPP protocols I am open to every topic. Tetra is of interest for me because of the "Digitaler Beh?rdenfunk" (firefighters) and I am especially interested in anything SIGTRAN-related. > > Best regards, > Dieter > -- > Dieter Spaar, Germany spaar at mirider.augusta.de > From laforge at gnumonks.org Sat Aug 18 11:59:43 2012 From: laforge at gnumonks.org (Harald Welte) Date: Sat, 18 Aug 2012 13:59:43 +0200 Subject: Any interest for Osmocom meetings in Bavaria ? In-Reply-To: <502d01a9.mirider@mirider.augusta.de> References: <502d01a9.mirider@mirider.augusta.de> Message-ID: <20120818115942.GV29525@prithivi.gnumonks.org> Hi all, On Thu, Aug 16, 2012 at 02:20:24PM +0200, Dieter Spaar wrote: > 25.8. (Sa) or 26.8. (Su) > 1.9. (Sa) or 2.9. (Su) > 8.9. (Sa) or 9.9. (Su) I'm fine with any of those dates. So I'll leave it to the other attendeeds to decide on the date. I currently cannot confirm 100% yet, but at least if no urgent issue comes up, I'm planning to be there. It would be a nice 630km motorbike ride from Berlin, if the weather is not too bad... Regards, Harald -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From dongizzmo at gmx.de Sun Aug 19 19:51:04 2012 From: dongizzmo at gmx.de (Don Gizzmo) Date: Sun, 19 Aug 2012 21:51:04 +0200 Subject: AW: Any interest for Osmocom meetings in Bavaria ? In-Reply-To: <20120818115942.GV29525@prithivi.gnumonks.org> References: <502d01a9.mirider@mirider.augusta.de> <20120818115942.GV29525@prithivi.gnumonks.org> Message-ID: <053c01cd7e43$f801f980$e805ec80$@gmx.de> Hi, On Thu, Aug 16, 2012 at 02:20:24PM +0200, Dieter Spaar wrote: > 25.8. (Sa) or 26.8. (Su) > 1.9. (Sa) or 2.9. (Su) > 8.9. (Sa) or 9.9. (Su) I prefer the second weekend (1.9./2.9). Whether it's Saturday or Sunday I don't mind, both is possible for me. I'm open to every topic that's GSM-related (and newer protocols). Tetra is also interesting. Like Martin I was playing around with osmocom.bb and have basic GSM-knowledge. Regards, Alex From ellen.apolinar.td at googlemail.com Mon Aug 20 14:26:04 2012 From: ellen.apolinar.td at googlemail.com (Ellen Apolinar) Date: Mon, 20 Aug 2012 16:26:04 +0200 Subject: Any interest for Osmocom meetings in Bavaria ? In-Reply-To: <053c01cd7e43$f801f980$e805ec80$@gmx.de> References: <502d01a9.mirider@mirider.augusta.de> <20120818115942.GV29525@prithivi.gnumonks.org> <053c01cd7e43$f801f980$e805ec80$@gmx.de> Message-ID: btw. where is the location when it is 630 km away from Berlin? On Sun, Aug 19, 2012 at 9:51 PM, Don Gizzmo wrote: > Hi, > > On Thu, Aug 16, 2012 at 02:20:24PM +0200, Dieter Spaar wrote: > > 25.8. (Sa) or 26.8. (Su) > > 1.9. (Sa) or 2.9. (Su) > > 8.9. (Sa) or 9.9. (Su) > > I prefer the second weekend (1.9./2.9). Whether it's Saturday or Sunday I > don't mind, both is possible for me. > > I'm open to every topic that's GSM-related (and newer protocols). Tetra is > also interesting. Like Martin I was playing around with osmocom.bb and > have > basic GSM-knowledge. > > Regards, > Alex > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From laforge at gnumonks.org Tue Aug 21 07:02:32 2012 From: laforge at gnumonks.org (Harald Welte) Date: Tue, 21 Aug 2012 09:02:32 +0200 Subject: Any interest for Osmocom meetings in Bavaria ? In-Reply-To: References: <502d01a9.mirider@mirider.augusta.de> <20120818115942.GV29525@prithivi.gnumonks.org> <053c01cd7e43$f801f980$e805ec80$@gmx.de> Message-ID: <20120821070232.GA16295@prithivi.gnumonks.org> Dear Ellen, On Mon, Aug 20, 2012 at 04:26:04PM +0200, Ellen Apolinar wrote: > btw. where is the location when it is 630 km away from Berlin? As Dieter wrote in his original post: > at my place in the south-east of Bavaria near Pfarrkirchen So if you just type "Pfarrkirchen, Germany" into your favorite internet map service, you should get a pretty clear idea. As there seems to be frequent misconception: This is _not_ a developer conference or anything like that. Just an informal user group meeting, like those we have in Berlin every two weeks. Regards, Harald -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From spaar at mirider.augusta.de Wed Aug 22 13:25:02 2012 From: spaar at mirider.augusta.de (Dieter Spaar) Date: Wed, 22 Aug 2012 13:25:02 CEST Subject: Any interest for Osmocom meetings in Bavaria ? Message-ID: <5034ddae.mirider@mirider.augusta.de> I have now selected the day for the meeting which should match for all who have send me their preferred days. The first Osmocom meeting in Bavaria near Pfarrkirchen will be held on: Saturday, 1. September, starting at 10:00 If you are going to come, please let me know until next Wednesday (29. August). I will then send you a private email with the details of the location. The agenda is not yet set, but it seems that at least those who send me their areas of interest are mainly targeted towards GMS (OpenBSC/OsmocomBB). We can of course also talk about other stuff, e.g. RTL-SDR, but for this it would be nice if one of the RTL-SDR experts would join us (here you have the chance to receive a nearly clean/empty spectrum without much noise from other sources ;-). Best regards, Dieter -- Dieter Spaar, Germany spaar at mirider.augusta.de From spaar at mirider.augusta.de Wed Aug 29 19:58:42 2012 From: spaar at mirider.augusta.de (Dieter Spaar) Date: Wed, 29 Aug 2012 19:58:42 CEST Subject: Any interest for Osmocom meetings in Bavaria ? Message-ID: <503e7472.mirider@mirider.augusta.de> As already mentioned, the Osmocom Meeting will take place this Saturday, 1.9.2012 at 10:00. Three people have confirmed that they will come, I have send them an email with the location details. Harald is not yet sure if he can attend. A few suggestions for the meeting: - I will run a GSM-1800 network with my test license so you can try out OsmocomBB. If you are interested to do so please bring your Osmocom phone plus Laptop with the already installed OsmocomBB software. - We can do some experiments with SIMtrace if there is any interest. - There should still be enough time for other things, we can decide what to do during the meeting. Best regards, Dieter -- Dieter Spaar, Germany spaar at mirider.augusta.de From andreas at eversberg.eu Mon Aug 20 06:51:57 2012 From: andreas at eversberg.eu (Andreas Eversberg) Date: Mon, 20 Aug 2012 08:51:57 +0200 Subject: fix of rtp socket binding Message-ID: <5031DE8D.5000505@eversberg.eu> hi, after having solved an LCR issue, i patched rtp_proxy.c the same way, because it has the same issue. 1. when next_udp_port (in rtp_socket_bind) reaches 0xfffe, the bind process will fail next time. 2. if rtp_sub_socket_bind of rtp socket succeeds and rtp_sub_socket_bind of rtcp socket fails, the rtp socket must be re-created, because it cannot not be bound again to the next higher port. 3. the port range will not wrap arround and start at 0, but at RTP_PORT_BASE. (after reaching RTP_PORT_MAX) andreas -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: patch URL: From holger at freyther.de Wed Aug 22 09:04:23 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Wed, 22 Aug 2012 11:04:23 +0200 Subject: fix of rtp socket binding In-Reply-To: <5031DE8D.5000505@eversberg.eu> References: <5031DE8D.5000505@eversberg.eu> Message-ID: <20120822090423.GD4301@localhost> On Mon, Aug 20, 2012 at 08:51:57AM +0200, Andreas Eversberg wrote: > hi, Hi Andreas, my two cents below. > out_rtcp_bfd: > - osmo_fd_unregister(&rs->rtcp.bfd); > + if (rs->rtcp.bfd.fd > 0) { > + osmo_fd_unregister(&rs->rtcp.bfd); We had this before but I don't remember if it was with the socket code. A filedescriptor of '0' is valid. An unitiliazed bfd.fd should be set to -1. > out_rtcp_socket: > - close(rs->rtcp.bfd.fd); > + close(rs->rtcp.bfd.fd); > + } But more importantly... why do we need to have these extra checks? The code should only jump to the cleanup label that needs to be cleaned up. So if the rtcp.bfd has not been registered, the code should not jump to out_rtcp_bfd. > /* try to bind to a consecutive pair of ports */ > - for (next_udp_port = next_udp_port % 0xffff; > - next_udp_port < 0xffff; next_udp_port += 2) { > + start_port = next_udp_port; > + while (1) { > rc = rtp_sub_socket_bind(&rs->rtp, ip, next_udp_port); > if (rc != 0) > - continue; > + goto try_next_port; > > rc = rtp_sub_socket_bind(&rs->rtcp, ip, next_udp_port+1); > - if (rc == 0) > + if (rc == 0) { > + next_udp_port = (next_udp_port + 2 > RTP_PORT_MAX) ? > + RTP_PORT_BASE : next_udp_port + 2; code duplication, please move the calculation to a macro or inline function. > + init_rss(&rs->rtp, rs, rc2, RTP_PRIV_RTP); > + rc2 = osmo_fd_register(&rs->rtp.bfd); > + if (rc2 < 0) { > + close(rs->rtp.bfd.fd); > + return rc2; > + } Can you think of a way to have rtp_socket_create and this somehow share the code to initialize the > +try_next_port: > + next_udp_port = (next_udp_port + 2 > RTP_PORT_MAX) ? > + RTP_PORT_BASE : next_udp_port + 2; > + if (next_udp_port == start_port) > break; > + /* we must use rc2, in order to preserve rc */ Hmm, maybe I deleted too much from the patch but break is only called when rc == 0 and for all other errors you return immediately? > } > if (rc < 0) { > DEBUGPC(DLMUX, "failed\n"); I think this is dead code. From andreas at eversberg.eu Wed Aug 29 06:22:22 2012 From: andreas at eversberg.eu (jolly) Date: Wed, 29 Aug 2012 08:22:22 +0200 Subject: fix of rtp socket binding In-Reply-To: <20120822090423.GD4301@localhost> References: <5031DE8D.5000505@eversberg.eu> <20120822090423.GD4301@localhost> Message-ID: <503DB51E.2020701@eversberg.eu> hi holger, i reworked the patch. Holger Hans Peter Freyther wrote: > We had this before but I don't remember if it was with the socket code. A > filedescriptor of '0' is valid. An unitiliazed bfd.fd should be set to -1. > > But more importantly... why do we need to have these extra checks? The > code should only jump to the cleanup label that needs to be cleaned up. > So if the rtcp.bfd has not been registered, the code should not jump to > out_rtcp_bfd. > the checks were required, because rtp_socket_bind() might have closed a socked. i removed the checks and closed both rtp and rtcp sockets at rtp_socket_bind(). > code duplication, please move the calculation to a macro or inline function. > done. >> + init_rss(&rs->rtp, rs, rc2, RTP_PRIV_RTP); >> + rc2 = osmo_fd_register(&rs->rtp.bfd); >> + if (rc2 < 0) { >> + close(rs->rtp.bfd.fd); >> + return rc2; >> + } >> > Can you think of a way to have rtp_socket_create and this somehow share the > code to initialize the > > alternatively the create and rtp_sub_socket_create and rtp_sub_socket_close. this makes more work, but i was lazy. > >> +try_next_port: >> + next_udp_port = (next_udp_port + 2 > RTP_PORT_MAX) ? >> + RTP_PORT_BASE : next_udp_port + 2; >> + if (next_udp_port == start_port) >> break; >> + /* we must use rc2, in order to preserve rc */ >> > Hmm, maybe I deleted too much from the patch but break is only called > when rc == 0 and for all other errors you return immediately? > > > >> } >> if (rc < 0) { >> DEBUGPC(DLMUX, "failed\n"); >> > I think this is dead code. > The code is not dead. If bind of rtp socket failed to bind, rc is -1, else if all sockets are tried, rc is -1, because the rtcp socket failed to bind. if rc==0, both sockets are bound. regards, andreas -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: rtp-bind-fix2.patch URL: From pablo at gnumonks.org Thu Aug 30 19:45:51 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 30 Aug 2012 21:45:51 +0200 Subject: fix of rtp socket binding In-Reply-To: <503DB51E.2020701@eversberg.eu> References: <5031DE8D.5000505@eversberg.eu> <20120822090423.GD4301@localhost> <503DB51E.2020701@eversberg.eu> Message-ID: <20120830194551.GA18081@1984> Hi Jolly, A couple of comments on your patch. On Wed, Aug 29, 2012 at 08:22:22AM +0200, jolly wrote: > hi holger, > > i reworked the patch. > > Holger Hans Peter Freyther wrote: > > We had this before but I don't remember if it was with the socket code. A > > filedescriptor of '0' is valid. An unitiliazed bfd.fd should be set to -1. > > > > But more importantly... why do we need to have these extra checks? The > > code should only jump to the cleanup label that needs to be cleaned up. > > So if the rtcp.bfd has not been registered, the code should not jump to > > out_rtcp_bfd. > > > the checks were required, because rtp_socket_bind() might have closed a > socked. i removed the checks and closed both rtp and rtcp sockets at > rtp_socket_bind(). > > code duplication, please move the calculation to a macro or inline function. > > > done. > >> + init_rss(&rs->rtp, rs, rc2, RTP_PRIV_RTP); > >> + rc2 = osmo_fd_register(&rs->rtp.bfd); > >> + if (rc2 < 0) { > >> + close(rs->rtp.bfd.fd); > >> + return rc2; > >> + } > >> > > Can you think of a way to have rtp_socket_create and this somehow share the > > code to initialize the > > > > > alternatively the create and rtp_sub_socket_create and > rtp_sub_socket_close. this makes more work, but i was lazy. > > > >> +try_next_port: > >> + next_udp_port = (next_udp_port + 2 > RTP_PORT_MAX) ? > >> + RTP_PORT_BASE : next_udp_port + 2; > >> + if (next_udp_port == start_port) > >> break; > >> + /* we must use rc2, in order to preserve rc */ > >> > > Hmm, maybe I deleted too much from the patch but break is only called > > when rc == 0 and for all other errors you return immediately? > > > > > > > >> } > >> if (rc < 0) { > >> DEBUGPC(DLMUX, "failed\n"); > >> > > I think this is dead code. > > > The code is not dead. If bind of rtp socket failed to bind, rc is -1, > else if all sockets are tried, rc is -1, because the rtcp socket failed > to bind. if rc==0, both sockets are bound. > > > regards, > > andreas > > diff --git a/openbsc/src/libtrau/rtp_proxy.c b/openbsc/src/libtrau/rtp_proxy.c > index 3d34ac6..36629ae 100644 > --- a/openbsc/src/libtrau/rtp_proxy.c > +++ b/openbsc/src/libtrau/rtp_proxy.c > @@ -555,12 +555,10 @@ struct rtp_socket *rtp_socket_create(void) > > rc = rtp_socket_bind(rs, INADDR_ANY); > if (rc < 0) > - goto out_rtcp_bfd; > + goto out_free; > > return rs; > > -out_rtcp_bfd: > - osmo_fd_unregister(&rs->rtcp.bfd); > out_rtcp_socket: > close(rs->rtcp.bfd.fd); > out_rtp_bfd: > @@ -595,39 +593,76 @@ static int rtp_sub_socket_bind(struct rtp_sub_socket *rss, uint32_t ip, > &alen); > } > > -#define RTP_PORT_BASE 30000 > -static unsigned int next_udp_port = RTP_PORT_BASE; > +#define RTP_PORT_BASE 30000 > +#define RTP_PORT_MAX 39998 > +#define NEXT_UDP_PORT next_udp_port = (next_udp_port + 2 > RTP_PORT_MAX) ? \ > + RTP_PORT_BASE : next_udp_port + 2 > +static unsigned short next_udp_port = RTP_PORT_BASE; > > /* bind a RTP socket to a local address */ > int rtp_socket_bind(struct rtp_socket *rs, uint32_t ip) > { > - int rc = -EIO; > + int rc, rc2; > struct in_addr ia; > + unsigned short start_port; > > ia.s_addr = htonl(ip); > DEBUGP(DLMUX, "rtp_socket_bind(rs=%p, IP=%s): ", rs, > inet_ntoa(ia)); > > /* try to bind to a consecutive pair of ports */ > - for (next_udp_port = next_udp_port % 0xffff; > - next_udp_port < 0xffff; next_udp_port += 2) { > + start_port = next_udp_port; > + while (1) { Can you use 'for' instead of 'while', just for readability. The limited loop is also good in case that we forget break and loop forever (in case of bug, of course). > rc = rtp_sub_socket_bind(&rs->rtp, ip, next_udp_port); > - if (rc != 0) > - continue; > + if (rc < 0) > + goto try_next_port; > > rc = rtp_sub_socket_bind(&rs->rtcp, ip, next_udp_port+1); > - if (rc == 0) > + if (rc == 0) { > + NEXT_UDP_PORT; Could you use a function for this instead? The use of macros in this way seems a bit evil to me. More specifically, you have to scroll up and down in the code to know what it does and the absence of parameters and return value makes this obscure. > + next_udp_port = (next_udp_port + 2 > RTP_PORT_MAX) ? > + RTP_PORT_BASE : next_udp_port + 2; Why this call after NEXT_UDP_PORT again? Is it a leftover? > + break; > + } > > + /* reopen rtp socket and try again with next udp port */ > + osmo_fd_unregister(&rs->rtp.bfd); > + close(rs->rtp.bfd.fd); > + rs->rtp.bfd.fd = -1; Suggestion: from here below > + rc2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); > + if (rc2 < 0) { > + rc = rc2; > + goto out_rtp; > + } > + init_rss(&rs->rtp, rs, rc2, RTP_PRIV_RTP); > + rc2 = osmo_fd_register(&rs->rtp.bfd); > + if (rc2 < 0) { > + close(rs->rtp.bfd.fd); > + rc = rc2; > + goto out_rtp; > + } To here, I'd move this code to a function. > +try_next_port: > + NEXT_UDP_PORT; > + if (next_udp_port == start_port) > break; > + /* we must use rc2, in order to preserve rc */ > } > if (rc < 0) { > DEBUGPC(DLMUX, "failed\n"); > - return rc; > + goto out_rtcp; > } > > ia.s_addr = rs->rtp.sin_local.sin_addr.s_addr; > DEBUGPC(DLMUX, "BOUND_IP=%s, BOUND_PORT=%u\n", > inet_ntoa(ia), ntohs(rs->rtp.sin_local.sin_port)); > return ntohs(rs->rtp.sin_local.sin_port); > + > +out_rtcp: > + osmo_fd_unregister(&rs->rtcp.bfd); > + close(rs->rtcp.bfd.fd); > +out_rtp: > + osmo_fd_unregister(&rs->rtp.bfd); > + close(rs->rtp.bfd.fd); > + return rc; > } > > static int rtp_sub_socket_connect(struct rtp_sub_socket *rss, From zecke at selfish.org Mon Aug 20 13:14:29 2012 From: zecke at selfish.org (Holger Hans Peter Freyther) Date: Mon, 20 Aug 2012 15:14:29 +0200 Subject: [PATCH] e1: Memory leak/Reference leak on the e1inp_line Message-ID: <1345468469-5159-1-git-send-email-zecke@selfish.org> Release the e1inp_line when the signalling link is destroyed. The e1inp_line was leaked on every OML/RSL disconnect. The leak occured on the following call path. e1inp_close_socket ipaccess_close e1inp_sign_link_destroy ipaccess_drop_oml ipaccess_drop handle_ts1_read ipaccess_fd_cb --- src/e1_input.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/e1_input.c b/src/e1_input.c index 957b74c..a85dd91 100644 --- a/src/e1_input.c +++ b/src/e1_input.c @@ -486,6 +486,7 @@ void e1inp_sign_link_destroy(struct e1inp_sign_link *link) if (link->ts->line->driver->close) link->ts->line->driver->close(link); + e1inp_line_put(link->ts->line); talloc_free(link); } -- 1.7.10.4 From pablo at gnumonks.org Tue Aug 21 01:10:32 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Tue, 21 Aug 2012 03:10:32 +0200 Subject: [PATCH] e1: Memory leak/Reference leak on the e1inp_line In-Reply-To: <1345468469-5159-1-git-send-email-zecke@selfish.org> References: <1345468469-5159-1-git-send-email-zecke@selfish.org> Message-ID: <20120821011032.GA25007@1984> Hi Holger, On Mon, Aug 20, 2012 at 03:14:29PM +0200, Holger Hans Peter Freyther wrote: > Release the e1inp_line when the signalling link is destroyed. The > e1inp_line was leaked on every OML/RSL disconnect. > > The leak occured on the following call path. > e1inp_close_socket > ipaccess_close > e1inp_sign_link_destroy > ipaccess_drop_oml > ipaccess_drop > handle_ts1_read > ipaccess_fd_cb > --- > src/e1_input.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/src/e1_input.c b/src/e1_input.c > index 957b74c..a85dd91 100644 > --- a/src/e1_input.c > +++ b/src/e1_input.c > @@ -486,6 +486,7 @@ void e1inp_sign_link_destroy(struct e1inp_sign_link *link) > if (link->ts->line->driver->close) > link->ts->line->driver->close(link); > > + e1inp_line_put(link->ts->line); > talloc_free(link); Good catch. If you want to fix it like that, I think that you also need to add the following chunk below: diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 76d1994..3185bc0 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -249,9 +249,6 @@ static int ipaccess_drop(struct osmo_fd *bfd) bfd->fd = -1; ret = -ENOENT; } - /* put the virtual E1 line that we cloned for this socket, if - * it becomes unused, it gets released. */ - e1inp_line_put(line); return ret; } IIRC, the refcnt becomes 2 if both the OML and RSL links are up. ipaccess_drop calls line->ops->sign_link_down(line), which usually call e1inp_sign_link_destroy twice (one for the RSL link, and one for the OML link). With your patch, the refcount becomes zero after the two e1inp_sign_link_destroy calls that happen in ->sign_link_down. Thus, releasing the line that we were leaking. Still, if you don't remove that e1inp_line_put in ipaccess_drop, you hit an access-after-release since e1inp_line_put takes an already released line. But let me check this tomorrow again after some sleeping :-). From holger at freyther.de Tue Aug 21 07:20:54 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Tue, 21 Aug 2012 09:20:54 +0200 Subject: [PATCH] e1: Memory leak/Reference leak on the e1inp_line In-Reply-To: <20120821011032.GA25007@1984> References: <1345468469-5159-1-git-send-email-zecke@selfish.org> <20120821011032.GA25007@1984> Message-ID: <20120821072054.GB3904@localhost> On Tue, Aug 21, 2012 at 03:10:32AM +0200, Pablo Neira Ayuso wrote: > Hi Holger, Hi Pablo, > IIRC, the refcnt becomes 2 if both the OML and RSL links are up. hehe, not really sure. The _rsl_cb will will clone the e1inp_line but I think after we know which BTS is making the connection we throw away the cloned line and _get_line the OML one. > With your patch, the refcount becomes zero after the two > e1inp_sign_link_destroy calls that happen in ->sign_link_down. Thus, > releasing the line that we were leaking. Sounds plausible. Luckily you only free the link when it becomes 0 (and not smaller). I am going to add an assertion for >= 0 for the refcount. > But let me check this tomorrow again after some sleeping :-). thanks From pablo at gnumonks.org Wed Aug 22 17:38:40 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Wed, 22 Aug 2012 19:38:40 +0200 Subject: [PATCH] e1: Memory leak/Reference leak on the e1inp_line In-Reply-To: <20120821072054.GB3904@localhost> References: <1345468469-5159-1-git-send-email-zecke@selfish.org> <20120821011032.GA25007@1984> <20120821072054.GB3904@localhost> Message-ID: <20120822173840.GA23253@1984> On Tue, Aug 21, 2012 at 09:20:54AM +0200, Holger Hans Peter Freyther wrote: > On Tue, Aug 21, 2012 at 03:10:32AM +0200, Pablo Neira Ayuso wrote: > > Hi Holger, > > Hi Pablo, > > > IIRC, the refcnt becomes 2 if both the OML and RSL links are up. > > hehe, not really sure. The _rsl_cb will will clone the e1inp_line > but I think after we know which BTS is making the connection we > throw away the cloned line and _get_line the OML one. > > > With your patch, the refcount becomes zero after the two > > e1inp_sign_link_destroy calls that happen in ->sign_link_down. Thus, > > releasing the line that we were leaking. > > Sounds plausible. Luckily you only free the link when it becomes > 0 (and not smaller). I am going to add an assertion for >= 0 for > the refcount. Hm, I'm looking again at the last patch I sent and it's not correct either. If we call ipaccess_drop, all signalling links are released since e1inp_sign_link_destroy destroys all sockets (it calls ipaccess_close). So, your patch is almost right. We have to e1inp_line_put in e1inp_sign_link_destroy. But we have to remove e1inp_line_put in the ipaccess and hsl drivers. I'll resend a patch for this. From laforge at gnumonks.org Tue Aug 21 07:10:24 2012 From: laforge at gnumonks.org (Harald Welte) Date: Tue, 21 Aug 2012 09:10:24 +0200 Subject: Aug 22, 8pm / Osmocom Berlin User Group meeting Message-ID: <20120821071024.GB16295@prithivi.gnumonks.org> Hi all! This is the announcement for the next Osmocom Berlin meeting. Aug 22, 8pm @ CCC Berlin, Marienstr. 11, 10113 Berlin There is no formal presentation scheduled for this meeting. However, updates will be provided on various current developments, such as * Progress on the CC32RS512 smart card (osmo-cos) * Possibly: Status of current attempts to get CSD implemented in OpenBSC If you are interested to show up, feel free to do so. There is no registration required. The meeting is free as in "free beer", despite no actual free beer being around. Regards, Harald -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From pfc.rivas at gmail.com Tue Aug 21 16:16:59 2012 From: pfc.rivas at gmail.com (Arturo Rivas) Date: Tue, 21 Aug 2012 18:16:59 +0200 Subject: OpenGGSN over OpenBSC+LCR+Asterisk Message-ID: <5D8F02E3-4F42-45A2-8428-3D14EE632DB0@gmail.com> Hi list! I have a working installation of OpenBSC+LCR+Asterisk in my system and now, I want to install OpenGGSN in addiction. I am trying tutorial of the next link: http://openbsc.osmocom.org/trac/wiki/OpenBSC_GPRS and I don't know if the new compilation of osmo-nitb will crash previous installation. I think that I have to install new programs in the same location where previous are but if I am not sure about because this could crash it. Thank you! Arturo Rivas. From laforge at gnumonks.org Wed Aug 22 07:55:51 2012 From: laforge at gnumonks.org (Harald Welte) Date: Wed, 22 Aug 2012 09:55:51 +0200 Subject: OpenGGSN over OpenBSC+LCR+Asterisk In-Reply-To: <5D8F02E3-4F42-45A2-8428-3D14EE632DB0@gmail.com> References: <5D8F02E3-4F42-45A2-8428-3D14EE632DB0@gmail.com> Message-ID: <20120822075551.GQ6135@prithivi.gnumonks.org> Hi Arturo, On Tue, Aug 21, 2012 at 06:16:59PM +0200, Arturo Rivas wrote: > I think that I have to install new programs in the same location where > previous are but if I am not sure about because this could crash it. you don't even _have_ to install openbsc/osmo-sgsn/openggsn at all, you can start them right out of their respective source tree. And while having multiple versions installed in different directories is likely to confuse the human user (making mistakes), the software itself doesn't have problems with it. The only part you need to be careful about is the libraries (libosmcoore, libosmo-abis, etc.) - they need to be installed. And I suggest that you either always install to the same directory, or you use "make uninstall" from the _old_ source tree before you install the new version. -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From holger at freyther.de Wed Aug 22 08:40:35 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Wed, 22 Aug 2012 10:40:35 +0200 Subject: OpenGGSN over OpenBSC+LCR+Asterisk In-Reply-To: <5D8F02E3-4F42-45A2-8428-3D14EE632DB0@gmail.com> References: <5D8F02E3-4F42-45A2-8428-3D14EE632DB0@gmail.com> Message-ID: <20120822084035.GC4301@localhost> On Tue, Aug 21, 2012 at 06:16:59PM +0200, Arturo Rivas wrote: > Hi list! Good Morning, > > I have a working installation of OpenBSC+LCR+Asterisk in my system and now, I want to install OpenGGSN in addiction. > > I am trying tutorial of the next link: http://openbsc.osmocom.org/trac/wiki/OpenBSC_GPRS and I don't know if the new compilation of osmo-nitb will crash previous installation. > > I think that I have to install new programs in the same location where previous are but if I am not sure about because this could crash it. What do you mean with "crash previous installation"? OpenGGSN provides a library called libgtp. It is an implementation of the GTP protocol used by the SGSN and GGSN to communicate with each other. Depending on when you built OpenGGSN you might or might not have had a installed version of libgtp. This matters because at the time you "./configure" OpenBSC it will decide to build or not build the OsmoSGSN application. Building with the libgtp library present does not influence the build of osmo-nitb. holger From pablo at gnumonks.org Wed Aug 22 15:04:42 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:42 +0200 Subject: [PATCH 00/11] libosmo-abis updates Message-ID: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Hi, The following patchset contain updates for libosmo-abis: * fix for leak of e1inp_line reported by Holger. * more robust handling of error codes in several parts of the ipaccess driver. * minor cleanups for LAPD and dahdi, fix some compilations warnings. * generic LAPD PCAP interface to create PCAP files containing the LAPD frames, so far it was only possible to store the OML/RSL traces, without the LAPD frames. * fix crash of IPA BTS example test If you're OK with those, let me know. I can push them myself if you want or you can manually apply them. Pablo Neira Ayuso (11): ipa: fix missing set of write_cb for IPA client connection ipaccess: fix leak of e1inp_line tests: e1inp_ipa_bsc_test: fix crash ipaccess: more robust error handle in receival path ipaccess: more robust error handling in the accept patch ipaccess: more robust error handling in the send path tests: e1inp_ipa_bts_test: fix compilation warnings lapd: use C99 structure initialization for profile templates input: dahdi: use logging facilities instead of fprintf and stderr input: dahdi: replace exit by return input: add generic PCAP interface for LAPD include/Makefile.am | 2 +- include/osmocom/abis/lapd.h | 1 + include/osmocom/abis/lapd_pcap.h | 11 +++ src/Makefile.am | 1 + src/input/dahdi.c | 54 ++++++++----- src/input/ipa.c | 13 +++- src/input/ipaccess.c | 107 ++++++++++++++++++++----- src/input/lapd.c | 66 +++++++++------- src/input/lapd_pcap.c | 160 ++++++++++++++++++++++++++++++++++++++ tests/e1inp_ipa_bsc_test.c | 8 +- tests/e1inp_ipa_bts_test.c | 7 +- 11 files changed, 353 insertions(+), 77 deletions(-) create mode 100644 include/osmocom/abis/lapd_pcap.h create mode 100644 src/input/lapd_pcap.c -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 15:04:43 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:43 +0200 Subject: [PATCH 01/11] ipa: fix missing set of write_cb for IPA client connection In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-2-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Now the BTS and BSC tests work again. --- src/input/ipa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/input/ipa.c b/src/input/ipa.c index a887959..3c6a507 100644 --- a/src/input/ipa.c +++ b/src/input/ipa.c @@ -249,6 +249,9 @@ ipa_client_conn_create(void *ctx, struct e1inp_ts *ts, /* default to generic write callback if not set. */ if (write_cb == NULL) ipa_link->write_cb = ipa_client_write_default_cb; + else + ipa_link->write_cb = write_cb; + if (ts) ipa_link->line = ts->line; ipa_link->data = data; -- 1.7.10.4 From holger at freyther.de Thu Aug 23 07:03:21 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:03:21 +0200 Subject: [PATCH 01/11] ipa: fix missing set of write_cb for IPA client connection In-Reply-To: <1345647893-1286-2-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-2-git-send-email-pablo@gnumonks.org> Message-ID: <20120823070321.GK28195@localhost> On Wed, Aug 22, 2012 at 05:04:43PM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso Hi, > > Now the BTS and BSC tests work again. could you look into integrating your test with the GNU autotest testsuite we use in libosmocore/libosmo-sccp/openbsc? This way we would catch this issue at build time. > if (write_cb == NULL) > ipa_link->write_cb = ipa_client_write_default_cb; > + else > + ipa_link->write_cb = write_cb; > + this means that only the tests (and no real application) set a custom write_cb? is there another way to test? From pablo at gnumonks.org Thu Aug 23 17:17:32 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 23 Aug 2012 19:17:32 +0200 Subject: [PATCH 01/11] ipa: fix missing set of write_cb for IPA client connection In-Reply-To: <20120823070321.GK28195@localhost> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-2-git-send-email-pablo@gnumonks.org> <20120823070321.GK28195@localhost> Message-ID: <20120823171732.GA21460@1984> On Thu, Aug 23, 2012 at 09:03:21AM +0200, Holger Hans Peter Freyther wrote: > On Wed, Aug 22, 2012 at 05:04:43PM +0200, pablo at gnumonks.org wrote: > > From: Pablo Neira Ayuso > > Hi, > > > > > Now the BTS and BSC tests work again. > > could you look into integrating your test with the GNU autotest testsuite > we use in libosmocore/libosmo-sccp/openbsc? This way we would catch this > issue at build time. I will. Would you be OK if I do that in some follow-up patchset? > > if (write_cb == NULL) > > ipa_link->write_cb = ipa_client_write_default_cb; > > + else > > + ipa_link->write_cb = write_cb; > > + > > this means that only the tests (and no real application) set a custom > write_cb? is there another way to test? It's ipaccess driver which is setting its own write_cb to integrate itself with the e1inp queue of messages that you get via e1inp_tx_ts. From holger at freyther.de Fri Aug 24 06:35:56 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Fri, 24 Aug 2012 08:35:56 +0200 Subject: [PATCH 01/11] ipa: fix missing set of write_cb for IPA client connection In-Reply-To: <20120823171732.GA21460@1984> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-2-git-send-email-pablo@gnumonks.org> <20120823070321.GK28195@localhost> <20120823171732.GA21460@1984> Message-ID: <20120824063556.GO4301@localhost> On Thu, Aug 23, 2012 at 07:17:32PM +0200, Pablo Neira Ayuso wrote: > > I will. Would you be OK if I do that in some follow-up patchset? Yes, no rush. > > It's ipaccess driver which is setting its own write_cb to integrate > itself with the e1inp queue of messages that you get via e1inp_tx_ts. The following is not urgent, so feel free to use the patch as is. With every test one attempts to simulate reality. In the above case the reality was okay, the simulation of it was broken. The question (and not for now) is if the test can be modified to be more close to reality. Or at least remove the write_cb parameter and set it from outside. holger From pablo at gnumonks.org Wed Aug 22 15:04:44 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:44 +0200 Subject: [PATCH 02/11] ipaccess: fix leak of e1inp_line In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-3-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Holger reported a leak in the ipaccess_drop path. It seems I forgot to call e1inp_line_put twice, one for the OML link and one for the RSL link. Note that, for some fully established A-bis IPA link, the refcnt of the e1inp_line becomes two. --- src/input/ipaccess.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 76d1994..44a5a59 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -250,7 +250,10 @@ static int ipaccess_drop(struct osmo_fd *bfd) ret = -ENOENT; } /* put the virtual E1 line that we cloned for this socket, if - * it becomes unused, it gets released. */ + * it becomes unused, it gets released. We have to make it + * twice: once for the OML link and once for the RSL link + */ + e1inp_line_put(line); e1inp_line_put(line); return ret; } -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 17:44:19 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Wed, 22 Aug 2012 19:44:19 +0200 Subject: [PATCH 02/11] ipaccess: fix leak of e1inp_line In-Reply-To: <1345647893-1286-3-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-3-git-send-email-pablo@gnumonks.org> Message-ID: <20120822174419.GB23253@1984> On Wed, Aug 22, 2012 at 05:04:44PM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso > > Holger reported a leak in the ipaccess_drop path. New version of this patch, this time based on Holger's plus handling the case in which no full OML / RSL has been established. From pablo at gnumonks.org Wed Aug 22 11:57:58 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Wed, 22 Aug 2012 13:57:58 +0200 Subject: [PATCH] ipaccess: fix leak of e1inp_line Message-ID: Holger reported a leak in the ipaccess_drop path and a patch to fix this. This is a new version of the patch posted that also handle the case in which only one of the link (OML / RSL) is established and no ID_RESP was received. Based on patch of Holger Freyther. --- src/e1_input.c | 1 + src/input/hsl.c | 4 +--- src/input/ipaccess.c | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/e1_input.c b/src/e1_input.c index 957b74c..a85dd91 100644 --- a/src/e1_input.c +++ b/src/e1_input.c @@ -486,6 +486,7 @@ void e1inp_sign_link_destroy(struct e1inp_sign_link *link) if (link->ts->line->driver->close) link->ts->line->driver->close(link); + e1inp_line_put(link->ts->line); talloc_free(link); } diff --git a/src/input/hsl.c b/src/input/hsl.c index 3dcba1d..b86d7f6 100644 --- a/src/input/hsl.c +++ b/src/input/hsl.c @@ -82,10 +82,8 @@ static void hsl_drop(struct e1inp_line *line, struct osmo_fd *bfd) osmo_fd_unregister(bfd); close(bfd->fd); bfd->fd = -1; + e1inp_line_put(line); } - /* put the virtual E1 line that we cloned for this socket, if - * it becomes unused, it gets released. */ - e1inp_line_put(line); } static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line, diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 76d1994..4c50640 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -248,10 +248,8 @@ static int ipaccess_drop(struct osmo_fd *bfd) close(bfd->fd); bfd->fd = -1; ret = -ENOENT; + e1inp_line_put(line); } - /* put the virtual E1 line that we cloned for this socket, if - * it becomes unused, it gets released. */ - e1inp_line_put(line); return ret; } -- 1.7.10.4 --OgqxwSJOaUobr8KG-- From holger at freyther.de Thu Aug 23 07:26:46 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:26:46 +0200 Subject: [PATCH 02/11] ipaccess: fix leak of e1inp_line In-Reply-To: <20120822174419.GB23253@1984> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-3-git-send-email-pablo@gnumonks.org> <20120822174419.GB23253@1984> Message-ID: <20120823072646.GP28195@localhost> On Wed, Aug 22, 2012 at 07:44:19PM +0200, Pablo Neira Ayuso wrote: > On Wed, Aug 22, 2012 at 05:04:44PM +0200, pablo at gnumonks.org wrote: > > From: Pablo Neira Ayuso > > > > Holger reported a leak in the ipaccess_drop path. > > New version of this patch, this time based on Holger's plus handling > the case in which no full OML / RSL has been established. You obviously know this code a lot more than I do. The manual test for it is. I will test it but probably not today. 1.) Use the drop bts ... command in OpenBSC... drop the RSL link, drop the OML link.. check if there is a leak or crash. 2.) Force the bts to reconnect (either by using tcpkill or such) or by... and check if there is a leak. From pablo at gnumonks.org Wed Aug 22 15:04:45 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:45 +0200 Subject: [PATCH 03/11] tests: e1inp_ipa_bsc_test: fix crash In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-4-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso The sequence to trigger the crash was: 1) establish a full A-bis IPA link (both OML and RSL correctly established and ID_RESP received from BTS). 2) nc 127.0.0.1 3002 # establish OML link only I forgot to set to NULL the oml and rsl links we're using. Otherwise, the test calls e1inp_sign_link_destroy(rsl) which does not exists. --- tests/e1inp_ipa_bsc_test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/e1inp_ipa_bsc_test.c b/tests/e1inp_ipa_bsc_test.c index 424c87b..a0e5653 100644 --- a/tests/e1inp_ipa_bsc_test.c +++ b/tests/e1inp_ipa_bsc_test.c @@ -62,10 +62,14 @@ sign_link_up(void *dev, struct e1inp_line *line, enum e1inp_sign_type type) static void sign_link_down(struct e1inp_line *line) { LOGP(DBSCTEST, LOGL_NOTICE, "signal link has been closed\n"); - if (oml_sign_link) + if (oml_sign_link) { e1inp_sign_link_destroy(oml_sign_link); - if (rsl_sign_link) + oml_sign_link = NULL; + } + if (rsl_sign_link) { e1inp_sign_link_destroy(rsl_sign_link); + rsl_sign_link = NULL; + } } static void fill_om_hdr(struct abis_om_hdr *oh, uint8_t len) -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 15:04:46 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:46 +0200 Subject: [PATCH 04/11] ipaccess: more robust error handle in receival path In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-5-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso If we hit any error in the receival path of the ipaccess input driver, then better spot an error containing the reason and close the socket to start over. --- src/input/ipaccess.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 44a5a59..31b8f04 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -387,9 +387,13 @@ static int handle_ts1_read(struct osmo_fd *bfd) int ret = 0, error; error = ipa_msg_recv(bfd->fd, &msg); - if (error < 0) + if (error < 0) { + if (ipaccess_drop(bfd) >= 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " + "closing socket. Reason: %s\n", strerror(errno)); + } return error; - else if (error == 0) { + } else if (error == 0) { if (ipaccess_drop(bfd) >= 0) { LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, " "dead socket\n"); -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 15:04:47 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:47 +0200 Subject: [PATCH 05/11] ipaccess: more robust error handling in the accept patch In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-6-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Better close the newly established TCP connection to force a re-establishment. --- src/input/ipaccess.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 31b8f04..c69ae24 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -601,15 +601,22 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); - close(bfd->fd); - e1inp_line_put(line); - return ret; + goto err; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ ret = ipaccess_send_id_req(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", + strerror(errno)); + goto err; + } - return ret; + return ret; +err: + close(bfd->fd); + e1inp_line_put(line); + return ret; } static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) @@ -645,14 +652,21 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); - close(bfd->fd); - e1inp_line_put(line); - return ret; + goto err; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ ret = ipaccess_send_id_req(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", + strerror(errno)); + goto err; + } return 0; +err: + close(bfd->fd); + e1inp_line_put(line); + return ret; } static struct msgb * -- 1.7.10.4 From holger at freyther.de Thu Aug 23 07:07:51 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:07:51 +0200 Subject: [PATCH 05/11] ipaccess: more robust error handling in the accept patch In-Reply-To: <1345647893-1286-6-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-6-git-send-email-pablo@gnumonks.org> Message-ID: <20120823070751.GL28195@localhost> On Wed, Aug 22, 2012 at 05:04:47PM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso > Better close the newly established TCP connection to force a > re-establishment. two things. a.) I think you can do the cleanup/codesharing in more paths. > ret = osmo_fd_register(bfd); > if (ret < 0) { > LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); > - close(bfd->fd); > - e1inp_line_put(line); > - return ret; > + goto err; > } > > /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ > ret = ipaccess_send_id_req(bfd->fd); > + if (ret < 0) { > + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", > + strerror(errno)); > + goto err; > + } the bfd remains registered! > + if (ret < 0) { > + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", > + strerror(errno)); > + goto err; > + } same bfd issue. From holger at freyther.de Thu Aug 23 07:28:54 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:28:54 +0200 Subject: [PATCH 05/11] ipaccess: more robust error handling in the accept patch In-Reply-To: <1345647893-1286-6-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-6-git-send-email-pablo@gnumonks.org> Message-ID: <20120823072854.GQ28195@localhost> On Wed, Aug 22, 2012 at 05:04:47PM +0200, pablo at gnumonks.org wrote: > +err: > + close(bfd->fd); > + e1inp_line_put(line); > + return ret; > } one more thing. The code in ipaccess_drop appears to set bfd->fd = -1. Do we need that? You certainly don't have to do this in the current patchset but it would be nice if we at least know if we should (re)initialize to -1 or not. holger From pablo at gnumonks.org Wed Aug 22 15:04:48 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:48 +0200 Subject: [PATCH 06/11] ipaccess: more robust error handling in the send path In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-7-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso In case of problems to transmit message, spot an error and close the socket to force a re-establishment. This also modifies ipa_client_read to close the socket in case that our callback reports an error. --- src/input/ipa.c | 10 ++++++-- src/input/ipaccess.c | 66 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/input/ipa.c b/src/input/ipa.c index 3c6a507..015d957 100644 --- a/src/input/ipa.c +++ b/src/input/ipa.c @@ -131,8 +131,14 @@ static void ipa_client_read(struct ipa_client_conn *link) ipa_client_retry(link); return; } - if (link->read_cb) - link->read_cb(link, msg); + if (link->read_cb) { + ret = link->read_cb(link, msg); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "connection closed with " + "server\n"); + ipa_client_retry(link); + } + } } static void ipa_client_write(struct ipa_client_conn *link) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index c69ae24..e59ab18 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -189,26 +189,33 @@ int ipaccess_send_id_req(int fd) /* base handling of the ip.access protocol */ int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd) { - int ipa_ccm = 0; uint8_t msg_type = *(msg->l2h); int ret = 0; switch (msg_type) { case IPAC_MSGT_PING: - ipa_ccm = 1; ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "cannot send PING " + "message. Reason: %s\n", strerror(errno)); + } else + ret = 1; break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); - ipa_ccm = 1; + ret = 1; break; case IPAC_MSGT_ID_ACK: DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); - ipa_ccm = 1; ret = ipaccess_send_id_ack(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + } else + ret = 1; break; } - return ipa_ccm; + return ret; } /* base handling of the ip.access protocol */ @@ -221,6 +228,10 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, switch (msg_type) { case IPAC_MSGT_PING: ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "cannot send PONG " + "message. Reason: %s\n", strerror(errno)); + } break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); @@ -229,7 +240,7 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, DEBUGP(DLMI, "ID_ACK\n"); break; } - return 0; + return ret; } static int ipaccess_drop(struct osmo_fd *bfd) @@ -269,8 +280,15 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, int len, ret; /* Handle IPA PING, PONG and ID_ACK messages. */ - if (ipaccess_rcvmsg_base(msg, bfd)) + ret = ipaccess_rcvmsg_base(msg, bfd); + switch(ret) { + case -1: + /* error in IPA control message handling */ + goto err; + case 1: + /* this is an IPA control message, skip further processing */ return 0; + } switch (msg_type) { case IPAC_MSGT_ID_RESP: @@ -517,6 +535,16 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); ret = send(bfd->fd, msg->data, msg->len, 0); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling " + "message. Reason: %s\n", strerror(errno)); + if (ipaccess_drop(bfd) >= 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " + "closing socket. Reason: %s\n", strerror(errno)); + return ret; + } + } + msgb_free(msg); /* set tx delay timer for next event */ @@ -759,13 +787,16 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; struct e1inp_ts *e1i_ts = NULL; struct e1inp_sign_link *sign_link; + int ret = 0; /* special handling for IPA CCM. */ if (hh->proto == IPAC_PROTO_IPACCESS) { uint8_t msg_type = *(msg->l2h); /* ping, pong and acknowledgment cases. */ - ipaccess_rcvmsg_bts_base(msg, link->ofd); + ret = ipaccess_rcvmsg_bts_base(msg, link->ofd); + if (ret < 0) + return ret; /* this is a request for identification from the BSC. */ if (msg_type == IPAC_MSGT_ID_GET) { @@ -798,15 +829,28 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) } rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev, data + 1, len - 1); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); msgb_free(rmsg); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP " + "message. Reason: %s\n", strerror(errno)); + return ret; + } + /* send ID_ACK. */ rmsg = ipa_bts_id_ack(); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); msgb_free(rmsg); + + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + } } - return 0; + return ret; } else if (link->port == IPA_TCP_PORT_OML) e1i_ts = &link->line->ts[0]; else if (link->port == IPA_TCP_PORT_RSL) -- 1.7.10.4 From holger at freyther.de Thu Aug 23 07:19:17 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:19:17 +0200 Subject: [PATCH 06/11] ipaccess: more robust error handling in the send path In-Reply-To: <1345647893-1286-7-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-7-git-send-email-pablo@gnumonks.org> Message-ID: <20120823071917.GM28195@localhost> On Wed, Aug 22, 2012 at 05:04:48PM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso > > In case of problems to transmit message, spot an error and > close the socket to force a re-establishment. > > This also modifies ipa_client_read to close the socket in > case that our callback reports an error. this somehow doesn't read right. Sorry to be picky here. :} > + LOGP(DLINP, LOGL_ERROR, "connection closed with " > + "server\n"); I try to have full sentences in the log message. This means it starts with a capital letter and ends with a full stop. > int ret = 0; int ret = 1 ; > > switch (msg_type) { > case IPAC_MSGT_PING: > - ipa_ccm = 1; > ret = ipaccess_send_pong(bfd->fd); > + if (ret < 0) { > + LOGP(DLINP, LOGL_ERROR, "cannot send PING " > + "message. Reason: %s\n", strerror(errno)); } > break; > case IPAC_MSGT_PONG: > DEBUGP(DLMI, "PONG!\n"); > break; > case IPAC_MSGT_ID_ACK: > DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); > - ipa_ccm = 1; > ret = ipaccess_send_id_ack(bfd->fd); > + if (ret < 0) { > + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " > + "message. Reason: %s\n", strerror(errno)); } > break; default: ret = 0; break; > } > - return ipa_ccm; > + return ret; > } does this read any better? > static int ipaccess_drop(struct osmo_fd *bfd) > @@ -269,8 +280,15 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, > int len, ret; > > /* Handle IPA PING, PONG and ID_ACK messages. */ > - if (ipaccess_rcvmsg_base(msg, bfd)) > + ret = ipaccess_rcvmsg_base(msg, bfd); > + switch(ret) { > + case -1: > + /* error in IPA control message handling */ > + goto err; > + case 1: > + /* this is an IPA control message, skip further processing */ > return 0; default: WARN_ON(ret); ? > + } > > switch (msg_type) { > case IPAC_MSGT_ID_RESP: > @@ -517,6 +535,16 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) > DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); > > ret = send(bfd->fd, msg->data, msg->len, 0); > + if (ret < 0) { if (ret != msg->len) From pablo at gnumonks.org Thu Aug 23 11:33:58 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 23 Aug 2012 13:33:58 +0200 Subject: [PATCH 06/11] ipaccess: more robust error handling in the send path In-Reply-To: <20120823071917.GM28195@localhost> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-7-git-send-email-pablo@gnumonks.org> <20120823071917.GM28195@localhost> Message-ID: <20120823113358.GA29678@1984> On Thu, Aug 23, 2012 at 09:19:17AM +0200, Holger Hans Peter Freyther wrote: > On Wed, Aug 22, 2012 at 05:04:48PM +0200, pablo at gnumonks.org wrote: > > From: Pablo Neira Ayuso > > > > In case of problems to transmit message, spot an error and > > close the socket to force a re-establishment. > > > > This also modifies ipa_client_read to close the socket in > > case that our callback reports an error. > > this somehow doesn't read right. Sorry to be picky here. :} No problem, I'll fix the description. > > > + LOGP(DLINP, LOGL_ERROR, "connection closed with " > > + "server\n"); > > I try to have full sentences in the log message. This means it starts > with a capital letter and ends with a full stop. > > > > int ret = 0; > int ret = 1 ; This will not help, ret is overwritten by ipaccess_send_*, I need to reload it anyway for the PING and ID_ACK cases after the send(). I have changed this to: int ret; And below, inlined the changes I've done for the new patch version: > > > > switch (msg_type) { > > case IPAC_MSGT_PING: > > - ipa_ccm = 1; > > ret = ipaccess_send_pong(bfd->fd); > > + if (ret < 0) { > > + LOGP(DLINP, LOGL_ERROR, "cannot send PING " > > + "message. Reason: %s\n", strerror(errno)); break; > } ret = 1; > > > > break; > > case IPAC_MSGT_PONG: > > DEBUGP(DLMI, "PONG!\n"); > > break; > > case IPAC_MSGT_ID_ACK: > > DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); > > - ipa_ccm = 1; > > ret = ipaccess_send_id_ack(bfd->fd); > > + if (ret < 0) { > > + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " > > + "message. Reason: %s\n", strerror(errno)); break; > } ret = 1; > > break; > default: > ret = 0; > break; > > } > > - return ipa_ccm; > > + return ret; > > } > > does this read any better? If you refer to remove ipa_ccm and to use ret instead, well, it's just that I have merged ret and ipa_ccm, and ipa_ccm = send(...) seems ugly to me. If you refer to the entire function, yes I think it reads better now. > > static int ipaccess_drop(struct osmo_fd *bfd) > > @@ -269,8 +280,15 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, > > int len, ret; > > > > /* Handle IPA PING, PONG and ID_ACK messages. */ > > - if (ipaccess_rcvmsg_base(msg, bfd)) > > + ret = ipaccess_rcvmsg_base(msg, bfd); > > + switch(ret) { > > + case -1: > > + /* error in IPA control message handling */ > > + goto err; > > + case 1: > > + /* this is an IPA control message, skip further processing */ > > return 0; > default: > WARN_ON(ret); > ? Added case 0 (this is not an IPA control message) and default case using LOGP to report an error. > > + } > > > > switch (msg_type) { > > case IPAC_MSGT_ID_RESP: > > @@ -517,6 +535,16 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) > > DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); > > > > ret = send(bfd->fd, msg->data, msg->len, 0); > > + if (ret < 0) { > if (ret != msg->len) I've changed all send callers to check for ret != msg->len. Note that if we ever support TCP segmentation (TCP_NODELAY unset), then we'll have to relax that checking (although I don't think we'll ever do, unless for the ipaccess BTS). Thanks for you review Holger. From pablo at gnumonks.org Thu Aug 23 11:59:01 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 23 Aug 2012 13:59:01 +0200 Subject: [PATCH 06/11] ipaccess: more robust error handling in the send path In-Reply-To: <20120823071917.GM28195@localhost> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-7-git-send-email-pablo@gnumonks.org> <20120823071917.GM28195@localhost> Message-ID: <20120823115901.GA556@1984> On Thu, Aug 23, 2012 at 09:19:17AM +0200, Holger Hans Peter Freyther wrote: > On Wed, Aug 22, 2012 at 05:04:48PM +0200, pablo at gnumonks.org wrote: > > From: Pablo Neira Ayuso > > > > In case of problems to transmit message, spot an error and > > close the socket to force a re-establishment. > > > > This also modifies ipa_client_read to close the socket in > > case that our callback reports an error. > > this somehow doesn't read right. Sorry to be picky here. :} New version of this patch attached. From pablo at gnumonks.org Wed Aug 22 12:41:28 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Wed, 22 Aug 2012 14:41:28 +0200 Subject: [PATCH] ipaccess: more robust error handling in the send path Message-ID: In case of problems to transmit message, spot an error and close the socket to force a re-establishment. I have also modified ipa_client_read function. Now it closes the socket if the callback returns an error. I think this is good to force a connection re-establishment and start from scratch. Thanks to Holger Freyther for feedback. --- src/input/ipa.c | 10 ++++-- src/input/ipaccess.c | 82 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/input/ipa.c b/src/input/ipa.c index 3c6a507..ceb271f 100644 --- a/src/input/ipa.c +++ b/src/input/ipa.c @@ -131,8 +131,14 @@ static void ipa_client_read(struct ipa_client_conn *link) ipa_client_retry(link); return; } - if (link->read_cb) - link->read_cb(link, msg); + if (link->read_cb) { + ret = link->read_cb(link, msg); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Connection closed with " + "server.\n"); + ipa_client_retry(link); + } + } } static void ipa_client_write(struct ipa_client_conn *link) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index ea21de7..079ed61 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -189,26 +189,39 @@ int ipaccess_send_id_req(int fd) /* base handling of the ip.access protocol */ int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd) { - int ipa_ccm = 0; uint8_t msg_type = *(msg->l2h); - int ret = 0; + int ret; switch (msg_type) { case IPAC_MSGT_PING: - ipa_ccm = 1; ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send PING " + "message. Reason: %s\n", strerror(errno)); + break; + } + ret = 1; break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); - ipa_ccm = 1; + ret = 1; break; case IPAC_MSGT_ID_ACK: DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); - ipa_ccm = 1; ret = ipaccess_send_id_ack(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + break; + } + ret = 1; + break; + default: + /* This is not an IPA PING, PONG or ID_ACK message */ + ret = 0; break; } - return ipa_ccm; + return ret; } /* base handling of the ip.access protocol */ @@ -221,6 +234,10 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, switch (msg_type) { case IPAC_MSGT_PING: ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send PONG " + "message. Reason: %s\n", strerror(errno)); + } break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); @@ -229,7 +246,7 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, DEBUGP(DLMI, "ID_ACK\n"); break; } - return 0; + return ret; } static int ipaccess_drop(struct osmo_fd *bfd) @@ -264,8 +281,23 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, int len, ret; /* Handle IPA PING, PONG and ID_ACK messages. */ - if (ipaccess_rcvmsg_base(msg, bfd)) + ret = ipaccess_rcvmsg_base(msg, bfd); + switch(ret) { + case -1: + /* error in IPA control message handling */ + goto err; + case 1: + /* this is an IPA control message, skip further processing */ return 0; + case 0: + /* this is not an IPA control message, continue */ + break; + default: + LOGP(DLINP, LOGL_ERROR, "Unexpected return from " + "ipaccess_rcvmsg_base " + "(ret=%d)\n", ret); + goto err; + } switch (msg_type) { case IPAC_MSGT_ID_RESP: @@ -512,6 +544,16 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); ret = send(bfd->fd, msg->data, msg->len, 0); + if (ret != msg->len) { + LOGP(DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling " + "message. Reason: %s\n", strerror(errno)); + if (ipaccess_drop(bfd) >= 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " + "closing socket. Reason: %s\n", strerror(errno)); + return ret; + } + } + msgb_free(msg); /* set tx delay timer for next event */ @@ -754,13 +796,16 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; struct e1inp_ts *e1i_ts = NULL; struct e1inp_sign_link *sign_link; + int ret = 0; /* special handling for IPA CCM. */ if (hh->proto == IPAC_PROTO_IPACCESS) { uint8_t msg_type = *(msg->l2h); /* ping, pong and acknowledgment cases. */ - ipaccess_rcvmsg_bts_base(msg, link->ofd); + ret = ipaccess_rcvmsg_bts_base(msg, link->ofd); + if (ret < 0) + return ret; /* this is a request for identification from the BSC. */ if (msg_type == IPAC_MSGT_ID_GET) { @@ -793,15 +838,28 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) } rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev, data + 1, len - 1); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); msgb_free(rmsg); + if (ret != rmsg->len) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP " + "message. Reason: %s\n", strerror(errno)); + return ret; + } + /* send ID_ACK. */ rmsg = ipa_bts_id_ack(); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); msgb_free(rmsg); + + if (ret != rmsg->len) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + } } - return 0; + return ret; } else if (link->port == IPA_TCP_PORT_OML) e1i_ts = &link->line->ts[0]; else if (link->port == IPA_TCP_PORT_RSL) -- 1.7.10.4 --9jxsPFA5p3P2qPhR-- From pablo at gnumonks.org Wed Aug 22 15:04:49 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:49 +0200 Subject: [PATCH 07/11] tests: e1inp_ipa_bts_test: fix compilation warnings In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-8-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso CC e1inp_ipa_bts_test.o e1inp_ipa_bts_test.c: In function ?sign_link_up?: e1inp_ipa_bts_test.c:47:8: warning: variable ?dst? set but not used [-Wunused-but-set-variable] e1inp_ipa_bts_test.c: In function ?test_bts_gsm_12_21_cb?: e1inp_ipa_bts_test.c:211:6: warning: variable ?ret? set but not used [-Wunused-but-set-variable] CCLD e1inp_ipa_bts_test --- tests/e1inp_ipa_bts_test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c index 3549661..bf46e9e 100644 --- a/tests/e1inp_ipa_bts_test.c +++ b/tests/e1inp_ipa_bts_test.c @@ -44,7 +44,6 @@ static struct e1inp_sign_link * sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type) { struct e1inp_sign_link *sign_link = NULL; - void *dst = NULL; switch(type) { case E1INP_SIGN_OML: @@ -58,7 +57,6 @@ sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type) LOGP(DBTSTEST, LOGL_ERROR, "cannot create OML sign link\n"); } - dst = oml_sign_link; if (oml_sign_link) { unsigned int event_type = 0; @@ -84,7 +82,6 @@ sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type) LOGP(DBTSTEST, LOGL_ERROR, "cannot create RSL sign link\n"); } - dst = rsl_sign_link; break; default: return NULL; @@ -221,6 +218,10 @@ static int test_bts_gsm_12_21_cb(struct osmo_fd *ofd, unsigned int what) unit->bts_id, unit->trx_id, 0, NULL, 0); + if (ret < 0) { + LOGP(DBTSTEST, LOGL_ERROR, "cannot send SW ACT REQ\n"); + break; + } bts_state = BTS_TEST_OML_WAIT_SW_ACT_ACK; break; case BTS_TEST_OML_WAIT_SW_ACT_ACK: -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 15:04:50 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:50 +0200 Subject: [PATCH 08/11] lapd: use C99 structure initialization for profile templates In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-9-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso --- src/input/lapd.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/input/lapd.c b/src/input/lapd.c index a7a86ce..5a475c4 100644 --- a/src/input/lapd.c +++ b/src/input/lapd.c @@ -71,39 +71,39 @@ #define LAPD_SET_K(n, o) {n,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o} const struct lapd_profile lapd_profile_isdn = { - LAPD_SET_K(7,7), - 3, - 260, - 3, - 1,0, - 1,0, - 2,0, - 10,0, - 0 + .k = LAPD_SET_K(7,7), + .n200 = 3, + .n201 = 260, + .n202 = 3, + .t200_sec = 1, .t200_usec = 0, + .t201_sec = 1, .t201_usec = 0, + .t202_sec = 2, .t202_usec = 0, + .t203_sec = 10, .t203_usec = 0, + .short_address = 0 }; const struct lapd_profile lapd_profile_abis = { - LAPD_SET_K(2,1), - 3, - 260, - 0, /* infinite */ - 0,240000, - 1,0, - 2,0, - 10,0, - 0 + .k = LAPD_SET_K(2,1), + .n200 = 3, + .n201 = 260, + .n202 = 0, /* infinite */ + .t200_sec = 0, .t200_usec = 240000, + .t201_sec = 1, .t201_usec = 0, + .t202_sec = 2, .t202_usec = 0, + .t203_sec = 10, .t203_usec = 0, + .short_address = 0 }; const struct lapd_profile lapd_profile_sat = { - LAPD_SET_K(15,15), - 5, - 260, - 5, - 2,400000, - 2,400000, - 2,400000, - 20,0, - 1 + .k = LAPD_SET_K(15,15), + .n200 = 5, + .n201 = 260, + .n202 = 5, + .t200_sec = 2, .t200_usec = 400000, + .t201_sec = 2, .t201_usec = 400000, + .t202_sec = 2, .t202_usec = 400000, + .t203_sec = 20, .t203_sec = 0, + .short_address = 1 }; typedef enum { -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 15:04:51 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:51 +0200 Subject: [PATCH 09/11] input: dahdi: use logging facilities instead of fprintf and stderr In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-10-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso --- src/input/dahdi.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/input/dahdi.c b/src/input/dahdi.c index 0cefa6c..ff5cb80 100644 --- a/src/input/dahdi.c +++ b/src/input/dahdi.c @@ -196,7 +196,7 @@ static int ts_want_write(struct e1inp_ts *e1i_ts) * writeset, since it doesn't support poll() based * write flow control */ if (e1i_ts->type == E1INP_TS_TYPE_TRAU) { - fprintf(stderr, "Trying to write TRAU ts\n"); + LOGP(DLINP, LOGL_DEBUG, "Trying to write TRAU ts\n"); return 0; } @@ -302,7 +302,7 @@ static int handle_tsX_write(struct osmo_fd *bfd) ret = subchan_mux_out(mx, tx_buf, D_BCHAN_TX_GRAN); if (ret != D_BCHAN_TX_GRAN) { - fprintf(stderr, "Huh, got ret of %d\n", ret); + LOGP(DLINP, LOGL_DEBUG, "Huh, got ret of %d\n", ret); if (ret < 0) return ret; } @@ -316,8 +316,8 @@ static int handle_tsX_write(struct osmo_fd *bfd) ret = write(bfd->fd, tx_buf, ret); if (ret < D_BCHAN_TX_GRAN) - fprintf(stderr, "send returns %d instead of %d\n", ret, - D_BCHAN_TX_GRAN); + LOGP(DLINP, LOGL_DEBUG, "send returns %d instead of %d\n", + ret, D_BCHAN_TX_GRAN); return ret; } @@ -337,7 +337,8 @@ static int handle_tsX_read(struct osmo_fd *bfd) ret = read(bfd->fd, msg->data, D_TSX_ALLOC_SIZE); if (ret < 0 || ret != D_TSX_ALLOC_SIZE) { - fprintf(stderr, "read error %d %s\n", ret, strerror(errno)); + LOGP(DLINP, LOGL_DEBUG, "read error %d %s\n", + ret, strerror(errno)); return ret; } @@ -388,7 +389,8 @@ static int dahdi_fd_cb(struct osmo_fd *bfd, unsigned int what) * write flow control */ break; default: - fprintf(stderr, "unknown E1 TS type %u\n", e1i_ts->type); + LOGP(DLINP, LOGL_NOTICE, + "unknown E1 TS type %u\n", e1i_ts->type); break; } @@ -429,7 +431,7 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) int x = 0; if (ioctl(fd, DAHDI_GET_BUFINFO, &bi)) { - fprintf(stderr, "Error getting bufinfo\n"); + LOGP(DLINP, LOGL_ERROR, "Error getting bufinfo\n"); exit(-1); } @@ -443,13 +445,13 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) } if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) { - fprintf(stderr, "Error setting bufinfo\n"); + LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); exit(-1); } if (!as_sigchan) { if (ioctl(fd, DAHDI_AUDIOMODE, &x)) { - fprintf(stderr, "Error setting bufinfo\n"); + LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); exit(-1); } } else { @@ -517,7 +519,8 @@ static int dahdi_e1_setup(struct e1inp_line *line) if (!bfd->fd) bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); if (bfd->fd == -1) { - fprintf(stderr, "%s could not open %s %s\n", + LOGP(DLINP, LOGL_ERROR, + "%s could not open %s %s\n", __func__, openstr, strerror(errno)); exit(-1); } @@ -537,7 +540,8 @@ static int dahdi_e1_setup(struct e1inp_line *line) if (!bfd->fd) bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); if (bfd->fd == -1) { - fprintf(stderr, "%s could not open %s %s\n", + LOGP(DLINP, LOGL_ERROR, + "%s could not open %s %s\n", __func__, openstr, strerror(errno)); exit(-1); } @@ -550,14 +554,16 @@ static int dahdi_e1_setup(struct e1inp_line *line) } if (bfd->fd < 0) { - fprintf(stderr, "%s could not open %s %s\n", + LOGP(DLINP, LOGL_ERROR, + "%s could not open %s %s\n", __func__, openstr, strerror(errno)); return bfd->fd; } ret = osmo_fd_register(bfd); if (ret < 0) { - fprintf(stderr, "could not register FD: %s\n", + LOGP(DLINP, LOGL_ERROR, + "could not register FD: %s\n", strerror(ret)); return ret; } -- 1.7.10.4 From pablo at gnumonks.org Wed Aug 22 15:04:52 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:52 +0200 Subject: [PATCH 10/11] input: dahdi: replace exit by return In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-11-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso This is a library, we leave up to the client code to decide when to finish the code execution. --- src/input/dahdi.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/input/dahdi.c b/src/input/dahdi.c index ff5cb80..8d3e060 100644 --- a/src/input/dahdi.c +++ b/src/input/dahdi.c @@ -425,14 +425,14 @@ struct e1inp_driver dahdi_driver = { .vty_show = &dahdi_vty_show, }; -void dahdi_set_bufinfo(int fd, int as_sigchan) +int dahdi_set_bufinfo(int fd, int as_sigchan) { struct dahdi_bufferinfo bi; int x = 0; if (ioctl(fd, DAHDI_GET_BUFINFO, &bi)) { LOGP(DLINP, LOGL_ERROR, "Error getting bufinfo\n"); - exit(-1); + return -EIO; } if (as_sigchan) { @@ -446,13 +446,13 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) { LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); - exit(-1); + return -EIO; } if (!as_sigchan) { if (ioctl(fd, DAHDI_AUDIOMODE, &x)) { LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); - exit(-1); + return -EIO; } } else { int one = 1; @@ -461,6 +461,7 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) * as this command will fail if the slot _already_ was a * signalling slot before :( */ } + return 0; } static int dahdi_e1_setup(struct e1inp_line *line) @@ -522,10 +523,13 @@ static int dahdi_e1_setup(struct e1inp_line *line) LOGP(DLINP, LOGL_ERROR, "%s could not open %s %s\n", __func__, openstr, strerror(errno)); - exit(-1); + return -EIO; } bfd->when = BSC_FD_READ | BSC_FD_EXCEPT; - dahdi_set_bufinfo(bfd->fd, 1); + ret = dahdi_set_bufinfo(bfd->fd, 1); + if (ret < 0) + return ret; + if (!e1i_ts->lapd) e1i_ts->lapd = lapd_instance_alloc(1, dahdi_write_msg, bfd, e1inp_dlsap_up, @@ -543,9 +547,11 @@ static int dahdi_e1_setup(struct e1inp_line *line) LOGP(DLINP, LOGL_ERROR, "%s could not open %s %s\n", __func__, openstr, strerror(errno)); - exit(-1); + return -EIO; } - dahdi_set_bufinfo(bfd->fd, 0); + ret = dahdi_set_bufinfo(bfd->fd, 0); + if (ret < 0) + return -EIO; /* We never include the DAHDI B-Channel FD into the * writeset, since it doesn't support poll() based * write flow control */ -- 1.7.10.4 From holger at freyther.de Thu Aug 23 07:20:32 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:20:32 +0200 Subject: [PATCH 10/11] input: dahdi: replace exit by return In-Reply-To: <1345647893-1286-11-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-11-git-send-email-pablo@gnumonks.org> Message-ID: <20120823072032.GN28195@localhost> On Wed, Aug 22, 2012 at 05:04:52PM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso > > This is a library, we leave up to the client code to decide when to > finish the code execution. from a non-native speaker... "we leave it up".. From pablo at gnumonks.org Wed Aug 22 15:04:53 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Wed, 22 Aug 2012 17:04:53 +0200 Subject: [PATCH 11/11] input: add generic PCAP interface for LAPD In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345647893-1286-12-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso This patch allows you to create PCAP traces between the BSC and BTS including the LAPD frames. Useful for debugging communication issues. So far, it was only possible to create layer 3 traces containing OML/RSL. LAPD traces can be also interesting to debug communication issues between the BSC and the BTS. To enable PCAP of LAPD, you only have to invoke: li->pcap_fd = osmo_pcap_lapd_open("/tmp/file.pcap", 0600); By default, li->pcap_fd is set to -1 which means disabled. openBSC needs a patch to replace all usage of e1_set_pcap_fd by osmo_pcap_lapd_open. --- include/Makefile.am | 2 +- include/osmocom/abis/lapd.h | 1 + include/osmocom/abis/lapd_pcap.h | 11 +++ src/Makefile.am | 1 + src/input/lapd.c | 12 +++ src/input/lapd_pcap.c | 160 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 include/osmocom/abis/lapd_pcap.h create mode 100644 src/input/lapd_pcap.c diff --git a/include/Makefile.am b/include/Makefile.am index 61e6cf5..16fa506 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,4 +3,4 @@ noinst_HEADERS=mISDNif.h internal.h nobase_include_HEADERS = osmocom/abis/ipa.h osmocom/abis/trau_frame.h \ osmocom/abis/ipa_proxy.h osmocom/abis/ipaccess.h osmocom/abis/abis.h \ osmocom/abis/subchan_demux.h osmocom/abis/e1_input.h \ - osmocom/abis/lapd.h osmocom/trau/osmo_ortp.h + osmocom/abis/lapd.h osmocom/abis/lapd_pcap.h osmocom/trau/osmo_ortp.h diff --git a/include/osmocom/abis/lapd.h b/include/osmocom/abis/lapd.h index 847a597..2457cde 100644 --- a/include/osmocom/abis/lapd.h +++ b/include/osmocom/abis/lapd.h @@ -35,6 +35,7 @@ struct lapd_instance { struct lapd_profile profile; /* must be a copy */ struct llist_head tei_list; /* list of TEI in this LAPD instance */ + int pcap_fd; /* PCAP file descriptor */ }; enum lapd_recv_errors { diff --git a/include/osmocom/abis/lapd_pcap.h b/include/osmocom/abis/lapd_pcap.h new file mode 100644 index 0000000..1c0d555 --- /dev/null +++ b/include/osmocom/abis/lapd_pcap.h @@ -0,0 +1,11 @@ +#ifndef _LAPD_PCAP_H_ +#define _LAPD_PCAP_H_ + +#define OSMO_LAPD_PCAP_INPUT 0 +#define OSMO_LAPD_PCAP_OUTPUT 1 + +int osmo_pcap_lapd_open(char *filename, mode_t mode); +int osmo_pcap_lapd_write(int fd, int direction, struct msgb *msg); +int osmo_pcap_lapd_close(int fd); + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index cf58aaa..01f0913 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,6 +23,7 @@ libosmoabis_la_SOURCES = init.c \ input/ipa.c \ input/ipaccess.c \ input/lapd.c \ + input/lapd_pcap.c \ input/misdn.c \ input/rs232.c diff --git a/src/input/lapd.c b/src/input/lapd.c index 5a475c4..bced94a 100644 --- a/src/input/lapd.c +++ b/src/input/lapd.c @@ -36,6 +36,7 @@ #include #include #include +#include #define LAPD_ADDR2(sapi, cr) ((((sapi) & 0x3f) << 2) | (((cr) & 0x1) << 1)) #define LAPD_ADDR3(tei) ((((tei) & 0x7f) << 1) | 0x1) @@ -311,6 +312,10 @@ static int lapd_tei_receive(struct lapd_instance *li, uint8_t *data, int len) msg = msgb_alloc_headroom(56, 56, "DL EST"); msg->l2h = msgb_push(msg, 8); memcpy(msg->l2h, resp, 8); + + /* write to PCAP file, if enabled. */ + osmo_pcap_lapd_write(li->pcap_fd, OSMO_LAPD_PCAP_OUTPUT, msg); + LOGP(DLLAPD, LOGL_DEBUG, "TX: %s\n", osmo_hexdump(msg->data, msg->len)); li->transmit_cb(msg, li->transmit_cbdata); @@ -336,6 +341,9 @@ int lapd_receive(struct lapd_instance *li, struct msgb *msg, int *error) struct lapd_sap *sap; struct lapd_tei *teip; + /* write to PCAP file, if enabled. */ + osmo_pcap_lapd_write(li->pcap_fd, OSMO_LAPD_PCAP_INPUT, msg); + LOGP(DLLAPD, LOGL_DEBUG, "RX: %s\n", osmo_hexdump(msg->data, msg->len)); if (msg->len < 2) { LOGP(DLLAPD, LOGL_ERROR, "LAPD frame receive len %d < 2, " @@ -585,6 +593,9 @@ static int send_ph_data_req(struct lapd_msg_ctx *lctx, struct msgb *msg) else msg->l2h[1] = LAPD_ADDR3(lctx->tei); + /* write to PCAP file, if enabled. */ + osmo_pcap_lapd_write(li->pcap_fd, OSMO_LAPD_PCAP_OUTPUT, msg); + /* forward frame to L1 */ LOGP(DLLAPD, LOGL_DEBUG, "TX: %s\n", osmo_hexdump(msg->data, msg->len)); li->transmit_cb(msg, li->transmit_cbdata); @@ -645,6 +656,7 @@ struct lapd_instance *lapd_instance_alloc(int network_side, li->transmit_cbdata = tx_cbdata; li->receive_cb = rx_cb; li->receive_cbdata = rx_cbdata; + li->pcap_fd = -1; memcpy(&li->profile, profile, sizeof(li->profile)); INIT_LLIST_HEAD(&li->tei_list); diff --git a/src/input/lapd_pcap.c b/src/input/lapd_pcap.c new file mode 100644 index 0000000..4430687 --- /dev/null +++ b/src/input/lapd_pcap.c @@ -0,0 +1,160 @@ +/* (C) 2008-2012 by Harald Welte + * + * All Rights Reserved + * + * Author: Harald Welte + * Pablo Neira Ayuso + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/* + * pcap writing of the mlapd load + * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat + */ +#define DLT_LINUX_LAPD 177 + +struct pcap_hdr { + uint32_t magic_number; + uint16_t version_major; + uint16_t version_minor; + int32_t thiszone; + uint32_t sigfigs; + uint32_t snaplen; + uint32_t network; +} __attribute__((packed)); + +struct pcap_rechdr { + uint32_t ts_sec; + uint32_t ts_usec; + uint32_t incl_len; + uint32_t orig_len; +} __attribute__((packed)); + +struct pcap_lapdhdr { + uint16_t pkttype; + uint16_t hatype; + uint16_t halen; + uint64_t addr; + int16_t protocol; +} __attribute__((packed)); + +osmo_static_assert(offsetof(struct pcap_lapdhdr, hatype) == 2, hatype_offset); +osmo_static_assert(offsetof(struct pcap_lapdhdr, halen) == 4, halen_offset); +osmo_static_assert(offsetof(struct pcap_lapdhdr, addr) == 6, addr_offset); +osmo_static_assert(offsetof(struct pcap_lapdhdr, protocol) == 14, proto_offset); +osmo_static_assert(sizeof(struct pcap_lapdhdr) == 16, lapd_header_size); + +int osmo_pcap_lapd_open(char *filename, mode_t mode) +{ + int fd; + struct pcap_hdr pcap_header = { + .magic_number = 0xa1b2c3d4, + .version_major = 2, + .version_minor = 4, + .thiszone = 0, + .sigfigs = 0, + .snaplen = 65535, + .network = DLT_LINUX_LAPD, + }; + + LOGP(DLLAPD, LOGL_NOTICE, "opening LAPD pcap file `%s'\n", filename); + + fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, mode); + if (fd < 0) { + LOGP(DLLAPD, LOGL_ERROR, "failed to open PCAP file: %s\n", + strerror(errno)); + return -1; + } + if (write(fd, &pcap_header, sizeof(pcap_header)) < 0) { + LOGP(DLLAPD, LOGL_ERROR, "cannot write PCAP header: %s\n", + strerror(errno)); + close(fd); + return -1; + } + return fd; +} + +/* This currently only works for the D-Channel */ +int osmo_pcap_lapd_write(int fd, int direction, struct msgb *msg) +{ + int ret; + int numbytes = 0; + struct timeval tv; + struct pcap_rechdr pcap_rechdr; + struct pcap_lapdhdr header; + char buf[sizeof(struct pcap_rechdr) + + sizeof(struct pcap_lapdhdr) + msg->len]; + + /* PCAP file has not been opened, skip. */ + if (fd < 0) + return 0; + + pcap_rechdr.ts_sec = 0; + pcap_rechdr.ts_usec = 0; + pcap_rechdr.incl_len = msg->len + sizeof(struct pcap_lapdhdr); + pcap_rechdr.orig_len = msg->len + sizeof(struct pcap_lapdhdr); + + header.pkttype = 4; + header.hatype = 0; + header.halen = 0; + header.addr = direction == OSMO_LAPD_PCAP_OUTPUT ? 0x0 : 0x1; + header.protocol = ntohs(48); + + gettimeofday(&tv, NULL); + pcap_rechdr.ts_sec = tv.tv_sec; + pcap_rechdr.ts_usec = tv.tv_usec; + + memcpy(buf + numbytes, &pcap_rechdr, sizeof(pcap_rechdr)); + numbytes += sizeof(pcap_rechdr); + + memcpy(buf + numbytes, &header, sizeof(header)); + numbytes += sizeof(header); + + memcpy(buf + numbytes, msg->data, msg->len); + numbytes += msg->len; + + ret = write(fd, buf, numbytes); + if (ret < 0) { + LOGP(DLLAPD, LOGL_ERROR, "cannot write packet to PCAP: %s\n", + strerror(errno)); + return -1; + } + return numbytes; +} + +int osmo_pcap_lapd_close(int fd) +{ + LOGP(DLLAPD, LOGL_NOTICE, "closing LAPD pcap file\n"); + return close(fd); +} -- 1.7.10.4 From holger at freyther.de Thu Aug 23 07:24:53 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Thu, 23 Aug 2012 09:24:53 +0200 Subject: [PATCH 11/11] input: add generic PCAP interface for LAPD In-Reply-To: <1345647893-1286-12-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <1345647893-1286-12-git-send-email-pablo@gnumonks.org> Message-ID: <20120823072453.GO28195@localhost> On Wed, Aug 22, 2012 at 05:04:53PM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso > > This patch allows you to create PCAP traces between the BSC and BTS including > the LAPD frames. Useful for debugging communication issues. nice! > + if (write(fd, &pcap_header, sizeof(pcap_header)) < 0) { != sizeof(pcap_header)? > + > + ret = write(fd, buf, numbytes); > + if (ret < 0) { ret != numbytes? From laforge at gnumonks.org Thu Aug 23 09:08:18 2012 From: laforge at gnumonks.org (Harald Welte) Date: Thu, 23 Aug 2012 11:08:18 +0200 Subject: [PATCH 00/11] libosmo-abis updates In-Reply-To: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> Message-ID: <20120823090818.GH6135@prithivi.gnumonks.org> Hi Pablo, On Wed, Aug 22, 2012 at 05:04:42PM +0200, pablo at gnumonks.org wrote: > The following patchset contain updates for libosmo-abis: Thanks a lot for your updates and fixes. I quickly looked through them and I don't have anything to add to Holgers review, except that I don't like a full stop at the end of log lines, like he does ;) -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From pablo at gnumonks.org Thu Aug 23 12:00:59 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 23 Aug 2012 14:00:59 +0200 Subject: [PATCH 00/11] libosmo-abis updates In-Reply-To: <20120823090818.GH6135@prithivi.gnumonks.org> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <20120823090818.GH6135@prithivi.gnumonks.org> Message-ID: <20120823120059.GB556@1984> On Thu, Aug 23, 2012 at 11:08:18AM +0200, Harald Welte wrote: > Hi Pablo, > > On Wed, Aug 22, 2012 at 05:04:42PM +0200, pablo at gnumonks.org wrote: > > The following patchset contain updates for libosmo-abis: > > Thanks a lot for your updates and fixes. I quickly looked through them > and I don't have anything to add to Holgers review, except that I don't > like a full stop at the end of log lines, like he does ;) Hm I don't like it either. So this is a 2 vs. 1 game :-P. Well since we have no consensus on the full stop, and there is many other logs that would need to be fixed to add the full stop, I decided not to add it. Please, let me know if you find any other issue. Otherwise I'll push this after a couple of this with no comments. Thanks to both of you! From pablo at gnumonks.org Thu Aug 23 18:08:05 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 23 Aug 2012 20:08:05 +0200 Subject: [PATCH 00/11] libosmo-abis updates In-Reply-To: <20120823120059.GB556@1984> References: <1345647893-1286-1-git-send-email-pablo@gnumonks.org> <20120823090818.GH6135@prithivi.gnumonks.org> <20120823120059.GB556@1984> Message-ID: <20120823180805.GB21460@1984> On Thu, Aug 23, 2012 at 02:00:59PM +0200, Pablo Neira Ayuso wrote: [...] > Please, let me know if you find any other issue. Otherwise I'll push > this after a couple of this with no comments. JFYI: I'll resend a new patchset to the mailing list to address Holger's comments so you can give it another review. From pfc.rivas at gmail.com Wed Aug 22 17:14:22 2012 From: pfc.rivas at gmail.com (Arturo Rivas) Date: Wed, 22 Aug 2012 19:14:22 +0200 Subject: OpenBTS error Message-ID: Hi list! When I run ggsn, terminal shows: *fg: 1* *debug: 1* *qos: 0x0b921f* *apn: internet* *net: 192.168.0.0/24* *dynip: 192.168.254.0/24* *pidfile: /var/run/ggsn.pid* *statedir: /var/lib/ggsn/* *timelimit: 0* *gtpclient: Initialising GTP tunnel* *openggsn[7002]: GTP: gtp_newgsn() started* *openggsn[7002]: gtp.c: 719: State information file (/var/lib/ggsn/gsn_restart) not found. Creating new file.* *openggsn[7002]: gtp.c: 740: fopen(path=/var/lib/ggsn/gsn_restart, mode=w) failed: Error = No such file or directory* *openggsn[7002]: gtp.c: 808: bind(fd0=4, addr=bf86f8dc, len=16) failed: Error = Address already in use* *openggsn[7002]: ggsn.c: 498: Failed to create gtp* * * If I run it again addr parameter change but log also indicates that address is already in use. Someone can help me? Thanks! Arturo Rivas. -------------- next part -------------- An HTML attachment was scrubbed... URL: From laforge at gnumonks.org Thu Aug 23 09:03:47 2012 From: laforge at gnumonks.org (Harald Welte) Date: Thu, 23 Aug 2012 11:03:47 +0200 Subject: OpenGGSN (was Re: OpenBTS error) In-Reply-To: References: Message-ID: <20120823090347.GG6135@prithivi.gnumonks.org> Hi Arturo, please make sure your subject is correct. Your message is not about OpenBTS, but about OpenGGSN. Secondly, OpenGGSN has its own mailing list, which is the better place to ask your question: On Wed, Aug 22, 2012 at 07:14:22PM +0200, Arturo Rivas wrote: > *openggsn[7002]: gtp.c: 719: State information file (/var/lib/ggsn/gsn_restart) not found. Creating new file.* > *openggsn[7002]: gtp.c: 740: fopen(path=/var/lib/ggsn/gsn_restart, mode=w) failed: Error = No such file or directory* This is also very clear: It tries to create the file /var/lib/ggsn/gsn_restart, but apparently the directory /var/lib/ggsn does not exist! > *openggsn[7002]: gtp.c: 808: bind(fd0=4, addr=bf86f8dc, len=16) failed: Error = Address already in use* > *openggsn[7002]: ggsn.c: 498: Failed to create gtp* Even more clear: the GTP protocol has already bound to, i.e. you have some other process running that has already claimed the GTP protocol on your specified IP address. GTP is a layer4 protocol, not layer5 like http/ftp. You cannot have multiple prgrams using GTP on the same IP address. Only one GTP socket can be opened for each address. In case of doubt, run GGSN and SGSN on separate machines. -- - Harald Welte http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6) From mailman-bounces at lists.osmocom.org Thu Aug 23 18:11:27 2012 From: mailman-bounces at lists.osmocom.org (mailman-bounces at lists.osmocom.org) Date: Thu, 23 Aug 2012 20:11:27 +0200 Subject: Uncaught bounce notification Message-ID: The attached message was received as a bounce, but either the bounce format was not recognized, or no member addresses could be extracted from it. This mailing list has been configured to send all unrecognized bounce messages to the list administrator(s). For more information see: https://lists.osmocom.org/mailman/admin/openbsc/bounce -------------- next part -------------- An embedded message was scrubbed... From: MAILER-DAEMON at yahoo.com Subject: Failure Notice Date: Thu, 23 Aug 2012 18:11:22 -0000 Size: 6915 URL: From pablo at gnumonks.org Thu Aug 23 22:44:49 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:49 +0200 Subject: [PATCH 00/13] libosmo-abis updates (v2) Message-ID: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Hi, This is the second version of the libosmo-abis patchset. Mostly aiming to improve robustness and fix leaks in error paths. I have tried to address all Holger comments, I leave two things for my TODO list: 1) automate testing via automated testing while compilation 2) check the bfd->fd = -1 to make sure we need it in all cases I have also intensively tested (although it was quite manual) this changes with the IPA BSC/BTS tests, running valgrind to check for leaks. If you find any issue or you think it's OK, please ACK/NACK. Thanks. Pablo Neira Ayuso (13): ipa: fix missing set of write_cb for IPA client connection ipaccess: fix leak of e1inp_line tests: e1inp_ipa_bsc_test: fix crash ipaccess: improve error handling tests: e1inp_ipa_bts_test: fix compilation warnings lapd: use C99 structure initialization for profile templates input: dahdi: use logging facilities instead of fprintf and stderr input: dahdi: replace exit by return input: add generic PCAP interface for LAPD tests: fix CPU suckup e1inp_ipa_bts_test after test finish tests: e1inp_ipa_*_test: add signal handling for process termination tests: e1inp_ipa_*_test: fix leak of msgb in ->sign_link path ipaccess: fix leak of IPA control messages in the BTS side include/Makefile.am | 2 +- include/osmocom/abis/lapd.h | 1 + include/osmocom/abis/lapd_pcap.h | 11 ++ src/Makefile.am | 1 + src/e1_input.c | 1 + src/input/dahdi.c | 54 ++++++---- src/input/hsl.c | 3 - src/input/ipa.c | 3 + src/input/ipaccess.c | 210 ++++++++++++++++++++++++++------------ src/input/lapd.c | 66 +++++++----- src/input/lapd_pcap.c | 159 +++++++++++++++++++++++++++++ tests/e1inp_ipa_bsc_test.c | 26 ++++- tests/e1inp_ipa_bts_test.c | 31 +++++- 13 files changed, 443 insertions(+), 125 deletions(-) create mode 100644 include/osmocom/abis/lapd_pcap.h create mode 100644 src/input/lapd_pcap.c -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:50 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:50 +0200 Subject: [PATCH 01/13] ipa: fix missing set of write_cb for IPA client connection In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-2-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Now the BTS and BSC tests work again. --- src/input/ipa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/input/ipa.c b/src/input/ipa.c index a887959..3c6a507 100644 --- a/src/input/ipa.c +++ b/src/input/ipa.c @@ -249,6 +249,9 @@ ipa_client_conn_create(void *ctx, struct e1inp_ts *ts, /* default to generic write callback if not set. */ if (write_cb == NULL) ipa_link->write_cb = ipa_client_write_default_cb; + else + ipa_link->write_cb = write_cb; + if (ts) ipa_link->line = ts->line; ipa_link->data = data; -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:51 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:51 +0200 Subject: [PATCH 02/13] ipaccess: fix leak of e1inp_line In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-3-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Holger reported a leak in the ipaccess_drop path and a patch to fix this. This is a new version of the patch posted that also handle the case in which only one of the link (OML / RSL) is established and no ID_RESP was received. Based on patch of Holger Freyther. --- src/e1_input.c | 1 + src/input/hsl.c | 3 --- src/input/ipaccess.c | 10 ++++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/e1_input.c b/src/e1_input.c index 957b74c..a85dd91 100644 --- a/src/e1_input.c +++ b/src/e1_input.c @@ -486,6 +486,7 @@ void e1inp_sign_link_destroy(struct e1inp_sign_link *link) if (link->ts->line->driver->close) link->ts->line->driver->close(link); + e1inp_line_put(link->ts->line); talloc_free(link); } diff --git a/src/input/hsl.c b/src/input/hsl.c index 3dcba1d..1a60c2b 100644 --- a/src/input/hsl.c +++ b/src/input/hsl.c @@ -83,9 +83,6 @@ static void hsl_drop(struct e1inp_line *line, struct osmo_fd *bfd) close(bfd->fd); bfd->fd = -1; } - /* put the virtual E1 line that we cloned for this socket, if - * it becomes unused, it gets released. */ - e1inp_line_put(line); } static int process_hsl_rsl(struct msgb *msg, struct e1inp_line *line, diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 76d1994..a3c3b70 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -237,9 +237,6 @@ static int ipaccess_drop(struct osmo_fd *bfd) int ret = 0; struct e1inp_line *line = bfd->data; - /* e1inp_sign_link_destroy releases the socket descriptors for us. */ - line->ops->sign_link_down(line); - /* Error case: we did not see any ID_RESP yet for this socket. */ if (bfd->fd != -1) { LOGP(DLINP, LOGL_ERROR, "Forcing socket shutdown with " @@ -249,9 +246,10 @@ static int ipaccess_drop(struct osmo_fd *bfd) bfd->fd = -1; ret = -ENOENT; } - /* put the virtual E1 line that we cloned for this socket, if - * it becomes unused, it gets released. */ - e1inp_line_put(line); + + /* e1inp_sign_link_destroy releases the socket descriptors for us. */ + line->ops->sign_link_down(line); + return ret; } -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:52 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:52 +0200 Subject: [PATCH 03/13] tests: e1inp_ipa_bsc_test: fix crash In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-4-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso The sequence to trigger the crash was: 1) establish a full A-bis IPA link (both OML and RSL correctly established and ID_RESP received from BTS). 2) nc 127.0.0.1 3002 # establish OML link only I forgot to set to NULL the oml and rsl links we're using. Otherwise, the test calls e1inp_sign_link_destroy(rsl) which does not exists. --- tests/e1inp_ipa_bsc_test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/e1inp_ipa_bsc_test.c b/tests/e1inp_ipa_bsc_test.c index 424c87b..a0e5653 100644 --- a/tests/e1inp_ipa_bsc_test.c +++ b/tests/e1inp_ipa_bsc_test.c @@ -62,10 +62,14 @@ sign_link_up(void *dev, struct e1inp_line *line, enum e1inp_sign_type type) static void sign_link_down(struct e1inp_line *line) { LOGP(DBSCTEST, LOGL_NOTICE, "signal link has been closed\n"); - if (oml_sign_link) + if (oml_sign_link) { e1inp_sign_link_destroy(oml_sign_link); - if (rsl_sign_link) + oml_sign_link = NULL; + } + if (rsl_sign_link) { e1inp_sign_link_destroy(rsl_sign_link); + rsl_sign_link = NULL; + } } static void fill_om_hdr(struct abis_om_hdr *oh, uint8_t len) -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:53 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:53 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-5-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso If we hit any error, spot an error message containing the reason and close the links to start over. This patch has been tested by injecting errors in: * ipaccess_send, by randomly returning -1. * returning error from the ->sign_link_up callback, both from the OML and RSL links. * returning error from the ->sign_link callback, both for the OML and RSL links. With this patch, Valgrind shows no "definitely lost" memory blocks anymore (including the error path that has been tested) and the ipaccess driver behaves more robustly in case of errors. --- src/input/ipaccess.c | 199 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 141 insertions(+), 58 deletions(-) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index a3c3b70..6475007 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -189,26 +189,39 @@ int ipaccess_send_id_req(int fd) /* base handling of the ip.access protocol */ int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd) { - int ipa_ccm = 0; uint8_t msg_type = *(msg->l2h); - int ret = 0; + int ret; switch (msg_type) { case IPAC_MSGT_PING: - ipa_ccm = 1; ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send PING " + "message. Reason: %s\n", strerror(errno)); + break; + } + ret = 1; break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); - ipa_ccm = 1; + ret = 1; break; case IPAC_MSGT_ID_ACK: DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); - ipa_ccm = 1; ret = ipaccess_send_id_ack(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + break; + } + ret = 1; + break; + default: + /* This is not an IPA PING, PONG or ID_ACK message */ + ret = 0; break; } - return ipa_ccm; + return ret; } /* base handling of the ip.access protocol */ @@ -221,6 +234,10 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, switch (msg_type) { case IPAC_MSGT_PING: ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send PONG " + "message. Reason: %s\n", strerror(errno)); + } break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); @@ -229,12 +246,12 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, DEBUGP(DLMI, "ID_ACK\n"); break; } - return 0; + return ret; } static int ipaccess_drop(struct osmo_fd *bfd) { - int ret = 0; + int ret = 1; struct e1inp_line *line = bfd->data; /* Error case: we did not see any ID_RESP yet for this socket. */ @@ -264,8 +281,23 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, int len, ret; /* Handle IPA PING, PONG and ID_ACK messages. */ - if (ipaccess_rcvmsg_base(msg, bfd)) + ret = ipaccess_rcvmsg_base(msg, bfd); + switch(ret) { + case -1: + /* error in IPA control message handling */ + goto err; + case 1: + /* this is an IPA control message, skip further processing */ return 0; + case 0: + /* this is not an IPA control message, continue */ + break; + default: + LOGP(DLINP, LOGL_ERROR, "Unexpected return from " + "ipaccess_rcvmsg_base " + "(ret=%d)\n", ret); + goto err; + } switch (msg_type) { case IPAC_MSGT_ID_RESP: @@ -379,17 +411,16 @@ static int handle_ts1_read(struct osmo_fd *bfd) struct e1inp_sign_link *link; struct ipaccess_head *hh; struct msgb *msg; - int ret = 0, error; - - error = ipa_msg_recv(bfd->fd, &msg); - if (error < 0) - return error; - else if (error == 0) { - if (ipaccess_drop(bfd) >= 0) { - LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, " - "dead socket\n"); - } - return error; + int ret; + + ret = ipa_msg_recv(bfd->fd, &msg); + if (ret < 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " + "closing socket. Reason: %s\n", strerror(errno)); + goto err; + } else if (ret == 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, dead socket\n"); + goto err; } DEBUGP(DLMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); @@ -397,7 +428,7 @@ static int handle_ts1_read(struct osmo_fd *bfd) if (hh->proto == IPAC_PROTO_IPACCESS) { ipaccess_rcvmsg(line, msg, bfd); msgb_free(msg); - return ret; + return 0; } /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() * might have free'd it !!! */ @@ -406,8 +437,8 @@ static int handle_ts1_read(struct osmo_fd *bfd) if (!link) { LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " "hh->proto=0x%02x\n", hh->proto); - msgb_free(msg); - return -EIO; + ret = -EINVAL; + goto err_msg; } msg->dst = link; @@ -416,20 +447,21 @@ static int handle_ts1_read(struct osmo_fd *bfd) LOGP(DLINP, LOGL_ERROR, "Fix your application, " "no action set for signalling messages.\n"); ret = -EINVAL; - goto err; + goto err_msg; } if (e1i_ts->line->ops->sign_link(msg) < 0) { LOGP(DLINP, LOGL_ERROR, "Bad signalling message," "sign_link returned error: %s\n", osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); ret = -EINVAL; + goto err; } - return ret; + + return 0; +err_msg: + msgb_free(msg); err: - osmo_fd_unregister(bfd); - close(bfd->fd); - bfd->fd = -1; - e1inp_line_put(line); + ipaccess_drop(bfd); return ret; } @@ -497,9 +529,9 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) case E1INP_SIGN_RSL: break; default: - msgb_free(msg); bfd->when |= BSC_FD_WRITE; /* come back for more msg */ - return -EINVAL; + ret = -EINVAL; + goto out; } msg->l2h = msg->data; @@ -508,7 +540,11 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); ret = send(bfd->fd, msg->data, msg->len, 0); - msgb_free(msg); + if (ret != msg->len) { + LOGP(DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling " + "message. Reason: %s\n", strerror(errno)); + goto err; + } /* set tx delay timer for next event */ e1i_ts->sign.tx_timer.cb = timeout_ts1_write; @@ -517,6 +553,12 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) /* Reducing this might break the nanoBTS 900 init. */ osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); +out: + msgb_free(msg); + return ret; +err: + ipaccess_drop(bfd); + msgb_free(msg); return ret; } @@ -571,7 +613,7 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) line = e1inp_line_clone(tall_ipa_ctx, link->line); if (line == NULL) { LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); - return -1; + return -ENOMEM; } /* create virrtual E1 timeslots for signalling */ @@ -592,15 +634,25 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); - close(bfd->fd); - e1inp_line_put(line); - return ret; + goto err_line; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ ret = ipaccess_send_id_req(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", + strerror(errno)); + goto err_socket; + } + return ret; - return ret; +err_socket: + osmo_fd_unregister(bfd); + close(bfd->fd); + bfd->fd = -1; +err_line: + e1inp_line_put(line); + return ret; } static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) @@ -615,7 +667,7 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) line = e1inp_line_clone(tall_ipa_ctx, link->line); if (line == NULL) { LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); - return -1; + return -ENOMEM; } /* initialize the fds */ for (i = 0; i < ARRAY_SIZE(line->ts); ++i) @@ -636,14 +688,24 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); - close(bfd->fd); - e1inp_line_put(line); - return ret; + goto err_line; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ ret = ipaccess_send_id_req(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", + strerror(errno)); + goto err_socket; + } + return ret; - return 0; +err_socket: + osmo_fd_unregister(bfd); + close(bfd->fd); + bfd->fd = -1; +err_line: + e1inp_line_put(line); + return ret; } static struct msgb * @@ -736,18 +798,21 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; struct e1inp_ts *e1i_ts = NULL; struct e1inp_sign_link *sign_link; + struct msgb *rmsg; + int ret = 0; /* special handling for IPA CCM. */ if (hh->proto == IPAC_PROTO_IPACCESS) { uint8_t msg_type = *(msg->l2h); /* ping, pong and acknowledgment cases. */ - ipaccess_rcvmsg_bts_base(msg, link->ofd); + ret = ipaccess_rcvmsg_bts_base(msg, link->ofd); + if (ret < 0) + goto err; /* this is a request for identification from the BSC. */ if (msg_type == IPAC_MSGT_ID_GET) { struct e1inp_sign_link *sign_link; - struct msgb *rmsg; uint8_t *data = msgb_l2(msg); int len = msgb_l2len(msg); @@ -756,10 +821,8 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) LOGP(DLINP, LOGL_ERROR, "Unable to set signal link, " "closing socket.\n"); - osmo_fd_unregister(link->ofd); - close(link->ofd->fd); - link->ofd->fd = -1; - return -EINVAL; + ret = -EINVAL; + goto err; } sign_link = link->line->ops->sign_link_up(msg, link->line, @@ -768,22 +831,32 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) LOGP(DLINP, LOGL_ERROR, "Unable to set signal link, " "closing socket.\n"); - osmo_fd_unregister(link->ofd); - close(link->ofd->fd); - link->ofd->fd = -1; - return -EINVAL; + ret = -EINVAL; + goto err; } rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev, data + 1, len - 1); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); + if (ret != rmsg->len) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP " + "message. Reason: %s\n", strerror(errno)); + goto err_rmsg; + } msgb_free(rmsg); /* send ID_ACK. */ rmsg = ipa_bts_id_ack(); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); + if (ret != rmsg->len) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + goto err_rmsg; + } msgb_free(rmsg); } - return 0; + return ret; } else if (link->port == IPA_TCP_PORT_OML) e1i_ts = &link->line->ts[0]; else if (link->port == IPA_TCP_PORT_RSL) @@ -794,8 +867,8 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) if (sign_link == NULL) { LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " "hh->proto=0x%02x\n", hh->proto); - msgb_free(msg); - return -EIO; + ret = -EIO; + goto err; } msg->dst = sign_link; @@ -803,10 +876,20 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) if (!link->line->ops->sign_link) { LOGP(DLINP, LOGL_ERROR, "Fix your application, " "no action set for signalling messages.\n"); - return -ENOENT; + ret = -ENOENT; + goto err; } link->line->ops->sign_link(msg); return 0; + +err_rmsg: + msgb_free(rmsg); +err: + osmo_fd_unregister(link->ofd); + close(link->ofd->fd); + link->ofd->fd = -1; + msgb_free(msg); + return ret; } struct ipaccess_line { -- 1.7.10.4 From holger at freyther.de Fri Aug 24 06:45:26 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Fri, 24 Aug 2012 08:45:26 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <1345761903-1947-5-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <1345761903-1947-5-git-send-email-pablo@gnumonks.org> Message-ID: <20120824064526.GP4301@localhost> On Fri, Aug 24, 2012 at 12:44:53AM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso > @@ -592,15 +634,25 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) > ret = osmo_fd_register(bfd); > if (ret < 0) { > LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); > - close(bfd->fd); > - e1inp_line_put(line); > - return ret; > + goto err_line; > - return ret; > +err_socket: > + osmo_fd_unregister(bfd); > + close(bfd->fd); > + bfd->fd = -1; > +err_line: > + e1inp_line_put(line); > + return ret; > } in this case the socket was closed and remains open now? It needs to jump under the osmo_fd_unregister line. > /* initialize the fds */ > for (i = 0; i < ARRAY_SIZE(line->ts); ++i) > @@ -636,14 +688,24 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) > ret = osmo_fd_register(bfd); > if (ret < 0) { > LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); > - close(bfd->fd); > - e1inp_line_put(line); > - return ret; > + goto err_line; same as above. From pablo at gnumonks.org Fri Aug 24 10:09:08 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Fri, 24 Aug 2012 12:09:08 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <20120824064526.GP4301@localhost> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <1345761903-1947-5-git-send-email-pablo@gnumonks.org> <20120824064526.GP4301@localhost> Message-ID: <20120824100908.GA22905@1984> On Fri, Aug 24, 2012 at 08:45:26AM +0200, Holger Hans Peter Freyther wrote: > On Fri, Aug 24, 2012 at 12:44:53AM +0200, pablo at gnumonks.org wrote: > > From: Pablo Neira Ayuso > > > @@ -592,15 +634,25 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) > > ret = osmo_fd_register(bfd); > > if (ret < 0) { > > LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); > > - close(bfd->fd); > > - e1inp_line_put(line); > > - return ret; > > + goto err_line; > > > > > - return ret; > > +err_socket: > > + osmo_fd_unregister(bfd); > > + close(bfd->fd); > > + bfd->fd = -1; > > +err_line: > > + e1inp_line_put(line); > > + return ret; > > } > > in this case the socket was closed and remains open now? It needs to jump under the > osmo_fd_unregister line. > > > > /* initialize the fds */ > > for (i = 0; i < ARRAY_SIZE(line->ts); ++i) > > @@ -636,14 +688,24 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) > > ret = osmo_fd_register(bfd); > > if (ret < 0) { > > LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); > > - close(bfd->fd); > > - e1inp_line_put(line); > > - return ret; > > + goto err_line; > > same as above. Yes, this has to be: err_socket: osmo_fd_unregister(bfd); err_line: close(bfd->fd); bfd->fd = -1; e1inp_line_put(line); return ret; Thanks Holger. New patch attached. From pablo at gnumonks.org Wed Aug 22 12:16:24 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Wed, 22 Aug 2012 14:16:24 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling Message-ID: If we hit any error, spot an error message containing the reason and close the links to start over. This patch has been tested by injecting errors in: * ipaccess_send, by randomly returning -1. * returning error from the ->sign_link_up callback, both from the OML and RSL links. * returning error from the ->sign_link callback, both for the OML and RSL links. With this patch, Valgrind shows no "definitely lost" memory blocks anymore (including the error path that has been tested) and the ipaccess driver behaves more robustly in case of errors. --- src/input/ipaccess.c | 199 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 141 insertions(+), 58 deletions(-) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index a3c3b70..4ab08db 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -189,26 +189,39 @@ int ipaccess_send_id_req(int fd) /* base handling of the ip.access protocol */ int ipaccess_rcvmsg_base(struct msgb *msg, struct osmo_fd *bfd) { - int ipa_ccm = 0; uint8_t msg_type = *(msg->l2h); - int ret = 0; + int ret; switch (msg_type) { case IPAC_MSGT_PING: - ipa_ccm = 1; ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send PING " + "message. Reason: %s\n", strerror(errno)); + break; + } + ret = 1; break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); - ipa_ccm = 1; + ret = 1; break; case IPAC_MSGT_ID_ACK: DEBUGP(DLMI, "ID_ACK? -> ACK!\n"); - ipa_ccm = 1; ret = ipaccess_send_id_ack(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + break; + } + ret = 1; + break; + default: + /* This is not an IPA PING, PONG or ID_ACK message */ + ret = 0; break; } - return ipa_ccm; + return ret; } /* base handling of the ip.access protocol */ @@ -221,6 +234,10 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, switch (msg_type) { case IPAC_MSGT_PING: ret = ipaccess_send_pong(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "Cannot send PONG " + "message. Reason: %s\n", strerror(errno)); + } break; case IPAC_MSGT_PONG: DEBUGP(DLMI, "PONG!\n"); @@ -229,12 +246,12 @@ int ipaccess_rcvmsg_bts_base(struct msgb *msg, DEBUGP(DLMI, "ID_ACK\n"); break; } - return 0; + return ret; } static int ipaccess_drop(struct osmo_fd *bfd) { - int ret = 0; + int ret = 1; struct e1inp_line *line = bfd->data; /* Error case: we did not see any ID_RESP yet for this socket. */ @@ -264,8 +281,23 @@ static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, int len, ret; /* Handle IPA PING, PONG and ID_ACK messages. */ - if (ipaccess_rcvmsg_base(msg, bfd)) + ret = ipaccess_rcvmsg_base(msg, bfd); + switch(ret) { + case -1: + /* error in IPA control message handling */ + goto err; + case 1: + /* this is an IPA control message, skip further processing */ return 0; + case 0: + /* this is not an IPA control message, continue */ + break; + default: + LOGP(DLINP, LOGL_ERROR, "Unexpected return from " + "ipaccess_rcvmsg_base " + "(ret=%d)\n", ret); + goto err; + } switch (msg_type) { case IPAC_MSGT_ID_RESP: @@ -379,17 +411,16 @@ static int handle_ts1_read(struct osmo_fd *bfd) struct e1inp_sign_link *link; struct ipaccess_head *hh; struct msgb *msg; - int ret = 0, error; - - error = ipa_msg_recv(bfd->fd, &msg); - if (error < 0) - return error; - else if (error == 0) { - if (ipaccess_drop(bfd) >= 0) { - LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, " - "dead socket\n"); - } - return error; + int ret; + + ret = ipa_msg_recv(bfd->fd, &msg); + if (ret < 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link problems, " + "closing socket. Reason: %s\n", strerror(errno)); + goto err; + } else if (ret == 0) { + LOGP(DLINP, LOGL_NOTICE, "Sign link vanished, dead socket\n"); + goto err; } DEBUGP(DLMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); @@ -397,7 +428,7 @@ static int handle_ts1_read(struct osmo_fd *bfd) if (hh->proto == IPAC_PROTO_IPACCESS) { ipaccess_rcvmsg(line, msg, bfd); msgb_free(msg); - return ret; + return 0; } /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() * might have free'd it !!! */ @@ -406,8 +437,8 @@ static int handle_ts1_read(struct osmo_fd *bfd) if (!link) { LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " "hh->proto=0x%02x\n", hh->proto); - msgb_free(msg); - return -EIO; + ret = -EINVAL; + goto err_msg; } msg->dst = link; @@ -416,20 +447,21 @@ static int handle_ts1_read(struct osmo_fd *bfd) LOGP(DLINP, LOGL_ERROR, "Fix your application, " "no action set for signalling messages.\n"); ret = -EINVAL; - goto err; + goto err_msg; } if (e1i_ts->line->ops->sign_link(msg) < 0) { LOGP(DLINP, LOGL_ERROR, "Bad signalling message," "sign_link returned error: %s\n", osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); ret = -EINVAL; + goto err; } - return ret; + + return 0; +err_msg: + msgb_free(msg); err: - osmo_fd_unregister(bfd); - close(bfd->fd); - bfd->fd = -1; - e1inp_line_put(line); + ipaccess_drop(bfd); return ret; } @@ -497,9 +529,9 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) case E1INP_SIGN_RSL: break; default: - msgb_free(msg); bfd->when |= BSC_FD_WRITE; /* come back for more msg */ - return -EINVAL; + ret = -EINVAL; + goto out; } msg->l2h = msg->data; @@ -508,7 +540,11 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) DEBUGP(DLMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); ret = send(bfd->fd, msg->data, msg->len, 0); - msgb_free(msg); + if (ret != msg->len) { + LOGP(DLINP, LOGL_ERROR, "failed to send A-bis IPA signalling " + "message. Reason: %s\n", strerror(errno)); + goto err; + } /* set tx delay timer for next event */ e1i_ts->sign.tx_timer.cb = timeout_ts1_write; @@ -517,6 +553,12 @@ static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) /* Reducing this might break the nanoBTS 900 init. */ osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); +out: + msgb_free(msg); + return ret; +err: + ipaccess_drop(bfd); + msgb_free(msg); return ret; } @@ -571,7 +613,7 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) line = e1inp_line_clone(tall_ipa_ctx, link->line); if (line == NULL) { LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); - return -1; + return -ENOMEM; } /* create virrtual E1 timeslots for signalling */ @@ -592,15 +634,25 @@ static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); - close(bfd->fd); - e1inp_line_put(line); - return ret; + goto err_line; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ ret = ipaccess_send_id_req(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", + strerror(errno)); + goto err_socket; + } + return ret; - return ret; +err_socket: + osmo_fd_unregister(bfd); +err_line: + close(bfd->fd); + bfd->fd = -1; + e1inp_line_put(line); + return ret; } static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) @@ -615,7 +667,7 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) line = e1inp_line_clone(tall_ipa_ctx, link->line); if (line == NULL) { LOGP(DLINP, LOGL_ERROR, "could not clone E1 line\n"); - return -1; + return -ENOMEM; } /* initialize the fds */ for (i = 0; i < ARRAY_SIZE(line->ts); ++i) @@ -636,14 +688,24 @@ static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) ret = osmo_fd_register(bfd); if (ret < 0) { LOGP(DLINP, LOGL_ERROR, "could not register FD\n"); - close(bfd->fd); - e1inp_line_put(line); - return ret; + goto err_line; } /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ ret = ipaccess_send_id_req(bfd->fd); + if (ret < 0) { + LOGP(DLINP, LOGL_ERROR, "could not send ID REQ. Reason: %s\n", + strerror(errno)); + goto err_socket; + } + return ret; - return 0; +err_socket: + osmo_fd_unregister(bfd); +err_line: + close(bfd->fd); + bfd->fd = -1; + e1inp_line_put(line); + return ret; } static struct msgb * @@ -736,18 +798,21 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; struct e1inp_ts *e1i_ts = NULL; struct e1inp_sign_link *sign_link; + struct msgb *rmsg; + int ret = 0; /* special handling for IPA CCM. */ if (hh->proto == IPAC_PROTO_IPACCESS) { uint8_t msg_type = *(msg->l2h); /* ping, pong and acknowledgment cases. */ - ipaccess_rcvmsg_bts_base(msg, link->ofd); + ret = ipaccess_rcvmsg_bts_base(msg, link->ofd); + if (ret < 0) + goto err; /* this is a request for identification from the BSC. */ if (msg_type == IPAC_MSGT_ID_GET) { struct e1inp_sign_link *sign_link; - struct msgb *rmsg; uint8_t *data = msgb_l2(msg); int len = msgb_l2len(msg); @@ -756,10 +821,8 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) LOGP(DLINP, LOGL_ERROR, "Unable to set signal link, " "closing socket.\n"); - osmo_fd_unregister(link->ofd); - close(link->ofd->fd); - link->ofd->fd = -1; - return -EINVAL; + ret = -EINVAL; + goto err; } sign_link = link->line->ops->sign_link_up(msg, link->line, @@ -768,22 +831,32 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) LOGP(DLINP, LOGL_ERROR, "Unable to set signal link, " "closing socket.\n"); - osmo_fd_unregister(link->ofd); - close(link->ofd->fd); - link->ofd->fd = -1; - return -EINVAL; + ret = -EINVAL; + goto err; } rmsg = ipa_bts_id_resp(link->line->ops->cfg.ipa.dev, data + 1, len - 1); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); + if (ret != rmsg->len) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_RESP " + "message. Reason: %s\n", strerror(errno)); + goto err_rmsg; + } msgb_free(rmsg); /* send ID_ACK. */ rmsg = ipa_bts_id_ack(); - ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); + ret = ipaccess_send(link->ofd->fd, rmsg->data, + rmsg->len); + if (ret != rmsg->len) { + LOGP(DLINP, LOGL_ERROR, "cannot send ID_ACK " + "message. Reason: %s\n", strerror(errno)); + goto err_rmsg; + } msgb_free(rmsg); } - return 0; + return ret; } else if (link->port == IPA_TCP_PORT_OML) e1i_ts = &link->line->ts[0]; else if (link->port == IPA_TCP_PORT_RSL) @@ -794,8 +867,8 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) if (sign_link == NULL) { LOGP(DLINP, LOGL_ERROR, "no matching signalling link for " "hh->proto=0x%02x\n", hh->proto); - msgb_free(msg); - return -EIO; + ret = -EIO; + goto err; } msg->dst = sign_link; @@ -803,10 +876,20 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) if (!link->line->ops->sign_link) { LOGP(DLINP, LOGL_ERROR, "Fix your application, " "no action set for signalling messages.\n"); - return -ENOENT; + ret = -ENOENT; + goto err; } link->line->ops->sign_link(msg); return 0; + +err_rmsg: + msgb_free(rmsg); +err: + osmo_fd_unregister(link->ofd); + close(link->ofd->fd); + link->ofd->fd = -1; + msgb_free(msg); + return ret; } struct ipaccess_line { -- 1.7.10.4 --J2SCkAp4GZ/dPZZf-- From holger at freyther.de Wed Aug 29 19:30:58 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Wed, 29 Aug 2012 21:30:58 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <20120824100908.GA22905@1984> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <1345761903-1947-5-git-send-email-pablo@gnumonks.org> <20120824064526.GP4301@localhost> <20120824100908.GA22905@1984> Message-ID: <20120829193058.GA11186@localhost> On Fri, Aug 24, 2012 at 12:09:08PM +0200, Pablo Neira Ayuso wrote: > @@ -416,20 +447,21 @@ static int handle_ts1_read(struct osmo_fd *bfd) > LOGP(DLINP, LOGL_ERROR, "Fix your application, " > "no action set for signalling messages.\n"); > ret = -EINVAL; > - goto err; > + goto err_msg; > } ah nice, potential memleak fix. :) > if (e1i_ts->line->ops->sign_link(msg) < 0) { > LOGP(DLINP, LOGL_ERROR, "Bad signalling message," > "sign_link returned error: %s\n", > osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); > ret = -EINVAL; > + goto err; bad. but not from your code. sign_link does delete the msgb.. dumping it will work most of the time but is a "read after free". Acked-by: Holger Freyther as far as I can see.. the error paths have no leaks From pablo at gnumonks.org Thu Aug 30 02:42:21 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 30 Aug 2012 04:42:21 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <20120829193058.GA11186@localhost> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <1345761903-1947-5-git-send-email-pablo@gnumonks.org> <20120824064526.GP4301@localhost> <20120824100908.GA22905@1984> <20120829193058.GA11186@localhost> Message-ID: <20120830024221.GA15826@1984> On Wed, Aug 29, 2012 at 09:30:58PM +0200, Holger Hans Peter Freyther wrote: > On Fri, Aug 24, 2012 at 12:09:08PM +0200, Pablo Neira Ayuso wrote: > > > @@ -416,20 +447,21 @@ static int handle_ts1_read(struct osmo_fd *bfd) > > LOGP(DLINP, LOGL_ERROR, "Fix your application, " > > "no action set for signalling messages.\n"); > > ret = -EINVAL; > > - goto err; > > + goto err_msg; > > } > > ah nice, potential memleak fix. :) > > > if (e1i_ts->line->ops->sign_link(msg) < 0) { > > LOGP(DLINP, LOGL_ERROR, "Bad signalling message," > > "sign_link returned error: %s\n", > > osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); > > ret = -EINVAL; > > + goto err; > > bad. but not from your code. sign_link does delete the msgb.. dumping it > will work most of the time but is a "read after free". Indeed. abis_[rsl|oml]_rcvmsg are usually called in the path of ->sign_link, and they are in charge of releasing the msgb. I'm going to remove that dump and send a patch to add it to openBSC's abis_[rsl|oml]_rcvmsg (before msgb is released). > Acked-by: Holger Freyther > > > as far as I can see.. the error paths have no leaks Thanks for your review Holger. Will fix the thing above and push the patchset. From pablo at gnumonks.org Thu Aug 30 19:53:22 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Thu, 30 Aug 2012 21:53:22 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <20120830024221.GA15826@1984> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <1345761903-1947-5-git-send-email-pablo@gnumonks.org> <20120824064526.GP4301@localhost> <20120824100908.GA22905@1984> <20120829193058.GA11186@localhost> <20120830024221.GA15826@1984> Message-ID: <20120830195322.GA19539@1984> On Thu, Aug 30, 2012 at 04:42:21AM +0200, Pablo Neira Ayuso wrote: [...] > > Acked-by: Holger Freyther > > > > > > as far as I can see.. the error paths have no leaks > > Thanks for your review Holger. Will fix the thing above and push the > patchset. JFYI: pushed to master now. From holger at freyther.de Fri Aug 31 14:07:38 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Fri, 31 Aug 2012 16:07:38 +0200 Subject: [PATCH 04/13] ipaccess: improve error handling In-Reply-To: <20120830195322.GA19539@1984> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <1345761903-1947-5-git-send-email-pablo@gnumonks.org> <20120824064526.GP4301@localhost> <20120824100908.GA22905@1984> <20120829193058.GA11186@localhost> <20120830024221.GA15826@1984> <20120830195322.GA19539@1984> Message-ID: <20120831140738.GH1299@localhost> On Thu, Aug 30, 2012 at 09:53:22PM +0200, Pablo Neira Ayuso wrote: > > JFYI: pushed to master now. > thanks! From pablo at gnumonks.org Thu Aug 23 22:44:54 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:54 +0200 Subject: [PATCH 05/13] tests: e1inp_ipa_bts_test: fix compilation warnings In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-6-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso CC e1inp_ipa_bts_test.o e1inp_ipa_bts_test.c: In function ?sign_link_up?: e1inp_ipa_bts_test.c:47:8: warning: variable ?dst? set but not used [-Wunused-but-set-variable] e1inp_ipa_bts_test.c: In function ?test_bts_gsm_12_21_cb?: e1inp_ipa_bts_test.c:211:6: warning: variable ?ret? set but not used [-Wunused-but-set-variable] CCLD e1inp_ipa_bts_test --- tests/e1inp_ipa_bts_test.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c index 3549661..bf46e9e 100644 --- a/tests/e1inp_ipa_bts_test.c +++ b/tests/e1inp_ipa_bts_test.c @@ -44,7 +44,6 @@ static struct e1inp_sign_link * sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type) { struct e1inp_sign_link *sign_link = NULL; - void *dst = NULL; switch(type) { case E1INP_SIGN_OML: @@ -58,7 +57,6 @@ sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type) LOGP(DBTSTEST, LOGL_ERROR, "cannot create OML sign link\n"); } - dst = oml_sign_link; if (oml_sign_link) { unsigned int event_type = 0; @@ -84,7 +82,6 @@ sign_link_up(void *unit, struct e1inp_line *line, enum e1inp_sign_type type) LOGP(DBTSTEST, LOGL_ERROR, "cannot create RSL sign link\n"); } - dst = rsl_sign_link; break; default: return NULL; @@ -221,6 +218,10 @@ static int test_bts_gsm_12_21_cb(struct osmo_fd *ofd, unsigned int what) unit->bts_id, unit->trx_id, 0, NULL, 0); + if (ret < 0) { + LOGP(DBTSTEST, LOGL_ERROR, "cannot send SW ACT REQ\n"); + break; + } bts_state = BTS_TEST_OML_WAIT_SW_ACT_ACK; break; case BTS_TEST_OML_WAIT_SW_ACT_ACK: -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:55 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:55 +0200 Subject: [PATCH 06/13] lapd: use C99 structure initialization for profile templates In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-7-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso --- src/input/lapd.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/input/lapd.c b/src/input/lapd.c index a7a86ce..5a475c4 100644 --- a/src/input/lapd.c +++ b/src/input/lapd.c @@ -71,39 +71,39 @@ #define LAPD_SET_K(n, o) {n,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o} const struct lapd_profile lapd_profile_isdn = { - LAPD_SET_K(7,7), - 3, - 260, - 3, - 1,0, - 1,0, - 2,0, - 10,0, - 0 + .k = LAPD_SET_K(7,7), + .n200 = 3, + .n201 = 260, + .n202 = 3, + .t200_sec = 1, .t200_usec = 0, + .t201_sec = 1, .t201_usec = 0, + .t202_sec = 2, .t202_usec = 0, + .t203_sec = 10, .t203_usec = 0, + .short_address = 0 }; const struct lapd_profile lapd_profile_abis = { - LAPD_SET_K(2,1), - 3, - 260, - 0, /* infinite */ - 0,240000, - 1,0, - 2,0, - 10,0, - 0 + .k = LAPD_SET_K(2,1), + .n200 = 3, + .n201 = 260, + .n202 = 0, /* infinite */ + .t200_sec = 0, .t200_usec = 240000, + .t201_sec = 1, .t201_usec = 0, + .t202_sec = 2, .t202_usec = 0, + .t203_sec = 10, .t203_usec = 0, + .short_address = 0 }; const struct lapd_profile lapd_profile_sat = { - LAPD_SET_K(15,15), - 5, - 260, - 5, - 2,400000, - 2,400000, - 2,400000, - 20,0, - 1 + .k = LAPD_SET_K(15,15), + .n200 = 5, + .n201 = 260, + .n202 = 5, + .t200_sec = 2, .t200_usec = 400000, + .t201_sec = 2, .t201_usec = 400000, + .t202_sec = 2, .t202_usec = 400000, + .t203_sec = 20, .t203_sec = 0, + .short_address = 1 }; typedef enum { -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:56 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:56 +0200 Subject: [PATCH 07/13] input: dahdi: use logging facilities instead of fprintf and stderr In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-8-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso --- src/input/dahdi.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/input/dahdi.c b/src/input/dahdi.c index 0cefa6c..ff5cb80 100644 --- a/src/input/dahdi.c +++ b/src/input/dahdi.c @@ -196,7 +196,7 @@ static int ts_want_write(struct e1inp_ts *e1i_ts) * writeset, since it doesn't support poll() based * write flow control */ if (e1i_ts->type == E1INP_TS_TYPE_TRAU) { - fprintf(stderr, "Trying to write TRAU ts\n"); + LOGP(DLINP, LOGL_DEBUG, "Trying to write TRAU ts\n"); return 0; } @@ -302,7 +302,7 @@ static int handle_tsX_write(struct osmo_fd *bfd) ret = subchan_mux_out(mx, tx_buf, D_BCHAN_TX_GRAN); if (ret != D_BCHAN_TX_GRAN) { - fprintf(stderr, "Huh, got ret of %d\n", ret); + LOGP(DLINP, LOGL_DEBUG, "Huh, got ret of %d\n", ret); if (ret < 0) return ret; } @@ -316,8 +316,8 @@ static int handle_tsX_write(struct osmo_fd *bfd) ret = write(bfd->fd, tx_buf, ret); if (ret < D_BCHAN_TX_GRAN) - fprintf(stderr, "send returns %d instead of %d\n", ret, - D_BCHAN_TX_GRAN); + LOGP(DLINP, LOGL_DEBUG, "send returns %d instead of %d\n", + ret, D_BCHAN_TX_GRAN); return ret; } @@ -337,7 +337,8 @@ static int handle_tsX_read(struct osmo_fd *bfd) ret = read(bfd->fd, msg->data, D_TSX_ALLOC_SIZE); if (ret < 0 || ret != D_TSX_ALLOC_SIZE) { - fprintf(stderr, "read error %d %s\n", ret, strerror(errno)); + LOGP(DLINP, LOGL_DEBUG, "read error %d %s\n", + ret, strerror(errno)); return ret; } @@ -388,7 +389,8 @@ static int dahdi_fd_cb(struct osmo_fd *bfd, unsigned int what) * write flow control */ break; default: - fprintf(stderr, "unknown E1 TS type %u\n", e1i_ts->type); + LOGP(DLINP, LOGL_NOTICE, + "unknown E1 TS type %u\n", e1i_ts->type); break; } @@ -429,7 +431,7 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) int x = 0; if (ioctl(fd, DAHDI_GET_BUFINFO, &bi)) { - fprintf(stderr, "Error getting bufinfo\n"); + LOGP(DLINP, LOGL_ERROR, "Error getting bufinfo\n"); exit(-1); } @@ -443,13 +445,13 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) } if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) { - fprintf(stderr, "Error setting bufinfo\n"); + LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); exit(-1); } if (!as_sigchan) { if (ioctl(fd, DAHDI_AUDIOMODE, &x)) { - fprintf(stderr, "Error setting bufinfo\n"); + LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); exit(-1); } } else { @@ -517,7 +519,8 @@ static int dahdi_e1_setup(struct e1inp_line *line) if (!bfd->fd) bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); if (bfd->fd == -1) { - fprintf(stderr, "%s could not open %s %s\n", + LOGP(DLINP, LOGL_ERROR, + "%s could not open %s %s\n", __func__, openstr, strerror(errno)); exit(-1); } @@ -537,7 +540,8 @@ static int dahdi_e1_setup(struct e1inp_line *line) if (!bfd->fd) bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); if (bfd->fd == -1) { - fprintf(stderr, "%s could not open %s %s\n", + LOGP(DLINP, LOGL_ERROR, + "%s could not open %s %s\n", __func__, openstr, strerror(errno)); exit(-1); } @@ -550,14 +554,16 @@ static int dahdi_e1_setup(struct e1inp_line *line) } if (bfd->fd < 0) { - fprintf(stderr, "%s could not open %s %s\n", + LOGP(DLINP, LOGL_ERROR, + "%s could not open %s %s\n", __func__, openstr, strerror(errno)); return bfd->fd; } ret = osmo_fd_register(bfd); if (ret < 0) { - fprintf(stderr, "could not register FD: %s\n", + LOGP(DLINP, LOGL_ERROR, + "could not register FD: %s\n", strerror(ret)); return ret; } -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:57 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:57 +0200 Subject: [PATCH 08/13] input: dahdi: replace exit by return In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-9-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso This is a library, we leave up to the client code to decide when to finish the code execution. --- src/input/dahdi.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/input/dahdi.c b/src/input/dahdi.c index ff5cb80..8d3e060 100644 --- a/src/input/dahdi.c +++ b/src/input/dahdi.c @@ -425,14 +425,14 @@ struct e1inp_driver dahdi_driver = { .vty_show = &dahdi_vty_show, }; -void dahdi_set_bufinfo(int fd, int as_sigchan) +int dahdi_set_bufinfo(int fd, int as_sigchan) { struct dahdi_bufferinfo bi; int x = 0; if (ioctl(fd, DAHDI_GET_BUFINFO, &bi)) { LOGP(DLINP, LOGL_ERROR, "Error getting bufinfo\n"); - exit(-1); + return -EIO; } if (as_sigchan) { @@ -446,13 +446,13 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) { LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); - exit(-1); + return -EIO; } if (!as_sigchan) { if (ioctl(fd, DAHDI_AUDIOMODE, &x)) { LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); - exit(-1); + return -EIO; } } else { int one = 1; @@ -461,6 +461,7 @@ void dahdi_set_bufinfo(int fd, int as_sigchan) * as this command will fail if the slot _already_ was a * signalling slot before :( */ } + return 0; } static int dahdi_e1_setup(struct e1inp_line *line) @@ -522,10 +523,13 @@ static int dahdi_e1_setup(struct e1inp_line *line) LOGP(DLINP, LOGL_ERROR, "%s could not open %s %s\n", __func__, openstr, strerror(errno)); - exit(-1); + return -EIO; } bfd->when = BSC_FD_READ | BSC_FD_EXCEPT; - dahdi_set_bufinfo(bfd->fd, 1); + ret = dahdi_set_bufinfo(bfd->fd, 1); + if (ret < 0) + return ret; + if (!e1i_ts->lapd) e1i_ts->lapd = lapd_instance_alloc(1, dahdi_write_msg, bfd, e1inp_dlsap_up, @@ -543,9 +547,11 @@ static int dahdi_e1_setup(struct e1inp_line *line) LOGP(DLINP, LOGL_ERROR, "%s could not open %s %s\n", __func__, openstr, strerror(errno)); - exit(-1); + return -EIO; } - dahdi_set_bufinfo(bfd->fd, 0); + ret = dahdi_set_bufinfo(bfd->fd, 0); + if (ret < 0) + return -EIO; /* We never include the DAHDI B-Channel FD into the * writeset, since it doesn't support poll() based * write flow control */ -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:58 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:58 +0200 Subject: [PATCH 09/13] input: add generic PCAP interface for LAPD In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-10-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso This patch allows you to create PCAP traces between the BSC and BTS including the LAPD frames. Useful for debugging communication issues. So far, it was only possible to create layer 3 traces containing OML/RSL. LAPD traces can be also interesting to debug communication issues between the BSC and the BTS. To enable PCAP of LAPD, you only have to invoke: li->pcap_fd = osmo_pcap_lapd_open("/tmp/file.pcap", 0600); By default, li->pcap_fd is set to -1 which means disabled. openBSC needs a patch to replace all usage of e1_set_pcap_fd by osmo_pcap_lapd_open. --- include/Makefile.am | 2 +- include/osmocom/abis/lapd.h | 1 + include/osmocom/abis/lapd_pcap.h | 11 +++ src/Makefile.am | 1 + src/input/lapd.c | 12 +++ src/input/lapd_pcap.c | 159 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 include/osmocom/abis/lapd_pcap.h create mode 100644 src/input/lapd_pcap.c diff --git a/include/Makefile.am b/include/Makefile.am index 61e6cf5..16fa506 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -3,4 +3,4 @@ noinst_HEADERS=mISDNif.h internal.h nobase_include_HEADERS = osmocom/abis/ipa.h osmocom/abis/trau_frame.h \ osmocom/abis/ipa_proxy.h osmocom/abis/ipaccess.h osmocom/abis/abis.h \ osmocom/abis/subchan_demux.h osmocom/abis/e1_input.h \ - osmocom/abis/lapd.h osmocom/trau/osmo_ortp.h + osmocom/abis/lapd.h osmocom/abis/lapd_pcap.h osmocom/trau/osmo_ortp.h diff --git a/include/osmocom/abis/lapd.h b/include/osmocom/abis/lapd.h index 847a597..2457cde 100644 --- a/include/osmocom/abis/lapd.h +++ b/include/osmocom/abis/lapd.h @@ -35,6 +35,7 @@ struct lapd_instance { struct lapd_profile profile; /* must be a copy */ struct llist_head tei_list; /* list of TEI in this LAPD instance */ + int pcap_fd; /* PCAP file descriptor */ }; enum lapd_recv_errors { diff --git a/include/osmocom/abis/lapd_pcap.h b/include/osmocom/abis/lapd_pcap.h new file mode 100644 index 0000000..1c0d555 --- /dev/null +++ b/include/osmocom/abis/lapd_pcap.h @@ -0,0 +1,11 @@ +#ifndef _LAPD_PCAP_H_ +#define _LAPD_PCAP_H_ + +#define OSMO_LAPD_PCAP_INPUT 0 +#define OSMO_LAPD_PCAP_OUTPUT 1 + +int osmo_pcap_lapd_open(char *filename, mode_t mode); +int osmo_pcap_lapd_write(int fd, int direction, struct msgb *msg); +int osmo_pcap_lapd_close(int fd); + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index cf58aaa..01f0913 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,6 +23,7 @@ libosmoabis_la_SOURCES = init.c \ input/ipa.c \ input/ipaccess.c \ input/lapd.c \ + input/lapd_pcap.c \ input/misdn.c \ input/rs232.c diff --git a/src/input/lapd.c b/src/input/lapd.c index 5a475c4..bced94a 100644 --- a/src/input/lapd.c +++ b/src/input/lapd.c @@ -36,6 +36,7 @@ #include #include #include +#include #define LAPD_ADDR2(sapi, cr) ((((sapi) & 0x3f) << 2) | (((cr) & 0x1) << 1)) #define LAPD_ADDR3(tei) ((((tei) & 0x7f) << 1) | 0x1) @@ -311,6 +312,10 @@ static int lapd_tei_receive(struct lapd_instance *li, uint8_t *data, int len) msg = msgb_alloc_headroom(56, 56, "DL EST"); msg->l2h = msgb_push(msg, 8); memcpy(msg->l2h, resp, 8); + + /* write to PCAP file, if enabled. */ + osmo_pcap_lapd_write(li->pcap_fd, OSMO_LAPD_PCAP_OUTPUT, msg); + LOGP(DLLAPD, LOGL_DEBUG, "TX: %s\n", osmo_hexdump(msg->data, msg->len)); li->transmit_cb(msg, li->transmit_cbdata); @@ -336,6 +341,9 @@ int lapd_receive(struct lapd_instance *li, struct msgb *msg, int *error) struct lapd_sap *sap; struct lapd_tei *teip; + /* write to PCAP file, if enabled. */ + osmo_pcap_lapd_write(li->pcap_fd, OSMO_LAPD_PCAP_INPUT, msg); + LOGP(DLLAPD, LOGL_DEBUG, "RX: %s\n", osmo_hexdump(msg->data, msg->len)); if (msg->len < 2) { LOGP(DLLAPD, LOGL_ERROR, "LAPD frame receive len %d < 2, " @@ -585,6 +593,9 @@ static int send_ph_data_req(struct lapd_msg_ctx *lctx, struct msgb *msg) else msg->l2h[1] = LAPD_ADDR3(lctx->tei); + /* write to PCAP file, if enabled. */ + osmo_pcap_lapd_write(li->pcap_fd, OSMO_LAPD_PCAP_OUTPUT, msg); + /* forward frame to L1 */ LOGP(DLLAPD, LOGL_DEBUG, "TX: %s\n", osmo_hexdump(msg->data, msg->len)); li->transmit_cb(msg, li->transmit_cbdata); @@ -645,6 +656,7 @@ struct lapd_instance *lapd_instance_alloc(int network_side, li->transmit_cbdata = tx_cbdata; li->receive_cb = rx_cb; li->receive_cbdata = rx_cbdata; + li->pcap_fd = -1; memcpy(&li->profile, profile, sizeof(li->profile)); INIT_LLIST_HEAD(&li->tei_list); diff --git a/src/input/lapd_pcap.c b/src/input/lapd_pcap.c new file mode 100644 index 0000000..c83bc60 --- /dev/null +++ b/src/input/lapd_pcap.c @@ -0,0 +1,159 @@ +/* (C) 2008-2012 by Harald Welte + * + * All Rights Reserved + * + * Author: Harald Welte + * Pablo Neira Ayuso + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/* + * pcap writing of the mlapd load + * pcap format is from http://wiki.wireshark.org/Development/LibpcapFileFormat + */ +#define DLT_LINUX_LAPD 177 + +struct pcap_hdr { + uint32_t magic_number; + uint16_t version_major; + uint16_t version_minor; + int32_t thiszone; + uint32_t sigfigs; + uint32_t snaplen; + uint32_t network; +} __attribute__((packed)); + +struct pcap_rechdr { + uint32_t ts_sec; + uint32_t ts_usec; + uint32_t incl_len; + uint32_t orig_len; +} __attribute__((packed)); + +struct pcap_lapdhdr { + uint16_t pkttype; + uint16_t hatype; + uint16_t halen; + uint64_t addr; + int16_t protocol; +} __attribute__((packed)); + +osmo_static_assert(offsetof(struct pcap_lapdhdr, hatype) == 2, hatype_offset); +osmo_static_assert(offsetof(struct pcap_lapdhdr, halen) == 4, halen_offset); +osmo_static_assert(offsetof(struct pcap_lapdhdr, addr) == 6, addr_offset); +osmo_static_assert(offsetof(struct pcap_lapdhdr, protocol) == 14, proto_offset); +osmo_static_assert(sizeof(struct pcap_lapdhdr) == 16, lapd_header_size); + +int osmo_pcap_lapd_open(char *filename, mode_t mode) +{ + int fd; + struct pcap_hdr pcap_header = { + .magic_number = 0xa1b2c3d4, + .version_major = 2, + .version_minor = 4, + .thiszone = 0, + .sigfigs = 0, + .snaplen = 65535, + .network = DLT_LINUX_LAPD, + }; + + LOGP(DLLAPD, LOGL_NOTICE, "opening LAPD pcap file `%s'\n", filename); + + fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, mode); + if (fd < 0) { + LOGP(DLLAPD, LOGL_ERROR, "failed to open PCAP file: %s\n", + strerror(errno)); + return -1; + } + if (write(fd, &pcap_header, sizeof(pcap_header)) + != sizeof(pcap_header)) { + LOGP(DLLAPD, LOGL_ERROR, "cannot write PCAP header: %s\n", + strerror(errno)); + close(fd); + return -1; + } + return fd; +} + +/* This currently only works for the D-Channel */ +int osmo_pcap_lapd_write(int fd, int direction, struct msgb *msg) +{ + int numbytes = 0; + struct timeval tv; + struct pcap_rechdr pcap_rechdr; + struct pcap_lapdhdr header; + char buf[sizeof(struct pcap_rechdr) + + sizeof(struct pcap_lapdhdr) + msg->len]; + + /* PCAP file has not been opened, skip. */ + if (fd < 0) + return 0; + + pcap_rechdr.ts_sec = 0; + pcap_rechdr.ts_usec = 0; + pcap_rechdr.incl_len = msg->len + sizeof(struct pcap_lapdhdr); + pcap_rechdr.orig_len = msg->len + sizeof(struct pcap_lapdhdr); + + header.pkttype = 4; + header.hatype = 0; + header.halen = 0; + header.addr = direction == OSMO_LAPD_PCAP_OUTPUT ? 0x0 : 0x1; + header.protocol = ntohs(48); + + gettimeofday(&tv, NULL); + pcap_rechdr.ts_sec = tv.tv_sec; + pcap_rechdr.ts_usec = tv.tv_usec; + + memcpy(buf + numbytes, &pcap_rechdr, sizeof(pcap_rechdr)); + numbytes += sizeof(pcap_rechdr); + + memcpy(buf + numbytes, &header, sizeof(header)); + numbytes += sizeof(header); + + memcpy(buf + numbytes, msg->data, msg->len); + numbytes += msg->len; + + if (write(fd, buf, numbytes) != numbytes) { + LOGP(DLLAPD, LOGL_ERROR, "cannot write packet to PCAP: %s\n", + strerror(errno)); + return -1; + } + return numbytes; +} + +int osmo_pcap_lapd_close(int fd) +{ + LOGP(DLLAPD, LOGL_NOTICE, "closing LAPD pcap file\n"); + return close(fd); +} -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:44:59 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:44:59 +0200 Subject: [PATCH 10/13] tests: fix CPU suckup e1inp_ipa_bts_test after test finish In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-11-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso We have to read from the eventfd, otherwise select keeps returning the file descriptor as ready to read. --- tests/e1inp_ipa_bts_test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c index bf46e9e..1b9a2db 100644 --- a/tests/e1inp_ipa_bts_test.c +++ b/tests/e1inp_ipa_bts_test.c @@ -205,9 +205,14 @@ static int abis_nm_sw_act_req(struct e1inp_sign_link *sign_link, static int test_bts_gsm_12_21_cb(struct osmo_fd *ofd, unsigned int what) { - int ret; + int ret, event_type; struct ipaccess_unit *unit = ofd->data; + if (read(eventfds[0], &event_type, sizeof(unsigned int)) < 0) { + LOGP(DBTSTEST, LOGL_ERROR, "error receiving event\n"); + return 0; + } + switch(bts_state) { case BTS_TEST_OML_SIGN_LINK_DOWN: /* Do nothing until OML link becomes ready. */ -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:45:00 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:45:00 +0200 Subject: [PATCH 11/13] tests: e1inp_ipa_*_test: add signal handling for process termination In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-12-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso This patch adds signal handling to release memory in the exit path of the tests. This is good to check what memory we are leaking in the exist path of the tests. --- tests/e1inp_ipa_bsc_test.c | 17 +++++++++++++++-- tests/e1inp_ipa_bts_test.c | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tests/e1inp_ipa_bsc_test.c b/tests/e1inp_ipa_bsc_test.c index a0e5653..b447893 100644 --- a/tests/e1inp_ipa_bsc_test.c +++ b/tests/e1inp_ipa_bsc_test.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -199,10 +200,16 @@ const struct log_info bsc_test_log_info = { .num_cat = ARRAY_SIZE(bsc_test_cat), }; -int main(void) +static struct e1inp_line *line; + +static void sighandler(int foo) { - struct e1inp_line *line; + e1inp_line_put(line); + exit(EXIT_SUCCESS); +} +int main(void) +{ tall_test = talloc_named_const(NULL, 1, "e1inp_test"); libosmo_abis_init(tall_test); @@ -220,6 +227,12 @@ int main(void) .sign_link = sign_link, }; + if (signal(SIGINT, sighandler) == SIG_ERR || + signal(SIGTERM, sighandler) == SIG_ERR) { + perror("Cannot set sighandler"); + exit(EXIT_FAILURE); + } + #define LINENR 0 line = e1inp_line_create(LINENR, "ipa"); diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c index 1b9a2db..f885c5c 100644 --- a/tests/e1inp_ipa_bts_test.c +++ b/tests/e1inp_ipa_bts_test.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -236,6 +237,14 @@ static int test_bts_gsm_12_21_cb(struct osmo_fd *ofd, unsigned int what) return 0; } +static struct e1inp_line *line; + +static void sighandler(int foo) +{ + e1inp_line_put(line); + exit(EXIT_SUCCESS); +} + int main(void) { struct ipaccess_unit bts_dev_info = { @@ -250,7 +259,6 @@ int main(void) .location2 = "testBTS", .serno = "", }; - struct e1inp_line *line; tall_test = talloc_named_const(NULL, 1, "e1inp_test"); libosmo_abis_init(tall_test); @@ -272,6 +280,12 @@ int main(void) #define LINENR 0 + if (signal(SIGINT, sighandler) == SIG_ERR || + signal(SIGTERM, sighandler) == SIG_ERR) { + perror("Cannot set sighandler"); + exit(EXIT_FAILURE); + } + line = e1inp_line_create(LINENR, "ipa"); if (line == NULL) { LOGP(DBTSTEST, LOGL_ERROR, "problem enabling E1 line\n"); -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:45:01 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:45:01 +0200 Subject: [PATCH 12/13] tests: e1inp_ipa_*_test: fix leak of msgb in ->sign_link path In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-13-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso Fix a leak in the tests: The ->sign_link callback is reponsible for releasing the msgb. --- tests/e1inp_ipa_bsc_test.c | 1 + tests/e1inp_ipa_bts_test.c | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/e1inp_ipa_bsc_test.c b/tests/e1inp_ipa_bsc_test.c index b447893..b2fb11c 100644 --- a/tests/e1inp_ipa_bsc_test.c +++ b/tests/e1inp_ipa_bsc_test.c @@ -191,6 +191,7 @@ static int sign_link(struct msgb *msg) LOGP(DBSCTEST, LOGL_ERROR, "Unknown signallin message.\n"); break; } + msgb_free(msg); return ret; } diff --git a/tests/e1inp_ipa_bts_test.c b/tests/e1inp_ipa_bts_test.c index f885c5c..31aac95 100644 --- a/tests/e1inp_ipa_bts_test.c +++ b/tests/e1inp_ipa_bts_test.c @@ -151,6 +151,7 @@ static int sign_link(struct msgb *msg) LOGP(DBTSTEST, LOGL_ERROR, "Unknown signalling message.\n"); break; } + msgb_free(msg); return ret; } -- 1.7.10.4 From pablo at gnumonks.org Thu Aug 23 22:45:02 2012 From: pablo at gnumonks.org (pablo at gnumonks.org) Date: Fri, 24 Aug 2012 00:45:02 +0200 Subject: [PATCH 13/13] ipaccess: fix leak of IPA control messages in the BTS side In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <1345761903-1947-14-git-send-email-pablo@gnumonks.org> From: Pablo Neira Ayuso --- src/input/ipaccess.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index 6475007..265c982 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -856,6 +856,7 @@ static int ipaccess_bts_cb(struct ipa_client_conn *link, struct msgb *msg) } msgb_free(rmsg); } + msgb_free(msg); return ret; } else if (link->port == IPA_TCP_PORT_OML) e1i_ts = &link->line->ts[0]; -- 1.7.10.4 From holger at freyther.de Fri Aug 24 18:12:18 2012 From: holger at freyther.de (Holger Hans Peter Freyther) Date: Fri, 24 Aug 2012 20:12:18 +0200 Subject: [PATCH 00/13] libosmo-abis updates (v2) In-Reply-To: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> Message-ID: <20120824181218.GC6490@localhost> On Fri, Aug 24, 2012 at 12:44:49AM +0200, pablo at gnumonks.org wrote: > From: Pablo Neira Ayuso Hi, I would like to have another look at some of the patches. I am not sure if it helps you in a way. I think I only want to have another look at patch 04 (error handling) and 13 (msgbg leak fix). Iff it helps feel free to push all but the above two patches. holger From pablo at gnumonks.org Mon Aug 27 08:49:42 2012 From: pablo at gnumonks.org (Pablo Neira Ayuso) Date: Mon, 27 Aug 2012 10:49:42 +0200 Subject: [PATCH 00/13] libosmo-abis updates (v2) In-Reply-To: <20120824181218.GC6490@localhost> References: <1345761903-1947-1-git-send-email-pablo@gnumonks.org> <20120824181218.GC6490@localhost> Message-ID: <20120827084942.GA5444@1984> On Fri, Aug 24, 2012 at 08:12:18PM +0200, Holger Hans Peter Freyther wrote: > On Fri, Aug 24, 2012 at 12:44:49AM +0200, pablo at gnumonks.org wrote: > > From: Pablo Neira Ayuso > > Hi, > > I would like to have another look at some of the patches. I am not > sure if it helps you in a way. I think I only want to have another > look at patch 04 (error handling) and 13 (msgbg leak fix). Iff it > helps feel free to push all but the above two patches. No need to rush, I can wait for your review. Then, I can send another version of the patchset. Let me know. From donb at capitolhillconsultants.com Mon Aug 27 14:02:03 2012 From: donb at capitolhillconsultants.com (Don A. Bailey) Date: Mon, 27 Aug 2012 07:02:03 -0700 Subject: Recurring outbound GPRS Attach Accept messages Message-ID: All, Apologies if this is the wrong mailing list for this question. If so, please redirect me to the appropriate Osmocom list. Thanks! I'm having trouble with some older 2G cellular modules. When they initiate GPRS, the GPRS Attach Accept response from the SGSN seems to be dropped on the floor. I thought this was because the inbound TLLI generated by the ME was not included in the subsequent response. However, I verified that the LLC correctly generates the response and attaches the TLLI. I'm not quite sure why these particular 2G modules are not receiving the response as the message seems to be correctly submitted from the SGSN to the BTS. The result is that the GPRS state will get "stuck" on the ME side, which will keep attempting to Attach until it gives up and issues a Detach message (under the same TLLI). Can anyone clue me in on what potential issues may be caused by this ME and how/if I can patch this problem in the SGSN? Thank you, D -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexander.chemeris at gmail.com Mon Aug 27 17:32:12 2012 From: alexander.chemeris at gmail.com (Alexander Chemeris) Date: Mon, 27 Aug 2012 21:32:12 +0400 Subject: Recurring outbound GPRS Attach Accept messages In-Reply-To: References: Message-ID: goto OsmoPCU mailing list? Sent from my Android device. -- Regards, Alexander Chemeris CEO, Fairwaves LLC http://fairwaves.ru 27.08.2012 18:07 ???????????? "Don A. Bailey" < donb at capitolhillconsultants.com> ???????: > All, > Apologies if this is the wrong mailing list for this question. If so, > please redirect me to the appropriate Osmocom list. Thanks! > > I'm having trouble with some older 2G cellular modules. When they initiate > GPRS, the GPRS Attach Accept response from the SGSN seems to be dropped on > the floor. I thought this was because the inbound TLLI generated by the ME > was not included in the subsequent response. However, I verified that the > LLC correctly generates the response and attaches the TLLI. I'm not quite > sure why these particular 2G modules are not receiving the response as the > message seems to be correctly submitted from the SGSN to the BTS. > > The result is that the GPRS state will get "stuck" on the ME side, which > will keep attempting to Attach until it gives up and issues a Detach > message (under the same TLLI). > > Can anyone clue me in on what potential issues may be caused by this ME > and how/if I can patch this problem in the SGSN? > > Thank you, > D > > -------------- next part -------------- An HTML attachment was scrubbed... URL: