Convert the rule back into syntactically correct iptables command
(self, delete=False)
| 383 | return self.rule |
| 384 | |
| 385 | def to_str(self, delete=False): |
| 386 | """ Convert the rule back into syntactically correct iptables command """ |
| 387 | # Order is important |
| 388 | order = ['-A', '-s', '-d', '!_-d', '-i', '!_-i', '-p', '-m', '-m2', '--icmp-type', '--state', |
| 389 | '--dport', '--destination-port', '-o', '!_-o', '-j', '--set-xmark', '--checksum', |
| 390 | '--to-source', '--to-destination', '--mark'] |
| 391 | str = '' |
| 392 | for k in order: |
| 393 | if k in list(self.rule.keys()): |
| 394 | printable = k.replace('-m2', '-m') |
| 395 | printable = printable.replace('!_-', '! -') |
| 396 | if delete: |
| 397 | printable = printable.replace('-A', '-D') |
| 398 | if str == '': |
| 399 | str = "%s %s" % (printable, self.rule[k]) |
| 400 | else: |
| 401 | str = "%s %s %s" % (str, printable, self.rule[k]) |
| 402 | str = str.replace("--checksum fill", "--checksum-fill") |
| 403 | return str |
| 404 | |
| 405 | def __eq__(self, rule): |
| 406 | if rule.get_table() != self.get_table(): |
no test coverage detected