Newer
Older
Matthew Fredrickson
committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
ast_mutex_unlock(&c0->lock);
usleep(1);
ast_mutex_lock(&c0->lock);
}
pr0 = get_proto(c0);
pr1 = get_proto(c1);
if (!pr0) {
ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
return -1;
}
if (!pr1) {
ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
return -1;
}
pvt0 = c0->tech_pvt;
pvt1 = c1->tech_pvt;
p0 = pr0->get_udptl_info(c0);
p1 = pr1->get_udptl_info(c1);
if (!p0 || !p1) {
/* Somebody doesn't want to play... */
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
return -2;
}
if (pr0->set_udptl_peer(c0, p1)) {
ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
} else {
/* Store UDPTL peer */
ast_udptl_get_peer(p1, &ac1);
}
if (pr1->set_udptl_peer(c1, p0))
ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
else {
/* Store UDPTL peer */
ast_udptl_get_peer(p0, &ac0);
}
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
cs[0] = c0;
cs[1] = c1;
cs[2] = NULL;
for (;;) {
if ((c0->tech_pvt != pvt0) ||
(c1->tech_pvt != pvt1) ||
(c0->masq || c0->masqr || c1->masq || c1->masqr)) {
ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
/* Tell it to try again later */
return -3;
}
to = -1;
ast_udptl_get_peer(p1, &t1);
ast_udptl_get_peer(p0, &t0);
if (inaddrcmp(&t1, &ac1)) {
ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d\n",
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t1.sin_addr), ntohs(t1.sin_port));
ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d\n",
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac1.sin_addr), ntohs(ac1.sin_port));
memcpy(&ac1, &t1, sizeof(ac1));
}
if (inaddrcmp(&t0, &ac0)) {
ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d\n",
c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t0.sin_addr), ntohs(t0.sin_port));
ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d\n",
c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac0.sin_addr), ntohs(ac0.sin_port));
memcpy(&ac0, &t0, sizeof(ac0));
}
who = ast_waitfor_n(cs, 2, &to);
if (!who) {
ast_log(LOG_DEBUG, "Ooh, empty read...\n");
/* check for hangup / whentohangup */
if (ast_check_hangup(c0) || ast_check_hangup(c1))
break;
continue;
}
f = ast_read(who);
if (!f) {
*fo = f;
*rc = who;
ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
/* That's all we needed */
return 0;
} else {
if (f->frametype == AST_FRAME_MODEM) {
/* Forward T.38 frames if they happen upon us */
if (who == c0) {
ast_write(c1, f);
} else if (who == c1) {
ast_write(c0, f);
}
}
ast_frfree(f);
}
/* Swap priority. Not that it's a big deal at this point */
cs[2] = cs[0];
cs[0] = cs[1];
cs[1] = cs[2];
}
return -1;
}
static int udptl_do_debug_ip(int fd, int argc, char *argv[])
{
struct hostent *hp;
struct ast_hostent ahp;
char iabuf[INET_ADDRSTRLEN];
int port;
char *p;
char *arg;
port = 0;
if (argc != 4)
return RESULT_SHOWUSAGE;
arg = argv[3];
p = strstr(arg, ":");
if (p) {
*p = '\0';
p++;
port = atoi(p);
}
hp = ast_gethostbyname(arg, &ahp);
if (hp == NULL)
return RESULT_SHOWUSAGE;
udptldebugaddr.sin_family = AF_INET;
memcpy(&udptldebugaddr.sin_addr, hp->h_addr, sizeof(udptldebugaddr.sin_addr));
udptldebugaddr.sin_port = htons(port);
if (port == 0)
ast_cli(fd, "UDPTL Debugging Enabled for IP: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), udptldebugaddr.sin_addr));
else
ast_cli(fd, "UDPTL Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), udptldebugaddr.sin_addr), port);
udptldebug = 1;
return RESULT_SUCCESS;
}
static int udptl_do_debug(int fd, int argc, char *argv[])
{
if (argc != 2) {
if (argc != 4)
return RESULT_SHOWUSAGE;
return udptl_do_debug_ip(fd, argc, argv);
}
udptldebug = 1;
memset(&udptldebugaddr,0,sizeof(udptldebugaddr));
ast_cli(fd, "UDPTL Debugging Enabled\n");
return RESULT_SUCCESS;
}
static int udptl_no_debug(int fd, int argc, char *argv[])
{
if (argc !=3)
return RESULT_SHOWUSAGE;
udptldebug = 0;
ast_cli(fd,"UDPTL Debugging Disabled\n");
return RESULT_SUCCESS;
}
static char debug_usage[] =
"Usage: udptl debug [ip host[:port]]\n"
" Enable dumping of all UDPTL packets to and from host.\n";
static char no_debug_usage[] =
"Usage: udptl no debug\n"
" Disable all UDPTL debugging\n";
static struct ast_cli_entry cli_debug_ip =
{{ "udptl", "debug", "ip", NULL } , udptl_do_debug, "Enable UDPTL debugging on IP", debug_usage };
static struct ast_cli_entry cli_debug =
{{ "udptl", "debug", NULL } , udptl_do_debug, "Enable UDPTL debugging", debug_usage };
static struct ast_cli_entry cli_no_debug =
{{ "udptl", "no", "debug", NULL } , udptl_no_debug, "Disable UDPTL debugging", no_debug_usage };
void ast_udptl_reload(void)
{
struct ast_config *cfg;
char *s;
udptlstart = 4500;
udptlend = 4999;
udptlfectype = 0;
udptlfecentries = 0;
udptlfecspan = 0;
udptlmaxdatagram = 0;
if ((cfg = ast_config_load("udptl.conf"))) {
if ((s = ast_variable_retrieve(cfg, "general", "udptlstart"))) {
udptlstart = atoi(s);
if (udptlstart < 1024)
udptlstart = 1024;
if (udptlstart > 65535)
udptlstart = 65535;
}
if ((s = ast_variable_retrieve(cfg, "general", "udptlend"))) {
udptlend = atoi(s);
if (udptlend < 1024)
udptlend = 1024;
if (udptlend > 65535)
udptlend = 65535;
}
if ((s = ast_variable_retrieve(cfg, "general", "udptlchecksums"))) {
#ifdef SO_NO_CHECK
if (ast_false(s))
nochecksums = 1;
else
nochecksums = 0;
#else
if (ast_false(s))
ast_log(LOG_WARNING, "Disabling UDPTL checksums is not supported on this operating system!\n");
#endif
}
if ((s = ast_variable_retrieve(cfg, "general", "T38FaxUdpEC"))) {
if (strcmp(s, "t38UDPFEC") == 0)
udptlfectype = 2;
else if (strcmp(s, "t38UDPRedundancy") == 0)
udptlfectype = 1;
}
if ((s = ast_variable_retrieve(cfg, "general", "T38FaxMaxDatagram"))) {
udptlmaxdatagram = atoi(s);
if (udptlmaxdatagram < 0)
udptlmaxdatagram = 0;
if (udptlmaxdatagram > LOCAL_FAX_MAX_DATAGRAM)
udptlmaxdatagram = LOCAL_FAX_MAX_DATAGRAM;
}
if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECentries"))) {
udptlfecentries = atoi(s);
if (udptlfecentries < 0)
udptlfecentries = 0;
if (udptlfecentries > MAX_FEC_ENTRIES)
udptlfecentries = MAX_FEC_ENTRIES;
}
if ((s = ast_variable_retrieve(cfg, "general", "UDPTLFECspan"))) {
udptlfecspan = atoi(s);
if (udptlfecspan < 0)
udptlfecspan = 0;
if (udptlfecspan > MAX_FEC_SPAN)
udptlfecspan = MAX_FEC_SPAN;
}
ast_config_destroy(cfg);
}
if (udptlstart >= udptlend) {
ast_log(LOG_WARNING, "Unreasonable values for UDPTL start/end\n");
udptlstart = 4500;
udptlend = 4999;
}
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "UDPTL allocating from port range %d -> %d\n", udptlstart, udptlend);
}
void ast_udptl_init(void)
{
ast_cli_register(&cli_debug);
ast_cli_register(&cli_debug_ip);
ast_cli_register(&cli_no_debug);
ast_udptl_reload();
}