1 /*
2     Copyright (C) 2004-2008  Thomas Ries <tries@gmx.net>
3 
4     This file is part of Siproxd.
5 
6     Siproxd 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     Siproxd 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
17     along with Siproxd; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 
21 #include <sys/types.h>
22 #include <netinet/in.h>
23 #include <osipparser2/osip_parser.h>
24 #include "siproxd.h"
25 #include "fwapi.h"
26 #include "log.h"
27 
28 static char const ident[]="$Id: fwapi.c 369 2008-01-19 16:07:14Z hb9xar $";
29 
fwapi_start_rtp(int rtp_direction,struct in_addr local_ipaddr,int local_port,struct in_addr remote_ipaddr,int remote_port)30 int fwapi_start_rtp(int rtp_direction,
31                     struct in_addr local_ipaddr, int local_port,
32                     struct in_addr remote_ipaddr, int remote_port) {
33 #ifdef CUSTOM_FWMODULE
34    int sts;
35    fw_ctl_t fwdata;
36    fwdata.action    = ACT_START_RTP;
37    fwdata.direction = (rtp_direction == DIR_INCOMING)? DIR_IN: DIR_OUT;
38    memcpy(&fwdata.local_ipaddr, &local_ipaddr, sizeof(fwdata.local_ipaddr));
39    fwdata.local_port = local_port;
40    memcpy(&fwdata.remote_ipaddr, &remote_ipaddr, sizeof(fwdata.remote_ipaddr));
41    fwdata.remote_port = remote_port;
42 
43    sts=custom_fw_control(fwdata);
44    if (sts != STS_SUCCESS) {
45       ERROR("Custom firewall module returned error [START, sts=%i]",sts);
46    }
47 #endif
48    return STS_SUCCESS;
49 }
50 
fwapi_stop_rtp(int rtp_direction,struct in_addr local_ipaddr,int local_port,struct in_addr remote_ipaddr,int remote_port)51 int fwapi_stop_rtp(int rtp_direction,
52                    struct in_addr local_ipaddr, int local_port,
53                    struct in_addr remote_ipaddr, int remote_port) {
54 #ifdef CUSTOM_FWMODULE
55    int sts;
56    fw_ctl_t fwdata;
57    fwdata.action    = ACT_STOP_RTP;
58    fwdata.direction = (rtp_direction == DIR_INCOMING)? DIR_IN: DIR_OUT;
59    memcpy(&fwdata.local_ipaddr, &local_ipaddr, sizeof(fwdata.local_ipaddr));
60    fwdata.local_port = local_port;
61    memcpy(&fwdata.remote_ipaddr, &remote_ipaddr, sizeof(fwdata.remote_ipaddr));
62    fwdata.remote_port = remote_port;
63 
64    sts=custom_fw_control(fwdata);
65    if (sts != STS_SUCCESS) {
66       ERROR("Custom firewall module returned error [STOP, sts=%i]",sts);
67    }
68 #endif
69    return STS_SUCCESS;
70 }
71