validation.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Cenk Gündoğan <mail@cgundogan.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #ifndef VALIDATION_H
20 #define VALIDATION_H
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include "net/gnrc/rpl/structs.h"
27 #include "net/gnrc/icmpv6.h"
28 
29 #define ENABLE_DEBUG (0)
30 #include "debug.h"
31 
41 static inline bool gnrc_rpl_validation_DIS(gnrc_rpl_dis_t *dis, uint16_t len)
42 {
43  uint16_t expected_len = sizeof(*dis) + sizeof(icmpv6_hdr_t);
44 
45  if (expected_len <= len) {
46  return true;
47  }
48 
49  DEBUG("RPL: wrong DIS len: %d, expected: %d\n", len, expected_len);
50 
51  return false;
52 }
53 
65 bool gnrc_rpl_validation_options(int msg_type, gnrc_rpl_instance_t *inst,
66  gnrc_rpl_opt_t *opt, uint16_t len);
67 
77 static inline bool gnrc_rpl_validation_DIO(gnrc_rpl_dio_t *dio, uint16_t len)
78 {
79  uint16_t expected_len = sizeof(*dio) + sizeof(icmpv6_hdr_t);
80 
81  if (expected_len <= len) {
82  return true;
83  }
84 
85  DEBUG("RPL: wrong DIO len: %d, expected: %d\n", len, expected_len);
86 
87  return false;
88 }
89 
99 static inline bool gnrc_rpl_validation_DAO(gnrc_rpl_dao_t *dao, uint16_t len)
100 {
101  uint16_t expected_len = sizeof(*dao) + sizeof(icmpv6_hdr_t);
102 
103  if ((dao->k_d_flags & GNRC_RPL_DAO_D_BIT)) {
104  expected_len += sizeof(ipv6_addr_t);
105  }
106 
107  if (expected_len <= len) {
108  return true;
109  }
110 
111  DEBUG("RPL: wrong DAO len: %d, expected: %d\n", len, expected_len);
112 
113  return false;
114 }
115 
127  uint16_t len,
128  ipv6_addr_t *dst)
129 {
130  uint16_t expected_len = sizeof(*dao_ack) + sizeof(icmpv6_hdr_t);
131 
132  if (ipv6_addr_is_multicast(dst)) {
133  DEBUG("RPL: received DAO-ACK on multicast address\n");
134  return false;
135  }
136 
137  if ((dao_ack->d_reserved & GNRC_RPL_DAO_ACK_D_BIT)) {
138  expected_len += sizeof(ipv6_addr_t);
139  }
140 
141  if (expected_len == len) {
142  return true;
143  }
144 
145  DEBUG("RPL: wrong DAO-ACK len: %d, expected: %d\n", len, expected_len);
146 
147  return false;
148 }
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* VALIDATION_H */
155 
RPL data structs.
Debug-header.
Definitions for GNRC&#39;s ICMPv6 implementation.
static bool gnrc_rpl_validation_DAO(gnrc_rpl_dao_t *dao, uint16_t len)
Checks validity of DAO control messages.
Definition: validation.h:99
DIO Base Object.
Definition: structs.h:88
static bool gnrc_rpl_validation_DIO(gnrc_rpl_dio_t *dio, uint16_t len)
Checks validity of DIO control messages.
Definition: validation.h:77
static bool gnrc_rpl_validation_DAO_ACK(gnrc_rpl_dao_ack_t *dao_ack, uint16_t len, ipv6_addr_t *dst)
Checks validity of DAO-ACK control messages.
Definition: validation.h:126
struct gnrc_rpl_instance gnrc_rpl_instance_t
Instance representation.
Definition: structs.h:218
#define DEBUG(...)
Print debug information to stdout.
Definition: debug.h:95
Destination Advertisement Object.
Definition: structs.h:137
RPL-Option Generic Format.
Definition: structs.h:77
General ICMPv6 message format.
Definition: icmpv6.h:141
bool gnrc_rpl_validation_options(int msg_type, gnrc_rpl_instance_t *inst, gnrc_rpl_opt_t *opt, uint16_t len)
Checks validity of control message options.
DODAG Information Solicitation.
Definition: structs.h:126
static bool gnrc_rpl_validation_DIS(gnrc_rpl_dis_t *dis, uint16_t len)
Checks validity of DIS control messages.
Definition: validation.h:41
Data type to represent an IPv6 address.
Definition: ipv6/addr.h:74
static bool ipv6_addr_is_multicast(const ipv6_addr_t *addr)
Check if addr is a multicast address.
Definition: ipv6/addr.h:393
Destination Advertisement Object Acknowledgement.
Definition: structs.h:150
uint8_t d_reserved
if set, indicates that the DODAG id should be included
Definition: structs.h:152
uint8_t k_d_flags
K and D flags.
Definition: structs.h:139