leaf
leaf copied to clipboard
propagate tun/cat listener errors to the user
The issue
Failures happening during initializing tun inbound listener won't propagate back to the user.
ex: Using this config.json
{
"log": {
"level": "debug"
},
"outbounds": [
{
"protocol": "socks",
"settings": {
"address": "192.168.1.100",
"port": 1080
},
"tag": "socks_out"
}
],
"inbounds": [
{
"protocol": "tun",
"settings": {
"name": "tun1",
"address": "198.18.0.1",
"gateway": "198.18.0.1",
"netmask": "255.254.0.0",
"mtu": 1500
},
"tag": "tun_in"
}
]
}
and running this comamnd:
leaf -c config.json
will lead to the program appears to be stuck without showing any errors even while using debug log level.
This will happen even though the tun device wasn't initialized properly because the executable doesn't have enough permissions or capabilities to configure a tun device:
start with options:
StartOptions {
config: File(
"config.json",
),
auto_reload: false,
runtime_opt: MultiThreadAuto(
2097152,
),
}
2025-09-12T21:37:22.952452Z DEBUG leaf::app::outbound::manager: default handler [socks_out]
The proposed solution
Differentiate between two cases:
- tun/cat listeners aren't being configured by the user
- tun/cat listeners failures during initialization
This will make it possible to propagate the errors to the user:
start with options:
StartOptions {
config: File(
"config.json",
),
auto_reload: false,
runtime_opt: MultiThreadAuto(
2097152,
),
}
2025-09-12T21:37:22.952452Z DEBUG leaf::app::outbound::manager: default handler [socks_out]
start leaf failed: create tun failed: Operation not permitted (os error 1)