mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-11-19 14:36:34 -05:00
Added tunnel info to rnstatus
This commit is contained in:
parent
daec67a116
commit
3281e28315
4 changed files with 29 additions and 13 deletions
|
|
@ -39,7 +39,6 @@ class Interface:
|
|||
OUT = False
|
||||
FWD = False
|
||||
RPT = False
|
||||
name = None
|
||||
|
||||
# Interface mode definitions
|
||||
MODE_FULL = 0x01
|
||||
|
|
@ -96,6 +95,7 @@ class Interface:
|
|||
DEFAULT_IFAC_SIZE = 16
|
||||
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.rxb = 0
|
||||
self.txb = 0
|
||||
self.frxb = 0
|
||||
|
|
@ -129,6 +129,7 @@ class Interface:
|
|||
self.parent_interface = None
|
||||
self.spawned_interfaces = None
|
||||
self.tunnel_id = None
|
||||
self.local_tunnel_id = None
|
||||
self.ingress_control = True
|
||||
self.phy_keepalive = False
|
||||
self.shared_medium = False
|
||||
|
|
|
|||
|
|
@ -899,16 +899,25 @@ class Reticulum:
|
|||
except Exception as e: RNS.log(f"Error while detaching interface \"{name}\": {e}", RNS.LOG_ERROR)
|
||||
return False
|
||||
|
||||
def _detach_interface(self, name, internal_forced=False):
|
||||
def _detach_interface(self, name, internal_forced=False, interface_instance=None):
|
||||
if not internal_forced and not Reticulum.__interface_management_enabled: return False
|
||||
try:
|
||||
interfaces = { iface.name: iface for iface in RNS.Transport.interfaces }
|
||||
if not name in interfaces:
|
||||
RNS.log(f"Attempt to detach non-existing interface \"{name}\"", RNS.LOG_WARNING)
|
||||
if interface_instance: interface = interface_instances
|
||||
else:
|
||||
interfaces = { iface.name: iface for iface in RNS.Transport.interfaces }
|
||||
interface = interfaces.get(name, None)
|
||||
if not interface:
|
||||
try: tunnel_id = bytes.fromhex(name)
|
||||
except: return None
|
||||
tunnel_ids = { iface.tunnel_id: iface for iface in RNS.Transport.interfaces if iface.tunnel_id }
|
||||
local_tunnel_ids = { iface.local_tunnel_id: iface for iface in RNS.Transport.interfaces if iface.local_tunnel_id }
|
||||
interface = tunnel_ids.get(tunnel_id, None) or local_tunnel_ids.get(tunnel_id, None)
|
||||
|
||||
if not interface:
|
||||
RNS.log(f"Attempt to detach non-existing interface \"{name or interface}\"", RNS.LOG_WARNING)
|
||||
return None
|
||||
|
||||
else:
|
||||
interface = interfaces[name]
|
||||
if isinstance(interface, I2PInterface.I2PInterface): return False
|
||||
if isinstance(interface, LocalInterface.LocalClientInterface): return False
|
||||
if isinstance(interface, LocalInterface.LocalServerInterface): return False
|
||||
|
|
@ -922,7 +931,7 @@ class Reticulum:
|
|||
|
||||
interface.detach()
|
||||
RNS.Transport.remove_interface(interface)
|
||||
RNS.log(f"Interface \"{name}\" was detached", RNS.LOG_NOTICE)
|
||||
RNS.log(f"Interface {interface} was detached", RNS.LOG_NOTICE)
|
||||
return True
|
||||
|
||||
except Exception as e: RNS.log(f"Error while detaching interface \"{name}\": {e}", RNS.LOG_ERROR); RNS.trace_exception(e)
|
||||
|
|
@ -1785,7 +1794,7 @@ class Reticulum:
|
|||
|
||||
ifstats["name"] = str(interface)
|
||||
ifstats["short_name"] = str(interface.name)
|
||||
ifstats["tunnel_id"] = interface.tunnel_id
|
||||
ifstats["tunnel_id"] = interface.tunnel_id or interface.local_tunnel_id
|
||||
ifstats["hash"] = interface.get_hash()
|
||||
ifstats["type"] = str(type(interface).__name__)
|
||||
ifstats["mtu"] = interface.HW_MTU
|
||||
|
|
|
|||
|
|
@ -3118,6 +3118,7 @@ class Transport:
|
|||
packet.send()
|
||||
|
||||
interface.wants_tunnel = False
|
||||
interface.local_tunnel_id = tunnel_id
|
||||
|
||||
except Exception as e: RNS.log(f"Could not synthesize tunnel for {interface}: {e}", RNS.LOG_ERROR)
|
||||
|
||||
|
|
@ -3141,6 +3142,10 @@ class Transport:
|
|||
if remote_transport_identity.validate(signature, signed_data):
|
||||
Transport.handle_tunnel(tunnel_id, packet.receiving_interface)
|
||||
|
||||
else:
|
||||
RNS.log(f"Invalid tunnel synthesis signature, tearing down interface {packet.receiving_interface}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
RNS.Reticulum.get_instance()._detach_interface(None, interface_instance=packet.receiving_interface, internal_forced=True)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("An error occurred while validating tunnel establishment packet.", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
|
|||
sorting=None, sort_reverse=False, remote=None, management_identity=None, must_exit=True, rns_instance=None,
|
||||
traffic_totals=False, discovered_interfaces=False, config_entries=False, burst_filter=False, blocked_ips=False,
|
||||
queue_stats=False, pps=False, profiling=False, remote_timeout=RNS.Transport.PATH_REQUEST_TIMEOUT,
|
||||
attach=None, detach=None, reload=None, show_stale=False, show_unknown=False, fstats=False):
|
||||
attach=None, detach=None, reload=None, show_stale=False, show_unknown=False, fstats=False, tstats=False):
|
||||
|
||||
if remote: require_shared = False
|
||||
else: require_shared = True
|
||||
|
|
@ -556,8 +556,8 @@ def program_setup(configdir, dispall=False, verbosity=0, name_filter=None, json=
|
|||
if "bitrate" in ifstat and ifstat["bitrate"] != None:
|
||||
print(f" Rate : {speed_str(ifstat['bitrate'])}, MTU {ifstat['mtu']}")
|
||||
|
||||
# if "tunnel_id" in ifstat: # TODO: Add switch
|
||||
# print(f" Tunnel ID : {RNS.prettyhexrep(ifstat['tunnel_id']) if ifstat['tunnel_id'] else 'None'}")
|
||||
if tstats and "tunnel_id" in ifstat:
|
||||
print(f" Tunnel ID : {RNS.prettyhexrep(ifstat['tunnel_id']) if ifstat['tunnel_id'] else 'None'}")
|
||||
|
||||
if "noise_floor" in ifstat:
|
||||
if not "interference" in ifstat: nstr = ""
|
||||
|
|
@ -927,6 +927,7 @@ def main(must_exit=True, rns_instance=None):
|
|||
parser.add_argument("-B", "--burst", action="store_true", help="only show interfaces with active bursts", default=False)
|
||||
parser.add_argument("-b", "--blocked-ips", action="store_true", help="show blocked IPs per interface", default=False)
|
||||
parser.add_argument("-t", "--totals", action="store_true", help="display traffic totals", default=False)
|
||||
parser.add_argument("-T", "--tunnels", action="store_true", help="display tunnel information", default=False)
|
||||
parser.add_argument("-p", "--pps", action="store_true", help="display packets per second in totals", default=False)
|
||||
parser.add_argument("-q", "--queues", action="store_true", help="display queue stats", default=False)
|
||||
parser.add_argument("-z", "--profiling", action="store_true", help="display live profiling results", default=False)
|
||||
|
|
@ -973,7 +974,7 @@ def main(must_exit=True, rns_instance=None):
|
|||
remote=args.R, management_identity=args.i, remote_timeout=args.w, must_exit=False, rns_instance=reticulum,
|
||||
traffic_totals=args.totals, discovered_interfaces=args.discovered, config_entries=args.D, burst_filter=args.burst,
|
||||
blocked_ips=args.blocked_ips, queue_stats=args.queues, pps=args.pps, profiling=args.profiling,
|
||||
show_stale=args.show_stale, show_unknown=args.show_unknown, fstats=args.filter_stats)
|
||||
show_stale=args.show_stale, show_unknown=args.show_unknown, fstats=args.filter_stats, tstats=args.tunnels)
|
||||
|
||||
finally:
|
||||
sys.stdout = old_stdout
|
||||
|
|
@ -992,7 +993,7 @@ def main(must_exit=True, rns_instance=None):
|
|||
remote=args.R, management_identity=args.i, remote_timeout=args.w, must_exit=must_exit, rns_instance=rns_instance,
|
||||
traffic_totals=args.totals, discovered_interfaces=args.discovered, config_entries=args.D, burst_filter=args.burst,
|
||||
blocked_ips=args.blocked_ips, queue_stats=args.queues, pps=args.pps, profiling=args.profiling,
|
||||
attach=args.attach, detach=args.detach, reload=args.reload, show_stale=args.show_stale,
|
||||
attach=args.attach, detach=args.detach, reload=args.reload, show_stale=args.show_stale, tstats=args.tunnels,
|
||||
show_unknown=args.show_unknown, fstats=args.filter_stats)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue