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-2024 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.4.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  OsTaskParameters task; ///<Task parameters
80  NetInterface *serverInterface; ///<Network-facing interface
81  NetInterface *clientInterface[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<Client-facing interfaces
82  uint_t clientInterfaceCount; ///<Number of client-facing interfaces
83  Ipv6Addr serverAddress; ///<Address to be used when relaying messages to the server
85 
86 
87 /**
88  * @brief DHCPv6 relay agent context
89  **/
90 
91 typedef struct
92 {
93  NetInterface *serverInterface; ///<Network-facing interface
94  NetInterface *clientInterface[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<Client-facing interfaces
95  uint_t clientInterfaceCount; ///<Number of client-facing interfaces
96  Ipv6Addr serverAddress; ///<Address to be used when relaying messages to the server
97  Socket *serverSocket; ///<Socket that handles the network-facing interface
98  Socket *clientSocket[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<Sockets that handle client-facing interfaces
99  SocketEventDesc eventDesc[DHCPV6_RELAY_MAX_CLIENT_IF]; ///<The events the application is interested in
100  bool_t running; ///<DHCPv6 relay agent is currently running or not?
101  bool_t stopRequest; ///<Stop request
102  OsEvent ackEvent; ///<Event object use to acknowledge user requests
103  OsEvent event; ///<Event object used to poll the sockets
104  OsTaskParameters taskParams; ///<Task parameters
105  OsTaskId taskId; ///<Task identifier
106  uint8_t buffer[DHCPV6_MAX_MSG_SIZE]; ///<Scratch buffer to store DHCPv6 messages
108 
109 
110 //DHCPv6 relay agent specific functions
113 
116 
117 void dhcpv6RelayTask(void *param);
118 
121 
122 //C++ guard
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif
bool_t running
DHCPv6 relay agent is currently running or not?
Definition: dhcpv6_relay.h:100
int bool_t
Definition: compiler_port.h:53
OsTaskParameters task
Task parameters.
Definition: dhcpv6_relay.h:79
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:446
uint_t clientInterfaceCount
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:82
Definitions common to DHCPv6 client, server and relay agent.
Event object.
error_t dhcpv6RelayStop(Dhcpv6RelayContext *context)
Stop DHCPv6 relay agent.
Definition: dhcpv6_relay.c:254
Ipv6Addr
Definition: ipv6.h:260
Ipv6Addr serverAddress
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:96
Structure describing socket events.
Definition: socket.h:426
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:80
void dhcpv6RelayTask(void *param)
DHCPv6 relay agent task.
Definition: dhcpv6_relay.c:371
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:93
OsEvent ackEvent
Event object use to acknowledge user requests.
Definition: dhcpv6_relay.h:102
#define DHCPV6_MAX_MSG_SIZE
Definition: dhcpv6_common.h:44
OsEvent event
Event object used to poll the sockets.
Definition: dhcpv6_relay.h:103
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:36
error_t dhcpv6RelayLeaveMulticastGroup(Dhcpv6RelayContext *context)
Leave All_DHCP_Relay_Agents_and_Servers multicast group.
Definition: dhcpv6_relay.c:348
Ipv6Addr serverAddress
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:83
error_t dhcpv6RelayJoinMulticastGroup(Dhcpv6RelayContext *context)
Join All_DHCP_Relay_Agents_and_Servers multicast group.
Definition: dhcpv6_relay.c:306
Task parameters.
#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:575
DHCPv6 relay agent context.
Definition: dhcpv6_relay.h:92
#define Socket
Definition: socket.h:36
Socket API.
OsTaskParameters taskParams
Task parameters.
Definition: dhcpv6_relay.h:104
thread_t * OsTaskId
Task identifier.
uint_t clientInterfaceCount
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:95
unsigned int uint_t
Definition: compiler_port.h:50
bool_t stopRequest
Stop request.
Definition: dhcpv6_relay.h:101
Socket * serverSocket
Socket that handles the network-facing interface.
Definition: dhcpv6_relay.h:97
OsTaskId taskId
Task identifier.
Definition: dhcpv6_relay.h:105