Browse Source

Simplify tuntap_open by using one function prototype for all OS

pull/1144/head
Hamish Coleman 1 year ago
parent
commit
439939dc7b
  1. 6
      examples/example_edge_embed.c
  2. 6
      include/n2n.h
  3. 7
      src/edge.c
  4. 13
      src/edge_utils.c
  5. 3
      src/tuntap_freebsd.c
  6. 3
      src/tuntap_linux.c
  7. 3
      src/tuntap_netbsd.c
  8. 3
      src/tuntap_osx.c

6
examples/example_edge_embed.c

@ -58,10 +58,8 @@ int main() {
"10.0.0.1", // Set ip address "10.0.0.1", // Set ip address
"255.255.255.0", // Netmask to use "255.255.255.0", // Netmask to use
"DE:AD:BE:EF:01:10", // Set mac address "DE:AD:BE:EF:01:10", // Set mac address
DEFAULT_MTU // MTU to use DEFAULT_MTU, // MTU to use
#ifdef _WIN32 0 // Metric - unused in n2n on most OS
, 0
#endif
) < 0) ) < 0)
{ {
return -1; return -1;

6
include/n2n.h

@ -127,11 +127,7 @@ void _traceEvent (int eventTraceLevel, char* file, int line, char * format, ...)
/* Tuntap API */ /* Tuntap API */
int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip, int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
char *device_mask, const char * device_mac, int mtu char *device_mask, const char * device_mac, int mtu, int metric);
#ifdef _WIN32
, int metric
#endif
);
int tuntap_read (struct tuntap_dev *tuntap, unsigned char *buf, int len); int tuntap_read (struct tuntap_dev *tuntap, unsigned char *buf, int len);
int tuntap_write (struct tuntap_dev *tuntap, unsigned char *buf, int len); int tuntap_write (struct tuntap_dev *tuntap, unsigned char *buf, int len);
void tuntap_close (struct tuntap_dev *tuntap); void tuntap_close (struct tuntap_dev *tuntap);

7
src/edge.c

@ -1246,11 +1246,8 @@ int main (int argc, char* argv[]) {
if(runlevel == 4) { /* configure the TUNTAP device, including routes */ if(runlevel == 4) { /* configure the TUNTAP device, including routes */
if(tuntap_open(&tuntap, eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, if(tuntap_open(&tuntap, eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode,
eee->tuntap_priv_conf.ip_addr, eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.ip_addr, eee->tuntap_priv_conf.netmask,
eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu,
#ifdef _WIN32 eee->tuntap_priv_conf.metric) < 0)
, eee->tuntap_priv_conf.metric
#endif
) < 0)
exit(1); exit(1);
memcpy(&eee->device, &tuntap, sizeof(tuntap)); memcpy(&eee->device, &tuntap, sizeof(tuntap));
traceEvent(TRACE_NORMAL, "created local tap device IP: %s, Mask: %s, MAC: %s", traceEvent(TRACE_NORMAL, "created local tap device IP: %s, Mask: %s, MAC: %s",

13
src/edge_utils.c

@ -2182,10 +2182,8 @@ void edge_read_from_tap (n2n_edge_t * eee) {
sleep(3); sleep(3);
tuntap_close(&(eee->device)); tuntap_close(&(eee->device));
tuntap_open(&(eee->device), eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, eee->tuntap_priv_conf.ip_addr, tuntap_open(&(eee->device), eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, eee->tuntap_priv_conf.ip_addr,
eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu,
#ifdef _WIN32 eee->tuntap_priv_conf.metric
,eee->tuntap_priv_conf.metric
#endif
); );
} else { } else {
const uint8_t * mac = eth_pkt; const uint8_t * mac = eth_pkt;
@ -3295,11 +3293,8 @@ int quick_edge_init (char *device_name, char *community_name,
/* Open the tuntap device */ /* Open the tuntap device */
if(tuntap_open(&tuntap, device_name, "static", if(tuntap_open(&tuntap, device_name, "static",
local_ip_address, "255.255.255.0", local_ip_address, "255.255.255.0",
device_mac, DEFAULT_MTU device_mac, DEFAULT_MTU,
#ifdef _WIN32 0) < 0)
, 0
#endif
) < 0)
return(-2); return(-2);
/* Init edge */ /* Init edge */

3
src/tuntap_freebsd.c

@ -36,7 +36,8 @@ int tuntap_open (tuntap_dev *device /* ignored */,
char *device_ip, char *device_ip,
char *device_mask, char *device_mask,
const char * device_mac, const char * device_mac,
int mtu) { int mtu,
int ignored) {
int i; int i;
char tap_device[N2N_FREEBSD_TAPDEVICE_SIZE]; char tap_device[N2N_FREEBSD_TAPDEVICE_SIZE];

3
src/tuntap_linux.c

@ -120,7 +120,8 @@ int tuntap_open (tuntap_dev *device,
char *device_ip, char *device_ip,
char *device_mask, char *device_mask,
const char * device_mac, const char * device_mac,
int mtu) { int mtu,
int ignored) {
char *tuntap_device = "/dev/net/tun"; char *tuntap_device = "/dev/net/tun";
int ioctl_fd; int ioctl_fd;

3
src/tuntap_netbsd.c

@ -40,7 +40,8 @@ int tuntap_open (tuntap_dev *device /* ignored */,
char *device_ip, char *device_ip,
char *device_mask, char *device_mask,
const char * device_mac, const char * device_mac,
int mtu) { int mtu,
int ignored) {
char tap_device[N2N_NETBSD_TAPDEVICE_SIZE]; char tap_device[N2N_NETBSD_TAPDEVICE_SIZE];
struct ifreq req; struct ifreq req;

3
src/tuntap_osx.c

@ -36,7 +36,8 @@ int tuntap_open (tuntap_dev *device /* ignored */,
char *device_ip, char *device_ip,
char *device_mask, char *device_mask,
const char * device_mac, const char * device_mac,
int mtu) { int mtu,
int ignored) {
int i; int i;
char tap_device[N2N_OSX_TAPDEVICE_SIZE]; char tap_device[N2N_OSX_TAPDEVICE_SIZE];

Loading…
Cancel
Save