summaryrefslogtreecommitdiff
path: root/openbsd-compat/port-tun.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/port-tun.c')
-rw-r--r--openbsd-compat/port-tun.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/openbsd-compat/port-tun.c b/openbsd-compat/port-tun.c
index 7579c6084..0e75c911d 100644
--- a/openbsd-compat/port-tun.c
+++ b/openbsd-compat/port-tun.c
@@ -56,12 +56,15 @@
56#include <linux/if_tun.h> 56#include <linux/if_tun.h>
57 57
58int 58int
59sys_tun_open(int tun, int mode) 59sys_tun_open(int tun, int mode, char **ifname)
60{ 60{
61 struct ifreq ifr; 61 struct ifreq ifr;
62 int fd = -1; 62 int fd = -1;
63 const char *name = NULL; 63 const char *name = NULL;
64 64
65 if (ifname != NULL)
66 *ifname = NULL;
67
65 if ((fd = open("/dev/net/tun", O_RDWR)) == -1) { 68 if ((fd = open("/dev/net/tun", O_RDWR)) == -1) {
66 debug("%s: failed to open tunnel control interface: %s", 69 debug("%s: failed to open tunnel control interface: %s",
67 __func__, strerror(errno)); 70 __func__, strerror(errno));
@@ -99,6 +102,9 @@ sys_tun_open(int tun, int mode)
99 else 102 else
100 debug("%s: %s mode %d fd %d", __func__, ifr.ifr_name, mode, fd); 103 debug("%s: %s mode %d fd %d", __func__, ifr.ifr_name, mode, fd);
101 104
105 if (ifname != NULL && (*ifname = strdup(ifr.ifr_name)))
106 goto failed;
107
102 return (fd); 108 return (fd);
103 109
104 failed: 110 failed:
@@ -116,13 +122,16 @@ sys_tun_open(int tun, int mode)
116#endif 122#endif
117 123
118int 124int
119sys_tun_open(int tun, int mode) 125sys_tun_open(int tun, int mode, char **ifname)
120{ 126{
121 struct ifreq ifr; 127 struct ifreq ifr;
122 char name[100]; 128 char name[100];
123 int fd = -1, sock, flag; 129 int fd = -1, sock, flag;
124 const char *tunbase = "tun"; 130 const char *tunbase = "tun";
125 131
132 if (ifname != NULL)
133 *ifname = NULL;
134
126 if (mode == SSH_TUNMODE_ETHERNET) { 135 if (mode == SSH_TUNMODE_ETHERNET) {
127#ifdef SSH_TUN_NO_L2 136#ifdef SSH_TUN_NO_L2
128 debug("%s: no layer 2 tunnelling support", __func__); 137 debug("%s: no layer 2 tunnelling support", __func__);
@@ -180,6 +189,9 @@ sys_tun_open(int tun, int mode)
180 goto failed; 189 goto failed;
181 } 190 }
182 191
192 if (ifname != NULL && (*ifname = strdup(ifr.ifr_name)))
193 goto failed;
194
183 close(sock); 195 close(sock);
184 return (fd); 196 return (fd);
185 197