lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

October 2023

  • 1 participants
  • 1843 discussions
[M] Change in osmocom-bb[master]: ASCI: Prepare gsm48_rr_rx_acch for voice group channel
by laforge 03 Oct '23

03 Oct '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/34529?usp=email ) Change subject: ASCI: Prepare gsm48_rr_rx_acch for voice group channel ...................................................................... ASCI: Prepare gsm48_rr_rx_acch for voice group channel The gsm48_rr_rx_acch function receives FACCH/SACCH. This is not only used for system information on SACCH, but also for short header messages and regular UI messages on TCH. Related: OS#5364 Change-Id: I39b27396a31137b3c4bdcb40dccdf3de60458fe2 --- M src/host/layer23/src/mobile/gsm48_rr.c 1 file changed, 62 insertions(+), 12 deletions(-) Approvals: pespin: Looks good to me, but someone else must approve fixeria: Looks good to me, approved Jenkins Builder: Verified diff --git a/src/host/layer23/src/mobile/gsm48_rr.c b/src/host/layer23/src/mobile/gsm48_rr.c index d725642..bda9861 100644 --- a/src/host/layer23/src/mobile/gsm48_rr.c +++ b/src/host/layer23/src/mobile/gsm48_rr.c @@ -4884,23 +4884,58 @@ } } +#define N201_Bter_SACCH 21 +#define N201_Bter_SDCCH_FACCH 23 +#define N201_B4 19 + /* receive ACCH at RR layer */ static int gsm48_rr_rx_acch(struct osmocom_ms *ms, struct msgb *msg) { - struct gsm48_system_information_type_header *sih = msgb_l3(msg); + const struct gsm48_system_information_type_header *sih; + const struct gsm48_hdr_sh *sgh; + const struct gsm48_hdr *gh; - switch (sih->system_information) { - case GSM48_MT_RR_SYSINFO_5: - return gsm48_rr_rx_sysinfo5(ms, msg); - case GSM48_MT_RR_SYSINFO_5bis: - return gsm48_rr_rx_sysinfo5bis(ms, msg); - case GSM48_MT_RR_SYSINFO_5ter: - return gsm48_rr_rx_sysinfo5ter(ms, msg); - case GSM48_MT_RR_SYSINFO_6: - return gsm48_rr_rx_sysinfo6(ms, msg); + /* Bter frame (SACCH or SDCCH/FACCH) */ + if (msgb_l3len(msg) == N201_Bter_SACCH || msgb_l3len(msg) == N201_Bter_SDCCH_FACCH) { + sgh = msgb_l3(msg); + if (sgh->rr_short_pd != GSM48_PDISC_SH_RR) { + LOGP(DRR, LOGL_NOTICE, "Short header message is not an RR message.\n"); + return -EINVAL; + } + switch (sgh->msg_type) { + default: + LOGP(DRR, LOGL_NOTICE, "Short header message type 0x%02x unsupported.\n", sgh->msg_type); + return -EINVAL; + } + } + + /* B4 frame (SACCH) */ + if ((msg->cb[0] & 0x40) && msgb_l3len(msg) == N201_B4) { + sih = msgb_l3(msg); + switch (sih->system_information) { + case GSM48_MT_RR_SYSINFO_5: + return gsm48_rr_rx_sysinfo5(ms, msg); + case GSM48_MT_RR_SYSINFO_5bis: + return gsm48_rr_rx_sysinfo5bis(ms, msg); + case GSM48_MT_RR_SYSINFO_5ter: + return gsm48_rr_rx_sysinfo5ter(ms, msg); + case GSM48_MT_RR_SYSINFO_6: + return gsm48_rr_rx_sysinfo6(ms, msg); + default: + LOGP(DRR, LOGL_NOTICE, "ACCH message type 0x%02x unknown.\n", sih->system_information); + return -EINVAL; + } + } + + /* B frame (UI frame on VGCS) */ + if (msgb_l3len(msg) < sizeof(*gh)) { + LOGP(DRR, LOGL_NOTICE, "ACCH message too short.\n"); + return -EINVAL; + } + gh = msgb_l3(msg); + switch (gh->msg_type) { default: - LOGP(DRR, LOGL_NOTICE, "ACCH message type 0x%02x unknown.\n", - sih->system_information); + LOGP(DRR, LOGL_NOTICE, "ACCH message type 0x%02x unknown.\n", gh->msg_type); return -EINVAL; } } @@ -4991,6 +5026,7 @@ case RSL_CHAN_Lm_ACCHs: case RSL_CHAN_SDCCH4_ACCH: case RSL_CHAN_SDCCH8_ACCH: + msg->cb[0] = rllh->link_id; return gsm48_rr_rx_acch(ms, msg); default: LOGP(DRSL, LOGL_NOTICE, "RSL with chan_nr 0x%02x unknown.\n", -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/34529?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I39b27396a31137b3c4bdcb40dccdf3de60458fe2 Gerrit-Change-Number: 34529 Gerrit-PatchSet: 7 Gerrit-Owner: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[L] Change in osmocom-bb[master]: ASCI: Add ASCI notification support to RR layer
by laforge 03 Oct '23

03 Oct '23
laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/34530?usp=email ) Change subject: ASCI: Add ASCI notification support to RR layer ...................................................................... ASCI: Add ASCI notification support to RR layer The notifications are received on NCH, as well as on FACCH. Related: OS#5364 Change-Id: I49df02cb4d99d9aab1ea3ca13beb2ea00ae4c9f4 --- M src/host/layer23/include/osmocom/bb/mobile/gsm48_rr.h M src/host/layer23/src/mobile/gsm48_rr.c 2 files changed, 264 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified fixeria: Looks good to me, approved diff --git a/src/host/layer23/include/osmocom/bb/mobile/gsm48_rr.h b/src/host/layer23/include/osmocom/bb/mobile/gsm48_rr.h index 6bc2f28..2d0ab58 100644 --- a/src/host/layer23/include/osmocom/bb/mobile/gsm48_rr.h +++ b/src/host/layer23/include/osmocom/bb/mobile/gsm48_rr.h @@ -207,6 +207,11 @@ /* sapi 3 */ uint8_t sapi3_state; uint8_t sapi3_link_id; + + /* group call */ + struct { + struct llist_head notif_list; /* list of received call notifications */ + } vgcs; }; const char *get_rr_name(int value); diff --git a/src/host/layer23/src/mobile/gsm48_rr.c b/src/host/layer23/src/mobile/gsm48_rr.c index bda9861..38a029f 100644 --- a/src/host/layer23/src/mobile/gsm48_rr.c +++ b/src/host/layer23/src/mobile/gsm48_rr.c @@ -1310,6 +1310,241 @@ } /* + * ASCI notification + */ + +struct asci_notif { + struct llist_head entry; + struct gsm48_rrlayer *rr; + uint8_t gcr[5]; + bool ch_desc_present; + struct gsm48_chan_desc ch_desc; + struct osmo_timer_list timer; +}; + +/* When does a notification received from NCH expires. */ +#define NOTIFICATION_TIMEOUT 5 + +static void asci_notif_timeout(void *arg); + +/* Add new notification to list. */ +static struct asci_notif *asci_notif_alloc(struct gsm48_rrlayer *rr, const uint8_t *gcr) +{ + struct asci_notif *notif; + + notif = talloc_zero(rr->ms, struct asci_notif); + if (!notif) + return NULL; + notif->rr = rr; + memcpy(notif->gcr, gcr, sizeof(notif->gcr)); + llist_add_tail(&notif->entry, &rr->vgcs.notif_list); + + notif->timer.cb = asci_notif_timeout; + notif->timer.data = notif; + + return notif; +} + +/* Remove notification from list. */ +static void asci_notif_free(struct asci_notif *notif) +{ + osmo_timer_del(&notif->timer); + llist_del(&notif->entry); + talloc_free(notif); +} + +/* Remove all ASCI notifications from list. */ +static void asci_notif_list_free(struct gsm48_rrlayer *rr) +{ + struct asci_notif *notif, *notif2; + + llist_for_each_entry_safe(notif, notif2, &rr->vgcs.notif_list, entry) + asci_notif_free(notif); +} + +/* Notification timed out. */ +static void asci_notif_timeout(void *arg) +{ + struct asci_notif *notif = arg; + struct gsm48_rrlayer *rr = notif->rr; + struct msgb *nmsg; + struct gsm48_mm_event *mme; + + /* Send notification of ceased call to MM layer. */ + LOGP(DRR, LOGL_INFO, "Notify MM layer about ceased group call.\n"); + nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_NOTIFICATION); + if (!nmsg) + return; + mme = (struct gsm48_mm_event *) nmsg->data; + memcpy(mme->notification.gcr, notif->gcr, sizeof(mme->notification.gcr)); + mme->notification.gone = true; + gsm48_mmevent_msg(rr->ms, nmsg); + + asci_notif_free(notif); +} + +/* Find notification in list. */ +static struct asci_notif *asci_notif_find(struct gsm48_rrlayer *rr, const uint8_t *gcr) +{ + struct asci_notif *notif; + + llist_for_each_entry(notif, &rr->vgcs.notif_list, entry) { + if (!memcmp(&notif->gcr, gcr, sizeof(notif->gcr))) + return notif; + } + + return NULL; +} + +static int gsm48_rr_rx_group_call(struct osmocom_ms *ms, const uint8_t *gcr, const uint8_t *ch_desc, bool nch) +{ + struct gsm48_rrlayer *rr = &ms->rrlayer; + struct asci_notif *notif; + bool update_call = false; + struct msgb *nmsg; + struct gsm48_mm_event *mme; + + /* Find or create notification entry. Only create entries for notifications on NCH */ + notif = asci_notif_find(rr, gcr); + if (!notif) { + update_call = true; + if (nch) { + notif = asci_notif_alloc(rr, gcr); + if (!notif) + return -ENOMEM; + } + } + + /* Update channel description. */ + if (notif) { + if (ch_desc) { + if (!notif->ch_desc_present) + update_call = true; + notif->ch_desc_present = true; + memcpy(&notif->ch_desc, ch_desc, sizeof(notif->ch_desc)); + } else { + notif->ch_desc_present = false; + if (!notif->ch_desc_present) + update_call = true; + } + /* (Re-)Start timer. */ + osmo_timer_schedule(&notif->timer, NOTIFICATION_TIMEOUT, 0); + } else + update_call = true; + + /* Send notification of new or updated call to MM layer. */ + if (update_call) { + LOGP(DRR, LOGL_INFO, "Notify MM layer about new/updated group call.\n"); + nmsg = gsm48_mmevent_msgb_alloc(GSM48_MM_EVENT_NOTIFICATION); + if (!nmsg) + return -ENOMEM; + mme = (struct gsm48_mm_event *) nmsg->data; + memcpy(mme->notification.gcr, gcr, sizeof(mme->notification.gcr)); + if (ch_desc) { + mme->notification.ch_desc_present = true; + memcpy(&mme->notification.ch_desc, ch_desc, sizeof(mme->notification.ch_desc)); + } + gsm48_mmevent_msg(ms, nmsg); + } + + return 0; +} + +/* Common function to decode Group Call Information */ +static int gsm48_rr_decode_group_call_info(struct osmocom_ms *ms, struct bitvec *bv, bool nch) +{ + struct bitvec *gcr_bv = NULL, *chd_bv = NULL; + int rc = 0; + int i; + + /* <Group Call Reference : bit(36)> */ + gcr_bv = bitvec_alloc(OSMO_BYTES_FOR_BITS(36), NULL); + OSMO_ASSERT(gcr_bv); + for (i = 0; i < 36; i++) + bitvec_set_bit(gcr_bv, bitvec_get_bit_pos(bv, bv->cur_bit++)); + /* Group Channel Description */ + if (bitvec_get_bit_pos(bv, bv->cur_bit++) == 1) { + chd_bv = bitvec_alloc(OSMO_BYTES_FOR_BITS(24), NULL); + OSMO_ASSERT(chd_bv); + for (i = 0; i < 24; i++) + bitvec_set_bit(chd_bv, bitvec_get_bit_pos(bv, bv->cur_bit++)); + /* FIXME: hopping */ + if (bitvec_get_bit_pos(bv, bv->cur_bit++) == 1) { + LOGP(DRR, LOGL_ERROR, "Hopping not supported on VGCS/VBS channel, please fix!\n"); + rc = -ENOTSUP; + goto out; + } + } + + rc = gsm48_rr_rx_group_call(ms, gcr_bv->data, (chd_bv) ? chd_bv->data : NULL, nch); + +out: + bitvec_free(chd_bv); + bitvec_free(gcr_bv); + + return rc; +} + +/* Notification/FACCH (9.1.21a) */ +static int gsm48_rr_rx_notif_facch(struct osmocom_ms *ms, struct msgb *msg) +{ + struct gsm48_hdr_sh *sgh = msgb_l3(msg); + int payload_len = msgb_l3len(msg) - sizeof(*sgh); + struct bitvec bv; + int rc; + + LOGP(DRR, LOGL_INFO, "NOTIFICATION/FACCH\n"); + + bv = (struct bitvec) { + .data = sgh->data, + .data_len = payload_len, + }; + + /* Group Call Information */ + if (bitvec_get_bit_pos(&bv, bv.cur_bit++) == 0) { + rc = gsm48_rr_decode_group_call_info(ms, &bv, false); + return rc; + } + + /* Note: Other information are not used. */ + return -ENOTSUP; +} + +/* Notification/NCH (9.1.21b) */ +static int gsm48_rr_rx_notif_nch(struct osmocom_ms *ms, struct msgb *msg) +{ + struct gsm48_notification_nch *nn = msgb_l3(msg); + int payload_len = msgb_l3len(msg) - sizeof(*nn); + struct bitvec bv; + int rc; + + LOGP(DRR, LOGL_INFO, "NOTIFICATION/NCH\n"); + + bv = (struct bitvec) { + .data = nn->data, + .data_len = payload_len, + }; + + /* 0 | 1 <NLN(NCH) : bit (2) > */ + if (bitvec_get_bit_pos(&bv, bv.cur_bit++) == 1) { + /* NLN not used + nln = bitvec_get_uint(&bv, 2); + nln_present = true; + */ + bv.cur_bit += 2; + } + + /* < list of Group Call NCH information > */ + while (bitvec_get_bit_pos(&bv, bv.cur_bit++) == 1) { + rc = gsm48_rr_decode_group_call_info(ms, &bv, true); + if (rc < 0) + break; + } + + return 0; +} + +/* * random access */ @@ -4875,6 +5110,10 @@ return gsm48_rr_rx_imm_ass_ext(ms, msg); case GSM48_MT_RR_IMM_ASS_REJ: return gsm48_rr_rx_imm_ass_rej(ms, msg); + + case GSM48_MT_RR_NOTIF_NCH: + return gsm48_rr_rx_notif_nch(ms, msg); + default: #if 0 LOGP(DRR, LOGL_NOTICE, "CCCH message type 0x%02x unknown.\n", @@ -4903,6 +5142,8 @@ return -EINVAL; } switch (sgh->msg_type) { + case GSM48_MT_RR_SH_FACCH: + return gsm48_rr_rx_notif_facch(ms, msg); default: LOGP(DRR, LOGL_NOTICE, "Short header message type 0x%02x unsupported.\n", sgh->msg_type); return -EINVAL; @@ -5708,6 +5949,9 @@ rr->audio_mode = 0x00; } + /* List of notifications about ongoing ASCI calls */ + INIT_LLIST_HEAD(&rr->vgcs.notif_list); + return 0; } @@ -5737,6 +5981,9 @@ stop_rr_t3124(rr); stop_rr_t3126(rr); + /* Free pending list entries. */ + asci_notif_list_free(rr); + return 0; } -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/34530?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I49df02cb4d99d9aab1ea3ca13beb2ea00ae4c9f4 Gerrit-Change-Number: 34530 Gerrit-PatchSet: 7 Gerrit-Owner: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[L] Change in osmocom-bb[master]: ASCI: Add group transmit mode support to RR layer
by laforge 03 Oct '23

03 Oct '23
Attention is currently required from: fixeria, jolly. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/34545?usp=email ) Change subject: ASCI: Add group transmit mode support to RR layer ...................................................................... Patch Set 6: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/34545?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Change-Id: I9b62eef5d877e5d9dcf349717efd2cce28862c58 Gerrit-Change-Number: 34545 Gerrit-PatchSet: 6 Gerrit-Owner: jolly <andreas(a)eversberg.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: jolly <andreas(a)eversberg.eu> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Comment-Date: Tue, 03 Oct 2023 12:45:54 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in osmo-bsc[master]: meas_feed: Use osmo_io instead of write queue
by laforge 03 Oct '23

03 Oct '23
Attention is currently required from: arehbein, daniel. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/34526?usp=email ) Change subject: meas_feed: Use osmo_io instead of write queue ...................................................................... Patch Set 7: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/34526?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc Gerrit-Branch: master Gerrit-Change-Id: Ib0570a3242e2846062e24c93cbbbbd31137acdee Gerrit-Change-Number: 34526 Gerrit-PatchSet: 7 Gerrit-Owner: arehbein <arehbein(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Attention: arehbein <arehbein(a)sysmocom.de> Gerrit-Attention: daniel <dwillmann(a)sysmocom.de> Gerrit-Comment-Date: Tue, 03 Oct 2023 12:43:43 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in libosmo-sccp[master]: xua_server: asp: Support removing local addresses
by laforge 03 Oct '23

03 Oct '23
Attention is currently required from: pespin. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34613?usp=email ) Change subject: xua_server: asp: Support removing local addresses ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34613?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: I942edff7695efeea7753f22e31c2098c201290ff Gerrit-Change-Number: 34613 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Tue, 03 Oct 2023 12:42:49 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in libosmo-sccp[master]: asp: Support removing local & remote addresses
by laforge 03 Oct '23

03 Oct '23
Attention is currently required from: pespin. laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34612?usp=email ) Change subject: asp: Support removing local & remote addresses ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34612?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: I554aee92285bd72eb90c6daf47b37055cb3067aa Gerrit-Change-Number: 34612 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Tue, 03 Oct 2023 12:42:22 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[L] Change in libosmo-sccp[master]: Split osmo_ss7_as functionalities to its own file
by pespin 03 Oct '23

03 Oct '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34590?usp=email ) Change subject: Split osmo_ss7_as functionalities to its own file ...................................................................... Split osmo_ss7_as functionalities to its own file Change-Id: I6e39dcb594ffe918ba117fce08cae7b5a6fd2dcc --- M src/Makefile.am M src/osmo_ss7.c A src/osmo_ss7_as.c M src/ss7_internal.h 4 files changed, 224 insertions(+), 171 deletions(-) Approvals: fixeria: Looks good to me, but someone else must approve Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/src/Makefile.am b/src/Makefile.am index 2067259..be6442d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,6 +37,7 @@ ipa.c \ m3ua.c \ osmo_ss7.c \ + osmo_ss7_as.c \ osmo_ss7_asp.c \ osmo_ss7_asp_peer.c \ osmo_ss7_hmrt.c \ diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index 1e8bcfb..dbbef6b 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -69,14 +69,6 @@ { 0, NULL } }; -struct value_string osmo_ss7_as_traffic_mode_vals[] = { - { OSMO_SS7_AS_TMOD_BCAST, "broadcast" }, - { OSMO_SS7_AS_TMOD_LOADSHARE, "loadshare" }, - { OSMO_SS7_AS_TMOD_ROUNDROBIN, "round-robin" }, - { OSMO_SS7_AS_TMOD_OVERRIDE, "override" }, - { 0, NULL } -}; - int osmo_ss7_find_free_rctx(struct osmo_ss7_instance *inst) { int32_t rctx; @@ -88,7 +80,7 @@ return -1; } -static uint32_t find_free_l_rk_id(struct osmo_ss7_instance *inst) +uint32_t ss7_find_free_l_rk_id(struct osmo_ss7_instance *inst) { uint32_t l_rk_id; @@ -855,19 +847,6 @@ * SS7 Application Server ***********************************************************************/ -static const struct rate_ctr_desc ss7_as_rcd[] = { - [SS7_AS_CTR_RX_MSU_TOTAL] = { "rx:msu:total", "Total number of MSU received" }, - [SS7_AS_CTR_TX_MSU_TOTAL] = { "tx:msu:total", "Total number of MSU transmitted" }, -}; - -static const struct rate_ctr_group_desc ss7_as_rcgd = { - .group_name_prefix = "sigtran_as", - .group_description = "SIGTRAN Application Server", - .num_ctr = ARRAY_SIZE(ss7_as_rcd), - .ctr_desc = ss7_as_rcd, -}; -static unsigned int g_ss7_as_rcg_idx; - /*! \brief Find Application Server by given name * \param[in] inst SS7 Instance on which we operate * \param[in] name Name of AS @@ -954,37 +933,6 @@ return as_without_asp; } -/*! \brief Allocate an Application Server - * \param[in] inst SS7 Instance on which we operate - * \param[in] name Name of Application Server - * \param[in] proto Protocol of Application Server - * \returns pointer to Application Server on success; NULL otherwise */ -struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name, - enum osmo_ss7_asp_protocol proto) -{ - struct osmo_ss7_as *as; - - as = talloc_zero(inst, struct osmo_ss7_as); - if (!as) - return NULL; - as->ctrg = rate_ctr_group_alloc(as, &ss7_as_rcgd, g_ss7_as_rcg_idx++); - if (!as->ctrg) { - talloc_free(as); - return NULL; - } - rate_ctr_group_set_name(as->ctrg, name); - as->inst = inst; - as->cfg.name = talloc_strdup(as, name); - as->cfg.proto = proto; - as->cfg.mode = OSMO_SS7_AS_TMOD_OVERRIDE; - as->cfg.recovery_timeout_msec = 2000; - as->cfg.routing_key.l_rk_id = find_free_l_rk_id(inst); - as->fi = xua_as_fsm_start(as, LOGL_DEBUG); - llist_add_tail(&as->list, &inst->as_list); - - return as; -} - /*! \brief Find or Create Application Server * \param[in] inst SS7 Instance on which we operate * \param[in] name Name of Application Server @@ -1012,124 +960,6 @@ return as; } -/*! \brief Add given ASP to given AS - * \param[in] as Application Server to which \ref asp is added - * \param[in] asp Application Server Process to be added to \ref as - * \returns 0 on success; negative in case of error */ -int osmo_ss7_as_add_asp(struct osmo_ss7_as *as, const char *asp_name) -{ - struct osmo_ss7_asp *asp; - unsigned int i; - - OSMO_ASSERT(ss7_initialized); - asp = osmo_ss7_asp_find_by_name(as->inst, asp_name); - if (!asp) - return -ENODEV; - - LOGPAS(as, DLSS7, LOGL_INFO, "Adding ASP %s to AS\n", asp->cfg.name); - - if (osmo_ss7_as_has_asp(as, asp)) - return 0; - - for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) { - if (!as->cfg.asps[i]) { - as->cfg.asps[i] = asp; - return 0; - } - } - - return -ENOSPC; -} - -/*! \brief Delete given ASP from given AS - * \param[in] as Application Server from which \ref asp is deleted - * \param[in] asp Application Server Process to delete from \ref as - * \returns 0 on success; negative in case of error */ -int osmo_ss7_as_del_asp(struct osmo_ss7_as *as, const char *asp_name) -{ - struct osmo_ss7_asp *asp; - unsigned int i; - - OSMO_ASSERT(ss7_initialized); - asp = osmo_ss7_asp_find_by_name(as->inst, asp_name); - if (!asp) - return -ENODEV; - - LOGPAS(as, DLSS7, LOGL_INFO, "Removing ASP %s from AS\n", asp->cfg.name); - - for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) { - if (as->cfg.asps[i] == asp) { - as->cfg.asps[i] = NULL; - return 0; - } - } - - return -EINVAL; -} - -/*! \brief Destroy given Application Server - * \param[in] as Application Server to destroy */ -void osmo_ss7_as_destroy(struct osmo_ss7_as *as) -{ - struct osmo_ss7_route *rt, *rt2; - - OSMO_ASSERT(ss7_initialized); - LOGPAS(as, DLSS7, LOGL_INFO, "Destroying AS\n"); - - if (as->fi) - osmo_fsm_inst_term(as->fi, OSMO_FSM_TERM_REQUEST, NULL); - - /* find any routes pointing to this AS and remove them */ - llist_for_each_entry_safe(rt, rt2, &as->inst->rtable_system->routes, list) { - if (rt->dest.as == as) - osmo_ss7_route_destroy(rt); - } - - as->inst = NULL; - llist_del(&as->list); - rate_ctr_group_free(as->ctrg); - talloc_free(as); -} - -/*! \brief Determine if given AS contains ASP - * \param[in] as Application Server in which to look for \ref asp - * \param[in] asp Application Server Process to look for in \ref as - * \returns true in case \ref asp is part of \ref as; false otherwise */ -bool osmo_ss7_as_has_asp(const struct osmo_ss7_as *as, - const struct osmo_ss7_asp *asp) -{ - unsigned int i; - - OSMO_ASSERT(ss7_initialized); - for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) { - if (as->cfg.asps[i] == asp) - return true; - } - return false; -} - -/*! Determine if given AS is in the active state. - * \param[in] as Application Server. - * \returns true in case as is active; false otherwise. */ -bool osmo_ss7_as_active(const struct osmo_ss7_as *as) -{ - if (!as->fi) - return false; - return as->fi->state == XUA_AS_S_ACTIVE; -} - -/*! Determine if given AS is in the down state. - * \param[in] as Application Server. - * \returns true in case as is down; false otherwise. */ -bool osmo_ss7_as_down(const struct osmo_ss7_as *as) -{ - OSMO_ASSERT(as); - - if (!as->fi) - return true; - return as->fi->state == XUA_AS_S_DOWN; -} - bool ss7_ipv6_sctp_supported(const char *host, bool bind) { int rc; diff --git a/src/osmo_ss7_as.c b/src/osmo_ss7_as.c new file mode 100644 index 0000000..34baf52 --- /dev/null +++ b/src/osmo_ss7_as.c @@ -0,0 +1,211 @@ +/* Core SS7 AS Handling */ + +/* (C) 2015-2017 by Harald Welte <laforge(a)gnumonks.org> + * (C) 2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <inttypes.h> + +#include <osmocom/sigtran/osmo_ss7.h> + +#include <osmocom/core/linuxlist.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/logging.h> + +#include "ss7_internal.h" +#include "xua_as_fsm.h" + +/*********************************************************************** + * SS7 Application Server + ***********************************************************************/ + +struct value_string osmo_ss7_as_traffic_mode_vals[] = { + { OSMO_SS7_AS_TMOD_BCAST, "broadcast" }, + { OSMO_SS7_AS_TMOD_LOADSHARE, "loadshare" }, + { OSMO_SS7_AS_TMOD_ROUNDROBIN, "round-robin" }, + { OSMO_SS7_AS_TMOD_OVERRIDE, "override" }, + { 0, NULL } +}; + +static const struct rate_ctr_desc ss7_as_rcd[] = { + [SS7_AS_CTR_RX_MSU_TOTAL] = { "rx:msu:total", "Total number of MSU received" }, + [SS7_AS_CTR_TX_MSU_TOTAL] = { "tx:msu:total", "Total number of MSU transmitted" }, +}; + +static const struct rate_ctr_group_desc ss7_as_rcgd = { + .group_name_prefix = "sigtran_as", + .group_description = "SIGTRAN Application Server", + .num_ctr = ARRAY_SIZE(ss7_as_rcd), + .ctr_desc = ss7_as_rcd, +}; +static unsigned int g_ss7_as_rcg_idx; + +/*! \brief Allocate an Application Server + * \param[in] inst SS7 Instance on which we operate + * \param[in] name Name of Application Server + * \param[in] proto Protocol of Application Server + * \returns pointer to Application Server on success; NULL otherwise */ +struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name, + enum osmo_ss7_asp_protocol proto) +{ + struct osmo_ss7_as *as; + + as = talloc_zero(inst, struct osmo_ss7_as); + if (!as) + return NULL; + as->ctrg = rate_ctr_group_alloc(as, &ss7_as_rcgd, g_ss7_as_rcg_idx++); + if (!as->ctrg) { + talloc_free(as); + return NULL; + } + rate_ctr_group_set_name(as->ctrg, name); + as->inst = inst; + as->cfg.name = talloc_strdup(as, name); + as->cfg.proto = proto; + as->cfg.mode = OSMO_SS7_AS_TMOD_OVERRIDE; + as->cfg.recovery_timeout_msec = 2000; + as->cfg.routing_key.l_rk_id = ss7_find_free_l_rk_id(inst); + as->fi = xua_as_fsm_start(as, LOGL_DEBUG); + llist_add_tail(&as->list, &inst->as_list); + + return as; +} + +/*! \brief Add given ASP to given AS + * \param[in] as Application Server to which \ref asp is added + * \param[in] asp Application Server Process to be added to \ref as + * \returns 0 on success; negative in case of error */ +int osmo_ss7_as_add_asp(struct osmo_ss7_as *as, const char *asp_name) +{ + struct osmo_ss7_asp *asp; + unsigned int i; + + OSMO_ASSERT(ss7_initialized); + asp = osmo_ss7_asp_find_by_name(as->inst, asp_name); + if (!asp) + return -ENODEV; + + LOGPAS(as, DLSS7, LOGL_INFO, "Adding ASP %s to AS\n", asp->cfg.name); + + if (osmo_ss7_as_has_asp(as, asp)) + return 0; + + for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) { + if (!as->cfg.asps[i]) { + as->cfg.asps[i] = asp; + return 0; + } + } + + return -ENOSPC; +} + +/*! \brief Delete given ASP from given AS + * \param[in] as Application Server from which \ref asp is deleted + * \param[in] asp Application Server Process to delete from \ref as + * \returns 0 on success; negative in case of error */ +int osmo_ss7_as_del_asp(struct osmo_ss7_as *as, const char *asp_name) +{ + struct osmo_ss7_asp *asp; + unsigned int i; + + OSMO_ASSERT(ss7_initialized); + asp = osmo_ss7_asp_find_by_name(as->inst, asp_name); + if (!asp) + return -ENODEV; + + LOGPAS(as, DLSS7, LOGL_INFO, "Removing ASP %s from AS\n", asp->cfg.name); + + for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) { + if (as->cfg.asps[i] == asp) { + as->cfg.asps[i] = NULL; + return 0; + } + } + + return -EINVAL; +} + +/*! \brief Destroy given Application Server + * \param[in] as Application Server to destroy */ +void osmo_ss7_as_destroy(struct osmo_ss7_as *as) +{ + struct osmo_ss7_route *rt, *rt2; + + OSMO_ASSERT(ss7_initialized); + LOGPAS(as, DLSS7, LOGL_INFO, "Destroying AS\n"); + + if (as->fi) + osmo_fsm_inst_term(as->fi, OSMO_FSM_TERM_REQUEST, NULL); + + /* find any routes pointing to this AS and remove them */ + llist_for_each_entry_safe(rt, rt2, &as->inst->rtable_system->routes, list) { + if (rt->dest.as == as) + osmo_ss7_route_destroy(rt); + } + + as->inst = NULL; + llist_del(&as->list); + rate_ctr_group_free(as->ctrg); + talloc_free(as); +} + +/*! \brief Determine if given AS contains ASP + * \param[in] as Application Server in which to look for \ref asp + * \param[in] asp Application Server Process to look for in \ref as + * \returns true in case \ref asp is part of \ref as; false otherwise */ +bool osmo_ss7_as_has_asp(const struct osmo_ss7_as *as, + const struct osmo_ss7_asp *asp) +{ + unsigned int i; + + OSMO_ASSERT(ss7_initialized); + for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) { + if (as->cfg.asps[i] == asp) + return true; + } + return false; +} + +/*! Determine if given AS is in the active state. + * \param[in] as Application Server. + * \returns true in case as is active; false otherwise. */ +bool osmo_ss7_as_active(const struct osmo_ss7_as *as) +{ + if (!as->fi) + return false; + return as->fi->state == XUA_AS_S_ACTIVE; +} + +/*! Determine if given AS is in the down state. + * \param[in] as Application Server. + * \returns true in case as is down; false otherwise. */ +bool osmo_ss7_as_down(const struct osmo_ss7_as *as) +{ + OSMO_ASSERT(as); + + if (!as->fi) + return true; + return as->fi->state == XUA_AS_S_DOWN; +} diff --git a/src/ss7_internal.h b/src/ss7_internal.h index 4539609..6449c5b 100644 --- a/src/ss7_internal.h +++ b/src/ss7_internal.h @@ -3,9 +3,11 @@ /* Internal header used by libosmo-sccp, not available publicly for lib users */ #include <stdbool.h> +#include <stdint.h> #include <osmocom/sigtran/osmo_ss7.h> extern bool ss7_initialized; +uint32_t ss7_find_free_l_rk_id(struct osmo_ss7_instance *inst); bool ss7_ipv6_sctp_supported(const char *host, bool bind); -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34590?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: I6e39dcb594ffe918ba117fce08cae7b5a6fd2dcc Gerrit-Change-Number: 34590 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[M] Change in libosmo-sccp[master]: asp: Factor out helper function to match host in asp_peer
by pespin 03 Oct '23

03 Oct '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34587?usp=email ) Change subject: asp: Factor out helper function to match host in asp_peer ...................................................................... asp: Factor out helper function to match host in asp_peer Change-Id: I6f13b285be09982ec83107ff96ade4dabf843815 --- M src/osmo_ss7_asp.c 1 file changed, 26 insertions(+), 25 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c index 596e7ae..eab6bc7 100644 --- a/src/osmo_ss7_asp.c +++ b/src/osmo_ss7_asp.c @@ -343,6 +343,21 @@ return osmo_ss7_asp_peer_add_host2(peer, talloc_ctx, host, false); } +static bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6) +{ + unsigned int i; + for (i = 0; i < peer->host_cnt; i++) { + bool iter_is_v6 = osmo_ip_str_type(peer->host[i]) == AF_INET6; + bool iter_is_anyaddr = host_is_ip_anyaddr(peer->host[i], iter_is_v6); + /* "::" (v6) covers "0.0.0.0" (v4), but not otherwise */ + if ((iter_is_v6 != host_is_v6) && !(iter_is_v6 && iter_is_anyaddr)) + continue; + if (iter_is_anyaddr || !strcmp(peer->host[i], host)) + return true; + } + return false; +} + int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp) { struct osmo_fd *ofd; @@ -570,7 +585,6 @@ uint16_t local_port, remote_port; bool loc_is_v6, rem_is_v6; int rc; - int i; OSMO_ASSERT(ss7_initialized); /* convert local and remote IP to string */ @@ -613,34 +627,12 @@ if (asp->cfg.remote.port && asp->cfg.remote.port != remote_port) continue; - for (i = 0; i < asp->cfg.local.host_cnt; i++) { - bool iter_is_v6 = osmo_ip_str_type(asp->cfg.local.host[i]) == AF_INET6; - bool iter_is_anyaddr = host_is_ip_anyaddr(asp->cfg.local.host[i], iter_is_v6); - /* "::" (v6) covers "0.0.0.0" (v4), but not otherwise */ - if (iter_is_v6 != loc_is_v6 && - !(iter_is_v6 && iter_is_anyaddr)) - continue; - if (iter_is_anyaddr || - !strcmp(asp->cfg.local.host[i], hostbuf_l)) - break; - } - if (i == asp->cfg.local.host_cnt) + if (!ss7_asp_peer_match_host(&asp->cfg.local, hostbuf_l, loc_is_v6)) continue; /* didn't match any local.host */ /* If no remote host was set, it's probably a server and hence we match any cli src */ if (asp->cfg.remote.host_cnt) { - for (i = 0; i < asp->cfg.remote.host_cnt; i++) { - bool iter_is_v6 = osmo_ip_str_type(asp->cfg.remote.host[i]) == AF_INET6; - bool iter_is_anyaddr = host_is_ip_anyaddr(asp->cfg.remote.host[i], iter_is_v6); - /* "::" (v6) covers "0.0.0.0" (v4), but not otherwise */ - if (iter_is_v6 != rem_is_v6 && - !(iter_is_v6 && iter_is_anyaddr)) - continue; - if (iter_is_anyaddr || - !strcmp(asp->cfg.remote.host[i], hostbuf_r)) - break; - } - if (i == asp->cfg.remote.host_cnt) + if (!ss7_asp_peer_match_host(&asp->cfg.remote, hostbuf_r, rem_is_v6)) continue; /* didn't match any remote.host */ } -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34587?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: I6f13b285be09982ec83107ff96ade4dabf843815 Gerrit-Change-Number: 34587 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[M] Change in libosmo-sccp[master]: Factor our osmo_ss7_as allocation to its own function
by pespin 03 Oct '23

03 Oct '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34589?usp=email ) Change subject: Factor our osmo_ss7_as allocation to its own function ...................................................................... Factor our osmo_ss7_as allocation to its own function This makes it easier to find out where the AS struct is allocated, plus also split between inst code looking up + checking + allocating and the code doing the allocation and initialization of the AS. Change-Id: Ie237ec8ac4b2e15b76fce3b3a56f47a59fdcc76e --- M src/osmo_ss7.c M src/ss7_internal.h 2 files changed, 48 insertions(+), 15 deletions(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified fixeria: Looks good to me, but someone else must approve diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index 9265898..1e8bcfb 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -954,6 +954,37 @@ return as_without_asp; } +/*! \brief Allocate an Application Server + * \param[in] inst SS7 Instance on which we operate + * \param[in] name Name of Application Server + * \param[in] proto Protocol of Application Server + * \returns pointer to Application Server on success; NULL otherwise */ +struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name, + enum osmo_ss7_asp_protocol proto) +{ + struct osmo_ss7_as *as; + + as = talloc_zero(inst, struct osmo_ss7_as); + if (!as) + return NULL; + as->ctrg = rate_ctr_group_alloc(as, &ss7_as_rcgd, g_ss7_as_rcg_idx++); + if (!as->ctrg) { + talloc_free(as); + return NULL; + } + rate_ctr_group_set_name(as->ctrg, name); + as->inst = inst; + as->cfg.name = talloc_strdup(as, name); + as->cfg.proto = proto; + as->cfg.mode = OSMO_SS7_AS_TMOD_OVERRIDE; + as->cfg.recovery_timeout_msec = 2000; + as->cfg.routing_key.l_rk_id = find_free_l_rk_id(inst); + as->fi = xua_as_fsm_start(as, LOGL_DEBUG); + llist_add_tail(&as->list, &inst->as_list); + + return as; +} + /*! \brief Find or Create Application Server * \param[in] inst SS7 Instance on which we operate * \param[in] name Name of Application Server @@ -972,23 +1003,9 @@ return NULL; if (!as) { - as = talloc_zero(inst, struct osmo_ss7_as); + as = ss7_as_alloc(inst, name, proto); if (!as) return NULL; - as->ctrg = rate_ctr_group_alloc(as, &ss7_as_rcgd, g_ss7_as_rcg_idx++); - if (!as->ctrg) { - talloc_free(as); - return NULL; - } - rate_ctr_group_set_name(as->ctrg, name); - as->inst = inst; - as->cfg.name = talloc_strdup(as, name); - as->cfg.proto = proto; - as->cfg.mode = OSMO_SS7_AS_TMOD_OVERRIDE; - as->cfg.recovery_timeout_msec = 2000; - as->cfg.routing_key.l_rk_id = find_free_l_rk_id(inst); - as->fi = xua_as_fsm_start(as, LOGL_DEBUG); - llist_add_tail(&as->list, &inst->as_list); LOGPAS(as, DLSS7, LOGL_INFO, "Created AS\n"); } diff --git a/src/ss7_internal.h b/src/ss7_internal.h index d05b16e..4539609 100644 --- a/src/ss7_internal.h +++ b/src/ss7_internal.h @@ -9,6 +9,9 @@ bool ss7_ipv6_sctp_supported(const char *host, bool bind); +struct osmo_ss7_as *ss7_as_alloc(struct osmo_ss7_instance *inst, const char *name, + enum osmo_ss7_asp_protocol proto); + struct osmo_ss7_asp *ss7_asp_alloc(struct osmo_ss7_instance *inst, const char *name, uint16_t remote_port, uint16_t local_port, enum osmo_ss7_asp_protocol proto); -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34589?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: Ie237ec8ac4b2e15b76fce3b3a56f47a59fdcc76e Gerrit-Change-Number: 34589 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
[L] Change in libosmo-sccp[master]: Split osmo_ss7_asp_peer functionalities to its own file
by pespin 03 Oct '23

03 Oct '23
pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmo-sccp/+/34588?usp=email ) Change subject: Split osmo_ss7_asp_peer functionalities to its own file ...................................................................... Split osmo_ss7_asp_peer functionalities to its own file Change-Id: I4fe457dc0ee1e904e05423557cfba2505b315a75 --- M src/Makefile.am M src/osmo_ss7_asp.c A src/osmo_ss7_asp_peer.c M src/ss7_internal.h 4 files changed, 247 insertions(+), 190 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved fixeria: Looks good to me, but someone else must approve diff --git a/src/Makefile.am b/src/Makefile.am index 3c0bdb4..2067259 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,7 @@ m3ua.c \ osmo_ss7.c \ osmo_ss7_asp.c \ + osmo_ss7_asp_peer.c \ osmo_ss7_hmrt.c \ osmo_ss7_vty.c \ osmo_ss7_xua_srv.c \ diff --git a/src/osmo_ss7_asp.c b/src/osmo_ss7_asp.c index eab6bc7..6068a9d 100644 --- a/src/osmo_ss7_asp.c +++ b/src/osmo_ss7_asp.c @@ -168,196 +168,6 @@ }; static unsigned int g_ss7_asp_rcg_idx; -void osmo_ss7_asp_peer_init(struct osmo_ss7_asp_peer *peer) -{ - memset(peer, 0, sizeof(*peer)); - peer->idx_primary = -1; -} - -int osmo_ss7_asp_peer_snprintf(char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer) -{ - int len = 0, offset = 0, rem = buf_len; - int ret, i; - char *after; - char *primary; - - if (buf_len < 3) - return -EINVAL; - - if (peer->host_cnt > 1) { - ret = snprintf(buf, rem, "("); - if (ret < 0) - return ret; - OSMO_SNPRINTF_RET(ret, rem, offset, len); - } - for (i = 0; i < peer->host_cnt; i++) { - primary = (peer->idx_primary == i) ? "*" : ""; - if (peer->host_cnt == 1) - after = ""; - else - after = (i == (peer->host_cnt - 1)) ? ")" : "|"; - ret = snprintf(buf + offset, rem, "%s%s%s", peer->host[i] ? : "0.0.0.0", primary, after); - OSMO_SNPRINTF_RET(ret, rem, offset, len); - } - ret = snprintf(buf + offset, rem, ":%u", peer->port); - if (ret < 0) - return ret; - OSMO_SNPRINTF_RET(ret, rem, offset, len); - - return len; -} - -/*! \brief Set (copy) addresses for a given ASP peer. Previous addresses are freed. - * \param[in] peer Application Server Process peer whose addresses are to be set. - * \param[in] talloc_ctx talloc context used to allocate new addresses. - * \param[in] hosts Array of strings containing IP addresses. - * \param[in] host_cnt Number of strings in hosts - * \param[in] idx_primary Index in "hosts" array marking the SCTP Primary Address, -1 if no explicit Primary Address set - * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt, int idx_primary) -{ - int i = 0; - - if (idx_primary >= (int)host_cnt || idx_primary < -1) - return -EINVAL; - - if (host_cnt > ARRAY_SIZE(peer->host)) - return -EINVAL; - - for (; i < host_cnt; i++) - osmo_talloc_replace_string(talloc_ctx, &peer->host[i], hosts[i]); - for (; i < peer->host_cnt; i++) { - talloc_free(peer->host[i]); - peer->host[i] = NULL; - } - - peer->host_cnt = host_cnt; - peer->idx_primary = idx_primary; - return 0; -} - -/*! \brief Set (copy) addresses for a given ASP peer. Previous addresses are freed. - * \param[in] peer Application Server Process peer whose addresses are to be set. - * \param[in] talloc_ctx talloc context used to allocate new addresses. - * \param[in] hosts Array of strings containing IP addresses. - * \param[in] host_cnt Number of strings in hosts - * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_set_hosts(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt) -{ - return osmo_ss7_asp_peer_set_hosts2(peer, talloc_ctx, hosts, host_cnt, -1); -} - -/* Is string formatted IPv4/v6 addr considered IN(6)ADDR_ANY? */ -static inline bool host_is_ip_anyaddr(const char *host, bool is_v6) -{ - /* NULL addr is resolved as 0.0.0.0 (IPv4) by getaddrinfo(), most - * probably for backward-compatibility reasons. - */ - return is_v6 ? (host && !strcmp(host, "::")) - : (!host || !strcmp(host, "0.0.0.0")); -} - -/*! \brief Append (copy) address to a given ASP peer. Previous addresses are kept. - * \param[in] peer Application Server Process peer the address is appended to. - * \param[in] talloc_ctx talloc context used to allocate new address. - * \param[in] host string containing an IP address. - * \param[in] is_primary_addr whether this IP address is to be added as SCTP Primary Address - * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, - const char *host, bool is_primary_addr) -{ - int i; - bool new_is_v6 = osmo_ip_str_type(host) == AF_INET6; - bool new_is_any = host_is_ip_anyaddr(host, new_is_v6); - struct osmo_sockaddr_str addr_str; - - if (osmo_sockaddr_str_from_str(&addr_str, host, 0) < 0) - return -EINVAL; - - if (new_is_any) { - /* Makes no sense to have INET(6)_ANY many times, or INET(6)_ANY - * together with specific addresses, be it of same or different - * IP version: */ - if (peer->host_cnt != 0) - return -EINVAL; - - /* Makes no sense to have INET(6)_ANY as primary: */ - if (is_primary_addr) - return -EINVAL; - - if (peer->host_cnt >= ARRAY_SIZE(peer->host)) - return -EINVAL; - osmo_talloc_replace_string(talloc_ctx, &peer->host[peer->host_cnt], host); - peer->host_cnt++; - return 0; - } - - /* Makes no sense to add specific address to set if INET(6)_ANY - * is already set, be it from same or different IP version: */ - for (i = 0; i < peer->host_cnt; i++) { - bool iter_is_v6 = osmo_ip_str_type(peer->host[i]) == AF_INET6; - if (host_is_ip_anyaddr(peer->host[i], iter_is_v6)) - return -EINVAL; - } - /* Reached this point, no INET(6)_ANY address is set nor we are adding an INET(6)_ANY address. */ - - /* Check if address already exists, and then if primary flags need to be changed: */ - for (i = 0; i < peer->host_cnt; i++) { - struct osmo_sockaddr_str it_addr_str; - bool it_is_primary; - osmo_sockaddr_str_from_str(&it_addr_str, peer->host[i], 0); - - if (osmo_sockaddr_str_cmp(&addr_str, &it_addr_str) != 0) - continue; - it_is_primary = (peer->idx_primary == i); - if (is_primary_addr == it_is_primary) { - /* Nothing to do, return below */ - } else if (is_primary_addr && !it_is_primary) { - /* Mark it as primary: */ - peer->idx_primary = i; - } else { /* if (!is_primary_addr && it_is_primary) { */ - /* mark it as non-primary: */ - peer->idx_primary = -1; - } - return 0; - } - - if (peer->host_cnt >= ARRAY_SIZE(peer->host)) - return -EINVAL; - - osmo_talloc_replace_string(talloc_ctx, &peer->host[peer->host_cnt], host); - if (is_primary_addr) - peer->idx_primary = peer->host_cnt; - peer->host_cnt++; - return 0; -} - -/*! \brief Append (copy) address to a given ASP peer. Previous addresses are kept. - * \param[in] peer Application Server Process peer the address is appended to. - * \param[in] talloc_ctx talloc context used to allocate new address. - * \param[in] host string containing an IP address. - * \returns 0 on success; negative otherwise */ -int osmo_ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, - const char *host) -{ - return osmo_ss7_asp_peer_add_host2(peer, talloc_ctx, host, false); -} - -static bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6) -{ - unsigned int i; - for (i = 0; i < peer->host_cnt; i++) { - bool iter_is_v6 = osmo_ip_str_type(peer->host[i]) == AF_INET6; - bool iter_is_anyaddr = host_is_ip_anyaddr(peer->host[i], iter_is_v6); - /* "::" (v6) covers "0.0.0.0" (v4), but not otherwise */ - if ((iter_is_v6 != host_is_v6) && !(iter_is_v6 && iter_is_anyaddr)) - continue; - if (iter_is_anyaddr || !strcmp(peer->host[i], host)) - return true; - } - return false; -} - int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp) { struct osmo_fd *ofd; diff --git a/src/osmo_ss7_asp_peer.c b/src/osmo_ss7_asp_peer.c new file mode 100644 index 0000000..cf591d9 --- /dev/null +++ b/src/osmo_ss7_asp_peer.c @@ -0,0 +1,235 @@ +/* SS7 ASP Peer (one endpoint of a conn) */ + +/* (C) 2015-2017 by Harald Welte <laforge(a)gnumonks.org> + * (C) 2023 by sysmocom s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <inttypes.h> +#include <netdb.h> +#include <netinet/in.h> +#include <netinet/sctp.h> + +#include <osmocom/core/utils.h> +#include <osmocom/core/talloc.h> +#include <osmocom/core/logging.h> +#include <osmocom/core/socket.h> +#include <osmocom/core/sockaddr_str.h> + +#include <osmocom/sigtran/osmo_ss7.h> + +#include "ss7_internal.h" + + +/*********************************************************************** + * SS7 Application Server Process peer + ***********************************************************************/ + +void osmo_ss7_asp_peer_init(struct osmo_ss7_asp_peer *peer) +{ + memset(peer, 0, sizeof(*peer)); + peer->idx_primary = -1; +} + +int osmo_ss7_asp_peer_snprintf(char *buf, size_t buf_len, struct osmo_ss7_asp_peer *peer) +{ + int len = 0, offset = 0, rem = buf_len; + int ret, i; + char *after; + char *primary; + + if (buf_len < 3) + return -EINVAL; + + if (peer->host_cnt > 1) { + ret = snprintf(buf, rem, "("); + if (ret < 0) + return ret; + OSMO_SNPRINTF_RET(ret, rem, offset, len); + } + for (i = 0; i < peer->host_cnt; i++) { + primary = (peer->idx_primary == i) ? "*" : ""; + if (peer->host_cnt == 1) + after = ""; + else + after = (i == (peer->host_cnt - 1)) ? ")" : "|"; + ret = snprintf(buf + offset, rem, "%s%s%s", peer->host[i] ? : "0.0.0.0", primary, after); + OSMO_SNPRINTF_RET(ret, rem, offset, len); + } + ret = snprintf(buf + offset, rem, ":%u", peer->port); + if (ret < 0) + return ret; + OSMO_SNPRINTF_RET(ret, rem, offset, len); + + return len; +} + +/*! \brief Set (copy) addresses for a given ASP peer. Previous addresses are freed. + * \param[in] peer Application Server Process peer whose addresses are to be set. + * \param[in] talloc_ctx talloc context used to allocate new addresses. + * \param[in] hosts Array of strings containing IP addresses. + * \param[in] host_cnt Number of strings in hosts + * \param[in] idx_primary Index in "hosts" array marking the SCTP Primary Address, -1 if no explicit Primary Address set + * \returns 0 on success; negative otherwise */ +int osmo_ss7_asp_peer_set_hosts2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt, int idx_primary) +{ + int i = 0; + + if (idx_primary >= (int)host_cnt || idx_primary < -1) + return -EINVAL; + + if (host_cnt > ARRAY_SIZE(peer->host)) + return -EINVAL; + + for (; i < host_cnt; i++) + osmo_talloc_replace_string(talloc_ctx, &peer->host[i], hosts[i]); + for (; i < peer->host_cnt; i++) { + talloc_free(peer->host[i]); + peer->host[i] = NULL; + } + + peer->host_cnt = host_cnt; + peer->idx_primary = idx_primary; + return 0; +} + +/*! \brief Set (copy) addresses for a given ASP peer. Previous addresses are freed. + * \param[in] peer Application Server Process peer whose addresses are to be set. + * \param[in] talloc_ctx talloc context used to allocate new addresses. + * \param[in] hosts Array of strings containing IP addresses. + * \param[in] host_cnt Number of strings in hosts + * \returns 0 on success; negative otherwise */ +int osmo_ss7_asp_peer_set_hosts(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, const char *const*hosts, size_t host_cnt) +{ + return osmo_ss7_asp_peer_set_hosts2(peer, talloc_ctx, hosts, host_cnt, -1); +} + +/* Is string formatted IPv4/v6 addr considered IN(6)ADDR_ANY? */ +static inline bool host_is_ip_anyaddr(const char *host, bool is_v6) +{ + /* NULL addr is resolved as 0.0.0.0 (IPv4) by getaddrinfo(), most + * probably for backward-compatibility reasons. + */ + return is_v6 ? (host && !strcmp(host, "::")) + : (!host || !strcmp(host, "0.0.0.0")); +} + +/*! \brief Append (copy) address to a given ASP peer. Previous addresses are kept. + * \param[in] peer Application Server Process peer the address is appended to. + * \param[in] talloc_ctx talloc context used to allocate new address. + * \param[in] host string containing an IP address. + * \param[in] is_primary_addr whether this IP address is to be added as SCTP Primary Address + * \returns 0 on success; negative otherwise */ +int osmo_ss7_asp_peer_add_host2(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, + const char *host, bool is_primary_addr) +{ + int i; + bool new_is_v6 = osmo_ip_str_type(host) == AF_INET6; + bool new_is_any = host_is_ip_anyaddr(host, new_is_v6); + struct osmo_sockaddr_str addr_str; + + if (osmo_sockaddr_str_from_str(&addr_str, host, 0) < 0) + return -EINVAL; + + if (new_is_any) { + /* Makes no sense to have INET(6)_ANY many times, or INET(6)_ANY + * together with specific addresses, be it of same or different + * IP version: */ + if (peer->host_cnt != 0) + return -EINVAL; + + /* Makes no sense to have INET(6)_ANY as primary: */ + if (is_primary_addr) + return -EINVAL; + + if (peer->host_cnt >= ARRAY_SIZE(peer->host)) + return -EINVAL; + osmo_talloc_replace_string(talloc_ctx, &peer->host[peer->host_cnt], host); + peer->host_cnt++; + return 0; + } + + /* Makes no sense to add specific address to set if INET(6)_ANY + * is already set, be it from same or different IP version: */ + for (i = 0; i < peer->host_cnt; i++) { + bool iter_is_v6 = osmo_ip_str_type(peer->host[i]) == AF_INET6; + if (host_is_ip_anyaddr(peer->host[i], iter_is_v6)) + return -EINVAL; + } + /* Reached this point, no INET(6)_ANY address is set nor we are adding an INET(6)_ANY address. */ + + /* Check if address already exists, and then if primary flags need to be changed: */ + for (i = 0; i < peer->host_cnt; i++) { + struct osmo_sockaddr_str it_addr_str; + bool it_is_primary; + osmo_sockaddr_str_from_str(&it_addr_str, peer->host[i], 0); + + if (osmo_sockaddr_str_cmp(&addr_str, &it_addr_str) != 0) + continue; + it_is_primary = (peer->idx_primary == i); + if (is_primary_addr == it_is_primary) { + /* Nothing to do, return below */ + } else if (is_primary_addr && !it_is_primary) { + /* Mark it as primary: */ + peer->idx_primary = i; + } else { /* if (!is_primary_addr && it_is_primary) { */ + /* mark it as non-primary: */ + peer->idx_primary = -1; + } + return 0; + } + + if (peer->host_cnt >= ARRAY_SIZE(peer->host)) + return -EINVAL; + + osmo_talloc_replace_string(talloc_ctx, &peer->host[peer->host_cnt], host); + if (is_primary_addr) + peer->idx_primary = peer->host_cnt; + peer->host_cnt++; + return 0; +} + +/*! \brief Append (copy) address to a given ASP peer. Previous addresses are kept. + * \param[in] peer Application Server Process peer the address is appended to. + * \param[in] talloc_ctx talloc context used to allocate new address. + * \param[in] host string containing an IP address. + * \returns 0 on success; negative otherwise */ +int osmo_ss7_asp_peer_add_host(struct osmo_ss7_asp_peer *peer, void *talloc_ctx, + const char *host) +{ + return osmo_ss7_asp_peer_add_host2(peer, talloc_ctx, host, false); +} + +bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6) +{ + unsigned int i; + for (i = 0; i < peer->host_cnt; i++) { + bool iter_is_v6 = osmo_ip_str_type(peer->host[i]) == AF_INET6; + bool iter_is_anyaddr = host_is_ip_anyaddr(peer->host[i], iter_is_v6); + /* "::" (v6) covers "0.0.0.0" (v4), but not otherwise */ + if ((iter_is_v6 != host_is_v6) && !(iter_is_v6 && iter_is_anyaddr)) + continue; + if (iter_is_anyaddr || !strcmp(peer->host[i], host)) + return true; + } + return false; +} diff --git a/src/ss7_internal.h b/src/ss7_internal.h index 34378e8..d05b16e 100644 --- a/src/ss7_internal.h +++ b/src/ss7_internal.h @@ -21,6 +21,8 @@ int ss7_asp_apply_peer_primary_address(const struct osmo_ss7_asp *asp); int ss7_asp_apply_primary_address(const struct osmo_ss7_asp *asp); +bool ss7_asp_peer_match_host(const struct osmo_ss7_asp_peer *peer, const char *host, bool host_is_v6); + bool ss7_xua_server_set_default_local_hosts(struct osmo_xua_server *oxs); enum ss7_as_ctr { -- To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/34588?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmo-sccp Gerrit-Branch: master Gerrit-Change-Id: I4fe457dc0ee1e904e05423557cfba2505b315a75 Gerrit-Change-Number: 34588 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-MessageType: merged
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • ...
  • 185
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.