mirror of
https://github.com/Kiritow/wg-ops.git
synced 2024-03-22 13:11:37 +08:00
Add MTU patch
This commit is contained in:
parent
811e81f126
commit
c344937eec
21
generate.py
21
generate.py
|
@ -1,8 +1,12 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import getopt
|
||||||
|
|
||||||
filepath = sys.argv[1]
|
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], 'k')
|
||||||
|
|
||||||
|
filepath = args[0]
|
||||||
|
|
||||||
path_udp2raw = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'bin/udp2raw_amd64')
|
path_udp2raw = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'bin/udp2raw_amd64')
|
||||||
path_w2u = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'bin/w2u')
|
path_w2u = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'bin/w2u')
|
||||||
|
@ -30,12 +34,16 @@ def add_tmux_session_once():
|
||||||
for line in content:
|
for line in content:
|
||||||
if line.startswith('ListenPort'):
|
if line.startswith('ListenPort'):
|
||||||
gen_ctx['wg_port'] = int(line.split('=')[1])
|
gen_ctx['wg_port'] = int(line.split('=')[1])
|
||||||
|
if line.startswith('MTU'):
|
||||||
|
gen_ctx['mtu_detected'] = True
|
||||||
if line.startswith('[Peer]'):
|
if line.startswith('[Peer]'):
|
||||||
if 'peer_started' not in gen_ctx:
|
if 'peer_started' not in gen_ctx:
|
||||||
gen_ctx['peer_started'] = True
|
gen_ctx['peer_started'] = True
|
||||||
|
if 'mtu_detected' not in gen_ctx:
|
||||||
|
sys.stderr.write('[WARN] MTU not detected, using suggested mtu value (1280).\n')
|
||||||
|
results.append('MTU=1280')
|
||||||
if gen_ctx['post_down']:
|
if gen_ctx['post_down']:
|
||||||
results.extend(gen_ctx['post_down'])
|
results.extend(gen_ctx['post_down'])
|
||||||
|
|
||||||
if 'has_setup_tmux' in gen_ctx:
|
if 'has_setup_tmux' in gen_ctx:
|
||||||
results.append('PostDown=sleep 1; /usr/bin/tmux kill-session -t tunnel-{}'.format(wg_name))
|
results.append('PostDown=sleep 1; /usr/bin/tmux kill-session -t tunnel-{}'.format(wg_name))
|
||||||
|
|
||||||
|
@ -177,9 +185,12 @@ for line in content:
|
||||||
else:
|
else:
|
||||||
results.insert(last_postup_idx, 'PostUp=ip -4 route add {} dev wg0'.format(route_target))
|
results.insert(last_postup_idx, 'PostUp=ip -4 route add {} dev wg0'.format(route_target))
|
||||||
else:
|
else:
|
||||||
print('[WARN] comment or unknown hint: {}'.format(line))
|
sys.stderr.write('[WARN] comment or unknown hint: {}\n'.format(line))
|
||||||
|
|
||||||
|
|
||||||
|
final_content = '# Generated by wg-ops at {}. DO NOT EDIT\n{}'.format(time.strftime("%Y-%m-%d %H:%M:%S"), '\n'.join(results))
|
||||||
|
if '-k' not in final_content:
|
||||||
with open('{}.gen'.format(filename), 'w') as f:
|
with open('{}.gen'.format(filename), 'w') as f:
|
||||||
f.write('# Generated by wg-ops at {}. DO NOT EDIT\n'.format(time.strftime("%Y-%m-%d %H:%M:%S")))
|
f.write(final_content)
|
||||||
f.write('\n'.join(results))
|
else:
|
||||||
|
print(final_content)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user