Skip to content

Instantly share code, notes, and snippets.

@shun159
Created July 26, 2013 15:25
Show Gist options
  • Save shun159/6089766 to your computer and use it in GitHub Desktop.
Save shun159/6089766 to your computer and use it in GitHub Desktop.
#
# NAPT TABLE implementation in TremaEdge
# Auther: Eishun Kondoh(e_kondo@ap-com.co.jp)
# Copyright (C) 2013 APCOMMUNICATIONS CO., LTD.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
data = {}
free_ports = (range(1025, 65535))
free_ports.reverse()
def create_entry(i_local_addr, i_local_tp, i_global_addr,o_local_addr, o_local_tp):
index = i_local_addr + str(i_local_tp) + o_local_addr + str(o_local_tp)
if not( data.has_key(index)):
data[index] = [i_local_addr, i_local_tp, i_global_addr, free_ports.pop(), o_local_addr, o_local_tp]
return data[index]
def napt_entry_aged_by(nw_src, nw_dst, tp_src, tp_dst):
index = nw_src + str(tp_src) + nw_dst + str(tp_dst)
if data.has_key(index):
port = data[index][3]
data.remove(index)
free_ports.append(port)
### Local variables:
### mode: Python
### coding: utf-8
### indent-tabs-mode: nil
### End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment