/IOS-simple/demo.rkt

http://github.com/tnelson/Margrave · Racket · 226 lines · 129 code · 47 blank · 50 comment · 0 complexity · b52a404efb5972d98e970dc150d7c90a MD5 · raw file

  1. ; Copyright Š 2009-2010 Brown University and Worcester Polytechnic Institute.
  2. ;
  3. ; This file is part of Margrave.
  4. ; Margrave is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU Lesser General Public License as published by
  6. ; the Free Software Foundation, either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; Margrave is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ; GNU Lesser General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU Lesser General Public License
  15. ; along with Margrave. If not, see <http://www.gnu.org/licenses/>.
  16. #lang racket
  17. (require margrave
  18. margrave/margrave-ios)
  19. (define my-vector "(ahostname, entry-interface,
  20. src-addr-in, src-addr-out,
  21. dest-addr-in, dest-addr-out,
  22. protocol, message, flags,
  23. src-port-in, src-port-out,
  24. dest-port-in, dest-port-out,
  25. length, next-hop, exit-interface)")
  26. (define (run-queries-for-example)
  27. ; Start Margrave's java engine
  28. ; Pass path of the engine files: 1 level up from here.
  29. ; (start-margrave-engine (build-path (current-directory) 'up))
  30. (start-margrave-engine)
  31. ; Load all the policies
  32. ; InboundACL -> InboundACL1, InboundACL2, InboundACL3 respectively.
  33. (load-ios-policies (build-path (current-directory) "initial") "" "1")
  34. (load-ios-policies (build-path (current-directory) "change1") "" "2")
  35. (load-ios-policies (build-path (current-directory) "change2") "" "3")
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ; which-packets
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. (printf "~n~nWhich-packets:~n")
  40. ; AND fe0(entry-interface)
  41. ; AND prot-tcp(protocol)
  42. ; AND ip-192-168-5-10(dest-addr-in)
  43. ; AND ip-10-1-1-2(ip-addr-in)
  44. (display-response (mtext "EXPLORE InboundACL1:Permit(ahostname, entry-interface,
  45. src-addr-in, src-addr-out,
  46. dest-addr-in, dest-addr-out,
  47. protocol, message, flags,
  48. src-port-in, src-port-out,
  49. dest-port-in, dest-port-out,
  50. length, next-hop, exit-interface)
  51. TUPLING") )
  52. ; The TUPLING keyword activates the tupling optimization, which is very useful for firewalls.
  53. (display-response (mtext "GET ONE"))
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ; verification
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57. (printf "~n~nVerification:~n")
  58. (display-response (mtext "EXPLORE InboundACL1:Permit(ahostname, entry-interface,
  59. src-addr-in, src-addr-out,
  60. dest-addr-in, dest-addr-out,
  61. protocol, message, flags,
  62. src-port-in, src-port-out,
  63. dest-port-in, dest-port-out,
  64. length, next-hop, exit-interface)
  65. AND src-addr-in = 10.1.1.2
  66. AND fe0 = entry-interface
  67. TUPLING") )
  68. (display-response (mtext "IS POSSIBLE?"))
  69. ;; due to gensym use, rule names will change along with line numbers and on each re-parse
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. ; rule responsibility
  72. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  73. (printf "~n~nRule-blaming:~n")
  74. (display-response (mtext (string-append "EXPLORE InboundACL1:Deny" my-vector
  75. " AND 10.1.1.2 = src-addr-in"
  76. " AND fe0 = entry-interface "
  77. " INCLUDE InboundACL1:Router-fe0-line9_applies" my-vector ","
  78. "InboundACL1:Router-fe0-line12_applies" my-vector
  79. " TUPLING")))
  80. (display-response (mtext (string-append "SHOW REALIZED InboundACL1:Router-fe0-line9_applies" my-vector ","
  81. "InboundACL1:Router-fe0-line12_applies" my-vector)))
  82. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  83. ; change-impact
  84. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  85. (printf "~n~nChange-impact:~n")
  86. ; vs change 1
  87. (display-response (mtext "EXPLORE (InboundACL1:Permit(ahostname, entry-interface,
  88. src-addr-in, src-addr-out,
  89. dest-addr-in, dest-addr-out,
  90. protocol, message, flags,
  91. src-port-in, src-port-out,
  92. dest-port-in, dest-port-out,
  93. length, next-hop, exit-interface)
  94. AND NOT InboundACL2:Permit(ahostname, entry-interface,
  95. src-addr-in, src-addr-out,
  96. dest-addr-in, dest-addr-out,
  97. protocol, message, flags,
  98. src-port-in, src-port-out,
  99. dest-port-in, dest-port-out,
  100. length, next-hop, exit-interface) )
  101. OR
  102. (InboundACL2:Permit(ahostname, entry-interface,
  103. src-addr-in, src-addr-out,
  104. dest-addr-in, dest-addr-out,
  105. protocol, message, flags,
  106. src-port-in, src-port-out,
  107. dest-port-in, dest-port-out,
  108. length, next-hop, exit-interface)
  109. AND NOT InboundACL1:Permit(ahostname, entry-interface,
  110. src-addr-in, src-addr-out,
  111. dest-addr-in, dest-addr-out,
  112. protocol, message, flags,
  113. src-port-in, src-port-out,
  114. dest-port-in, dest-port-out,
  115. length, next-hop, exit-interface) )
  116. TUPLING"))
  117. (display-response (mtext "IS POSSIBLE?"))
  118. ; Vs. change 2
  119. (display-response (mtext "EXPLORE (InboundACL1:Permit(ahostname, entry-interface,
  120. src-addr-in, src-addr-out,
  121. dest-addr-in, dest-addr-out,
  122. protocol, message, flags,
  123. src-port-in, src-port-out,
  124. dest-port-in, dest-port-out,
  125. length, next-hop, exit-interface)
  126. AND NOT InboundACL3:Permit(ahostname, entry-interface,
  127. src-addr-in, src-addr-out,
  128. dest-addr-in, dest-addr-out,
  129. protocol, message, flags,
  130. src-port-in, src-port-out,
  131. dest-port-in, dest-port-out,
  132. length, next-hop, exit-interface) )
  133. OR
  134. (InboundACL3:Permit(ahostname, entry-interface,
  135. src-addr-in, src-addr-out,
  136. dest-addr-in, dest-addr-out,
  137. protocol, message, flags,
  138. src-port-in, src-port-out,
  139. dest-port-in, dest-port-out,
  140. length, next-hop, exit-interface)
  141. AND NOT InboundACL1:Permit(ahostname, entry-interface,
  142. src-addr-in, src-addr-out,
  143. dest-addr-in, dest-addr-out,
  144. protocol, message, flags,
  145. src-port-in, src-port-out,
  146. dest-port-in, dest-port-out,
  147. length, next-hop, exit-interface) )
  148. TUPLING") )
  149. (display-response (mtext "IS POSSIBLE?"))
  150. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  151. ; Rule relationships
  152. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  153. (printf "~n~nRule relationships:~n")
  154. ;; This involves rules in the first change (InboundACL2)
  155. ; line 12 wants to apply: what prevents it from doing so?
  156. (display-response (mtext (string-append "EXPLORE InboundACL2:Router-fe0-line12_matches" my-vector
  157. " INCLUDE InboundACL2:Router-fe0-line9_applies" my-vector ","
  158. "InboundACL2:Router-fe0-line10_applies" my-vector ","
  159. "InboundACL2:Router-fe0-line11_applies" my-vector
  160. " TUPLING")))
  161. (display-response (mtext (string-append "SHOW REALIZED InboundACL2:Router-fe0-line9_applies" my-vector ","
  162. "InboundACL2:Router-fe0-line10_applies" my-vector ","
  163. "InboundACL2:Router-fe0-line11_applies" my-vector)))
  164. ; Computing superfluous rules
  165. ; ----> In sup-ios.rkt
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. ; 2.1 in other file
  168. ;(stop-margrave-engine)
  169. )