d4cc4a7846535134e206ac35613b19bf485b567d
[senf.git] / senf / Packets / DefaultBundle / NDPOptions.hh
1 // $Id$
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/IPv6Packet.hh>
32
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34 namespace senf {
35
36     //#############################################################
37     //ICMPv6 Neighbor Discovery (RFC 4861) Options
38     //#############################################################
39     struct NDPOptionParser : public PacketParserBase
40     {
41     public:
42 #       include SENF_PARSER()
43         SENF_PARSER_FIELD    ( type, UInt8Parser );
44         SENF_PARSER_FIELD    ( length, UInt8Parser );
45         SENF_PARSER_FINALIZE ( NDPOptionParser );
46
47         typedef GenericTLVParserRegistry<NDPOptionParser> Registry;
48     };
49
50     struct NDPGenericOptionParser : public GenericTLVParserBase<NDPOptionParser>
51     {
52         typedef GenericTLVParserBase<NDPOptionParser> base;
53         NDPGenericOptionParser(data_iterator i, state_type s) : base(i,s) {}
54
55         senf::PacketParserBase::size_type bytes() const
56         {
57             return length()*8;
58         }
59     };
60
61     struct NDPSourceLLAddressTLVParser : public NDPOptionParser
62     {
63 #       include SENF_PARSER()
64         SENF_PARSER_INHERIT  ( NDPOptionParser );
65         SENF_PARSER_FIELD    ( source, MACAddressParser);
66         SENF_PARSER_FINALIZE ( NDPSourceLLAddressTLVParser);
67
68         SENF_PARSER_INIT() {
69             defaultInit();
70             type() = typeId;
71             length() = 1;
72         }
73         static const type_t::value_type typeId = 0x01;
74         void dump(std::ostream & os) const;
75     };
76
77     struct NDPTargetLLAddressTLVParser : public NDPOptionParser
78     {
79 #       include SENF_PARSER()
80         SENF_PARSER_INHERIT  ( NDPOptionParser );
81         SENF_PARSER_FIELD    ( target, MACAddressParser );
82         SENF_PARSER_FINALIZE ( NDPTargetLLAddressTLVParser );
83
84         SENF_PARSER_INIT() {
85             defaultInit();
86             type() = typeId;
87             length() = 1;
88         }
89
90         senf::PacketParserBase::size_type bytes(NDPTargetLLAddressTLVParser p) {
91                     return length()*8;
92         }
93         static const type_t::value_type typeId = 0x02;
94         void dump(std::ostream & os) const;
95     };
96
97     struct NDPPrefixInformationTLVParser : public NDPOptionParser
98     {
99 #       include SENF_PARSER()
100         SENF_PARSER_INHERIT          ( NDPOptionParser );
101         SENF_PARSER_FIELD            ( prefixLength, UInt8Parser );
102         SENF_PARSER_BITFIELD         ( l, 1, bool );
103         SENF_PARSER_BITFIELD         ( a, 1, bool );
104         SENF_PARSER_PRIVATE_BITFIELD ( reserved1, 6, unsigned );
105         SENF_PARSER_FIELD            ( validLifetime, UInt32Parser );
106         SENF_PARSER_FIELD            ( preferredLifetime, UInt32Parser );
107         SENF_PARSER_PRIVATE_BITFIELD ( reserved2, 32, unsigned );
108         SENF_PARSER_FIELD            ( prefix, INet6AddressParser );
109         SENF_PARSER_FINALIZE         ( NDPPrefixInformationTLVParser );
110
111         SENF_PARSER_INIT() {
112             defaultInit();
113             type() = typeId;
114             length() = 4;
115             reserved1() = 0;
116             reserved2() = 0;
117         }
118         senf::PacketParserBase::size_type bytes(NDPPrefixInformationTLVParser p) {
119             return length()*8;
120         }
121         static const UInt8Parser::value_type typeId = 0x03;
122         void dump(std::ostream & os) const;
123     };
124
125     struct NDPMTUTLVParser : public NDPOptionParser
126     {
127 #       include SENF_PARSER()
128         SENF_PARSER_INHERIT          ( NDPOptionParser );
129         SENF_PARSER_PRIVATE_BITFIELD ( reserved, 16, unsigned );
130         SENF_PARSER_FIELD            ( mtu, UInt32Parser );
131         SENF_PARSER_FINALIZE         ( NDPMTUTLVParser );
132
133         SENF_PARSER_INIT() {
134             defaultInit();
135             type() = typeId;
136             length() = 1;
137             reserved() = 0;
138         }
139         static const UInt8Parser::value_type typeId = 0x05;
140         void dump(std::ostream & os) const;
141     };
142 }
143
144 //-/////////////////////////////////////////////////////////////////////////////////////////////////
145 //#include "NDPOptions.cci"
146 //#include "NDPOptions.ct"
147 //#include "NDPOptions.cti"
148 #endif
149
150 \f
151 // Local Variables:
152 // mode: c++
153 // fill-column: 100
154 // c-file-style: "senf"
155 // indent-tabs-mode: nil
156 // ispell-local-dictionary: "american"
157 // compile-command: "scons -u test"
158 // comment-column: 40
159 // End:
160