interface: add MTU attribute

This commit is contained in:
Shiz 2022-01-18 20:58:14 +01:00
parent 7e821eb8b0
commit dfdefe1934
3 changed files with 10 additions and 7 deletions

View File

@ -371,7 +371,8 @@ def main():
interface_name = args.interface or 'wg0'
interface = WeegeeInterface.create(ctx, args.name, interface_name,
private_key=args.private_key, public_key=args.public_key,
addresses=args.address, port=args.port, hosts=[WeegeeHost.load(ctx, h) for h in args.host],
addresses=args.address, port=args.port, mtu=args.mtu,
hosts=[WeegeeHost.load(ctx, h) for h in args.host],
extra=args.metadata,
)
interface.save()
@ -383,6 +384,7 @@ def main():
add_interface.add_argument('-K', '--private-key', metavar='KEY', help='private key (optional)')
add_interface.add_argument('-i', '--interface', metavar='NAME', help='interface name (optional)')
add_interface.add_argument('-p', '--port', type=int, help='listen port')
add_interface.add_argument('-m', '--mtu', type=int, help='interface MTU')
add_interface.add_argument('-d', '--metadata', action='append', help='metadata item(s)')
add_interface.add_argument('name', help='interface name')
add_interface.set_defaults(func=do_add_interface, parser=add_interface)

View File

@ -230,14 +230,14 @@ class WeegeeHost(WeegeeBase):
return None
return interface.list_peers()
def sync_interface(self, name: str, addresses: List[IPInterface], routes: List[IPNetwork], config: str) -> bool:
def sync_interface(self, name: str, mtu: O[int], addresses: List[IPInterface], routes: List[IPNetwork], config: str) -> bool:
interface = self.conn.get_interface(name)
if not interface and self.automanage:
interface = self.conn.create_interface(name)
interface = self.conn.create_interface(name, mtu)
if not interface:
return False
if self.automanage:
interface.sync(addresses, routes)
interface.sync(addresses, routes, mtu)
interface.sync_config(config)
return True
@ -348,7 +348,7 @@ class WeegeeInterface(WeegeePublicInterface):
return set(i for i in cls.find_all(ctx) if set(i.hosts) & hosts)
@classmethod
def create(cls, ctx: WeegeeContext, name: str, interface_name: str, private_key: O[str] = None, public_key: O[str] = None, port: O[int] = None, hosts: List[WeegeeHost] = [], addresses: List[IPInterface] = [], extra: O[List[str]] = None) -> 'WeegeeInterface':
def create(cls, ctx: WeegeeContext, name: str, interface_name: str, private_key: O[str] = None, public_key: O[str] = None, port: O[int] = None, mtu: O[int] = None, hosts: List[WeegeeHost] = [], addresses: List[IPInterface] = [], extra: O[List[str]] = None) -> 'WeegeeInterface':
for host in [WeegeeHost.get_local_host(ctx)] + hosts:
try:
private_key = private_key or host.conn.gen_private_key()
@ -364,7 +364,7 @@ class WeegeeInterface(WeegeePublicInterface):
hosts=[h.item for h in hosts],
interface_name=interface_name,
public_key=public_key, private_key=private_key,
addresses=addresses, port=port,
addresses=addresses, port=port, mtu=mtu,
extra=extra,
)
@ -567,7 +567,7 @@ def do_sync_interface(interface: WeegeeInterface, peers: Set[WeegeePeer], connec
for host in interface.hosts:
if auto and not host.autosync:
continue
if not host.sync_interface(interface.interface_name, interface.addresses, routes, config):
if not host.sync_interface(interface.interface_name, interface.mtu, interface.addresses, routes, config):
raise ValueError(f'host {host.name} failed to sync interface!')
return other_peers

View File

@ -73,6 +73,7 @@ WEEGEE_INTERFACE = WeegeeMeta(
f'hosts: [@{WEEGEE_HOST.get_name()}]',
'interface_name: str',
'port: ?int = ',
'mtu: ?int = ',
],
item_prefix=WEEGEE_PUB_INTERFACE.item_prefix,
)