How can I set Raspberry Pi 4 led as internet indicator?

I am using a bridged modem and my Pi 4 as a router. Pi's led is always red. After I set modem in bridge mode, only DSL, (I am using VDSL), Power and LAN leds are on. But "internet" led which indicates there is internet connection is off. So, I want to set Pi4's led as green when internet connection is active, and red when internet is off. Can i do this? Or will it require me to write code? There is a Led Configuration option under System in Openwrt. There are Options like "default-on", "led0", "led1", "mmc0". I don't know how to use them.

You need to install some ledtrig module, like netlink.

Is there a chance that i would brick my router by just messing the Led configs on Luci?

No, you won't brick the router through the LED configuration page on LuCI. And even if you could, Raspberry Pis are quite possibly the easiest routers to flash. Just re-image or exchange the SD card.

Do you want the LED to indicate if the Ethernet link between the router and the modem is up, or do you want it to indicate if there's Internet connectivity?

If it's the former, you can do this from the web interface:

  1. Go to LuCI → SystemLED Configuration and click Add LED action.
  2. Set Name to anything you want.
  3. Set LED Name to either led0 or led1. I think led0 is the green one, but I could be misremembering.
  4. Set Trigger to network device activity.
  5. Set Device to the WAN interface.
  6. Choose desired Trigger Mode options.
  7. Click Save then Save & Apply.

You can only set a led if it is connected on a available GPIO pin.
I don’t think Pi4 have any GPIO connected led. As far as I know they are all directly hardware controlled and the power LED is definitely hardwired to the 5V power line.

This gives a hint to control onboard LED (maybe not all of them, but I believe possible), but probably need to manually doing that under OpenWrt?

ComputeModule4 (CM4) is definitely not RaspberryPi4, not even close.

There are two software controllable leds on the pi 4. Led0 and led1. Those should show up in the system by default. I use the netdev trigger on them - in my case, it indicates my vpn traffic.

Other option would be to use hotplug scripts or polling on schedule to change sysfs LED values directly. The notation of "I have internet" is technically composite of having DNS and being able to connect like across the closest sea.

Oh yes, I didn't realize it's CM4, however for the non-CM one, it's still possible to control onboard LED by software.

They both use the exact same SoC and run the same set of operating systems (OpenWrt, Raspberry Pi OS, etc). The biggest difference, besides the form factor, is the VL805 xHCI controller hanging off the SoC's 1x PCIe lane in the Pi 4B. But that isn't relevant to the OP's question. The "activity" LED is definitely controllable by writing to files in the /sys/class/leds/led0 directory on both CM4 and Pi 4B.