Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Msg.h
Go to the documentation of this file.
1 /*
2  * Dibbler - a portable DHCPv6
3  *
4  * authors: Tomasz Mrugalski <thomson@klub.com.pl>
5  * Marek Senderski <msend@o2.pl>
6  * changes: Michal Kowalczuk <michal@kowalczuk.eu>
7  *
8  * released under GNU GPL v2 only licence
9  */
10 
11 class TMsg;
12 #ifndef MSG_H
13 #define MSG_H
14 
15 #include <iostream>
16 #include <string>
17 #include <vector>
18 #include <list>
19 #include "SmartPtr.h"
20 #include "Container.h"
21 #include "DHCPConst.h"
22 #include "IPv6Addr.h"
23 #include "Opt.h"
24 #include "OptDUID.h"
25 #include "OptOptionRequest.h"
26 #include "Key.h"
27 #include "ScriptParams.h"
28 
29 class TOptStatusCode;
30 
31 // Hey! It's grampa of all messages
32 class TMsg
33 {
34  public:
35  // Used to create TMsg object (normal way)
36  TMsg(int iface, SPtr<TIPv6Addr> addr, int msgType);
37  TMsg(int iface, SPtr<TIPv6Addr> addr, int msgType, long transID);
38 
39  // used to create TMsg object based on received char[] data
40  TMsg(int iface, SPtr<TIPv6Addr> addr, char* &buf, int &bufSize);
41 
42  virtual int getSize();
43 
44  // transmit (or retransmit)
45 
46  virtual unsigned long getTimeout();
47 
48  virtual int storeSelf(char * buffer);
49 
50  virtual std::string getName() const = 0;
51 
52  // returns requested option (or NULL, there is no such option)
53  SPtr<TOpt> getOption(int type) const;
54  void firstOption();
55  int countOption();
56  void addOption(SPtr<TOpt> opt) { Options.push_back(opt); }
57 
58  virtual SPtr<TOpt> getOption();
59 
60  long getType();
61  long getTransID();
62  TOptList & getOptLst();
63  int getIface();
64  virtual ~TMsg();
65  bool isDone();
66  bool isDone(bool done);
67 
68  // useful auth stuff below
69  void calculateDigests(char* buffer, size_t len);
70 
72  void setAuthDigestPtr(char* ptr, unsigned len);
73  bool loadAuthKey();
74  void setAuthKey(const TKey& key);
75  TKey getAuthKey();
76 
77  bool validateAuthInfo(char *buf, int bufSize, AuthProtocols proto,
78  const DigestTypesLst& acceptedDigestTypes);
79  uint32_t getSPI();
80  void setSPI(uint32_t val);
82 
83  // notify scripts stuff
84  void* getNotifyScriptParams();
85 
87 
88  void setLocalAddr(SPtr<TIPv6Addr> myaddr);
90 
93 
96 
99 
100  protected:
101  int MsgType;
102  long TransID;
103 
104  bool delOption(int code);
105 
107  TOptList::iterator NextOpt; // to be removed together with firstOption() and getOption();
108  void setAttribs(int iface, SPtr<TIPv6Addr> addr,
109  int msgType, long transID);
110  virtual bool check(bool clntIDmandatory, bool srvIDmandatory);
111 
112  bool IsDone; // Is this transaction done?
113  int Iface; // logical interface (for direct messages it equals PhysicalIface
114  // for relayed messages Iface points to relayX, PhysicalInterface to ethX)
115 
116 
120 
123 
124  // Auth stuff
125  uint32_t SPI_; // Key identifier
126  char* AuthDigestPtr_; // Digest (pointer to Authentication Information field of OPTION AUTH)
127  unsigned AuthDigestLen_; // Length of the digest
128  TKey AuthKey_; // Auth Key
129 
130  // a pointer to NotifyScriptParams structure (if defined)
132 };
133 
134 typedef std::list< SPtr<TMsg> > TMsgLst;
135 
136 #endif
137