31 #include "ip64-addrmap.h"
36 #include "ip64-conf.h"
40 #ifdef IP64_ADDRMAP_CONF_ENTRIES
41 #define NUM_ENTRIES IP64_ADDRMAP_CONF_ENTRIES
43 #define NUM_ENTRIES 32
46 MEMB(entrymemb,
struct ip64_addrmap_entry, NUM_ENTRIES);
49 #define FIRST_MAPPED_PORT 10000
50 #define LAST_MAPPED_PORT 20000
51 static uint16_t mapped_port = FIRST_MAPPED_PORT;
56 struct ip64_addrmap_entry *
57 ip64_addrmap_list(
void)
63 ip64_addrmap_init(
void)
67 mapped_port = FIRST_MAPPED_PORT;
73 struct ip64_addrmap_entry *m;
93 struct ip64_addrmap_entry *m, *oldest;
102 if(m->flags & FLAGS_RECYCLABLE) {
125 struct ip64_addrmap_entry *
126 ip64_addrmap_lookup(
const uip_ip6addr_t *ip6addr,
132 struct ip64_addrmap_entry *m;
134 printf(
"lookup ip4port %d ip6port %d\n",
uip_htons(ip4port),
138 printf(
"protocol %d %d, ip4port %d %d, ip6port %d %d, ip4 %d ip6 %d\n",
139 m->protocol, protocol,
143 uip_ip6addr_cmp(&m->ip6addr, ip6addr));
144 if(m->protocol == protocol &&
145 m->ip4port == ip4port &&
146 m->ip6port == ip6port &&
148 uip_ip6addr_cmp(&m->ip6addr, ip6addr)) {
155 struct ip64_addrmap_entry *
156 ip64_addrmap_lookup_port(uint16_t mapped_port, uint8_t protocol)
158 struct ip64_addrmap_entry *m;
162 printf(
"mapped port %d %d, protocol %d %d\n",
163 m->mapped_port, mapped_port,
164 m->protocol, protocol);
165 if(m->mapped_port == mapped_port &&
166 m->protocol == protocol) {
174 increase_mapped_port(
void)
177 if(mapped_port >= LAST_MAPPED_PORT) {
178 mapped_port = FIRST_MAPPED_PORT;
182 struct ip64_addrmap_entry *
183 ip64_addrmap_create(
const uip_ip6addr_t *ip6addr,
189 struct ip64_addrmap_entry *m;
201 uip_ip4addr_copy(&m->ip4addr, ip4addr);
202 m->ip4port = ip4port;
203 uip_ip6addr_copy(&m->ip6addr, ip6addr);
204 m->ip6port = ip6port;
205 m->protocol = protocol;
206 m->flags = FLAGS_NONE;
213 struct ip64_addrmap_entry *n;
216 if(n->mapped_port == mapped_port) {
217 increase_mapped_port();
224 m->mapped_port = mapped_port;
225 increase_mapped_port();
234 ip64_addrmap_set_lifetime(
struct ip64_addrmap_entry *e,
243 ip64_addrmap_set_recycleble(
struct ip64_addrmap_entry *e)
246 e->flags |= FLAGS_RECYCLABLE;
Linked list manipulation routines.
void memb_init(struct memb *m)
Initialize a memory block that was declared with MEMB().
void * list_item_next(void *item)
Get the next item following this item.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
char memb_free(struct memb *m, void *ptr)
Deallocate a memory block from a memory block previously declared with MEMB().
void * memb_alloc(struct memb *m)
Allocate a memory block from a block of memory declared with MEMB().
#define NULL
The null pointer.
#define uip_ip4addr_cmp(addr1, addr2)
Compare two IP addresses.
void list_remove(list_t list, void *item)
Remove a specific element from a list.
clock_time_t timer_remaining(struct timer *t)
The time until the timer expires.
Representation of an IP address.
void list_init(list_t list)
Initialize a list.
void * list_head(list_t list)
Get a pointer to the first element of a list.
#define MEMB(name, structure, num)
Declare a memory block.
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
void list_add(list_t list, void *item)
Add an item at the end of a list.
#define LIST(name)
Declare a linked list.
Memory block allocation routines.
int timer_expired(struct timer *t)
Check if a timer has expired.