Line 43... |
Line 43... |
|
|
#include <sys/poll.h>
|
#include <sys/poll.h>
|
#include <unistd.h>
|
#include <unistd.h>
|
#include <errno.h>
|
#include <errno.h>
|
|
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
#include <linux/if.h>
|
#include <linux/if.h>
|
#include <linux/if_tun.h>
|
#include <linux/if_tun.h>
|
|
#endif
|
|
|
/* Package includes */
|
/* Package includes */
|
#include "arch.h"
|
#include "arch.h"
|
#include "config.h"
|
#include "config.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
Line 187... |
Line 189... |
return nwritten;
|
return nwritten;
|
|
|
} /* eth_write_file_packet () */
|
} /* eth_write_file_packet () */
|
|
|
|
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
|
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
/*!Write an Ethernet packet to a TAP interface.
|
/*!Write an Ethernet packet to a TAP interface.
|
|
|
This writes a single Ethernet packet to a TAP interface.
|
This writes a single Ethernet packet to a TAP interface.
|
|
|
Line 203... |
Line 207... |
static ssize_t
|
static ssize_t
|
eth_write_tap_packet (struct eth_device *eth,
|
eth_write_tap_packet (struct eth_device *eth,
|
unsigned char *buf,
|
unsigned char *buf,
|
unsigned long int length)
|
unsigned long int length)
|
{
|
{
|
ssize_t nwritten;
|
ssize_t nwritten = 0;
|
|
|
|
|
|
|
#if ETH_DEBUG
|
#if ETH_DEBUG
|
int j;
|
int j;
|
|
|
printf ("Writing TAP\n");
|
printf ("Writing TAP\n");
|
Line 240... |
Line 246... |
}
|
}
|
|
|
return nwritten;
|
return nwritten;
|
|
|
} /* eth_write_tap_packet () */
|
} /* eth_write_tap_packet () */
|
|
#endif
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
/*!Write an Ethernet packet.
|
/*!Write an Ethernet packet.
|
|
|
Line 264... |
Line 271... |
{
|
{
|
/* Send packet according to interface type. */
|
/* Send packet according to interface type. */
|
switch (eth->rtx_type)
|
switch (eth->rtx_type)
|
{
|
{
|
case ETH_RTX_FILE: return eth_write_file_packet (eth, buf, length);
|
case ETH_RTX_FILE: return eth_write_file_packet (eth, buf, length);
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
case ETH_RTX_TAP: return eth_write_tap_packet (eth, buf, length);
|
case ETH_RTX_TAP: return eth_write_tap_packet (eth, buf, length);
|
|
#endif
|
|
|
default:
|
default:
|
fprintf (stderr, "Unknown Ethernet write interface: ignored.\n");
|
fprintf (stderr, "Unknown Ethernet write interface: ignored.\n");
|
return (ssize_t) -1;
|
return (ssize_t) -1;
|
}
|
}
|
Line 470... |
Line 479... |
return packet_length;
|
return packet_length;
|
|
|
} /* eth_read_file_packet () */
|
} /* eth_read_file_packet () */
|
|
|
|
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
|
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
/*!Read an Ethernet packet from a FILE interface.
|
/*!Read an Ethernet packet from a FILE interface.
|
|
|
This reads a single Ethernet packet from the outside world via a TAP
|
This reads a single Ethernet packet from the outside world via a TAP
|
interface.
|
interface.
|
Line 489... |
Line 500... |
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
static ssize_t
|
static ssize_t
|
eth_read_tap_packet (struct eth_device *eth,
|
eth_read_tap_packet (struct eth_device *eth,
|
unsigned char *buf)
|
unsigned char *buf)
|
{
|
{
|
|
|
struct pollfd fds[1];
|
struct pollfd fds[1];
|
int n;
|
int n;
|
ssize_t packet_length;
|
ssize_t packet_length;
|
|
|
/* Poll to see if there is data to read */
|
/* Poll to see if there is data to read */
|
Line 538... |
Line 550... |
{
|
{
|
return 0; /* No packet */
|
return 0; /* No packet */
|
}
|
}
|
} /* eth_read_tap_packet () */
|
} /* eth_read_tap_packet () */
|
|
|
|
#endif
|
|
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
/*!Read an Ethernet packet.
|
/*!Read an Ethernet packet.
|
|
|
This reads a single Ethernet packet from the outside world into the
|
This reads a single Ethernet packet from the outside world into the
|
Line 558... |
Line 571... |
unsigned char *buf)
|
unsigned char *buf)
|
{
|
{
|
switch (eth->rtx_type)
|
switch (eth->rtx_type)
|
{
|
{
|
case ETH_RTX_FILE: return eth_read_file_packet (eth, buf);
|
case ETH_RTX_FILE: return eth_read_file_packet (eth, buf);
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
case ETH_RTX_TAP: return eth_read_tap_packet (eth, buf);
|
case ETH_RTX_TAP: return eth_read_tap_packet (eth, buf);
|
|
#endif
|
|
|
default:
|
default:
|
fprintf (stderr, "Unknown Ethernet read interface: ignored.\n");
|
fprintf (stderr, "Unknown Ethernet read interface: ignored.\n");
|
return (ssize_t) -1;
|
return (ssize_t) -1;
|
}
|
}
|
Line 718... |
Line 733... |
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
static int
|
static int
|
eth_ignore_tap_packets (struct eth_device *eth)
|
eth_ignore_tap_packets (struct eth_device *eth)
|
{
|
{
|
int result = 0;
|
int result = 0;
|
|
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
|
|
int n;
|
int n;
|
|
|
/* Read packets until there are none left. */
|
/* Read packets until there are none left. */
|
do
|
do
|
{
|
{
|
Line 764... |
Line 782... |
}
|
}
|
}
|
}
|
}
|
}
|
while (n > 0);
|
while (n > 0);
|
|
|
|
#endif
|
|
|
return result;
|
return result;
|
|
|
} /* eth_ignore_tap_packets () */
|
} /* eth_ignore_tap_packets () */
|
|
|
|
|
Line 957... |
Line 977... |
fprintf (stderr, "Warning: Cannot open Ethernet TX file \"%s\": %s\n",
|
fprintf (stderr, "Warning: Cannot open Ethernet TX file \"%s\": %s\n",
|
eth->txfile, strerror (errno));
|
eth->txfile, strerror (errno));
|
}
|
}
|
} /* eth_open_file_if () */
|
} /* eth_open_file_if () */
|
|
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
|
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
/*!Open the external TAP interface to the Ethernet
|
/*!Open the external TAP interface to the Ethernet
|
|
|
Packets are transferred over a TAP/TUN interface. We assume a persistent
|
Packets are transferred over a TAP/TUN interface. We assume a persistent
|
Line 972... |
Line 993... |
@param[in] eth The Ethernet interface data structure. */
|
@param[in] eth The Ethernet interface data structure. */
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
static void
|
static void
|
eth_open_tap_if (struct eth_device *eth)
|
eth_open_tap_if (struct eth_device *eth)
|
{
|
{
|
|
|
struct ifreq ifr;
|
struct ifreq ifr;
|
|
|
/* We don't support re-opening. If it's open, it stays open. */
|
/* We don't support re-opening. If it's open, it stays open. */
|
if (eth->rtx_fd >= 0)
|
if (eth->rtx_fd >= 0)
|
{
|
{
|
Line 1008... |
Line 1030... |
return;
|
return;
|
}
|
}
|
#if ETH_DEBUG
|
#if ETH_DEBUG
|
PRINTF ("Opened TAP %s\n", ifr.ifr_name);
|
PRINTF ("Opened TAP %s\n", ifr.ifr_name);
|
#endif
|
#endif
|
|
|
} /* eth_open_tap_if () */
|
} /* eth_open_tap_if () */
|
|
|
|
#endif
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
/*!Open the external interface to the Ethernet
|
/*!Open the external interface to the Ethernet
|
|
|
Calls the appropriate function for the interface type.
|
Calls the appropriate function for the interface type.
|
Line 1024... |
Line 1049... |
eth_open_if (struct eth_device *eth)
|
eth_open_if (struct eth_device *eth)
|
{
|
{
|
switch (eth->rtx_type)
|
switch (eth->rtx_type)
|
{
|
{
|
case ETH_RTX_FILE: eth_open_file_if (eth); break;
|
case ETH_RTX_FILE: eth_open_file_if (eth); break;
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
case ETH_RTX_TAP: eth_open_tap_if (eth); break;
|
case ETH_RTX_TAP: eth_open_tap_if (eth); break;
|
|
#endif
|
|
|
default:
|
default:
|
fprintf (stderr, "Unknown Ethernet interface: ignored.\n");
|
fprintf (stderr, "Unknown Ethernet interface: ignored.\n");
|
break;
|
break;
|
}
|
}
|
Line 1683... |
Line 1710... |
if (0 == strcasecmp ("file", val.str_val))
|
if (0 == strcasecmp ("file", val.str_val))
|
{
|
{
|
printf ("Ethernet FILE type\n");
|
printf ("Ethernet FILE type\n");
|
eth->rtx_type = ETH_RTX_FILE;
|
eth->rtx_type = ETH_RTX_FILE;
|
}
|
}
|
|
#if HAVE_LINUX_IF_TUN_H==1
|
else if (0 == strcasecmp ("tap", val.str_val))
|
else if (0 == strcasecmp ("tap", val.str_val))
|
{
|
{
|
printf ("Ethernet TAP type\n");
|
printf ("Ethernet TAP type\n");
|
eth->rtx_type = ETH_RTX_TAP;
|
eth->rtx_type = ETH_RTX_TAP;
|
}
|
}
|
|
#endif
|
else
|
else
|
{
|
{
|
fprintf (stderr, "Warning: Unknown Ethernet type: file assumed.\n");
|
fprintf (stderr, "Warning: Unknown Ethernet type: file assumed.\n");
|
eth->rtx_type = ETH_RTX_FILE;
|
eth->rtx_type = ETH_RTX_FILE;
|
}
|
}
|