- Moved all ARP handling to service wrapper (and narrowed interface to low level code).
- Adjusted packet forwarding to moving all ARP handling to service wrapper. - Unified general coding/formatting style.
This commit is contained in:
parent
35051ffbd3
commit
342e720cfd
7 changed files with 148 additions and 114 deletions
|
@ -31,10 +31,9 @@
|
|||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: tapdev.c,v 1.2 2007/03/22 18:59:34 adamdunkels Exp $
|
||||
* $Id: tapdev.c,v 1.3 2007/03/27 21:47:18 oliverschmidt Exp $
|
||||
*/
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -47,7 +46,6 @@
|
|||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
#ifdef linux
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/if.h>
|
||||
|
@ -57,50 +55,21 @@
|
|||
#define DEVTAP "/dev/tap0"
|
||||
#endif /* linux */
|
||||
|
||||
#include "net/uip.h"
|
||||
#include "net/uip_arp.h"
|
||||
#include "net/uip-fw.h"
|
||||
#include "net/tapdev.h"
|
||||
|
||||
#include "net/tcpip.h"
|
||||
#include "contiki-net.h"
|
||||
#include "tapdev.h"
|
||||
|
||||
#define DROP 0
|
||||
|
||||
#if DROP
|
||||
static int drop = 0;
|
||||
#endif
|
||||
|
||||
static int fd;
|
||||
|
||||
static unsigned long lasttime;
|
||||
static struct timezone tz;
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
static void do_send(void);
|
||||
|
||||
u16_t
|
||||
tapdev_poll(void)
|
||||
{
|
||||
fd_set fdset;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
if(fd > 0) {
|
||||
FD_SET(fd, &fdset);
|
||||
}
|
||||
|
||||
ret = select(fd + 1, &fdset, NULL, NULL, &tv);
|
||||
if(ret == 0) {
|
||||
return 0;
|
||||
}
|
||||
ret = read(fd, uip_buf, UIP_BUFSIZE);
|
||||
if(ret == -1) {
|
||||
perror("tapdev_poll: read");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tapdev_init(void)
|
||||
|
@ -125,32 +94,53 @@ tapdev_init(void)
|
|||
}
|
||||
#endif /* Linux */
|
||||
|
||||
snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.1.1");
|
||||
system(buf);
|
||||
snprintf(buf, sizeof(buf), "route add -net 172.16.0.0 192.168.1.2");
|
||||
snprintf(buf, sizeof(buf), "ifconfig tap0 inet 192.168.2.1");
|
||||
system(buf);
|
||||
printf("%s\n", buf);
|
||||
|
||||
lasttime = 0;
|
||||
|
||||
/* gdk_input_add(fd, GDK_INPUT_READ,
|
||||
read_callback, NULL);*/
|
||||
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
do_send(void)
|
||||
u16_t
|
||||
tapdev_poll(void)
|
||||
{
|
||||
fd_set fdset;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&fdset);
|
||||
if(fd > 0) {
|
||||
FD_SET(fd, &fdset);
|
||||
}
|
||||
|
||||
ret = select(fd + 1, &fdset, NULL, NULL, &tv);
|
||||
|
||||
if(ret == 0) {
|
||||
return 0;
|
||||
}
|
||||
ret = read(fd, uip_buf, UIP_BUFSIZE);
|
||||
|
||||
if(ret == -1) {
|
||||
perror("tapdev_poll: read");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tapdev_send(void)
|
||||
{
|
||||
int ret;
|
||||
char tmpbuf[UIP_BUFSIZE];
|
||||
int i;
|
||||
|
||||
if(fd <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* printf("tapdev_send: sending %d bytes\n", size);*/
|
||||
/* check_checksum(uip_buf, size);*/
|
||||
|
||||
#if DROP
|
||||
drop++;
|
||||
if(drop % 8 == 7) {
|
||||
|
@ -158,37 +148,12 @@ do_send(void)
|
|||
return;
|
||||
}
|
||||
#endif /* DROP */
|
||||
|
||||
for(i = 0; i < 40 + UIP_LLH_LEN; i++) {
|
||||
tmpbuf[i] = uip_buf[i];
|
||||
}
|
||||
|
||||
|
||||
for(; i < uip_len; i++) {
|
||||
tmpbuf[i] = ((char *)uip_appdata)[i - 40 - UIP_LLH_LEN];
|
||||
}
|
||||
|
||||
ret = write(fd, tmpbuf, uip_len);
|
||||
|
||||
ret = write(fd, uip_buf, uip_len);
|
||||
|
||||
if(ret == -1) {
|
||||
perror("tap_dev: tapdev_send: writev");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
u8_t
|
||||
tapdev_send(void)
|
||||
{
|
||||
uip_arp_out();
|
||||
|
||||
do_send();
|
||||
uip_len -= UIP_LLH_LEN;
|
||||
return UIP_FW_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
tapdev_send_raw(void)
|
||||
{
|
||||
do_send();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue