Further simplification of uip.h buffers

This commit is contained in:
Simon Duquennoy 2018-10-18 19:11:56 +02:00
parent 6c583efa37
commit 655faf0dca
5 changed files with 28 additions and 34 deletions

View File

@ -456,6 +456,7 @@ static uint16_t last_seq;
/*---------------------------------------------------------------------------*/
/* uIPv6 Pointers */
/*---------------------------------------------------------------------------*/
#define UIP_EXT_BUF ((struct uip_ext_hdr *)UIP_IP_PAYLOAD(0))
#define UIP_EXT_BUF_NEXT ((uint8_t *)(UIP_IP_PAYLOAD(HBHO_TOTAL_LEN)))
#define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)(UIP_IP_PAYLOAD(0) + 2))
extern uint16_t uip_slen;
@ -1320,11 +1321,11 @@ out()
}
/* Slide 'right' by HBHO_TOTAL_LEN bytes */
memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF(0), uip_len - UIP_IPH_LEN);
memset(UIP_EXT_BUF(0), 0, HBHO_TOTAL_LEN);
memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
memset(UIP_EXT_BUF, 0, HBHO_TOTAL_LEN);
UIP_EXT_BUF(0)->next = UIP_IP_BUF->proto;
UIP_EXT_BUF(0)->len = 0;
UIP_EXT_BUF->next = UIP_IP_BUF->proto;
UIP_EXT_BUF->len = 0;
lochbhmptr = UIP_EXT_OPT_FIRST;
lochbhmptr->type = HBHO_OPT_TYPE_TRICKLE;

View File

@ -81,21 +81,6 @@
#define UIP_TCP_BUF ((struct uip_tcp_hdr *)UIP_IP_PAYLOAD(uip_ext_len))
#define UIP_TCP_PAYLOAD ((unsigned char *)UIP_IP_PAYLOAD(uip_ext_len) + UIP_TCPH_LEN)
/**
* Direct access to extension headers, with explicit ext header offset
*/
#define UIP_EXT_BUF(ext) ((struct uip_ext_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_HBHO_BUF(ext) ((struct uip_hbho_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_RH_BUF(ext) ((struct uip_routing_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_FRAG_BUF(ext) ((struct uip_frag_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_DESTO_BUF(ext) ((struct uip_desto_hdr *)UIP_IP_PAYLOAD(ext))
#define UIP_RPL_SRH_BUF(ext) ((struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(ext) + RPL_RH_LEN))
/**
* Direct access to extension header options, with explicit ext header and option offset
*/
#define UIP_EXT_HDR_OPT_BUF(ext, opt) ((struct uip_ext_hdr_opt *)(UIP_IP_PAYLOAD(ext) + (opt)))
#include "net/ipv6/uipopt.h"
#include "net/ipv6/uipbuf.h"
#include "net/linkaddr.h"

View File

@ -628,7 +628,7 @@ uip_reass(uint8_t *prev_proto_ptr)
uint16_t offset=0;
uint16_t len;
uint16_t i;
struct uip_frag_hdr *frag_buf = UIP_FRAG_BUF(uip_ext_len);
struct uip_frag_hdr *frag_buf = (struct uip_frag_hdr *)UIP_IP_PAYLOAD(uip_ext_len);
/* If ip_reasstmr is zero, no packet is present in the buffer */
/* We first write the unfragmentable part of IP header into the reassembly

View File

@ -290,6 +290,10 @@ insert_srh_header(void)
rpl_dag_t *dag;
uip_ipaddr_t node_addr;
/* Always insest SRH as first extension header */
struct uip_routing_hdr *rh_hdr = (struct uip_routing_hdr *)UIP_IP_PAYLOAD(0);
struct uip_rpl_srh_hdr *srh_hdr = (struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(0) + RPL_RH_LEN);
LOG_INFO("SRH creating source routing header with destination ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO_("\n");
@ -371,22 +375,22 @@ insert_srh_header(void)
memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len);
/* Insert source routing header (as first ext header) */
UIP_RH_BUF(0)->next = UIP_IP_BUF->proto;
rh_hdr->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_ROUTING;
/* Initialize IPv6 Routing Header */
UIP_RH_BUF(0)->len = (ext_len - 8) / 8;
UIP_RH_BUF(0)->routing_type = RPL_RH_TYPE_SRH;
UIP_RH_BUF(0)->seg_left = path_len;
rh_hdr->len = (ext_len - 8) / 8;
rh_hdr->routing_type = RPL_RH_TYPE_SRH;
rh_hdr->seg_left = path_len;
/* Initialize RPL Source Routing Header */
UIP_RPL_SRH_BUF(0)->cmpr = (cmpri << 4) + cmpre;
UIP_RPL_SRH_BUF(0)->pad = padding << 4;
srh_hdr->cmpr = (cmpri << 4) + cmpre;
srh_hdr->pad = padding << 4;
/* Initialize addresses field (the actual source route).
* From last to first. */
node = dest_node;
hop_ptr = ((uint8_t *)UIP_RH_BUF(0)) + ext_len - padding; /* Pointer where to write the next hop compressed address */
hop_ptr = ((uint8_t *)rh_hdr) + ext_len - padding; /* Pointer where to write the next hop compressed address */
while(node != NULL && node->parent != root_node) {
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);

View File

@ -180,6 +180,10 @@ insert_srh_header(void)
uip_sr_node_t *node;
uip_ipaddr_t node_addr;
/* Always insest SRH as first extension header */
struct uip_routing_hdr *rh_hdr = (struct uip_routing_hdr *)UIP_IP_PAYLOAD(0);
struct uip_rpl_srh_hdr *srh_hdr = (struct uip_rpl_srh_hdr *)(UIP_IP_PAYLOAD(0) + RPL_RH_LEN);
LOG_INFO("SRH creating source routing header with destination ");
LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr);
LOG_INFO_(" \n");
@ -261,22 +265,22 @@ insert_srh_header(void)
memset(uip_buf + UIP_IPH_LEN + uip_ext_len, 0, ext_len);
/* Insert source routing header (as first ext header) */
UIP_RH_BUF(0)->next = UIP_IP_BUF->proto;
rh_hdr->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_ROUTING;
/* Initialize IPv6 Routing Header */
UIP_RH_BUF(0)->len = (ext_len - 8) / 8;
UIP_RH_BUF(0)->routing_type = RPL_RH_TYPE_SRH;
UIP_RH_BUF(0)->seg_left = path_len;
rh_hdr->len = (ext_len - 8) / 8;
rh_hdr->routing_type = RPL_RH_TYPE_SRH;
rh_hdr->seg_left = path_len;
/* Initialize RPL Source Routing Header */
UIP_RPL_SRH_BUF(0)->cmpr = (cmpri << 4) + cmpre;
UIP_RPL_SRH_BUF(0)->pad = padding << 4;
srh_hdr->cmpr = (cmpri << 4) + cmpre;
srh_hdr->pad = padding << 4;
/* Initialize addresses field (the actual source route).
* From last to first. */
node = dest_node;
hop_ptr = ((uint8_t *)UIP_RH_BUF(0)) + ext_len - padding; /* Pointer where to write the next hop compressed address */
hop_ptr = ((uint8_t *)rh_hdr) + ext_len - padding; /* Pointer where to write the next hop compressed address */
while(node != NULL && node->parent != root_node) {
NETSTACK_ROUTING.get_sr_node_ipaddr(&node_addr, node);