summaryrefslogtreecommitdiff
path: root/cleopatre/application/igmp_snoopd/inc/internal.h
blob: da0afc8af2c1ee4cfca70fc76d65df6c1ee054ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef INTERNAL_H
#define INTERNAL_H

#include <net/ethernet.h>

#include "libspid.h"

#include "data_struct.h"
#include "igmp_common.h"

/* Maximum number of multicast groups */
#define MCAST_GROUP_MAX_NB      12

/* Maxium number of members in a multicast group */
#define MCAST_MEMBER_MAX_NB     1

/** IGMP V3 metrics */
struct v3_metrics
{
    /** The last time a query was seen */
    time_t last_query_time;

    /** Robustess variable. See RFC.*/
    uint8_t robustness_variable;

    /** Query interval. See RFC. */
    duration_sec_t query_interval;

    /** Query response interval. See RFC. */
    duration_sec_t query_response_interval;

    /** Group Membership Interval. See RFC. */
    duration_sec_t group_membership_interval;

    /* Other Querier present Interval. See RFC. */
    duration_sec_t other_querier_present_interval;
};

/** An entry in the multicast info. An entry represents information about
 *  a groups and its members. */
struct multicast_info_entry
{
    /** The group MAC address. */
    unsigned char group_mac_addr[LIBSPID_MAC_BIN_LEN];

    /** The number of members in the group. */
    size_t member_count;

    /** The addresses of the members in the group. */
    unsigned char members_mac_addr[MCAST_MEMBER_MAX_NB][LIBSPID_MAC_BIN_LEN];
};

/** The content of the multicast info. */
struct multicast_info
{
    /** The number of entries (groups). */
    size_t entry_count;

    /** The entries. */
    struct multicast_info_entry entries[MCAST_GROUP_MAX_NB];
};

/** The context */
struct context
{
    /** The head of the list containing the multicast groups. */
    struct list_head_groups groups_head;

    /** The IGMP v3 metrics. */
    struct v3_metrics metrics;

    /** The last multicast info entries written to a file. */
    struct multicast_info *multicast_info;
};

/**
 * Init the part handling IGMP v3.
 * \param  metrics  The IGMP v3 metrics.
 */
void init_v3 (struct v3_metrics *metrics);

/**
 * Initialize a multicast_info structure.
 * \param  mcast_info  The structure to initialize.
 */
void init_multicast_info (struct multicast_info *mcast_info);

/**
 * Process a v1 query.
 */
void process_v1_query ();

/**
 * Process a v1 report.
 */
void process_v1_report ();

/**
 * Process a v2 query.
 */
void process_v2_query ();

/**
 * Process a v2 report.
 */
void process_v2_report();

/**
 * Process a v2 leave report.
 */
void process_v2_leave ();

/**
 * Process a v3 query.
 * \param  ctx  The context.
 * \param  start  The start of the query.
 * \param  msg_end  The end of the message(containing the report).
 */
void process_v3_query (struct context *ctx,
                       const unsigned char *start,
                       const unsigned char *msg_end);

/**
 * Process a v3 report.
 * \param  ctx  The context.
 * \param  host_eth_addr  The Ethernet MAC address of the host that sent the report.
 * \param  start  The start of the report.
 * \param  msg_end  The end of the message(containing the report).
 */
void process_v3_report (struct context *ctx,
                        const unsigned char host_eth_addr[ETH_ALEN],
                        const unsigned char *start,
                        const unsigned char * msg_end);

/**
 * Remove the inactive groups and members.
 * \param  ctx  The context.
 */
void del_inactive (struct context *ctx);

/**
 * Dump the info related to handling IGMP v3.
 * \param  metrics  The IGMP v3 metrics.
 */
void dump_info_v3 (const struct v3_metrics *metrics);

#endif /* INTERNAL_H */