Commit Graph

82 Commits

Author SHA1 Message Date
Pau Espin 05ff552f25 stream_{cli,srv}: Add 'res' param to read_cb2
Notify user about read errors, similar to what is supported in the
earlier ofd cb backend of osmo_stream_cli/srv:
https://osmocom.org/issues/6405#note-15

Related: OS#6405
Fixes: 5fec34a9f2
Fixes: 0245cf5e07
Change-Id: I395c75ff1e9904757ce1d767a9ac2f779593c4c8
2024-04-18 10:55:13 +02:00
Pau Espin 211c15d543 examples/ipa-stream-client: Fix memleaks in read_cb()
Change-Id: I86fc159d928fc7ebce2f771670c5a198c52f5fc0
2024-04-16 19:11:51 +02:00
Andreas Eversberg b06e63b7c7 stream_{client,server} example: Cleanup on exit
In order to detect memory leaks while debugging, stream server/client
and keyboard is closed on exit.

Related: OS#5753
Change-Id: I9dbb7f46b2a798e88ad4df8ff73c6ee40c07b843
2024-03-07 10:28:20 +01:00
Andreas Eversberg d467b6348c stream_{cli,srv}: Fix memory leak, if sending a message fails
Also the example client/server must not access msgb after sending it,
especially if the msgb got freed due to a failure.

Change-Id: I627a71b4f0183cd83835c328a5cdd67a413ae614
2024-02-29 13:23:20 +01:00
Harald Welte 54d17d664a examples/stream-{server,client}: Generate talloc report on SIGUSR1
This can help with memleak debugging.

Change-Id: Ia16632602b937db88e2da2b053192887bdb8a986
2024-02-28 08:48:42 +00:00
Andreas Eversberg a7b687b121 examples/stream-*: Add options, to set local/remote peer
This helps to test connections via a network and failing connections.

The client may add "-r <peer>" to the command line, to set the address
of the remote peer.

The server may add "-l <peer>" to the command line, to select address
of local peer.

By default "127.0.0.1" is used.

Change-Id: Ie6da55ef248436e521c5d8f21f8053356c46a114
2024-02-28 08:47:34 +00:00
Harald Welte 15dcf5e743 examples/stream-*: Support SCTP when called with "-s" argument
Change-Id: I4137cdf1e21cb669b632fe5c126ec27475d98400
2024-02-28 08:46:00 +00:00
arehbein 106b63907a stream: Add and use helper function osmo_ipa_push_headers()
Related OS#5753, OS#5751

Change-Id: I61e1fe59166c46595efe8c1f32b8f2607cb6c529
2023-10-09 12:49:36 +00:00
arehbein bc496b1db0 stream: Add client-side (segmentation) support for IPA
With this commit, IPA segmentation is taken care of by setting the
segmentation callback provided by libosmo-netif.

The ipa-stream-server example needs to prepend IPA headers now because
those are stripped by the segm. cb on both sides.

Depends: libosmocore.git I3a639e6896cc3b3fc8e9b2e1a58254710efa0d3f

Related: OS#5753, OS#5751
Change-Id: I822abf52c6ae396c90b5c50228a0a39c848d3de6
2023-10-02 13:40:01 +00:00
arehbein f990b307bd stream: Add server-side (segmentation) support for IPA
With this commit, IPA segmentation can be taken care of by setting
the segmentation callback osmo_ipa_segmentation_cb().

Depends: libosmocore.git I3a639e6896cc3b3fc8e9b2e1a58254710efa0d3f

Related: OS#5753, OS#5751
Change-Id: I6c91ff385cb5f36ab6b6c96d0e44997995d0d24c
2023-08-25 13:26:46 +00:00
arehbein 8712af589c examples: Add extension header octet to example
Mainly to make data/packets look (pseudo-)correct in Wireshark.

Also: Add helper for allocating message buffers with extended headroom for IPA.

Change-Id: I962b9edcba65cdc98da00d2f8753dc5acd481502
2023-08-07 16:50:22 +02:00
Pau Espin 832c086852 stream: Drop name param from recently added API osmo_stream_srv_create2()
It was later decided that since setting a name is not really required,
it is best to leave it out of the create() function and let the user use
the osmo_stream_srv_set_name() API if needed (otherwise a dynamic name
based on socket is selected)

Change-Id: I5d677ef57b7db0aedd8c43282568c845097cb12b
2023-06-20 13:50:44 +02:00
Pau Espin 08e9b6c612 stream: Drop recently added API osmo_stream_cli_create2
It was later decided that since setting a name is not really required,
it is best to leave it out of the create() function and let the user use
the osmo_stream_cli_set_name() API if needed (otherwise a dynamic name
based on socket is selected).

Change-Id: I2a2fad318ef22c2ac117f95588a078ca3beccea5
2023-06-20 13:49:37 +02:00
Daniel Willmann 8cd2c4455e examples: Set logging level to DEBUG in {,ipa-}stream-{client,server}
Change-Id: I8c37bbe3db9823a399773d6790000ba508e79377
2023-06-16 09:23:28 +00:00
Daniel Willmann c873b62929 examples: Use new stream API in {ipa-,}stream-{client,server}
Change-Id: I97a9979199c816686b32080534627f6f033e009e
2023-06-14 18:17:13 +02:00
Daniel Willmann 6aa4b6961c ipa-stream-server: Return -EBADF in read_cb after osmo_stream_srv_destroy()
This fixes a potential heap-use-after-free error.
When there is still data to be written the osmo_stream_srv_cb() will
call osmo_stream_srv_write() which will try to dereference conn even
though it has already been freed.

Change-Id: I5ac1920b8d4ce3b0205f00d253e7ed878fb745e3
2023-05-31 12:11:15 +02:00
Pau Espin 6fe1f35001 osmux: Replace deprecated osmux_xfrm_input_* APIs in examples & tests
Change-Id: I7f3f8d40f89ffdd135a73316ee60fd429ba2a5b0
2022-10-03 11:30:45 +02:00
Pau Espin 3b0991e80f osmux: Allocate struct osmux_out_handle through API
Until now, the osmux_out_handle was allocated by the client, and passed
to the API to initialize it. This makes it really hard to improve the
implementation without breaking the ABI.

Let's break the ABI now one last time (hopefully) by allocating the
struct through an API. With only this change, the already built users
(osmo-mgw, openbsc) can still work fine, since there's no change on the
struct osmux_out_handle. However, they will somehow break next time the
struct is changed until they are ported to the same API (easy to do).

Related: OS#5987
Change-Id: Ie8df581f375c9a183a7af60b431561bda82f6e34
2022-09-02 11:29:05 +02:00
Pau Espin bc45a8f599 examples/osmux-test-output: Avoid using deprecated Osmux API
Change-Id: I408bfc84b9c1740df946fa29191f0e286f5b46e1
2022-08-31 16:19:25 +02:00
Harald Welte fa74cc5c68 Don't depend on libosmo-abis (by default)
The only reason we have a libosmo-netif -> libosmo-abis
dependency is the lapd examples whihc are built but not even installed.

Let's build those only if --enable-lapd-examples is specified at the
command line, and remove the dependency to libosmo-abis in all other
cases.

Change-Id: Ida8157cd9111b196e4bf08782c45d0e3d393f1c9
Closes: OS#4726
2021-02-11 15:40:54 +01:00
Harald Welte eb96eb7d68 Use osmo_fd_setup() wherever applicable
Change-Id: Ifb90e00036cc51ef02f3cf4dda1ff7dcd1f8a5b5
2020-10-18 23:12:20 +02:00
Daniel Willmann 384b8f15cb examples: Use osmo_stream_*_set_nodelay in ipa examples
We have functions to help with/abstract the nodelay settings so use
those.

Change-Id: Icb143c6e5fc3063f942a744deb576865674a4c62
2020-10-14 18:05:40 +02:00
Pau Espin b988f2bb36 Use OSMO_FD_* instead of deprecated BSC_FD_*
New define is available since libosmocore 1.1.0, and we already require
1.3.0, so no need to update dependenices.
Let's change it to avoid people re-using old BSC_FD_* symbols when
copy-pasting somewhere else.

Change-Id: I269690c1c9e4d19b5b69eef206b95e71f7931188
2020-05-09 19:14:17 +02:00
Max af63d87a76 Stream client: add disconnect callback
It's similar to connect_cb() but called once client has been
disconnected.

Change-Id: I905adb2d6191216551a3bcdcd1aec1f96f01612a
2019-02-20 17:33:32 +01:00
Max 6a7ebcc1e3 Stream examples: fix typos in error message
Likely a copy-paste error from corresponding client example code.

Change-Id: I47cc8c7340eb188d85a49d4f41c295bed0e1bee4
2019-02-06 08:09:27 +00:00
Max 732652b5b7 Add socket name functions to stream client/server
Add functions to get the description of a server link or client
connection which examine data on corresponding socket.

Those functions use static buffers and intended for single use in
log/printf statements as illustarted by corresponding example changes.

Change-Id: If9a8e211da85956781479862a63c4fc6e53ed6be
2019-02-05 16:25:20 +00:00
Max dee873489f Stream examples: print accepted client address
Display socket information for accepted client.

Change-Id: I5aa6757be79754cf7ffa4a276dae1cfb80fe904e
2019-02-05 15:09:28 +00:00
Max 4ce53ff107 Stream examples: fix server's endless loop
Stream server example had an error which resulted in infinite loop on
client disconnect. Fix this by properly handling client closing
connection to allow it to reconnect multiple times.

Change-Id: Icfc2cf7f971b9e3a4abc34cc18d8a44c811c5617
2019-01-29 18:20:34 +01:00
Max f8767012c8 Stream examples: log sent/received bytes
Make client and server examples more verbose by logging actual bytes
sent/received.

Change-Id: I6979b2f92c96c2366f18bf31e4bc495a6709133a
2019-01-29 18:20:34 +01:00
Max 5c7bf3b23d Stream examples: filter internal logging
Set category filter to make sure internal library logging won't
interfere with example's own logging. It's also nice example
illustrating log_set_category_filter() usage.

Change-Id: I17d7878d302f011d8ff0d86708d677f5b559299e
2019-01-29 18:20:22 +01:00
Harald Welte da5f41cdad Migrate from osmo_ipa_idtag_parse() to ipa_ccm_id_resp_parse()
In libosmocore Change-ID I1834d90fbcdbfcb05f5b8cfe39bfe9543737ef8f
we have introduced ipa_ccm_id_resp_parse() as a bugfixed replacement
of ipa_ccm_idtag_parse().

The main difference is that the returned "value" parts now have
a correct reported "length", whereas before this commit they all
reported a one-byte too-long "length" for each IE.

Let's use this opportunity to remove the copy+pasted
osmo_ipa_idtag_parse() function from the libosmo-netif codebase.

Change-Id: I4626d247626543e032593bf226b6c233f6678562
2018-08-01 17:36:21 +02:00
Harald Welte e2fbd3dee4 remove "channel" layer
The "channel" layer on top of IPA client + server was introduced in
2011 but never used in any osmocom program/project so far.  Contrary
to the several other IPA multiplex related implementations in libosmo*,
it did not deal properly with segmented IPA messages, i.e. where a
single TCP segment (and hence recv/read call) does not contain a full
IPA message.

So rather than fixing it up and having yet another IPA related API in
our libraries, let's remove it.

Change-Id: I97c378750acb1637ee032fa88a968edf68d8979f
2018-06-29 10:57:24 +02:00
Pau Espin df0ad6c1a4 osmux: Move examples and tests to use new output APIs
Change-Id: Ie69c427308eb7d81aedab7fbb71f1bdaf43f0275
2018-04-19 18:24:25 +02:00
Pau Espin 6fb0f4de86 examples: use osmo_init_logging2
Change-Id: I7f1f4503f254931edeebfbadf3953efa7b20f85f
2018-04-17 13:55:09 +02:00
Max 8440357d4c examples: add simple UDP client/server
In addition to showing basic UDP send/receive example, it helps to test
corner-case when dealing with 0-length UDP packets.

Change-Id: I08c0adf1cf9b6a6f1f7090b237d0497c2ec13cdf
Related: OS#2219
2017-10-13 18:13:14 +02:00
Neels Hofmeyr eda74fafb4 examples/stream-server.c: use read() rc instead of strlen()
Fixes: CID#57922
Change-Id: Ibaafdd49d9446a12fe7d0e2f5b2039da3ffc7ea9
2016-12-01 15:55:49 +00:00
Harald Welte 1f760e8dcc ipa-stream-{client,server}: Add missing #include <sys/socket.h>
This lead to compiler warnings on FreeBSD, as setsockopt() is undefined.

Change-Id: Ie0ee3e48adfd0cd252703ec020cef28cf76ca223
2016-12-01 16:07:23 +01:00
Harald Welte e63f88146d stream-client: check read() return value before using it as length input to memcpy
Change-Id: Id962821c71b3a1c4c01c1131eb809b8ec8eaa062
Fixes: Coverity CID 57859
2016-12-01 15:52:53 +01:00
Harald Welte a47c8a3f3f stream-client: Check for osmo_fd_register() return value
Change-Id: I1b5fa97d14e69ff502b6deba0fd898a01e53420f
Fixes: Coverity CID 57633
2016-12-01 15:52:53 +01:00
Harald Welte 046b12fa88 rs232-write: Check return value of osmo_fd_register()
Change-Id: If40e85600ca1dfbda5975d7aa92cccdb11f9c34d
Fixes: Coverity CID 57632
2016-12-01 15:52:53 +01:00
Harald Welte 7f0e9f1171 examples/lapd-over-datagram-network: Fix compiler warning
lapd-over-datagram-network.c:38:12: warning: ‘sapi’ defined but not used [-Wunused-variable]
 static int sapi = 63, tei = 0;
            ^~~~

Change-Id: If367deb0e0d7d5e031db2bd905179263d18703f0
2016-11-11 15:33:35 +01:00
Holger Hans Peter Freyther 92efd03e87 Do not use strlen on binary inpit
Coverity points out that buf might not be NULL terminated. For the
memcpy ret was already used, so use ret for msgb_put as well.

Fixes: CID#57922
2016-01-23 10:37:28 +01:00
Alexander Huemer d4be141ab0 teip is a pointer, not an int 2015-11-07 12:35:53 +01:00
Holger Hans Peter Freyther 86115434f1 endian: Use the new endian macros for portability
Use the new macros to deal with little/big endian. Im a bit
worried to make this change due the little test coverage in
this module but in case of a typo the elements would not be
defined.
2015-03-22 09:38:36 +01:00
Nikola Kolev 2f1ddb2709 Fix the compilation on FreeBSD. 2015-02-25 15:52:14 +01:00
Jan Engelhardt 226e994832 build: remove all_includes
This variable is never set and could therefore be removed.
2014-10-02 23:22:55 +02:00
Martin Hauke 603f6c40d5 build: rename INCLUDES to AM_CPPFLAGS in Makefile.am to avoid warnings 2014-09-11 18:22:02 +02:00
Pablo Neira Ayuso 282aee422f osmux: allow to set initial RTP SSRC
Instead of using the osmuxh->circuit_id.
2013-05-12 19:56:21 +02:00
Pablo Neira Ayuso d32caea9ea osmux: add osmux_snprintf
Useful for debugging purposes. Modify also examples to use it.
2013-02-19 17:14:33 +01:00
Pablo Neira Ayuso aeeb4399a2 examples: use DOSMUX_TEST instead of DLINP in logging messages 2013-02-19 17:13:37 +01:00