aboutsummaryrefslogtreecommitdiff
path: root/sbin/nos-tun
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2001-03-28 17:30:26 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2001-03-28 17:30:26 +0000
commit6d4a212d49955af77411923fb0b230de6d074311 (patch)
treebd1c59c39729b605519243282a46dbb1301a22b1 /sbin/nos-tun
parent944adaa6c03100a4a8dc6eec893a8d35773884d2 (diff)
downloadsrc-6d4a212d49955af77411923fb0b230de6d074311.tar.gz
src-6d4a212d49955af77411923fb0b230de6d074311.zip
Allow specification of which source address to use for encapsulation.
PR: 25847 Submitted by: Eugene Polovnikov <eugene@brain-fag.org>
Notes
Notes: svn path=/head/; revision=74948
Diffstat (limited to 'sbin/nos-tun')
-rw-r--r--sbin/nos-tun/nos-tun.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/sbin/nos-tun/nos-tun.c b/sbin/nos-tun/nos-tun.c
index ceed05fd6a7a..95abd5f58223 100644
--- a/sbin/nos-tun/nos-tun.c
+++ b/sbin/nos-tun/nos-tun.c
@@ -239,11 +239,13 @@ int main (int argc, char **argv)
char *point_to = NULL;
char *to_point = NULL;
char *target;
+ char *source = NULL;
char *protocol = NULL;
int protnum;
struct sockaddr t_laddr; /* Source address of tunnel */
struct sockaddr whereto; /* Destination of tunnel */
+ struct sockaddr wherefrom; /* Source of tunnel */
struct sockaddr_in *to;
char buf[0x2000]; /* Packets buffer */
@@ -272,7 +274,7 @@ int main (int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc != 1 || (devname == NULL) ||
+ if ((argc != 1 && argc != 2) || (devname == NULL) ||
(point_to == NULL) || (to_point == NULL)) {
usage();
}
@@ -282,7 +284,11 @@ int main (int argc, char **argv)
else
protnum = atoi(protocol);
- target = *argv;
+ if (argc == 1) {
+ target = *argv;
+ } else {
+ source = *argv++; target = *argv;
+ }
/* Establish logging through 'syslog' */
openlog("nos-tun", LOG_PID, LOG_DAEMON);
@@ -306,6 +312,15 @@ int main (int argc, char **argv)
Finish(5);
}
+ if (source) {
+ if (Set_address(source, (struct sockaddr_in *)&wherefrom))
+ Finish(9);
+ if (bind(net, &wherefrom, sizeof(wherefrom)) < 0) {
+ syslog(LOG_ERR, "can't bind source address - %m");
+ Finish(10);
+ }
+ }
+
if (connect(net,&whereto,sizeof(struct sockaddr_in)) < 0 ) {
syslog(LOG_ERR,"can't connect to target - %m");
close(net);
@@ -365,7 +380,7 @@ static void
usage()
{
fprintf(stderr,
-"usage: nos-tun -t <tun_name> -s <source_addr> -d <dest_addr> -p <protocol_number> <target_addr>\n");
+"usage: nos-tun -t <tun_name> -s <source_addr> -d <dest_addr> -p <protocol_number> [<source_addr>] <target_addr>\n");
exit(1);
}