- 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:
oliverschmidt 2007-03-27 21:47:17 +00:00
parent 35051ffbd3
commit 342e720cfd
7 changed files with 148 additions and 114 deletions

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: contiki-main.c,v 1.9 2007/03/22 23:59:26 adamdunkels Exp $
* $Id: contiki-main.c,v 1.10 2007/03/27 21:47:17 oliverschmidt Exp $
*/
#include "contiki.h"
@ -61,8 +61,9 @@
#include "dev/radio-sensor.h"
#include "dev/leds.h"
u8_t tapdev_output(void);
static struct uip_fw_netif tapif =
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tapdev_send)};
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tapdev_output)};
static struct uip_fw_netif meshif =
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
/*static struct uip_fw_netif ethernodeif =

View file

@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ethernode-uip.c,v 1.3 2007/03/22 18:59:34 adamdunkels Exp $
* $Id: ethernode-uip.c,v 1.4 2007/03/27 21:47:18 oliverschmidt Exp $
*/
#include "contiki.h"
@ -76,7 +76,7 @@ PROCESS_THREAD(ethernode_uip_process, ev, data)
uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len);
tapdev_send_raw();
tapdev_send();
/* if(uip_fw_forward() == UIP_FW_LOCAL)*/ {
/* A frame was avaliable (and is now read into the uip_buf), so
we process it. */

View file

@ -1,4 +1,4 @@
#include "contiki-net.h"
#include "net/tapdev.h"
#include "net/uip_arp.h"
@ -11,8 +11,7 @@ PROCESS(tapdev_drv_process, "TAP driver");
void tapdev_drv_request_poll(void);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tapdev_drv_process, ev, data)
PROCESS_THREAD(tapdev_drv_process, ev, data)
{
PROCESS_BEGIN();
@ -42,12 +41,11 @@ PROCESS_THREAD(tapdev_drv_process, ev, data)
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
if(uip_len > 0) {
tapdev_send_raw();
tapdev_send();
}
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -1,48 +1,87 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: tapdev-service.c,v 1.2 2007/03/27 21:47:18 oliverschmidt Exp $
*/
#include "net/packet-service.h"
#include "net/tapdev.h"
#include "contiki-net.h"
#include "tapdev.h"
#include "net/uip-neighbor.h"
#include "net/uip_arp.h"
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
/* static struct uip_eth_addr addr = */
/* {0x08, 0x12, 0x23, 0x89, 0xa3, 0x94}; */
u8_t tapdev_output(void);
SERVICE(tapdev_service, packet_service, { tapdev_send });
SERVICE(tapdev_service, packet_service, { tapdev_output });
PROCESS(tapdev_service_process, "TAP driver");
PROCESS(tapdev_process, "TAP driver");
/*---------------------------------------------------------------------------*/
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
u8_t
tapdev_output(void)
{
uip_arp_out();
tapdev_send();
uip_len -= UIP_LLH_LEN;
return UIP_FW_OK;
}
/*---------------------------------------------------------------------------*/
static void
pollhandler(void)
{
/* tapdev_service_request_poll();*/
process_poll(&tapdev_service_process);
process_poll(&tapdev_process);
uip_len = tapdev_poll();
if(uip_len > 0) {
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
uip_arp_ipin();
uip_len -= sizeof(struct uip_eth_hdr);
/* uip_input();*/
#if UIP_CONF_IPV6
if(BUF->type == htons(UIP_ETHTYPE_IPV6)) {
uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
tcpip_input();
} else
#endif /* UIP_CONF_IPV6 */
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
tcpip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
} else if(BUF->type == htons(UIP_ETHTYPE_ARP)) {
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0. */
uip_len is set to a value > 0. */
if(uip_len > 0) {
tapdev_send_raw();
tapdev_send();
}
}
}
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tapdev_service_process, ev, data)
PROCESS_THREAD(tapdev_process, ev, data)
{
PROCESS_BEGIN();
@ -50,7 +89,7 @@ PROCESS_THREAD(tapdev_service_process, ev, data)
SERVICE_REGISTER(tapdev_service);
process_poll(&tapdev_service_process);
process_poll(&tapdev_process);
while(1) {
PROCESS_YIELD();
@ -61,3 +100,4 @@ PROCESS_THREAD(tapdev_service_process, ev, data)
PROCESS_END();
}
/*---------------------------------------------------------------------------*/

View file

@ -1,8 +1,41 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: tapdev-service.h,v 1.2 2007/03/27 21:47:18 oliverschmidt Exp $
*/
#ifndef __TAPDEV_SERVICE_H__
#define __TAPDEV_SERVICE_H__
#include "contiki.h"
PROCESS_NAME(tapdev_service_process);
PROCESS_NAME(tapdev_process);
#endif /* __TAPDEV_SERVICE_H__ */

View file

@ -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();
}
/*---------------------------------------------------------------------------*/

View file

@ -31,17 +31,14 @@
*
* This file is part of the uIP TCP/IP stack.
*
* $Id: tapdev.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*
* $Id: tapdev.h,v 1.2 2007/03/27 21:47:18 oliverschmidt Exp $
*/
#ifndef __TAPDEV_H__
#define __TAPDEV_H__
#include "contiki.h"
void tapdev_init(void);
u16_t tapdev_poll(void);
u8_t tapdev_send(void);
void tapdev_send_raw(void);
void tapdev_send(void);
#endif /* __TAPDEV_H__ */