UPnP list on NVRAM overflow?

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
deltatux
DD-WRT User


Joined: 22 Jan 2011
Posts: 72

PostPosted: Tue Mar 29, 2011 21:47    Post subject: UPnP list on NVRAM overflow? Reply with quote
Hi,

I have UPnP enabled on my ASUS RT-N16 router flashed with DD-WRT Build 16214 Mega and I noticed that UPnP is saved to the NVRAM and sometimes it looks like it's going to overflow ... is there a command that I can issue in a cron that I can program to clear the UPnP list at like 5 AM every morning? Usually I have to clear the NVRAM so that my router wouldn't crash from NVRAM exhaustion.

Also, why is the UPnP list saved on NVRAM, wouldn't it make more sense to just store it in regular memory as it should constantly fill and automatically delete entries that are no longer active?

Cheers,
deltatux
Sponsor
crashfly
DD-WRT Guru


Joined: 24 Feb 2009
Posts: 2026
Location: Sol System > Earth > USA > Arkansas

PostPosted: Tue Mar 29, 2011 22:25    Post subject: Re: UPnP list on NVRAM overflow? Reply with quote
deltatux wrote:
Also, why is the UPnP list saved on NVRAM, wouldn't it make more sense to just store it in regular memory as it should constantly fill and automatically delete entries that are no longer active?

Cheers,
deltatux

Well now ... that is an option that I would not mind seeing. The developers would have to get involved to make it happen though.

As for the clearing, there is an option to remove UPnP port forwards on startup. You could have the router reboot once a day in the early morning. It may not be the best solution, but it would work.

Another solution that came to mind would be finding out the exact commands to stop and start the UPnP service. Then that could be run as a cron job.

_________________
E3000 22200M KongVPN K26
WRT600n v1.1 refirb mega 18767 BS K24 NEWD2 [not used]
WRT54G v2 16214 BS K24 [access point]

Try Dropbox for syncing files - get 2.5gb online for free by signing up.

Read! Peacock thread
*PLEASE* upgrade PAST v24SP1 or no support.
phuzi0n
DD-WRT Guru


Joined: 10 Oct 2006
Posts: 10141

PostPosted: Wed Mar 30, 2011 0:02    Post subject: Reply with quote
My ttraff variable cleaner script modified for UPnP:

for i in `nvram show | grep forward_port | cut -f1 -d=""`; do nvram unset $i; done

I don't know how well this will actually work though. I'm not sure whether the UPnP daemon or just the GUI uses the variables, but unseting them does make them disappear from the GUI. You might end up having the UPnP daemon forget about them but then have programs re-requesting the mapping even though this will not remove the actual forwards from iptables. ie. you could flood iptables with lots of duplicate rules.

_________________
Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
deltatux
DD-WRT User


Joined: 22 Jan 2011
Posts: 72

PostPosted: Wed Mar 30, 2011 1:14    Post subject: Reply with quote
Ya, that's what I'm afraid of ... is there no commands to unset UPnP? How does the GUI do it when you press the Delete All button? Does it execute commands on the router?

If so, what command is it?

EDIT: I kind of understand that nvram command but if it's only cosmetic then it's kind of useless no?

deltatux
phuzi0n
DD-WRT Guru


Joined: 10 Oct 2006
Posts: 10141

PostPosted: Wed Mar 30, 2011 3:27    Post subject: Reply with quote
I guess you could also add this to clear the port forwards from iptables after you delete the nvram variables.

startservice wan

_________________
Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
deltatux
DD-WRT User


Joined: 22 Jan 2011
Posts: 72

PostPosted: Wed Mar 30, 2011 3:49    Post subject: Reply with quote
phuzi0n wrote:
I guess you could also add this to clear the port forwards from iptables after you delete the nvram variables.

startservice wan


What does that command do?

Also, I noticed this in the nvram ... is this in minutes, hours or days?
Code:

upnp_max_age=180


Also I noticed that the UPnP list is listed like this in the nvram:
Code:

forward_port0=60176-60176>192.168.56.1:60176-60176,tcp,on,MSNMSGR
forward_port1=60177-60177>192.168.0.11:60176-60176,tcp,on,MSNMSGR
forward_port2=58030-58030>192.168.0.12:58030-58030,tcp,on,DNA (TCP)
forward_port3=58030-58030>192.168.0.12:58030-58030,udp,on,DNA (UDP)
forward_port4=54929-54929>192.168.0.12:54929-54929,tcp,on,MSNMSGR
forward_port5=63131-63131>192.168.56.1:63131-63131,tcp,on,MSNMSGR
forward_port6=63132-63132>192.168.0.11:63131-63131,tcp,on,MSNMSGR
forward_port7=58045-58045>192.168.0.12:58045-58045,tcp,on,MSNMSGR
forward_port8=57043-57043>192.168.0.12:57043-57043,udp,on,Teredo


Any way to do a for loop that detects how many "forward_port" are there, and then delete them one by one? the script you suggested I think deletes all the forwarded ports.

This isn't ideal as I have static ports that forwards to my home server services.

Thanks,
deltatux
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Mar 30, 2011 9:58    Post subject: Reply with quote
uPnP is not only contaminating the nvram space but the FORWARD chain as well.
It should be just 1 entry in the FORWARD chain just like the "Access Restrictions".
Netfilter (iptables) should be used how it is intended!

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
oxygenx
DD-WRT Guru


Joined: 11 Nov 2007
Posts: 566

PostPosted: Wed Mar 30, 2011 10:46    Post subject: Reply with quote
I guess writing the UPNP data optionally to jffs instead of nvram would be a good idea. i also had a case where upnp overflowed the nvram (over 100 rules caused by a misconfigured client)
_________________
Router: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, wl1: g-Only, WPA-Mixed-Mixed)
WDS Node 1: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, WDS-connected Router, wl1: g-Only WPA-Mixed-Mixed)
WDS Node 2: WRT54GL (g-Only, WPA-Mixed-Mixed WDS-connected to Router)
Modem: Cisco EPC3202
clients: Notebook 1, D-Link 323, PS3 Slim, Kathrein UFC960 connected to WDS Node 1 via Gigabit Switch. Notebook 2, Deskjet 6980 connected to WDS Node 2
phuzi0n
DD-WRT Guru


Joined: 10 Oct 2006
Posts: 10141

PostPosted: Wed Mar 30, 2011 13:17    Post subject: Reply with quote
@deltatux - It starts all the services for the WAN, including rebuilding the firewall which will wipe out the removed UPnP forwards.

The script only deletes UPnP forwards, it doesn't touch the static ones made in the GUI.

@frater - Yes, yes it should... But surely you remember that they tried many different UPnP daemons when the k2.6 builds were introduced and had many more serious problems with them. Right now they're using Broadcom's UPnP daemon which does some bad things but is the lesser of evils that they tried.

@oxygenx - UPnP forwards should only be saved in RAM. There's absolutely no reason to save them on persistent storage because UPnP clients are responsible for making sure their ports stay mapped by the UPnP server.

_________________
Read the forum announcements thoroughly! Be cautious if you're inexperienced.
Available for paid consulting. (Don't PM about complicated setups otherwise)
Looking for bricks and spare routers to expand my collection. (not interested in G spec models)
oxygenx
DD-WRT Guru


Joined: 11 Nov 2007
Posts: 566

PostPosted: Wed Mar 30, 2011 13:39    Post subject: Reply with quote
phuzi0n wrote:

@oxygenx - UPnP forwards should only be saved in RAM. There's absolutely no reason to save them on persistent storage because UPnP clients are responsible for making sure their ports stay mapped by the UPnP server.

Are you sure about this? it sounds reseasonable, but i know that in reality it does not work like that.

Applications like Skype or Bittorrent only notice a dropped upnp record after they are restarted and not on-the-fly.

_________________
Router: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, wl1: g-Only, WPA-Mixed-Mixed)
WDS Node 1: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, WDS-connected Router, wl1: g-Only WPA-Mixed-Mixed)
WDS Node 2: WRT54GL (g-Only, WPA-Mixed-Mixed WDS-connected to Router)
Modem: Cisco EPC3202
clients: Notebook 1, D-Link 323, PS3 Slim, Kathrein UFC960 connected to WDS Node 1 via Gigabit Switch. Notebook 2, Deskjet 6980 connected to WDS Node 2
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Mar 30, 2011 17:14    Post subject: Reply with quote
oxygenx wrote:
phuzi0n wrote:

@oxygenx - UPnP forwards should only be saved in RAM. There's absolutely no reason to save them on persistent storage because UPnP clients are responsible for making sure their ports stay mapped by the UPnP server.

Are you sure about this? it sounds reseasonable, but i know that in reality it does not work like that.

Applications like Skype or Bittorrent only notice a dropped upnp record after they are restarted and not on-the-fly.
DD-WRT is set up in a way that restarting the firewall means it will flush all the tables and then completely rebuild it based on statically saved parameters (hardcoded, nvram, /tmp/etc/config files).

A better way would be a file in /tmp for these entries. But that's not how it is setup now.

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)


Last edited by frater on Thu Mar 31, 2011 8:12; edited 1 time in total
deltatux
DD-WRT User


Joined: 22 Jan 2011
Posts: 72

PostPosted: Wed Mar 30, 2011 18:42    Post subject: Reply with quote
frater wrote:
oxygenx wrote:
phuzi0n wrote:

@oxygenx - UPnP forwards should only be saved in RAM. There's absolutely no reason to save them on persistent storage because UPnP clients are responsible for making sure their ports stay mapped by the UPnP server.

Are you sure about this? it sounds reseasonable, but i know that in reality it does not work like that.

Applications like Skype or Bittorrent only notice a dropped upnp record after they are restarted and not on-the-fly.
DD-WRT is set up in a way that restarting the firewall means it will flush all the tables and then completely rebuild it based on statically save parameters (hardcoded, nvram, /tmp/etc/config files).

A better way would be a file in /tmp for these entries. But that's not how it is setup now.


Should we raise this up with BrainSlayer and see if he's willing to move it off the nvram and put it into the /tmp folder RAMDISK instead?

deltatux
oxygenx
DD-WRT Guru


Joined: 11 Nov 2007
Posts: 566

PostPosted: Wed Mar 30, 2011 18:48    Post subject: Reply with quote
deltatux wrote:


Should we raise this up with BrainSlayer and see if he's willing to move it off the nvram and put it into the /tmp folder RAMDISK instead?

deltatux

I dont think thats a good idea.

If it is not required that entries are kept (as phuzi0n said), than they should not be saved at all.

If that's not true, than they need to survive a reboot, /tmp is than not an option.

i still think, optionally jffs would be the best way to solve it.

_________________
Router: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, wl1: g-Only, WPA-Mixed-Mixed)
WDS Node 1: WNDR3300 (wl0: n-Only 5Ghz, WPA2-AES, WDS-connected Router, wl1: g-Only WPA-Mixed-Mixed)
WDS Node 2: WRT54GL (g-Only, WPA-Mixed-Mixed WDS-connected to Router)
Modem: Cisco EPC3202
clients: Notebook 1, D-Link 323, PS3 Slim, Kathrein UFC960 connected to WDS Node 1 via Gigabit Switch. Notebook 2, Deskjet 6980 connected to WDS Node 2
fggs
DD-WRT Guru


Joined: 28 Jan 2008
Posts: 1741

PostPosted: Wed Mar 30, 2011 18:49    Post subject: Reply with quote
@frater: I had that idea when I started messing with iptables. According to official netfilter's faq, using a file with iptables-restore format is safer than scripts that calls iptables on every line. I second your idea of having iptables-save, iptables-save plus iptables-restore would make loading faster and also easier to maintain.
frater
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2777

PostPosted: Wed Mar 30, 2011 19:04    Post subject: Reply with quote
I am using iptables-restore with files stored in /opt/etc and symbolic links in /tmp/etc/config
This works great. I have written a lot of scripts (asiablock, worldblock, fixtables, stophack, stophammer,asterisk) that manipulate the DD-WRT firewall dynamically and they all work flawless.

A uPnP-daemon should use a seperate chain and by maintaining a special file in /tmp these entries can be easily managed.

Although oxygenx is correct that /tmp would not be suitable because it doesn't survive a reboot, I think this is going too far. A router reboot should be something that rarely occurs and restoring all these uPnP-entries is really the responsability of the application that initiated them.

nvram-overflow is a serious problem.
losing upnp entries after a reboot is an inconvenience.

_________________
Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge

DD-WRT v24-sp2 vpn (c) 2010 NewMedia-NET GmbH
Release: 12/16/10 (SVN revision: 15758M)
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum