Contiki-NG
ip64-addrmap.h
1 /*
2  * Copyright (c) 2012, Thingsquare, http://www.thingsquare.com/.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 #ifndef IP64_ADDRMAP_H
33 #define IP64_ADDRMAP_H
34 
35 #include "contiki.h"
36 #include "sys/timer.h"
37 #include "net/ipv6/uip.h"
38 
39 struct ip64_addrmap_entry {
40  struct ip64_addrmap_entry *next;
41  struct timer timer;
42  uip_ip6addr_t ip6addr;
43  uip_ip4addr_t ip4addr;
44  uint32_t ip6to4, ip4to6;
45  uint16_t mapped_port;
46  uint16_t ip6port;
47  uint16_t ip4port;
48  uint8_t protocol;
49  uint8_t flags;
50 };
51 
52 #define FLAGS_NONE 0
53 #define FLAGS_RECYCLABLE 1
54 
55 /**
56  * Initialize the ip64_addrmap module.
57  */
58 void ip64_addrmap_init(void);
59 
60 
61 /**
62  * Look up an address mapping from inside the IPv6 network, given the
63  * IPv6 address/port, the IPv4 address/port, and the protocol.
64  */
65 struct ip64_addrmap_entry *ip64_addrmap_lookup(const uip_ip6addr_t *ip6addr,
66  uint16_t ip6port,
67  const uip_ip4addr_t *ip4addr,
68  uint16_t ip4port,
69  uint8_t protocol);
70 
71 /**
72  * Look up an address mapping from the outside IPv4 network, given the
73  * mapped port number and protocol.
74  */
75 struct ip64_addrmap_entry *ip64_addrmap_lookup_port(uint16_t mappedport,
76  uint8_t protocol);
77 
78 /**
79  * Create a new address mapping from an IPv6 address/port, an IPv4
80  * address/port, and a protocol number.
81  */
82 struct ip64_addrmap_entry *ip64_addrmap_create(const uip_ip6addr_t *ip6addr,
83  uint16_t ip6port,
84  const uip_ip4addr_t *ip4addr,
85  uint16_t ip4port,
86  uint8_t protocol);
87 
88 /**
89  * Set the lifetime of an address mapping.
90  */
91 void ip64_addrmap_set_lifetime(struct ip64_addrmap_entry *e,
92  clock_time_t lifetime);
93 
94 /**
95  * Mark an address mapping to be recyclable.
96  */
97 void ip64_addrmap_set_recycleble(struct ip64_addrmap_entry *e);
98 
99 /**
100  * Obtain the list of all address mappings.
101  */
102 struct ip64_addrmap_entry *ip64_addrmap_list(void);
103 #endif /* IP64_ADDRMAP_H */
Representation of an IP address.
Definition: uip.h:95
A timer.
Definition: timer.h:82
Timer library header file.
Header file for the uIP TCP/IP stack.