|
| 1 | +open HolKernel boolLib liteLib simpLib Parse bossLib; |
| 2 | + |
| 3 | +open policy_arith_to_varTheory; |
| 4 | + |
| 5 | +open bdd_utilsLib; |
| 6 | +open sptrees_fwd_proofLib; |
| 7 | + |
| 8 | + |
| 9 | +val _ = new_theory "internet_firewall_3"; |
| 10 | + |
| 11 | +val _ = type_abbrev("single_rule", “:((string# num list) action_expr) arith_rule”); |
| 12 | + |
| 13 | +val test_pd_type = “[("h", type_record [("srcPort", type_length 16); |
| 14 | + ("dstPort", type_length 16); |
| 15 | + ("srcNAT", type_length 16); |
| 16 | + ("dstNAT", type_length 16)])]”; |
| 17 | + |
| 18 | +(************************************************) |
| 19 | + |
| 20 | +(* rule 1 *) |
| 21 | + |
| 22 | +val is_srcPort_le_57222 = “(arithm_le (lv_acc (lv_x "h") "srcPort") ^(bdd_utilsLib.make_bv 57222 16))”; |
| 23 | +val is_srcPort_ge_57222 = “(arithm_ge (lv_acc (lv_x "h") "srcPort") ^(bdd_utilsLib.make_bv 57222 16))”; |
| 24 | + |
| 25 | +val is_dstPort_le_53 = “(arithm_le (lv_acc (lv_x "h") "dstPort") ^(bdd_utilsLib.make_bv 53 16))”; |
| 26 | +val is_dstPort_ge_53 = “(arithm_ge (lv_acc (lv_x "h") "dstPort") ^(bdd_utilsLib.make_bv 53 16))”; |
| 27 | + |
| 28 | +val is_srcNAT_le_54587 = “(arithm_le (lv_acc (lv_x "h") "srcNAT") ^(bdd_utilsLib.make_bv 54587 16))”; |
| 29 | +val is_srcNAT_ge_54587 = “(arithm_ge (lv_acc (lv_x "h") "srcNAT") ^(bdd_utilsLib.make_bv 54587 16))”; |
| 30 | + |
| 31 | +val is_dstNAT_le_53 = “(arithm_le (lv_acc (lv_x "h") "dstNAT") ^(bdd_utilsLib.make_bv 53 16))”; |
| 32 | +val is_dstNAT_ge_53 = “(arithm_ge (lv_acc (lv_x "h") "dstNAT") ^(bdd_utilsLib.make_bv 53 16))”; |
| 33 | + |
| 34 | + |
| 35 | +val arith_policy_rule1 = “((arith_and (arith_a ^is_srcPort_le_57222) |
| 36 | + (arith_and (arith_a ^is_srcPort_ge_57222) |
| 37 | + (arith_and (arith_a ^is_dstPort_le_53) |
| 38 | + (arith_and (arith_a ^is_dstPort_ge_53) |
| 39 | + (arith_and (arith_a ^is_srcNAT_le_54587) |
| 40 | + (arith_and (arith_a ^is_srcNAT_ge_54587) |
| 41 | + (arith_and (arith_a ^is_dstNAT_le_53) |
| 42 | + (arith_a ^is_dstNAT_ge_53)))))))) , |
| 43 | + action ("allow",[1])):single_rule”; |
| 44 | + |
| 45 | +(* rule 2 *) |
| 46 | + |
| 47 | +val is_srcPort_le_56258 = “(arithm_le (lv_acc (lv_x "h") "srcPort") ^(bdd_utilsLib.make_bv 56258 16))”; |
| 48 | +val is_srcPort_ge_56258 = “(arithm_ge (lv_acc (lv_x "h") "srcPort") ^(bdd_utilsLib.make_bv 56258 16))”; |
| 49 | + |
| 50 | +val is_dstPort_le_3389 = “(arithm_le (lv_acc (lv_x "h") "dstPort") ^(bdd_utilsLib.make_bv 3389 16))”; |
| 51 | +val is_dstPort_ge_3389 = “(arithm_ge (lv_acc (lv_x "h") "dstPort") ^(bdd_utilsLib.make_bv 3389 16))”; |
| 52 | + |
| 53 | +val is_srcNAT_le_56258 = “(arithm_le (lv_acc (lv_x "h") "srcNAT") ^(bdd_utilsLib.make_bv 56258 16))”; |
| 54 | +val is_srcNAT_ge_56258 = “(arithm_ge (lv_acc (lv_x "h") "srcNAT") ^(bdd_utilsLib.make_bv 56258 16))”; |
| 55 | + |
| 56 | +val is_dstNAT_le_3389 = “(arithm_le (lv_acc (lv_x "h") "dstNAT") ^(bdd_utilsLib.make_bv 3389 16))”; |
| 57 | +val is_dstNAT_ge_3389 = “(arithm_ge (lv_acc (lv_x "h") "dstNAT") ^(bdd_utilsLib.make_bv 3389 16))”; |
| 58 | + |
| 59 | + |
| 60 | +val arith_policy_rule2 = “((arith_and (arith_a ^is_srcPort_le_56258) |
| 61 | + (arith_and (arith_a ^is_srcPort_ge_56258) |
| 62 | + (arith_and (arith_a ^is_dstPort_le_3389) |
| 63 | + (arith_and (arith_a ^is_dstPort_ge_3389) |
| 64 | + (arith_and (arith_a ^is_srcNAT_le_56258) |
| 65 | + (arith_and (arith_a ^is_srcNAT_ge_56258) |
| 66 | + (arith_and (arith_a ^is_dstNAT_le_3389) |
| 67 | + (arith_a ^is_dstNAT_ge_3389)))))))) , |
| 68 | + action ("allow",[1])):single_rule”; |
| 69 | + |
| 70 | +(* rule 3 *) |
| 71 | + |
| 72 | +val is_srcPort_le_6881 = “(arithm_le (lv_acc (lv_x "h") "srcPort") ^(bdd_utilsLib.make_bv 6881 16))”; |
| 73 | +val is_srcPort_ge_6881 = “(arithm_ge (lv_acc (lv_x "h") "srcPort") ^(bdd_utilsLib.make_bv 6881 16))”; |
| 74 | + |
| 75 | +val is_dstPort_le_50321 = “(arithm_le (lv_acc (lv_x "h") "dstPort") ^(bdd_utilsLib.make_bv 50321 16))”; |
| 76 | +val is_dstPort_ge_50321 = “(arithm_ge (lv_acc (lv_x "h") "dstPort") ^(bdd_utilsLib.make_bv 50321 16))”; |
| 77 | + |
| 78 | +val is_srcNAT_le_43265 = “(arithm_le (lv_acc (lv_x "h") "srcNAT") ^(bdd_utilsLib.make_bv 43265 16))”; |
| 79 | +val is_srcNAT_ge_43265 = “(arithm_ge (lv_acc (lv_x "h") "srcNAT") ^(bdd_utilsLib.make_bv 43265 16))”; |
| 80 | + |
| 81 | +val is_dstNAT_le_50321 = “(arithm_le (lv_acc (lv_x "h") "dstNAT") ^(bdd_utilsLib.make_bv 50321 16))”; |
| 82 | +val is_dstNAT_ge_50321 = “(arithm_ge (lv_acc (lv_x "h") "dstNAT") ^(bdd_utilsLib.make_bv 50321 16))”; |
| 83 | + |
| 84 | + |
| 85 | +val arith_policy_rule3 = “((arith_and (arith_a ^is_srcPort_le_6881) |
| 86 | + (arith_and (arith_a ^is_srcPort_ge_6881) |
| 87 | + (arith_and (arith_a ^is_dstPort_le_50321) |
| 88 | + (arith_and (arith_a ^is_dstPort_ge_50321) |
| 89 | + (arith_and (arith_a ^is_srcNAT_le_43265) |
| 90 | + (arith_and (arith_a ^is_srcNAT_ge_43265) |
| 91 | + (arith_and (arith_a ^is_dstNAT_le_50321) |
| 92 | + (arith_a ^is_dstNAT_ge_50321)))))))) , |
| 93 | + action ("allow",[1])):single_rule”; |
| 94 | + |
| 95 | +(* Default policy rule *) |
| 96 | +val arith_policy_rule_default = “(arith_a a_True, action ("drop", [])):single_rule”; |
| 97 | + |
| 98 | +(* Combined arith policy list *) |
| 99 | +val arith_policy = “[ |
| 100 | + ^arith_policy_rule1; |
| 101 | + ^arith_policy_rule2; |
| 102 | + ^arith_policy_rule3; |
| 103 | + ^arith_policy_rule_default |
| 104 | +]:single_rule list”; |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +(* Combined policy mapping *) |
| 109 | +val policy_me = “[ |
| 110 | + ("is_srcPort_le_57222", ^is_srcPort_le_57222); |
| 111 | + ("is_srcPort_ge_57222", ^is_srcPort_ge_57222); |
| 112 | + ("is_dstPort_le_53", ^is_dstPort_le_53); |
| 113 | + ("is_dstPort_ge_53", ^is_dstPort_ge_53); |
| 114 | + ("is_srcNAT_le_54587", ^is_srcNAT_le_54587); |
| 115 | + ("is_srcNAT_ge_54587", ^is_srcNAT_ge_54587); |
| 116 | + ("is_dstNAT_le_53", ^is_dstNAT_le_53); |
| 117 | + ("is_dstNAT_ge_53", ^is_dstNAT_ge_53); |
| 118 | + ("is_srcPort_le_56258", ^is_srcPort_le_56258); |
| 119 | + ("is_srcPort_ge_56258", ^is_srcPort_ge_56258); |
| 120 | + ("is_dstPort_le_3389", ^is_dstPort_le_3389); |
| 121 | + ("is_dstPort_ge_3389", ^is_dstPort_ge_3389); |
| 122 | + ("is_srcNAT_le_56258", ^is_srcNAT_le_56258); |
| 123 | + ("is_srcNAT_ge_56258", ^is_srcNAT_ge_56258); |
| 124 | + ("is_dstNAT_le_3389", ^is_dstNAT_le_3389); |
| 125 | + ("is_dstNAT_ge_3389", ^is_dstNAT_ge_3389); |
| 126 | + ("is_srcPort_le_6881", ^is_srcPort_le_6881); |
| 127 | + ("is_srcPort_ge_6881", ^is_srcPort_ge_6881); |
| 128 | + ("is_dstPort_le_50321", ^is_dstPort_le_50321); |
| 129 | + ("is_dstPort_ge_50321", ^is_dstPort_ge_50321); |
| 130 | + ("is_srcNAT_le_43265", ^is_srcNAT_le_43265); |
| 131 | + ("is_srcNAT_ge_43265", ^is_srcNAT_ge_43265); |
| 132 | + ("is_dstNAT_le_50321", ^is_dstNAT_le_50321); |
| 133 | + ("is_dstNAT_ge_50321", ^is_dstNAT_ge_50321); |
| 134 | +]”; |
| 135 | + |
| 136 | +(* Grouped policy ordering *) |
| 137 | +val policy_full_order = “[ |
| 138 | + ("srcPortGrp",["is_srcPort_le_57222";"is_srcPort_ge_57222";"is_srcPort_le_56258";"is_srcPort_ge_56258";"is_srcPort_le_6881";"is_srcPort_ge_6881"]); |
| 139 | + ("dstPortGrp",["is_dstPort_le_53";"is_dstPort_ge_53";"is_dstPort_le_3389";"is_dstPort_ge_3389";"is_dstPort_le_50321";"is_dstPort_ge_50321"]); |
| 140 | + ("srcNATGrp" ,["is_srcNAT_le_54587";"is_srcNAT_ge_54587";"is_srcNAT_le_56258";"is_srcNAT_ge_56258";"is_srcNAT_le_43265";"is_srcNAT_ge_43265"]); |
| 141 | + ("dstNATGrp" ,["is_dstNAT_le_53";"is_dstNAT_ge_53";"is_dstNAT_le_3389";"is_dstNAT_ge_3389";"is_dstNAT_le_50321";"is_dstNAT_ge_50321"]) |
| 142 | +]”; |
| 143 | + |
| 144 | +(* Flat policy order (grouped) *) |
| 145 | +val policy_order = “["is_srcPort_le_57222"; "is_srcPort_ge_57222"; "is_srcPort_le_56258"; "is_srcPort_ge_56258"; "is_srcPort_le_6881"; "is_srcPort_ge_6881"; "is_dstPort_le_53"; "is_dstPort_ge_53"; "is_dstPort_le_3389"; "is_dstPort_ge_3389"; "is_dstPort_le_50321"; "is_dstPort_ge_50321"; "is_srcNAT_le_54587"; "is_srcNAT_ge_54587"; "is_srcNAT_le_56258"; "is_srcNAT_ge_56258"; "is_srcNAT_le_43265"; "is_srcNAT_ge_43265"; "is_dstNAT_le_53"; "is_dstNAT_ge_53"; "is_dstNAT_le_3389"; "is_dstNAT_ge_3389"; "is_dstNAT_le_50321"; "is_dstNAT_ge_50321"]”; |
| 146 | + |
| 147 | + |
| 148 | +(***********************************************) |
| 149 | + |
| 150 | +val final_thm_res = |
| 151 | +sptrees_fwd_proofLib.sptrees_convert_arith_policy_to_interval_tables (arith_policy, policy_me, test_pd_type, policy_full_order, policy_order) |
| 152 | + |
| 153 | +val _ = export_theory (); |
0 commit comments