blob: 95e60bf2109fa570bbbfe28506bb75e5217684c3 [file] [log] [blame]
Everton Marques871dbcf2009-08-11 15:43:05 -03001/*
2 PIM for Quagga
3 Copyright (C) 2008 Everton da Silva Marques
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 MA 02110-1301 USA
19
20 $QuaggaId: $Format:%an, %ai, %h$ $
21*/
22
23#ifndef PIM_IGMP_H
24#define PIM_IGMP_H
25
26#include <netinet/in.h>
27
28#include <zebra.h>
29#include "vty.h"
30#include "linklist.h"
31
32/*
33 The following sizes are likely to support
34 any message sent within local MTU.
35*/
36#define PIM_IGMP_BUFSIZE_READ (20000)
37#define PIM_IGMP_BUFSIZE_WRITE (20000)
38
39#define PIM_IGMP_MEMBERSHIP_QUERY (0x11)
40#define PIM_IGMP_V1_MEMBERSHIP_REPORT (0x12)
41#define PIM_IGMP_V2_MEMBERSHIP_REPORT (0x16)
42#define PIM_IGMP_V2_LEAVE_GROUP (0x17)
43#define PIM_IGMP_V3_MEMBERSHIP_REPORT (0x22)
44
45#define IGMP_V3_REPORT_HEADER_SIZE (8)
46#define IGMP_V3_GROUP_RECORD_MIN_SIZE (8)
47#define IGMP_V3_MSG_MIN_SIZE (IGMP_V3_REPORT_HEADER_SIZE + \
48 IGMP_V3_GROUP_RECORD_MIN_SIZE)
49#define IGMP_V12_MSG_SIZE (8)
50
51#define IGMP_V3_GROUP_RECORD_TYPE_OFFSET (0)
52#define IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET (1)
53#define IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET (2)
54#define IGMP_V3_GROUP_RECORD_GROUP_OFFSET (4)
55#define IGMP_V3_GROUP_RECORD_SOURCE_OFFSET (8)
56
57/* RFC 3376: 8.1. Robustness Variable - Default: 2 */
Leonard Herve236b0152009-08-11 15:51:52 -030058#define IGMP_DEFAULT_ROBUSTNESS_VARIABLE (2)
Everton Marques871dbcf2009-08-11 15:43:05 -030059
60/* RFC 3376: 8.2. Query Interval - Default: 125 seconds */
Leonard Herve236b0152009-08-11 15:51:52 -030061#define IGMP_GENERAL_QUERY_INTERVAL (125)
Everton Marques871dbcf2009-08-11 15:43:05 -030062
63/* RFC 3376: 8.3. Query Response Interval - Default: 100 deciseconds */
Leonard Herve236b0152009-08-11 15:51:52 -030064#define IGMP_QUERY_MAX_RESPONSE_TIME_DSEC (100)
65
66/* RFC 3376: 8.8. Last Member Query Interval - Default: 10 deciseconds */
67#define IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC (10)
Everton Marques871dbcf2009-08-11 15:43:05 -030068
69struct igmp_join {
70 struct in_addr group_addr;
71 struct in_addr source_addr;
72 int sock_fd;
73};
74
75struct igmp_sock {
76 int fd;
77 struct interface *interface;
78 struct in_addr ifaddr;
79 time_t sock_creation;
80
81 struct thread *t_igmp_read; /* read: IGMP sockets */
82 struct thread *t_igmp_query_timer; /* timer: issue IGMP general queries */
83 struct thread *t_other_querier_timer; /* timer: other querier present */
84
85 int querier_query_interval; /* QQI */
86 int querier_robustness_variable; /* QRV */
87 int startup_query_count;
88
89 struct list *igmp_group_list; /* list of struct igmp_group */
90};
91
92struct igmp_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
93 struct in_addr ifaddr);
94struct igmp_sock *igmp_sock_lookup_by_fd(struct list *igmp_sock_list,
95 int fd);
96struct igmp_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
97 struct in_addr ifaddr,
98 struct interface *ifp);
99void igmp_sock_delete(struct igmp_sock *igmp);
100void igmp_sock_free(struct igmp_sock *igmp);
101
102int pim_igmp_packet(struct igmp_sock *igmp, char *buf, size_t len);
103
104void pim_igmp_general_query_on(struct igmp_sock *igmp);
105void pim_igmp_general_query_off(struct igmp_sock *igmp);
106void pim_igmp_other_querier_timer_on(struct igmp_sock *igmp);
107void pim_igmp_other_querier_timer_off(struct igmp_sock *igmp);
108
109#define IGMP_SOURCE_MASK_FORWARDING (1 << 0)
110#define IGMP_SOURCE_MASK_DELETE (1 << 1)
111#define IGMP_SOURCE_MASK_SEND (1 << 2)
112#define IGMP_SOURCE_TEST_FORWARDING(flags) ((flags) & IGMP_SOURCE_MASK_FORWARDING)
113#define IGMP_SOURCE_TEST_DELETE(flags) ((flags) & IGMP_SOURCE_MASK_DELETE)
114#define IGMP_SOURCE_TEST_SEND(flags) ((flags) & IGMP_SOURCE_MASK_SEND)
115#define IGMP_SOURCE_DO_FORWARDING(flags) ((flags) |= IGMP_SOURCE_MASK_FORWARDING)
116#define IGMP_SOURCE_DO_DELETE(flags) ((flags) |= IGMP_SOURCE_MASK_DELETE)
117#define IGMP_SOURCE_DO_SEND(flags) ((flags) |= IGMP_SOURCE_MASK_SEND)
118#define IGMP_SOURCE_DONT_FORWARDING(flags) ((flags) &= ~IGMP_SOURCE_MASK_FORWARDING)
119#define IGMP_SOURCE_DONT_DELETE(flags) ((flags) &= ~IGMP_SOURCE_MASK_DELETE)
120#define IGMP_SOURCE_DONT_SEND(flags) ((flags) &= ~IGMP_SOURCE_MASK_SEND)
121
122struct igmp_source {
123 struct in_addr source_addr;
124 struct thread *t_source_timer;
125 struct igmp_group *source_group; /* back pointer */
126 time_t source_creation;
127 uint32_t source_flags;
128 struct channel_oil *source_channel_oil;
129
130 /*
131 RFC 3376: 6.6.3.2. Building and Sending Group and Source Specific Queries
132 */
133 int source_query_retransmit_count;
134};
135
136struct igmp_group {
137 /*
138 RFC 3376: 6.2.2. Definition of Group Timers
139
140 The group timer is only used when a group is in EXCLUDE mode and it
141 represents the time for the *filter-mode* of the group to expire and
142 switch to INCLUDE mode.
143 */
144 struct thread *t_group_timer;
145
146 /* Shared between group-specific and
147 group-and-source-specific retransmissions */
148 struct thread *t_group_query_retransmit_timer;
149
150 /* Counter exclusive for group-specific retransmissions
151 (not used by group-and-source-specific retransmissions,
152 since sources have their counters) */
153 int group_specific_query_retransmit_count;
154
155 struct in_addr group_addr;
156 int group_filtermode_isexcl; /* 0=INCLUDE, 1=EXCLUDE */
157 struct list *group_source_list; /* list of struct igmp_source */
158 time_t group_creation;
159 struct igmp_sock *group_igmp_sock; /* back pointer */
160 int64_t last_igmp_v1_report_dsec;
161 int64_t last_igmp_v2_report_dsec;
162};
163
164struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp,
165 struct in_addr group_addr,
166 const char *ifname);
167
168void igmp_group_delete_empty_include(struct igmp_group *group);
169
170void igmp_startup_mode_on(struct igmp_sock *igmp);
171
172void igmp_group_timer_on(struct igmp_group *group,
173 long interval_msec, const char *ifname);
174
175#endif /* PIM_IGMP_H */