Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AddrMgr.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: Grzegorz Pluto <g.pluto(at)u-r-b-a-n(dot)pl>
7  *
8  * released under GNU GPL v2 licence
9  */
10 
11 class TAddrMgr;
12 #ifndef ADDRMGR_H
13 #define ADDRMGR_H
14 
15 #include <string>
16 #include <map>
17 #include "SmartPtr.h"
18 #include "Container.h"
19 #include "AddrClient.h"
20 #include "AddrIA.h"
21 
38 class TAddrMgr
39 {
40  public:
41 
43  typedef std::map<std::string, int> NameToIndexMapping;
44 
46  typedef std::map<int, std::string> IndexToNameMapping;
47 
48  friend std::ostream & operator<<(std::ostream & strum,TAddrMgr &x);
49  TAddrMgr(const std::string& addrdb, bool loadfile = false);
50  virtual ~TAddrMgr();
51 
52  bool updateInterfacesInfo(const NameToIndexMapping& nameToIndex,
53  const IndexToNameMapping& indexToName);
54 
56  const NameToIndexMapping& nameToIndex,
57  const IndexToNameMapping& indexToName);
58 
59  //--- Client container ---
61  void firstClient();
66  int countClient();
67  bool delClient(SPtr<TDUID> duid);
68 
69  // checks if address is conformant to current configuration (used in loadDB())
70  virtual bool verifyAddr(SPtr<TIPv6Addr> addr) { return true; }
71  virtual bool verifyPrefix(SPtr<TIPv6Addr> addr) { return true; }
72 
73  // --- prefix related ---
74  virtual bool addPrefix(SPtr<TDUID> clntDuid, SPtr<TIPv6Addr> clntAddr,
75  const std::string& ifname,
76  int ifindex, unsigned long IAID, unsigned long T1, unsigned long T2,
77  SPtr<TIPv6Addr> prefix, unsigned long pref, unsigned long valid,
78  int length, bool quiet);
79  virtual bool updatePrefix(SPtr<TDUID> duid , SPtr<TIPv6Addr> addr,
80  const std::string& ifname,
81  int ifindex, unsigned long IAID, unsigned long T1,
82  unsigned long T2, SPtr<TIPv6Addr> prefix, unsigned long pref,
83  unsigned long valid, int length, bool quiet);
84 
85  virtual bool delPrefix(SPtr<TDUID> clntDuid, unsigned long IAID,
86  SPtr<TIPv6Addr> prefix, bool quiet);
87  bool prefixIsFree(SPtr<TIPv6Addr> prefix);
88 
89  //--- Time related methods ---
90  unsigned long getT1Timeout();
91  unsigned long getT2Timeout();
92  unsigned long getPrefTimeout();
93  unsigned long getValidTimeout();
94 
95  // --- backup/restore ---
96  void dbLoad(const char * xmlFile);
97  virtual void dump();
98  bool isDone();
99 
100 #ifdef MOD_LIBXML2
101  // database loading methods that use libxml2
102  xmlDocPtr xmlLoad(const char * filename);
103  SPtr<TAddrAddr> parseAddrAddr(xmlDocPtr doc, xmlNodePtr xmlAddr, int depth);
104  SPtr<TAddrIA> libxml_parseAddrIA(xmlDocPtr doc, xmlNodePtr xmlIA, int depth);
105  SPtr<TAddrClient> parseAddrClient(xmlDocPtr doc, xmlNodePtr xmlClient, int depth);
106  void parseAddrMgr(xmlDocPtr doc,int depth);
107 #else
108  // database loading methods that use internal loading routines
109  bool xmlLoadBuiltIn(const char * xmlFile);
110  SPtr<TAddrClient> parseAddrClient(const char * xmlFile, FILE *f);
111  SPtr<TAddrIA> parseAddrIA(const char * xmlFile, FILE * f, int t1,int t2,
112  int iaid, const std::string& ifname, int ifindex,
113  SPtr<TIPv6Addr> unicast = SPtr<TIPv6Addr>());
114  SPtr<TAddrIA> parseAddrPD(const char * xmlFile, FILE * f, int t1,int t2,
115  int iaid, const std::string& ifname, int ifindex,
116  SPtr<TIPv6Addr> unicast = SPtr<TIPv6Addr>());
117  SPtr<TAddrAddr> parseAddrAddr(const char * xmlFile, char * buf,bool pd);
118  SPtr<TAddrPrefix> parseAddrPrefix(const char * xmlFile, char * buf,bool pd);
119  SPtr<TAddrIA> parseAddrTA(const char * xmlFile, FILE *f);
120 #endif
121 
122  uint64_t getNextReplayDetectionValue();
123 
124 protected:
125  virtual void print(std::ostream & out) = 0;
126  bool addPrefix(SPtr<TAddrClient> client, SPtr<TDUID> duid , SPtr<TIPv6Addr> clntAddr,
127  const std::string& ifname, int ifindex, unsigned long IAID,
128  unsigned long T1, unsigned long T2, SPtr<TIPv6Addr> prefix,
129  unsigned long pref, unsigned long valid, int length, bool quiet);
130  bool updatePrefix(SPtr<TAddrClient> client, SPtr<TDUID> duid , SPtr<TIPv6Addr> clntAddr,
131  int iface, unsigned long IAID, unsigned long T1, unsigned long T2,
132  SPtr<TIPv6Addr> prefix, unsigned long pref, unsigned long valid,
133  int length, bool quiet);
134 
135  bool IsDone;
136  TContainer< SPtr<TAddrClient> > ClntsLst;
137  std::string XmlFile;
138 
141 
143 };
144 
145 #endif
146