From 1321ad5f1dc05a97d58c4750863e645016fe0aa8 Mon Sep 17 00:00:00 2001 Message-Id: <1321ad5f1dc05a97d58c4750863e645016fe0aa8.1730415964.git.mdw@distorted.org.uk> From: Mark Wooding Date: Wed, 22 Mar 2017 00:52:39 +0000 Subject: [PATCH] wip Organization: Straylight/Edgeware From: Ian Jackson --- client | 2 +- hippotat/__init__.py | 18 ++++++++++++++---- server | 10 ++-------- test.cfg | 1 + 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/client b/client index b60f3d1..49a10ef 100755 --- a/client +++ b/client @@ -57,7 +57,7 @@ def check_outbound(): while (outstanding < and (queue.notempty() or outstanding < c. -common_startup(defcfg) +common_startup() process_cfg() start_ipif(c.ipif_command, outbound) common_run() diff --git a/hippotat/__init__.py b/hippotat/__init__.py index f51caf5..c57767a 100644 --- a/hippotat/__init__.py +++ b/hippotat/__init__.py @@ -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,16 @@ 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] #[] overrides @@ -71,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): @@ -249,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', @@ -257,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(): diff --git a/server b/server index b746bc2..2daf0b0 100755 --- a/server +++ b/server @@ -2,7 +2,6 @@ from hippotat import * -import sys import os import twisted.internet @@ -31,11 +30,6 @@ def route(packet, saddr, daddr): else: log_discard(packet, saddr, daddr, 'no client') -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)) - #---------- client ---------- class Client(): @@ -138,7 +132,7 @@ class IphttpResource(twisted.web.resource.Resource): # find client, update config, etc. metadata = request.args['m'] (ci_s, pw, tro) = metadata.split(b'\n')[0:3] - ci = ipaddr(ci_s]) + ci = ipaddr(ci_s) cl = clients[ci] if pw != cl.pw: raise ValueError('bad password') @@ -184,7 +178,7 @@ def process_cfg(): ('peer', 'relay'), ('rnets','network'))) -common_startup(defcfg) +common_startup() process_cfg() start_ipif(c.ipif_command, route) start_http() diff --git a/test.cfg b/test.cfg index ba1b09a..902f6c1 100644 --- a/test.cfg +++ b/test.cfg @@ -3,6 +3,7 @@ ipif = PATH=/usr/local/sbin:/sbin:/usr/sbin:$PATH really /home/ian/things/Userv/ [server] addrs = 127.0.0.1 +port = 8099 [virtual] network = 192.0.2.0/24 -- [mdw]