19
19
20
20
#include <inttypes.h>
21
21
22
- struct InterRouter
23
- {
24
- // What goes here?
25
- };
26
-
27
22
/**
28
23
* The RouteHeader is hidden from the switches by the l2 encryption layer but it is seen
29
24
* by every router which hands off the packet.
25
+ *
26
+ * 1 2 3
27
+ * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
28
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29
+ * 0 | ver | MTU | Flow ID |
30
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31
+ * 4 | |
32
+ * + +
33
+ * 8 | |
34
+ * + Destination IP6 +
35
+ * 12 | |
36
+ * + +
37
+ * 16 | |
38
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39
+ *
40
+ * Ver is 3 bits representing the protocol version *modulo 8*,
30
41
*/
31
42
struct RouteHeader
32
43
{
33
- /**
34
- * This is to be initialized to what the sending node believes is the full path MTU
35
- * (or 0xffff if unsure) and clamped to the MTU of each path by the routers which forward
36
- * the packet.
37
- * Little endian.
38
- */
39
- uint16_t mtu_le ;
44
+ uint16_t versionAndMtu_be ;
40
45
41
46
/**
42
47
* An arbitrary value created by hashing information which represents the dataflow such
@@ -59,6 +64,28 @@ struct RouteHeader
59
64
#define RouteHeader_SIZE 20
60
65
Assert_compileTime (sizeof (struct RouteHeader ) == RouteHeader_SIZE );
61
66
67
+
68
+ static inline void RouteHeader_setVersion (struct RouteHeader * hdr , uint8_t version )
69
+ {
70
+ type -> versionAndMtu_be = (type -> versionAndMtu_be & Endian_hostToBigEndian16 (0x1fff )) |
71
+ Endian_hostToBigEndian16 ((version % 8 ) << 13 );
72
+ }
73
+
74
+ static inline uint8_t RouteHeader_getVersion (struct RouteHeader * hdr )
75
+ {
76
+ return Endian_bigEndianToHost16 (type -> versionAndMtu_be ) >> 13 ;
77
+ }
78
+
79
+ static inline uint16_t RouteHeader_getMTU (struct RouteHeader * hdr )
80
+ {
81
+ return Endian_bigEndianToHost16 (type -> versionAndMtu_be ) >> 13 ;
82
+ }
83
+
84
+ * This is to be initialized to what the sending node believes is the full path MTU
85
+ * (or 0xffff if unsure ) and clamped to the MTU of each path by the routers which forward
86
+ * the packet .
87
+
88
+
62
89
#endif
63
90
64
91
@@ -86,6 +113,12 @@ Assert_compileTime(sizeof(struct RouteHeader) == RouteHeader_SIZE);
86
113
#include "util/Endian.h"
87
114
88
115
/**
116
+ * 1 2 3
117
+ * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
118
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119
+ * 0 | ver |R| unused| unused | Content Type |
120
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
121
+ *
89
122
* The DataHeader is protected from the switches by the l2 encryption layer and from the
90
123
* routers by the l3 layer of encryption. It's primary uses are to tell the endpoint enough
91
124
* information to route the packet to the correct cjdns subsystem and (maybe) reconstruct
@@ -98,11 +131,17 @@ struct DataHeader
98
131
* milliseconds it has something else to send back, this is acceptable, otherwise it should
99
132
* synthisize a control packet to respond with.
100
133
*/
101
- #define DataHeader_highBits_RESPOND_TO_ME Endian_hostToLittleEndian16(1<<15)
134
+ #define DataHeader_RESPOND_TO_ME (1<<7)
135
+
136
+ /**
137
+ * Version is set to the version of the data as per Version.h
138
+ * If the number is over 255, it wraps
139
+ */
140
+ uint8_t versionAndFlags ;
102
141
103
- uint16_t highBits_le ;
142
+ uint8_t unused ;
104
143
105
- // TODO What goes here?
144
+ uint16_t contentType_be ;
106
145
};
107
146
#define DataHeader_SIZE 4
108
147
Assert_compileTime (sizeof (struct DataHeader ) == DataHeader_SIZE );
@@ -149,30 +188,41 @@ enum DataHeader_ContentType
149
188
* cjdns on other machines, providing they first agree on which numbers to use via
150
189
* CTRL messages.
151
190
*/
152
- DataHeader_ContentType_AVAILABLE = 257 ,
153
- DataHeader_ContentType_AVAILABLE_MAX = 32767
191
+ DataHeader_ContentType_AVAILABLE = 257 ) ,
192
+ DataHeader_ContentType_AVAILABLE_MAX = 0xffff
154
193
};
155
194
156
195
static inline enum DataHeader_ContentType DataHeader_getContentType (struct DataHeader * hdr )
157
196
{
158
- return Endian_littleEndianToHost16 ( hdr -> highBits_le & ~ DataHeader_highBits_RESPOND_TO_ME );
197
+ return Endian_bigEndianToHost16 ( hdr -> contentType_be );
159
198
}
160
199
161
200
static inline void DataHeader_setContentType (struct DataHeader * hdr ,
162
201
enum DataHeader_ContentType type )
163
202
{
164
203
Assert_true (type <= DataHeader_ContentType_AVAILABLE_MAX );
165
- hdr -> highBits_le = (hdr -> highBits_le & DataHeader_highBits_RESPOND_TO_ME ) |
166
- Endian_hostToLittleEndian16 (type );
204
+ hdr -> contentType_be = Endian_hostToBigEndian16 (type );
167
205
}
168
206
169
207
static inline void DataHeader_setRespondToMe (struct DataHeader * hdr , bool rtm )
170
208
{
171
- type -> highBits_le = (type -> highBits_le & ~DataHeader_highBits_RESPOND_TO_ME ) |
172
- (rtm ) ? DataHeader_highBits_RESPOND_TO_ME : 0 ;
209
+ type -> versionAndFlags = (type -> versionAndFlags & ~DataHeader_RESPOND_TO_ME ) |
210
+ (rtm ) ? DataHeader_RESPOND_TO_ME : 0 ;
173
211
}
174
212
175
213
static inline bool DataHeader_getRespondToMe (struct DataHeader * hdr )
176
214
{
177
- return type -> highBits_le & DataHeader_highBits_RESPOND_TO_ME ;
215
+ return type -> versionAndFlags & DataHeader_RESPOND_TO_ME ;
178
216
}
217
+
218
+ static inline void DataHeader_setVersion (struct DataHeader * hdr , uint8_t version )
219
+ {
220
+ type -> versionAndFlags = (type -> versionAndFlags & 0x1f ) | ((version % 8 ) << 5 );
221
+ }
222
+
223
+ static inline uint8_t DataHeader_getVersion (struct DataHeader * hdr )
224
+ {
225
+ return type -> versionAndFlags >> 5 ;
226
+ }
227
+
228
+ #endif
0 commit comments