Skip to content

Commit

Permalink
[SQUASH ME] ng_sixlowpan_iphc: more error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Apr 24, 2015
1 parent f46e863 commit cbe231a
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions sys/net/network_layer/ng_sixlowpan/iphc/ng_sixlowpan_iphc.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt)
ng_ipv6_hdr_t *ipv6_hdr;
uint8_t *iphc_hdr = pkt->data;
uint16_t payload_offset = NG_SIXLOWPAN_IPHC_HDR_LEN;
ng_sixlowpan_ctx_t *ctx;
ng_sixlowpan_ctx_t *ctx = NULL;
ng_pktsnip_t *payload;
ng_pktsnip_t *ipv6 = ng_pktbuf_add(NULL, NULL, sizeof(ng_ipv6_hdr_t),
NG_NETTYPE_IPV6);
Expand Down Expand Up @@ -192,14 +192,14 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt)

if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) {
sci = iphc_hdr[CID_EXT_IDX] >> 4;
}

if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAM) {
ctx = ng_sixlowpan_ctx_lookup_id(sci);
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_SAM) {
ctx = ng_sixlowpan_ctx_lookup_id(sci);

if (ctx == NULL) {
DEBUG("6lo iphc: could not find source context\n");
return false;
}
if (ctx == NULL) {
DEBUG("6lo iphc: could not find source context\n");
return false;
}
}
}
Expand Down Expand Up @@ -264,23 +264,23 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt)

if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_CID_EXT) {
dci = iphc_hdr[CID_EXT_IDX] & 0x0f;
}

if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAM) {
ctx = ng_sixlowpan_ctx_lookup_id(dci);
if (iphc_hdr[IPHC2_IDX] & NG_SIXLOWPAN_IPHC2_DAM) {
ctx = ng_sixlowpan_ctx_lookup_id(dci);

if (ctx == NULL) {
DEBUG("6lo iphc: could not find destination context\n");
return false;
}
if (ctx == NULL) {
DEBUG("6lo iphc: could not find destination context\n");
return false;
}
}
}

switch (iphc_hdr[IPHC2_IDX] & (NG_SIXLOWPAN_IPHC2_M |NG_SIXLOWPAN_IPHC2_DAC |
switch (iphc_hdr[IPHC2_IDX] & (NG_SIXLOWPAN_IPHC2_M | NG_SIXLOWPAN_IPHC2_DAC |
NG_SIXLOWPAN_IPHC2_DAM)) {
case IPHC_M_DAC_DAM_U_FULL:
case IPHC_M_DAC_DAM_M_FULL:
memcpy(&(ipv6_hdr->dst.u8), iphc_hdr + payload, 16);
memcpy(&(ipv6_hdr->dst.u8), iphc_hdr + payload_offset, 16);
payload_offset += 16;
break;

Expand Down Expand Up @@ -362,6 +362,7 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt)
uint8_t orig_ctx_len = ctx->prefix_len;

ng_ipv6_addr_set_unspecified(&ipv6_hdr->dst);

if (ctx->prefix_len > 64) {
ctx->prefix_len = 64;
}
Expand Down Expand Up @@ -397,6 +398,8 @@ bool ng_sixlowpan_iphc_decode(ng_pktsnip_t *pkt)
/* insert IPv6 header */
ipv6->next = pkt->next;
pkt->next = ipv6;

return true;
}

bool ng_sixlowpan_iphc_encode(ng_pktsnip_t *pkt)
Expand Down

0 comments on commit cbe231a

Please sign in to comment.