2006-06-17 22:41:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, 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.
|
2008-10-14 09:40:56 +00:00
|
|
|
*/
|
2011-12-02 16:07:27 +00:00
|
|
|
|
2008-10-14 09:40:56 +00:00
|
|
|
/**
|
|
|
|
* \file
|
2017-06-22 16:27:04 +00:00
|
|
|
* Core of the TCP/IP stack, handles input/output/routing
|
2008-10-15 07:59:34 +00:00
|
|
|
*
|
2008-10-14 09:40:56 +00:00
|
|
|
* \author Adam Dunkels <adam@sics.se>\author
|
|
|
|
* \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
|
|
|
|
* \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
|
2006-06-17 22:41:10 +00:00
|
|
|
*/
|
|
|
|
|
2011-12-02 16:07:27 +00:00
|
|
|
#include "contiki-net.h"
|
2017-09-22 13:06:44 +00:00
|
|
|
#include "net/ipv6/uip-packetqueue.h"
|
2010-10-29 05:36:07 +00:00
|
|
|
|
2013-11-22 08:17:54 +00:00
|
|
|
#include "net/ipv6/uip-nd6.h"
|
|
|
|
#include "net/ipv6/uip-ds6.h"
|
2017-09-08 13:48:39 +00:00
|
|
|
#include "net/linkaddr.h"
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2016-02-01 17:02:33 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2017-06-22 07:49:01 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL_LITE == 1
|
|
|
|
#include "net/rpl-lite/rpl.h"
|
|
|
|
#else /* UIP_CONF_IPV6_RPL_LITE == 1 */
|
2017-09-10 13:10:55 +00:00
|
|
|
#include "net/rpl-classic/rpl.h"
|
|
|
|
#include "net/rpl-classic/rpl-private.h"
|
2017-06-22 07:49:01 +00:00
|
|
|
#endif /* UIP_CONF_IPV6_RPL_LITE == 1 */
|
2016-02-01 17:02:33 +00:00
|
|
|
#endif
|
|
|
|
|
2011-12-02 16:07:27 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-06-20 09:51:42 +00:00
|
|
|
/* Log configuration */
|
|
|
|
#include "sys/log.h"
|
2017-06-21 14:16:49 +00:00
|
|
|
#define LOG_MODULE "TCP/IP"
|
2017-07-15 13:19:09 +00:00
|
|
|
#define LOG_LEVEL LOG_LEVEL_TCPIP
|
2008-10-14 09:40:56 +00:00
|
|
|
|
|
|
|
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[UIP_LLIPH_LEN + uip_ext_len])
|
|
|
|
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
|
2010-02-09 12:58:53 +00:00
|
|
|
#define UIP_TCP_BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2010-03-16 15:35:03 +00:00
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
2010-03-16 15:41:00 +00:00
|
|
|
extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
|
2010-03-16 15:35:03 +00:00
|
|
|
#endif
|
2011-12-02 14:54:49 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
process_event_t tcpip_event;
|
2010-02-05 12:43:36 +00:00
|
|
|
#if UIP_CONF_ICMP6
|
|
|
|
process_event_t tcpip_icmp6_event;
|
|
|
|
#endif /* UIP_CONF_ICMP6 */
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2011-12-02 16:07:27 +00:00
|
|
|
/* Periodic check of active connections. */
|
2008-10-14 09:40:56 +00:00
|
|
|
static struct etimer periodic;
|
|
|
|
|
2017-06-16 15:02:42 +00:00
|
|
|
#if UIP_CONF_IPV6_REASSEMBLY
|
2011-12-02 16:07:27 +00:00
|
|
|
/* Timer for reassembly. */
|
2008-10-14 09:40:56 +00:00
|
|
|
extern struct etimer uip_reass_timer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UIP_TCP
|
2006-06-17 22:41:10 +00:00
|
|
|
/**
|
|
|
|
* \internal Structure for holding a TCP port and a process ID.
|
|
|
|
*/
|
|
|
|
struct listenport {
|
2012-02-17 22:45:13 +00:00
|
|
|
uint16_t port;
|
2006-06-17 22:41:10 +00:00
|
|
|
struct process *p;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct internal_state {
|
|
|
|
struct listenport listenports[UIP_LISTENPORTS];
|
|
|
|
struct process *p;
|
|
|
|
} s;
|
2008-10-14 09:40:56 +00:00
|
|
|
#endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
TCP_POLL,
|
|
|
|
UDP_POLL,
|
|
|
|
PACKET_INPUT
|
|
|
|
};
|
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING
|
2017-06-10 12:35:39 +00:00
|
|
|
#define NEXTHOP_NON_STORING(addr) rpl_ext_header_srh_get_next_hop(addr)
|
2016-02-25 16:18:48 +00:00
|
|
|
#else
|
|
|
|
#define NEXTHOP_NON_STORING(addr) 0
|
|
|
|
#endif
|
2015-08-11 15:32:42 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
init_appstate(uip_tcp_appstate_t *as, void *state)
|
|
|
|
{
|
|
|
|
as->p = PROCESS_CURRENT();
|
|
|
|
as->state = state;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2009-02-20 21:21:56 +00:00
|
|
|
|
2012-02-17 22:45:13 +00:00
|
|
|
uint8_t
|
2013-11-16 13:42:57 +00:00
|
|
|
tcpip_output(const uip_lladdr_t *a)
|
2009-02-20 21:21:56 +00:00
|
|
|
{
|
2010-01-25 13:37:05 +00:00
|
|
|
int ret;
|
2017-10-07 14:46:21 +00:00
|
|
|
if(netstack_process_ip_callback(NETSTACK_IP_OUTPUT, (const linkaddr_t *)a) ==
|
|
|
|
NETSTACK_IP_PROCESS) {
|
|
|
|
ret = NETSTACK_NETWORK.output((const linkaddr_t *) a);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
/* Ok, ignore and drop... */
|
|
|
|
uip_clear_buf();
|
|
|
|
return 0;
|
2009-02-20 21:21:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
PROCESS(tcpip_process, "TCP/IP stack");
|
|
|
|
|
2010-02-09 12:58:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2017-06-16 15:02:42 +00:00
|
|
|
#if UIP_TCP
|
2010-02-09 12:58:53 +00:00
|
|
|
static void
|
|
|
|
start_periodic_tcp_timer(void)
|
|
|
|
{
|
|
|
|
if(etimer_expired(&periodic)) {
|
|
|
|
etimer_restart(&periodic);
|
|
|
|
}
|
|
|
|
}
|
2017-06-16 15:02:42 +00:00
|
|
|
#endif /* UIP_TCP */
|
2010-02-09 12:58:53 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
check_for_tcp_syn(void)
|
|
|
|
{
|
2017-06-16 15:02:42 +00:00
|
|
|
#if UIP_TCP
|
2010-02-09 12:58:53 +00:00
|
|
|
/* This is a hack that is needed to start the periodic TCP timer if
|
|
|
|
an incoming packet contains a SYN: since uIP does not inform the
|
|
|
|
application if a SYN arrives, we have no other way of starting
|
|
|
|
this timer. This function is called for every incoming IP packet
|
|
|
|
to check for such SYNs. */
|
|
|
|
#define TCP_SYN 0x02
|
|
|
|
if(UIP_IP_BUF->proto == UIP_PROTO_TCP &&
|
|
|
|
(UIP_TCP_BUF->flags & TCP_SYN) == TCP_SYN) {
|
|
|
|
start_periodic_tcp_timer();
|
|
|
|
}
|
2017-06-16 15:02:42 +00:00
|
|
|
#endif /* UIP_TCP */
|
2010-02-09 12:58:53 +00:00
|
|
|
}
|
2006-06-17 22:41:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
packet_input(void)
|
|
|
|
{
|
|
|
|
if(uip_len > 0) {
|
2010-02-09 12:58:53 +00:00
|
|
|
check_for_tcp_syn();
|
2008-03-29 15:19:25 +00:00
|
|
|
uip_input();
|
|
|
|
if(uip_len > 0) {
|
2008-10-14 09:40:56 +00:00
|
|
|
tcpip_ipv6_output();
|
2008-03-29 15:19:25 +00:00
|
|
|
}
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-10-14 09:40:56 +00:00
|
|
|
#if UIP_TCP
|
2007-12-08 23:06:02 +00:00
|
|
|
#if UIP_ACTIVE_OPEN
|
2006-06-17 22:41:10 +00:00
|
|
|
struct uip_conn *
|
2015-03-26 07:18:09 +00:00
|
|
|
tcp_connect(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
|
|
|
struct uip_conn *c;
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2006-08-10 16:43:32 +00:00
|
|
|
c = uip_connect(ripaddr, port);
|
2006-06-17 22:41:10 +00:00
|
|
|
if(c == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:32:42 +00:00
|
|
|
init_appstate(&c->appstate, appstate);
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
tcpip_poll_tcp(c);
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
return c;
|
|
|
|
}
|
2007-12-08 23:06:02 +00:00
|
|
|
#endif /* UIP_ACTIVE_OPEN */
|
2006-06-17 22:41:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2012-02-17 22:45:13 +00:00
|
|
|
tcp_unlisten(uint16_t port)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
2015-08-12 15:51:26 +00:00
|
|
|
unsigned char i;
|
2006-06-17 22:41:10 +00:00
|
|
|
struct listenport *l;
|
|
|
|
|
|
|
|
l = s.listenports;
|
|
|
|
for(i = 0; i < UIP_LISTENPORTS; ++i) {
|
|
|
|
if(l->port == port &&
|
|
|
|
l->p == PROCESS_CURRENT()) {
|
|
|
|
l->port = 0;
|
|
|
|
uip_unlisten(port);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2012-02-17 22:45:13 +00:00
|
|
|
tcp_listen(uint16_t port)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
2015-08-12 15:51:26 +00:00
|
|
|
unsigned char i;
|
2006-06-17 22:41:10 +00:00
|
|
|
struct listenport *l;
|
|
|
|
|
|
|
|
l = s.listenports;
|
|
|
|
for(i = 0; i < UIP_LISTENPORTS; ++i) {
|
|
|
|
if(l->port == 0) {
|
|
|
|
l->port = port;
|
|
|
|
l->p = PROCESS_CURRENT();
|
|
|
|
uip_listen(port);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2015-08-11 15:32:42 +00:00
|
|
|
tcp_attach(struct uip_conn *conn, void *appstate)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
2015-08-11 15:32:42 +00:00
|
|
|
init_appstate(&conn->appstate, appstate);
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
2008-10-14 09:40:56 +00:00
|
|
|
#endif /* UIP_TCP */
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-09-29 03:54:18 +00:00
|
|
|
#if UIP_UDP
|
2006-06-17 22:41:10 +00:00
|
|
|
void
|
2015-08-11 15:32:42 +00:00
|
|
|
udp_attach(struct uip_udp_conn *conn, void *appstate)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
2015-08-11 15:32:42 +00:00
|
|
|
init_appstate(&conn->appstate, appstate);
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
struct uip_udp_conn *
|
2012-02-17 22:45:13 +00:00
|
|
|
udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
2015-08-11 15:32:42 +00:00
|
|
|
struct uip_udp_conn *c = uip_udp_new(ripaddr, port);
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
if(c == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-08-11 15:32:42 +00:00
|
|
|
init_appstate(&c->appstate, appstate);
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
struct uip_udp_conn *
|
2012-02-17 22:45:13 +00:00
|
|
|
udp_broadcast_new(uint16_t port, void *appstate)
|
2006-06-17 22:41:10 +00:00
|
|
|
{
|
|
|
|
uip_ipaddr_t addr;
|
|
|
|
struct uip_udp_conn *conn;
|
2009-04-13 19:54:07 +00:00
|
|
|
|
|
|
|
uip_create_linklocal_allnodes_mcast(&addr);
|
2017-06-16 15:02:42 +00:00
|
|
|
|
2006-08-09 16:13:39 +00:00
|
|
|
conn = udp_new(&addr, port, appstate);
|
2006-06-17 22:41:10 +00:00
|
|
|
if(conn != NULL) {
|
|
|
|
udp_bind(conn, port);
|
|
|
|
}
|
|
|
|
return conn;
|
|
|
|
}
|
2007-09-29 03:54:18 +00:00
|
|
|
#endif /* UIP_UDP */
|
2008-10-14 09:40:56 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#if UIP_CONF_ICMP6
|
2012-02-17 22:45:13 +00:00
|
|
|
uint8_t
|
2008-10-14 09:40:56 +00:00
|
|
|
icmp6_new(void *appstate) {
|
|
|
|
if(uip_icmp6_conns.appstate.p == PROCESS_NONE) {
|
2015-08-11 15:32:42 +00:00
|
|
|
init_appstate(&uip_icmp6_conns.appstate, appstate);
|
2008-10-14 09:40:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-01-25 13:37:05 +00:00
|
|
|
void
|
2012-02-17 22:45:13 +00:00
|
|
|
tcpip_icmp6_call(uint8_t type)
|
2010-01-25 13:37:05 +00:00
|
|
|
{
|
|
|
|
if(uip_icmp6_conns.appstate.p != PROCESS_NONE) {
|
2010-02-05 12:43:36 +00:00
|
|
|
/* XXX: This is a hack that needs to be updated. Passing a pointer (&type)
|
|
|
|
like this only works with process_post_synch. */
|
|
|
|
process_post_synch(uip_icmp6_conns.appstate.p, tcpip_icmp6_event, &type);
|
2010-01-25 13:37:05 +00:00
|
|
|
}
|
2008-10-14 09:40:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-01-25 13:37:05 +00:00
|
|
|
#endif /* UIP_CONF_ICMP6 */
|
2006-06-17 22:41:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
eventhandler(process_event_t ev, process_data_t data)
|
|
|
|
{
|
2008-10-15 07:59:34 +00:00
|
|
|
#if UIP_TCP
|
2015-08-12 15:51:26 +00:00
|
|
|
unsigned char i;
|
2006-06-17 22:41:10 +00:00
|
|
|
register struct listenport *l;
|
2008-10-15 07:59:34 +00:00
|
|
|
#endif /*UIP_TCP*/
|
2006-06-17 22:41:10 +00:00
|
|
|
struct process *p;
|
2012-11-26 18:47:11 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
switch(ev) {
|
2016-04-22 19:41:03 +00:00
|
|
|
case PROCESS_EVENT_EXITED:
|
|
|
|
/* This is the event we get if a process has exited. We go through
|
2008-10-14 09:40:56 +00:00
|
|
|
the TCP/IP tables to see if this process had any open
|
|
|
|
connections or listening TCP ports. If so, we'll close those
|
|
|
|
connections. */
|
|
|
|
|
2016-04-22 19:41:03 +00:00
|
|
|
p = (struct process *)data;
|
2008-10-15 07:59:34 +00:00
|
|
|
#if UIP_TCP
|
2016-04-22 19:41:03 +00:00
|
|
|
l = s.listenports;
|
|
|
|
for(i = 0; i < UIP_LISTENPORTS; ++i) {
|
|
|
|
if(l->p == p) {
|
|
|
|
uip_unlisten(l->port);
|
|
|
|
l->port = 0;
|
|
|
|
l->p = PROCESS_NONE;
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
2016-04-22 19:41:03 +00:00
|
|
|
++l;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
struct uip_conn *cptr;
|
|
|
|
|
2017-06-23 19:26:59 +00:00
|
|
|
for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_TCP_CONNS]; ++cptr) {
|
2016-04-22 19:41:03 +00:00
|
|
|
if(cptr->appstate.p == p) {
|
|
|
|
cptr->appstate.p = PROCESS_NONE;
|
|
|
|
cptr->tcpstateflags = UIP_CLOSED;
|
2008-10-14 09:40:56 +00:00
|
|
|
}
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
2016-04-22 19:41:03 +00:00
|
|
|
}
|
2008-10-15 07:59:34 +00:00
|
|
|
#endif /* UIP_TCP */
|
2006-06-17 22:41:10 +00:00
|
|
|
#if UIP_UDP
|
2016-04-22 19:41:03 +00:00
|
|
|
{
|
|
|
|
struct uip_udp_conn *cptr;
|
2011-12-02 16:07:27 +00:00
|
|
|
|
2016-04-22 19:41:03 +00:00
|
|
|
for(cptr = &uip_udp_conns[0];
|
|
|
|
cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
|
|
|
|
if(cptr->appstate.p == p) {
|
|
|
|
cptr->lport = 0;
|
2008-10-14 09:40:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-22 19:41:03 +00:00
|
|
|
}
|
2006-06-17 22:41:10 +00:00
|
|
|
#endif /* UIP_UDP */
|
2016-04-22 19:41:03 +00:00
|
|
|
break;
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2016-04-22 19:41:03 +00:00
|
|
|
case PROCESS_EVENT_TIMER:
|
|
|
|
/* We get this event if one of our timers have expired. */
|
|
|
|
{
|
|
|
|
/* Check the clock so see if we should call the periodic uIP
|
2008-10-15 07:59:34 +00:00
|
|
|
processing. */
|
2016-04-22 19:41:03 +00:00
|
|
|
if(data == &periodic &&
|
|
|
|
etimer_expired(&periodic)) {
|
2008-10-14 09:40:56 +00:00
|
|
|
#if UIP_TCP
|
2017-06-23 19:26:59 +00:00
|
|
|
for(i = 0; i < UIP_TCP_CONNS; ++i) {
|
2016-04-22 19:41:03 +00:00
|
|
|
if(uip_conn_active(i)) {
|
|
|
|
/* Only restart the timer if there are active
|
2008-10-14 09:40:56 +00:00
|
|
|
connections. */
|
2016-04-22 19:41:03 +00:00
|
|
|
etimer_restart(&periodic);
|
|
|
|
uip_periodic(i);
|
|
|
|
tcpip_ipv6_output();
|
|
|
|
}
|
|
|
|
}
|
2008-10-15 07:59:34 +00:00
|
|
|
#endif /* UIP_TCP */
|
2016-04-22 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
2008-10-14 09:40:56 +00:00
|
|
|
#if UIP_CONF_IPV6_REASSEMBLY
|
2016-04-22 19:41:03 +00:00
|
|
|
/*
|
|
|
|
* check the timer for reassembly
|
|
|
|
*/
|
|
|
|
if(data == &uip_reass_timer &&
|
|
|
|
etimer_expired(&uip_reass_timer)) {
|
|
|
|
uip_reass_over();
|
|
|
|
tcpip_ipv6_output();
|
|
|
|
}
|
2008-10-14 09:40:56 +00:00
|
|
|
#endif /* UIP_CONF_IPV6_REASSEMBLY */
|
2016-04-22 19:41:03 +00:00
|
|
|
/*
|
|
|
|
* check the different timers for neighbor discovery and
|
|
|
|
* stateless autoconfiguration
|
|
|
|
*/
|
|
|
|
/*if(data == &uip_ds6_timer_periodic &&
|
2011-07-11 10:04:52 +00:00
|
|
|
etimer_expired(&uip_ds6_timer_periodic)) {
|
|
|
|
uip_ds6_periodic();
|
2008-10-14 09:40:56 +00:00
|
|
|
tcpip_ipv6_output();
|
2010-03-15 16:41:24 +00:00
|
|
|
}*/
|
2011-12-02 16:07:27 +00:00
|
|
|
#if !UIP_CONF_ROUTER
|
2016-04-22 19:41:03 +00:00
|
|
|
if(data == &uip_ds6_timer_rs &&
|
|
|
|
etimer_expired(&uip_ds6_timer_rs)) {
|
|
|
|
uip_ds6_send_rs();
|
|
|
|
tcpip_ipv6_output();
|
|
|
|
}
|
2010-03-15 16:41:24 +00:00
|
|
|
#endif /* !UIP_CONF_ROUTER */
|
2016-04-22 19:41:03 +00:00
|
|
|
if(data == &uip_ds6_timer_periodic &&
|
|
|
|
etimer_expired(&uip_ds6_timer_periodic)) {
|
|
|
|
uip_ds6_periodic();
|
|
|
|
tcpip_ipv6_output();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-10-14 09:40:56 +00:00
|
|
|
#if UIP_TCP
|
2016-04-22 19:41:03 +00:00
|
|
|
case TCP_POLL:
|
|
|
|
if(data != NULL) {
|
|
|
|
uip_poll_conn(data);
|
|
|
|
tcpip_ipv6_output();
|
|
|
|
/* Start the periodic polling, if it isn't already active. */
|
|
|
|
start_periodic_tcp_timer();
|
|
|
|
}
|
|
|
|
break;
|
2008-10-14 09:40:56 +00:00
|
|
|
#endif /* UIP_TCP */
|
2007-09-29 03:54:18 +00:00
|
|
|
#if UIP_UDP
|
2016-04-22 19:41:03 +00:00
|
|
|
case UDP_POLL:
|
|
|
|
if(data != NULL) {
|
|
|
|
uip_udp_periodic_conn(data);
|
|
|
|
tcpip_ipv6_output();
|
|
|
|
}
|
|
|
|
break;
|
2007-09-29 03:54:18 +00:00
|
|
|
#endif /* UIP_UDP */
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2016-04-22 19:41:03 +00:00
|
|
|
case PACKET_INPUT:
|
|
|
|
packet_input();
|
|
|
|
break;
|
2006-06-17 22:41:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
tcpip_input(void)
|
|
|
|
{
|
2017-10-07 14:46:21 +00:00
|
|
|
if(netstack_process_ip_callback(NETSTACK_IP_INPUT, NULL) ==
|
2017-09-15 13:48:25 +00:00
|
|
|
NETSTACK_IP_PROCESS) {
|
|
|
|
process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
|
|
|
|
} /* else - do nothing and drop */
|
2015-06-15 08:25:58 +00:00
|
|
|
uip_clear_buf();
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-25 16:18:48 +00:00
|
|
|
extern void remove_ext_hdr(void);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
output_fallback(void)
|
2008-10-14 09:40:56 +00:00
|
|
|
{
|
2016-02-25 16:18:48 +00:00
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_INFO("fallback: removing ext hdrs & setting proto %d %d\n",
|
2016-02-25 16:18:48 +00:00
|
|
|
uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40));
|
|
|
|
if(uip_ext_len > 0) {
|
|
|
|
uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40);
|
|
|
|
remove_ext_hdr();
|
|
|
|
/* This should be copied from the ext header... */
|
|
|
|
UIP_IP_BUF->proto = proto;
|
|
|
|
}
|
|
|
|
/* Inform the other end that the destination is not reachable. If it's
|
|
|
|
* not informed routes might get lost unexpectedly until there's a need
|
|
|
|
* to send a new packet to the peer */
|
|
|
|
if(UIP_FALLBACK_INTERFACE.output() < 0) {
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_ERR("fallback: output error. Reporting DST UNREACH\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
uip_icmp6_error_output(ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR, 0);
|
|
|
|
uip_flags = 0;
|
|
|
|
tcpip_ipv6_output();
|
2008-10-14 09:40:56 +00:00
|
|
|
return;
|
2010-10-24 21:05:42 +00:00
|
|
|
}
|
2016-02-25 16:18:48 +00:00
|
|
|
#else
|
2017-06-10 12:35:39 +00:00
|
|
|
LOG_ERR("output: destination off-link and no default route\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
#endif /* !UIP_FALLBACK_INTERFACE */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
drop_route(uip_ds6_route_t *route)
|
|
|
|
{
|
2017-06-10 12:35:39 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0)
|
2011-12-02 16:07:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
/* If we are running RPL, and if we are the root of the
|
|
|
|
network, we'll trigger a global repair before we remove
|
|
|
|
the route. */
|
2017-06-10 12:35:39 +00:00
|
|
|
rpl_dag_t *dag;
|
2016-02-25 16:18:48 +00:00
|
|
|
dag = (rpl_dag_t *)route->state.dag;
|
2017-06-10 12:35:39 +00:00
|
|
|
if(dag != NULL && dag->instance != NULL) {
|
|
|
|
rpl_repair_root(dag->instance->instance_id);
|
2008-10-14 09:40:56 +00:00
|
|
|
}
|
2017-06-10 12:35:39 +00:00
|
|
|
#endif /* UIP_CONF_IPV6_RPL && (UIP_CONF_IPV6_RPL_LITE == 0) */
|
2016-02-25 16:18:48 +00:00
|
|
|
uip_ds6_route_rm(route);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
annotate_transmission(uip_ipaddr_t *nexthop)
|
|
|
|
{
|
|
|
|
#if TCPIP_CONF_ANNOTATE_TRANSMISSIONS
|
|
|
|
static uint8_t annotate_last;
|
|
|
|
static uint8_t annotate_has_last = 0;
|
2011-12-02 16:07:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(annotate_has_last) {
|
|
|
|
printf("#L %u 0; red\n", annotate_last);
|
2008-10-14 09:40:56 +00:00
|
|
|
}
|
2016-02-25 16:18:48 +00:00
|
|
|
printf("#L %u 1; red\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
|
|
|
|
annotate_last = nexthop->u8[sizeof(uip_ipaddr_t) - 1];
|
|
|
|
annotate_has_last = 1;
|
|
|
|
#endif /* TCPIP_CONF_ANNOTATE_TRANSMISSIONS */
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static uip_ipaddr_t*
|
|
|
|
get_nexthop(uip_ipaddr_t *addr)
|
|
|
|
{
|
|
|
|
uip_ipaddr_t *nexthop;
|
|
|
|
uip_ds6_route_t *route;
|
2011-12-02 16:07:27 +00:00
|
|
|
|
2017-06-23 19:12:36 +00:00
|
|
|
LOG_INFO("output: processing packet from ");
|
|
|
|
LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr);
|
|
|
|
LOG_INFO_(" to ");
|
2017-06-10 12:35:39 +00:00
|
|
|
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_INFO_("\n");
|
2017-06-10 12:35:39 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(NEXTHOP_NON_STORING(addr)) {
|
2017-06-21 16:10:55 +00:00
|
|
|
LOG_INFO("output: selected next hop from SRH: ");
|
|
|
|
LOG_INFO_6ADDR(addr);
|
2017-06-23 19:12:36 +00:00
|
|
|
LOG_INFO_("\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
return addr;
|
2016-06-13 10:04:19 +00:00
|
|
|
}
|
2016-02-03 15:30:59 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
/* We first check if the destination address is on our immediate
|
|
|
|
link. If so, we simply use the destination address as our
|
|
|
|
nexthop address. */
|
2017-06-10 12:35:39 +00:00
|
|
|
if(uip_ds6_is_addr_onlink(&UIP_IP_BUF->destipaddr)) {
|
2017-06-21 16:10:55 +00:00
|
|
|
LOG_INFO("output: destination is on link\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
return &UIP_IP_BUF->destipaddr;
|
|
|
|
}
|
2016-02-01 17:02:33 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
/* Check if we have a route to the destination address. */
|
|
|
|
route = uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr);
|
|
|
|
|
|
|
|
/* No route was found - we send to the default route instead. */
|
|
|
|
if(route == NULL) {
|
|
|
|
nexthop = uip_ds6_defrt_choose();
|
|
|
|
if(nexthop == NULL) {
|
|
|
|
output_fallback();
|
2017-06-21 16:10:55 +00:00
|
|
|
} else {
|
|
|
|
LOG_INFO("output: no route found, using default route: ");
|
|
|
|
LOG_INFO_6ADDR(nexthop);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_INFO_("\n");
|
2016-02-01 17:02:33 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
} else {
|
|
|
|
/* A route was found, so we look up the nexthop neighbor for
|
|
|
|
the route. */
|
|
|
|
nexthop = uip_ds6_route_nexthop(route);
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
/* If the nexthop is dead, for example because the neighbor
|
|
|
|
never responded to link-layer acks, we drop its route. */
|
|
|
|
if(nexthop == NULL) {
|
2017-06-21 16:10:55 +00:00
|
|
|
LOG_ERR("output: found dead route\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
drop_route(route);
|
|
|
|
/* We don't have a nexthop to send the packet to, so we drop
|
|
|
|
it. */
|
2017-06-21 16:10:55 +00:00
|
|
|
} else {
|
|
|
|
LOG_INFO("output: found next hop from routing table: ");
|
|
|
|
LOG_INFO_6ADDR(nexthop);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_INFO_("\n");
|
2016-02-01 17:02:33 +00:00
|
|
|
}
|
2016-02-25 16:18:48 +00:00
|
|
|
}
|
2016-02-01 17:02:33 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
return nexthop;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2015-08-11 15:32:42 +00:00
|
|
|
#if UIP_ND6_SEND_NS
|
2016-02-25 16:18:48 +00:00
|
|
|
static int
|
|
|
|
queue_packet(uip_ds6_nbr_t *nbr)
|
|
|
|
{
|
|
|
|
/* Copy outgoing pkt in the queuing buffer for later transmit. */
|
|
|
|
#if UIP_CONF_IPV6_QUEUE_PKT
|
|
|
|
if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
|
|
|
|
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
|
|
|
|
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
send_queued(uip_ds6_nbr_t *nbr)
|
|
|
|
{
|
|
|
|
#if UIP_CONF_IPV6_QUEUE_PKT
|
|
|
|
/*
|
|
|
|
* Send the queued packets from here, may not be 100% perfect though.
|
|
|
|
* This happens in a few cases, for example when instead of receiving a
|
|
|
|
* NA after sendiong a NS, you receive a NS with SLLAO: the entry moves
|
|
|
|
* to STALE, and you must both send a NA and the queued packet.
|
|
|
|
*/
|
|
|
|
if(uip_packetqueue_buflen(&nbr->packethandle) != 0) {
|
|
|
|
uip_len = uip_packetqueue_buflen(&nbr->packethandle);
|
|
|
|
memcpy(UIP_IP_BUF, uip_packetqueue_buf(&nbr->packethandle), uip_len);
|
|
|
|
uip_packetqueue_free(&nbr->packethandle);
|
|
|
|
tcpip_output(uip_ds6_nbr_get_ll(nbr));
|
|
|
|
}
|
|
|
|
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
send_nd6_ns(uip_ipaddr_t *nexthop)
|
|
|
|
{
|
|
|
|
int err = 1;
|
|
|
|
|
2015-08-11 15:32:42 +00:00
|
|
|
#if UIP_ND6_SEND_NS
|
2016-02-25 16:18:48 +00:00
|
|
|
uip_ds6_nbr_t *nbr = NULL;
|
|
|
|
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE, NBR_TABLE_REASON_IPV6_ND, NULL)) != NULL) {
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
queue_packet(nbr);
|
|
|
|
/* RFC4861, 7.2.2:
|
|
|
|
* "If the source address of the packet prompting the solicitation is the
|
|
|
|
* same as one of the addresses assigned to the outgoing interface, that
|
|
|
|
* address SHOULD be placed in the IP Source Address of the outgoing
|
|
|
|
* solicitation. Otherwise, any one of the addresses assigned to the
|
|
|
|
* interface should be used."*/
|
|
|
|
if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)){
|
|
|
|
uip_nd6_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbr->ipaddr);
|
|
|
|
} else {
|
|
|
|
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
|
|
|
|
nbr->nscount = 1;
|
|
|
|
/* Send the first NS try from here (multicast destination IP address). */
|
|
|
|
}
|
2010-03-16 15:35:03 +00:00
|
|
|
#else
|
2017-06-21 16:10:55 +00:00
|
|
|
LOG_ERR("output: neighbor not in cache: ");
|
2017-06-10 12:35:39 +00:00
|
|
|
LOG_ERR_6ADDR(nexthop);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_ERR_("\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
#endif
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
tcpip_ipv6_output(void)
|
|
|
|
{
|
|
|
|
uip_ipaddr_t ipaddr;
|
|
|
|
uip_ds6_nbr_t *nbr = NULL;
|
|
|
|
const uip_lladdr_t *linkaddr;
|
|
|
|
uip_ipaddr_t *nexthop;
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(uip_len == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(uip_len > UIP_LINK_MTU) {
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_ERR("output: Packet too big");
|
2016-02-25 16:18:48 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(uip_is_addr_unspecified(&UIP_IP_BUF->destipaddr)){
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_ERR("output: Destination address unspecified");
|
2016-02-25 16:18:48 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2015-08-11 15:32:42 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2017-06-10 12:35:39 +00:00
|
|
|
if(!rpl_ext_header_update()) {
|
2015-08-11 15:32:42 +00:00
|
|
|
/* Packet can not be forwarded */
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_ERR("output: RPL header update error\n");
|
2015-08-11 15:32:42 +00:00
|
|
|
uip_clear_buf();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* UIP_CONF_IPV6_RPL */
|
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
|
|
|
|
linkaddr = NULL;
|
|
|
|
goto send_packet;
|
|
|
|
}
|
2013-08-11 22:18:27 +00:00
|
|
|
|
2017-07-06 17:24:27 +00:00
|
|
|
/* We first check if the destination address is one of ours. There is no
|
|
|
|
* loopback interface -- instead, process this directly as incoming. */
|
|
|
|
if(uip_ds6_is_my_addr(&UIP_IP_BUF->destipaddr)) {
|
|
|
|
LOG_INFO("output: sending to ourself\n");
|
|
|
|
packet_input();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for a next hop */
|
2016-02-25 16:18:48 +00:00
|
|
|
if((nexthop = get_nexthop(&ipaddr)) == NULL) {
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
annotate_transmission(nexthop);
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
nbr = uip_ds6_nbr_lookup(nexthop);
|
2017-06-16 13:57:24 +00:00
|
|
|
|
|
|
|
#if UIP_ND6_AUTOFILL_NBR_CACHE
|
|
|
|
if(nbr == NULL) {
|
|
|
|
/* Neighbor not found in cache? Derive its link-layer address from it's
|
|
|
|
link-local IPv6, assuming it used autoconfiguration. This is not
|
|
|
|
standard-compliant but this is a convenient way to keep the
|
|
|
|
neighbor cache out of the way in cases ND is not used */
|
|
|
|
uip_lladdr_t lladdr;
|
|
|
|
uip_ds6_set_lladdr_from_iid(&lladdr, nexthop);
|
|
|
|
if((nbr = uip_ds6_nbr_add(nexthop, &lladdr,
|
2017-06-21 14:07:17 +00:00
|
|
|
0, NBR_REACHABLE, NBR_TABLE_REASON_IPV6_ND_AUTOFILL, NULL)) == NULL) {
|
2017-06-21 15:11:20 +00:00
|
|
|
LOG_ERR("output: failed to autofill neighbor cache for host ");
|
|
|
|
LOG_ERR_6ADDR(nexthop);
|
2017-06-29 14:44:56 +00:00
|
|
|
LOG_ERR_(", link-layer addr ");
|
|
|
|
LOG_ERR_LLADDR((linkaddr_t*)&lladdr);
|
2017-06-23 07:21:31 +00:00
|
|
|
LOG_ERR_("\n");
|
2017-06-16 13:57:24 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* UIP_ND6_AUTOFILL_NBR_CACHE */
|
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
if(nbr == NULL) {
|
|
|
|
if(send_nd6_ns(nexthop)) {
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_ERR("output: failed to add neighbor to cache\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
goto exit;
|
2008-10-14 09:40:56 +00:00
|
|
|
} else {
|
2015-08-11 15:32:42 +00:00
|
|
|
/* We're sending NS here instead of original packet */
|
2016-02-25 16:18:48 +00:00
|
|
|
goto send_packet;
|
|
|
|
}
|
|
|
|
}
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2015-08-11 15:32:42 +00:00
|
|
|
#if UIP_ND6_SEND_NS
|
2016-02-25 16:18:48 +00:00
|
|
|
if(nbr->state == NBR_INCOMPLETE) {
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_ERR("output: nbr cache entry incomplete\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
queue_packet(nbr);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
/* Send in parallel if we are running NUD (nbc state is either STALE,
|
|
|
|
DELAY, or PROBE). See RFC 4861, section 7.3.3 on node behavior. */
|
|
|
|
if(nbr->state == NBR_STALE) {
|
|
|
|
nbr->state = NBR_DELAY;
|
|
|
|
stimer_set(&nbr->reachable, UIP_ND6_DELAY_FIRST_PROBE_TIME);
|
|
|
|
nbr->nscount = 0;
|
2017-06-20 09:51:42 +00:00
|
|
|
LOG_INFO("output: nbr cache entry stale moving to delay\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
}
|
2015-08-11 15:32:42 +00:00
|
|
|
#endif /* UIP_ND6_SEND_NS */
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2016-02-25 16:18:48 +00:00
|
|
|
send_packet:
|
|
|
|
if(nbr) {
|
|
|
|
linkaddr = uip_ds6_nbr_get_ll(nbr);
|
|
|
|
} else {
|
|
|
|
linkaddr = NULL;
|
|
|
|
}
|
2008-10-14 09:40:56 +00:00
|
|
|
|
2017-06-23 19:12:36 +00:00
|
|
|
LOG_INFO("output: sending to ");
|
|
|
|
LOG_INFO_LLADDR((linkaddr_t *)linkaddr);
|
|
|
|
LOG_INFO_("\n");
|
2016-02-25 16:18:48 +00:00
|
|
|
tcpip_output(linkaddr);
|
|
|
|
|
|
|
|
if(nbr) {
|
|
|
|
send_queued(nbr);
|
2008-10-14 09:40:56 +00:00
|
|
|
}
|
2016-02-25 16:18:48 +00:00
|
|
|
|
|
|
|
exit:
|
2015-06-15 08:25:58 +00:00
|
|
|
uip_clear_buf();
|
2016-02-25 16:18:48 +00:00
|
|
|
return;
|
2008-10-14 09:40:56 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2007-09-29 03:54:18 +00:00
|
|
|
#if UIP_UDP
|
2006-06-17 22:41:10 +00:00
|
|
|
void
|
|
|
|
tcpip_poll_udp(struct uip_udp_conn *conn)
|
|
|
|
{
|
|
|
|
process_post(&tcpip_process, UDP_POLL, conn);
|
|
|
|
}
|
2007-09-29 03:54:18 +00:00
|
|
|
#endif /* UIP_UDP */
|
2006-06-17 22:41:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2008-10-14 09:40:56 +00:00
|
|
|
#if UIP_TCP
|
2006-06-17 22:41:10 +00:00
|
|
|
void
|
|
|
|
tcpip_poll_tcp(struct uip_conn *conn)
|
|
|
|
{
|
|
|
|
process_post(&tcpip_process, TCP_POLL, conn);
|
|
|
|
}
|
2008-10-14 09:40:56 +00:00
|
|
|
#endif /* UIP_TCP */
|
2006-06-17 22:41:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
tcpip_uipcall(void)
|
|
|
|
{
|
2013-03-06 13:32:36 +00:00
|
|
|
uip_udp_appstate_t *ts;
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2007-09-29 03:54:18 +00:00
|
|
|
#if UIP_UDP
|
2006-06-17 22:41:10 +00:00
|
|
|
if(uip_conn != NULL) {
|
|
|
|
ts = &uip_conn->appstate;
|
|
|
|
} else {
|
|
|
|
ts = &uip_udp_conn->appstate;
|
|
|
|
}
|
2007-09-29 03:54:18 +00:00
|
|
|
#else /* UIP_UDP */
|
|
|
|
ts = &uip_conn->appstate;
|
|
|
|
#endif /* UIP_UDP */
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2008-10-15 07:59:34 +00:00
|
|
|
#if UIP_TCP
|
2016-04-22 19:41:03 +00:00
|
|
|
{
|
|
|
|
unsigned char i;
|
|
|
|
struct listenport *l;
|
2015-08-12 15:51:26 +00:00
|
|
|
|
2016-04-22 19:41:03 +00:00
|
|
|
/* If this is a connection request for a listening port, we must
|
2008-10-15 07:59:34 +00:00
|
|
|
mark the connection with the right process ID. */
|
2016-04-22 19:41:03 +00:00
|
|
|
if(uip_connected()) {
|
|
|
|
l = &s.listenports[0];
|
|
|
|
for(i = 0; i < UIP_LISTENPORTS; ++i) {
|
|
|
|
if(l->port == uip_conn->lport &&
|
|
|
|
l->p != PROCESS_NONE) {
|
|
|
|
ts->p = l->p;
|
|
|
|
ts->state = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++l;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the periodic polling, if it isn't already active. */
|
|
|
|
start_periodic_tcp_timer();
|
|
|
|
}
|
|
|
|
}
|
2010-02-09 12:58:53 +00:00
|
|
|
#endif /* UIP_TCP */
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
if(ts->p != NULL) {
|
|
|
|
process_post_synch(ts->p, tcpip_event, ts->state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
PROCESS_THREAD(tcpip_process, ev, data)
|
|
|
|
{
|
|
|
|
PROCESS_BEGIN();
|
2015-08-12 15:51:26 +00:00
|
|
|
|
2008-10-14 09:40:56 +00:00
|
|
|
#if UIP_TCP
|
2015-08-11 15:32:42 +00:00
|
|
|
memset(s.listenports, 0, UIP_LISTENPORTS*sizeof(*(s.listenports)));
|
|
|
|
s.p = PROCESS_CURRENT();
|
2008-10-14 09:40:56 +00:00
|
|
|
#endif
|
2009-02-20 21:21:56 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
tcpip_event = process_alloc_event();
|
2010-02-05 12:43:36 +00:00
|
|
|
#if UIP_CONF_ICMP6
|
|
|
|
tcpip_icmp6_event = process_alloc_event();
|
|
|
|
#endif /* UIP_CONF_ICMP6 */
|
2010-02-09 12:58:53 +00:00
|
|
|
etimer_set(&periodic, CLOCK_SECOND / 2);
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
uip_init();
|
2010-03-16 15:35:03 +00:00
|
|
|
#ifdef UIP_FALLBACK_INTERFACE
|
|
|
|
UIP_FALLBACK_INTERFACE.init();
|
|
|
|
#endif
|
2016-04-22 19:41:03 +00:00
|
|
|
/* initialize RPL if configured for using RPL */
|
2017-06-16 15:02:42 +00:00
|
|
|
#if UIP_CONF_IPV6_RPL
|
2010-05-01 13:04:31 +00:00
|
|
|
rpl_init();
|
|
|
|
#endif /* UIP_CONF_IPV6_RPL */
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
while(1) {
|
|
|
|
PROCESS_YIELD();
|
|
|
|
eventhandler(ev, data);
|
|
|
|
}
|
2016-04-22 19:41:03 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
PROCESS_END();
|
|
|
|
}
|
2008-11-09 12:29:24 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|