summaryrefslogtreecommitdiff
path: root/net/openvpn/patches/patch-ac
blob: d34f8a3fa066501122450d3c08fa01c127943a5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$NetBSD: patch-ac,v 1.3 2006/04/11 20:09:52 jlam Exp $

--- tun.c.orig	2006-04-05 02:29:24.000000000 -0400
+++ tun.c
@@ -877,7 +877,37 @@ open_tun_generic (const char *dev, const
 	  if (dynamic && !has_digit(dev))
 	    {
 	      int i;
-	      for (i = 0; i < 256; ++i)
+#if defined(TAPGIFNAME)
+	      /*
+	       * Perhaps we have a cloning device.  Try opening
+	       * the device without any appended digits,
+	       * and use ioctl(,TAPGIFNAME,) to get the resulting
+	       * interface name.
+	       */
+	      openvpn_snprintf (tunname, sizeof (tunname), "/dev/%s", dev);
+	      if ((tt->fd = open (tunname, O_RDWR)) > 0)
+		{
+		  struct ifreq ifr;
+		  if (ioctl (tt->fd, TAPGIFNAME, (void*)&ifr) < 0)
+		    {
+		      msg (D_READ_WRITE | M_ERRNO,
+			   "ioctl(,TAPGIFNAME,) failed for %s", tunname);
+		      close(tt->fd);
+		    }
+		  else
+		    {
+		      strlcpy (dynamic_name, ifr.ifr_name,
+			       sizeof (dynamic_name));
+		      dynamic_opened = true;
+		      msg (M_INFO, "TUN/TAP dynamic interface %s opened",
+			   dynamic_name);
+		    }
+		}
+	      if (!dynamic_opened)
+		msg (D_READ_WRITE | M_ERRNO, "Tried opening %s (failed)",
+		     tunname);
+#endif /* TAPGIFNAME */
+	      for (i = 0; i < 256 && !dynamic_opened; ++i)
 		{
 		  openvpn_snprintf (tunname, sizeof (tunname),
 				    "/dev/%s%d", dev, i);