[Vtun-Commit] CVS: 11 files have been modified in vtun.
Status: Inactive
Brought to you by:
mtbishop
|
From: Bishop <mtb...@us...> - 2005-12-16 22:06:58
|
The following files were modified in vtun: Name Old version New version Comment ---- ----------- ----------- ------- ChangeLog 1.12.2.15.2.7 1.12.2.15.2.7.2.1=20=20=20=20 Credits 1.6.2.6.2.3 1.6.2.6.2.3.8.1=20=20=20=20=20=20 cfg_file.y 1.1.1.2.2.13.2.2 1.1.1.2.2.13.2.2.4.1=20 cfg_kwords.h 1.1.1.1.2.3.2.6 1.1.1.1.2.3.2.6.4.1=20=20 main.c 1.1.1.2.2.8.2.2 1.1.1.2.2.8.2.2.4.1=20=20 netlib.c 1.7.2.4 1.7.2.4.10.1=20=20=20=20=20=20=20=20=20 netlib.h 1.2.2.1 1.2.2.1.10.1=20=20=20=20=20=20=20=20=20 server.c 1.4.2.5.2.2 1.4.2.5.2.2.2.1=20=20=20=20=20=20 vtun.h 1.7.2.6.2.4 1.7.2.6.2.4.4.1=20=20=20=20=20=20 vtund.conf 1.1.1.2.2.4.2.2 1.1.1.2.2.4.2.2.8.1=20=20 vtund.conf.5 1.1.2.6.2.1 1.1.2.6.2.1.8.1=20=20=20=20=20=20 The accompanying log: From Alan: This adds a config option "bindaddr" that forces vtund to listen on a particular address in server mode. The syntax is identical to the existing srcaddr option (i.e. you can bind to a device name, an ip, or hostname) and appears in the general section of the config file. If bindaddr is omitted, vtund listens on 0.0.0.0, which is the current behavior. Factored the "fill in a sockaddr from dev/ip/hostname" stuff out of local_addr() and into a new function generic_addr() so bindaddr can use it too. Moved the svr_port member of the vtun struct into a new vtun_addr member which holds both listen port and listen address now. Syntax for "port" remains the same though...so there are this and other inconsistencies in the config semantics now, but I didn't feel comfortable fixing them. The diff of the modified file(s): --- ChangeLog 6 Jun 2005 11:34:08 -0000 1.12.2.15.2.7 +++ ChangeLog 16 Dec 2005 22:06:45 -0000 1.12.2.15.2.7.2.1 @@ -8,6 +8,7 @@ started on UNSUPPORTED rpmbuild option (bc) Fixed Bug#1176343 SIGINT kills foreground server process (bc) Added RFE#936523 Bind VTun Server to Specific Interface (bc) + Completely Rewrote the Bind To Specific Interface (alan grow) =20=09 3.0.0-pre1: Implementation of Nickolai 'kolya' Zeldovich's mlockall() patch (bc) --- Credits 19 Apr 2004 18:46:16 -0000 1.6.2.6.2.3 +++ Credits 16 Dec 2005 22:06:45 -0000 1.6.2.6.2.3.8.1 @@ -133,3 +133,7 @@ Added support for different sized keys. Re-sync ciphers when using non-ECB modes over a UDP connection. Fixed Bug#908824 (persist=3Dkeep not re-applying routes) + +Alan Grow <agrow-at-thegotonerd.com> + Added a Listening Address/Interface (rfe936523) + Cleaned up the code around that portion of the config. --- cfg_file.y 2 Jun 2005 13:31:54 -0000 1.1.1.2.2.13.2.2 +++ cfg_file.y 16 Dec 2005 22:06:45 -0000 1.1.1.2.2.13.2.2.4.1 @@ -71,7 +71,7 @@ } %expect 20 =20 -%token K_OPTIONS K_DEFAULT K_PORT K_PERSIST K_TIMEOUT +%token K_OPTIONS K_DEFAULT K_PORT K_BINDADDR K_PERSIST K_TIMEOUT %token K_PASSWD K_PROG K_PPP K_SPEED K_IFCFG K_FWALL K_ROUTE K_DEVICE=20 %token K_MULTI K_SRCADDR K_IFACE K_ADDR %token K_TYPE K_PROT K_COMPRESS K_ENCRYPT K_KALIVE K_STAT @@ -142,10 +142,12 @@ /* Don't override command line options */ option: '\n' | K_PORT NUM {=20 - if(vtun.svr_port =3D=3D -1) - vtun.svr_port =3D $2; + if(vtun.bind_addr.port =3D=3D -1) + vtun.bind_addr.port =3D $2; }=20 =20 + | K_BINDADDR '{' bindaddr_option '}' + | K_IFACE STRING {=20 if(vtun.svr_addr =3D=3D -1) vtun.svr_addr =3D strdup($2); @@ -194,6 +196,28 @@ } ; =20 +bindaddr_option:=20 + K_ADDR WORD { + vtun.bind_addr.name =3D strdup($2); + vtun.bind_addr.type =3D VTUN_ADDR_NAME; + } + + | K_IFACE WORD { + vtun.bind_addr.name =3D strdup($2); + vtun.bind_addr.type =3D VTUN_ADDR_IFACE; + } + + | K_IFACE STRING { + vtun.bind_addr.name =3D strdup($2); + vtun.bind_addr.type =3D VTUN_ADDR_IFACE; + } + + | K_ERROR { + cfg_error("Unknown option '%s'",$1); + YYABORT; + } + ; + syslog_opt: NUM { vtun.syslog =3D $1; --- cfg_kwords.h 2 Jun 2005 13:31:54 -0000 1.1.1.1.2.3.2.6 +++ cfg_kwords.h 16 Dec 2005 22:06:45 -0000 1.1.1.1.2.3.2.6.4.1 @@ -36,6 +36,7 @@ { "srcaddr", K_SRCADDR },=20 { "addr", K_ADDR },=20 { "iface", K_IFACE },=20 + { "bindaddr", K_BINDADDR }, { "persist", K_PERSIST },=20 { "multi", K_MULTI },=20 { "iface", K_IFACE },=20 --- main.c 2 Jun 2005 13:31:54 -0000 1.1.1.2.2.8.2.2 +++ main.c 16 Dec 2005 22:06:45 -0000 1.1.1.2.2.8.2.2.4.1 @@ -72,7 +72,7 @@ =20 vtun.svr_name =3D NULL; vtun.svr_addr =3D NULL; - vtun.svr_port =3D -1; + vtun.bind_addr.port =3D -1; vtun.svr_type =3D -1; vtun.syslog =3D LOG_DAEMON; =20 @@ -105,7 +105,7 @@ vtun.svr_addr =3D strdup(optarg); break; case 'P': - vtun.svr_port =3D atoi(optarg); + vtun.bind_addr.port =3D atoi(optarg); break; case 'f': vtun.cfg_file =3D strdup(optarg); @@ -151,8 +151,8 @@ * Now fill uninitialized fields of the options structure * with default values.=20 */=20 - if(vtun.svr_port =3D=3D -1) - vtun.svr_port =3D VTUN_PORT; + if(vtun.bind_addr.port =3D=3D -1) + vtun.bind_addr.port =3D VTUN_PORT; if(vtun.persist =3D=3D -1) vtun.persist =3D 0; if(vtun.timeout =3D=3D -1) --- netlib.c 25 Apr 2002 09:19:50 -0000 1.7.2.4 +++ netlib.c 16 Dec 2005 22:06:45 -0000 1.7.2.4.10.1 @@ -17,7 +17,7 @@ */ =20 /* - * $Id$ + * netlib.c,v 1.7.2.4 2002/04/25 09:19:50 bergolth Exp */=20 =20 #include "config.h" @@ -207,7 +207,6 @@ /* Set local address */ int local_addr(struct sockaddr_in *addr, struct vtun_host *host, int con) { - struct hostent * hent; int opt; =20 if( con ){ @@ -218,31 +217,9 @@ return -1;=20 } } else { - memset(addr, 0, sizeof(struct sockaddr_in)); - addr->sin_family =3D AF_INET; - switch( host->src_addr.type ){ - case VTUN_ADDR_IFACE: - if( !( addr->sin_addr.s_addr =3D getifaddr(host->src_addr.na= me)) ){ - vtun_syslog(LOG_ERR,"Can't get address of interface %s",= =20 - host->src_addr.name); - return -1; - } - break; - case VTUN_ADDR_NAME: - if( !(hent =3D gethostbyname(host->src_addr.name)) ){ - vtun_syslog(LOG_ERR,"Can't resolv local address %s",=20 - host->src_addr.name); + if (generic_addr(addr, &host->src_addr) < 0) return -1; } - addr->sin_addr.s_addr =3D *(unsigned long *)hent->h_addr;=20 - break; - default: - addr->sin_addr.s_addr =3D INADDR_ANY;=20 - break; - } - } - if( host->src_addr.port )=09 - addr->sin_port =3D htons(host->src_addr.port); =20 host->sopt.laddr =3D strdup(inet_ntoa(addr->sin_addr)); =20 @@ -255,7 +232,7 @@ =20 memset(addr,0,sizeof(struct sockaddr_in)); addr->sin_family =3D AF_INET; - addr->sin_port =3D htons(vtun.svr_port); + addr->sin_port =3D htons(vtun.bind_addr.port); =20 /* Lookup server's IP address. * We do it on every reconnect because server's IP=20 @@ -268,7 +245,45 @@ addr->sin_addr.s_addr =3D *(unsigned long *)hent->h_addr;=20 =20 host->sopt.raddr =3D strdup(inet_ntoa(addr->sin_addr)); - host->sopt.rport =3D vtun.svr_port; + host->sopt.rport =3D vtun.bind_addr.port; + + return 0;=20 +} + +/* Set address by interface name, ip address or hostname */ +int generic_addr(struct sockaddr_in *addr, struct vtun_addr *vaddr) +{ + struct hostent *hent; + memset(addr, 0, sizeof(struct sockaddr_in)); +=20=20 + addr->sin_family =3D AF_INET; +=20=20 + switch (vaddr->type) { + case VTUN_ADDR_IFACE: + if (!(addr->sin_addr.s_addr =3D + getifaddr(vaddr->name))) { + vtun_syslog(LOG_ERR, + "Can't get address of interface %s", + vaddr->name); + return -1; + } + break; + case VTUN_ADDR_NAME: + if (!(hent =3D gethostbyname(vaddr->name))) { + vtun_syslog(LOG_ERR, + "Can't resolv local address %s", + vaddr->name); + return -1; + } + addr->sin_addr.s_addr =3D *(unsigned long *) hent->h_addr; + break; + default: + addr->sin_addr.s_addr =3D INADDR_ANY; + break; + } +=20=20 + if (vaddr->port) + addr->sin_port =3D htons(vaddr->port); =20 return 0;=20 } --- netlib.h 21 Sep 2000 18:40:26 -0000 1.2.2.1 +++ netlib.h 16 Dec 2005 22:06:45 -0000 1.2.2.1.10.1 @@ -17,7 +17,7 @@ */ =20 /* - * $Id$ + * netlib.h,v 1.2.2.1 2000/09/21 18:40:26 maxk Exp */=20 #ifndef _VTUN_NETDEV_H #define _VTUN_NETDEV_H @@ -37,5 +37,6 @@ =20 int local_addr(struct sockaddr_in *addr, struct vtun_host *host, int con); int server_addr(struct sockaddr_in *addr, struct vtun_host *host); +int generic_addr(struct sockaddr_in *addr, struct vtun_addr *vaddr); =20 #endif /* _VTUN_NETDEV_H */ --- server.c 6 Jun 2005 07:57:41 -0000 1.4.2.5.2.2 +++ server.c 16 Dec 2005 22:06:45 -0000 1.4.2.5.2.2.2.1 @@ -90,7 +90,7 @@ host->rmt_fd =3D sock;=20 =20=09 host->sopt.laddr =3D strdup(inet_ntoa(my_addr.sin_addr)); - host->sopt.lport =3D vtun.svr_port; + host->sopt.lport =3D vtun.bind_addr.port; host->sopt.raddr =3D strdup(ip); host->sopt.rport =3D ntohs(cl_addr.sin_port); =20 @@ -118,13 +118,12 @@ =20 memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family =3D AF_INET; - my_addr.sin_addr.s_addr =3D INADDR_ANY; - my_addr.sin_port =3D htons(vtun.svr_port);=09 - if (NULL !=3D vtun.svr_addr) { /* Set to NULL near main.c:74 so if n= ot NULL, we know it changed */ - /* currently we are ONLY accepting iface names for the addr. Later= we'll do IPs too. */ - if ( !(my_addr.sin_addr.s_addr =3D getifaddr (vtun.svr_addr))) { - vtun_syslog(LOG_ERR,"Can't resolve server interface: %s; using INADDR_A= NY", vtun.svr_addr); - } + + /* Set listen address */ + if( generic_addr(&my_addr, &vtun.bind_addr) < 0) + { + vtun_syslog(LOG_ERR, "Can't fill in listen socket"); + exit(1); } =20 if( (s=3Dsocket(AF_INET,SOCK_STREAM,0))=3D=3D -1 ){ @@ -152,7 +151,7 @@ sigaction(SIGINT,&sa,NULL); server_term =3D 0; =20 - set_title("waiting for connections on port %d", vtun.svr_port); + set_title("waiting for connections on port %d", vtun.bind_addr.port); =20 while( (!server_term) || (server_term =3D=3D VTUN_SIG_HUP) ){ opt=3Dsizeof(cl_addr); --- vtun.h 2 Jun 2005 13:31:54 -0000 1.7.2.6.2.4 +++ vtun.h 16 Dec 2005 22:06:45 -0000 1.7.2.6.2.4.4.1 @@ -202,7 +202,7 @@ =20 char *svr_name; /* Server's host name */ char *svr_addr; /* Server's address (string) */ - int svr_port; /* Server's port */ + struct vtun_addr bind_addr; /* Server should listen on this address */ int svr_type; /* Server mode */ int syslog; /* Facility to log messages to syslog under */ }; --- vtund.conf 4 Mar 2004 07:43:39 -0000 1.1.1.2.2.4.2.2 +++ vtund.conf 16 Dec 2005 22:06:45 -0000 1.1.1.2.2.4.2.2.8.1 @@ -38,6 +38,25 @@ # port - Server TCP port number. # # ----------- +# bindaddr - Server listen address. Used to force vtund to bind +# to the specific address and port in server mode. +# Format:=09=20=20 +# bindaddr { +# option .....; +# }; +# +# 'bindaddr' options: +# +# iface - Use interface address as the listen address. +# Format: +# iface if_name; +# +# addr - Listen address. +# Format: +# addr ip_address; +# addr host_name; +# +# ----------- # syslog - Syslog facility. # # ----------- @@ -211,7 +230,7 @@ # # ----------- # srcaddr - Local (source) address. Used to force vtund to bind -# to the specific address and port. +# to the specific address and port in client mode. # Format:=09=20=20 # srcaddr { # option .....; @@ -251,6 +270,7 @@ # options { port 5000; # Listen on this port. + bindaddr { iface lo; }; # Listen only on loopback device. =20 # Syslog facility syslog daemon; --- vtund.conf.5 21 Apr 2005 19:19:48 -0000 1.1.2.6.2.1 +++ vtund.conf.5 16 Dec 2005 22:06:45 -0000 1.1.2.6.2.1.8.1 @@ -55,6 +55,23 @@ server port number to listen on or connect to. By default, \fBvtund\fR(8) uses port 5000. =20 +.IP \fBbindaddr\ \fIlist\fR +server listen address. Used to force vtund to bind to the specific +address and port in server mode. Format: +.nf + \fBbindaddr\fR { + \fIoption \fIvalue\fR; + }; +.fi +.IP +\fBbindaddr\fR options: +.RS +.IP \fBiface\ \fIif_name\fR +use interface address \fIif_name\fR as the bind address. +.IP \fBaddr\ \fIaddr\fR +bind address. Can be either IP address or host name. +.RE + .IP \fBtimeout\ \fIseconds\fR General timeout. =20 |