Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SAT>IP server: accept RTSP requests from the external IP (NAT)
  • Loading branch information
perexg committed Nov 30, 2015
1 parent 00eff4b commit ec45cf3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/satip/rtsp.c
Expand Up @@ -71,6 +71,7 @@ typedef struct session {
static uint32_t session_number;
static uint16_t stream_id;
static char *rtsp_ip = NULL;
static char *rtsp_nat_ip = NULL;
static int rtsp_port = -1;
static int rtsp_descramble = 1;
static int rtsp_rewrite_pmt = 0;
Expand Down Expand Up @@ -248,7 +249,8 @@ rtsp_check_urlbase(char *u)
#endif
}
if (strcmp(u, rtsp_ip))
return NULL;
if (rtsp_nat_ip == NULL || rtsp_nat_ip[0] == '\0' || strcmp(u, rtsp_nat_ip))
return NULL;
return p ? p + 1 : u + strlen(u);
}

Expand Down Expand Up @@ -1562,7 +1564,8 @@ rtsp_close_sessions(void)
*
*/
void satip_server_rtsp_init
(const char *bindaddr, int port, int descramble, int rewrite_pmt, int muxcnf)
(const char *bindaddr, int port, int descramble, int rewrite_pmt, int muxcnf,
const char *nat_ip)
{
static tcp_server_ops_t ops = {
.start = rtsp_serve,
Expand All @@ -1571,6 +1574,7 @@ void satip_server_rtsp_init
};
int reg = 0;
uint8_t rnd[4];
char *s;
if (!rtsp_server) {
uuid_random(rnd, sizeof(rnd));
session_number = *(uint32_t *)rnd;
Expand All @@ -1584,12 +1588,16 @@ void satip_server_rtsp_init
rtsp_server = NULL;
reg = 1;
}
free(rtsp_ip);
rtsp_ip = strdup(bindaddr);
if ((s = rtsp_ip) != NULL)
rtsp_ip = strdup(bindaddr);
free(s);
rtsp_port = port;
rtsp_descramble = descramble;
rtsp_rewrite_pmt = rewrite_pmt;
rtsp_muxcnf = muxcnf;
if ((s = rtsp_nat_ip) != NULL)
rtsp_nat_ip = nat_ip ? strdup(nat_ip) : NULL;
free(s);
if (!rtsp_server)
rtsp_server = tcp_server_create(bindaddr, port, &ops, NULL);
if (reg)
Expand All @@ -1613,6 +1621,7 @@ void satip_server_rtsp_done(void)
rtsp_server = NULL;
rtsp_port = -1;
free(rtsp_ip);
free(rtsp_nat_ip);
rtsp_ip = NULL;
satip_rtp_done();
pthread_mutex_unlock(&global_lock);
Expand Down
16 changes: 14 additions & 2 deletions src/satip/server.c
Expand Up @@ -625,6 +625,13 @@ const idclass_t satip_server_class = {
.list = satip_server_class_muxcfg_list,
.group = 1,
},
{
.type = PT_STR,
.id = "satip_nat_ip",
.name = N_("External IP (NAT)"),
.off = offsetof(struct satip_server_conf, satip_nat_ip),
.group = 1,
},
{
.type = PT_INT,
.id = "satip_dvbs",
Expand Down Expand Up @@ -691,6 +698,7 @@ const idclass_t satip_server_class = {
static void satip_server_save(void)
{
int descramble, rewrite_pmt, muxcnf;
char *nat_ip;

config_save();
if (!satip_server_rtsp_port_locked) {
Expand All @@ -699,11 +707,13 @@ static void satip_server_save(void)
descramble = satip_server_conf.satip_descramble;
rewrite_pmt = satip_server_conf.satip_rewrite_pmt;
muxcnf = satip_server_conf.satip_muxcnf;
nat_ip = satip_server_conf.satip_nat_ip ? strdup(satip_server_conf.satip_nat_ip) : NULL;
pthread_mutex_unlock(&global_lock);
satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf);
satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, nat_ip);
satip_server_info("re", descramble, muxcnf);
satips_upnp_send_announce();
pthread_mutex_lock(&global_lock);
free(nat_ip);
} else {
pthread_mutex_unlock(&global_lock);
tvhinfo("satips", "SAT>IP Server shutdown");
Expand All @@ -723,6 +733,7 @@ void satip_server_init(int rtsp_port)
struct sockaddr_storage http;
char http_ip[128];
int descramble, rewrite_pmt, muxcnf;
char *nat_ip;

http_server_ip = NULL;
satip_server_bootid = time(NULL);
Expand All @@ -746,8 +757,9 @@ void satip_server_init(int rtsp_port)
descramble = satip_server_conf.satip_descramble;
rewrite_pmt = satip_server_conf.satip_rewrite_pmt;
muxcnf = satip_server_conf.satip_muxcnf;
nat_ip = satip_server_conf.satip_nat_ip;

satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf);
satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, nat_ip);

satip_server_info("", descramble, muxcnf);
}
Expand Down
4 changes: 3 additions & 1 deletion src/satip/server.h
Expand Up @@ -50,6 +50,7 @@ struct satip_server_conf {
int satip_dvbc2;
int satip_atsc;
int satip_dvbcb;
char *satip_nat_ip;
};

extern struct satip_server_conf satip_server_conf;
Expand Down Expand Up @@ -78,7 +79,8 @@ void satip_rtp_init(int boot);
void satip_rtp_done(void);

void satip_server_rtsp_init(const char *bindaddr, int port,
int descramble, int rewrite_pmt, int muxcnf);
int descramble, int rewrite_pmt, int muxcnf,
const char *nat_ip);
void satip_server_rtsp_register(void);
void satip_server_rtsp_done(void);

Expand Down

0 comments on commit ec45cf3

Please sign in to comment.