dhcpv6_relay.h
Go to the documentation of this file.
1 /**
2  * @file dhcpv6_relay.h
3  * @brief DHCPv6 relay agent (Dynamic Host Configuration Protocol for IPv6)
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 _DHCPV6_RELAY_H
32 #define _DHCPV6_RELAY_H
33 
34 //Dependencies
35 #include "dhcpv6/dhcpv6_common.h"
36 #include "core/socket.h"
37 
38 //DHCPv6 relay agent support
39 #ifndef DHCPV6_RELAY_SUPPORT
40  #define DHCPV6_RELAY_SUPPORT ENABLED
41 #elif (DHCPV6_RELAY_SUPPORT != ENABLED && DHCPV6_RELAY_SUPPORT != DISABLED)
42  #error DHCPV6_RELAY_SUPPORT parameter is not valid
43 #endif
44 
45 //Stack size required to run the DHCPv6 relay agent
46 #ifndef DHCPV6_RELAY_STACK_SIZE
47  #define DHCPV6_RELAY_STACK_SIZE 500
48 #elif (DHCPV6_RELAY_STACK_SIZE < 1)
49  #error DHCPV6_RELAY_STACK_SIZE parameter is not valid
50 #endif
51 
52 //Priority at which the DHCPv6 relay agent should run
53 #ifndef DHCPV6_RELAY_PRIORITY
54  #define DHCPV6_RELAY_PRIORITY OS_TASK_PRIORITY_NORMAL
55 #endif
56 
57 //Maximum number of client-facing interfaces
58 #ifndef DHCPV6_RELAY_MAX_CLIENT_IF
59  #define DHCPV6_RELAY_MAX_CLIENT_IF 4
60 #elif (DHCPV6_RELAY_MAX_CLIENT_IF < 1)
61  #error DHCPV6_RELAY_MAX_CLIENT_IF parameter is not valid
62 #endif
63 
64 //The amount of overhead added by relay forwarding
65 #define DHCPV6_RELAY_FORW_OVERHEAD (sizeof(Dhcpv6RelayMessage) + 2 * sizeof(Dhcpv6Option) + sizeof(uint32_t))
66 
67 //C++ guard
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 
73 /**
74  * @brief DHCPv6 relay agent settings
75  **/
76 
77 typedef struct
78 {
79  NetInterface *serverInterface; ///<Network-facing interface
80  NetInterface *clientInterface[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<Client-facing interfaces
81  uint_t clientInterfaceCount; ///<Number of client-facing interfaces
82  Ipv6Addr serverAddress; ///<Address to be used when relaying messages to the server
84 
85 
86 /**
87  * @brief DHCPv6 relay agent context
88  **/
89 
90 typedef struct
91 {
92  NetInterface *serverInterface; ///<Network-facing interface
93  NetInterface *clientInterface[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<Client-facing interfaces
94  uint_t clientInterfaceCount; ///<Number of client-facing interfaces
95  Ipv6Addr serverAddress; ///<Address to be used when relaying messages to the server
96  Socket *serverSocket; ///<Socket that handles the network-facing interface
97  Socket *clientSocket[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<Sockets that handle client-facing interfaces
98  SocketEventDesc eventDesc[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<The events the application is interested in
99  bool_t running; ///<DHCPv6 relay agent is currently running or not?
100  bool_t stopRequest; ///<Stop request
101  OsEvent ackEvent; ///<Event object use to acknowledge user requests
102  OsEvent event; ///<Event object used to poll the sockets
103  uint8_t buffer[DHCPV6_MAX_MSG_SIZE]; ///<Scratch buffer to store DHCPv6 messages
105 
106 
107 //DHCPv6 relay agent specific functions
110 
113 
114 void dhcpv6RelayTask(void *param);
115 
118 
119 //C++ guard
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif
bool_t running
DHCPv6 relay agent is currently running or not?
Definition: dhcpv6_relay.h:99
int bool_t
Definition: compiler_port.h:49
error_t dhcpv6RelayStart(Dhcpv6RelayContext *context, const Dhcpv6RelaySettings *settings)
Start DHCPv6 relay agent.
Definition: dhcpv6_relay.c:58
error_t dhcpv6ForwardClientMessage(Dhcpv6RelayContext *context, uint_t index)
Forward client message.
Definition: dhcpv6_relay.c:434
uint_t clientInterfaceCount
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:81
Definitions common to DHCPv6 client, server and relay agent.
Event object.
error_t dhcpv6RelayStop(Dhcpv6RelayContext *context)
Stop DHCPv6 relay agent.
Definition: dhcpv6_relay.c:247
Ipv6Addr serverAddress
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:95
Structure describing socket events.
Definition: socket.h:307
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:79
void dhcpv6RelayTask(void *param)
DHCPv6 relay agent task.
Definition: dhcpv6_relay.c:361
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:92
OsEvent ackEvent
Event object use to acknowledge user requests.
Definition: dhcpv6_relay.h:101
#define DHCPV6_MAX_MSG_SIZE
Definition: dhcpv6_common.h:44
OsEvent event
Event object used to poll the sockets.
Definition: dhcpv6_relay.h:102
error_t
Error codes.
Definition: error.h:42
#define NetInterface
Definition: net.h:36
error_t dhcpv6RelayLeaveMulticastGroup(Dhcpv6RelayContext *context)
Leave All_DHCP_Relay_Agents_and_Servers multicast group.
Definition: dhcpv6_relay.c:338
Ipv6Addr serverAddress
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:82
error_t dhcpv6RelayJoinMulticastGroup(Dhcpv6RelayContext *context)
Join All_DHCP_Relay_Agents_and_Servers multicast group.
Definition: dhcpv6_relay.c:296
__start_packed struct @179 Ipv6Addr
IPv6 network address.
#define DHCPV6_RELAY_MAX_CLIENT_IF
Definition: dhcpv6_relay.h:59
DHCPv6 relay agent settings.
Definition: dhcpv6_relay.h:77
error_t dhcpv6ForwardRelayReplyMessage(Dhcpv6RelayContext *context)
Forward Relay-Reply message.
Definition: dhcpv6_relay.c:563
DHCPv6 relay agent context.
Definition: dhcpv6_relay.h:90
#define Socket
Definition: socket.h:36
Socket API.
uint_t clientInterfaceCount
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:94
unsigned int uint_t
Definition: compiler_port.h:45
bool_t stopRequest
Stop request.
Definition: dhcpv6_relay.h:100
Socket * serverSocket
Socket that handles the network-facing interface.
Definition: dhcpv6_relay.h:96