Return value of ifup/down

Hi Forum

while writing a cronjob to reset my isp connection at night i was running into this issue (only ifdown is shown as ifup behaves the same):

root@lede:~# ifdown nonexistent_if
Interface nonexistent_if not found
root@lede:~# echo $?
root@lede:~# ifdown existent_if
root@lede:~# echo $?

Shouldn't the return value be something different than 0 if ifup/down encounters any error or am i getting something wrong here? I have almost no experience with ash. Is this possibly a bug?

Thanks for reading,

Hey there.;a=blob;f=package/network/config/netifd/files/sbin/ifup;h=5515b91f76df2b5c36d46ac4b86dfc9bdcd78b1d;hb=HEAD

That's the code of ifdown and ifup. It's no source that builds those commands binary but that's actually a sh script to handle interfaces.

So there's just no return value in that script.

Maybe you want to use something of the ubus world directly instead of ifdown. Since that's what this ifdown script does internally (calling ubus) this sounds like an option to me. So I'd suggest to get familiar with ubus.


You can check before running command ifdown, whether device exists:
if (ip a s tun0 up); then


Hi golialive,

thanks for your reply and the link to the ifupdown scripts.

So there’s just no return value in that script.

To be splitting hairs: That's not entirely true. The exit statement with no additional parameter returns 0 which by convention means "success". As ifupdown allready has some error handling (it even returns a meaningfull error message) it should better "exit 1". Maybe someone should file a bug... But thank you anyway.

Maybe you want to use something of the ubus world directly instead of ifdown.

I know a little about shell scripts but i don't know anything about ubus. Actually i heard the name for the first time and i couldn't find much documentation. In my case it sounds to me like using a sledge-hammer to crack a nut.


Hey there.

I get your point about exit values, of course you're right with splitting hairs.
And if you take ifup and ifdown and scripts meant to mimic default linux pendants, you're completely right complaining about that. But I'm not sure if that's the case. So I'm not sure if filing a bug report will result in someone taking care. Instead of filing bug, you might just submit a patch if you can?

Ubus isn't a sledge hammer but the central way how services an deamons on an OpenWRT or LEDE communicate.

When it comes to regular linux ifup/ifdown commands: They deal with actual interfaces. Ubus doesn't necessarily.
Maybe you don't want to ifup eth0.2 but ifup wan? Think about lan interfaces being bridged to some wifi interfaces. You want to just call ifup lan and maybe expect everything, from eth0.1 (bridged to lan), wlan0-0 and wlan0-1 to be taken up and the bridge to be created? That's just something the linux ifup will not do for you, but LEDEs ifup will.

You'l probably find the desired information somewhere in ubus call network.interface.lan status.

I'm not going to tell you ubus is alwas the way to go. That would not be true. If there's a better command, take it. Especially when it comes to regular linux maintenance things you'd normally do in short cron jobs, I completely agree about ubus being just not as easy to handle as regular linux commands we all know. I'm just explaining why ubus is relevant, why there's a difference between what you know from regular linux and LEDE and why I (me personally, being not a LEDE developer but a regular user just like you) understand about the current state being the way it is.