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-2023 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 2.2.4
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  OsTaskId taskId; ///<Task identifier
104 #if (OS_STATIC_TASK_SUPPORT == ENABLED)
105  OsTaskTcb taskTcb; ///<Task control block
106  OsStackType taskStack[DHCPV6_RELAY_STACK_SIZE]; ///<Task stack
107 #endif
108  uint8_t buffer[DHCPV6_MAX_MSG_SIZE]; ///<Scratch buffer to store DHCPv6 messages
110 
111 
112 //DHCPv6 relay agent specific functions
115 
118 
119 void dhcpv6RelayTask(void *param);
120 
123 
124 //C++ guard
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif
bool_t running
DHCPv6 relay agent is currently running or not?
Definition: dhcpv6_relay.h:99
int bool_t
Definition: compiler_port.h:53
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:448
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:256
Ipv6Addr serverAddress
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:95
Structure describing socket events.
Definition: socket.h:365
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:79
void dhcpv6RelayTask(void *param)
DHCPv6 relay agent task.
Definition: dhcpv6_relay.c:373
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:43
Task control block.
#define NetInterface
Definition: net.h:36
error_t dhcpv6RelayLeaveMulticastGroup(Dhcpv6RelayContext *context)
Leave All_DHCP_Relay_Agents_and_Servers multicast group.
Definition: dhcpv6_relay.c:350
uint32_t OsStackType
Stack data type.
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:308
#define DHCPV6_RELAY_MAX_CLIENT_IF
Definition: dhcpv6_relay.h:59
DHCPv6 relay agent settings.
Definition: dhcpv6_relay.h:78
error_t dhcpv6ForwardRelayReplyMessage(Dhcpv6RelayContext *context)
Forward Relay-Reply message.
Definition: dhcpv6_relay.c:577
DHCPv6 relay agent context.
Definition: dhcpv6_relay.h:91
#define Socket
Definition: socket.h:36
Socket API.
thread_t * OsTaskId
Task identifier.
uint_t clientInterfaceCount
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:94
unsigned int uint_t
Definition: compiler_port.h:50
bool_t stopRequest
Stop request.
Definition: dhcpv6_relay.h:100
OsTaskTcb taskTcb
Task control block.
Definition: dhcpv6_relay.h:105
__start_packed struct @0 Ipv6Addr
IPv6 network address.
#define DHCPV6_RELAY_STACK_SIZE
Definition: dhcpv6_relay.h:47
Socket * serverSocket
Socket that handles the network-facing interface.
Definition: dhcpv6_relay.h:96
OsTaskId taskId
Task identifier.
Definition: dhcpv6_relay.h:103