aboutsummaryrefslogtreecommitdiffstats
path: root/src/libosmocc
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2021-04-02 16:22:45 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2021-04-03 23:00:01 +0200
commit046834ac97f09fd9c04a61f8711ad15ffb361789 (patch)
treec6bc51784a2cf4a7af96e3999173deb88106e608 /src/libosmocc
parent2d1b5fb437a2035db06f994997c8afdb995d54b2 (diff)
libomsocc: Add function to check if interface is attached
Diffstat (limited to 'src/libosmocc')
-rw-r--r--src/libosmocc/endpoint.c35
-rw-r--r--src/libosmocc/endpoint.h1
2 files changed, 23 insertions, 13 deletions
diff --git a/src/libosmocc/endpoint.c b/src/libosmocc/endpoint.c
index e1d6027..481926d 100644
--- a/src/libosmocc/endpoint.c
+++ b/src/libosmocc/endpoint.c
@@ -172,6 +172,27 @@ static int split_address(const char *address, const char **host_p, uint16_t *por
return 0;
}
+
+osmo_cc_call_t *osmo_cc_get_attached_interface(osmo_cc_endpoint_t *ep, const char *interface)
+{
+ osmo_cc_call_t *att;
+
+ for (att = ep->call_list; att; att = att->next) {
+ if (att->state != OSMO_CC_STATE_ATTACH_IN)
+ continue;
+ /* no interface given, just use the attached peer */
+ if (!interface[0])
+ break;
+ /* no interface name given on attached peer, ignore it */
+ if (!att->attached_name || !att->attached_name[0])
+ continue;
+ /* interface given, use the attached peer with the same interface name */
+ if (!strcmp(interface, att->attached_name))
+ break;
+ }
+
+ return att;
+}
/* helper to forward message to upper layer */
static void forward_to_ul(osmo_cc_call_t *call, osmo_cc_msg_t *msg)
{
@@ -233,19 +254,7 @@ reject:
if (rc < 0)
interface[0] = '\0';
/* check for incoming attachment */
- for (att = call->ep->call_list; att; att = att->next) {
- if (att->state != OSMO_CC_STATE_ATTACH_IN)
- continue;
- /* no interface given, just use the attached peer */
- if (!interface[0])
- break;
- /* no interface name given on attached peer, ignore it */
- if (!att->attached_name || !att->attached_name[0])
- continue;
- /* interface given, use the attached peer with the same interface name */
- if (!strcmp(interface, att->attached_name))
- break;
- }
+ att = osmo_cc_get_attached_interface(call->ep, interface);
if (!att && !interface[0]) {
PDEBUG(DCC, DEBUG_ERROR, "No remote peer attached, rejecting call.\n");
goto reject;
diff --git a/src/libosmocc/endpoint.h b/src/libosmocc/endpoint.h
index 7145726..7c16dca 100644
--- a/src/libosmocc/endpoint.h
+++ b/src/libosmocc/endpoint.h
@@ -112,6 +112,7 @@ int osmo_cc_new(osmo_cc_endpoint_t *ep, const char *version, const char *name, u
void osmo_cc_delete(struct osmo_cc_endpoint *ep);
int osmo_cc_handle(void);
osmo_cc_call_t *osmo_cc_call_by_callref(osmo_cc_endpoint_t *ep, uint32_t callref);
+osmo_cc_call_t *osmo_cc_get_attached_interface(osmo_cc_endpoint_t *ep, const char *interface);
void osmo_cc_ll_msg(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg);
void osmo_cc_ul_msg(void *priv, uint32_t callref, osmo_cc_msg_t *msg);
osmo_cc_call_t *osmo_cc_call_new(osmo_cc_endpoint_t *ep);