Skip to content

Commit f106779

Browse files
committed
Further defined the next protocol version
1 parent 67f275f commit f106779

File tree

2 files changed

+79
-32
lines changed

2 files changed

+79
-32
lines changed

doc/FutureHeaders.h

+73-23
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,29 @@
1919

2020
#include <inttypes.h>
2121

22-
struct InterRouter
23-
{
24-
// What goes here?
25-
};
26-
2722
/**
2823
* The RouteHeader is hidden from the switches by the l2 encryption layer but it is seen
2924
* 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*,
3041
*/
3142
struct RouteHeader
3243
{
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;
4045

4146
/**
4247
* An arbitrary value created by hashing information which represents the dataflow such
@@ -59,6 +64,28 @@ struct RouteHeader
5964
#define RouteHeader_SIZE 20
6065
Assert_compileTime(sizeof(struct RouteHeader) == RouteHeader_SIZE);
6166

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+
6289
#endif
6390

6491

@@ -86,6 +113,12 @@ Assert_compileTime(sizeof(struct RouteHeader) == RouteHeader_SIZE);
86113
#include "util/Endian.h"
87114

88115
/**
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+
*
89122
* The DataHeader is protected from the switches by the l2 encryption layer and from the
90123
* routers by the l3 layer of encryption. It's primary uses are to tell the endpoint enough
91124
* information to route the packet to the correct cjdns subsystem and (maybe) reconstruct
@@ -98,11 +131,17 @@ struct DataHeader
98131
* milliseconds it has something else to send back, this is acceptable, otherwise it should
99132
* synthisize a control packet to respond with.
100133
*/
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;
102141

103-
uint16_t highBits_le;
142+
uint8_t unused;
104143

105-
// TODO What goes here?
144+
uint16_t contentType_be;
106145
};
107146
#define DataHeader_SIZE 4
108147
Assert_compileTime(sizeof(struct DataHeader) == DataHeader_SIZE);
@@ -149,30 +188,41 @@ enum DataHeader_ContentType
149188
* cjdns on other machines, providing they first agree on which numbers to use via
150189
* CTRL messages.
151190
*/
152-
DataHeader_ContentType_AVAILABLE = 257,
153-
DataHeader_ContentType_AVAILABLE_MAX = 32767
191+
DataHeader_ContentType_AVAILABLE = 257),
192+
DataHeader_ContentType_AVAILABLE_MAX = 0xffff
154193
};
155194

156195
static inline enum DataHeader_ContentType DataHeader_getContentType(struct DataHeader* hdr)
157196
{
158-
return Endian_littleEndianToHost16( hdr->highBits_le & ~DataHeader_highBits_RESPOND_TO_ME );
197+
return Endian_bigEndianToHost16(hdr->contentType_be);
159198
}
160199

161200
static inline void DataHeader_setContentType(struct DataHeader* hdr,
162201
enum DataHeader_ContentType type)
163202
{
164203
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);
167205
}
168206

169207
static inline void DataHeader_setRespondToMe(struct DataHeader* hdr, bool rtm)
170208
{
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;
173211
}
174212

175213
static inline bool DataHeader_getRespondToMe(struct DataHeader* hdr)
176214
{
177-
return type->highBits_le & DataHeader_highBits_RESPOND_TO_ME;
215+
return type->versionAndFlags & DataHeader_RESPOND_TO_ME;
178216
}
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

doc/djc_layer_model.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Direct over phy (future):
2626

2727
## LayerB
2828
Switch Layer, this layer is seen by all switches along a direct path as well as the routers
29-
at the ends of the path but no information in this layer is directly passed to routers
30-
downstream in the forwarding path.
29+
at the ends of the path but when a router forwards the packet on, headers at this layer are
30+
replaced with new ones just as the Ethernet header is replaced by each IP router.
3131

3232
This layer contains:
3333

@@ -40,12 +40,10 @@ No data in this layer is directly forwarded on to the final endpoints or downstr
4040
and no data at this layer or below it can be accessed by the switches due to a CryptoAuth header
4141
which begins this layer. Since the width of a CryptoSessionHeader depends on the state of the
4242
CryptoAuth session represented, a router should only forward packets to another router after
43-
the CryptoAuth session with that router has entered into the ESTABLISHED state in to prevent
43+
the CryptoAuth session with that router has entered into the ESTABLISHED state in order to prevent
4444
fluctuating MTU.
4545

46-
[ CryptoSessionHeader ][ InterRouter ]
47-
48-
NOTE: In versions previous to v9, InterRouter was omitted.
46+
[ CryptoSessionHeader ]
4947

5048
### LayerC Control Packet
5149
In order for switches to send error and other control messages, a branch of *LayerC* exists which
@@ -70,7 +68,7 @@ NOTE: In versions previous to v9, RouteHeader is replaced with an IPv6 header.
7068

7169
## LayerE
7270
Data layer, this layer is only of interest to the sender and the recipient. It it protected by
73-
a CryptoAuth header which prevents intermediate routers from accessing the data therein.
71+
a CryptoAuth layer which prevents intermediate routers from accessing the data therein.
7472

7573
This layer contains:
7674

@@ -108,9 +106,8 @@ CryptoAuth session state.
108106
[ CryptoAuth ] 20
109107
[ SwitchHeader ] 12
110108
[ CryptoSessionHeader ] 24
111-
[ InterRouter ] 4?
112109
[ RouteHeader ] 20
113110
[ CryptoSessionHeader ] 24/124
114-
[ DataHeader ] 4?
111+
[ DataHeader ] 4
115112
[ TCP/UDP/other ]
116113
[ user's data ]

0 commit comments

Comments
 (0)