Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UserConfig
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
UserConfig
Commits
3e8ee19c
You need to sign in or sign up before continuing.
Commit
3e8ee19c
authored
1 year ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
NET blatto-daemon
parent
295787a8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
network/blatto-daemon.py
+97
-0
97 additions, 0 deletions
network/blatto-daemon.py
network/init.sh
+5
-3
5 additions, 3 deletions
network/init.sh
with
102 additions
and
3 deletions
network/blatto-daemon.py
0 → 100755
+
97
−
0
View file @
3e8ee19c
#!/usr/bin/env python3
import
time
import
signal
import
sys
,
os
import
socket
import
json
import
subprocess
def
p
(
*
args
):
print
(
*
args
,
flush
=
True
)
def
handler
(
signum
,
frame
):
signame
=
signal
.
Signals
(
signum
).
name
p
(
f
'
Signal handler called with signal
{
signame
}
(
{
signum
}
)
'
)
signal
.
signal
(
signal
.
SIGHUP
,
handler
)
signal
.
pthread_sigmask
(
signal
.
SIG_BLOCK
,
[
signal
.
SIGHUP
])
p
(
"
PID
"
,
os
.
getpid
())
sock
=
socket
.
socket
(
socket
.
AF_INET6
,
socket
.
SOCK_DGRAM
)
def
ip
(
*
args
):
if
args
[
0
]
in
[
6
,
-
6
]:
args
=
list
(
args
)
args
[
0
]
=
"
-6
"
r
=
subprocess
.
run
([
"
ip
"
,
"
-j
"
,
*
args
],
stdout
=
subprocess
.
PIPE
,
encoding
=
"
utf-8
"
)
return
json
.
loads
(
r
.
stdout
)
if
r
.
stdout
else
None
def
iwconfig
():
r
=
subprocess
.
run
([
"
sh
"
,
"
-c
"
,
"
iwconfig | jc --iwconfig
"
],
stdout
=
subprocess
.
PIPE
,
encoding
=
"
utf-8
"
)
return
json
.
loads
(
r
.
stdout
)
if
r
.
stdout
else
None
def
send
(
msg
,
target_ip
):
msg
=
json
.
dumps
(
msg
).
encode
(
"
utf-8
"
)
p
(
msg
)
sock
.
sendto
(
b
"
____01
"
+
msg
,
(
target_ip
,
12011
))
def
format_ip
(
addr_info
):
return
f
"
{
addr_info
[
'
local
'
]
}
/
{
addr_info
[
'
prefixlen
'
]
}
"
def
sort_ips
(
addrs
):
return
addrs
while
True
:
p
(
"
RUN
"
)
ipa
=
ip
(
"
a
"
)
iwc
=
{
i
[
"
name
"
]:
i
for
i
in
iwconfig
()}
def
is_blatto
(
i
):
for
ip
in
i
[
"
addr_info
"
]:
if
any
(
ip
[
"
local
"
].
startswith
(
f
"
2a01:510:d504:75
{
i
}
a:
"
)
for
i
in
range
(
0
,
10
)):
return
True
return
False
def
is_blatto_wg
(
i
):
for
ip
in
i
[
"
addr_info
"
]:
if
any
(
ip
[
"
local
"
].
startswith
(
f
"
2a01:510:d504:75
{
i
}
b:
"
)
for
i
in
range
(
0
,
10
)):
return
True
return
False
interfaces
=
{}
blatto
=
False
for
i
in
ipa
:
if
i
[
"
operstate
"
]
in
[
"
UP
"
,
"
UNKNOWN
"
]:
out
=
{
"
addr
"
:
[
format_ip
(
ip
)
for
ip
in
sort_ips
(
i
[
"
addr_info
"
])],
"
mtu
"
:
i
[
"
mtu
"
]
}
if
i
[
"
link_type
"
]
==
"
ether
"
:
# WiFi or ethernet, no loopback or wireguard
if
is_blatto
(
i
):
blatto
=
True
if
is_blatto_wg
(
i
):
blatto_wg
=
{
"
mtu
"
:
i
[
"
mtu
"
]}
if
i
[
"
ifname
"
]
in
iwc
:
w
=
iwc
[
i
[
"
ifname
"
]]
out
[
"
essid
"
]
=
w
[
"
essid
"
]
interfaces
[
i
[
"
ifname
"
]]
=
out
if
blatto_wg
:
try
:
autorouting
=
open
(
"
/run/wg-blatto/autorouting
"
).
read
().
strip
()
current_routing
=
open
(
"
/run/wg-blatto/routing
"
).
read
().
strip
()
wanted_routing
=
"
no
"
if
blatto
else
autorouting
p
(
f
"
blatto-wg routing:
{
current_routing
}
->
{
wanted_routing
}
"
)
if
wanted_routing
!=
current_routing
:
subprocess
.
run
([
"
/etc/net/wg-blatto-route
"
,
wanted_routing
])
current_routing
=
open
(
"
/run/wg-blatto/routing
"
).
read
().
strip
()
blatto_wg
[
"
routing
"
]
=
current_routing
except
FileNotFoundError
as
e
:
p
(
f
"
blatto-wg routing:
{
e
}
"
)
send
({
"
blatto-wg
"
:
blatto_wg
,
"
blatto
"
:
blatto
,
"
interfaces
"
:
interfaces
},
"
2a01:510:d504:751a::1
"
if
blatto
else
"
2a01:510:d504:751b::1
"
)
p
(
"
DONE
"
)
signal
.
sigtimedwait
([
signal
.
SIGHUP
],
10
)
This diff is collapsed.
Click to expand it.
network/init.sh
+
5
−
3
View file @
3e8ee19c
#!/bin/bash
cd
"
$(
dirname
"
$0
"
)
"
.
../userconfig-lib.sh
version
7
version
8
need_root
install_begin
...
...
@@ -29,9 +29,11 @@ done
r udevadm control
--reload-rules
r udevadm trigger
git_clupdate https://codeberg.org/regnarg/cdwifi-autologin.git build_git_cdwifi-autologin
r
-c
git_clupdate https://codeberg.org/regnarg/cdwifi-autologin.git build_git_cdwifi-autologin
confln build_git_cdwifi-autologin/cdwifi-autologin.sh /usr/bin/ cE
confln cdwifi-autologin.service /lib/systemd/system/ cr
confln blatto-daemon.py /usr/bin/net-blatto-daemon c
init-service net-blatto-daemon root /usr/bin/net-blatto-daemon
""
"ExecReload=/bin/kill -HUP
\$
MAINPID"
install_ok
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment