blob: 30a5a30f7b63f914604914973e6ff2542ac8ab51 [file] [log] [blame]
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +08001/*
2 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2010 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <openbsc/bsc_nat.h>
23#include <openbsc/gsm_data.h>
24#include <openbsc/bssap.h>
25#include <openbsc/debug.h>
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020026#include <openbsc/mgcp.h>
27#include <openbsc/mgcp_internal.h>
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +080028
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020029#include <osmocore/talloc.h>
Holger Hans Peter Freyther13959482010-06-15 18:50:57 +080030#include <osmocore/gsm0808.h>
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020031
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +080032#include <netinet/in.h>
33#include <arpa/inet.h>
34
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +020035#include <errno.h>
36#include <unistd.h>
37
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +080038int bsc_mgcp_assign(struct sccp_connections *con, struct msgb *msg)
39{
40 struct tlv_parsed tp;
41 u_int16_t cic;
42 u_int8_t timeslot;
43 u_int8_t multiplex;
44
45 if (!msg->l3h) {
46 LOGP(DNAT, LOGL_ERROR, "Assignment message should have l3h pointer.\n");
47 return -1;
48 }
49
50 if (msgb_l3len(msg) < 3) {
51 LOGP(DNAT, LOGL_ERROR, "Assignment message has not enough space for GSM0808.\n");
52 return -1;
53 }
54
55 tlv_parse(&tp, gsm0808_att_tlvdef(), msg->l3h + 3, msgb_l3len(msg) - 3, 0, 0);
56 if (!TLVP_PRESENT(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
57 LOGP(DNAT, LOGL_ERROR, "Circuit identity code not found in assignment message.\n");
58 return -1;
59 }
60
61 cic = ntohs(*(u_int16_t *)TLVP_VAL(&tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE));
62 timeslot = cic & 0x1f;
63 multiplex = (cic & ~0x1f) >> 5;
64
65 con->msc_timeslot = (32 * multiplex) + timeslot;
66 con->bsc_timeslot = con->msc_timeslot;
67 return 0;
68}
69
70void bsc_mgcp_clear(struct sccp_connections *con)
71{
72 con->msc_timeslot = -1;
73 con->bsc_timeslot = -1;
74}
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020075
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020076void bsc_mgcp_free_endpoint(struct bsc_nat *nat, int i)
77{
78 if (nat->bsc_endpoints[i].transaction_id) {
79 talloc_free(nat->bsc_endpoints[i].transaction_id);
80 nat->bsc_endpoints[i].transaction_id = NULL;
81 }
82
83 nat->bsc_endpoints[i].bsc = NULL;
84 mgcp_free_endp(&nat->mgcp_cfg->endpoints[i]);
85}
86
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020087void bsc_mgcp_free_endpoints(struct bsc_nat *nat)
88{
89 int i;
90
91 for (i = 1; i < nat->mgcp_cfg->number_endpoints; ++i)
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +020092 bsc_mgcp_free_endpoint(nat, i);
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +020093}
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +020094
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +020095struct bsc_connection *bsc_mgcp_find_con(struct bsc_nat *nat, int endpoint)
96{
97 struct sccp_connections *sccp;
98
99 llist_for_each_entry(sccp, &nat->sccp_connections, list_entry) {
100 if (sccp->msc_timeslot == -1)
101 continue;
102 if (mgcp_timeslot_to_endpoint(0, sccp->msc_timeslot) != endpoint)
103 continue;
104
105 return sccp->bsc;
106 }
107
108 LOGP(DMGCP, LOGL_ERROR, "Failed to find the connection.\n");
109 return NULL;
110}
111
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200112int bsc_mgcp_policy_cb(struct mgcp_config *cfg, int endpoint, int state, const char *transaction_id)
113{
114 struct bsc_nat *nat;
115 struct bsc_endpoint *bsc_endp;
116 struct bsc_connection *bsc_con;
117 struct mgcp_endpoint *mgcp_endp;
118 struct msgb *bsc_msg;
119
120 nat = cfg->data;
121 bsc_endp = &nat->bsc_endpoints[endpoint];
122 mgcp_endp = &nat->mgcp_cfg->endpoints[endpoint];
123
124 bsc_con = bsc_mgcp_find_con(nat, endpoint);
125
126 if (!bsc_con) {
127 LOGP(DMGCP, LOGL_ERROR, "Did not find BSC for a new connection on 0x%x for %d\n", endpoint, state);
128
129 switch (state) {
130 case MGCP_ENDP_CRCX:
131 return MGCP_POLICY_REJECT;
132 break;
133 case MGCP_ENDP_DLCX:
134 return MGCP_POLICY_CONT;
135 break;
136 case MGCP_ENDP_MDCX:
137 return MGCP_POLICY_CONT;
138 break;
139 default:
140 LOGP(DMGCP, LOGL_FATAL, "Unhandled state: %d\n", state);
141 return MGCP_POLICY_CONT;
142 break;
143 }
144 }
145
146 if (bsc_endp->transaction_id) {
147 LOGP(DMGCP, LOGL_ERROR, "One transaction with id '%s' on 0x%x\n",
148 bsc_endp->transaction_id, endpoint);
149 talloc_free(bsc_endp->transaction_id);
150 }
151
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200152 /* we need to generate a new and patched message */
153 bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length,
154 nat->mgcp_cfg->source_addr, mgcp_endp->rtp_port);
155 if (!bsc_msg) {
156 LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n");
157 return MGCP_POLICY_CONT;
158 }
159
160
Holger Hans Peter Freytherb3e0a032010-04-04 18:11:49 +0200161 bsc_endp->transaction_id = talloc_strdup(nat, transaction_id);
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200162 bsc_endp->bsc = bsc_con;
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200163 bsc_endp->pending_delete = 0;
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200164
165 /* we need to update some bits */
166 if (state == MGCP_ENDP_CRCX) {
167 struct sockaddr_in sock;
168 socklen_t len = sizeof(sock);
Holger Hans Peter Freyther2066b8c2010-04-06 11:17:56 +0200169 if (getpeername(bsc_con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len) != 0) {
Holger Hans Peter Freyther92febd32010-04-06 11:17:07 +0200170 LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n",
171 errno, strerror(errno));
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200172 } else {
173 mgcp_endp->bts = sock.sin_addr;
174 }
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200175 } else if (state == MGCP_ENDP_DLCX) {
176 /* we will free the endpoint now in case the BSS does not respond */
177 bsc_endp->pending_delete = 1;
178 mgcp_free_endp(mgcp_endp);
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200179 }
180
Holger Hans Peter Freyther2896df72010-04-08 10:24:57 +0200181 bsc_write(bsc_con, bsc_msg, NAT_IPAC_PROTO_MGCP);
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200182 return MGCP_POLICY_DEFER;
183}
184
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200185/*
186 * We have received a msg from the BSC. We will see if we know
187 * this transaction and if it belongs to the BSC. Then we will
188 * need to patch the content to point to the local network and we
189 * need to update the I: that was assigned by the BSS.
190 */
191void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
192{
193 struct msgb *output;
194 struct bsc_endpoint *bsc_endp = NULL;
195 struct mgcp_endpoint *endp = NULL;
Holger Hans Peter Freytherd2dd6e82010-04-06 11:06:11 +0200196 int i, code;
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200197 char transaction_id[60];
198
199 /* Some assumption that our buffer is big enough.. and null terminate */
200 if (msgb_l2len(msg) > 2000) {
201 LOGP(DMGCP, LOGL_ERROR, "MGCP message too long.\n");
202 return;
203 }
204
205 msg->l2h[msgb_l2len(msg)] = '\0';
206
207 if (bsc_mgcp_parse_response((const char *) msg->l2h, &code, transaction_id) != 0) {
208 LOGP(DMGCP, LOGL_ERROR, "Failed to parse response code.\n");
209 return;
210 }
211
212 for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
213 if (bsc->nat->bsc_endpoints[i].bsc != bsc)
214 continue;
Holger Hans Peter Freyther3f7c7d02010-04-05 18:00:05 +0200215 /* no one listening? a bug? */
216 if (!bsc->nat->bsc_endpoints[i].transaction_id)
217 continue;
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200218 if (strcmp(transaction_id, bsc->nat->bsc_endpoints[i].transaction_id) != 0)
219 continue;
220
221 endp = &bsc->nat->mgcp_cfg->endpoints[i];
222 bsc_endp = &bsc->nat->bsc_endpoints[i];
223 break;
224 }
225
226 if (!bsc_endp) {
Holger Hans Peter Freytherb9ac37d2010-04-05 17:58:52 +0200227 LOGP(DMGCP, LOGL_ERROR, "Could not find active endpoint: %s for msg: '%s'\n",
228 transaction_id, (const char *) msg->l2h);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200229 return;
230 }
231
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200232 /* make it point to our endpoint if it was not deleted */
233 if (bsc_endp->pending_delete) {
234 bsc_endp->bsc = NULL;
235 bsc_endp->pending_delete = 0;
236 } else {
237 endp->ci = bsc_mgcp_extract_ci((const char *) msg->l2h);
238 }
239
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200240 /* free some stuff */
241 talloc_free(bsc_endp->transaction_id);
242 bsc_endp->transaction_id = NULL;
243
Holger Hans Peter Freytherdd16b422010-04-07 09:53:54 +0200244 /*
245 * rewrite the information. In case the endpoint was deleted
246 * there should be nothing for us to rewrite so putting endp->rtp_port
247 * with the value of 0 should be no problem.
248 */
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200249 output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg),
250 bsc->nat->mgcp_cfg->source_addr, endp->rtp_port);
Holger Hans Peter Freyther5cc94fb2010-04-05 22:56:49 +0200251
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200252 if (!output) {
253 LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n");
254 return;
255 }
256
257 if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) {
258 LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n");
259 msgb_free(output);
260 }
261}
262
263int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60])
264{
265 /* we want to parse two strings */
266 return sscanf(str, "%3d %59s\n", code, transaction) != 2;
267}
268
269int bsc_mgcp_extract_ci(const char *str)
270{
271 int ci;
272 char *res = strstr(str, "I: ");
273 if (!res)
274 return CI_UNUSED;
275
Holger Hans Peter Freyther806aca92010-04-05 09:07:39 +0200276 if (sscanf(res, "I: %d", &ci) != 1)
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200277 return CI_UNUSED;
278 return ci;
279}
280
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200281/* we need to replace some strings... */
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200282struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port)
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200283{
284 static const char *ip_str = "c=IN IP4 ";
285 static const char *aud_str = "m=audio ";
286
287 char buf[128];
288 char *running, *token;
289 struct msgb *output;
290
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200291 if (length > 4096 - 128) {
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200292 LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n");
293 return NULL;
294 }
295
296 output = msgb_alloc_headroom(4096, 128, "MGCP rewritten");
297 if (!output) {
298 LOGP(DMGCP, LOGL_ERROR, "Failed to allocate new MGCP msg.\n");
299 return NULL;
300 }
301
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200302 running = input;
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200303 output->l2h = output->data;
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200304 for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) {
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200305 int len = strlen(token);
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200306 int cr = len > 0 && token[len - 1] == '\r';
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200307
308 if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) {
309 output->l3h = msgb_put(output, strlen(ip_str));
310 memcpy(output->l3h, ip_str, strlen(ip_str));
311 output->l3h = msgb_put(output, strlen(ip));
312 memcpy(output->l3h, ip, strlen(ip));
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200313
314 if (cr) {
315 output->l3h = msgb_put(output, 2);
316 output->l3h[0] = '\r';
317 output->l3h[1] = '\n';
318 } else {
319 output->l3h = msgb_put(output, 1);
320 output->l3h[0] = '\n';
321 }
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200322 } else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) {
323 int payload;
324 if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) {
325 LOGP(DMGCP, LOGL_ERROR, "Could not parsed audio line.\n");
326 msgb_free(output);
327 return NULL;
328 }
329
Holger Hans Peter Freyther9e5300a2010-04-04 19:34:44 +0200330 snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s",
331 port, payload, cr ? "\r\n" : "\n");
Holger Hans Peter Freyther76c83542010-04-01 06:48:52 +0200332 buf[sizeof(buf)-1] = '\0';
333
334 output->l3h = msgb_put(output, strlen(buf));
335 memcpy(output->l3h, buf, strlen(buf));
336 } else {
337 output->l3h = msgb_put(output, len + 1);
338 memcpy(output->l3h, token, len);
339 output->l3h[len] = '\n';
340 }
341 }
342
343 return output;
344}
345
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200346static int mgcp_do_read(struct bsc_fd *fd)
347{
348 struct bsc_nat *nat;
349 struct msgb *msg, *resp;
350 int rc;
351
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200352 nat = fd->data;
353
354 rc = read(fd->fd, nat->mgcp_msg, sizeof(nat->mgcp_msg) - 1);
355 if (rc <= 0) {
356 LOGP(DMGCP, LOGL_ERROR, "Failed to read errno: %d\n", errno);
357 return -1;
358 }
359
360 nat->mgcp_msg[rc] = '\0';
361 nat->mgcp_length = rc;
362
363 msg = msgb_alloc(sizeof(nat->mgcp_msg), "MGCP GW Read");
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200364 if (!msg) {
365 LOGP(DMGCP, LOGL_ERROR, "Failed to create buffer.\n");
366 return -1;
367 }
368
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200369 msg->l2h = msgb_put(msg, rc);
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200370 memcpy(msg->l2h, nat->mgcp_msg, msgb_l2len(msg));
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200371 resp = mgcp_handle_message(nat->mgcp_cfg, msg);
372 msgb_free(msg);
373
374 /* we do have a direct answer... e.g. AUEP */
375 if (resp) {
376 if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) {
377 LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n");
378 msgb_free(resp);
379 }
380 }
381
382 return 0;
383}
384
385static int mgcp_do_write(struct bsc_fd *bfd, struct msgb *msg)
386{
387 int rc;
388
389 rc = write(bfd->fd, msg->data, msg->len);
390
391 if (rc != msg->len) {
392 LOGP(DMGCP, LOGL_ERROR, "Failed to write msg to MGCP CallAgent.\n");
393 return -1;
394 }
395
396 return rc;
397}
398
399int bsc_mgcp_init(struct bsc_nat *nat)
400{
401 int on;
402 struct sockaddr_in addr;
403
404 if (!nat->mgcp_cfg->call_agent_addr) {
405 LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n");
406 return -1;
407 }
408
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200409 if (nat->mgcp_cfg->bts_ip) {
410 LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n");
411 return -1;
412 }
413
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200414 nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0);
415 if (nat->mgcp_queue.bfd.fd < 0) {
416 LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno);
417 return -1;
418 }
419
420 on = 1;
421 setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
422
423 addr.sin_family = AF_INET;
424 addr.sin_port = htons(nat->mgcp_cfg->source_port);
425 inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr);
426
427 if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
428 LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno);
429 close(nat->mgcp_queue.bfd.fd);
430 nat->mgcp_queue.bfd.fd = -1;
431 return -1;
432 }
433
434 addr.sin_port = htons(2727);
435 inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr);
436 if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
437 LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
438 nat->mgcp_cfg->call_agent_addr, errno);
439 close(nat->mgcp_queue.bfd.fd);
440 nat->mgcp_queue.bfd.fd = -1;
441 return -1;
442 }
443
444 write_queue_init(&nat->mgcp_queue, 10);
445 nat->mgcp_queue.bfd.when = BSC_FD_READ;
446 nat->mgcp_queue.bfd.data = nat;
447 nat->mgcp_queue.read_cb = mgcp_do_read;
448 nat->mgcp_queue.write_cb = mgcp_do_write;
449
450 if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) {
451 LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n");
452 close(nat->mgcp_queue.bfd.fd);
453 nat->mgcp_queue.bfd.fd = -1;
454 return -1;
455 }
456
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200457 /* some more MGCP config handling */
Holger Hans Peter Freyther4ad58502010-04-06 11:14:03 +0200458 nat->mgcp_cfg->audio_payload = -1;
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200459 nat->mgcp_cfg->data = nat;
460 nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb;
Holger Hans Peter Freytherbba59342010-04-07 10:52:48 +0200461 nat->mgcp_cfg->force_realloc = 1;
Holger Hans Peter Freyther290d84e2010-04-09 18:51:01 +0200462 nat->mgcp_cfg->bts_ip = "";
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200463 nat->bsc_endpoints = talloc_zero_array(nat,
464 struct bsc_endpoint,
465 nat->mgcp_cfg->number_endpoints + 1);
466
Holger Hans Peter Freythera7f80182010-03-31 13:02:22 +0200467 return 0;
468}
Holger Hans Peter Freyther26a43892010-04-05 23:09:27 +0200469
470void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc)
471{
472 int i;
473 for (i = 1; i < bsc->nat->mgcp_cfg->number_endpoints; ++i) {
474 struct bsc_endpoint *bsc_endp = &bsc->nat->bsc_endpoints[i];
475
476 if (bsc_endp->bsc != bsc)
477 continue;
478
479 bsc_endp->bsc = NULL;
480 bsc_endp->pending_delete = 0;
481 if (bsc_endp->transaction_id)
482 talloc_free(bsc_endp->transaction_id);
483 bsc_endp->transaction_id = NULL;
484 mgcp_free_endp(&bsc->nat->mgcp_cfg->endpoints[i]);
485 }
486}