EVE 1.0
uip-fw.h
Go to the documentation of this file.
1 /**
2  * \addtogroup uipfw
3  * @{
4  */
5 
6 /**
7  * \file
8  * uIP packet forwarding header file.
9  * \author Adam Dunkels <adam@sics.se>
10  */
11 
12 /*
13  * Copyright (c) 2004, Swedish Institute of Computer Science.
14  * All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the Institute nor the names of its contributors
25  * may be used to endorse or promote products derived from this software
26  * without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  * This file is part of the Contiki operating system.
41  *
42  * Author: Adam Dunkels <adam@sics.se>
43  *
44  */
45 #ifndef UIP_FW_H_
46 #define UIP_FW_H_
47 
48 #include "net/uip.h"
49 
50 /**
51  * Representation of a uIP network interface.
52  */
53 struct uip_fw_netif {
54  struct uip_fw_netif *next; /**< Pointer to the next interface when
55  linked in a list. */
56  uip_ipaddr_t ipaddr; /**< The IP address of this interface. */
57  uip_ipaddr_t netmask; /**< The netmask of the interface. */
58  uint8_t (* output)(struct uip_fw_netif *netif);
59  /**< A pointer to the function that
60  sends a packet. */
61  bool (* quote)(struct uip_fw_netif *netif); /**< A pointer to the function which tells
62  * if it is allowed to send a packet */
63 };
64 
65 /**
66  * Instantiating macro for a uIP network interface.
67  *
68  * Example:
69  \code
70  struct uip_fw_netif slipnetif =
71  {UIP_FW_NETIF(192,168,76,1, 255,255,255,0, slip_output)};
72  \endcode
73  * \param ip1,ip2,ip3,ip4 The IP address of the network interface.
74  *
75  * \param nm1,nm2,nm3,nm4 The netmask of the network interface.
76  *
77  * \param outputfunc A pointer to the output function of the network interface.
78  *
79  * \hideinitializer
80  */
81 #define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
82  NULL, \
83  { {ip1, ip2, ip3, ip4} }, \
84  { {nm1, nm2, nm3, nm4} }, \
85  outputfunc
86 
87 /**
88  * Set the IP address of a network interface.
89  *
90  * \param netif A pointer to the uip_fw_netif structure for the network interface.
91  *
92  * \param addr A pointer to an IP address.
93  *
94  * \hideinitializer
95  */
96 #define uip_fw_setipaddr(netif, addr) \
97  do { (netif)->ipaddr[0] = ((uint16_t *)(addr))[0]; \
98  (netif)->ipaddr[1] = ((uint16_t *)(addr))[1]; } while(0)
99 /**
100  * Set the netmask of a network interface.
101  *
102  * \param netif A pointer to the uip_fw_netif structure for the network interface.
103  *
104  * \param addr A pointer to an IP address representing the netmask.
105  *
106  * \hideinitializer
107  */
108 #define uip_fw_setnetmask(netif, addr) \
109  do { (netif)->netmask[0] = ((uint16_t *)(addr))[0]; \
110  (netif)->netmask[1] = ((uint16_t *)(addr))[1]; } while(0)
111 
112 void uip_fw_init(void);
113 uint8_t uip_fw_forward(void);
114 bool uip_fw_quote(const uip_ipaddr_t *destipaddr);
115 uint8_t uip_fw_output(void);
116 void uip_fw_register(struct uip_fw_netif *netif);
117 void uip_fw_default(struct uip_fw_netif *netif);
118 void uip_fw_periodic(void);
119 
120 
121 /**
122  * A non-error message that indicates that a packet should be
123  * processed locally.
124  *
125  * \hideinitializer
126  */
127 #define UIP_FW_LOCAL 0
128 
129 /**
130  * A non-error message that indicates that something went OK.
131  *
132  * \hideinitializer
133  */
134 #define UIP_FW_OK 0
135 
136 /**
137  * A non-error message that indicates that a packet was forwarded.
138  *
139  * \hideinitializer
140  */
141 #define UIP_FW_FORWARDED 1
142 
143 /**
144  * A non-error message that indicates that a zero-length packet
145  * transmission was attempted, and that no packet was sent.
146  *
147  * \hideinitializer
148  */
149 #define UIP_FW_ZEROLEN 2
150 
151 /**
152  * An error message that indicates that a packet that was too large
153  * for the outbound network interface was detected.
154  *
155  * \hideinitializer
156  */
157 #define UIP_FW_TOOLARGE 3
158 
159 /**
160  * An error message that indicates that no suitable interface could be
161  * found for an outbound packet.
162  *
163  * \hideinitializer
164  */
165 #define UIP_FW_NOROUTE 4
166 
167 /**
168  * An error message that indicates that a packet that should be
169  * forwarded or output was dropped.
170  *
171  * \hideinitializer
172  */
173 #define UIP_FW_DROPPED 5
174 
175 
176 #endif /* UIP_FW_H_ */
177 
178 /** @} */
uint8_t uip_fw_forward(void)
Definition: uip-fw.c:428
void uip_fw_default(struct uip_fw_netif *netif)
Definition: uip-fw.c:540
void uip_fw_register(struct uip_fw_netif *netif)
Definition: uip-fw.c:523
bool uip_fw_quote(const uip_ipaddr_t *destipaddr)
Definition: uip-fw.c:343
bool(* quote)(struct uip_fw_netif *netif)
Definition: uip-fw.h:61
void uip_fw_periodic(void)
Definition: uip-fw.c:550
uint8_t uip_fw_output(void)
Definition: uip-fw.c:376
uint8_t(* output)(struct uip_fw_netif *netif)
Definition: uip-fw.h:58
struct uip_fw_netif * next
Definition: uip-fw.h:54
void uip_fw_init(void)
Definition: uip-fw.c:186
uip_ipaddr_t netmask
Definition: uip-fw.h:57
uip_ipaddr_t ipaddr
Definition: uip-fw.h:56