- working on running siproxd in front of a routing device
and NOT on the firewall itself.
This commit is contained in:
parent
ce32ec0e74
commit
0984731872
@ -1,6 +1,8 @@
|
||||
0.5.11
|
||||
======
|
||||
19-Feb-2005: - more work an new libosip API
|
||||
1-Mar-2005: - working on running siproxd in front of a routing device
|
||||
and NOT on the firewall itself.
|
||||
19-Feb-2005: - more work on new libosip API
|
||||
13-Feb-2005: - made compile with libosip2-2.2.0 (change of libosip2 API)
|
||||
|
||||
0.5.10
|
||||
|
||||
@ -9,9 +9,19 @@
|
||||
######################################################################
|
||||
# The interface names of INBOUND and OUTBOUND interface.
|
||||
#
|
||||
# If siproxd is not running on the host doing the masquerading
|
||||
# but on a host within the private network segment, "in front" of
|
||||
# the masquerading router: define if_inbound and if_outbound to
|
||||
# point to the same interface (the inbound interface). In *addition*
|
||||
# define 'host_outbound' to hold your external (public) IP address
|
||||
# or a hostname that resolves to that address (use a dyndns address for
|
||||
# example).
|
||||
#
|
||||
if_inbound = eth0
|
||||
if_outbound = ppp0
|
||||
|
||||
# uncomment the following line ONLY IF YOU KNOW WHAT YOU ARE DOING!
|
||||
# READ THE FAQ FIRST!
|
||||
#host_outbound = 1.2.3.4
|
||||
|
||||
######################################################################
|
||||
# Access control.
|
||||
|
||||
35
src/proxy.c
35
src/proxy.c
@ -1004,22 +1004,16 @@ if (configuration.debuglevel)
|
||||
*/
|
||||
|
||||
/* get outbound address */
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &outside_addr) !=
|
||||
STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
if (get_interface_ip(IF_OUTBOUND, &outside_addr) != STS_SUCCESS) {
|
||||
sdp_message_free(sdp);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
/* get inbound address */
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &inside_addr) !=
|
||||
STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
if (get_interface_ip(IF_INBOUND, &inside_addr) != STS_SUCCESS) {
|
||||
sdp_message_free(sdp);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
/* figure out what address to use for RTP masquerading */
|
||||
if (MSG_IS_REQUEST(mymsg)) {
|
||||
@ -1179,6 +1173,27 @@ if (configuration.debuglevel)
|
||||
memcpy(&addr_media, &addr_sess, sizeof(addr_sess));
|
||||
}
|
||||
|
||||
/*&&&& If I'm sitting BEFORE the actual masquerading router:
|
||||
ok: I _must_ _not_ _try_ _to_ _use_ _my_ _outbound_ _address_ (map_addr)
|
||||
but my inbound address instead. Also make sure that the port
|
||||
seems ok: assignment does not get fucked up.
|
||||
todo: RPORT option must be removed.
|
||||
seens ok: Possibly a new RTP_DIRECTION value is needed ("no double assignments
|
||||
of same port on different IPs" or something similar)??
|
||||
*/
|
||||
/*
|
||||
* I am running in front of the routing device. I cannot use the
|
||||
* external IP to bind a listen socket to, so force the use of
|
||||
* my inbound IP for listening
|
||||
*/
|
||||
if ((rtp_direction == DIR_INCOMING) &&
|
||||
(configuration.outbound_host) &&
|
||||
(strcmp(configuration.outbound_host, "")!=0)) {
|
||||
/*&&&&*/
|
||||
INFO("**** Front-Routing Hack ****");
|
||||
memcpy(&map_addr, &inside_addr, sizeof (map_addr));
|
||||
}
|
||||
|
||||
sts = rtp_start_fwd(osip_message_get_call_id(mymsg),
|
||||
client_id,
|
||||
rtp_direction,
|
||||
|
||||
@ -150,6 +150,7 @@ static int parse_config (FILE *configfile) {
|
||||
{ "silence_log", TYP_INT4, &configuration.silence_log },
|
||||
{ "if_inbound", TYP_STRING, &configuration.inbound_if },
|
||||
{ "if_outbound", TYP_STRING, &configuration.outbound_if },
|
||||
{ "host_outbound", TYP_STRING, &configuration.outbound_host },
|
||||
{ "rtp_port_low", TYP_INT4, &configuration.rtp_port_low },
|
||||
{ "rtp_port_high", TYP_INT4, &configuration.rtp_port_high },
|
||||
{ "rtp_timeout", TYP_INT4, &configuration.rtp_timeout },
|
||||
|
||||
@ -376,10 +376,7 @@ int register_client(sip_ticket_t *ticket, int force_lcl_masq) {
|
||||
struct in_addr addr;
|
||||
char *addrstr;
|
||||
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr) !=
|
||||
STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
if (get_interface_ip(IF_OUTBOUND, &addr) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@ -64,14 +64,10 @@ int route_preprocess(sip_ticket_t *ticket){
|
||||
return STS_SUCCESS;
|
||||
}
|
||||
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr2) != STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
if (get_interface_ip(IF_INBOUND, &addr2) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr3)!= STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
if (get_interface_ip(IF_OUTBOUND, &addr3)!= STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
@ -249,17 +245,13 @@ int route_add_recordroute(sip_ticket_t *ticket){
|
||||
switch (ticket->direction) {
|
||||
case REQTYP_INCOMING:
|
||||
case RESTYP_INCOMING:
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
if (get_interface_ip(IF_INBOUND, &addr) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
break;
|
||||
case REQTYP_OUTGOING:
|
||||
case RESTYP_OUTGOING:
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
if (get_interface_ip(IF_OUTBOUND, &addr) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
break;
|
||||
@ -338,16 +330,10 @@ int route_purge_recordroute(sip_ticket_t *ticket){
|
||||
|
||||
/* resolve IP addresses (of RR header, inbound & outbound IF) */
|
||||
sts = get_ip_by_host(r_route->url->host, &addr1);
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr2)
|
||||
!= STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
if (get_interface_ip(IF_INBOUND, &addr2) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr3)
|
||||
!= STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
if (get_interface_ip(IF_OUTBOUND, &addr3) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@ -174,11 +174,8 @@ int check_vialoop (sip_ticket_t *ticket) {
|
||||
int is_via_local (osip_via_t *via) {
|
||||
int sts, found;
|
||||
struct in_addr addr_via, addr_myself;
|
||||
char *my_interfaces[]=
|
||||
{ configuration.inbound_if, configuration.outbound_if, (char*)-1 };
|
||||
int port;
|
||||
int i;
|
||||
char *ptr;
|
||||
|
||||
if (via==NULL) {
|
||||
ERROR("called is_via_local with NULL via");
|
||||
@ -197,19 +194,14 @@ int is_via_local (osip_via_t *via) {
|
||||
}
|
||||
|
||||
found=0;
|
||||
for (i=0; ; i++) {
|
||||
for (i=0; i<2; i++) {
|
||||
/*
|
||||
* try to search by interface name first
|
||||
* search my in/outbound interfaces
|
||||
*/
|
||||
ptr=my_interfaces[i];
|
||||
if (ptr==(char*)-1) break; /* end of list mark */
|
||||
|
||||
if (ptr) {
|
||||
DEBUGC(DBCLASS_BABBLE,"resolving IP of interface %s",ptr);
|
||||
if (get_ip_by_ifname(ptr, &addr_myself) != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?", ptr);
|
||||
continue;
|
||||
}
|
||||
DEBUGC(DBCLASS_BABBLE,"resolving IP of interface %s",
|
||||
(i==IF_INBOUND)? "inbound":"outbound");
|
||||
if (get_interface_ip(i, &addr_myself) != STS_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check the extracted VIA against my own host addresses */
|
||||
@ -390,11 +382,8 @@ int is_sipuri_local (sip_ticket_t *ticket) {
|
||||
osip_message_t *sip=ticket->sipmsg;
|
||||
int found;
|
||||
struct in_addr addr_uri, addr_myself;
|
||||
char *my_interfaces[]=
|
||||
{ configuration.inbound_if, configuration.outbound_if, (char*)-1 };
|
||||
int port;
|
||||
int i;
|
||||
char *ptr;
|
||||
|
||||
if (sip==NULL) {
|
||||
ERROR("called is_sipuri_local with NULL sip");
|
||||
@ -416,19 +405,14 @@ int is_sipuri_local (sip_ticket_t *ticket) {
|
||||
}
|
||||
|
||||
found=0;
|
||||
for (i=0; ; i++) {
|
||||
for (i=0; i<2; i++) {
|
||||
/*
|
||||
* try to search by interface name first
|
||||
* search my in/outbound interfaces
|
||||
*/
|
||||
ptr=my_interfaces[i];
|
||||
if (ptr==(char*)-1) break; /* end of list mark */
|
||||
|
||||
if (ptr) {
|
||||
DEBUGC(DBCLASS_BABBLE,"resolving IP of interface %s",ptr);
|
||||
if (get_ip_by_ifname(ptr, &addr_myself) != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?", ptr);
|
||||
continue;
|
||||
}
|
||||
DEBUGC(DBCLASS_BABBLE,"resolving IP of interface %s",
|
||||
(i==IF_INBOUND)? "inbound":"outbound");
|
||||
if (get_interface_ip(i, &addr_myself) != STS_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check the extracted HOST against my own host addresses */
|
||||
@ -603,18 +587,8 @@ int sip_add_myvia (sip_ticket_t *ticket, int interface) {
|
||||
int sts;
|
||||
char branch_id[VIA_BRANCH_SIZE];
|
||||
|
||||
if (interface == IF_OUTBOUND) {
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
} else {
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
if (get_interface_ip(interface, &addr) != STS_SUCCESS) {
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
sts = sip_calculate_branch_id(ticket, branch_id);
|
||||
|
||||
@ -424,10 +424,8 @@ int main (int argc, char *argv[])
|
||||
dest_port= (url->port)?atoi(url->port):SIP_PORT;
|
||||
|
||||
if ( (get_ip_by_host(url->host, &addr1) == STS_SUCCESS) &&
|
||||
(get_ip_by_ifname(configuration.inbound_if,&addr2) ==
|
||||
STS_SUCCESS) &&
|
||||
(get_ip_by_ifname(configuration.outbound_if,&addr3) ==
|
||||
STS_SUCCESS)) {
|
||||
(get_interface_ip(IF_INBOUND,&addr2) == STS_SUCCESS) &&
|
||||
(get_interface_ip(IF_OUTBOUND,&addr3) == STS_SUCCESS)) {
|
||||
|
||||
if ((configuration.sip_listen_port == dest_port) &&
|
||||
((memcmp(&addr1, &addr2, sizeof(addr1)) == 0) ||
|
||||
@ -457,7 +455,7 @@ int main (int argc, char *argv[])
|
||||
* If not, send back error to UA and
|
||||
* skip any proxying attempt
|
||||
*/
|
||||
} else if (get_ip_by_ifname(configuration.outbound_if,NULL) !=
|
||||
} else if (get_interface_ip(IF_OUTBOUND,NULL) !=
|
||||
STS_SUCCESS) {
|
||||
DEBUGC(DBCLASS_SIP, "got a %s to proxy, but outbound interface "
|
||||
"is down", (MSG_IS_REQUEST(ticket.sipmsg))? "REQ" : "RES");
|
||||
|
||||
@ -60,6 +60,7 @@ struct siproxd_config {
|
||||
int debugport;
|
||||
char *inbound_if;
|
||||
char *outbound_if;
|
||||
char *outbound_host;
|
||||
int sip_listen_port;
|
||||
int daemonize;
|
||||
int silence_log;
|
||||
@ -147,6 +148,7 @@ int route_determine_nexthop(sip_ticket_t *ticket,
|
||||
int get_ip_by_host(char *hostname, struct in_addr *addr); /*X*/
|
||||
void secure_enviroment (void);
|
||||
int get_ip_by_ifname(char *ifname, struct in_addr *retaddr); /*X*/
|
||||
int get_interface_ip(int interface, struct in_addr *retaddr); /*X*/
|
||||
char *utils_inet_ntoa(struct in_addr in);
|
||||
int utils_inet_aton(const char *cp, struct in_addr *inp);
|
||||
|
||||
@ -159,8 +161,6 @@ int compare_callid(osip_call_id_t *cid1, osip_call_id_t *cid2); /*X*/
|
||||
int is_sipuri_local (sip_ticket_t *ticket); /*X*/
|
||||
int check_rewrite_rq_uri (osip_message_t *sip); /*X*/
|
||||
int sip_gen_response(sip_ticket_t *ticket, int code); /*X*/
|
||||
#define IF_OUTBOUND 0
|
||||
#define IF_INBOUND 1
|
||||
int sip_add_myvia (sip_ticket_t *ticket, int interface); /*X*/
|
||||
int sip_del_myvia (sip_ticket_t *ticket); /*X*/
|
||||
int sip_rewrite_contact (sip_ticket_t *ticket, int direction); /*X*/
|
||||
@ -242,8 +242,8 @@ int sip_message_set_body(osip_message_t * sip, const char *buf, int len);
|
||||
#define SEC_MINLEN 16 /* minimum received length */
|
||||
#define SEC_MAXLINELEN 1024 /* maximum acceptable length of one line
|
||||
in the SIP telegram (security check)
|
||||
Careful: Proxy-Authorization lines may
|
||||
get quite long */
|
||||
Careful: Proxy-Authorization lines may
|
||||
get quite long */
|
||||
|
||||
/* symbols for access control */
|
||||
#define ACCESSCTL_SIP 1 /* for access control - SIP allowed */
|
||||
@ -260,6 +260,10 @@ int sip_message_set_body(osip_message_t * sip, const char *buf, int len);
|
||||
#define DIR_INCOMING 1
|
||||
#define DIR_OUTGOING 2
|
||||
|
||||
/* Interfaces */
|
||||
#define IF_OUTBOUND 0
|
||||
#define IF_INBOUND 1
|
||||
|
||||
/* various */
|
||||
#ifndef satoi
|
||||
#define satoi atoi /* used in libosips MSG_TEST_CODE macro ... */
|
||||
|
||||
42
src/utils.c
42
src/utils.c
@ -291,6 +291,48 @@ void secure_enviroment (void) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_interface_ip:
|
||||
* fetches own IP address by interface INBOUND/OUTBOUND
|
||||
*
|
||||
* STS_SUCCESS on returning a valid IP and interface is UP
|
||||
* STS_FAILURE if interface is DOWN or other problem
|
||||
*/
|
||||
int get_interface_ip(int interface, struct in_addr *retaddr) {
|
||||
int sts=STS_FAILURE;
|
||||
char *tmp=NULL;
|
||||
|
||||
if (interface == IF_INBOUND) {
|
||||
tmp = configuration.inbound_if;
|
||||
} else if (interface == IF_OUTBOUND) {
|
||||
tmp = configuration.outbound_if;
|
||||
}
|
||||
|
||||
if ((interface == IF_OUTBOUND) &&
|
||||
(configuration.outbound_host) &&
|
||||
(strcmp(configuration.outbound_host, "")!=0)) {
|
||||
DEBUGC(DBCLASS_DNS, "fetching outbound IP by HOSTNAME");
|
||||
if (retaddr) {
|
||||
sts = get_ip_by_host(configuration.outbound_host, retaddr);
|
||||
} else {
|
||||
sts = STS_SUCCESS;
|
||||
}
|
||||
|
||||
} else if (tmp && (strcmp(tmp, "")!=0)) {
|
||||
DEBUGC(DBCLASS_DNS, "fetching interface IP by INTERFACE [%i]", interface);
|
||||
sts = get_ip_by_ifname(tmp, retaddr);
|
||||
if (sts != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?", tmp);
|
||||
}
|
||||
|
||||
} else {
|
||||
ERROR("Don't know what interface to look for - configuration error?");
|
||||
}
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* get_ip_by_ifname:
|
||||
* fetches own IP address by its interface name
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user