/usr/share/pyshared/pyroman/interface.py is in pyroman 0.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #Copyright (c) 2011 Erich Schubert erich@debian.org
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
from pyroman import Firewall
from util import Util
from exception import PyromanException
class Interface:
"""
Interfaces (or -groups) are used to filter based on physical networks
"""
def __init__(self, name, iface, loginfo):
"""
Create a new interface
name -- name for this interface (-group)
iface -- kernel interface names, e.g. "eth0 eth1"
"""
if name == "" or not Util.verify_name(name):
raise PyromanException("Interface lacking a valid name (name: %s, iface: %s) at %s" \
% (name, iface, loginfo))
if Firewall.interfaces.has_key(name):
raise PyromanException("Duplicate interface specification: %s at %s" % (name, loginfo))
if iface == "":
raise PyromanException("Interface definition lacking kernel interfaces: %s at %s" \
% (name, loginfo))
self.name = name
self.iface = Util.splitter.split(iface)
self.loginfo = loginfo
# register with firewall
Firewall.interfaces[name] = self
def get_filter(self, dir):
"""
Generate filter rules for this interface by generating a list of
filter rules for all source specifications
dir -- either "d" or "s" for destination filter or source filter
"""
idir = None
if dir == "d":
idir = "o"
elif dir == "s":
idir = "i"
else:
raise PyromanException("Unknown direction specified: %s" % dir)
# when necessary, turn around filter directions
result = []
for i in self.iface:
if i == "": continue
if i == "*":
result.append( "" )
else:
result.append( "-%s %s" % (idir, i) )
return result
def prepare(self):
"""
Prepare interface definition for generation
Nothing to do here for now
"""
pass
def verify(self):
"""
Verify that the interface definition is complete, in addition to the
checks at creation time. (Currenlty, no additional checks are done.)
"""
# no additional checks yet
pass
|