updated picoTCP to 1.4.0, lowered build optimization levels to -O2, improved selftest

This commit is contained in:
Joseph Henry
2017-06-05 14:26:06 -07:00
parent 47a80e8954
commit 19839eeac9
367 changed files with 107850 additions and 3813 deletions

View File

@@ -1,6 +1,6 @@
/*********************************************************************
PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved.
See LICENSE and COPYING for usage.
PicoTCP. Copyright (c) 2012-2017 Altran Intelligent Systems. Some rights reserved.
See COPYING, LICENSE.GPLv2 and LICENSE.GPLv3 for usage.
Authors: Daniele Lacamera
*********************************************************************/
@@ -27,23 +27,26 @@ struct pico_device_tap {
#define TUN_MTU 2048
// We only support one global link state - we only have two USR signals, we
// can't spread these out over an arbitrary amount of devices. When you unplug
// one tap, you unplug all of them.
/* We only support one global link state - we only have two USR signals, we */
/* can't spread these out over an arbitrary amount of devices. When you unplug */
/* one tap, you unplug all of them. */
static int link_state = 0;
static int tapdev_link_state = 0;
static void sig_handler(int signo)
{
if (signo == SIGUSR1)
link_state = 0;
if (signo == SIGUSR2)
link_state = 1;
if (signo == SIGUSR1) {
tapdev_link_state = 0;
}
if (signo == SIGUSR2) {
tapdev_link_state = 1;
}
}
static int tap_link_state(__attribute__((unused)) struct pico_device *self)
{
return link_state;
return tapdev_link_state;
}
@@ -62,8 +65,9 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score)
pfd.fd = tap->fd;
pfd.events = POLLIN;
do {
if (poll(&pfd, 1, 0) <= 0)
if (poll(&pfd, 1, 0) <= 0) {
return loop_score;
}
len = (int)read(tap->fd, buf, TUN_MTU);
if (len > 0) {
@@ -79,8 +83,9 @@ static int pico_tap_poll(struct pico_device *dev, int loop_score)
void pico_tap_destroy(struct pico_device *dev)
{
struct pico_device_tap *tap = (struct pico_device_tap *) dev;
if(tap->fd > 0)
if(tap->fd > 0) {
close(tap->fd);
}
}
#ifndef __FreeBSD__
@@ -89,14 +94,14 @@ static int tap_open(char *name)
struct ifreq ifr;
int tap_fd;
if((tap_fd = open("/dev/net/tun", O_RDWR)) < 0) {
return(-1);
return -1;
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, name, IFNAMSIZ);
if(ioctl(tap_fd, TUNSETIFF, &ifr) < 0) {
return(-1);
return -1;
}
return tap_fd;
@@ -119,9 +124,6 @@ static int tap_get_mac(char *name, uint8_t *mac)
struct ifreq eth;
int retval = -1;
sck = socket(AF_INET, SOCK_DGRAM, 0);
if(sck < 0) {
return retval;
@@ -133,12 +135,9 @@ static int tap_get_mac(char *name, uint8_t *mac)
if (ioctl(sck, SIOCGIFHWADDR, &eth) < 0) {
perror("ioctl(SIOCGIFHWADDR)");
return -1;
;
}
memcpy (mac, &eth.ifr_hwaddr.sa_data, 6);
close(sck);
return 0;
@@ -156,8 +155,9 @@ static int tap_get_mac(char *name, uint8_t *mac)
root = ifap;
while(ifap) {
if (strcmp(name, ifap->ifa_name) == 0)
if (strcmp(name, ifap->ifa_name) == 0) {
sdl = (struct sockaddr_dl *) ifap->ifa_addr;
}
if (sdl->sdl_type == IFT_ETHER) {
memcpy(mac, LLADDR(sdl), 6);
@@ -178,16 +178,18 @@ struct pico_device *pico_tap_create(char *name)
uint8_t mac[6] = {};
struct sigaction sa;
if (!tap)
if (!tap) {
return NULL;
}
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = sig_handler;
if ((sigaction(SIGUSR1, &sa, NULL) == 0) &&
(sigaction(SIGUSR2, &sa, NULL) == 0))
tap->dev.link_state = &tap_link_state;
(sigaction(SIGUSR2, &sa, NULL) == 0)) {
tap->dev.link_state = &tap_link_state;
}
tap->dev.overhead = 0;
tap->fd = tap_open(name);
@@ -197,12 +199,20 @@ struct pico_device *pico_tap_create(char *name)
return NULL;
}
/* Host's mac address is generated * by the host kernel and is
* retrieved via tap_get_mac().
*/
if (tap_get_mac(name, mac) < 0) {
dbg("Tap mac query failed.\n");
pico_tap_destroy((struct pico_device *)tap);
return NULL;
}
/* To act as a second endpoint in the same subnet, the picoTCP
* app using the tap device must have a different mac address.
* For simplicity, we just add 1 to the last byte of the linux
* endpoint so the two addresses are consecutive.
*/
mac[5]++;
if( 0 != pico_device_init((struct pico_device *)tap, name, mac)) {