874190902cae2f6770e413aed08f4b525cae0628
[senf.git] / Packets / DefaultBundle / ICMPv6TypePacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Philipp Batroff <pug@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 // Definition of non-inline non-template functions
24
25 #ifndef HH_SENF_Packets_DefaultBundle_ICMPv6TypePacket_
26 #define HH_SENF_Packets_DefaultBundle_ICMPv6TypePacket_ 1
27
28 // Custom includes
29 #include "../../Packets/Packets.hh"
30 #include "ICMPv6Packet.hh"
31
32 namespace senf {
33
34     //#############################################################
35     //ICMPv6 Echo Request
36     //#############################################################
37     struct ICMPv6EchoRequestParser : public PacketParserBase
38     {
39 #       include SENF_FIXED_PARSER()
40         SENF_PARSER_FIELD ( identifier, UInt16Parser );
41         SENF_PARSER_FIELD ( seqNr,      UInt16Parser );
42         
43         SENF_PARSER_FINALIZE ( ICMPv6EchoRequestParser );
44     };
45     
46     struct ICMPv6EchoRequestType
47         : public PacketTypeBase,
48           public PacketTypeMixin<ICMPv6EchoRequestType>
49     {
50         typedef PacketTypeMixin<ICMPv6EchoRequestType> mixin;
51         typedef ConcretePacket<ICMPv6EchoRequestType> packet;
52         typedef ICMPv6EchoRequestParser parser;
53         
54         using mixin::nextPacketRange;
55         using mixin::init;
56         using mixin::initSize;
57     };
58     
59     typedef ConcretePacket<ICMPv6EchoRequestType> ICMPv6EchoRequest;
60     
61     //#############################################################
62     //ICMPv6 Echo Reply
63     //#############################################################
64     struct ICMPv6EchoReplyParser : public PacketParserBase
65     {
66 #       include SENF_FIXED_PARSER()
67         SENF_PARSER_FIELD ( identifier, UInt16Parser );
68         SENF_PARSER_FIELD ( seqNr,      UInt16Parser );
69         
70         SENF_PARSER_FINALIZE ( ICMPv6EchoReplyParser );
71     };
72     
73     struct ICMPv6EchoReplyType
74         : public PacketTypeBase,
75           public PacketTypeMixin<ICMPv6EchoReplyType>
76     {
77         typedef PacketTypeMixin<ICMPv6EchoReplyType> mixin;
78         typedef ConcretePacket<ICMPv6EchoReplyType> packet;
79         typedef ICMPv6EchoReplyParser parser;
80         
81         using mixin::nextPacketRange;
82         using mixin::init;
83         using mixin::initSize;
84     };
85         
86     typedef ConcretePacket<ICMPv6EchoReplyType> ICMPv6EchoReply;
87     
88     //#############################################################
89     //ICMPv6 Error Destination Unreachable Message
90     //#############################################################
91     struct ICMPv6ErrDestUnreachableParser : public PacketParserBase
92     {
93 #       include SENF_FIXED_PARSER()
94         
95         //should be set static 0 by sender and ignored by receiver
96         SENF_PARSER_PRIVATE_FIELD ( unused, UInt32Parser );
97         
98         SENF_PARSER_INIT() { 
99             unused() = 0; 
100         }
101         /*   Code     0 - No route to destination
102                     1 - Communication with destination
103                             administratively prohibited
104                     2 - Beyond scope of source address
105                     3 - Address unreachable
106                     4 - Port unreachable
107                     5 - Source address failed ingress/egress policy
108                     6 - Reject route to destination   */
109         void setErrCode(int code) {
110             ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
111             icmpv6->code() = code;
112         }
113         
114         SENF_PARSER_FINALIZE ( ICMPv6ErrDestUnreachableParser );
115     };
116     
117     struct ICMPv6ErrDestUnreachableType
118         : public PacketTypeBase,
119           public PacketTypeMixin<ICMPv6ErrDestUnreachableType>
120     {
121         typedef PacketTypeMixin<ICMPv6ErrDestUnreachableType> mixin;
122         typedef ConcretePacket<ICMPv6ErrDestUnreachableType> packet;
123         typedef ICMPv6ErrDestUnreachableParser parser;
124         
125         using mixin::nextPacketRange;
126         using mixin::init;
127         using mixin::initSize;
128     };
129         
130     typedef ConcretePacket<ICMPv6ErrDestUnreachableType> ICMPv6ErrDestUnreachable;
131     
132     //#############################################################
133     //ICMPv6 Error Packet Too Big Message
134     //#############################################################
135     struct ICMPv6ErrTooBigParser : public PacketParserBase
136     {
137 #       include SENF_FIXED_PARSER()
138         SENF_PARSER_FIELD ( mtu, UInt32Parser );
139     
140         /*   Code     static set to 0       */
141     //     SENF_PARSER_INIT() {
142     //         ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
143     //         icmpv6->code() = 0;
144     //     }
145         
146         SENF_PARSER_FINALIZE ( ICMPv6ErrTooBigParser );
147     };
148     
149     struct ICMPv6ErrTooBigType
150         : public PacketTypeBase,
151           public PacketTypeMixin<ICMPv6ErrTooBigType>
152     {
153         typedef PacketTypeMixin<ICMPv6ErrTooBigType> mixin;
154         typedef ConcretePacket<ICMPv6ErrTooBigType> packet;
155         typedef ICMPv6ErrTooBigParser parser;
156         
157         using mixin::nextPacketRange;
158         using mixin::init;
159         using mixin::initSize;
160     };
161
162     typedef ConcretePacket<ICMPv6ErrTooBigType> ICMPv6ErrTooBig;
163     
164     //#############################################################
165     //ICMPv6 Error Time Exceeded Message
166     //#############################################################
167     struct ICMPv6ErrTimeExceededParser : public PacketParserBase
168     {
169 #       include SENF_FIXED_PARSER()
170         //should be set static 0 by sender and ignored by receiver
171         SENF_PARSER_FIELD    ( unused, UInt32Parser );
172         /*  Code    0 - Hop limit exceeded in transit
173                     1 - Fragment reassembly time exceeded   */
174         void setErrCode(int code){
175             ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
176             icmpv6->code() = code;
177         }
178         
179         SENF_PARSER_FINALIZE ( ICMPv6ErrTimeExceededParser );
180     };
181     
182     struct ICMPv6ErrTimeExceededType
183         : public PacketTypeBase,
184           public PacketTypeMixin<ICMPv6ErrTimeExceededType>
185     {
186         typedef PacketTypeMixin<ICMPv6ErrTimeExceededType> mixin;
187         typedef ConcretePacket<ICMPv6ErrTimeExceededType> packet;
188         typedef ICMPv6ErrTimeExceededParser parser;
189         
190         using mixin::nextPacketRange;
191         using mixin::init;
192         using mixin::initSize;
193     };
194     typedef ConcretePacket<ICMPv6ErrTimeExceededType> ICMPv6ErrTimeExceeded;
195     
196     //#############################################################
197     //ICMPv6 Error Parameter Problem Message
198     //#############################################################
199     struct ICMPv6ErrParamProblemParser : public PacketParserBase
200     {
201 #       include SENF_FIXED_PARSER()
202         //should be set static 0 by sender and ignored by receiver
203         SENF_PARSER_FIELD ( pointer, UInt32Parser );
204         /*  Code      0 - Erroneous header field encountered
205                     1 - Unrecognized Next Header type encountered
206                     2 - Unrecognized IPv6 option encountered          */
207         
208         void setErrCode(int code){
209             ICMPv6Packet icmpv6 (senf::Packet().rfind<ICMPv6Packet>(senf::nothrow));
210             icmpv6->code() = code;
211         }
212         SENF_PARSER_FINALIZE ( ICMPv6ErrParamProblemParser );
213     };
214     
215     struct ICMPv6ErrParamProblemType
216         : public PacketTypeBase,
217           public PacketTypeMixin<ICMPv6ErrParamProblemType>
218     {
219         typedef PacketTypeMixin<ICMPv6ErrParamProblemType> mixin;
220         typedef ConcretePacket<ICMPv6ErrParamProblemType> packet;
221         typedef ICMPv6ErrParamProblemParser parser;
222         
223         using mixin::nextPacketRange;
224         using mixin::init;
225         using mixin::initSize;
226     };
227     typedef ConcretePacket<ICMPv6ErrParamProblemType> ICMPv6ErrParamProblem;
228     
229     //#############################################################
230     //ICMPv6 MLDv2 (RFC 3810) Multicast Listener Query
231     //#############################################################
232     struct MLDv2ListenerQueryParser : public PacketParserBase
233     {
234 #      include SENF_PARSER()
235         //need a variant here
236         // a.) maxResponseCode < 32768 =>Interger
237         // b.) maxResponseCode >=32768 => float (is there a float parser???)
238         /* 
239         float value as followed: 
240         0 1 2 3 4 5 6 7 8 9 A B C D E F
241         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242         |1| exp |          mant         |
243         +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
244         
245         SENF_PARSER_FIELD ( maxResponseCode, UInt16Parser       );
246         SENF_PARSER_FIELD ( reserved,        UInt16Parser       ); // set to zero by default
247         SENF_PARSER_FIELD ( mcAddress,       INet6AddressParser );
248         SENF_PARSER_BITFIELD ( resv,  4, unsigned ); // set to zero by default
249         SENF_PARSER_BITFIELD ( sFlag, 1, unsigned );
250         SENF_PARSER_BITFIELD ( qrv,   3, unsigned );
251         SENF_PARSER_FIELD    ( qqic, UInt8Parser );
252         SENF_PARSER_PRIVATE_FIELD ( nrSources, UInt16Parser );
253         SENF_PARSER_VECTOR   (srcAddresses, nrSources, INet6AddressParser );
254         
255         SENF_PARSER_FINALIZE ( MLDv2ListenerQueryParser );
256         
257         SENF_PARSER_INIT() { 
258             reserved() = 0; 
259             resv() = 0;
260         }
261     };
262     
263     struct MLDv2ListenerQueryType
264         : public PacketTypeBase,
265           public PacketTypeMixin<MLDv2ListenerQueryType>
266     {
267         typedef PacketTypeMixin<MLDv2ListenerQueryType> mixin;
268         typedef ConcretePacket<MLDv2ListenerQueryType> packet;
269         typedef MLDv2ListenerQueryParser parser;
270         
271         using mixin::nextPacketRange;
272         using mixin::init;
273         using mixin::initSize;
274     };
275         
276     typedef ConcretePacket<MLDv2ListenerQueryType> MLDv2ListenerQuery;
277     
278     //#############################################################
279     //ICMPv6 MLDv2 (RFC 3810) Multicast Listener Report Message
280     //#############################################################
281     //First: the Multicast Address Record Parser
282     struct MLDv2AddressRecordParser : public PacketParserBase
283     {
284 #       include SENF_PARSER()
285         
286         SENF_PARSER_FIELD   ( recordType, UInt8Parser );
287         SENF_PARSER_PRIVATE_FIELD   ( auxDataLen, UInt8Parser );
288         SENF_PARSER_PRIVATE_FIELD   ( nrOfSrcs, UInt16Parser );
289         SENF_PARSER_FIELD   ( mcAddress, INet6AddressParser);
290         SENF_PARSER_VECTOR  ( srcAddresses, nrOfSrcs, INet6AddressParser );
291         SENF_PARSER_VECTOR  ( auxData, auxDataLen, UInt32Parser );
292         
293         SENF_PARSER_FINALIZE ( MLDv2AddressRecordParser );
294     };
295     
296     struct MLDv2ListenerReportParser : public PacketParserBase
297     {
298 #       include SENF_PARSER()
299         
300         SENF_PARSER_FIELD   ( reserved, UInt16Parser );   //set to zero by default
301         SENF_PARSER_PRIVATE_FIELD   ( nrMcastAddrRecords_, UInt16Parser );
302         SENF_PARSER_LIST    ( mcastAddrRecords, nrMcastAddrRecords_, MLDv2AddressRecordParser );
303         
304         SENF_PARSER_FINALIZE ( MLDv2ListenerReportParser );
305         
306         SENF_PARSER_INIT() { 
307             reserved() = 0; 
308         }
309     };
310     
311     struct MLDv2ListenerReportType
312         : public PacketTypeBase,
313           public PacketTypeMixin<MLDv2ListenerReportType>
314     {
315         typedef PacketTypeMixin<MLDv2ListenerReportType> mixin;
316         typedef ConcretePacket<MLDv2ListenerReportType> packet;
317         typedef MLDv2ListenerReportParser parser;
318         
319         using mixin::nextPacketRange;
320         using mixin::init;
321         using mixin::initSize;
322     };
323         
324     typedef ConcretePacket<MLDv2ListenerReportType> MLDv2ListenerReport;
325 }
326
327 #endif