OpenSDN source code
gmp_host.h
Go to the documentation of this file.
1 /* $Id: gmp_host.h 362048 2010-02-09 00:25:11Z builder $
2  *
3  * gmp_host.h - External definitions for gmp_host
4  *
5  * Dave Katz, March 2008
6  *
7  * Copyright (c) 2008, Juniper Networks, Inc.
8  * Copyright Contributors to the OpenSDN project
9  * All rights reserved.
10  *
11  * This file contains the external definitions for host-side GMP. It should
12  * be included by code calling the host side.
13  */
14 
15 #ifndef __GMP_HOST_H__
16 #define __GMP_HOST_H__
17 
18 
19 /*
20  * Overview
21  *
22  * The gmph_* files define the host side of IGMP/MLD. This part of the
23  * protocol initiates requests for listening to multicast groups and
24  * responds to incoming Query packets from the router side.
25  *
26  * This code supports multiple instances. An instance is simply a
27  * grouping of interfaces and clients accessing those interfaces; an
28  * interface can be bound to one and only one instance, as is a
29  * client. The use of multiple instances may or may not be desirable
30  * depending on the circumstances of the application; combining or
31  * separating instances has no semantic impact from the standpoint of
32  * this code.
33  *
34  * Within an instance, one or more interfaces are bound to the instance; as
35  * outlined above, a set of interfaces semantically defines an instance.
36  * Interfaces are completely independent of one another. An interface
37  * is described by a gmpx_intf_id, which is an opaque type defined in the
38  * application's gmpx_environment.h file. This code neither knows nor
39  * cares about the actual data type (common values are pointers to an
40  * application data structure or an IFL index); the only requirement is
41  * that the data type is scalar and that the value is unique per interface.
42  * I/O is performed by passing the interface ID to and from the application's
43  * supplied I/O routines.
44  *
45  * Also within an instance, one or more clients are bound. A client is a
46  * single requestor of multicast traffic; the most typical binding is to
47  * a single user process. This code combines the possibly-overlapping
48  * requests from multiple clients to create the GMP interface state in such
49  * a way as to guarantee that requested traffic will be delivered. Note that
50  * this means that filtering of received traffic to a client, based on the
51  * actual request from that client, must still take place in the data path
52  * (since one client may include an (S,G) and another may exclude it, for
53  * example.)
54  *
55  * Clients make Listen calls to request or cancel reception of multicast groups.
56  *
57  *
58  * Application call flow
59  *
60  * When an application wants to use GMPH services, it must first create an
61  * instance with gmph_create_instance(). This returns an opaque instance ID
62  * that is used in subsequent calls.
63  *
64  * At least one client is then created with gmph_register().
65  *
66  * Interfaces are then bound to the instance with gmph_attach_intf().
67  * Interfaces and clients may be created in any order.
68  *
69  * Clients then may request or cancel multicast groups by calling gmph_listen()
70  * for the appropriate interface and group. Of course, a client may not
71  * call gmph_listen() for an interface until that interface is bound to the
72  * instance.
73  *
74  *
75  * When tearing down services, clients and interfaces may be torn down
76  * in any order. gmph_detach() is used to get rid of a client. In
77  * this case, gmph_listen() calls to clean up previously requested
78  * groups are unnecessary, and appropriate Leave messages will be
79  * enqueued for transmission.
80  *
81  * gmph_detach_intf() will unceremoniously destroy an interface, along with
82  * any group state bound to it. Any pending Leave messages will be
83  * discarded.
84  *
85  * If a graceful shutdown of an interface is desired,
86  * gmph_detach_intf_soft() can be called instead. The caller supplies
87  * a pointer to a callback routine, and once all pending messages are
88  * sent on the interface, GMP will call back to notify the application
89  * that the interface is being destroyed, and then immediately unbinds
90  * the interface. A subsequent call to gmph_attach_intf(), prior to
91  * the callback, will reanimate the interface and not shut it down,
92  * and no callback will be made. Similarly, a call to
93  * gmph_detach_intf() will unceremoniously and immediately unbind the
94  * interface (and there will be no callback).
95  *
96  * It is up to the application to cause Leaves to be sent for any
97  * joined groups by calling gmph_listen() for each of them (or by
98  * calling gmph_leave_all_groups()) prior to calling
99  * gmph_detach_intf_soft(). Otherwise, any Joins previously sent will
100  * not be countermanded.
101  *
102  * gmph_destroy_instance() is used to get rid of the instance when it
103  * is no longer needed. It will unceremoniously destroy all interface
104  * and client state, and will discard any packets pending
105  * transmission, so it can be called to single-handedly clean up
106  * everything. On the other hand, if a graceful shutdown is required,
107  * gmph_detach_intf_soft() should be called for each interface, and
108  * the application should wait for all callbacks, before destroying
109  * the intstance.
110  *
111  *
112  * Detailed calls
113  *
114  * gmph_create_instance(proto, context)
115  *
116  * Creates an instance, returning an instance ID that is used in subsequent
117  * calls. The context value is an opaque value that is passed through
118  * in timer creation calls.
119  *
120  * gmph_register(instance_id)
121  *
122  * Creates a client, returning a client ID that is used in subsequent calls.
123  *
124  * gmph_attach_intf(instance_id, intf_id)
125  *
126  * Binds an interface to an instance. Once the client is created and the
127  * interface is bound to the instance, listen requests can be made.
128  *
129  * gmph_listen(client_id, intf_id, group, filter_mode, sources)
130  *
131  * Requests or cancels reception of a (*,G) or multiple (S,G)s. A Leave is
132  * signaled by a listen request with filter mode Include and no sources;
133  * all other combinations are joins. The request must be idempotent for
134  * the group; in other words, the group state for the client is set to the
135  * contents of the request. If an additional source is to be added for an
136  * existing group, for instance, all requested sources must be listed on
137  * the request.
138  *
139  * gmph_detach_intf(instance_id, intf_id)
140  *
141  * Unbinds an interface from the instance. All state on the interface
142  * is destroyed immediately, and no Leave messages will be sent.
143  *
144  * gmph_detach_intf_soft(instance_id, intf_id, callback, context)
145  *
146  * Gracefully unbinds an interface from the instance. Once all
147  * necessary packets have been sent, the callback is made (with the
148  * opaque context passed by the caller) and the interface is
149  * destroyed immediately thereafter. If gmph_attach_intf() is called
150  * after this routine, but prior to the callback, it will keep the
151  * interface in existence and no callback will be made. Any enqueued
152  * packets will still be sent.
153  *
154  * gmph_detach(client_id)
155  *
156  * Detaches a client from the instance. Any active Listen requests
157  * from the client will be dealt with appropriately (enqueueing Leave
158  * messages if the client being destroyed is the only one interested in
159  * those groups.)
160  *
161  * gmph_destroy_instance(instance_id)
162  *
163  * Destroys the instance and all state contained therein, immediately. This
164  * will clean up all clients, interfaces, and listen requests, but will not
165  * send appropriate Leave messages.
166  *
167  * gmph_set_intf_version(instance_id, intf_id, version)
168  *
169  * Sets the maximum version number supported by the host. This is generally
170  * not called, since the code will adapt to the version sent by the querier
171  * automatically. Setting the version caps it to the specified value.
172  *
173  * gmph_set_intf_passive(instance_id, intf_id, passive)
174  *
175  * Sets the passive state of the interface to the specified value. If an
176  * interface is passive, the code will not send Report messages under any
177  * circumstances. This is primarily for the benefit of IGMP snooping
178  * switches, which pass host-generated Reports transparently but must keep
179  * aggregated host state on the upstream interfaces.
180  *
181  * gmph_send_intf_groups(instance_id, intf_id)
182  *
183  * Enqueues all group state on the specified interface for transmission.
184  * This is typically used for refreshing upstream state in proxy switches.
185  *
186  * gmph_leave_all_groups(client_id, intf_id)
187  *
188  * Removes all groups listened to on the specified interface by the
189  * specified client. This is equivalent to calling gmph_listen(client_id,
190  * intf_id, group, INCLUDE, NULL) for each group originally listend
191  * go, and will resut in Leaves being sent for these groups if no other
192  * client is listening to them.
193  *
194  * gmph_intf_has_channel(instance_id, intf_id, source, group, exact)
195  *
196  * Returns TRUE if the specified (S,G) has been requested on the
197  * interface, or FALSE if not. If exact matching is requested, it will
198  * return TRUE for a (*,G) call only if a (*,G) request has been made;
199  * if inexact, it will return TRUE for a (*,G) call if one or more (S,G)s
200  * for the same group have been requested.
201  */
202 
203 
204 /*
205  * Soft interface detach callback
206  *
207  * This typedef defines the callback passed as a parameter to
208  * gmph_detach_intf_soft(). This routine will be called after any necessary
209  * packets are transmitted. The interface will cease to exist immediately
210  * after the callback is made.
211  */
212 typedef void (*gmph_soft_detach_callback)(gmp_proto proto,
213  gmpx_intf_id intf_id,
214  void *context);
215 
216 /*
217  * External references
218  */
220 extern void gmph_detach(gmp_client_id client_id);
221 extern int gmph_listen(gmp_client_id client_id, gmpx_intf_id intf_id,
222  const u_int8_t *group, gmp_filter_mode filter_mode,
223  gmp_addr_thread *addr_thread);
224 extern gmp_instance_id gmph_create_instance(gmp_proto proto, void *context);
225 extern void gmph_destroy_instance(gmp_instance_id instance_id);
226 extern int gmph_set_intf_version(gmp_instance_id instance_id,
227  gmpx_intf_id intf_id, u_int version);
228 extern int gmph_attach_intf(gmp_instance_id instance_id, gmpx_intf_id intf_id);
229 extern int gmph_detach_intf(gmp_instance_id instance_id, gmpx_intf_id intf_id);
230 extern int gmph_detach_intf_soft(gmp_instance_id instance_id,
231  gmpx_intf_id intf_id,
232  gmph_soft_detach_callback callback,
233  void *context);
234 extern int gmph_leave_all_groups(gmp_client_id client_id, gmpx_intf_id intf_id);
235 extern void gmph_send_intf_groups(gmp_instance_id instance_id,
236  gmpx_intf_id intf_id);
237 extern void gmph_set_intf_passive(gmp_instance_id instance_id,
238  gmpx_intf_id intf_id, boolean passive);
239 extern boolean gmph_intf_has_channel(gmp_instance_id instance_id,
240  gmpx_intf_id intf_id,
241  const u_int8_t *source_addr,
242  const u_int8_t *group_addr,
243  boolean exact);
244 
245 #endif /* __GMP_HOST_H__ */
void * gmp_client_id
Definition: gmp.h:40
gmp_filter_mode
Definition: gmp.h:67
void * gmp_instance_id
Definition: gmp.h:33
gmp_proto
Definition: gmp.h:46
int gmph_attach_intf(gmp_instance_id instance_id, gmpx_intf_id intf_id)
gmp_instance_id gmph_create_instance(gmp_proto proto, void *context)
void gmph_detach(gmp_client_id client_id)
void gmph_destroy_instance(gmp_instance_id instance_id)
int gmph_detach_intf(gmp_instance_id instance_id, gmpx_intf_id intf_id)
void gmph_send_intf_groups(gmp_instance_id instance_id, gmpx_intf_id intf_id)
int gmph_listen(gmp_client_id client_id, gmpx_intf_id intf_id, const u_int8_t *group, gmp_filter_mode filter_mode, gmp_addr_thread *addr_thread)
gmp_client_id gmph_register(gmp_instance_id instance_id)
int gmph_set_intf_version(gmp_instance_id instance_id, gmpx_intf_id intf_id, u_int version)
boolean gmph_intf_has_channel(gmp_instance_id instance_id, gmpx_intf_id intf_id, const u_int8_t *source_addr, const u_int8_t *group_addr, boolean exact)
int gmph_leave_all_groups(gmp_client_id client_id, gmpx_intf_id intf_id)
void(* gmph_soft_detach_callback)(gmp_proto proto, gmpx_intf_id intf_id, void *context)
Definition: gmp_host.h:212
void gmph_set_intf_passive(gmp_instance_id instance_id, gmpx_intf_id intf_id, boolean passive)
int gmph_detach_intf_soft(gmp_instance_id instance_id, gmpx_intf_id intf_id, gmph_soft_detach_callback callback, void *context)