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