the game . . . iptables comes in groups: filter, nat, mangle and raw every group has chains: INPUT, OUTPUT, FORWARD, userdefined stuff two python objects: Chain and Tables simple constructions: Chain has 2 methods, Tables 4 methods main: chains=Tables(sourcefile=“rules“) main: chains.table_printout() thats all https://github.com/sl0/conv 222 lines of code, +260 lines and 20 tests Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 6 / 20
than 8k lines of iptables commands having more than one machine in the chain to the internet ⇒ latency thats poor . . . have a close look into the chains: mostly unused . . . have a close look into the chains: mostly unused, but all needed! Think! Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 11 / 20
rules in every chain is important blocks of accept, drops or others, each having one policy in common see a chain as a set, and make partitions from policies inside every partition, rules may be exchanged freely goal is to have as few blocks as possible ⇒ administrators artwork sorting each partition on behalf of the paket-counters how to do it? python is our friend, iptables-optimizer.py is the result https://github.com/sl0/opti 221 lines of code, +270 lines in 17 tests Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 12 / 20
from simple via complex to genious startup with subprocess: iptables-save -c, iptables -I, iptables -D. . . partitioning: easy doing with loop over chain subprocess: difficulties with errorchecking, python-versions: complex subprocess: slow convergence to sorted partitions endless loop, interruptable by ctrl-c or SIGTERM ⇒ to much risk! redesign, refactoring, no longer use of subprocess now: read from file, build and sort the partitions, save all as a file addon: testable without any relation to the kernel this is much quicker, only one iptables-save and iptables-restore / cycle Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 13 / 20
lines of code ⇒ Software is broken by design, unittest helps! 2 Software shall run with different python-versionsa ⇒ use tox! aDebian etch, lenny, sarge, wheezy Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 14 / 20
for usage ip6tables are as simple as iptables adm6: generates ip6tables for many machines from a single ruleset adm6: ready for production use. adm6: no setup.py, tox.ini, . . . , still some work to be done adm6: future: database config, f.e. in zeo or postgres adm6: future: OpenBSD pf.conf generated from same ruleset adm6: future: windows™advfirewall scripts as well adm6: past: was presented in OpenChaos, Feb 24th, 2011 Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 16 / 20
2.7.3 (default, Jan 2 2013, 16:53:07) 2 [GCC 4.7.2] on linux2 3 Type "help", "copyright", "credits" or "license" for more information. 4 >>> import this 5 The Zen of Python, by Tim Peters 6 7 Beautiful is better than ugly. 8 Explicit is better than implicit. 9 Simple is better than complex. 10 Complex is better than complicated. 11 Flat is better than nested. 12 Sparse is better than dense. 13 Readability counts. 14 ... python modules: ipaddr, scapy, pythonwifi, socket, urllib, . . . on the net: https://github.com/gregmalcolm/python_koans/wiki https://github.com/openstack https://github.com/mininet https://github.com/horms/openvswitch https://www.google.com/search?q=python+network http://datenterrorist.de (balle) . . . books: (d) Bastian Ballmann, Network Hacks, Springer Vieweg, 2012 (e) Brandon Rhodes & John Goerzen, Foundations of Python Network Programming, Apress, 2010 (e) Noah Gift & Jeremy M.Jones, Python for Unix and Linux System Administration, O’Reilly, 2008 (e) Greg L. Turnquist, Python Testing Cookbook, PACKT publishing, 2011 Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 19 / 20
featured with python as well: reliable networks for trustworthy communications happy working Johannes Hubertz sl0.self_at_googlemail dot com powered by L ATEX2ε and PSTricks Johannes Hubertz (pycologne.de) python networkstuff . . . OpenChaos – Köln, 30. Mai 2013 20 / 20