Packets/GenericTLV: fix for dynamic size length fields (doh)
[senf.git] / senf / Packets / DefaultBundle / IPv6Extensions.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //     Philipp Batroff <philipp.batroff@fokus.fraunhofer.de>
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the
21 // Free Software Foundation, Inc.,
22 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
24 /** \file
25     \brief IPv6Extensions public header */
26
27 #ifndef HH_SENF_Packets_DefaultBundle_IPv6Extensions_
28 #define HH_SENF_Packets_DefaultBundle_IPv6Extensions_ 1
29
30 // Custom includes
31 #include <senf/Packets/Packets.hh>
32 #include "IPv6ExtOptionType.hh"
33 #include "ListOptionTypeParser.hh"
34 #include "IPv6Packet.hh"
35
36 //#include "IPv6Extensions.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40
41     /** \brief Parse in IPv6 fragment extension header
42         
43         Parser implementing the IPv6 fragment extension. The fields implemented are:
44         \image html IPv6FragmentPacket.png
45
46         \see IPv6ExtensionType_Fragment \n
47             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
48      */
49     struct IPv6FragmentPacketParser : public PacketParserBase
50     {
51 #       include SENF_FIXED_PARSER()
52
53         SENF_PARSER_FIELD            ( nextHeader     , UInt8Parser  );
54         SENF_PARSER_PRIVATE_FIELD    ( reserved1      , UInt8Parser  );
55         SENF_PARSER_BITFIELD         ( fragmentOffset , 13, unsigned );
56         SENF_PARSER_PRIVATE_BITFIELD ( reserved2      ,  2, unsigned );
57         SENF_PARSER_BITFIELD         ( moreFragments  ,  1, bool     );
58         SENF_PARSER_FIELD            ( id             , UInt32Parser );
59
60         SENF_PARSER_FINALIZE(IPv6FragmentPacketParser);
61     };
62
63     /** \brief IPv6 fragment extension
64
65         \par Packet type (typedef):
66             \ref IPv6FragmentPacket
67
68         \par Fields:
69             \ref IPv6FragmentPacketParser
70         
71         \par Associated registries:
72             \ref IpTypes
73         
74         \par Finalize action:
75             Set \a nextHeader from type of next packet if found in \ref IpTypes
76
77         \ingroup protocolbundle_default
78      */
79     struct IPv6FragmentPacketType
80         : public PacketTypeBase,
81           public PacketTypeMixin<IPv6FragmentPacketType, IpTypes>
82     {
83 #ifndef DOXYGEN
84         typedef PacketTypeMixin<IPv6FragmentPacketType, IpTypes> mixin;
85 #endif
86         /** \brief IPv6 fragment extension packet typedef */
87         typedef ConcretePacket<IPv6FragmentPacketType> packet;
88         /** \brief typedef to the parser of IPv6 fragment extension packet */
89         typedef IPv6FragmentPacketParser parser;
90
91         using mixin::nextPacketRange;
92         using mixin::nextPacketType;
93         using mixin::initSize;
94         using mixin::init;
95
96         static key_t nextPacketKey(packet p) 
97             { return p->nextHeader(); }
98         
99         /** \brief Dump given IPv6FragmentPacket in readable form to given output stream */
100         static void dump(packet p, std::ostream & os); 
101
102         static void finalize(packet p) { 
103             p->nextHeader() << key(p.next(nothrow)); }
104     };
105
106     /** \brief IPv6 fragment extension packet typedef 
107         \ingroup protocolbundle_default
108      */
109     typedef ConcretePacket<IPv6FragmentPacketType> IPv6FragmentPacket;
110
111 // =====================================================================================================
112
113     /** \brief Parse in IPv6 routing extension header
114
115         Parser implementing the IPv6 routing Header extension (type 0 only).
116         The fields implemented are:
117         \image html IPv6RoutingPacket.png
118
119         \see IPv6ExtensionType_Routing \n
120             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
121      */
122     struct IPv6RoutingPacketParser : public PacketParserBase
123     {
124         /*
125         The Type 0 Routing header has the following format: (RFC 2460)
126
127         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
128         |  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
129         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130         |                            Reserved                           |
131         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132         |                                                               |
133         +                                                               +
134         |                                                               |
135         +                           Address[1]                          +
136         |                                                               |
137         +                                                               +
138         |                                                               |
139         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140         .                               .                               .
141         .                               .                               .
142         .                               .                               .
143         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144         |                                                               |
145         +                                                               +
146         |                                                               |
147         +                           Address[n]                          +
148         |                                                               |
149         +                                                               +
150         |                                                               |
151         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
152         */
153 #       include SENF_PARSER()
154         
155         SENF_PARSER_FIELD ( nextHeader, UInt8Parser      );
156         SENF_PARSER_FIELD ( headerLength, UInt8Parser    );
157         SENF_PARSER_FIELD ( routingType, UInt8Parser     ); //set to Zero for minimal implementation
158         SENF_PARSER_FIELD_RO ( segmentsLeft, UInt8Parser );
159         SENF_PARSER_FIELD ( reserved, UInt32Parser       ); //set to zero by RFC
160         SENF_PARSER_VECTOR ( hopAddresses, segmentsLeft, INet6AddressParser );
161         
162         SENF_PARSER_FINALIZE ( IPv6RoutingPacketParser );
163         
164         //provisionary, since only type 0 is implemented
165         SENF_PARSER_INIT() { 
166             routingType() = 0u;
167             reserved() = 0u; 
168         }
169     };
170     
171     /** \brief IPv6 routing extension
172
173         \par Packet type (typedef):
174             \ref IPv6RoutingPacket
175
176         \par Fields:
177             \ref IPv6RoutingPacketParser
178         
179         \par Associated registries:
180             \ref IpTypes
181         
182         \par Finalize action:
183             Set \a nextHeader from type of next packet if found in \ref IpTypes
184
185         \ingroup protocolbundle_default
186      */
187     struct IPv6RoutingPacketType
188     :   public PacketTypeBase,
189         public PacketTypeMixin<IPv6RoutingPacketType, IpTypes>
190     {
191 #ifndef DOXYGEN
192         typedef PacketTypeMixin<IPv6RoutingPacketType, IpTypes> mixin;
193 #endif
194         /** \brief IPv6 routing extension packet typedef */
195         typedef ConcretePacket<IPv6RoutingPacketType> packet;
196         /** \brief typedef to the parser of IPv6 routing extension packet */
197         typedef IPv6RoutingPacketParser parser;
198         
199         using mixin::nextPacketRange;
200         using mixin::nextPacketType;
201         using mixin::init;
202         using mixin::initSize;
203         
204         static key_t nextPacketKey(packet p) 
205             { return p->nextHeader(); }
206         /** \brief Dump given IPv6RoutingPacket in readable form to given output stream */
207         static void dump(packet p, std::ostream & os); 
208         
209         static void finalize(packet p) { 
210             p->nextHeader() << key(p.next(nothrow)); }
211     };
212     
213     /** \brief IPv6 routing extension packet typedef
214         \ingroup protocolbundle_default
215      */
216     typedef ConcretePacket<IPv6RoutingPacketType> IPv6RoutingPacket;
217
218     
219 // =====================================================================================================
220     
221     /** \brief Parse in IPv6 Hop-By-Hop extension header
222
223         Parser implementing the IPv6 routing Header extension. The fields implemented are:
224         \image html IPv6HopByHopOptionsPacket.png
225
226         \see IPv6ExtensionType_HopByHop \n
227             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
228     */
229     struct IPv6HopByHopOptionsPacketParser : public PacketParserBase 
230     {
231 #       include SENF_PARSER()
232       
233         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
234         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
235
236         typedef detail::FixedAuxParserPolicy<UInt8Parser, 1u> ListOptionTypeAuxPolicy;
237         typedef detail::ListOptionTypeParser_Policy<
238             IPv6GenericOptionTLVParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
239         typedef ListParser<ListOptionTypePolicy> ListOptionTypeParser;
240
241         SENF_PARSER_FIELD  ( options, ListOptionTypeParser);
242
243         SENF_PARSER_FINALIZE ( IPv6HopByHopOptionsPacketParser );
244     };
245     
246     /** \brief IPv6 Hop-By-Hop extension
247
248         \par Packet type (typedef):
249             \ref IPv6HopByHopOptionsPacket
250
251         \par Fields:
252             \ref IPv6HopByHopOptionsPacketParser
253         
254         \par Associated registries:
255             \ref IpTypes
256         
257         \par Finalize action:
258             Set \a nextHeader from type of next packet if found in \ref IpTypes
259
260         \ingroup protocolbundle_default
261     */
262     struct IPv6HopByHopOptionsPacketType
263     :   public PacketTypeBase,
264         public PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes>
265     {
266 #ifndef DOXYGEN
267         typedef PacketTypeMixin<IPv6HopByHopOptionsPacketType, IpTypes> mixin;
268 #endif
269         /** \brief IPv6 Hop-By-Hop extension packet typedef */
270         typedef ConcretePacket<IPv6HopByHopOptionsPacketType> packet;
271         /** \brief typedef to the parser of IPv6 Hop-By-Hop extension packet */
272         typedef IPv6HopByHopOptionsPacketParser parser;
273         
274         using mixin::nextPacketRange;
275         using mixin::nextPacketType;
276         using mixin::init;
277         using mixin::initSize;
278         
279         static key_t nextPacketKey(packet p) 
280         { return p->nextHeader(); }
281         
282         /** \brief Dump given IPv6HopByHopOptionsPacket in readable form to given output stream */
283         static void dump(packet p, std::ostream & os); 
284         
285         static void finalize(packet p) { 
286             p->nextHeader() << key(p.next(nothrow)); }
287     };
288     
289     /** \brief IPv6 routing Hop-By-Hop packet typedef
290         \ingroup protocolbundle_default
291      */
292     typedef ConcretePacket<IPv6HopByHopOptionsPacketType> IPv6HopByHopOptionsPacket;
293     
294 // =====================================================================================================
295     
296     /** \brief Parse in IPv6 Destination Options extension header
297
298         Parser implementing the IPv6 Destination Options Header extension. 
299         The fields implemented are:
300         \image html IPv6DestinationOptionsPacket.png
301
302         \see IPv6ExtensionType_Destination \n
303             <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>
304      */    
305     struct IPv6DestinationOptionsPacketParser : public PacketParserBase 
306     {
307 #       include SENF_PARSER()
308         SENF_PARSER_FIELD ( nextHeader, UInt8Parser   );
309         SENF_PARSER_FIELD ( headerLength, UInt8Parser );
310         
311         SENF_PARSER_FINALIZE ( IPv6DestinationOptionsPacketParser );
312     };
313     
314     /** \brief IPv6 Destination Options extension
315
316         \par Packet type (typedef):
317             \ref IPv6DestinationOptionsPacket
318
319         \par Fields:
320             \ref IPv6DestinationOptionsPacketParser
321         
322         \par Associated registries:
323             \ref IpTypes
324         
325         \par Finalize action:
326             Set \a nextHeader from type of next packet if found in \ref IpTypes
327
328         \ingroup protocolbundle_default
329      */
330     struct IPv6DestinationOptionsPacketType
331     :   public PacketTypeBase,
332         public PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes>
333     {
334 #ifndef DOXYGEN
335         typedef PacketTypeMixin<IPv6DestinationOptionsPacketType, IpTypes> mixin;
336 #endif
337         /** \brief IPv6 Destination Options extension packet typedef */
338         typedef ConcretePacket<IPv6DestinationOptionsPacketType> packet;
339         /** \brief typedef to the parser of IPv6 Destination Options extension packet */
340         typedef IPv6DestinationOptionsPacketParser parser;
341         
342         using mixin::nextPacketRange;
343         using mixin::nextPacketType;
344         using mixin::init;
345         using mixin::initSize;
346         
347         static key_t nextPacketKey(packet p) 
348         { return p->nextHeader(); }
349         /** \brief Dump given IPv6DestinationOptionsPacket in readable form to given output stream */
350         static void dump(packet p, std::ostream & os); 
351         
352         static void finalize(packet p) { 
353             p->nextHeader() << key(p.next(nothrow)); }
354     };
355     
356     /** \brief IPv6 routing Destination Options packet typedef
357         \ingroup protocolbundle_default
358      */
359     typedef ConcretePacket<IPv6DestinationOptionsPacketType> IPv6DestinationOptionsPacket;
360     
361 }
362
363 ///////////////////////////////hh.e////////////////////////////////////////
364 //#include "IPv6Extensions.cci"
365 //#include "IPv6Extensions.ct"
366 //#include "IPv6Extensions.cti"
367 #endif
368
369 \f
370 // Local Variables:
371 // mode: c++
372 // fill-column: 100
373 // c-file-style: "senf"
374 // indent-tabs-mode: nil
375 // ispell-local-dictionary: "american"
376 // compile-command: "scons -u test"
377 // comment-column: 40
378 // End: