mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-19 12:28:28 +01:00
Changes methods that do not reference the instance to static methods
This commit is contained in:
parent
ad676029c7
commit
112931dd2c
@ -35,7 +35,8 @@ class BaseMethod(object):
|
||||
def set_firewall(self, firewall):
|
||||
self.firewall = firewall
|
||||
|
||||
def get_supported_features(self):
|
||||
@staticmethod
|
||||
def get_supported_features():
|
||||
result = Features()
|
||||
result.ipv6 = False
|
||||
result.udp = False
|
||||
@ -43,10 +44,12 @@ class BaseMethod(object):
|
||||
result.user = False
|
||||
return result
|
||||
|
||||
def get_tcp_dstip(self, sock):
|
||||
@staticmethod
|
||||
def get_tcp_dstip(sock):
|
||||
return original_dst(sock)
|
||||
|
||||
def recv_udp(self, udp_listener, bufsize):
|
||||
@staticmethod
|
||||
def recv_udp(udp_listener, bufsize):
|
||||
debug3('Accept UDP using recvfrom.\n')
|
||||
data, srcip = udp_listener.recvfrom(bufsize)
|
||||
return (srcip, None, data)
|
||||
@ -77,7 +80,8 @@ class BaseMethod(object):
|
||||
def restore_firewall(self, port, family, udp, user):
|
||||
raise NotImplementedError()
|
||||
|
||||
def firewall_command(self, line):
|
||||
@staticmethod
|
||||
def firewall_command(line):
|
||||
return False
|
||||
|
||||
|
||||
|
@ -35,11 +35,11 @@ class Generic(object):
|
||||
|
||||
class pf_addr(Structure):
|
||||
class _pfa(Union):
|
||||
_fields_ = [("v4", c_uint32), # struct in_addr
|
||||
("v6", c_uint32 * 4), # struct in6_addr
|
||||
("addr8", c_uint8 * 16),
|
||||
("addr16", c_uint16 * 8),
|
||||
("addr32", c_uint32 * 4)]
|
||||
_fields_ = [("v4", c_uint32), # struct in_addr
|
||||
("v6", c_uint32 * 4), # struct in6_addr
|
||||
("addr8", c_uint8 * 16),
|
||||
("addr16", c_uint16 * 8),
|
||||
("addr32", c_uint32 * 4)]
|
||||
|
||||
_fields_ = [("pfa", _pfa)]
|
||||
_anonymous_ = ("pfa",)
|
||||
@ -66,7 +66,8 @@ class Generic(object):
|
||||
pfctl('-e')
|
||||
_pf_context['started_by_sshuttle'] += 1
|
||||
|
||||
def disable(self, anchor):
|
||||
@staticmethod
|
||||
def disable(anchor):
|
||||
pfctl('-a %s -F all' % anchor)
|
||||
if _pf_context['started_by_sshuttle'] == 1:
|
||||
pfctl('-d')
|
||||
@ -98,11 +99,13 @@ class Generic(object):
|
||||
port = socket.ntohs(self._get_natlook_port(pnl.rdxport))
|
||||
return (ip, port)
|
||||
|
||||
def _add_natlook_ports(self, pnl, src_port, dst_port):
|
||||
@staticmethod
|
||||
def _add_natlook_ports(pnl, src_port, dst_port):
|
||||
pnl.sxport = socket.htons(src_port)
|
||||
pnl.dxport = socket.htons(dst_port)
|
||||
|
||||
def _get_natlook_port(self, xport):
|
||||
@staticmethod
|
||||
def _get_natlook_port(xport):
|
||||
return xport
|
||||
|
||||
def add_anchors(self, anchor, status=None):
|
||||
@ -129,18 +132,22 @@ class Generic(object):
|
||||
'I', self.PF_CHANGE_ADD_TAIL), 4) # action = PF_CHANGE_ADD_TAIL
|
||||
ioctl(pf_get_dev(), pf.DIOCCHANGERULE, pr)
|
||||
|
||||
def _inet_version(self, family):
|
||||
@staticmethod
|
||||
def _inet_version(family):
|
||||
return b'inet' if family == socket.AF_INET else b'inet6'
|
||||
|
||||
def _lo_addr(self, family):
|
||||
@staticmethod
|
||||
def _lo_addr(family):
|
||||
return b'127.0.0.1' if family == socket.AF_INET else b'::1'
|
||||
|
||||
def add_rules(self, anchor, rules):
|
||||
@staticmethod
|
||||
def add_rules(anchor, rules):
|
||||
assert isinstance(rules, bytes)
|
||||
debug3("rules:\n" + rules.decode("ASCII"))
|
||||
pfctl('-a %s -f /dev/stdin' % anchor, rules)
|
||||
|
||||
def has_skip_loopback(self):
|
||||
@staticmethod
|
||||
def has_skip_loopback():
|
||||
return b'skip' in pfctl('-s Interfaces -i lo -v')[0]
|
||||
|
||||
|
||||
|
@ -175,7 +175,8 @@ class DnsProxy(Handler):
|
||||
self.to_nameserver = self._addrinfo(peer, port)
|
||||
self.try_send()
|
||||
|
||||
def _addrinfo(self, peer, port):
|
||||
@staticmethod
|
||||
def _addrinfo(peer, port):
|
||||
if int(port) == 0:
|
||||
port = 53
|
||||
family, _, _, _, sockaddr = socket.getaddrinfo(peer, port)[0]
|
||||
|
@ -200,7 +200,8 @@ class SockWrapper:
|
||||
_, e = sys.exc_info()[:2]
|
||||
self.seterr('nowrite: %s' % e)
|
||||
|
||||
def too_full(self):
|
||||
@staticmethod
|
||||
def too_full():
|
||||
return False # fullness is determined by the socket's select() state
|
||||
|
||||
def uwrite(self, buf):
|
||||
|
Loading…
Reference in New Issue
Block a user