mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
Make RTP ports configurable
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1026 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -1,3 +1,4 @@
|
|||||||
|
-- Make RTP ports configurable
|
||||||
-- Add RDNIS support to SIP and IAX2
|
-- Add RDNIS support to SIP and IAX2
|
||||||
-- Add transfer app (implement in SIP and IAX2)
|
-- Add transfer app (implement in SIP and IAX2)
|
||||||
-- Make voicemail segmentable by context (app_voicemail2)
|
-- Make voicemail segmentable by context (app_voicemail2)
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <asterisk/manager.h>
|
#include <asterisk/manager.h>
|
||||||
#include <asterisk/pbx.h>
|
#include <asterisk/pbx.h>
|
||||||
#include <asterisk/enum.h>
|
#include <asterisk/enum.h>
|
||||||
|
#include <asterisk/rtp.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -1317,6 +1318,7 @@ int main(int argc, char *argv[])
|
|||||||
printf(term_quit());
|
printf(term_quit());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
ast_rtp_init();
|
||||||
if (ast_image_init()) {
|
if (ast_image_init()) {
|
||||||
printf(term_quit());
|
printf(term_quit());
|
||||||
exit(1);
|
exit(1);
|
||||||
|
9
configs/rtp.conf.sample
Executable file
9
configs/rtp.conf.sample
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
;
|
||||||
|
; RTP Configuration
|
||||||
|
;
|
||||||
|
[general]
|
||||||
|
;
|
||||||
|
; RTP start and RTP end configure start and end addresses
|
||||||
|
;
|
||||||
|
rtpstart=10000
|
||||||
|
rtpend=20000
|
@@ -99,6 +99,10 @@ void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
|
|||||||
|
|
||||||
void ast_rtp_stop(struct ast_rtp *rtp);
|
void ast_rtp_stop(struct ast_rtp *rtp);
|
||||||
|
|
||||||
|
void ast_rtp_init(void);
|
||||||
|
|
||||||
|
void ast_rtp_reload(void);
|
||||||
|
|
||||||
#if defined(__cplusplus) || defined(c_plusplus)
|
#if defined(__cplusplus) || defined(c_plusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
2
loader.c
2
loader.c
@@ -24,6 +24,7 @@
|
|||||||
#include <asterisk/term.h>
|
#include <asterisk/term.h>
|
||||||
#include <asterisk/manager.h>
|
#include <asterisk/manager.h>
|
||||||
#include <asterisk/enum.h>
|
#include <asterisk/enum.h>
|
||||||
|
#include <asterisk/rtp.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <asterisk/md5.h>
|
#include <asterisk/md5.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -146,6 +147,7 @@ void ast_module_reload(void)
|
|||||||
/* We'll do the logger and manager the favor of calling its reload here first */
|
/* We'll do the logger and manager the favor of calling its reload here first */
|
||||||
reload_manager();
|
reload_manager();
|
||||||
ast_enum_reload();
|
ast_enum_reload();
|
||||||
|
ast_rtp_reload();
|
||||||
time(&ast_lastreloadtime);
|
time(&ast_lastreloadtime);
|
||||||
|
|
||||||
ast_pthread_mutex_lock(&modlock);
|
ast_pthread_mutex_lock(&modlock);
|
||||||
|
59
rtp.c
59
rtp.c
@@ -32,6 +32,7 @@
|
|||||||
#include <asterisk/channel.h>
|
#include <asterisk/channel.h>
|
||||||
#include <asterisk/acl.h>
|
#include <asterisk/acl.h>
|
||||||
#include <asterisk/channel_pvt.h>
|
#include <asterisk/channel_pvt.h>
|
||||||
|
#include <asterisk/config.h>
|
||||||
|
|
||||||
#define TYPE_HIGH 0x0
|
#define TYPE_HIGH 0x0
|
||||||
#define TYPE_LOW 0x1
|
#define TYPE_LOW 0x1
|
||||||
@@ -41,6 +42,9 @@
|
|||||||
|
|
||||||
static int dtmftimeout = 300; /* 300 samples */
|
static int dtmftimeout = 300; /* 300 samples */
|
||||||
|
|
||||||
|
static int rtpstart = 0;
|
||||||
|
static int rtpend = 0;
|
||||||
|
|
||||||
// The value of each payload format mapping:
|
// The value of each payload format mapping:
|
||||||
struct rtpPayloadType {
|
struct rtpPayloadType {
|
||||||
int isAstFormat; // whether the following code is an AST_FORMAT
|
int isAstFormat; // whether the following code is an AST_FORMAT
|
||||||
@@ -567,6 +571,7 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io)
|
|||||||
struct ast_rtp *rtp;
|
struct ast_rtp *rtp;
|
||||||
int x;
|
int x;
|
||||||
int flags;
|
int flags;
|
||||||
|
int startplace;
|
||||||
rtp = malloc(sizeof(struct ast_rtp));
|
rtp = malloc(sizeof(struct ast_rtp));
|
||||||
if (!rtp)
|
if (!rtp)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -583,11 +588,12 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io)
|
|||||||
}
|
}
|
||||||
flags = fcntl(rtp->s, F_GETFL);
|
flags = fcntl(rtp->s, F_GETFL);
|
||||||
fcntl(rtp->s, F_SETFL, flags | O_NONBLOCK);
|
fcntl(rtp->s, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
/* Find us a place */
|
||||||
|
x = (rand() % (rtpend-rtpstart)) + rtpstart;
|
||||||
|
x = x & ~1;
|
||||||
|
startplace = x;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Find us a place */
|
|
||||||
x = (rand() % (65000-1025)) + 1025;
|
|
||||||
/* Must be an even port number by RTP spec */
|
/* Must be an even port number by RTP spec */
|
||||||
x = x & ~1;
|
|
||||||
rtp->us.sin_port = htons(x);
|
rtp->us.sin_port = htons(x);
|
||||||
if (!bind(rtp->s, &rtp->us, sizeof(rtp->us)))
|
if (!bind(rtp->s, &rtp->us, sizeof(rtp->us)))
|
||||||
break;
|
break;
|
||||||
@@ -597,6 +603,15 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io)
|
|||||||
free(rtp);
|
free(rtp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
x += 2;
|
||||||
|
if (x > rtpend)
|
||||||
|
x = (rtpstart + 1) & ~1;
|
||||||
|
if (x == startplace) {
|
||||||
|
ast_log(LOG_WARNING, "No RTP ports remaining\n");
|
||||||
|
close(rtp->s);
|
||||||
|
free(rtp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (io && sched) {
|
if (io && sched) {
|
||||||
/* Operate this one in a callback mode */
|
/* Operate this one in a callback mode */
|
||||||
@@ -1081,3 +1096,41 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ast_rtp_reload(void)
|
||||||
|
{
|
||||||
|
struct ast_config *cfg;
|
||||||
|
char *s;
|
||||||
|
rtpstart = 5000;
|
||||||
|
rtpend = 31000;
|
||||||
|
cfg = ast_load("rtp.conf");
|
||||||
|
if (cfg) {
|
||||||
|
if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) {
|
||||||
|
rtpstart = atoi(s);
|
||||||
|
if (rtpstart < 1024)
|
||||||
|
rtpstart = 1024;
|
||||||
|
if (rtpstart > 65535)
|
||||||
|
rtpstart = 65535;
|
||||||
|
}
|
||||||
|
if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) {
|
||||||
|
rtpend = atoi(s);
|
||||||
|
if (rtpend < 1024)
|
||||||
|
rtpend = 1024;
|
||||||
|
if (rtpend > 65535)
|
||||||
|
rtpend = 65535;
|
||||||
|
}
|
||||||
|
ast_destroy(cfg);
|
||||||
|
}
|
||||||
|
if (rtpstart >= rtpend) {
|
||||||
|
ast_log(LOG_WARNING, "Unreasonable values for RTP start/end\n");
|
||||||
|
rtpstart = 5000;
|
||||||
|
rtpend = 31000;
|
||||||
|
}
|
||||||
|
if (option_verbose > 1)
|
||||||
|
ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_rtp_init(void)
|
||||||
|
{
|
||||||
|
ast_rtp_reload();
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user