Added ICMPv6 types for IPv6 Neighbor Discovery
[senf.git] / senf / Packets / DefaultBundle / NDPOptions.hh
1 // $Id: ICMPv6TypePacket.hh 1449 2009-09-25 23:03:48Z g0dil $
2 //
3 // Copyright (C) 2010
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Sauer <ssauer@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_NDPOptions_
26 #define HH_SENF_Packets_DefaultBundle_NDPOptions_ 1
27
28 // Custom includes
29 #include <senf/Packets/Packets.hh>
30 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
31 #include <senf/Packets/DefaultBundle/ListOptionTypeParser.hh>
32
33 namespace senf {
34     //#############################################################
35     //ICMPv6 Neighbor Discovery (RFC 4861) Options
36     //#############################################################
37     struct NDPOptionParser : public PacketParserBase
38     {
39     public:
40 #       include SENF_PARSER()
41         SENF_PARSER_FIELD    ( type, UInt8Parser );
42         SENF_PARSER_FIELD    ( length, UInt8Parser );
43         SENF_PARSER_FINALIZE ( NDPOptionParser );
44
45         typedef GenericTLVParserRegistry<NDPOptionParser> Registry;
46     };
47     typedef GenericTLVParserBase<NDPOptionParser> NDPGenericOptionParser;
48
49     struct NDPSourceLLAddressTLVParser : public NDPOptionParser
50     {
51 #      include SENF_PARSER()
52         SENF_PARSER_INHERIT  ( NDPOptionParser );
53         SENF_PARSER_FIELD    ( source, MACAddressParser);
54         SENF_PARSER_FINALIZE ( NDPSourceLLAddressTLVParser);
55
56         SENF_PARSER_INIT() {
57             defaultInit();
58             type() = typeId;
59             length() = 1;
60         }
61         static const type_t::value_type typeId = 0x01;
62         void dump(std::ostream & os) const;
63     };
64
65     struct NDPTargetLLAddressTLVParser : public NDPOptionParser
66     {
67 #      include SENF_PARSER()
68         SENF_PARSER_INHERIT  ( NDPOptionParser );
69         SENF_PARSER_FIELD    ( target, MACAddressParser );
70         SENF_PARSER_FINALIZE ( NDPTargetLLAddressTLVParser );
71
72         SENF_PARSER_INIT() {
73             defaultInit();
74             type() = typeId;
75             length() = 1;
76         }
77         static const UInt8Parser::value_type typeId = 0x02;
78         void dump(std::ostream & os) const;
79     };
80
81     struct NDPPrefixInformationTLVParser : public NDPOptionParser
82     {
83 #      include SENF_PARSER()
84         SENF_PARSER_INHERIT          ( NDPOptionParser );
85         SENF_PARSER_FIELD            ( prefixLength, UInt8Parser );
86         SENF_PARSER_BITFIELD         ( l, 1, bool );
87         SENF_PARSER_BITFIELD         ( a, 1, bool );
88         SENF_PARSER_PRIVATE_BITFIELD ( reserved1, 6, unsigned );
89         SENF_PARSER_FIELD            ( validLifetime, UInt32Parser );
90         SENF_PARSER_FIELD            ( preferredLifetime, UInt32Parser );
91         SENF_PARSER_PRIVATE_BITFIELD ( reserved2, 32, unsigned );
92         SENF_PARSER_FIELD            ( prefix, INet6AddressParser );
93         SENF_PARSER_FINALIZE         ( NDPPrefixInformationTLVParser );
94
95         SENF_PARSER_INIT() {
96             defaultInit();
97             type() = typeId;
98             length() = 4;
99             reserved1() = 0;
100             reserved2() = 0;
101         }
102         static const UInt8Parser::value_type typeId = 0x03;
103         void dump(std::ostream & os) const;
104     };
105
106     struct NDPMTUTLVParser : public NDPOptionParser
107     {
108 #      include SENF_PARSER()
109         SENF_PARSER_INHERIT          ( NDPOptionParser );
110         SENF_PARSER_PRIVATE_BITFIELD ( reserved, 16, unsigned );
111         SENF_PARSER_FIELD            ( mtu, UInt32Parser );
112         SENF_PARSER_FINALIZE         ( NDPMTUTLVParser );
113
114         SENF_PARSER_INIT() {
115             defaultInit();
116             type() = typeId;
117             length() = 1;
118             reserved() = 0;
119         }
120         static const UInt8Parser::value_type typeId = 0x05;
121         void dump(std::ostream & os) const;
122     };
123 }
124
125 #endif
126
127
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"
135 // comment-column: 40
136 // End:
137