igmp_router.h
Go to the documentation of this file.
1 /**
2  * @file igmp_router.h
3  * @brief IGMP router
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2022 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.1.4
29  **/
30 
31 #ifndef _IGMP_ROUTER_H
32 #define _IGMP_ROUTER_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "igmp/igmp_common.h"
37 
38 //IGMP router support
39 #ifndef IGMP_ROUTER_SUPPORT
40  #define IGMP_ROUTER_SUPPORT DISABLED
41 #elif (IGMP_ROUTER_SUPPORT != ENABLED && IGMP_ROUTER_SUPPORT != DISABLED)
42  #error IGMP_ROUTER_SUPPORT parameter is not valid
43 #endif
44 
45 //Forward declaration of DhcpClientContext structure
46 struct _IgmpRouterContext;
47 #define IgmpRouterContext struct _IgmpRouterContext
48 
49 //C++ guard
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 /**
56  * @brief IGMP versions
57  **/
58 
59 typedef enum
60 {
63  IGMP_VERSION_3 = 3
65 
66 
67 /**
68  * @brief IGMP router states
69  **/
70 
71 typedef enum
72 {
77 
78 
79 /**
80  * @brief Multicast group states
81  **/
82 
83 typedef enum
84 {
90 
91 
92 /**
93  * @brief Add multicast route callback
94  **/
95 
98 
99 
100 /**
101  * @brief Delete multicast route callback
102  **/
103 
106 
107 
108 /**
109  * @brief Multicast group
110  **/
111 
112 typedef struct
113 {
114  IgmpRouterGroupState state; ///<Multicast group state
115  Ipv4Addr addr; ///<Multicast group address
116  uint_t lastMemberQueryCount; ///<Number of Group-Specific Queries to be sent
117  NetTimer timer; ///<Timer for the group membership
118  NetTimer v1HostTimer; ///<IGMPv1 Host timer
119  NetTimer retransmitTimer; ///<Retransmit timer for the group membership
121 
122 
123 /**
124  * @brief IGMP router settings
125  **/
126 
127 typedef struct
128 {
129  NetInterface *interface; ///<Underlying network interface
130  IgmpVersion version; ///<IGMP version
131  uint_t numGroups; ///<Maximum number of multicast groups
132  IgmpRouterGroup *groups; ///<Multicast groups
133  IgmpRouterAddMcastRouteCallback addMcastRouteCallback; ///<Add multicast route callback
136 
137 
138 /**
139  * @brief IGMP router context
140  **/
141 
143 {
144  NetInterface *interface; ///<The primary interface on an attached network
145  IgmpVersion version; ///<IGMP version
146  uint_t numGroups; ///<Maximum number of multicast groups
147  IgmpRouterGroup *groups; ///<Multicast groups
148  IgmpRouterAddMcastRouteCallback addMcastRouteCallback; ///<Add multicast route callback
150  bool_t running; ///<IGMP router operation state
151  IgmpRouterState state; ///<IGMP router state
152  uint_t startupQueryCount; ///<Number of General Queries to be sent on startup
153  NetTimer generalQueryTimer; ///<General Query timer
154  NetTimer otherQuerierPresentTimer; ///<Other Querier Present timer
155 };
156 
157 
158 //IGMP router related functions
160 
162  const IgmpRouterSettings *settings);
163 
166 
167 void igmpRouterTick(IgmpRouterContext *context);
168 void igmpRouterFsm(IgmpRouterContext *context);
170 
171 //C++ guard
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif
unsigned int uint_t
Definition: compiler_port.h:45
int bool_t
Definition: compiler_port.h:48
error_t
Error codes.
Definition: error.h:43
Definitions common to IGMP host, router and snooping switch.
Ipv4Addr groupAddr
Definition: igmp_common.h:169
void igmpRouterGetDefaultSettings(IgmpRouterSettings *settings)
Initialize settings with default values.
Definition: igmp_router.c:58
error_t igmpRouterStart(IgmpRouterContext *context)
Start IGMP router.
Definition: igmp_router.c:149
error_t igmpRouterStop(IgmpRouterContext *context)
Stop IGMP router.
Definition: igmp_router.c:183
error_t igmpRouterInit(IgmpRouterContext *context, const IgmpRouterSettings *settings)
IGMP router initialization.
Definition: igmp_router.c:87
IgmpRouterGroupState
Multicast group states.
Definition: igmp_router.h:84
@ IGMP_ROUTER_GROUP_STATE_V1_MEMBERS_PRESENT
Definition: igmp_router.h:87
@ IGMP_ROUTER_GROUP_STATE_CHECKING_MEMBERSHIP
Definition: igmp_router.h:88
@ IGMP_ROUTER_GROUP_STATE_MEMBERS_PRESENT
Definition: igmp_router.h:86
@ IGMP_ROUTER_GROUP_STATE_NO_MEMBERS_PRESENT
Definition: igmp_router.h:85
#define IgmpRouterContext
Definition: igmp_router.h:47
IgmpRouterState
IGMP router states.
Definition: igmp_router.h:72
@ IGMP_ROUTER_STATE_QUERIER
Definition: igmp_router.h:74
@ IGMP_ROUTER_STATE_INIT
Definition: igmp_router.h:73
@ IGMP_ROUTER_STATE_NON_QUERIER
Definition: igmp_router.h:75
void(* IgmpRouterAddMcastRouteCallback)(IgmpRouterContext *context, Ipv4Addr groupAddr, NetInterface *interface)
Add multicast route callback.
Definition: igmp_router.h:96
void(* IgmpRouterDeleteMcastRouteCallback)(IgmpRouterContext *context, Ipv4Addr groupAddr, NetInterface *interface)
Delete multicast route callback.
Definition: igmp_router.h:104
void igmpRouterFsm(IgmpRouterContext *context)
IGMP router state machine.
Definition: igmp_router.c:245
void igmpRouterTick(IgmpRouterContext *context)
IGMP router timer handler.
Definition: igmp_router.c:220
IgmpVersion
IGMP versions.
Definition: igmp_router.h:60
@ IGMP_VERSION_1
Definition: igmp_router.h:61
@ IGMP_VERSION_3
Definition: igmp_router.h:63
@ IGMP_VERSION_2
Definition: igmp_router.h:62
void igmpRouterGroupFsm(IgmpRouterContext *context, IgmpRouterGroup *group)
IGMP group state machine.
Definition: igmp_router.c:316
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:239
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
IGMP router context.
Definition: igmp_router.h:143
IgmpRouterGroup * groups
Multicast groups.
Definition: igmp_router.h:147
bool_t running
IGMP router operation state.
Definition: igmp_router.h:150
uint_t startupQueryCount
Number of General Queries to be sent on startup.
Definition: igmp_router.h:152
uint_t numGroups
Maximum number of multicast groups.
Definition: igmp_router.h:146
IgmpVersion version
IGMP version.
Definition: igmp_router.h:145
NetTimer generalQueryTimer
General Query timer.
Definition: igmp_router.h:153
IgmpRouterAddMcastRouteCallback addMcastRouteCallback
Add multicast route callback.
Definition: igmp_router.h:148
IgmpRouterState state
IGMP router state.
Definition: igmp_router.h:151
NetTimer otherQuerierPresentTimer
Other Querier Present timer.
Definition: igmp_router.h:154
NetInterface * interface
The primary interface on an attached network.
Definition: igmp_router.h:144
IgmpRouterDeleteMcastRouteCallback deleteMcastRouteCallback
Delete multicast route callback.
Definition: igmp_router.h:149
Multicast group.
Definition: igmp_router.h:113
uint_t lastMemberQueryCount
Number of Group-Specific Queries to be sent.
Definition: igmp_router.h:116
IgmpRouterGroupState state
Multicast group state.
Definition: igmp_router.h:114
NetTimer v1HostTimer
IGMPv1 Host timer.
Definition: igmp_router.h:118
NetTimer timer
Timer for the group membership.
Definition: igmp_router.h:117
NetTimer retransmitTimer
Retransmit timer for the group membership.
Definition: igmp_router.h:119
Ipv4Addr addr
Multicast group address.
Definition: igmp_router.h:115
IGMP router settings.
Definition: igmp_router.h:128
IgmpRouterGroup * groups
Multicast groups.
Definition: igmp_router.h:132
uint_t numGroups
Maximum number of multicast groups.
Definition: igmp_router.h:131
IgmpVersion version
IGMP version.
Definition: igmp_router.h:130
IgmpRouterAddMcastRouteCallback addMcastRouteCallback
Add multicast route callback.
Definition: igmp_router.h:133
NetInterface * interface
Underlying network interface.
Definition: igmp_router.h:129
IgmpRouterDeleteMcastRouteCallback deleteMcastRouteCallback
Delete multicast route callback.
Definition: igmp_router.h:134
Timer.
Definition: net_misc.h:172
uint16_t group
Definition: tls13_misc.h:206