From eugene@kabir.zssm.zp.ua  Fri Mar 16 01:19:13 2001
Return-Path: <eugene@kabir.zssm.zp.ua>
Received: from kabir.zssm.zp.ua (kabir.zssm.zp.ua [212.8.32.6])
	by hub.freebsd.org (Postfix) with ESMTP id 978DC37B719
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 16 Mar 2001 01:19:11 -0800 (PST)
	(envelope-from eugene@kabir.zssm.zp.ua)
Received: (from eugene@localhost)
	by kabir.zssm.zp.ua (8.9.3/8.9.3) id LAA51340;
	Fri, 16 Mar 2001 11:19:00 +0200 (EET)
	(envelope-from eugene)
Message-Id: <200103160919.LAA51340@kabir.zssm.zp.ua>
Date: Fri, 16 Mar 2001 11:19:00 +0200 (EET)
From: eugene@brain-fag.org
Reply-To: eugene@brain-fag.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: inability of nos-tun to work correctly in multihomed environment
X-Send-Pr-Version: 3.2

>Number:         25847
>Category:       bin
>Synopsis:       inability of nos-tun to work correctly in multihomed environment
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    phk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 16 01:20:00 PST 2001
>Closed-Date:    Wed Mar 28 09:30:42 PST 2001
>Last-Modified:  Wed Mar 28 09:30:54 PST 2001
>Originator:     Eugene Polovnikov
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
ZSS JSC
>Environment:

All versions of FreeBSD which include nos-tun. 

>Description:

Current version of nos-tun doesn't allow for setting a source address of
outgoing IP packets that prevents it to work on some situation.

>How-To-Repeat:

>Fix:
--- nos-tun.c.orig	Fri Mar 16 11:01:38 2001
+++ nos-tun.c	Fri Mar 16 11:17:35 2001
@@ -239,11 +239,13 @@
   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 @@
   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 @@
   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 @@
     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 @@
 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);
 }
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->phk 
Responsible-Changed-By: ru 
Responsible-Changed-When: Fri Mar 16 03:53:17 PST 2001 
Responsible-Changed-Why:  
Let Poul decide to be or not to be. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25847 
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Wed Mar 28 09:30:42 PST 2001 
State-Changed-Why:  
committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25847 
>Unformatted:
