PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/fwbuilder-4.1.2/src/iptlib/RoutingCompiler_ipt.h

#
C Header | 195 lines | 83 code | 42 blank | 70 comment | 0 complexity | 18f6f68fc34843f33862dd65a617bda6 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. Firewall Builder Routing add-on
  3. Copyright (C) 2004 Compal GmbH, Germany
  4. Author: Tidei Maurizio <fwbuilder-routing at compal.de>
  5. Permission is hereby granted, free of charge, to any person
  6. obtaining a copy of this software and associated documentation files
  7. (the "Software"), to deal in the Software without restriction,
  8. including without limitation the rights to use, copy, modify, merge,
  9. publish, distribute, sublicense, and/or sell copies of the Software,
  10. and to permit persons to whom the Software is furnished to do so,
  11. subject to the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  18. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. SOFTWARE.
  22. */
  23. #ifndef __ROUTINGCOMPILER_IPT_HH__
  24. #define __ROUTINGCOMPILER_IPT_HH__
  25. #include <fwbuilder/libfwbuilder-config.h>
  26. #include "fwcompiler/RoutingCompiler.h"
  27. #include "fwbuilder/RuleElement.h"
  28. #include "config.h"
  29. namespace libfwbuilder {
  30. class RuleElementRDst;
  31. class RuleElementRItf;
  32. class RuleElementRGtw;
  33. };
  34. namespace fwcompiler {
  35. class RoutingCompiler_ipt : public RoutingCompiler {
  36. protected:
  37. /**
  38. * prints rule in some universal format (close to that visible
  39. * to user in the GUI). Used for debugging purposes. This method
  40. * calls RoutingCompiler::debugPrintRule
  41. */
  42. virtual std::string debugPrintRule(libfwbuilder::Rule *rule);
  43. /**
  44. * processes rules with negation in Dst if it holds only one object
  45. */
  46. DECLARE_ROUTING_RULE_PROCESSOR(singleDstNegation);
  47. /**
  48. * processes rules with negation in Dst
  49. */
  50. DECLARE_ROUTING_RULE_PROCESSOR(DstNegation);
  51. /**
  52. * check if we have to install default route
  53. */
  54. DECLARE_ROUTING_RULE_PROCESSOR(FindDefaultRoute);
  55. /**
  56. * expand address range objects in destination
  57. */
  58. DECLARE_ROUTING_RULE_PROCESSOR(addressRangesInDst);
  59. /**
  60. * remove duplicate rules
  61. */
  62. class PrintRule;
  63. class optimize3 : public RoutingRuleProcessor
  64. {
  65. std::map<std::string, bool> rules_seen_so_far;
  66. RoutingCompiler_ipt::PrintRule *printRule;
  67. public:
  68. optimize3(const std::string &name) : RoutingRuleProcessor(name){
  69. printRule=NULL;
  70. }
  71. virtual bool processNext();
  72. };
  73. friend class RoutingCompiler_ipt::optimize3;
  74. /**
  75. * eliminates duplicate objects in DST. Uses default comparison
  76. * in eliminateDuplicatesInRE which compares IDs
  77. */
  78. class eliminateDuplicatesInDST : public eliminateDuplicatesInRE
  79. {
  80. public:
  81. eliminateDuplicatesInDST(const std::string &n) :
  82. eliminateDuplicatesInRE(n,libfwbuilder::RuleElementRDst::TYPENAME) {}
  83. };
  84. /**
  85. * eliminates duplicate rules
  86. */
  87. class eliminateDuplicateRules : public RoutingRuleProcessor
  88. {
  89. std::map<std::string, std::string> rules_seen_so_far;
  90. std::map<std::string, std::string>::iterator rules_it;
  91. RoutingCompiler_ipt::PrintRule *printRule;
  92. public:
  93. eliminateDuplicateRules(const std::string &name) : RoutingRuleProcessor(name){
  94. printRule=NULL;
  95. }
  96. virtual bool processNext();
  97. };
  98. /**
  99. * prints single policy rule, assuming all groups have been
  100. * expanded, destination holds exactly one object, and this
  101. * object is not a group. Negation should also have been taken
  102. * care of before this method is called.
  103. *
  104. * This processor is not necessarily the last in the
  105. * conveyor, so it should push rules back to tmp_queue (for
  106. * example there could be progress indicator processor after
  107. * this one)
  108. */
  109. class PrintRule : public RoutingRuleProcessor
  110. {
  111. bool print_once_on_top;
  112. std::string current_rule_label;
  113. virtual std::string _printAddr(libfwbuilder::Address *o);
  114. public:
  115. PrintRule(const std::string &name);
  116. virtual bool processNext();
  117. std::string RoutingRuleToString(libfwbuilder::RoutingRule *r);
  118. std::string _printRGtw(libfwbuilder::RoutingRule *r);
  119. std::string _printRItf(libfwbuilder::RoutingRule *r);
  120. std::string _printRDst(libfwbuilder::RoutingRule *r);
  121. };
  122. friend class RoutingCompiler_ipt::PrintRule;
  123. virtual std::string myPlatformName();
  124. // These buffers are needed to collect output generated from the single ECMP rules belonging to one destination,
  125. // because all these routes have to be activated with a single ip command. So ECMP ip commands are built up gradually
  126. // during compilation and inserted in the shell script after all rules are processed.
  127. std::map< std::string, std::string> ecmp_rules_buffer; // sortedDstId+metric-->nexthops
  128. std::map< std::string, std::string> ecmp_comments_buffer; // sortedDstId+metric-->rule's info for the fw script
  129. bool have_default_route;
  130. bool defined_restore_script_output;
  131. public:
  132. RoutingCompiler_ipt(libfwbuilder::FWObjectDatabase *_db,
  133. libfwbuilder::Firewall *fw, bool ipv6_policy,
  134. fwcompiler::OSConfigurator *_oscnf) :
  135. RoutingCompiler(_db, fw, ipv6_policy, _oscnf)
  136. {
  137. have_default_route = false;
  138. defined_restore_script_output = false;
  139. }
  140. virtual void verifyPlatform();
  141. virtual int prolog();
  142. virtual void compile();
  143. virtual void epilog();
  144. };
  145. }
  146. #endif