PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/puphpet/puppet/modules/firewall/spec/fixtures/iptables/conversion_hash.rb

https://github.com/innesm4/Environment-setup
Ruby | 934 lines | 924 code | 3 blank | 7 comment | 0 complexity | c63c630866e543e6f5e23dc30ec53212 MD5 | raw file
Possible License(s): Apache-2.0
  1. # These hashes allow us to iterate across a series of test data
  2. # creating rspec examples for each parameter to ensure the input :line
  3. # extrapolates to the desired value for the parameter in question. And
  4. # vice-versa
  5. # This hash is for testing a line conversion to a hash of parameters
  6. # which will be used to create a resource.
  7. ARGS_TO_HASH = {
  8. 'dport_and_sport' => {
  9. :line => '-A nova-compute-FORWARD -s 0.0.0.0/32 -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -j ACCEPT',
  10. :table => 'filter',
  11. :params => {
  12. :action => 'accept',
  13. :chain => 'nova-compute-FORWARD',
  14. :source => '0.0.0.0/32',
  15. :destination => '255.255.255.255/32',
  16. :sport => ['68'],
  17. :dport => ['67'],
  18. :proto => 'udp',
  19. },
  20. },
  21. 'long_rule_1' => {
  22. :line => '-A INPUT -s 1.1.1.1/32 -d 1.1.1.1/32 -p tcp -m multiport --dports 7061,7062 -m multiport --sports 7061,7062 -m comment --comment "000 allow foo" -j ACCEPT',
  23. :table => 'filter',
  24. :compare_all => true,
  25. :params => {
  26. :action => "accept",
  27. :chain => "INPUT",
  28. :destination => "1.1.1.1/32",
  29. :dport => ["7061","7062"],
  30. :ensure => :present,
  31. :line => '-A INPUT -s 1.1.1.1/32 -d 1.1.1.1/32 -p tcp -m multiport --dports 7061,7062 -m multiport --sports 7061,7062 -m comment --comment "000 allow foo" -j ACCEPT',
  32. :name => "000 allow foo",
  33. :proto => "tcp",
  34. :provider => "iptables",
  35. :source => "1.1.1.1/32",
  36. :sport => ["7061","7062"],
  37. :table => "filter",
  38. },
  39. },
  40. 'action_drop_1' => {
  41. :line => '-A INPUT -m comment --comment "000 allow foo" -j DROP',
  42. :table => 'filter',
  43. :params => {
  44. :jump => nil,
  45. :action => "drop",
  46. },
  47. },
  48. 'action_reject_1' => {
  49. :line => '-A INPUT -m comment --comment "000 allow foo" -j REJECT',
  50. :table => 'filter',
  51. :params => {
  52. :jump => nil,
  53. :action => "reject",
  54. },
  55. },
  56. 'action_nil_1' => {
  57. :line => '-A INPUT -m comment --comment "000 allow foo"',
  58. :table => 'filter',
  59. :params => {
  60. :jump => nil,
  61. :action => nil,
  62. },
  63. },
  64. 'jump_custom_chain_1' => {
  65. :line => '-A INPUT -m comment --comment "000 allow foo" -j custom_chain',
  66. :table => 'filter',
  67. :params => {
  68. :jump => "custom_chain",
  69. :action => nil,
  70. },
  71. },
  72. 'source_destination_ipv4_no_cidr' => {
  73. :line => '-A INPUT -s 1.1.1.1 -d 2.2.2.2 -m comment --comment "000 source destination ipv4 no cidr"',
  74. :table => 'filter',
  75. :params => {
  76. :source => '1.1.1.1/32',
  77. :destination => '2.2.2.2/32',
  78. },
  79. },
  80. 'source_destination_ipv6_no_cidr' => {
  81. :line => '-A INPUT -s 2001:db8:85a3::8a2e:370:7334 -d 2001:db8:85a3::8a2e:370:7334 -m comment --comment "000 source destination ipv6 no cidr"',
  82. :table => 'filter',
  83. :params => {
  84. :source => '2001:db8:85a3::8a2e:370:7334/128',
  85. :destination => '2001:db8:85a3::8a2e:370:7334/128',
  86. },
  87. },
  88. 'source_destination_ipv4_netmask' => {
  89. :line => '-A INPUT -s 1.1.1.0/255.255.255.0 -d 2.2.0.0/255.255.0.0 -m comment --comment "000 source destination ipv4 netmask"',
  90. :table => 'filter',
  91. :params => {
  92. :source => '1.1.1.0/24',
  93. :destination => '2.2.0.0/16',
  94. },
  95. },
  96. 'source_destination_ipv6_netmask' => {
  97. :line => '-A INPUT -s 2001:db8:1234::/ffff:ffff:ffff:0000:0000:0000:0000:0000 -d 2001:db8:4321::/ffff:ffff:ffff:0000:0000:0000:0000:0000 -m comment --comment "000 source destination ipv6 netmask"',
  98. :table => 'filter',
  99. :params => {
  100. :source => '2001:db8:1234::/48',
  101. :destination => '2001:db8:4321::/48',
  102. },
  103. },
  104. 'source_destination_negate_source' => {
  105. :line => '-A INPUT ! -s 1.1.1.1 -d 2.2.2.2 -m comment --comment "000 negated source address"',
  106. :table => 'filter',
  107. :params => {
  108. :source => '! 1.1.1.1/32',
  109. :destination => '2.2.2.2/32',
  110. },
  111. },
  112. 'source_destination_negate_destination' => {
  113. :line => '-A INPUT -s 1.1.1.1 ! -d 2.2.2.2 -m comment --comment "000 negated destination address"',
  114. :table => 'filter',
  115. :params => {
  116. :source => '1.1.1.1/32',
  117. :destination => '! 2.2.2.2/32',
  118. },
  119. },
  120. 'source_destination_negate_destination_alternative' => {
  121. :line => '-A INPUT -s 1.1.1.1 -d ! 2.2.2.2 -m comment --comment "000 negated destination address alternative"',
  122. :table => 'filter',
  123. :params => {
  124. :source => '1.1.1.1/32',
  125. :destination => '! 2.2.2.2/32',
  126. },
  127. },
  128. 'dport_range_1' => {
  129. :line => '-A INPUT -m multiport --dports 1:1024 -m comment --comment "000 allow foo"',
  130. :table => 'filter',
  131. :params => {
  132. :dport => ["1-1024"],
  133. },
  134. },
  135. 'dport_range_2' => {
  136. :line => '-A INPUT -m multiport --dports 15,512:1024 -m comment --comment "000 allow foo"',
  137. :table => 'filter',
  138. :params => {
  139. :dport => ["15","512-1024"],
  140. },
  141. },
  142. 'sport_range_1' => {
  143. :line => '-A INPUT -m multiport --sports 1:1024 -m comment --comment "000 allow foo"',
  144. :table => 'filter',
  145. :params => {
  146. :sport => ["1-1024"],
  147. },
  148. },
  149. 'sport_range_2' => {
  150. :line => '-A INPUT -m multiport --sports 15,512:1024 -m comment --comment "000 allow foo"',
  151. :table => 'filter',
  152. :params => {
  153. :sport => ["15","512-1024"],
  154. },
  155. },
  156. 'dst_type_1' => {
  157. :line => '-A INPUT -m addrtype --dst-type LOCAL',
  158. :table => 'filter',
  159. :params => {
  160. :dst_type => 'LOCAL',
  161. },
  162. },
  163. 'src_type_1' => {
  164. :line => '-A INPUT -m addrtype --src-type LOCAL',
  165. :table => 'filter',
  166. :params => {
  167. :src_type => 'LOCAL',
  168. },
  169. },
  170. 'dst_range_1' => {
  171. :line => '-A INPUT -m iprange --dst-range 10.0.0.2-10.0.0.20',
  172. :table => 'filter',
  173. :params => {
  174. :dst_range => '10.0.0.2-10.0.0.20',
  175. },
  176. },
  177. 'src_range_1' => {
  178. :line => '-A INPUT -m iprange --src-range 10.0.0.2-10.0.0.20',
  179. :table => 'filter',
  180. :params => {
  181. :src_range => '10.0.0.2-10.0.0.20',
  182. },
  183. },
  184. 'tcp_flags_1' => {
  185. :line => '-A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK,FIN SYN -m comment --comment "000 initiation"',
  186. :table => 'filter',
  187. :compare_all => true,
  188. :chain => 'INPUT',
  189. :proto => 'tcp',
  190. :params => {
  191. :chain => "INPUT",
  192. :ensure => :present,
  193. :line => '-A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK,FIN SYN -m comment --comment "000 initiation"',
  194. :name => "000 initiation",
  195. :proto => "tcp",
  196. :provider => "iptables",
  197. :table => "filter",
  198. :tcp_flags => "SYN,RST,ACK,FIN SYN",
  199. },
  200. },
  201. 'state_returns_sorted_values' => {
  202. :line => '-A INPUT -m state --state INVALID,RELATED,ESTABLISHED',
  203. :table => 'filter',
  204. :params => {
  205. :state => ['ESTABLISHED', 'INVALID', 'RELATED'],
  206. :action => nil,
  207. },
  208. },
  209. 'ctstate_returns_sorted_values' => {
  210. :line => '-A INPUT -m conntrack --ctstate INVALID,RELATED,ESTABLISHED',
  211. :table => 'filter',
  212. :params => {
  213. :ctstate => ['ESTABLISHED', 'INVALID', 'RELATED'],
  214. :action => nil,
  215. },
  216. },
  217. 'comment_string_character_validation' => {
  218. :line => '-A INPUT -s 192.168.0.1/32 -m comment --comment "000 allow from 192.168.0.1, please"',
  219. :table => 'filter',
  220. :params => {
  221. :source => '192.168.0.1/32',
  222. },
  223. },
  224. 'log_level_debug' => {
  225. :line => '-A INPUT -m comment --comment "956 INPUT log-level" -m state --state NEW -j LOG --log-level 7',
  226. :table => 'filter',
  227. :params => {
  228. :state => ['NEW'],
  229. :log_level => '7',
  230. :jump => 'LOG'
  231. },
  232. },
  233. 'log_level_warn' => {
  234. :line => '-A INPUT -m comment --comment "956 INPUT log-level" -m state --state NEW -j LOG',
  235. :table => 'filter',
  236. :params => {
  237. :state => ['NEW'],
  238. :log_level => '4',
  239. :jump => 'LOG'
  240. },
  241. },
  242. 'load_limit_module_and_implicit_burst' => {
  243. :line => '-A INPUT -m multiport --dports 123 -m comment --comment "057 INPUT limit NTP" -m limit --limit 15/hour',
  244. :table => 'filter',
  245. :params => {
  246. :dport => ['123'],
  247. :limit => '15/hour',
  248. :burst => '5'
  249. },
  250. },
  251. 'limit_with_explicit_burst' => {
  252. :line => '-A INPUT -m multiport --dports 123 -m comment --comment "057 INPUT limit NTP" -m limit --limit 30/hour --limit-burst 10',
  253. :table => 'filter',
  254. :params => {
  255. :dport => ['123'],
  256. :limit => '30/hour',
  257. :burst => '10'
  258. },
  259. },
  260. 'proto_ipencap' => {
  261. :line => '-A INPUT -p ipencap -m comment --comment "0100 INPUT accept ipencap"',
  262. :table => 'filter',
  263. :params => {
  264. :proto => 'ipencap',
  265. }
  266. },
  267. 'load_uid_owner_filter_module' => {
  268. :line => '-A OUTPUT -m owner --uid-owner root -m comment --comment "057 OUTPUT uid root only" -j ACCEPT',
  269. :table => 'filter',
  270. :params => {
  271. :action => 'accept',
  272. :uid => 'root',
  273. :chain => 'OUTPUT',
  274. },
  275. },
  276. 'load_uid_owner_postrouting_module' => {
  277. :line => '-t mangle -A POSTROUTING -m owner --uid-owner root -m comment --comment "057 POSTROUTING uid root only" -j ACCEPT',
  278. :table => 'mangle',
  279. :params => {
  280. :action => 'accept',
  281. :chain => 'POSTROUTING',
  282. :uid => 'root',
  283. },
  284. },
  285. 'load_gid_owner_filter_module' => {
  286. :line => '-A OUTPUT -m owner --gid-owner root -m comment --comment "057 OUTPUT gid root only" -j ACCEPT',
  287. :table => 'filter',
  288. :params => {
  289. :action => 'accept',
  290. :chain => 'OUTPUT',
  291. :gid => 'root',
  292. },
  293. },
  294. 'load_gid_owner_postrouting_module' => {
  295. :line => '-t mangle -A POSTROUTING -m owner --gid-owner root -m comment --comment "057 POSTROUTING gid root only" -j ACCEPT',
  296. :table => 'mangle',
  297. :params => {
  298. :action => 'accept',
  299. :chain => 'POSTROUTING',
  300. :gid => 'root',
  301. },
  302. },
  303. 'mark_set-mark' => {
  304. :line => '-t mangle -A PREROUTING -j MARK --set-xmark 0x3e8/0xffffffff',
  305. :table => 'mangle',
  306. :params => {
  307. :jump => 'MARK',
  308. :chain => 'PREROUTING',
  309. :set_mark => '0x3e8/0xffffffff',
  310. }
  311. },
  312. 'iniface_1' => {
  313. :line => '-A INPUT -i eth0 -m comment --comment "060 iniface" -j DROP',
  314. :table => 'filter',
  315. :params => {
  316. :action => 'drop',
  317. :chain => 'INPUT',
  318. :iniface => 'eth0',
  319. },
  320. },
  321. 'iniface_with_vlans_1' => {
  322. :line => '-A INPUT -i eth0.234 -m comment --comment "060 iniface" -j DROP',
  323. :table => 'filter',
  324. :params => {
  325. :action => 'drop',
  326. :chain => 'INPUT',
  327. :iniface => 'eth0.234',
  328. },
  329. },
  330. 'iniface_with_plus_1' => {
  331. :line => '-A INPUT -i eth+ -m comment --comment "060 iniface" -j DROP',
  332. :table => 'filter',
  333. :params => {
  334. :action => 'drop',
  335. :chain => 'INPUT',
  336. :iniface => 'eth+',
  337. },
  338. },
  339. 'outiface_1' => {
  340. :line => '-A OUTPUT -o eth0 -m comment --comment "060 outiface" -j DROP',
  341. :table => 'filter',
  342. :params => {
  343. :action => 'drop',
  344. :chain => 'OUTPUT',
  345. :outiface => 'eth0',
  346. },
  347. },
  348. 'outiface_with_vlans_1' => {
  349. :line => '-A OUTPUT -o eth0.234 -m comment --comment "060 outiface" -j DROP',
  350. :table => 'filter',
  351. :params => {
  352. :action => 'drop',
  353. :chain => 'OUTPUT',
  354. :outiface => 'eth0.234',
  355. },
  356. },
  357. 'outiface_with_plus_1' => {
  358. :line => '-A OUTPUT -o eth+ -m comment --comment "060 outiface" -j DROP',
  359. :table => 'filter',
  360. :params => {
  361. :action => 'drop',
  362. :chain => 'OUTPUT',
  363. :outiface => 'eth+',
  364. },
  365. },
  366. 'pkttype multicast' => {
  367. :line => '-A INPUT -m pkttype --pkt-type multicast -j ACCEPT',
  368. :table => 'filter',
  369. :params => {
  370. :action => 'accept',
  371. :pkttype => 'multicast',
  372. },
  373. },
  374. 'socket_option' => {
  375. :line => '-A PREROUTING -m socket -j ACCEPT',
  376. :table => 'mangle',
  377. :params => {
  378. :action => 'accept',
  379. :chain => 'PREROUTING',
  380. :socket => true,
  381. },
  382. },
  383. 'isfragment_option' => {
  384. :line => '-A INPUT -f -m comment --comment "010 a-f comment with dashf" -j ACCEPT',
  385. :table => 'filter',
  386. :params => {
  387. :name => '010 a-f comment with dashf',
  388. :action => 'accept',
  389. :isfragment => true,
  390. },
  391. },
  392. 'single_tcp_sport' => {
  393. :line => '-A OUTPUT -s 10.94.100.46/32 -p tcp -m tcp --sport 20443 -j ACCEPT',
  394. :table => 'mangle',
  395. :params => {
  396. :action => 'accept',
  397. :chain => 'OUTPUT',
  398. :source => "10.94.100.46/32",
  399. :proto => "tcp",
  400. :sport => ["20443"],
  401. },
  402. },
  403. 'single_udp_sport' => {
  404. :line => '-A OUTPUT -s 10.94.100.46/32 -p udp -m udp --sport 20443 -j ACCEPT',
  405. :table => 'mangle',
  406. :params => {
  407. :action => 'accept',
  408. :chain => 'OUTPUT',
  409. :source => "10.94.100.46/32",
  410. :proto => "udp",
  411. :sport => ["20443"],
  412. },
  413. },
  414. 'single_tcp_dport' => {
  415. :line => '-A OUTPUT -s 10.94.100.46/32 -p tcp -m tcp --dport 20443 -j ACCEPT',
  416. :table => 'mangle',
  417. :params => {
  418. :action => 'accept',
  419. :chain => 'OUTPUT',
  420. :source => "10.94.100.46/32",
  421. :proto => "tcp",
  422. :dport => ["20443"],
  423. },
  424. },
  425. 'single_udp_dport' => {
  426. :line => '-A OUTPUT -s 10.94.100.46/32 -p udp -m udp --dport 20443 -j ACCEPT',
  427. :table => 'mangle',
  428. :params => {
  429. :action => 'accept',
  430. :chain => 'OUTPUT',
  431. :source => "10.94.100.46/32",
  432. :proto => "udp",
  433. :dport => ["20443"],
  434. },
  435. },
  436. 'connlimit_above' => {
  437. :line => '-A INPUT -p tcp -m multiport --dports 22 -m comment --comment "061 REJECT connlimit_above 10" -m connlimit --connlimit-above 10 --connlimit-mask 32 -j REJECT --reject-with icmp-port-unreachable',
  438. :table => 'filter',
  439. :params => {
  440. :proto => 'tcp',
  441. :dport => ["22"],
  442. :connlimit_above => '10',
  443. :action => 'reject',
  444. },
  445. },
  446. 'connlimit_above_with_connlimit_mask' => {
  447. :line => '-A INPUT -p tcp -m multiport --dports 22 -m comment --comment "061 REJECT connlimit_above 10 with mask 24" -m connlimit --connlimit-above 10 --connlimit-mask 24 -j REJECT --reject-with icmp-port-unreachable',
  448. :table => 'filter',
  449. :params => {
  450. :proto => 'tcp',
  451. :dport => ["22"],
  452. :connlimit_above => '10',
  453. :connlimit_mask => '24',
  454. :action => 'reject',
  455. },
  456. },
  457. 'connmark' => {
  458. :line => '-A INPUT -m comment --comment "062 REJECT connmark" -m connmark --mark 0x1 -j REJECT --reject-with icmp-port-unreachable',
  459. :table => 'filter',
  460. :params => {
  461. :proto => 'all',
  462. :connmark => '0x1',
  463. :action => 'reject',
  464. },
  465. },
  466. }
  467. # This hash is for testing converting a hash to an argument line.
  468. HASH_TO_ARGS = {
  469. 'long_rule_1' => {
  470. :params => {
  471. :action => "accept",
  472. :chain => "INPUT",
  473. :destination => "1.1.1.1",
  474. :dport => ["7061","7062"],
  475. :ensure => :present,
  476. :name => "000 allow foo",
  477. :proto => "tcp",
  478. :source => "1.1.1.1",
  479. :sport => ["7061","7062"],
  480. :table => "filter",
  481. },
  482. :args => ["-t", :filter, "-s", "1.1.1.1/32", "-d", "1.1.1.1/32", "-p", :tcp, "-m", "multiport", "--sports", "7061,7062", "-m", "multiport", "--dports", "7061,7062", "-m", "comment", "--comment", "000 allow foo", "-j", "ACCEPT"],
  483. },
  484. 'long_rule_2' => {
  485. :params => {
  486. :chain => "INPUT",
  487. :destination => "2.10.13.3/24",
  488. :dport => ["7061"],
  489. :ensure => :present,
  490. :jump => "my_custom_chain",
  491. :name => "700 allow bar",
  492. :proto => "udp",
  493. :source => "1.1.1.1",
  494. :sport => ["7061","7062"],
  495. :table => "filter",
  496. },
  497. :args => ["-t", :filter, "-s", "1.1.1.1/32", "-d", "2.10.13.0/24", "-p", :udp, "-m", "multiport", "--sports", "7061,7062", "-m", "multiport", "--dports", "7061", "-m", "comment", "--comment", "700 allow bar", "-j", "my_custom_chain"],
  498. },
  499. 'no_action' => {
  500. :params => {
  501. :name => "100 no action",
  502. :table => "filter",
  503. },
  504. :args => ["-t", :filter, "-p", :tcp, "-m", "comment", "--comment",
  505. "100 no action"],
  506. },
  507. 'zero_prefixlen_ipv4' => {
  508. :params => {
  509. :name => '100 zero prefix length ipv4',
  510. :table => 'filter',
  511. :source => '0.0.0.0/0',
  512. :destination => '0.0.0.0/0',
  513. },
  514. :args => ['-t', :filter, '-p', :tcp, '-m', 'comment', '--comment', '100 zero prefix length ipv4'],
  515. },
  516. 'zero_prefixlen_ipv6' => {
  517. :params => {
  518. :name => '100 zero prefix length ipv6',
  519. :table => 'filter',
  520. :source => '::/0',
  521. :destination => '::/0',
  522. },
  523. :args => ['-t', :filter, '-p', :tcp, '-m', 'comment', '--comment', '100 zero prefix length ipv6'],
  524. },
  525. 'source_destination_ipv4_no_cidr' => {
  526. :params => {
  527. :name => '000 source destination ipv4 no cidr',
  528. :table => 'filter',
  529. :source => '1.1.1.1',
  530. :destination => '2.2.2.2',
  531. },
  532. :args => ['-t', :filter, '-s', '1.1.1.1/32', '-d', '2.2.2.2/32', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv4 no cidr'],
  533. },
  534. 'source_destination_ipv6_no_cidr' => {
  535. :params => {
  536. :name => '000 source destination ipv6 no cidr',
  537. :table => 'filter',
  538. :source => '2001:db8:1234::',
  539. :destination => '2001:db8:4321::',
  540. },
  541. :args => ['-t', :filter, '-s', '2001:db8:1234::/128', '-d', '2001:db8:4321::/128', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv6 no cidr'],
  542. },
  543. 'source_destination_ipv4_netmask' => {
  544. :params => {
  545. :name => '000 source destination ipv4 netmask',
  546. :table => 'filter',
  547. :source => '1.1.1.0/255.255.255.0',
  548. :destination => '2.2.0.0/255.255.0.0',
  549. },
  550. :args => ['-t', :filter, '-s', '1.1.1.0/24', '-d', '2.2.0.0/16', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv4 netmask'],
  551. },
  552. 'source_destination_ipv6_netmask' => {
  553. :params => {
  554. :name => '000 source destination ipv6 netmask',
  555. :table => 'filter',
  556. :source => '2001:db8:1234::/ffff:ffff:ffff:0000:0000:0000:0000:0000',
  557. :destination => '2001:db8:4321::/ffff:ffff:ffff:0000:0000:0000:0000:0000',
  558. },
  559. :args => ['-t', :filter, '-s', '2001:db8:1234::/48', '-d', '2001:db8:4321::/48', '-p', :tcp, '-m', 'comment', '--comment', '000 source destination ipv6 netmask'],
  560. },
  561. 'sport_range_1' => {
  562. :params => {
  563. :name => "100 sport range",
  564. :sport => ["1-1024"],
  565. :table => "filter",
  566. },
  567. :args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--sports", "1:1024", "-m", "comment", "--comment", "100 sport range"],
  568. },
  569. 'sport_range_2' => {
  570. :params => {
  571. :name => "100 sport range",
  572. :sport => ["15","512-1024"],
  573. :table => "filter",
  574. },
  575. :args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--sports", "15,512:1024", "-m", "comment", "--comment", "100 sport range"],
  576. },
  577. 'dport_range_1' => {
  578. :params => {
  579. :name => "100 sport range",
  580. :dport => ["1-1024"],
  581. :table => "filter",
  582. },
  583. :args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--dports", "1:1024", "-m", "comment", "--comment", "100 sport range"],
  584. },
  585. 'dport_range_2' => {
  586. :params => {
  587. :name => "100 sport range",
  588. :dport => ["15","512-1024"],
  589. :table => "filter",
  590. },
  591. :args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--dports", "15,512:1024", "-m", "comment", "--comment", "100 sport range"],
  592. },
  593. 'dst_type_1' => {
  594. :params => {
  595. :name => '000 dst_type',
  596. :table => 'filter',
  597. :dst_type => 'LOCAL',
  598. },
  599. :args => ['-t', :filter, '-p', :tcp, '-m', 'addrtype', '--dst-type', :LOCAL, '-m', 'comment', '--comment', '000 dst_type'],
  600. },
  601. 'src_type_1' => {
  602. :params => {
  603. :name => '000 src_type',
  604. :table => 'filter',
  605. :src_type => 'LOCAL',
  606. },
  607. :args => ['-t', :filter, '-p', :tcp, '-m', 'addrtype', '--src-type', :LOCAL, '-m', 'comment', '--comment', '000 src_type'],
  608. },
  609. 'dst_range_1' => {
  610. :params => {
  611. :name => '000 dst_range',
  612. :table => 'filter',
  613. :dst_range => '10.0.0.1-10.0.0.10',
  614. },
  615. :args => ['-t', :filter, '-p', :tcp, '-m', 'iprange', '--dst-range', '10.0.0.1-10.0.0.10', '-m', 'comment', '--comment', '000 dst_range'],
  616. },
  617. 'src_range_1' => {
  618. :params => {
  619. :name => '000 src_range',
  620. :table => 'filter',
  621. :dst_range => '10.0.0.1-10.0.0.10',
  622. },
  623. :args => ['-t', :filter, '-p', :tcp, '-m', 'iprange', '--dst-range', '10.0.0.1-10.0.0.10', '-m', 'comment', '--comment', '000 src_range'],
  624. },
  625. 'tcp_flags_1' => {
  626. :params => {
  627. :name => "000 initiation",
  628. :tcp_flags => "SYN,RST,ACK,FIN SYN",
  629. :table => "filter",
  630. },
  631. :args => ["-t", :filter, "-p", :tcp, "-m", "tcp", "--tcp-flags", "SYN,RST,ACK,FIN", "SYN", "-m", "comment", "--comment", "000 initiation",]
  632. },
  633. 'states_set_from_array' => {
  634. :params => {
  635. :name => "100 states_set_from_array",
  636. :table => "filter",
  637. :state => ['ESTABLISHED', 'INVALID']
  638. },
  639. :args => ["-t", :filter, "-p", :tcp, "-m", "comment", "--comment", "100 states_set_from_array",
  640. "-m", "state", "--state", "ESTABLISHED,INVALID"],
  641. },
  642. 'ctstates_set_from_array' => {
  643. :params => {
  644. :name => "100 ctstates_set_from_array",
  645. :table => "filter",
  646. :ctstate => ['ESTABLISHED', 'INVALID']
  647. },
  648. :args => ["-t", :filter, "-p", :tcp, "-m", "comment", "--comment", "100 ctstates_set_from_array",
  649. "-m", "conntrack", "--ctstate", "ESTABLISHED,INVALID"],
  650. },
  651. 'comment_string_character_validation' => {
  652. :params => {
  653. :name => "000 allow from 192.168.0.1, please",
  654. :table => 'filter',
  655. :source => '192.168.0.1'
  656. },
  657. :args => ['-t', :filter, '-s', '192.168.0.1/32', '-p', :tcp, '-m', 'comment', '--comment', '000 allow from 192.168.0.1, please'],
  658. },
  659. 'port_property' => {
  660. :params => {
  661. :name => '001 port property',
  662. :table => 'filter',
  663. :port => '80',
  664. },
  665. :args => ['-t', :filter, '-p', :tcp, '-m', 'multiport', '--ports', '80', '-m', 'comment', '--comment', '001 port property'],
  666. },
  667. 'log_level_debug' => {
  668. :params => {
  669. :name => '956 INPUT log-level',
  670. :table => 'filter',
  671. :state => 'NEW',
  672. :jump => 'LOG',
  673. :log_level => 'debug'
  674. },
  675. :args => ['-t', :filter, '-p', :tcp, '-m', 'comment', '--comment', '956 INPUT log-level', '-m', 'state', '--state', 'NEW', '-j', 'LOG', '--log-level', '7'],
  676. },
  677. 'log_level_warn' => {
  678. :params => {
  679. :name => '956 INPUT log-level',
  680. :table => 'filter',
  681. :state => 'NEW',
  682. :jump => 'LOG',
  683. :log_level => 'warn'
  684. },
  685. :args => ['-t', :filter, '-p', :tcp, '-m', 'comment', '--comment', '956 INPUT log-level', '-m', 'state', '--state', 'NEW', '-j', 'LOG', '--log-level', '4'],
  686. },
  687. 'load_limit_module_and_implicit_burst' => {
  688. :params => {
  689. :name => '057 INPUT limit NTP',
  690. :table => 'filter',
  691. :dport => '123',
  692. :limit => '15/hour'
  693. },
  694. :args => ['-t', :filter, '-p', :tcp, '-m', 'multiport', '--dports', '123', '-m', 'comment', '--comment', '057 INPUT limit NTP', '-m', 'limit', '--limit', '15/hour'],
  695. },
  696. 'limit_with_explicit_burst' => {
  697. :params => {
  698. :name => '057 INPUT limit NTP',
  699. :table => 'filter',
  700. :dport => '123',
  701. :limit => '30/hour',
  702. :burst => '10'
  703. },
  704. :args => ['-t', :filter, '-p', :tcp, '-m', 'multiport', '--dports', '123', '-m', 'comment', '--comment', '057 INPUT limit NTP', '-m', 'limit', '--limit', '30/hour', '--limit-burst', '10'],
  705. },
  706. 'proto_ipencap' => {
  707. :params => {
  708. :name => '0100 INPUT accept ipencap',
  709. :table => 'filter',
  710. :proto => 'ipencap',
  711. },
  712. :args => ['-t', :filter, '-p', :ipencap, '-m', 'comment', '--comment', '0100 INPUT accept ipencap'],
  713. },
  714. 'load_uid_owner_filter_module' => {
  715. :params => {
  716. :name => '057 OUTPUT uid root only',
  717. :table => 'filter',
  718. :uid => 'root',
  719. :action => 'accept',
  720. :chain => 'OUTPUT',
  721. :proto => 'all',
  722. },
  723. :args => ['-t', :filter, '-p', :all, '-m', 'owner', '--uid-owner', 'root', '-m', 'comment', '--comment', '057 OUTPUT uid root only', '-j', 'ACCEPT'],
  724. },
  725. 'load_uid_owner_postrouting_module' => {
  726. :params => {
  727. :name => '057 POSTROUTING uid root only',
  728. :table => 'mangle',
  729. :uid => 'root',
  730. :action => 'accept',
  731. :chain => 'POSTROUTING',
  732. :proto => 'all',
  733. },
  734. :args => ['-t', :mangle, '-p', :all, '-m', 'owner', '--uid-owner', 'root', '-m', 'comment', '--comment', '057 POSTROUTING uid root only', '-j', 'ACCEPT'],
  735. },
  736. 'load_gid_owner_filter_module' => {
  737. :params => {
  738. :name => '057 OUTPUT gid root only',
  739. :table => 'filter',
  740. :chain => 'OUTPUT',
  741. :gid => 'root',
  742. :action => 'accept',
  743. :proto => 'all',
  744. },
  745. :args => ['-t', :filter, '-p', :all, '-m', 'owner', '--gid-owner', 'root', '-m', 'comment', '--comment', '057 OUTPUT gid root only', '-j', 'ACCEPT'],
  746. },
  747. 'load_gid_owner_postrouting_module' => {
  748. :params => {
  749. :name => '057 POSTROUTING gid root only',
  750. :table => 'mangle',
  751. :gid => 'root',
  752. :action => 'accept',
  753. :chain => 'POSTROUTING',
  754. :proto => 'all',
  755. },
  756. :args => ['-t', :mangle, '-p', :all, '-m', 'owner', '--gid-owner', 'root', '-m', 'comment', '--comment', '057 POSTROUTING gid root only', '-j', 'ACCEPT'],
  757. },
  758. 'mark_set-mark_int' => {
  759. :params => {
  760. :name => '058 set-mark 1000',
  761. :table => 'mangle',
  762. :jump => 'MARK',
  763. :chain => 'PREROUTING',
  764. :set_mark => '1000',
  765. },
  766. :args => ['-t', :mangle, '-p', :tcp, '-m', 'comment', '--comment', '058 set-mark 1000', '-j', 'MARK', '--set-xmark', '0x3e8/0xffffffff'],
  767. },
  768. 'mark_set-mark_hex' => {
  769. :params => {
  770. :name => '058 set-mark 0x32',
  771. :table => 'mangle',
  772. :jump => 'MARK',
  773. :chain => 'PREROUTING',
  774. :set_mark => '0x32',
  775. },
  776. :args => ['-t', :mangle, '-p', :tcp, '-m', 'comment', '--comment', '058 set-mark 0x32', '-j', 'MARK', '--set-xmark', '0x32/0xffffffff'],
  777. },
  778. 'mark_set-mark_hex_with_hex_mask' => {
  779. :params => {
  780. :name => '058 set-mark 0x32/0xffffffff',
  781. :table => 'mangle',
  782. :jump => 'MARK',
  783. :chain => 'PREROUTING',
  784. :set_mark => '0x32/0xffffffff',
  785. },
  786. :args => ['-t', :mangle, '-p', :tcp, '-m', 'comment', '--comment', '058 set-mark 0x32/0xffffffff', '-j', 'MARK', '--set-xmark', '0x32/0xffffffff'],
  787. },
  788. 'mark_set-mark_hex_with_mask' => {
  789. :params => {
  790. :name => '058 set-mark 0x32/4',
  791. :table => 'mangle',
  792. :jump => 'MARK',
  793. :chain => 'PREROUTING',
  794. :set_mark => '0x32/4',
  795. },
  796. :args => ['-t', :mangle, '-p', :tcp, '-m', 'comment', '--comment', '058 set-mark 0x32/4', '-j', 'MARK', '--set-xmark', '0x32/0x4'],
  797. },
  798. 'iniface_1' => {
  799. :params => {
  800. :name => '060 iniface',
  801. :table => 'filter',
  802. :action => 'drop',
  803. :chain => 'INPUT',
  804. :iniface => 'eth0',
  805. },
  806. :args => ["-t", :filter, "-i", "eth0", "-p", :tcp, "-m", "comment", "--comment", "060 iniface", "-j", "DROP"],
  807. },
  808. 'iniface_with_vlans_1' => {
  809. :params => {
  810. :name => '060 iniface',
  811. :table => 'filter',
  812. :action => 'drop',
  813. :chain => 'INPUT',
  814. :iniface => 'eth0.234',
  815. },
  816. :args => ["-t", :filter, "-i", "eth0.234", "-p", :tcp, "-m", "comment", "--comment", "060 iniface", "-j", "DROP"],
  817. },
  818. 'iniface_with_plus_1' => {
  819. :params => {
  820. :name => '060 iniface',
  821. :table => 'filter',
  822. :action => 'drop',
  823. :chain => 'INPUT',
  824. :iniface => 'eth+',
  825. },
  826. :args => ["-t", :filter, "-i", "eth+", "-p", :tcp, "-m", "comment", "--comment", "060 iniface", "-j", "DROP"],
  827. },
  828. 'outiface_1' => {
  829. :params => {
  830. :name => '060 outiface',
  831. :table => 'filter',
  832. :action => 'drop',
  833. :chain => 'OUTPUT',
  834. :outiface => 'eth0',
  835. },
  836. :args => ["-t", :filter, "-o", "eth0", "-p", :tcp, "-m", "comment", "--comment", "060 outiface", "-j", "DROP"],
  837. },
  838. 'outiface_with_vlans_1' => {
  839. :params => {
  840. :name => '060 outiface',
  841. :table => 'filter',
  842. :action => 'drop',
  843. :chain => 'OUTPUT',
  844. :outiface => 'eth0.234',
  845. },
  846. :args => ["-t", :filter, "-o", "eth0.234", "-p", :tcp, "-m", "comment", "--comment", "060 outiface", "-j", "DROP"],
  847. },
  848. 'outiface_with_plus_1' => {
  849. :params => {
  850. :name => '060 outiface',
  851. :table => 'filter',
  852. :action => 'drop',
  853. :chain => 'OUTPUT',
  854. :outiface => 'eth+',
  855. },
  856. :args => ["-t", :filter, "-o", "eth+", "-p", :tcp, "-m", "comment", "--comment", "060 outiface", "-j", "DROP"],
  857. },
  858. 'pkttype multicast' => {
  859. :params => {
  860. :name => '062 pkttype multicast',
  861. :table => "filter",
  862. :action => 'accept',
  863. :chain => 'INPUT',
  864. :iniface => 'eth0',
  865. :pkttype => 'multicast',
  866. },
  867. :args => ["-t", :filter, "-i", "eth0", "-p", :tcp, "-m", "pkttype", "--pkt-type", :multicast, "-m", "comment", "--comment", "062 pkttype multicast", "-j", "ACCEPT"],
  868. },
  869. 'socket_option' => {
  870. :params => {
  871. :name => '050 socket option',
  872. :table => 'mangle',
  873. :action => 'accept',
  874. :chain => 'PREROUTING',
  875. :socket => true,
  876. },
  877. :args => ['-t', :mangle, '-p', :tcp, '-m', 'socket', '-m', 'comment', '--comment', '050 socket option', '-j', 'ACCEPT'],
  878. },
  879. 'isfragment_option' => {
  880. :params => {
  881. :name => '050 isfragment option',
  882. :table => 'filter',
  883. :proto => :all,
  884. :action => 'accept',
  885. :isfragment => true,
  886. },
  887. :args => ['-t', :filter, '-p', :all, '-f', '-m', 'comment', '--comment', '050 isfragment option', '-j', 'ACCEPT'],
  888. },
  889. 'isfragment_option not changing -f in comment' => {
  890. :params => {
  891. :name => '050 testcomment-with-fdashf',
  892. :table => 'filter',
  893. :proto => :all,
  894. :action => 'accept',
  895. },
  896. :args => ['-t', :filter, '-p', :all, '-m', 'comment', '--comment', '050 testcomment-with-fdashf', '-j', 'ACCEPT'],
  897. },
  898. 'connlimit_above' => {
  899. :params => {
  900. :name => '061 REJECT connlimit_above 10',
  901. :table => 'filter',
  902. :proto => 'tcp',
  903. :dport => ["22"],
  904. :connlimit_above => '10',
  905. :action => 'reject',
  906. },
  907. :args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--dports", "22", "-m", "comment", "--comment", "061 REJECT connlimit_above 10", "-j", "REJECT", "-m", "connlimit", "--connlimit-above", "10"],
  908. },
  909. 'connlimit_above_with_connlimit_mask' => {
  910. :params => {
  911. :name => '061 REJECT connlimit_above 10 with mask 24',
  912. :table => 'filter',
  913. :proto => 'tcp',
  914. :dport => ["22"],
  915. :connlimit_above => '10',
  916. :connlimit_mask => '24',
  917. :action => 'reject',
  918. },
  919. :args => ["-t", :filter, "-p", :tcp, "-m", "multiport", "--dports", "22", "-m", "comment", "--comment", "061 REJECT connlimit_above 10 with mask 24", "-j", "REJECT", "-m", "connlimit", "--connlimit-above", "10", "--connlimit-mask", "24"],
  920. },
  921. 'connmark' => {
  922. :params => {
  923. :name => '062 REJECT connmark',
  924. :table => 'filter',
  925. :proto => 'all',
  926. :connmark => '0x1',
  927. :action => 'reject',
  928. },
  929. :args => ["-t", :filter, "-p", :all, "-m", "comment", "--comment", "062 REJECT connmark", "-j", "REJECT", "-m", "connmark", "--mark", "0x1"],
  930. },
  931. }