Move function for clearing uip_buf to uipbuf module

This commit is contained in:
Simon Duquennoy 2018-10-17 23:33:02 +02:00
parent b4d45d7f56
commit d4bc09e002
17 changed files with 68 additions and 67 deletions

View File

@ -231,7 +231,7 @@ slip_input_callback(void)
if(!cmd_input(&uip_buf[UIP_LLH_LEN], uip_len)) {
cmd_send((uint8_t *)"EUnknown command", 16);
}
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static void

View File

@ -244,7 +244,7 @@ icmp_input()
/* If we enter here, we will definitely forward */
tcpip_ipv6_output();
}
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static void
@ -254,7 +254,7 @@ mcast_fwd(void *p)
uip_len = mcast_len;
UIP_IP_BUF->ttl--;
tcpip_output(NULL);
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static uint8_t

View File

@ -1376,7 +1376,7 @@ out()
drop:
uip_slen = 0;
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static uint8_t

View File

@ -84,7 +84,7 @@ mcast_fwd(void *p)
uip_len = mcast_len;
UIP_IP_BUF->ttl--;
tcpip_output(NULL);
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static uint8_t

View File

@ -125,7 +125,7 @@ tcpip_output(const uip_lladdr_t *a)
return ret;
} else {
/* Ok, ignore and drop... */
uip_clear_buf();
uipbuf_clear();
return 0;
}
}
@ -448,7 +448,7 @@ tcpip_input(void)
NETSTACK_IP_PROCESS) {
process_post_synch(&tcpip_process, PACKET_INPUT, NULL);
} /* else - do nothing and drop */
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static void
@ -652,7 +652,7 @@ tcpip_ipv6_output(void)
if(!NETSTACK_ROUTING.ext_header_update()) {
/* Packet can not be forwarded */
LOG_ERR("output: routing protocol extension header update error\n");
uip_clear_buf();
uipbuf_clear();
return;
}
@ -740,7 +740,7 @@ send_packet:
}
exit:
uip_clear_buf();
uipbuf_clear();
return;
}
/*---------------------------------------------------------------------------*/

View File

@ -156,7 +156,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
/* check if originating packet is not an ICMP error */
uint16_t shift;
if(uip_last_proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128) {
uip_clear_buf();
uipbuf_clear();
return;
}
@ -185,7 +185,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
/* the source should not be unspecified nor multicast, the check for
multicast is done in uip_process */
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)){
uip_clear_buf();
uipbuf_clear();
return;
}
@ -195,7 +195,7 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) {
if(type == ICMP6_PARAM_PROB && code == ICMP6_PARAMPROB_OPTION){
uip_ds6_select_src(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
} else {
uip_clear_buf();
uipbuf_clear();
return;
}
} else {
@ -286,7 +286,7 @@ echo_reply_input(void)
}
}
uip_clear_buf();
uipbuf_clear();
return;
}
/*---------------------------------------------------------------------------*/

View File

@ -314,7 +314,7 @@ create_na:
#if UIP_CONF_ROUTER
flags = flags | UIP_ND6_NA_FLAG_ROUTER;
#endif
uip_clear_buf();
uipbuf_clear();
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
@ -348,7 +348,7 @@ create_na:
return;
discard:
uip_clear_buf();
uipbuf_clear();
return;
}
#endif /* UIP_ND6_SEND_NA */
@ -359,7 +359,7 @@ discard:
void
uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
{
uip_clear_buf();
uipbuf_clear();
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
@ -388,7 +388,7 @@ uip_nd6_ns_output(uip_ipaddr_t * src, uip_ipaddr_t * dest, uip_ipaddr_t * tgt)
}
if (uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
LOG_ERR("Dropping NS due to no suitable source address\n");
uip_clear_buf();
uipbuf_clear();
return;
}
UIP_IP_BUF->len[1] =
@ -595,7 +595,7 @@ na_input(void)
#endif /*UIP_CONF_IPV6_QUEUE_PKT */
discard:
uip_clear_buf();
uipbuf_clear();
return;
}
#endif /* UIP_ND6_SEND_NS */
@ -691,7 +691,7 @@ rs_input(void)
uip_ds6_send_ra_sollicited();
discard:
uip_clear_buf();
uipbuf_clear();
return;
}
@ -1082,7 +1082,7 @@ ra_input(void)
#endif /*UIP_CONF_IPV6_QUEUE_PKT */
discard:
uip_clear_buf();
uipbuf_clear();
return;
}
#endif /* !UIP_CONF_ROUTER */

View File

@ -1340,19 +1340,6 @@ extern uint8_t uip_last_proto;
extern uint16_t uip_urglen, uip_surglen;
#endif /* UIP_URGDATA > 0 */
/*
* Clear uIP buffer
*
* This function clears the uIP buffer by reseting the uip_len and
* uip_ext_len pointers.
*/
#define uip_clear_buf() { \
uip_len = 0; \
uip_ext_len = 0; \
uip_last_proto = 0; \
uipbuf_clear_attr();\
}
/**
* Representation of a uIP TCP connection.
*

View File

@ -511,7 +511,7 @@ uip_remove_ext_hdr(void)
uip_ext_len, uip_len);
if(uip_len < UIP_IPH_LEN + uip_ext_len) {
LOG_ERR("uip_len too short compared to ext len\n");
uip_clear_buf();
uipbuf_clear();
return;
}
last_uip_ext_len = uip_ext_len;
@ -802,7 +802,7 @@ uip_reass_over(void)
* any RFC, we decided not to include it as it reduces the size of
* the packet.
*/
uip_clear_buf();
uipbuf_clear();
memcpy(UIP_IP_BUF, FBUF, UIP_IPH_LEN); /* copy the header for src
and dest address*/
uip_icmp6_error_output(ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_REASSEMBLY, 0);
@ -948,7 +948,7 @@ uip_process(uint8_t flag)
} else if(flag == UIP_TIMER) {
/* Reset the length variables. */
#if UIP_TCP
uip_clear_buf();
uipbuf_clear();
uip_slen = 0;
/* Increase the initial sequence number. */
@ -1473,7 +1473,7 @@ uip_process(uint8_t flag)
LOG_ERR("Unknown ICMPv6 message type/code %d\n", UIP_ICMP_BUF->type);
UIP_STAT(++uip_stat.icmp.drop);
UIP_STAT(++uip_stat.icmp.typeerr);
uip_clear_buf();
uipbuf_clear();
}
if(uip_len > 0) {
@ -1989,7 +1989,7 @@ uip_process(uint8_t flag)
uip_add_rcv_nxt(1);
uip_flags = UIP_CONNECTED | UIP_NEWDATA;
uip_connr->len = 0;
uip_clear_buf();
uipbuf_clear();
uip_slen = 0;
UIP_APPCALL();
goto appsend;
@ -2322,7 +2322,7 @@ uip_process(uint8_t flag)
return;
drop:
uip_clear_buf();
uipbuf_clear();
uip_ext_bitmap = 0;
uip_flags = 0;
return;

View File

@ -38,6 +38,15 @@
static uint16_t uipbuf_attrs[UIPBUF_ATTR_MAX];
/*---------------------------------------------------------------------------*/
void
uipbuf_clear(void)
{
uip_len = 0;
uip_ext_len = 0;
uip_last_proto = 0;
uipbuf_clear_attr();
}
/*---------------------------------------------------------------------------*/
bool
uipbuf_add_ext_hdr(int16_t len)

View File

@ -35,6 +35,11 @@
#include "contiki.h"
/**
* \brief Resets uIP buffer
*/
void uipbuf_clear(void);
/**
* \brief Update uip buffer length for addition of an extension header
* \param len The length of the new extension header

View File

@ -248,7 +248,7 @@ dis_input(void)
}
}
}
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void
@ -468,7 +468,7 @@ dio_input(void)
rpl_process_dio(&from, &dio);
discard:
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void
@ -807,7 +807,7 @@ dao_input_storing(void)
/* independent if we remove or not - ACK the request */
if(flags & RPL_DAO_K_FLAG) {
/* indicate that we accepted the no-path DAO */
uip_clear_buf();
uipbuf_clear();
dao_ack_output(instance, &dao_sender_addr, sequence,
RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
}
@ -897,7 +897,7 @@ fwd_dao:
}
if(should_ack) {
LOG_DBG("Sending DAO ACK\n");
uip_clear_buf();
uipbuf_clear();
dao_ack_output(instance, &dao_sender_addr, sequence,
RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
}
@ -1011,7 +1011,7 @@ dao_input_nonstoring(void)
if(flags & RPL_DAO_K_FLAG) {
LOG_DBG("Sending DAO ACK\n");
uip_clear_buf();
uipbuf_clear();
dao_ack_output(instance, &dao_sender_addr, sequence,
RPL_DAO_ACK_UNCONDITIONAL_ACCEPT);
}
@ -1044,7 +1044,7 @@ dao_input(void)
}
discard:
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
#if RPL_WITH_DAO_ACK
@ -1283,7 +1283,7 @@ dao_ack_input(void)
instance = rpl_get_instance(instance_id);
if(instance == NULL) {
uip_clear_buf();
uipbuf_clear();
return;
}
@ -1291,7 +1291,7 @@ dao_ack_input(void)
parent = rpl_find_parent(instance->current_dag, &UIP_IP_BUF->srcipaddr);
if(parent == NULL) {
/* not a known instance - drop the packet and ignore */
uip_clear_buf();
uipbuf_clear();
return;
}
} else {
@ -1300,7 +1300,7 @@ dao_ack_input(void)
if(instance->current_dag->rank == ROOT_RANK(instance)) {
LOG_DBG("DODAG root received a DAO ACK, ignoring it\n");
uip_clear_buf();
uipbuf_clear();
return;
}
@ -1360,7 +1360,7 @@ dao_ack_input(void)
}
}
#endif /* RPL_WITH_DAO_ACK */
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void

View File

@ -143,7 +143,7 @@ dis_input(void)
rpl_process_dis(&UIP_IP_BUF->srcipaddr, uip_is_addr_mcast(&UIP_IP_BUF->destipaddr));
discard:
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void
@ -325,7 +325,7 @@ dio_input(void)
rpl_process_dio(&from, &dio);
discard:
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void
@ -536,7 +536,7 @@ dao_input(void)
rpl_process_dao(&from, &dao);
discard:
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void
@ -647,7 +647,7 @@ dao_ack_input(void)
rpl_process_dao_ack(sequence, status);
discard:
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
void

View File

@ -57,7 +57,7 @@ input_callback(void)
/*PRINTF("SIN: %u\n", uip_len);*/
if(uip_buf[UIP_LLH_LEN] == '!') {
PRINTF("Got configuration message of type %c\n", uip_buf[UIP_LLH_LEN + 1]);
uip_clear_buf();
uipbuf_clear();
#if 0
if(uip_buf[UIP_LLH_LEN + 1] == 'P') {
uip_ipaddr_t prefix;
@ -84,7 +84,7 @@ input_callback(void)
uip_len = 18;
slip_write(uip_buf, uip_len);
}
uip_clear_buf();
uipbuf_clear();
} else {
/* Save the last sender received over SLIP to avoid bouncing the
@ -98,7 +98,7 @@ input_callback(void)
uip_len = len;
/* PRINTF("send len %d\n", len); */
} else {
uip_clear_buf();
uipbuf_clear();
}
}
}

View File

@ -61,7 +61,7 @@ request_prefix(void)
uip_buf[1] = 'P';
uip_len = 2;
slip_write(uip_buf, uip_len);
uip_clear_buf();
uipbuf_clear();
}
/*---------------------------------------------------------------------------*/
static void
@ -77,14 +77,14 @@ slip_input_callback(void)
memset(&prefix, 0, 16);
memcpy(&prefix, &uip_buf[UIP_LLH_LEN + 2], 8);
uip_clear_buf();
uipbuf_clear();
LOG_INFO("Setting prefix ");
LOG_INFO_6ADDR(&prefix);
LOG_INFO_("\n");
set_prefix_64(&prefix);
}
uip_clear_buf();
uipbuf_clear();
} else if(uip_buf[UIP_LLH_LEN] == '?') {
LOG_INFO("Got request message of type %c\n", uip_buf[UIP_LLH_LEN + 1]);
@ -100,7 +100,7 @@ slip_input_callback(void)
uip_len = 18;
slip_write(uip_buf, uip_len);
}
uip_clear_buf();
uipbuf_clear();
} else {
/* Save the last sender received over SLIP to avoid bouncing the
packet back if no route is found */

View File

@ -236,13 +236,13 @@ void mac_ethernetToLowpan(uint8_t * ethHeader)
if (((struct uip_eth_hdr *) ethHeader)->type != UIP_HTONS(UIP_ETHTYPE_IPV6)) {
PRINTF("eth2low: Packet is not IPv6, dropping\n");
/* rndis_stat.txbad++; */
uip_clear_buf();
uipbuf_clear();
return;
}
// In sniffer mode we don't ever send anything
if (usbstick_mode.sendToRf == 0) {
uip_clear_buf();
uipbuf_clear();
return;
}
@ -261,7 +261,7 @@ void mac_ethernetToLowpan(uint8_t * ethHeader)
/* IPv6 does not use broadcast addresses, hence this should not happen */
PRINTF("eth2low: Ethernet broadcast address received, should not happen?\n");
/* rndis_stat.txbad++; */
uip_clear_buf();
uipbuf_clear();
return;
} else {
PRINTF("eth2low: Addressed packet received... ");
@ -269,7 +269,7 @@ void mac_ethernetToLowpan(uint8_t * ethHeader)
if (mac_createSicslowpanLongAddr( &(((struct uip_eth_hdr *) ethHeader)->dest.addr[0]), &destAddr) == 0) {
PRINTF(" translation failed\n");
/* rndis_stat.txbad++; */
uip_clear_buf();
uipbuf_clear();
return;
}
PRINTF(" translated OK\n");
@ -293,7 +293,7 @@ void mac_ethernetToLowpan(uint8_t * ethHeader)
}
}
uip_clear_buf();
uipbuf_clear();
}
@ -341,7 +341,7 @@ void mac_LowpanToEthernet(void)
/* rndis_send(uip_buf, uip_len, 1); */
/* rndis_stat.rxok++; */
/* uip_clear_buf(); */
/* uipbuf_clear(); */
}
/**

View File

@ -87,7 +87,7 @@ tcpip_input(void)
if(uip_len > 0) {
slip_write(uip_buf, uip_len);
leds_toggle(LEDS_RED);
uip_clear_buf();
uipbuf_clear();
}
}
}