validation.h
3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Copyright (C) 2016 Cenk Gündoğan <mail@cgundogan.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup net_gnrc_rpl
* @{
*
* @file
* @brief RPL control message validation functions
*
* @author Cenk Gündoğan <mail@cgundogan.de>
*/
#ifndef GNRC_RPL_VALIDATION_H_
#define GNRC_RPL_VALIDATION_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "net/gnrc/rpl/structs.h"
#include "net/gnrc/icmpv6.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Checks validity of DIS control messages
*
* @param[in] dis The DIS control message
* @param[in] len Length of the DIS control message
*
* @return true, if @p dis is valid
* @return false, otherwise
*/
static inline bool gnrc_rpl_validation_DIS(gnrc_rpl_dis_t *dis, uint16_t len)
{
uint16_t expected_len = sizeof(*dis) + sizeof(icmpv6_hdr_t);
if (expected_len <= len) {
return true;
}
DEBUG("RPL: wrong DIS len: %d, expected: %d\n", len, expected_len);
return false;
}
/**
* @brief Checks validity of control message options
*
* @param[in] msg_type Type of the control message
* @param[in] inst The RPL instance
* @param[in] opt Options of the control message
* @param[in] len Length of the options
*
* @return true, if @p opt is valid
* @return false, otherwise
*/
bool gnrc_rpl_validation_options(int msg_type, gnrc_rpl_instance_t *inst,
gnrc_rpl_opt_t *opt, uint16_t len);
/**
* @brief Checks validity of DIO control messages
*
* @param[in] dio The DIO control message
* @param[in] len Length of the DIO control message
*
* @return true, if @p dio is valid
* @return false, otherwise
*/
static inline bool gnrc_rpl_validation_DIO(gnrc_rpl_dio_t *dio, uint16_t len)
{
uint16_t expected_len = sizeof(*dio) + sizeof(icmpv6_hdr_t);
if (expected_len <= len) {
return true;
}
DEBUG("RPL: wrong DIO len: %d, expected: %d\n", len, expected_len);
return false;
}
/**
* @brief Checks validity of DAO control messages
*
* @param[in] dao The DAO control message
* @param[in] len Length of the DAO control message
*
* @return true, if @p dao is valid
* @return false, otherwise
*/
static inline bool gnrc_rpl_validation_DAO(gnrc_rpl_dao_t *dao, uint16_t len)
{
uint16_t expected_len = sizeof(*dao) + sizeof(icmpv6_hdr_t);
if ((dao->k_d_flags & GNRC_RPL_DAO_D_BIT)) {
expected_len += sizeof(ipv6_addr_t);
}
if (expected_len <= len) {
return true;
}
DEBUG("RPL: wrong DAO len: %d, expected: %d\n", len, expected_len);
return false;
}
/**
* @brief Checks validity of DAO-ACK control messages
*
* @param[in] dao_ack The DAO-ACK control message
* @param[in] len Length of the DAO-ACK control message
*
* @return true, if @p dao_ack is valid
* @return false, otherwise
*/
static inline bool gnrc_rpl_validation_DAO_ACK(gnrc_rpl_dao_ack_t *dao_ack, uint16_t len)
{
uint16_t expected_len = sizeof(*dao_ack) + sizeof(icmpv6_hdr_t);
if ((dao_ack->d_reserved & GNRC_RPL_DAO_ACK_D_BIT)) {
expected_len += sizeof(ipv6_addr_t);
}
if (expected_len == len) {
return true;
}
DEBUG("RPL: wrong DAO-ACK len: %d, expected: %d\n", len, expected_len);
return false;
}
#ifdef __cplusplus
}
#endif
#endif /* GNRC_RPL_VALIDATION_H_ */
/** @} */