Community discussions

MikroTik App
 
R1CH
Forum Guru
Forum Guru
Topic Author
Posts: 1101
Joined: Sun Oct 01, 2006 11:44 pm

UPnP NAT Entry Timeout?

Fri Dec 24, 2010 9:45 pm

I've had my MT router running for over a month and it's UPnP enabled. Sometimes client devices make a UPnP request then they reboot or crash or disconnect or whatever before requesting the entry to be removed. My DST-NAT now has over 250 entries from just 3 PCs, the majority of which are useless since the application that requested them is no longer running. I can see this becoming an issue the longer I leave the device on, the more stale UPnP entries are going to build up.

Is there any way to set a timeout or other way to automatically remove these other than rebooting the device?
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Dec 27, 2010 12:56 am

I'd like the answer to this myself...

I know you can highlight and remove the dynamic entries, but there has to be an easier way... script?



Surely someone must know...
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Thu Jan 06, 2011 10:48 pm

I know these can be removed manually... anyone write a script for this?
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Jan 17, 2011 1:23 am

bump
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Feb 21, 2011 7:29 pm

I was thinking along the lines of a script running with scheduler... anyone?
 
kazibole
just joined
Posts: 7
Joined: Fri Jun 24, 2011 6:04 am

Re: UPnP NAT Entry Timeout?

Fri Jun 24, 2011 6:07 am

+1 for a timeout option or script!
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Wed Nov 16, 2011 5:37 am

Time for another bump... :)


Of course a script would be lovely. :lol: :?
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: UPnP NAT Entry Timeout?

Wed Nov 16, 2011 8:42 pm

How about a "script" for turning UPnP off and on every night to clear it ?
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Nov 28, 2011 9:33 pm

How about a "script" for turning UPnP off and on every night to clear it ?
A kill and restart script is what I had thought of at first, it seems to work really well on other open source platforms. There has to be some decent way to do this in RouterOS.
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: UPnP NAT Entry Timeout?

Mon Nov 28, 2011 9:42 pm

Yes, http://forum.mikrotik.com/viewtopic.php?f=1&t=56529

I think the example - tomato tries to do it beautifully.

People's reactions from RouterBOARDs is "beautiful" and I'd like to get some of those good feelings for my tech soul as well. :)

MikroTik staff, any plans for UPnP ? :)
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 1:11 am

BTW, a prime example of this is the Xbox360 vs. PS3. PS3 opens a upnp port in the NAT table, but when you shut the machine off it released the dhcp address and closes the port. The Xbox360 does not. It opens 3074UDP upon logging into LIVE and never closes it when turning the box off. To remove the port forward you have to remove it manually.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 1:21 am

Disclaimer: I don't use UPnP.

If you have tested that disabling and re-enabling UPnP actually flushes rules this is trivial:
/ip upnp set enabled=no; /ip upnp set enabled=yes;
Schedule that, and you're done.

If that doesn't actually flush rules you could try this: I'd assume that UPnP creates dynamic NAT rules. If that is correct, you can delete all dynamic NAT rules:
/ip firewall nat { remove [find where dynamic] };
This could interact weirdly with other things that create dynamic NAT rules though - it would be a very bad idea to run that on a router that also is a Hotspot.
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 2:13 am

Thank you, fewi!

Yes, you are correct inasmuch as UPnP creates dynamic NAT rules. I do think you're onto something with the second script line you wrote. What is being thought of, however, is some sort of pass/fail scripting.

For instance, UPnP opens a dynamic NAT rule of udp3074. Machine that created the rule is shut down, but the nat rule remains in place. Script would run (scheduler) and check for "the last time any packets came through this rule," or "last time any activity occurred on this rule" and, by way of user defined settings, either remove the dynamic rule or leave it open.

The tomato firmware does something to this effect with upnp and natpmp. Settings such as "cleaning interval (time)" and "number of entries left open before cleaning is even attempted" and so on.
Disclaimer: I don't use UPnP.

If you have tested that disabling and re-enabling UPnP actually flushes rules this is trivial:
/ip upnp set enabled=no; /ip upnp set enabled=yes;
Schedule that, and you're done.

If that doesn't actually flush rules you could try this: I'd assume that UPnP creates dynamic NAT rules. If that is correct, you can delete all dynamic NAT rules:
/ip firewall nat { remove [find where dynamic] };
This could interact weirdly with other things that create dynamic NAT rules though - it would be a very bad idea to run that on a router that also is a Hotspot.
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 2:55 am

Ah. Well, you can access the the connection table via "/ip firewall connection", access the dynamic rules and extract the ports used by them, and then look for connections in the connection table by that port. I doubt that you can determine when a rule was last used without some rather complex logic in the built in scripting language, though. Good luck!
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 3:21 am

This is what I use lately:
/system scheduler add interval=1d name=resetUPnP on-event="/ip upnp set enabled=no;\r\
    \n/delay 3000ms;\r\
    \n/ip upnp set enabled=yes;" start-time=04:30:00
 
User avatar
SeaburyNorton
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Tue Sep 28, 2010 9:39 pm

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 9:24 pm

Thank you as well, NP!

I assume if you've been using this for a while, you can verify that it does clean out the dynamic NAT forwards...

This is what I use lately:
/system scheduler add interval=1d name=resetUPnP on-event="/ip upnp set enabled=no;\r\
    \n/delay 3000ms;\r\
    \n/ip upnp set enabled=yes;" start-time=04:30:00
 
fewi
Forum Guru
Forum Guru
Posts: 7717
Joined: Tue Aug 11, 2009 3:19 am

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 9:53 pm

It probably cleans them just fine, but it's a bit of a brute force approach: it'll also clear forwarding rules that are still active. So if the device/app that requested the UPnP hole be punched is still active you're dragging it out from under its feet. How it handles that would depend on the device/app.
 
User avatar
NetworkPro
Forum Guru
Forum Guru
Posts: 1376
Joined: Mon Jan 05, 2009 6:23 pm
Location: bit.ly/the-qos
Contact:

Re: UPnP NAT Entry Timeout?

Mon Dec 05, 2011 10:27 pm

I think Skype needed to be restarted to re-estabilsh UPnP :)

Who is online

Users browsing this forum: Bing [Bot], GoogleOther [Bot], intania and 195 guests