ipv4_routing.h
Go to the documentation of this file.
1 /**
2  * @file ipv4_routing.h
3  * @brief IPv4 routing
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _IPV4_ROUTING_H
30 #define _IPV4_ROUTING_H
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "ipv4/ipv4.h"
35 
36 //IPv4 routing support
37 #ifndef IPV4_ROUTING_SUPPORT
38  #define IPV4_ROUTING_SUPPORT DISABLED
39 #elif (IPV4_ROUTING_SUPPORT != ENABLED && IPV4_ROUTING_SUPPORT != DISABLED)
40  #error IPV4_ROUTING_SUPPORT parameter is not valid
41 #endif
42 
43 //Size of the IPv4 routing table
44 #ifndef IPV4_ROUTING_TABLE_SIZE
45  #define IPV4_ROUTING_TABLE_SIZE 8
46 #elif (IPV4_ROUTING_TABLE_SIZE < 1)
47  #error IPV4_ROUTING_TABLE_SIZE parameter is not valid
48 #endif
49 
50 //C++ guard
51 #ifdef __cplusplus
52  extern "C" {
53 #endif
54 
55 
56 /**
57  * @brief Routing table entry
58  **/
59 
60 typedef struct
61 {
62  bool_t valid; ///<Valid entry
63  Ipv4Addr networkDest; ///<Network destination
64  Ipv4Addr networkMask; ///<Subnet mask for this route
65  NetInterface *interface; ///<Outgoing network interface
66  Ipv4Addr nextHop; ///<Next hop
67  uint_t metric; ///<Metric value
69 
70 
71 //IPv4 routing related functions
73 error_t ipv4EnableRouting(NetInterface *interface, bool_t enable);
74 
75 error_t ipv4AddRoute(Ipv4Addr networkDest, Ipv4Addr networkMask,
76  NetInterface *interface, Ipv4Addr nextHop, uint_t metric);
77 
78 error_t ipv4DeleteRoute(Ipv4Addr networkDest, Ipv4Addr networkMask);
80 
82  const NetBuffer *ipPacket, size_t ipPacketOffset);
83 
84 //C++ guard
85 #ifdef __cplusplus
86  }
87 #endif
88 
89 #endif
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:232
TCP/IP stack core.
Ipv4Addr nextHop
Next hop.
Definition: ipv4_routing.h:66
IPv4 (Internet Protocol Version 4)
uint8_t ipPacket[]
Definition: ndp.h:427
error_t ipv4ForwardPacket(NetInterface *srcInterface, const NetBuffer *ipPacket, size_t ipPacketOffset)
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
error_t ipv4DeleteAllRoutes(void)
Ipv4Addr networkDest
Network destination.
Definition: ipv4_routing.h:63
Routing table entry.
Definition: ipv4_routing.h:60
error_t
Error codes.
Definition: error.h:40
uint_t metric
Metric value.
Definition: ipv4_routing.h:67
unsigned int uint_t
Definition: compiler_port.h:43
NetInterface * interface
Outgoing network interface.
Definition: ipv4_routing.h:65
#define NetInterface
Definition: net.h:34
error_t ipv4EnableRouting(NetInterface *interface, bool_t enable)
error_t ipv4AddRoute(Ipv4Addr networkDest, Ipv4Addr networkMask, NetInterface *interface, Ipv4Addr nextHop, uint_t metric)
Ipv4Addr networkMask
Subnet mask for this route.
Definition: ipv4_routing.h:64
bool_t valid
Valid entry.
Definition: ipv4_routing.h:62
int bool_t
Definition: compiler_port.h:47
error_t ipv4DeleteRoute(Ipv4Addr networkDest, Ipv4Addr networkMask)
error_t ipv4InitRouting(void)