chiark / gitweb /
wip
[hippotat.git] / hippotat / __init__.py
index 1baaed33c68703758d160ee2d32f9e1b0059b471..c57767ae1c2c3045def4875cdaa1efd7c7c61191 100644 (file)
@@ -3,6 +3,8 @@
 import signal
 signal.signal(signal.SIGINT, signal.SIG_DFL)
 
+import sys
+
 import twisted
 from twisted.internet import reactor
 from twisted.logger import LogLevel
@@ -11,14 +13,56 @@ import twisted.internet.endpoints
 import ipaddress
 from ipaddress import AddressValueError
 
-import hippotat.slip as slip
-
 from optparse import OptionParser
 from configparser import ConfigParser
 from configparser import NoOptionError
 
 import collections
 
+import re as regexp
+
+import hippotat.slip as slip
+
+defcfg = '''
+[DEFAULT]
+#[<client>] overrides
+max_batch_down = 65536           # used by server, subject to [limits]
+max_queue_time = 10              # used by server, subject to [limits]
+max_request_time = 54            # used by server, subject to [limits]
+target_requests_outstanding = 3  # must match; subject to [limits] on server
+max_requests_outstanding = 4     # used by client
+max_batch_up = 4000              # used by client
+
+#[server] or [<client>] overrides
+ipif = userv root ipif %(local)s,%(peer)s,%(mtu)s,slip %(rnets)s
+# extra interpolations:  %(local)s        %(peer)s          %(rnet)s
+#  obtained   on server  [virtual]server  [virtual]relay    [virtual]network
+#      from   on client  <client>         [virtual]server   [virtual]routes
+
+[virtual]
+mtu = 1500
+routes = ''
+# network = <prefix>/<len>  # mandatory for server
+# server  = <ipaddr>   # used by both, default is computed from `network'
+# relay   = <ipaddr>   # used by server, default from `network' and `server'
+#  default server is first host in network
+#  default relay is first host which is not server
+
+[server]
+# addrs = 127.0.0.1 ::1    # mandatory for server
+port = 80                  # used by server
+# url              # used by client; default from first `addrs' and `port'
+
+# [<client-ip4-or-ipv6-address>]
+# password = <password>    # used by both, must match
+
+[limits]
+max_batch_down = 262144           # used by server
+max_queue_time = 121              # used by server
+max_request_time = 121            # used by server
+target_requests_outstanding = 10  # used by server
+'''
+
 # these need to be defined here so that they can be imported by import *
 cfg = ConfigParser()
 optparser = OptionParser()
@@ -31,6 +75,11 @@ class ConfigResults:
 
 c = ConfigResults()
 
+def log_discard(packet, saddr, daddr, why):
+  print('DROP ', saddr, daddr, why)
+#  syslog.syslog(syslog.LOG_DEBUG,
+#                'discarded packet %s -> %s (%s)' % (saddr, daddr, why))
+
 #---------- packet parsing ----------
 
 def packet_addrs(packet):
@@ -80,6 +129,9 @@ class _IpifProcessProtocol(twisted.internet.protocol.ProcessProtocol):
     for packet in packets:
       if not len(packet): continue
       (saddr, daddr) = packet_addrs(packet)
+      if saddr.is_link_local or daddr.is_link_local:
+        log_discard(packet, saddr, daddr, 'link-local')
+        continue
       self._router(packet, saddr, daddr)
   def processEnded(self, status):
     status.raiseException()
@@ -206,7 +258,7 @@ def process_cfg_clients(constructor):
 
 #---------- startup ----------
 
-def common_startup(defcfg):
+def common_startup():
   twisted.logger.globalLogPublisher.addObserver(crash_on_critical)
 
   optparser.add_option('-c', '--config', dest='configfile',
@@ -214,7 +266,8 @@ def common_startup(defcfg):
   (opts, args) = optparser.parse_args()
   if len(args): optparser.error('no non-option arguments please')
 
-  cfg.read_string(defcfg)
+  re = regexp.compile('#.*')
+  cfg.read_string(re.sub('', defcfg))
   cfg.read(opts.configfile)
 
 def common_run():