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