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-2026 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.6.0
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 DISABLED
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_INTERFACES
59  #define DHCPV6_RELAY_MAX_CLIENT_INTERFACES 8
60 #elif (DHCPV6_RELAY_MAX_CLIENT_INTERFACES < 1)
61  #error DHCPV6_RELAY_MAX_CLIENT_INTERFACES parameter is not valid
62 #endif
63 
64 //The amount of overhead added by relay forwarding
65 #define DHCPV6_RELAY_FORWARDING_OVERHEAD (sizeof(Dhcpv6RelayMessage) + \
66  2 * sizeof(Dhcpv6Option) + sizeof(uint32_t))
67 
68 //C++ guard
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
73 
74 /**
75  * @brief DHCPv6 relay agent settings
76  **/
77 
78 typedef struct
79 {
80  OsTaskParameters task; ///<Task parameters
81  NetInterface *serverInterface; ///<Network-facing interface
82  uint_t numClientInterfaces; ///<Number of client-facing interfaces
83  NetInterface *clientInterfaces[DHCPV6_RELAY_MAX_CLIENT_INTERFACES]; ///<Client-facing interfaces
84  Ipv6Addr serverIpAddr; ///<Address to be used when relaying messages to the server
86 
87 
88 /**
89  * @brief DHCPv6 relay agent context
90  **/
91 
92 typedef struct
93 {
94  NetContext *netContext; ///<TCP/IP stack context
95  NetInterface *serverInterface; ///<Network-facing interface
96  uint_t numClientInterfaces; ///<Number of client-facing interfaces
97  NetInterface *clientInterfaces[DHCPV6_RELAY_MAX_CLIENT_INTERFACES]; ///<Client-facing interfaces
98  Ipv6Addr serverIpAddr; ///<Address to be used when relaying messages to the server
99  Socket *serverSocket; ///<Socket that handles the network-facing interface
100  Socket *clientSockets[DHCPV6_RELAY_MAX_CLIENT_INTERFACES]; ///<Sockets that handle client-facing interfaces
101  SocketEventDesc eventDesc[DHCPV6_RELAY_MAX_CLIENT_INTERFACES]; ///<The events the application is interested in
102  bool_t running; ///<Operational state of the DHCPv6 relay agent
103  bool_t stop; ///<Stop request
104  OsEvent event; ///<Event object used to poll the sockets
105  OsTaskParameters taskParams; ///<Task parameters
106  OsTaskId taskId; ///<Task identifier
107  uint8_t buffer[DHCPV6_MAX_MSG_SIZE]; ///<Scratch buffer to store DHCPv6 messages
109 
110 
111 //DHCPv6 relay agent related functions
113 
115  const Dhcpv6RelaySettings *settings);
116 
119 
120 void dhcpv6RelayTask(Dhcpv6RelayContext *context);
121 
123 
124 //C++ guard
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif
bool_t running
Operational state of the DHCPv6 relay agent.
Definition: dhcpv6_relay.h:102
#define DHCPV6_RELAY_MAX_CLIENT_INTERFACES
Definition: dhcpv6_relay.h:59
#define NetContext
Definition: net.h:36
int bool_t
Definition: compiler_port.h:63
OsTaskParameters task
Task parameters.
Definition: dhcpv6_relay.h:80
void dhcpv6RelayGetDefaultSettings(Dhcpv6RelaySettings *settings)
Initialize settings with default values.
Definition: dhcpv6_relay.c:55
Definitions common to DHCPv6 client, server and relay agent.
Event object.
error_t dhcpv6RelayStop(Dhcpv6RelayContext *context)
Stop DHCPv6 relay agent.
Definition: dhcpv6_relay.c:258
Ipv6Addr
Definition: ipv6.h:280
void dhcpv6RelayTask(Dhcpv6RelayContext *context)
DHCPv6 relay agent task.
Definition: dhcpv6_relay.c:307
Structure describing socket events.
Definition: socket.h:433
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:81
NetInterface * serverInterface
Network-facing interface.
Definition: dhcpv6_relay.h:95
#define DHCPV6_MAX_MSG_SIZE
Definition: dhcpv6_common.h:44
error_t dhcpv6RelayStart(Dhcpv6RelayContext *context)
Start DHCPv6 relay agent.
Definition: dhcpv6_relay.c:175
OsEvent event
Event object used to poll the sockets.
Definition: dhcpv6_relay.h:104
uint_t numClientInterfaces
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:96
error_t
Error codes.
Definition: error.h:43
#define NetInterface
Definition: net.h:40
NetContext * netContext
TCP/IP stack context.
Definition: dhcpv6_relay.h:94
uint_t numClientInterfaces
Number of client-facing interfaces.
Definition: dhcpv6_relay.h:82
Task parameters.
void dhcpv6RelayDeinit(Dhcpv6RelayContext *context)
Release DHCP relay agent context.
Definition: dhcpv6_relay.c:377
DHCPv6 relay agent settings.
Definition: dhcpv6_relay.h:79
bool_t stop
Stop request.
Definition: dhcpv6_relay.h:103
DHCPv6 relay agent context.
Definition: dhcpv6_relay.h:93
#define Socket
Definition: socket.h:36
Socket API.
OsTaskParameters taskParams
Task parameters.
Definition: dhcpv6_relay.h:105
thread_t * OsTaskId
Task identifier.
Ipv6Addr serverIpAddr
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:84
unsigned int uint_t
Definition: compiler_port.h:57
Ipv6Addr serverIpAddr
Address to be used when relaying messages to the server.
Definition: dhcpv6_relay.h:98
Socket * serverSocket
Socket that handles the network-facing interface.
Definition: dhcpv6_relay.h:99
OsTaskId taskId
Task identifier.
Definition: dhcpv6_relay.h:106
error_t dhcpv6RelayInit(Dhcpv6RelayContext *context, const Dhcpv6RelaySettings *settings)
DHCPv6 relay agent initialization.
Definition: dhcpv6_relay.c:90