Indent tcpip.c

This commit is contained in:
Simon Duquennoy 2016-04-22 21:41:03 +02:00 committed by Simon Duquennoy
parent 5b5f07ba52
commit 0296e6aba0

View File

@ -219,7 +219,7 @@ struct uip_conn *
tcp_connect(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate) tcp_connect(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
{ {
struct uip_conn *c; struct uip_conn *c;
c = uip_connect(ripaddr, port); c = uip_connect(ripaddr, port);
if(c == NULL) { if(c == NULL) {
return NULL; return NULL;
@ -227,9 +227,9 @@ tcp_connect(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
c->appstate.p = PROCESS_CURRENT(); c->appstate.p = PROCESS_CURRENT();
c->appstate.state = appstate; c->appstate.state = appstate;
tcpip_poll_tcp(c); tcpip_poll_tcp(c);
return c; return c;
} }
#endif /* UIP_ACTIVE_OPEN */ #endif /* UIP_ACTIVE_OPEN */
@ -300,7 +300,7 @@ udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
{ {
struct uip_udp_conn *c; struct uip_udp_conn *c;
uip_udp_appstate_t *s; uip_udp_appstate_t *s;
c = uip_udp_new(ripaddr, port); c = uip_udp_new(ripaddr, port);
if(c == NULL) { if(c == NULL) {
return NULL; return NULL;
@ -365,151 +365,151 @@ eventhandler(process_event_t ev, process_data_t data)
struct process *p; struct process *p;
switch(ev) { switch(ev) {
case PROCESS_EVENT_EXITED: case PROCESS_EVENT_EXITED:
/* This is the event we get if a process has exited. We go through /* This is the event we get if a process has exited. We go through
the TCP/IP tables to see if this process had any open the TCP/IP tables to see if this process had any open
connections or listening TCP ports. If so, we'll close those connections or listening TCP ports. If so, we'll close those
connections. */ connections. */
p = (struct process *)data; p = (struct process *)data;
#if UIP_TCP #if UIP_TCP
l = s.listenports; l = s.listenports;
for(i = 0; i < UIP_LISTENPORTS; ++i) { for(i = 0; i < UIP_LISTENPORTS; ++i) {
if(l->p == p) { if(l->p == p) {
uip_unlisten(l->port); uip_unlisten(l->port);
l->port = 0; l->port = 0;
l->p = PROCESS_NONE; l->p = PROCESS_NONE;
}
++l;
} }
++l;
{ }
struct uip_conn *cptr;
{
for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) { struct uip_conn *cptr;
if(cptr->appstate.p == p) {
cptr->appstate.p = PROCESS_NONE; for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) {
cptr->tcpstateflags = UIP_CLOSED; if(cptr->appstate.p == p) {
} cptr->appstate.p = PROCESS_NONE;
cptr->tcpstateflags = UIP_CLOSED;
} }
} }
}
#endif /* UIP_TCP */ #endif /* UIP_TCP */
#if UIP_UDP #if UIP_UDP
{ {
struct uip_udp_conn *cptr; struct uip_udp_conn *cptr;
for(cptr = &uip_udp_conns[0]; for(cptr = &uip_udp_conns[0];
cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) { cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
if(cptr->appstate.p == p) { if(cptr->appstate.p == p) {
cptr->lport = 0; cptr->lport = 0;
}
} }
} }
}
#endif /* UIP_UDP */ #endif /* UIP_UDP */
break; break;
case PROCESS_EVENT_TIMER: case PROCESS_EVENT_TIMER:
/* We get this event if one of our timers have expired. */ /* We get this event if one of our timers have expired. */
{ {
/* Check the clock so see if we should call the periodic uIP /* Check the clock so see if we should call the periodic uIP
processing. */ processing. */
if(data == &periodic && if(data == &periodic &&
etimer_expired(&periodic)) { etimer_expired(&periodic)) {
#if UIP_TCP #if UIP_TCP
for(i = 0; i < UIP_CONNS; ++i) { for(i = 0; i < UIP_CONNS; ++i) {
if(uip_conn_active(i)) { if(uip_conn_active(i)) {
/* Only restart the timer if there are active /* Only restart the timer if there are active
connections. */ connections. */
etimer_restart(&periodic); etimer_restart(&periodic);
uip_periodic(i); uip_periodic(i);
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output(); tcpip_ipv6_output();
#else #else
if(uip_len > 0) { if(uip_len > 0) {
PRINTF("tcpip_output from periodic len %d\n", uip_len); PRINTF("tcpip_output from periodic len %d\n", uip_len);
tcpip_output(); tcpip_output();
PRINTF("tcpip_output after periodic len %d\n", uip_len); PRINTF("tcpip_output after periodic len %d\n", uip_len);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
}
} }
#endif /* NETSTACK_CONF_WITH_IPV6 */
}
}
#endif /* UIP_TCP */ #endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD #if UIP_CONF_IP_FORWARD
uip_fw_periodic(); uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */ #endif /* UIP_CONF_IP_FORWARD */
} }
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
#if UIP_CONF_IPV6_REASSEMBLY #if UIP_CONF_IPV6_REASSEMBLY
/* /*
* check the timer for reassembly * check the timer for reassembly
*/ */
if(data == &uip_reass_timer && if(data == &uip_reass_timer &&
etimer_expired(&uip_reass_timer)) { etimer_expired(&uip_reass_timer)) {
uip_reass_over(); uip_reass_over();
tcpip_ipv6_output(); tcpip_ipv6_output();
} }
#endif /* UIP_CONF_IPV6_REASSEMBLY */ #endif /* UIP_CONF_IPV6_REASSEMBLY */
/* /*
* check the different timers for neighbor discovery and * check the different timers for neighbor discovery and
* stateless autoconfiguration * stateless autoconfiguration
*/ */
/*if(data == &uip_ds6_timer_periodic && /*if(data == &uip_ds6_timer_periodic &&
etimer_expired(&uip_ds6_timer_periodic)) { etimer_expired(&uip_ds6_timer_periodic)) {
uip_ds6_periodic(); uip_ds6_periodic();
tcpip_ipv6_output(); tcpip_ipv6_output();
}*/ }*/
#if !UIP_CONF_ROUTER #if !UIP_CONF_ROUTER
if(data == &uip_ds6_timer_rs && if(data == &uip_ds6_timer_rs &&
etimer_expired(&uip_ds6_timer_rs)) { etimer_expired(&uip_ds6_timer_rs)) {
uip_ds6_send_rs(); uip_ds6_send_rs();
tcpip_ipv6_output(); tcpip_ipv6_output();
} }
#endif /* !UIP_CONF_ROUTER */ #endif /* !UIP_CONF_ROUTER */
if(data == &uip_ds6_timer_periodic && if(data == &uip_ds6_timer_periodic &&
etimer_expired(&uip_ds6_timer_periodic)) { etimer_expired(&uip_ds6_timer_periodic)) {
uip_ds6_periodic(); uip_ds6_periodic();
tcpip_ipv6_output(); tcpip_ipv6_output();
} }
#endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* NETSTACK_CONF_WITH_IPV6 */
} }
break; break;
#if UIP_TCP #if UIP_TCP
case TCP_POLL: case TCP_POLL:
if(data != NULL) { if(data != NULL) {
uip_poll_conn(data); uip_poll_conn(data);
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output(); tcpip_ipv6_output();
#else /* NETSTACK_CONF_WITH_IPV6 */ #else /* NETSTACK_CONF_WITH_IPV6 */
if(uip_len > 0) { if(uip_len > 0) {
PRINTF("tcpip_output from tcp poll len %d\n", uip_len); PRINTF("tcpip_output from tcp poll len %d\n", uip_len);
tcpip_output(); tcpip_output();
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
/* Start the periodic polling, if it isn't already active. */
start_periodic_tcp_timer();
} }
break; #endif /* NETSTACK_CONF_WITH_IPV6 */
/* Start the periodic polling, if it isn't already active. */
start_periodic_tcp_timer();
}
break;
#endif /* UIP_TCP */ #endif /* UIP_TCP */
#if UIP_UDP #if UIP_UDP
case UDP_POLL: case UDP_POLL:
if(data != NULL) { if(data != NULL) {
uip_udp_periodic_conn(data); uip_udp_periodic_conn(data);
#if NETSTACK_CONF_WITH_IPV6 #if NETSTACK_CONF_WITH_IPV6
tcpip_ipv6_output(); tcpip_ipv6_output();
#else #else
if(uip_len > 0) { if(uip_len > 0) {
tcpip_output(); tcpip_output();
}
#endif /* UIP_UDP */
} }
break; #endif /* UIP_UDP */
}
break;
#endif /* UIP_UDP */ #endif /* UIP_UDP */
case PACKET_INPUT: case PACKET_INPUT:
packet_input(); packet_input();
break; break;
}; };
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -563,25 +563,25 @@ tcpip_ipv6_output(void)
nexthop = uip_ds6_defrt_choose(); nexthop = uip_ds6_defrt_choose();
if(nexthop == NULL) { if(nexthop == NULL) {
#ifdef UIP_FALLBACK_INTERFACE #ifdef UIP_FALLBACK_INTERFACE
PRINTF("FALLBACK: removing ext hdrs & setting proto %d %d\n", PRINTF("FALLBACK: removing ext hdrs & setting proto %d %d\n",
uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40)); uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40));
if(uip_ext_len > 0) { if(uip_ext_len > 0) {
extern void remove_ext_hdr(void); extern void remove_ext_hdr(void);
uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40); uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40);
remove_ext_hdr(); remove_ext_hdr();
/* This should be copied from the ext header... */ /* This should be copied from the ext header... */
UIP_IP_BUF->proto = proto; UIP_IP_BUF->proto = proto;
} }
/* Inform the other end that the destination is not reachable. If it's /* 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 * not informed routes might get lost unexpectedly until there's a need
* to send a new packet to the peer */ * to send a new packet to the peer */
if(UIP_FALLBACK_INTERFACE.output() < 0) { if(UIP_FALLBACK_INTERFACE.output() < 0) {
PRINTF("FALLBACK: output error. Reporting DST UNREACH\n"); PRINTF("FALLBACK: output error. Reporting DST UNREACH\n");
uip_icmp6_error_output(ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR, 0); uip_icmp6_error_output(ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR, 0);
uip_flags = 0; uip_flags = 0;
tcpip_ipv6_output(); tcpip_ipv6_output();
return; return;
} }
#else #else
PRINTF("tcpip_ipv6_output: Destination off-link but no route\n"); PRINTF("tcpip_ipv6_output: Destination off-link but no route\n");
#endif /* !UIP_FALLBACK_INTERFACE */ #endif /* !UIP_FALLBACK_INTERFACE */
@ -655,13 +655,13 @@ tcpip_ipv6_output(void)
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len); uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
} }
#endif #endif
/* RFC4861, 7.2.2: /* RFC4861, 7.2.2:
* "If the source address of the packet prompting the solicitation is the * "If the source address of the packet prompting the solicitation is the
* same as one of the addresses assigned to the outgoing interface, that * same as one of the addresses assigned to the outgoing interface, that
* address SHOULD be placed in the IP Source Address of the outgoing * address SHOULD be placed in the IP Source Address of the outgoing
* solicitation. Otherwise, any one of the addresses assigned to the * solicitation. Otherwise, any one of the addresses assigned to the
* interface should be used."*/ * interface should be used."*/
if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)){ if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)){
uip_nd6_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbr->ipaddr); uip_nd6_ns_output(&UIP_IP_BUF->srcipaddr, NULL, &nbr->ipaddr);
} else { } else {
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr); uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
@ -747,7 +747,7 @@ void
tcpip_uipcall(void) tcpip_uipcall(void)
{ {
uip_udp_appstate_t *ts; uip_udp_appstate_t *ts;
#if UIP_UDP #if UIP_UDP
if(uip_conn != NULL) { if(uip_conn != NULL) {
ts = &uip_conn->appstate; ts = &uip_conn->appstate;
@ -759,30 +759,30 @@ tcpip_uipcall(void)
#endif /* UIP_UDP */ #endif /* UIP_UDP */
#if UIP_TCP #if UIP_TCP
{ {
unsigned char i; unsigned char i;
struct listenport *l; struct listenport *l;
/* If this is a connection request for a listening port, we must /* If this is a connection request for a listening port, we must
mark the connection with the right process ID. */ mark the connection with the right process ID. */
if(uip_connected()) { if(uip_connected()) {
l = &s.listenports[0]; l = &s.listenports[0];
for(i = 0; i < UIP_LISTENPORTS; ++i) { for(i = 0; i < UIP_LISTENPORTS; ++i) {
if(l->port == uip_conn->lport && if(l->port == uip_conn->lport &&
l->p != PROCESS_NONE) { l->p != PROCESS_NONE) {
ts->p = l->p; ts->p = l->p;
ts->state = NULL; ts->state = NULL;
break; break;
} }
++l; ++l;
} }
/* Start the periodic polling, if it isn't already active. */ /* Start the periodic polling, if it isn't already active. */
start_periodic_tcp_timer(); start_periodic_tcp_timer();
} }
} }
#endif /* UIP_TCP */ #endif /* UIP_TCP */
if(ts->p != NULL) { if(ts->p != NULL) {
process_post_synch(ts->p, tcpip_event, ts->state); process_post_synch(ts->p, tcpip_event, ts->state);
} }
@ -793,14 +793,14 @@ PROCESS_THREAD(tcpip_process, ev, data)
PROCESS_BEGIN(); PROCESS_BEGIN();
#if UIP_TCP #if UIP_TCP
{ {
unsigned char i; unsigned char i;
for(i = 0; i < UIP_LISTENPORTS; ++i) { for(i = 0; i < UIP_LISTENPORTS; ++i) {
s.listenports[i].port = 0; s.listenports[i].port = 0;
} }
s.p = PROCESS_CURRENT(); s.p = PROCESS_CURRENT();
} }
#endif #endif
tcpip_event = process_alloc_event(); tcpip_event = process_alloc_event();
@ -813,7 +813,7 @@ PROCESS_THREAD(tcpip_process, ev, data)
#ifdef UIP_FALLBACK_INTERFACE #ifdef UIP_FALLBACK_INTERFACE
UIP_FALLBACK_INTERFACE.init(); UIP_FALLBACK_INTERFACE.init();
#endif #endif
/* initialize RPL if configured for using RPL */ /* initialize RPL if configured for using RPL */
#if NETSTACK_CONF_WITH_IPV6 && UIP_CONF_IPV6_RPL #if NETSTACK_CONF_WITH_IPV6 && UIP_CONF_IPV6_RPL
rpl_init(); rpl_init();
#endif /* UIP_CONF_IPV6_RPL */ #endif /* UIP_CONF_IPV6_RPL */
@ -822,7 +822,7 @@ PROCESS_THREAD(tcpip_process, ev, data)
PROCESS_YIELD(); PROCESS_YIELD();
eventhandler(ev, data); eventhandler(ev, data);
} }
PROCESS_END(); PROCESS_END();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/