allow arbitrary subnets for the ip tunnel

This commit is contained in:
Kevin Hester
2020-12-23 17:45:54 +08:00
parent e59fe9af72
commit 7f66d324b3
4 changed files with 19 additions and 14 deletions

View File

@@ -277,7 +277,7 @@ def onConnected(interface):
if args.tunnel:
closeNow = False # Even if others said we could close, stay open if the user asked for a tunnel
tunnel.Tunnel(interface)
tunnel.Tunnel(interface, subnet=args.tunnel_net)
except Exception as ex:
print(ex)
@@ -402,6 +402,9 @@ def main():
parser.add_argument('--tunnel',
action='store_true', help="Create a TUN tunnel device for forwarding IP packets over the mesh")
parser.add_argument(
"--subnet", dest='tunnel_net', help="Read from a GPIO mask", default=None)
parser.set_defaults(router=None)
parser.add_argument('--version', action='version', version=f"{pkg_resources.require('meshtastic')[0].version}")

View File

@@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
syntax='proto3',
serialized_options=b'\n\023com.geeksville.meshB\010PortnumsH\003',
create_key=_descriptor._internal_create_key,
serialized_pb=b'\n\x0eportnums.proto*\xa2\x01\n\x07PortNum\x12\x0f\n\x0bUNKNOWN_APP\x10\x00\x12\x14\n\x10TEXT_MESSAGE_APP\x10\x01\x12\x17\n\x13REMOTE_HARDWARE_APP\x10\x02\x12\x10\n\x0cPOSITION_APP\x10\x03\x12\x10\n\x0cNODEINFO_APP\x10\x04\x12\r\n\tREPLY_APP\x10 \x12\x10\n\x0bPRIVATE_APP\x10\x80\x02\x12\x12\n\rIP_TUNNEL_APP\x10\x80\x08\x42!\n\x13\x63om.geeksville.meshB\x08PortnumsH\x03\x62\x06proto3'
serialized_pb=b'\n\x0eportnums.proto*\xa1\x01\n\x07PortNum\x12\x0f\n\x0bUNKNOWN_APP\x10\x00\x12\x14\n\x10TEXT_MESSAGE_APP\x10\x01\x12\x17\n\x13REMOTE_HARDWARE_APP\x10\x02\x12\x10\n\x0cPOSITION_APP\x10\x03\x12\x10\n\x0cNODEINFO_APP\x10\x04\x12\r\n\tREPLY_APP\x10 \x12\x11\n\rIP_TUNNEL_APP\x10!\x12\x10\n\x0bPRIVATE_APP\x10\x80\x02\x42!\n\x13\x63om.geeksville.meshB\x08PortnumsH\x03\x62\x06proto3'
)
_PORTNUM = _descriptor.EnumDescriptor(
@@ -61,12 +61,12 @@ _PORTNUM = _descriptor.EnumDescriptor(
type=None,
create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor(
name='PRIVATE_APP', index=6, number=256,
name='IP_TUNNEL_APP', index=6, number=33,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
_descriptor.EnumValueDescriptor(
name='IP_TUNNEL_APP', index=7, number=1024,
name='PRIVATE_APP', index=7, number=256,
serialized_options=None,
type=None,
create_key=_descriptor._internal_create_key),
@@ -74,7 +74,7 @@ _PORTNUM = _descriptor.EnumDescriptor(
containing_type=None,
serialized_options=None,
serialized_start=19,
serialized_end=181,
serialized_end=180,
)
_sym_db.RegisterEnumDescriptor(_PORTNUM)
@@ -85,8 +85,8 @@ REMOTE_HARDWARE_APP = 2
POSITION_APP = 3
NODEINFO_APP = 4
REPLY_APP = 32
IP_TUNNEL_APP = 33
PRIVATE_APP = 256
IP_TUNNEL_APP = 1024
DESCRIPTOR.enum_types_by_name['PortNum'] = _PORTNUM

View File

@@ -7,7 +7,6 @@
# sudo bin/run.sh --port /dev/ttyUSB0 --tunnel --debug
# FIXME: set MTU correctly
# allow setting arbitary IP addresses
from . import portnums_pb2
from pubsub import pub
@@ -52,19 +51,22 @@ def onTunnelReceive(packet, interface):
FIXME figure out how to do closures with methods in python"""
tunnelInstance.onReceive(packet)
subnetPrefix = "10.115"
class Tunnel:
"""A TUN based IP tunnel over meshtastic"""
def __init__(self, iface):
def __init__(self, iface, subnet=None, netmask="255.255.0.0"):
"""
Constructor
iface is the already open MeshInterface instance
subnet is used to construct our network number (normally 10.115.x.x)
"""
if subnet is None:
subnet = "10.115"
self.iface = iface
self.subnetPrefix = subnet
global tunnelInstance
tunnelInstance = self
@@ -83,7 +85,7 @@ class Tunnel:
self.tun = TapDevice(name="mesh", mtu=200)
# tun.create()
self.tun.up()
self.tun.ifconfig(address=myAddr,netmask="255.255.0.0")
self.tun.ifconfig(address=myAddr,netmask=netmask)
logging.debug(f"starting TUN reader, our IP address is {myAddr}")
self._rxThread = threading.Thread(target=self.__tunReader, args=(), daemon=True)
self._rxThread.start()
@@ -150,7 +152,7 @@ class Tunnel:
return None
def _nodeNumToIp(self, nodeNum):
return f"{subnetPrefix}.{(nodeNum >> 8) & 0xff}.{nodeNum & 0xff}"
return f"{self.subnetPrefix}.{(nodeNum >> 8) & 0xff}.{nodeNum & 0xff}"
def sendPacket(self, destAddr, p):
"""Forward the provided IP packet into the mesh"""

2
proto

Submodule proto updated: 3c06a5962b...3473446418