~ubuntu-branches/ubuntu/precise/libpgm/precise

« back to all changes in this revision

Viewing changes to openpgm/pgm/pgmMIB.c

  • Committer: Bazaar Package Importer
  • Author(s): Gabriel de Perthuis
  • Date: 2011-04-07 16:48:52 UTC
  • Revision ID: james.westby@ubuntu.com-20110407164852-8uamem42ojeptj6l
Tags: upstream-5.1.116~dfsg
ImportĀ upstreamĀ versionĀ 5.1.116~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Note: this file originally auto-generated by mib2c using
 
3
 *        : mib2c.notify.conf,v 5.3 2004/04/15 12:29:19 dts12 Exp $
 
4
 */
 
5
 
 
6
#include <net-snmp/net-snmp-config.h>
 
7
#include <net-snmp/net-snmp-includes.h>
 
8
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
9
 
 
10
#include <impl/i18n.h>
 
11
#include <impl/framework.h>
 
12
#include <impl/receiver.h>
 
13
#include <impl/socket.h>
 
14
 
 
15
#include "pgm/snmp.h"
 
16
#include "impl/pgmMIB.h"
 
17
#include "impl/pgmMIB_columns.h"
 
18
#include "impl/pgmMIB_enums.h"
 
19
 
 
20
 
 
21
//#define PGMMIB_DEBUG
 
22
 
 
23
 
 
24
/* locals */
 
25
 
 
26
struct pgm_snmp_data_context_t {
 
27
        pgm_sock_t*     sock;
 
28
        pgm_peer_t*     peer;
 
29
};
 
30
 
 
31
typedef struct pgm_snmp_data_context_t pgm_snmp_data_context_t;
 
32
 
 
33
struct pgm_snmp_context_t {
 
34
        pgm_slist_t*    list;
 
35
        pgm_list_t*     node;
 
36
        int             index;          /* table index */
 
37
        unsigned        instance;       /* unique number per node */
 
38
        pgm_snmp_data_context_t data_context;
 
39
};
 
40
 
 
41
typedef struct pgm_snmp_context_t pgm_snmp_context_t;
 
42
 
 
43
 
 
44
static const oid snmptrap_oid[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0};
 
45
 
 
46
 
 
47
/* functions */
 
48
 
 
49
static int initialize_table_pgmSourceTable(void);
 
50
static Netsnmp_Node_Handler pgmSourceTable_handler;
 
51
static Netsnmp_First_Data_Point pgmSourceTable_get_first_data_point;
 
52
static Netsnmp_Next_Data_Point pgmSourceTable_get_next_data_point;
 
53
static Netsnmp_Free_Loop_Context pgmSourceTable_free_loop_context;
 
54
 
 
55
static int initialize_table_pgmSourceConfigTable(void);
 
56
static Netsnmp_Node_Handler pgmSourceConfigTable_handler;
 
57
static Netsnmp_First_Data_Point pgmSourceConfigTable_get_first_data_point;
 
58
static Netsnmp_Next_Data_Point pgmSourceConfigTable_get_next_data_point;
 
59
static Netsnmp_Free_Loop_Context pgmSourceConfigTable_free_loop_context;
 
60
 
 
61
static int initialize_table_pgmSourcePerformanceTable(void);
 
62
static Netsnmp_Node_Handler pgmSourcePerformanceTable_handler;
 
63
static Netsnmp_First_Data_Point pgmSourcePerformanceTable_get_first_data_point;
 
64
static Netsnmp_Next_Data_Point pgmSourcePerformanceTable_get_next_data_point;
 
65
static Netsnmp_Free_Loop_Context pgmSourcePerformanceTable_free_loop_context;
 
66
 
 
67
static int initialize_table_pgmReceiverTable(void);
 
68
static Netsnmp_Node_Handler pgmReceiverTable_handler;
 
69
static Netsnmp_First_Data_Point pgmReceiverTable_get_first_data_point;
 
70
static Netsnmp_Next_Data_Point pgmReceiverTable_get_next_data_point;
 
71
static Netsnmp_Free_Loop_Context pgmReceiverTable_free_loop_context;
 
72
 
 
73
static int initialize_table_pgmReceiverConfigTable(void);
 
74
static Netsnmp_Node_Handler pgmReceiverConfigTable_handler;
 
75
static Netsnmp_First_Data_Point pgmReceiverConfigTable_get_first_data_point;
 
76
static Netsnmp_Next_Data_Point pgmReceiverConfigTable_get_next_data_point;
 
77
static Netsnmp_Free_Loop_Context pgmReceiverConfigTable_free_loop_context;
 
78
 
 
79
static int initialize_table_pgmReceiverPerformanceTable(void);
 
80
static Netsnmp_Node_Handler pgmReceiverPerformanceTable_handler;
 
81
static Netsnmp_First_Data_Point pgmReceiverPerformanceTable_get_first_data_point;
 
82
static Netsnmp_Next_Data_Point pgmReceiverPerformanceTable_get_next_data_point;
 
83
static Netsnmp_Free_Loop_Context pgmReceiverPerformanceTable_free_loop_context;
 
84
 
 
85
PGM_GNUC_INTERNAL
 
86
bool
 
87
pgm_mib_init (
 
88
        pgm_error_t**   error
 
89
        )
 
90
{
 
91
        if (MIB_REGISTERED_OK != initialize_table_pgmSourceTable()) {
 
92
                pgm_set_error (error,
 
93
                             PGM_ERROR_DOMAIN_SNMP,
 
94
                             PGM_ERROR_FAILED,
 
95
                             _("pgmSourceTable registration: see SNMP log for further details."));
 
96
                return FALSE;
 
97
        }
 
98
        if (MIB_REGISTERED_OK != initialize_table_pgmSourceConfigTable()) {
 
99
                pgm_set_error (error,
 
100
                             PGM_ERROR_DOMAIN_SNMP,
 
101
                             PGM_ERROR_FAILED,
 
102
                             _("pgmSourceConfigTable registration: see SNMP log for further details."));
 
103
                return FALSE;
 
104
        }
 
105
        if (MIB_REGISTERED_OK != initialize_table_pgmSourcePerformanceTable()) {
 
106
                pgm_set_error (error,
 
107
                             PGM_ERROR_DOMAIN_SNMP,
 
108
                             PGM_ERROR_FAILED,
 
109
                             _("pgmSourcePerformanceTable registration: see SNMP log for further details."));
 
110
                return FALSE;
 
111
        }
 
112
        if (MIB_REGISTERED_OK != initialize_table_pgmReceiverTable()) {
 
113
                pgm_set_error (error,
 
114
                             PGM_ERROR_DOMAIN_SNMP,
 
115
                             PGM_ERROR_FAILED,
 
116
                             _("pgmReceiverTable registration: see SNMP log for further details."));
 
117
                return FALSE;
 
118
        }
 
119
        if (MIB_REGISTERED_OK != initialize_table_pgmReceiverConfigTable()) {
 
120
                pgm_set_error (error,
 
121
                             PGM_ERROR_DOMAIN_SNMP,
 
122
                             PGM_ERROR_FAILED,
 
123
                             _("pgmReceiverConfigTable registration: see SNMP log for further details."));
 
124
                return FALSE;
 
125
        }
 
126
        if (MIB_REGISTERED_OK != initialize_table_pgmReceiverPerformanceTable()) {
 
127
                pgm_set_error (error,
 
128
                             PGM_ERROR_DOMAIN_SNMP,
 
129
                             PGM_ERROR_FAILED,
 
130
                             _("pgmReceiverPerformanceTable registration: see SNMP log for further details."));
 
131
                return FALSE;
 
132
        }
 
133
 
 
134
        return TRUE;
 
135
}
 
136
 
 
137
/*
 
138
 * pgmSourceTable
 
139
 *
 
140
 * returns MIB_REGISTERED_OK on success, failures include:
 
141
 *      MIB_REGISTRATION_FAILED
 
142
 *      MIB_DUPLICATE_REGISTRATION
 
143
 *      SNMPERR_GENERR
 
144
 */
 
145
 
 
146
static
 
147
int
 
148
initialize_table_pgmSourceTable (void)
 
149
{
 
150
        pgm_debug ("initialize_table_pgmSourceTable ()");
 
151
 
 
152
        static const oid pgmSourceTable_oid[] = {1,3,6,1,3,112,1,2,100,2};
 
153
        netsnmp_table_registration_info* table_info = NULL;
 
154
        netsnmp_iterator_info* iinfo = NULL;
 
155
        netsnmp_handler_registration* reg = NULL;
 
156
 
 
157
        reg = netsnmp_create_handler_registration ("pgmSourceTable",    pgmSourceTable_handler,
 
158
                                                   pgmSourceTable_oid,  OID_LENGTH( pgmSourceTable_oid ),
 
159
                                                   HANDLER_CAN_RONLY);
 
160
        if (NULL == reg)
 
161
                goto error;
 
162
 
 
163
        table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
 
164
        if (NULL == table_info)
 
165
                goto error;
 
166
 
 
167
        table_info->min_column = COLUMN_PGMSOURCESOURCEADDRESS;
 
168
        table_info->max_column = COLUMN_PGMSOURCESOURCEPORTNUMBER;
 
169
 
 
170
        netsnmp_table_helper_add_indexes (table_info,
 
171
                                          ASN_OCTET_STR,  /* index: pgmSourceGlobalId */
 
172
                                          ASN_UNSIGNED,  /* index: pgmSourceSourcePort */
 
173
                                          0);
 
174
 
 
175
        iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
 
176
        if (NULL == iinfo)
 
177
                goto error;
 
178
 
 
179
        iinfo->get_first_data_point     = pgmSourceTable_get_first_data_point;
 
180
        iinfo->get_next_data_point      = pgmSourceTable_get_next_data_point;
 
181
        iinfo->free_loop_context_at_end = pgmSourceTable_free_loop_context;
 
182
        iinfo->table_reginfo            = table_info;
 
183
 
 
184
        return netsnmp_register_table_iterator (reg, iinfo);
 
185
 
 
186
error:
 
187
        if (table_info && table_info->indexes)          /* table_data_free_func() is internal */
 
188
                snmp_free_var (table_info->indexes);
 
189
        SNMP_FREE( table_info );
 
190
        SNMP_FREE( iinfo );
 
191
        netsnmp_handler_registration_free (reg);
 
192
 
 
193
        return -1;
 
194
}
 
195
 
 
196
/* called for first row of data in SNMP table
 
197
 *
 
198
 * goal is to cache all the relevant data for subsequent get_next_data_point (row) calls in my_loop_context,
 
199
 * optionally returns my_data_context.
 
200
 *
 
201
 * returns answer or NULL
 
202
 */
 
203
 
 
204
static
 
205
netsnmp_variable_list*
 
206
pgmSourceTable_get_first_data_point(
 
207
        void**                  my_loop_context,        /* valid through one query of multiple "data points" */
 
208
        void**                  my_data_context,        /* answer blob which is passed to handler() */
 
209
        netsnmp_variable_list*  put_index_data,         /* answer */
 
210
        netsnmp_iterator_info*  mydata                  /* iinfo on init() */
 
211
        )
 
212
{
 
213
/* pre-conditions */
 
214
        pgm_assert (NULL != my_loop_context);
 
215
        pgm_assert (NULL != my_data_context);
 
216
        pgm_assert (NULL != put_index_data);
 
217
        pgm_assert (NULL != mydata);
 
218
 
 
219
        pgm_debug ("pgmSourceTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
220
                (const void*)my_loop_context,
 
221
                (const void*)my_data_context,
 
222
                (const void*)put_index_data,
 
223
                (const void*)mydata);
 
224
 
 
225
        pgm_rwlock_reader_lock (&pgm_sock_list_lock);
 
226
 
 
227
        if (NULL == pgm_sock_list) {
 
228
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
229
                return NULL;
 
230
        }
 
231
 
 
232
/* create our own context for this SNMP loop */
 
233
        pgm_snmp_context_t* context = pgm_new0 (pgm_snmp_context_t, 1);
 
234
        context->list = pgm_sock_list;
 
235
        *my_loop_context = context;
 
236
 
 
237
/* pass on for generic row access */
 
238
        return pgmSourceTable_get_next_data_point (my_loop_context, my_data_context, put_index_data, mydata);
 
239
}
 
240
 
 
241
static
 
242
netsnmp_variable_list*
 
243
pgmSourceTable_get_next_data_point(
 
244
        void**                  my_loop_context,
 
245
        void**                  my_data_context,
 
246
        netsnmp_variable_list*  put_index_data,
 
247
        netsnmp_iterator_info*  mydata
 
248
        )
 
249
{
 
250
/* pre-conditions */
 
251
        pgm_assert (NULL != my_loop_context);
 
252
        pgm_assert (NULL != my_data_context);
 
253
        pgm_assert (NULL != put_index_data);
 
254
        pgm_assert (NULL != mydata);
 
255
 
 
256
        pgm_debug ("pgmSourceTable_get_next_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
257
                (const void*)my_loop_context,
 
258
                (const void*)my_data_context,
 
259
                (const void*)put_index_data,
 
260
                (const void*)mydata);
 
261
 
 
262
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)*my_loop_context;
 
263
        netsnmp_variable_list *idx = put_index_data;
 
264
 
 
265
        if (NULL == context->list)
 
266
                return NULL;
 
267
 
 
268
        pgm_sock_t* sock = context->list->data;
 
269
 
 
270
/* pgmSourceGlobalId */
 
271
        char gsi[ PGM_GSISTRLEN ];
 
272
        pgm_gsi_print_r (&sock->tsi.gsi, gsi, sizeof(gsi));
 
273
        snmp_set_var_typed_value (idx, ASN_OCTET_STR, (const u_char*)&gsi, strlen (gsi));
 
274
        idx = idx->next_variable;
 
275
 
 
276
/* pgmSourceSourcePort */
 
277
        const unsigned sport = ntohs (sock->tsi.sport);
 
278
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&sport, sizeof(sport));
 
279
 
 
280
        *my_data_context = sock;
 
281
        context->list = context->list->next;
 
282
 
 
283
        return put_index_data;
 
284
}
 
285
 
 
286
static
 
287
void
 
288
pgmSourceTable_free_loop_context (
 
289
        void*                   my_loop_context,
 
290
        netsnmp_iterator_info*  mydata
 
291
        )
 
292
{
 
293
/* pre-conditions */
 
294
        pgm_assert (NULL != my_loop_context);
 
295
        pgm_assert (NULL != mydata);
 
296
 
 
297
        pgm_debug ("pgmSourceTable_free_loop_context (my_loop_context:%p mydata:%p)",
 
298
                (const void*)my_loop_context,
 
299
                (const void*)mydata);
 
300
 
 
301
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)my_loop_context;
 
302
        pgm_free (context);
 
303
        my_loop_context = NULL;
 
304
 
 
305
        pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
306
}
 
307
 
 
308
static
 
309
int
 
310
pgmSourceTable_handler (
 
311
        netsnmp_mib_handler*            handler,
 
312
        netsnmp_handler_registration*   reginfo,
 
313
        netsnmp_agent_request_info*     reqinfo,
 
314
        netsnmp_request_info*           requests
 
315
        )
 
316
{
 
317
/* pre-conditions */
 
318
        pgm_assert (NULL != handler);
 
319
        pgm_assert (NULL != reginfo);
 
320
        pgm_assert (NULL != reqinfo);
 
321
        pgm_assert (NULL != requests);
 
322
 
 
323
        pgm_debug ("pgmSourceTable_handler (handler:%p reginfo:%p reqinfo:%p requests:%p)",
 
324
                (const void*)handler,
 
325
                (const void*)reginfo,
 
326
                (const void*)reqinfo,
 
327
                (const void*)requests);
 
328
        
 
329
        switch (reqinfo->mode) {
 
330
 
 
331
/* Read-support (also covers GetNext requests) */
 
332
 
 
333
        case MODE_GET:
 
334
                for (netsnmp_request_info* request = requests;
 
335
                     request;
 
336
                     request = request->next)
 
337
                {
 
338
                        const pgm_sock_t* sock = (pgm_sock_t*)netsnmp_extract_iterator_context (request);
 
339
                        if (NULL == sock) {
 
340
                                netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE);
 
341
                                continue;
 
342
                        }
 
343
 
 
344
                        netsnmp_variable_list *var = request->requestvb;
 
345
                        netsnmp_table_request_info* table_info = netsnmp_extract_table_info (request);
 
346
                        if (NULL == table_info) {
 
347
                                snmp_log (LOG_ERR, "pgmSourceTable_handler: empty table request info.\n");
 
348
                                continue;
 
349
                        }
 
350
 
 
351
                        switch (table_info->colnum) {
 
352
 
 
353
                        case COLUMN_PGMSOURCESOURCEADDRESS:
 
354
                                {
 
355
                                        struct sockaddr_in s4;
 
356
                                        if (AF_INET == sock->send_gsr.gsr_source.ss_family)
 
357
                                                memcpy (&s4, &sock->send_gsr.gsr_source, sizeof(s4));
 
358
                                        else
 
359
                                                memset (&s4, 0, sizeof(s4));
 
360
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
361
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
362
                                                                  sizeof(struct in_addr) );
 
363
                                }
 
364
                                break;
 
365
 
 
366
                        case COLUMN_PGMSOURCEGROUPADDRESS:
 
367
                                {
 
368
                                        struct sockaddr_in s4;
 
369
                                        if (AF_INET == sock->send_gsr.gsr_group.ss_family)
 
370
                                                memcpy (&s4, &sock->send_gsr.gsr_group, sizeof(s4));
 
371
                                        else
 
372
                                                memset (&s4, 0, sizeof(s4));
 
373
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
374
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
375
                                                                  sizeof(struct in_addr) );
 
376
                                }
 
377
                                break;
 
378
 
 
379
                        case COLUMN_PGMSOURCEDESTPORT:
 
380
                                {
 
381
                                        const unsigned dport = ntohs (sock->dport);
 
382
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
383
                                                                  (const u_char*)&dport, sizeof(dport) );
 
384
                                }
 
385
                                break;
 
386
 
 
387
/* copy index[0] */
 
388
                        case COLUMN_PGMSOURCESOURCEGSI:
 
389
                                snmp_set_var_typed_value (var, ASN_OCTET_STR,
 
390
                                                          (const u_char*)table_info->indexes->val.string,
 
391
                                                          table_info->indexes->val_len);
 
392
                                break;
 
393
 
 
394
/* copy index[1] */
 
395
                        case COLUMN_PGMSOURCESOURCEPORTNUMBER:
 
396
                                snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
397
                                                          (const u_char*)table_info->indexes->next_variable->val.integer,
 
398
                                                          table_info->indexes->next_variable->val_len);
 
399
                        
 
400
                                break;
 
401
 
 
402
                        default:
 
403
                                snmp_log (LOG_ERR, "pgmSourceTable_handler: unknown column.\n");
 
404
                                break;
 
405
                        }
 
406
                }
 
407
                break;
 
408
 
 
409
        case MODE_SET_RESERVE1:
 
410
        default:
 
411
                snmp_log (LOG_ERR, "pgmSourceTable_handler: unsupported mode.\n");
 
412
                break;
 
413
 
 
414
        }
 
415
 
 
416
        return SNMP_ERR_NOERROR;
 
417
}
 
418
 
 
419
/*
 
420
 * pgmSourceConfigTable
 
421
 *
 
422
 */
 
423
 
 
424
static
 
425
int
 
426
initialize_table_pgmSourceConfigTable(void)
 
427
{
 
428
        pgm_debug ("initialize_table_pgmSourceConfigTable ()");
 
429
 
 
430
        static const oid pgmSourceConfigTable_oid[] = {1,3,6,1,3,112,1,2,100,3};
 
431
        netsnmp_table_registration_info* table_info = NULL;
 
432
        netsnmp_iterator_info* iinfo = NULL;
 
433
        netsnmp_handler_registration* reg = NULL;
 
434
 
 
435
        reg = netsnmp_create_handler_registration ("pgmSourceConfigTable",      pgmSourceConfigTable_handler,
 
436
                                                   pgmSourceConfigTable_oid,    OID_LENGTH( pgmSourceConfigTable_oid ),
 
437
                                                   HANDLER_CAN_RONLY);
 
438
        if (NULL == reg)
 
439
                goto error;
 
440
 
 
441
        table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
 
442
        if (NULL == table_info)
 
443
                goto error;
 
444
 
 
445
        table_info->min_column = COLUMN_PGMSOURCETTL;
 
446
        table_info->max_column = COLUMN_PGMSOURCESPMPATHADDRESS;
 
447
 
 
448
        netsnmp_table_helper_add_indexes (table_info,
 
449
                                          ASN_OCTET_STR,  /* index: pgmSourceConfigGlobalId */
 
450
                                          ASN_UNSIGNED,  /* index: pgmSourceConfigSourcePort */
 
451
                                          0);
 
452
 
 
453
        iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
 
454
        if (NULL == iinfo)
 
455
                goto error;
 
456
 
 
457
        iinfo->get_first_data_point     = pgmSourceConfigTable_get_first_data_point;
 
458
        iinfo->get_next_data_point      = pgmSourceConfigTable_get_next_data_point;
 
459
        iinfo->free_loop_context_at_end = pgmSourceConfigTable_free_loop_context;
 
460
        iinfo->table_reginfo            = table_info;
 
461
 
 
462
        return netsnmp_register_table_iterator (reg, iinfo);
 
463
 
 
464
error:
 
465
        if (table_info && table_info->indexes)          /* table_data_free_func() is internal */
 
466
                snmp_free_var (table_info->indexes);
 
467
        SNMP_FREE( table_info );
 
468
        SNMP_FREE( iinfo );
 
469
        netsnmp_handler_registration_free (reg);
 
470
 
 
471
        return -1;
 
472
}
 
473
 
 
474
/* called for first row of data in SNMP table
 
475
 *
 
476
 * goal is to cache all the relevant data for subsequent get_next_data_point (row) calls in my_loop_context,
 
477
 * optionally returns my_data_context.
 
478
 *
 
479
 * returns answer or NULL
 
480
 */
 
481
 
 
482
static
 
483
netsnmp_variable_list*
 
484
pgmSourceConfigTable_get_first_data_point(
 
485
        void**                  my_loop_context,        /* valid through one query of multiple "data points" */
 
486
        void**                  my_data_context,        /* answer blob which is passed to handler() */
 
487
        netsnmp_variable_list*  put_index_data,         /* answer */
 
488
        netsnmp_iterator_info*  mydata                  /* iinfo on init() */
 
489
        )
 
490
{
 
491
/* pre-conditions */
 
492
        pgm_assert (NULL != my_loop_context);
 
493
        pgm_assert (NULL != my_data_context);
 
494
        pgm_assert (NULL != put_index_data);
 
495
        pgm_assert (NULL != mydata);
 
496
 
 
497
        pgm_debug ("pgmSourceConfigTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
498
                (const void*)my_loop_context,
 
499
                (const void*)my_data_context,
 
500
                (const void*)put_index_data,
 
501
                (const void*)mydata);
 
502
 
 
503
        pgm_rwlock_reader_lock (&pgm_sock_list_lock);
 
504
 
 
505
        if (NULL == pgm_sock_list) {
 
506
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
507
                return NULL;
 
508
        }
 
509
 
 
510
/* create our own context for this SNMP loop */
 
511
        pgm_snmp_context_t* context = pgm_new0 (pgm_snmp_context_t, 1);
 
512
        context->list = pgm_sock_list;
 
513
        *my_loop_context = context;
 
514
 
 
515
/* pass on for generic row access */
 
516
        return pgmSourceConfigTable_get_next_data_point (my_loop_context, my_data_context, put_index_data, mydata);
 
517
}
 
518
 
 
519
static
 
520
netsnmp_variable_list*
 
521
pgmSourceConfigTable_get_next_data_point(
 
522
        void**                  my_loop_context,
 
523
        void**                  my_data_context,
 
524
        netsnmp_variable_list*  put_index_data,
 
525
        netsnmp_iterator_info*  mydata
 
526
        )
 
527
{
 
528
/* pre-conditions */
 
529
        pgm_assert (NULL != my_loop_context);
 
530
        pgm_assert (NULL != my_data_context);
 
531
        pgm_assert (NULL != put_index_data);
 
532
        pgm_assert (NULL != mydata);
 
533
 
 
534
        pgm_debug ("pgmSourceConfigTable_get_next_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
535
                (const void*)my_loop_context,
 
536
                (const void*)my_data_context,
 
537
                (const void*)put_index_data,
 
538
                (const void*)mydata);
 
539
 
 
540
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)*my_loop_context;
 
541
        netsnmp_variable_list *idx = put_index_data;
 
542
 
 
543
        if (NULL == context->list)
 
544
                return NULL;
 
545
 
 
546
        pgm_sock_t* sock = context->list->data;
 
547
 
 
548
/* pgmSourceGlobalId */
 
549
        char gsi[ PGM_GSISTRLEN ];
 
550
        pgm_gsi_print_r (&sock->tsi.gsi, gsi, sizeof(gsi));
 
551
        snmp_set_var_typed_value (idx, ASN_OCTET_STR, (const u_char*)&gsi, strlen (gsi));
 
552
        idx = idx->next_variable;
 
553
 
 
554
/* pgmSourceSourcePort */
 
555
        const unsigned sport = ntohs (sock->tsi.sport);
 
556
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&sport, sizeof(sport));
 
557
 
 
558
        *my_data_context = sock;
 
559
        context->list = context->list->next;
 
560
 
 
561
        return put_index_data;
 
562
}
 
563
 
 
564
static
 
565
void
 
566
pgmSourceConfigTable_free_loop_context (
 
567
        void*                   my_loop_context,
 
568
        netsnmp_iterator_info*  mydata
 
569
        )
 
570
{
 
571
/* pre-conditions */
 
572
        pgm_assert (NULL != my_loop_context);
 
573
        pgm_assert (NULL != mydata);
 
574
 
 
575
        pgm_debug ("pgmSourceConfigTable_free_loop_context (my_loop_context:%p mydata:%p)",
 
576
                (const void*)my_loop_context,
 
577
                (const void*)mydata);
 
578
 
 
579
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)my_loop_context;
 
580
        pgm_free (context);
 
581
        my_loop_context = NULL;
 
582
 
 
583
        pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
584
}
 
585
 
 
586
static
 
587
int
 
588
pgmSourceConfigTable_handler (
 
589
        netsnmp_mib_handler*            handler,
 
590
        netsnmp_handler_registration*   reginfo,
 
591
        netsnmp_agent_request_info*     reqinfo,
 
592
        netsnmp_request_info*           requests
 
593
        )
 
594
{
 
595
/* pre-conditions */
 
596
        pgm_assert (NULL != handler);
 
597
        pgm_assert (NULL != reginfo);
 
598
        pgm_assert (NULL != reqinfo);
 
599
        pgm_assert (NULL != requests);
 
600
 
 
601
        pgm_debug ("pgmSourceConfigTable_handler (handler:%p reginfo:%p reqinfo:%p requests:%p)",
 
602
                (const void*)handler,
 
603
                (const void*)reginfo,
 
604
                (const void*)reqinfo,
 
605
                (const void*)requests);
 
606
 
 
607
        switch (reqinfo->mode) {
 
608
 
 
609
/* Read-support (also covers GetNext requests) */
 
610
 
 
611
        case MODE_GET:
 
612
                for (netsnmp_request_info* request = requests;
 
613
                     request;
 
614
                     request = request->next)
 
615
                {
 
616
                        const pgm_sock_t* sock = (pgm_sock_t*)netsnmp_extract_iterator_context (request);
 
617
                        if (NULL == sock) {
 
618
                                netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE);
 
619
                                continue;
 
620
                        }
 
621
 
 
622
                        netsnmp_variable_list *var = request->requestvb;
 
623
                        netsnmp_table_request_info* table_info = netsnmp_extract_table_info (request);
 
624
                        if (NULL == table_info) {
 
625
                                snmp_log (LOG_ERR, "pgmSourceTable_handler: empty table request info.\n");
 
626
                                continue;
 
627
                        }
 
628
 
 
629
                        switch (table_info->colnum) {
 
630
 
 
631
                        case COLUMN_PGMSOURCETTL:
 
632
                                {
 
633
                                        const unsigned hops = sock->hops;
 
634
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
635
                                                                  (const u_char*)&hops, sizeof(hops) );
 
636
                                }
 
637
                                break;
 
638
 
 
639
                        case COLUMN_PGMSOURCEADVMODE:
 
640
                                {
 
641
                                        const unsigned adv_mode = 0 == sock->adv_mode ? PGMSOURCEADVMODE_TIME : PGMSOURCEADVMODE_DATA;
 
642
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
643
                                                                  (const u_char*)&adv_mode, sizeof(adv_mode) );
 
644
                                }
 
645
                                break;
 
646
 
 
647
/* FIXED: pgmSourceLateJoin = disable(2) */
 
648
                        case COLUMN_PGMSOURCELATEJOIN:
 
649
                                {
 
650
                                        const unsigned late_join = PGMSOURCELATEJOIN_DISABLE;
 
651
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
652
                                                                  (const u_char*)&late_join, sizeof(late_join) );
 
653
                                }
 
654
                                break;
 
655
 
 
656
                        case COLUMN_PGMSOURCETXWMAXRTE:
 
657
                                {
 
658
                                        const unsigned txw_max_rte = sock->txw_max_rte;
 
659
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
660
                                                                  (const u_char*)&txw_max_rte, sizeof(txw_max_rte) );
 
661
                                }
 
662
                                break;
 
663
 
 
664
                        case COLUMN_PGMSOURCETXWSECS:
 
665
                                {
 
666
                                        const unsigned txw_secs = sock->txw_secs;
 
667
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
668
                                                                  (const u_char*)&txw_secs, sizeof(txw_secs) );
 
669
                                }
 
670
                                break;
 
671
 
 
672
/* FIXED: TXW_ADV_SECS = 0 */
 
673
                        case COLUMN_PGMSOURCETXWADVSECS:
 
674
                                {
 
675
                                        const unsigned txw_adv_secs = 0;
 
676
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
677
                                                                  (const u_char*)&txw_adv_secs, sizeof(txw_adv_secs) );
 
678
                                }
 
679
                                break;
 
680
 
 
681
/* FIXED: pgmSourceAdvIvl = TXW_ADV_SECS * 1000 = 0 */
 
682
                        case COLUMN_PGMSOURCEADVIVL:
 
683
                                {
 
684
                                        const unsigned adv_ivl = 0;
 
685
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
686
                                                                  (const u_char*)&adv_ivl, sizeof(adv_ivl) );
 
687
                                }
 
688
                                break;
 
689
 
 
690
                        case COLUMN_PGMSOURCESPMIVL:
 
691
                                {
 
692
                                        const unsigned spm_ivl = pgm_to_msecs (sock->spm_ambient_interval);
 
693
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
694
                                                                  (const u_char*)&spm_ivl, sizeof(spm_ivl) );
 
695
                                }
 
696
                                break;
 
697
 
 
698
/* TODO: IHB_MIN */
 
699
                        case COLUMN_PGMSOURCESPMHEARTBEATIVLMIN:
 
700
                                {
 
701
                                        const unsigned ihb_min = 0;
 
702
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
703
                                                                  (const u_char*)&ihb_min, sizeof(ihb_min) );
 
704
                                }
 
705
                                break;
 
706
 
 
707
/* TODO: IHB_MAX */
 
708
                        case COLUMN_PGMSOURCESPMHEARTBEATIVLMAX:
 
709
                                {
 
710
                                        const unsigned ihb_max = 0;
 
711
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
712
                                                                  (const u_char*)&ihb_max, sizeof(ihb_max) );
 
713
                                }
 
714
                                break;
 
715
 
 
716
/* NAK_BO_IVL */
 
717
                        case COLUMN_PGMSOURCERDATABACKOFFIVL:
 
718
                                {
 
719
                                        const unsigned nak_bo_ivl = pgm_to_msecs (sock->nak_bo_ivl);
 
720
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
721
                                                                  (const u_char*)&nak_bo_ivl, sizeof(nak_bo_ivl) );
 
722
                                }
 
723
                                break;
 
724
 
 
725
/* FIXED: pgmSourceFEC = disabled(1) */
 
726
                        case COLUMN_PGMSOURCEFEC:
 
727
                                {
 
728
                                        const unsigned fec = (sock->use_ondemand_parity || sock->use_proactive_parity) ? 1 : 0;
 
729
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
730
                                                                  (const u_char*)&fec, sizeof(fec) );
 
731
                                }
 
732
                                break;
 
733
 
 
734
/* FIXED: pgmSourceFECTransmissionGrpSize = 0 */
 
735
                        case COLUMN_PGMSOURCEFECTRANSMISSIONGRPSIZE:
 
736
                                {
 
737
                                        const unsigned fec_tgs = sock->rs_k;
 
738
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
739
                                                                  (const u_char*)&fec_tgs, sizeof(fec_tgs) );
 
740
                                }
 
741
                                break;
 
742
 
 
743
/* FIXED: pgmSourceFECProactiveParitySize = 0 */
 
744
                        case COLUMN_PGMSOURCEFECPROACTIVEPARITYSIZE:
 
745
                                {
 
746
                                        const unsigned fec_paps = sock->rs_proactive_h;
 
747
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
748
                                                                  (const u_char*)&fec_paps, sizeof(fec_paps) );
 
749
                                }
 
750
                                break;
 
751
 
 
752
/* IPv6 not supported */
 
753
                        case COLUMN_PGMSOURCESPMPATHADDRESS:
 
754
                                {
 
755
                                        struct sockaddr_in s4;
 
756
                                        if (AF_INET == sock->recv_gsr[0].gsr_source.ss_family)
 
757
                                                memcpy (&s4, &sock->recv_gsr[0].gsr_source, sizeof(s4));
 
758
                                        else
 
759
                                                memset (&s4, 0, sizeof(s4));
 
760
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
761
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
762
                                                                  sizeof(struct in_addr) );
 
763
                                }
 
764
                                break;
 
765
 
 
766
                        default:
 
767
                                snmp_log (LOG_ERR, "pgmSourceConfigTable_handler: unknown column.\n");
 
768
                                break;
 
769
                        }
 
770
                }
 
771
                break;
 
772
 
 
773
        case MODE_SET_RESERVE1:
 
774
        default:
 
775
                snmp_log (LOG_ERR, "pgmSourceConfigTable_handler: unsupported mode.\n");
 
776
                break;
 
777
 
 
778
        }
 
779
 
 
780
        return SNMP_ERR_NOERROR;
 
781
}
 
782
 
 
783
/*
 
784
 * pgmSourcePerformanceTable
 
785
 */
 
786
 
 
787
static
 
788
int
 
789
initialize_table_pgmSourcePerformanceTable (void)
 
790
{
 
791
        pgm_debug ("initialize_table_pgmSourcePerformanceTable ()");
 
792
 
 
793
        static const oid pgmSourcePerformanceTable_oid[] = {1,3,6,1,3,112,1,2,100,4};
 
794
        netsnmp_table_registration_info* table_info = NULL;
 
795
        netsnmp_iterator_info* iinfo = NULL;
 
796
        netsnmp_handler_registration* reg = NULL;
 
797
 
 
798
        reg = netsnmp_create_handler_registration ("pgmSourcePerformanceTable",         pgmSourcePerformanceTable_handler,
 
799
                                                   pgmSourcePerformanceTable_oid,       OID_LENGTH( pgmSourcePerformanceTable_oid ),
 
800
                                                   HANDLER_CAN_RONLY);
 
801
        if (NULL == reg)
 
802
                goto error;
 
803
 
 
804
        table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
 
805
        if (NULL == table_info)
 
806
                goto error;
 
807
 
 
808
        table_info->min_column = COLUMN_PGMSOURCEDATABYTESSENT;
 
809
        table_info->max_column = COLUMN_PGMSOURCENNAKERRORS;
 
810
 
 
811
        netsnmp_table_helper_add_indexes (table_info,
 
812
                                          ASN_OCTET_STR,  /* index: pgmSourceGlobalId */
 
813
                                          ASN_UNSIGNED,  /* index: pgmSourceSourcePort */
 
814
                                          0);
 
815
 
 
816
        iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
 
817
        if (NULL == iinfo)
 
818
                goto error;
 
819
 
 
820
        iinfo->get_first_data_point     = pgmSourcePerformanceTable_get_first_data_point;
 
821
        iinfo->get_next_data_point      = pgmSourcePerformanceTable_get_next_data_point;
 
822
        iinfo->free_loop_context_at_end = pgmSourcePerformanceTable_free_loop_context;
 
823
        iinfo->table_reginfo            = table_info;
 
824
 
 
825
        return netsnmp_register_table_iterator (reg, iinfo);
 
826
 
 
827
error:
 
828
        if (table_info && table_info->indexes)          /* table_data_free_func() is internal */
 
829
                snmp_free_var (table_info->indexes);
 
830
        SNMP_FREE( table_info );
 
831
        SNMP_FREE( iinfo );
 
832
        netsnmp_handler_registration_free (reg);
 
833
 
 
834
        return -1;
 
835
}
 
836
 
 
837
/* called for first row of data in SNMP table
 
838
 *
 
839
 * goal is to cache all the relevant data for subsequent get_next_data_point (row) calls in my_loop_context,
 
840
 * optionally returns my_data_context.
 
841
 *
 
842
 * returns answer or NULL
 
843
 */
 
844
 
 
845
static
 
846
netsnmp_variable_list*
 
847
pgmSourcePerformanceTable_get_first_data_point (
 
848
        void**                  my_loop_context,        /* valid through one query of multiple "data points" */
 
849
        void**                  my_data_context,        /* answer blob which is passed to handler() */
 
850
        netsnmp_variable_list*  put_index_data,         /* answer */
 
851
        netsnmp_iterator_info*  mydata                  /* iinfo on init() */
 
852
        )
 
853
{
 
854
/* pre-conditions */
 
855
        pgm_assert (NULL != my_loop_context);
 
856
        pgm_assert (NULL != my_data_context);
 
857
        pgm_assert (NULL != put_index_data);
 
858
        pgm_assert (NULL != mydata);
 
859
 
 
860
        pgm_debug ("pgmSourcePerformanceTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
861
                (const void*)my_loop_context,
 
862
                (const void*)my_data_context,
 
863
                (const void*)put_index_data,
 
864
                (const void*)mydata);
 
865
 
 
866
        pgm_rwlock_reader_lock (&pgm_sock_list_lock);
 
867
 
 
868
        if (NULL == pgm_sock_list) {
 
869
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
870
                return NULL;
 
871
        }
 
872
 
 
873
/* create our own context for this SNMP loop */
 
874
        pgm_snmp_context_t* context = pgm_new0 (pgm_snmp_context_t, 1);
 
875
        context->list = pgm_sock_list;
 
876
        *my_loop_context = context;
 
877
 
 
878
/* pass on for generic row access */
 
879
        return pgmSourcePerformanceTable_get_next_data_point (my_loop_context, my_data_context, put_index_data, mydata);
 
880
}
 
881
 
 
882
static
 
883
netsnmp_variable_list*
 
884
pgmSourcePerformanceTable_get_next_data_point (
 
885
        void**                  my_loop_context,
 
886
        void**                  my_data_context,
 
887
        netsnmp_variable_list*  put_index_data,
 
888
        netsnmp_iterator_info*  mydata
 
889
        )
 
890
{
 
891
/* pre-conditions */
 
892
        pgm_assert (NULL != my_loop_context);
 
893
        pgm_assert (NULL != my_data_context);
 
894
        pgm_assert (NULL != put_index_data);
 
895
        pgm_assert (NULL != mydata);
 
896
 
 
897
        pgm_debug ("pgmSourcePerformanceTable_get_next_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
898
                (const void*)my_loop_context,
 
899
                (const void*)my_data_context,
 
900
                (const void*)put_index_data,
 
901
                (const void*)mydata);
 
902
 
 
903
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)*my_loop_context;
 
904
        netsnmp_variable_list *idx = put_index_data;
 
905
 
 
906
        if (NULL == context->list)
 
907
                return NULL;
 
908
 
 
909
        pgm_sock_t* sock = context->list->data;
 
910
 
 
911
/* pgmSourceGlobalId */
 
912
        char gsi[ PGM_GSISTRLEN ];
 
913
        pgm_gsi_print_r (&sock->tsi.gsi, gsi, sizeof(gsi));
 
914
        snmp_set_var_typed_value (idx, ASN_OCTET_STR, (const u_char*)&gsi, strlen (gsi));
 
915
        idx = idx->next_variable;
 
916
 
 
917
/* pgmSourceSourcePort */
 
918
        const unsigned sport = ntohs (sock->tsi.sport);
 
919
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&sport, sizeof(sport));
 
920
 
 
921
        *my_data_context = sock;
 
922
        context->list = context->list->next;
 
923
 
 
924
        return put_index_data;
 
925
}
 
926
 
 
927
static
 
928
void
 
929
pgmSourcePerformanceTable_free_loop_context (
 
930
        void*                   my_loop_context,
 
931
        netsnmp_iterator_info*  mydata
 
932
        )
 
933
{
 
934
/* pre-conditions */
 
935
        pgm_assert (NULL != my_loop_context);
 
936
        pgm_assert (NULL != mydata);
 
937
 
 
938
        pgm_debug ("pgmPerformanceSourceTable_free_loop_context (my_loop_context:%p mydata:%p)",
 
939
                (const void*)my_loop_context,
 
940
                (const void*)mydata);
 
941
 
 
942
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)my_loop_context;
 
943
        pgm_free (context);
 
944
        my_loop_context = NULL;
 
945
 
 
946
        pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
947
}
 
948
 
 
949
static
 
950
int
 
951
pgmSourcePerformanceTable_handler (
 
952
        netsnmp_mib_handler*            handler,
 
953
        netsnmp_handler_registration*   reginfo,
 
954
        netsnmp_agent_request_info*     reqinfo,
 
955
        netsnmp_request_info*           requests
 
956
        )
 
957
{
 
958
/* pre-conditions */
 
959
        pgm_assert (NULL != handler);
 
960
        pgm_assert (NULL != reginfo);
 
961
        pgm_assert (NULL != reqinfo);
 
962
        pgm_assert (NULL != requests);
 
963
 
 
964
        pgm_debug ("pgmSourcePerformanceTable_handler (handler:%p reginfo:%p reqinfo:%p requests:%p)",
 
965
                (const void*)handler,
 
966
                (const void*)reginfo,
 
967
                (const void*)reqinfo,
 
968
                (const void*)requests);
 
969
 
 
970
        switch (reqinfo->mode) {
 
971
 
 
972
/* Read-support (also covers GetNext requests) */
 
973
 
 
974
        case MODE_GET:
 
975
                for (netsnmp_request_info* request = requests;
 
976
                     request;
 
977
                     request = request->next)
 
978
                {
 
979
                        const pgm_sock_t* sock = (pgm_sock_t*)netsnmp_extract_iterator_context (request);
 
980
                        if (NULL == sock) {
 
981
                                netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE);
 
982
                                continue;
 
983
                        }
 
984
 
 
985
                        const pgm_txw_t* window = (const pgm_txw_t*)sock->window;
 
986
 
 
987
                        netsnmp_variable_list *var = request->requestvb;
 
988
                        netsnmp_table_request_info* table_info = netsnmp_extract_table_info (request);
 
989
                        if (NULL == table_info) {
 
990
                                snmp_log (LOG_ERR, "pgmSourceTable_handler: empty table request info.\n");
 
991
                                continue;
 
992
                        }
 
993
 
 
994
                        switch (table_info->colnum) {
 
995
 
 
996
                        case COLUMN_PGMSOURCEDATABYTESSENT:
 
997
                                {
 
998
                                        const unsigned data_bytes = sock->cumulative_stats[PGM_PC_SOURCE_DATA_BYTES_SENT];
 
999
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1000
                                                                  (const u_char*)&data_bytes, sizeof(data_bytes) );
 
1001
                                }
 
1002
                                break;
 
1003
 
 
1004
                        case COLUMN_PGMSOURCEDATAMSGSSENT:
 
1005
                                {
 
1006
                                        const unsigned data_msgs = sock->cumulative_stats[PGM_PC_SOURCE_DATA_MSGS_SENT];
 
1007
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1008
                                                                  (const u_char*)&data_msgs, sizeof(data_msgs) );
 
1009
                                }
 
1010
                                break;
 
1011
 
 
1012
                        case COLUMN_PGMSOURCEBYTESBUFFERED:
 
1013
                                {
 
1014
                                        const unsigned bytes_buffered = sock->can_send_data ? pgm_txw_size (window) : 0;
 
1015
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1016
                                                                  (const u_char*)&bytes_buffered, sizeof(bytes_buffered) );
 
1017
                                }
 
1018
                                break;
 
1019
 
 
1020
                        case COLUMN_PGMSOURCEMSGSBUFFERED:
 
1021
                                {
 
1022
                                        const unsigned msgs_buffered = sock->can_send_data ? pgm_txw_length (window) : 0;
 
1023
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1024
                                                                  (const u_char*)&msgs_buffered, sizeof(msgs_buffered) );
 
1025
                                }
 
1026
                                break;
 
1027
 
 
1028
/* PGM_PC_SOURCE_SELECTIVE_BYTES_RETRANSMITTED + COLUMN_PGMSOURCEPARITYBYTESRETRANSMITTED */
 
1029
                        case COLUMN_PGMSOURCEBYTESRETRANSMITTED:
 
1030
                                {
 
1031
                                        const unsigned bytes_resent = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_BYTES_RETRANSMITTED];
 
1032
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1033
                                                                  (const u_char*)&bytes_resent, sizeof(bytes_resent) );
 
1034
                                }
 
1035
                                break;
 
1036
 
 
1037
/* PGM_PC_SOURCE_SELECTIVE_MSGS_RETRANSMITTED + COLUMN_PGMSOURCEPARITYMSGSRETRANSMITTED */
 
1038
                        case COLUMN_PGMSOURCEMSGSRETRANSMITTED:
 
1039
                                {
 
1040
                                        const unsigned msgs_resent = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_MSGS_RETRANSMITTED];
 
1041
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1042
                                                                  (const u_char*)&msgs_resent, sizeof(msgs_resent) );
 
1043
                                }
 
1044
                                break;
 
1045
 
 
1046
                        case COLUMN_PGMSOURCEBYTESSENT:
 
1047
                                {
 
1048
                                        const unsigned bytes_sent = sock->cumulative_stats[PGM_PC_SOURCE_BYTES_SENT];
 
1049
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1050
                                                                  (const u_char*)&bytes_sent, sizeof(bytes_sent) );
 
1051
                                }
 
1052
                                break;
 
1053
 
 
1054
/* COLUMN_PGMSOURCEPARITYNAKPACKETSRECEIVED + COLUMN_PGMSOURCESELECTIVENAKPACKETSRECEIVED */
 
1055
                        case COLUMN_PGMSOURCERAWNAKSRECEIVED:
 
1056
                                {
 
1057
                                        const unsigned nak_packets = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NAKS_RECEIVED];
 
1058
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1059
                                                                  (const u_char*)&nak_packets, sizeof(nak_packets) );
 
1060
                                }
 
1061
                                break;
 
1062
 
 
1063
/* PGM_PC_SOURCE_SELECTIVE_NAKS_IGNORED + COLUMN_PGMSOURCEPARITYNAKSIGNORED */
 
1064
                        case COLUMN_PGMSOURCENAKSIGNORED:
 
1065
                                {
 
1066
                                        const unsigned naks_ignored = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NAKS_IGNORED];
 
1067
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1068
                                                                  (const u_char*)&naks_ignored, sizeof(naks_ignored) );
 
1069
                                }
 
1070
                                break;
 
1071
 
 
1072
                        case COLUMN_PGMSOURCECKSUMERRORS:
 
1073
                                {
 
1074
                                        const unsigned cksum_errors = sock->cumulative_stats[PGM_PC_SOURCE_CKSUM_ERRORS];
 
1075
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1076
                                                                  (const u_char*)&cksum_errors, sizeof(cksum_errors) );
 
1077
                                }
 
1078
                                break;
 
1079
 
 
1080
                        case COLUMN_PGMSOURCEMALFORMEDNAKS:
 
1081
                                {
 
1082
                                        const unsigned malformed_naks = sock->cumulative_stats[PGM_PC_SOURCE_MALFORMED_NAKS];
 
1083
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1084
                                                                  (const u_char*)&malformed_naks, sizeof(malformed_naks) );
 
1085
                                }
 
1086
                                break;
 
1087
 
 
1088
                        case COLUMN_PGMSOURCEPACKETSDISCARDED:
 
1089
                                {
 
1090
                                        const unsigned packets_discarded = sock->cumulative_stats[PGM_PC_SOURCE_PACKETS_DISCARDED];
 
1091
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1092
                                                                  (const u_char*)&packets_discarded, sizeof(packets_discarded) );
 
1093
                                }
 
1094
                                break;
 
1095
 
 
1096
/* PGM_PC_SOURCE_SELECTIVE_NAKS_RECEIVED + COLUMN_PGMSOURCEPARITYNAKSRECEIVED */
 
1097
                        case COLUMN_PGMSOURCENAKSRCVD:
 
1098
                                {
 
1099
                                        const unsigned naks_received = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NAKS_RECEIVED];
 
1100
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1101
                                                                  (const u_char*)&naks_received, sizeof(naks_received) );
 
1102
                                }
 
1103
                                break;
 
1104
 
 
1105
/* FIXED: 0 */
 
1106
                        case COLUMN_PGMSOURCEPARITYBYTESRETRANSMITTED:
 
1107
                                {
 
1108
                                        const unsigned parity_bytes_resent = 0;
 
1109
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1110
                                                                  (const u_char*)&parity_bytes_resent, sizeof(parity_bytes_resent) );
 
1111
                                }
 
1112
                                break;
 
1113
 
 
1114
                        case COLUMN_PGMSOURCESELECTIVEBYTESRETRANSMITED:
 
1115
                                {
 
1116
                                        const unsigned selective_bytes_resent = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_BYTES_RETRANSMITTED];
 
1117
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1118
                                                                  (const u_char*)&selective_bytes_resent, sizeof(selective_bytes_resent) );
 
1119
                                }
 
1120
                                break;
 
1121
 
 
1122
/* FIXED: 0 */
 
1123
                        case COLUMN_PGMSOURCEPARITYMSGSRETRANSMITTED:
 
1124
                                {
 
1125
                                        const unsigned parity_msgs_resent = 0;
 
1126
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1127
                                                                  (const u_char*)&parity_msgs_resent, sizeof(parity_msgs_resent) );
 
1128
                                }
 
1129
                                break;
 
1130
 
 
1131
                        case COLUMN_PGMSOURCESELECTIVEMSGSRETRANSMITTED:
 
1132
                                {
 
1133
                                        const unsigned selective_msgs_resent = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_MSGS_RETRANSMITTED];
 
1134
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1135
                                                                  (const u_char*)&selective_msgs_resent, sizeof(selective_msgs_resent) );
 
1136
                                }
 
1137
                                break;
 
1138
 
 
1139
/* FIXED: 0 */
 
1140
                        case COLUMN_PGMSOURCEBYTESADMIT:
 
1141
                                {
 
1142
                                        const unsigned bytes_admit = 0;
 
1143
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1144
                                                                  (const u_char*)&bytes_admit, sizeof(bytes_admit) );
 
1145
                                }
 
1146
                                break;
 
1147
 
 
1148
/* FIXED: 0 */
 
1149
                        case COLUMN_PGMSOURCEMSGSADMIT:
 
1150
                                {
 
1151
                                        const unsigned msgs_admit = 0;
 
1152
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1153
                                                                  (const u_char*)&msgs_admit, sizeof(msgs_admit) );
 
1154
                                }
 
1155
                                break;
 
1156
 
 
1157
/* FIXED: 0 */
 
1158
                        case COLUMN_PGMSOURCEPARITYNAKPACKETSRECEIVED:
 
1159
                                {
 
1160
                                        const unsigned parity_nak_packets = 0;
 
1161
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1162
                                                                  (const u_char*)&parity_nak_packets, sizeof(parity_nak_packets) );
 
1163
                                }
 
1164
                                break;
 
1165
 
 
1166
                        case COLUMN_PGMSOURCESELECTIVENAKPACKETSRECEIVED:
 
1167
                                {
 
1168
                                        const unsigned selective_nak_packets = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NAKS_RECEIVED];
 
1169
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1170
                                                                  (const u_char*)&selective_nak_packets, sizeof(selective_nak_packets) );
 
1171
                                }
 
1172
                                break;
 
1173
 
 
1174
/* FIXED: 0 */
 
1175
                        case COLUMN_PGMSOURCEPARITYNAKSRECEIVED:
 
1176
                                {
 
1177
                                        const unsigned parity_naks = 0;
 
1178
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1179
                                                                  (const u_char*)&parity_naks, sizeof(parity_naks) );
 
1180
                                }
 
1181
                                break;
 
1182
 
 
1183
                        case COLUMN_PGMSOURCESELECTIVENAKSRECEIVED:
 
1184
                                {
 
1185
                                        const unsigned selective_naks = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NAKS_RECEIVED];
 
1186
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1187
                                                                  (const u_char*)&selective_naks, sizeof(selective_naks) );
 
1188
                                }
 
1189
                                break;
 
1190
 
 
1191
/* FIXED: 0 */
 
1192
                        case COLUMN_PGMSOURCEPARITYNAKSIGNORED:
 
1193
                                {
 
1194
                                        const unsigned parity_naks_ignored = 0;
 
1195
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1196
                                                                  (const u_char*)&parity_naks_ignored, sizeof(parity_naks_ignored) );
 
1197
                                }
 
1198
                                break;
 
1199
 
 
1200
                        case COLUMN_PGMSOURCESELECTIVENAKSIGNORED:
 
1201
                                {
 
1202
                                        const unsigned selective_naks_ignored = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NAKS_IGNORED];
 
1203
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1204
                                                                  (const u_char*)&selective_naks_ignored, sizeof(selective_naks_ignored) );
 
1205
                                }
 
1206
                                break;
 
1207
 
 
1208
                        case COLUMN_PGMSOURCEACKERRORS:
 
1209
                                {
 
1210
                                        const unsigned ack_errors = sock->cumulative_stats[PGM_PC_SOURCE_ACK_ERRORS];;
 
1211
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1212
                                                                  (const u_char*)&ack_errors, sizeof(ack_errors) );
 
1213
                                }
 
1214
                                break;
 
1215
 
 
1216
                        case COLUMN_PGMSOURCEPGMCCACKER:
 
1217
                                {
 
1218
                                        struct sockaddr_in s4;
 
1219
                                        if (AF_INET == sock->acker_nla.ss_family)
 
1220
                                                memcpy (&s4, &sock->acker_nla, sizeof(s4));
 
1221
                                        else
 
1222
                                                memset (&s4, 0, sizeof(s4));
 
1223
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
1224
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
1225
                                                                  sizeof(struct in_addr) );
 
1226
                                }
 
1227
                                break;
 
1228
 
 
1229
                        case COLUMN_PGMSOURCETRANSMISSIONCURRENTRATE:
 
1230
                                {
 
1231
                                        const unsigned tx_current_rate = sock->cumulative_stats[PGM_PC_SOURCE_TRANSMISSION_CURRENT_RATE];
 
1232
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1233
                                                                  (const u_char*)&tx_current_rate, sizeof(tx_current_rate) );
 
1234
                                }
 
1235
                                break;
 
1236
 
 
1237
                        case COLUMN_PGMSOURCEACKPACKETSRECEIVED:
 
1238
                                {
 
1239
                                        const unsigned ack_packets = sock->cumulative_stats[PGM_PC_SOURCE_ACK_PACKETS_RECEIVED];
 
1240
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1241
                                                                  (const u_char*)&ack_packets, sizeof(ack_packets) );
 
1242
                                }
 
1243
                                break;
 
1244
 
 
1245
/* COLUMN_PGMSOURCEPARITYNNAKPACKETSRECEIVED + COLUMN_PGMSOURCESELECTIVENNAKPACKETSRECEIVED */
 
1246
                        case COLUMN_PGMSOURCENNAKPACKETSRECEIVED:
 
1247
                                {
 
1248
                                        const unsigned nnak_packets = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NNAK_PACKETS_RECEIVED];
 
1249
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1250
                                                                  (const u_char*)&nnak_packets, sizeof(nnak_packets) );
 
1251
                                }
 
1252
                                break;
 
1253
 
 
1254
/* FIXED: 0 */
 
1255
                        case COLUMN_PGMSOURCEPARITYNNAKPACKETSRECEIVED:
 
1256
                                {
 
1257
                                        const unsigned parity_nnak_packets = 0;
 
1258
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1259
                                                                  (const u_char*)&parity_nnak_packets, sizeof(parity_nnak_packets) );
 
1260
                                }
 
1261
                                break;
 
1262
 
 
1263
                        case COLUMN_PGMSOURCESELECTIVENNAKPACKETSRECEIVED:
 
1264
                                {
 
1265
                                        const unsigned selective_nnak_packets = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NNAK_PACKETS_RECEIVED];
 
1266
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1267
                                                                  (const u_char*)&selective_nnak_packets, sizeof(selective_nnak_packets) );
 
1268
                                }
 
1269
                                break;
 
1270
 
 
1271
/* COLUMN_PGMSOURCEPARITYNNAKSRECEIVED + COLUMN_PGMSOURCESELECTIVENNAKSRECEIVED */
 
1272
                        case COLUMN_PGMSOURCENNAKSRECEIVED:
 
1273
                                {
 
1274
                                        const unsigned nnaks_received = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NNAKS_RECEIVED];
 
1275
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1276
                                                                  (const u_char*)&nnaks_received, sizeof(nnaks_received) );
 
1277
                                }
 
1278
                                break;
 
1279
 
 
1280
/* FIXED: 0 */
 
1281
                        case COLUMN_PGMSOURCEPARITYNNAKSRECEIVED:
 
1282
                                {
 
1283
                                        const unsigned parity_nnaks = 0;
 
1284
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1285
                                                                  (const u_char*)&parity_nnaks, sizeof(parity_nnaks) );
 
1286
                                }
 
1287
                                break;
 
1288
 
 
1289
                        case COLUMN_PGMSOURCESELECTIVENNAKSRECEIVED:
 
1290
                                {
 
1291
                                        const unsigned selective_nnaks = sock->cumulative_stats[PGM_PC_SOURCE_SELECTIVE_NNAKS_RECEIVED];
 
1292
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1293
                                                                  (const u_char*)&selective_nnaks, sizeof(selective_nnaks) );
 
1294
                                }
 
1295
                                break;
 
1296
 
 
1297
                        case COLUMN_PGMSOURCENNAKERRORS:
 
1298
                                {
 
1299
                                        const unsigned malformed_nnaks = sock->cumulative_stats[PGM_PC_SOURCE_NNAK_ERRORS];
 
1300
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
1301
                                                                  (const u_char*)&malformed_nnaks, sizeof(malformed_nnaks) );
 
1302
                                }
 
1303
                                break;
 
1304
 
 
1305
                        default:
 
1306
                                snmp_log (LOG_ERR, "pgmSourcePerformanceTable_handler: unknown column.\n");
 
1307
                                break;
 
1308
                        }
 
1309
                }
 
1310
                break;
 
1311
 
 
1312
        case MODE_SET_RESERVE1:
 
1313
        default:
 
1314
                snmp_log (LOG_ERR, "pgmSourcePerformanceTable_handler: unsupported mode.\n");
 
1315
                break;
 
1316
 
 
1317
        }
 
1318
 
 
1319
        return SNMP_ERR_NOERROR;
 
1320
}
 
1321
 
 
1322
/*
 
1323
 * pgmReceiverTable
 
1324
 */
 
1325
 
 
1326
static
 
1327
int
 
1328
initialize_table_pgmReceiverTable(void)
 
1329
{
 
1330
        pgm_debug ("initialize_table_pgmReceiverTable ()");
 
1331
 
 
1332
        static const oid pgmReceiverTable_oid[] = {1,3,6,1,3,112,1,3,100,2};
 
1333
        netsnmp_table_registration_info* table_info = NULL;
 
1334
        netsnmp_iterator_info* iinfo = NULL;
 
1335
        netsnmp_handler_registration* reg = NULL;
 
1336
 
 
1337
        reg = netsnmp_create_handler_registration ("pgmReceiverTable",          pgmReceiverTable_handler,
 
1338
                                                   pgmReceiverTable_oid,        OID_LENGTH( pgmReceiverTable_oid ),
 
1339
                                                   HANDLER_CAN_RONLY);
 
1340
        if (NULL == reg)
 
1341
                goto error;
 
1342
 
 
1343
        table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
 
1344
        if (NULL == table_info)
 
1345
                goto error;
 
1346
 
 
1347
        table_info->min_column = COLUMN_PGMRECEIVERGROUPADDRESS;
 
1348
        table_info->max_column = COLUMN_PGMRECEIVERUNIQUEINSTANCE;
 
1349
 
 
1350
        netsnmp_table_helper_add_indexes (table_info,
 
1351
                                          ASN_OCTET_STR,  /* index: pgmReceiverGlobalId */
 
1352
                                          ASN_UNSIGNED,  /* index: pgmReceiverSourcePort */
 
1353
                                          ASN_UNSIGNED,  /* index: pgmReceiverInstance */
 
1354
                                          0);
 
1355
 
 
1356
        iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
 
1357
        if (NULL == iinfo)
 
1358
                goto error;
 
1359
 
 
1360
        iinfo->get_first_data_point     = pgmReceiverTable_get_first_data_point;
 
1361
        iinfo->get_next_data_point      = pgmReceiverTable_get_next_data_point;
 
1362
        iinfo->free_loop_context_at_end = pgmReceiverTable_free_loop_context;
 
1363
        iinfo->table_reginfo            = table_info;
 
1364
 
 
1365
        return netsnmp_register_table_iterator (reg, iinfo);
 
1366
 
 
1367
error:
 
1368
        if (table_info && table_info->indexes)          /* table_data_free_func() is internal */
 
1369
                snmp_free_var (table_info->indexes);
 
1370
        SNMP_FREE( table_info );
 
1371
        SNMP_FREE( iinfo );
 
1372
        netsnmp_handler_registration_free (reg);
 
1373
 
 
1374
        return -1;
 
1375
}
 
1376
 
 
1377
/* called for first row of data in SNMP table
 
1378
 *
 
1379
 * goal is to cache all the relevant data for subsequent get_next_data_point (row) calls in my_loop_context,
 
1380
 * optionally returns my_data_context.
 
1381
 *
 
1382
 * returns answer or NULL
 
1383
 */
 
1384
 
 
1385
static
 
1386
netsnmp_variable_list*
 
1387
pgmReceiverTable_get_first_data_point (
 
1388
        void**                  my_loop_context,        /* valid through one query of multiple "data points" */
 
1389
        void**                  my_data_context,        /* answer blob which is passed to handler() */
 
1390
        netsnmp_variable_list*  put_index_data,         /* answer */
 
1391
        netsnmp_iterator_info*  mydata                  /* iinfo on init() */
 
1392
        )
 
1393
{
 
1394
/* pre-conditions */
 
1395
        pgm_assert (NULL != my_loop_context);
 
1396
        pgm_assert (NULL != my_data_context);
 
1397
        pgm_assert (NULL != put_index_data);
 
1398
        pgm_assert (NULL != mydata);
 
1399
 
 
1400
        pgm_debug ("pgmReceiverTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
1401
                (const void*)my_loop_context,
 
1402
                (const void*)my_data_context,
 
1403
                (const void*)put_index_data,
 
1404
                (const void*)mydata);
 
1405
 
 
1406
        pgm_rwlock_reader_lock (&pgm_sock_list_lock);
 
1407
 
 
1408
        if (NULL == pgm_sock_list) {
 
1409
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
1410
                return NULL;
 
1411
        }
 
1412
 
 
1413
/* create our own context for this SNMP loop */
 
1414
        pgm_snmp_context_t* context = pgm_new0 (pgm_snmp_context_t, 1);
 
1415
 
 
1416
/* hunt to find first node, through all socks */
 
1417
        for (context->list = pgm_sock_list;
 
1418
             context->list;
 
1419
             context->list = context->list->next)
 
1420
        {
 
1421
/* and through all peers for each sock */
 
1422
                pgm_sock_t* sock = (pgm_sock_t*)context->list->data;
 
1423
                pgm_rwlock_reader_lock (&sock->peers_lock);
 
1424
                context->node = sock->peers_list;
 
1425
                if (context->node) {
 
1426
/* maintain this sock's peers lock */
 
1427
                        break;
 
1428
                }
 
1429
 
 
1430
                pgm_rwlock_reader_unlock (&sock->peers_lock);
 
1431
        }
 
1432
 
 
1433
/* no node found */
 
1434
        if (NULL == context->node) {
 
1435
                pgm_free (context);
 
1436
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
1437
                return NULL;
 
1438
        }
 
1439
 
 
1440
        *my_loop_context = context; 
 
1441
        *my_data_context = &context->data_context;
 
1442
 
 
1443
/* pass on for generic row access */
 
1444
        return pgmReceiverTable_get_next_data_point (my_loop_context, my_data_context, put_index_data, mydata);
 
1445
}
 
1446
 
 
1447
static
 
1448
netsnmp_variable_list*
 
1449
pgmReceiverTable_get_next_data_point (
 
1450
        void**                  my_loop_context,
 
1451
        void**                  my_data_context,
 
1452
        netsnmp_variable_list*  put_index_data,
 
1453
        netsnmp_iterator_info*  mydata
 
1454
        )
 
1455
{
 
1456
/* pre-conditions */
 
1457
        pgm_assert (NULL != my_loop_context);
 
1458
        pgm_assert (NULL != my_data_context);
 
1459
        pgm_assert (NULL != put_index_data);
 
1460
        pgm_assert (NULL != mydata);
 
1461
 
 
1462
        pgm_debug ("pgmReceiverTable_get_next_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
1463
                (const void*)my_loop_context,
 
1464
                (const void*)my_data_context,
 
1465
                (const void*)put_index_data,
 
1466
                (const void*)mydata);
 
1467
 
 
1468
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)*my_loop_context;
 
1469
        pgm_snmp_data_context_t* data_context = (pgm_snmp_data_context_t*)*my_data_context;
 
1470
        netsnmp_variable_list *idx = put_index_data;
 
1471
 
 
1472
        if (NULL == context->list)
 
1473
                return NULL;
 
1474
 
 
1475
        pgm_sock_t* sock = context->list->data;
 
1476
        data_context->sock = sock;
 
1477
 
 
1478
        if (NULL == context->node)
 
1479
                return NULL;
 
1480
 
 
1481
        pgm_peer_t* peer = context->node->data;
 
1482
        data_context->peer = peer;
 
1483
 
 
1484
/* pgmReceiverGlobalId */
 
1485
        char gsi[ PGM_GSISTRLEN ];
 
1486
        pgm_gsi_print_r (&peer->tsi.gsi, gsi, sizeof(gsi));
 
1487
        snmp_set_var_typed_value (idx, ASN_OCTET_STR, (const u_char*)&gsi, strlen (gsi));
 
1488
        idx = idx->next_variable;
 
1489
 
 
1490
/* pgmReceiverSourcePort */
 
1491
        const unsigned sport = ntohs (peer->tsi.sport);
 
1492
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&sport, sizeof(sport));
 
1493
        idx = idx->next_variable;
 
1494
 
 
1495
/* pgmReceiverInstance */
 
1496
        const unsigned instance = context->instance++;
 
1497
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&instance, sizeof(instance));
 
1498
 
 
1499
/* hunt for next valid node */
 
1500
        if (context->node->next) {
 
1501
                context->node = context->node->next;
 
1502
        }
 
1503
        else
 
1504
        {
 
1505
                context->node = NULL;
 
1506
                while (context->list->next) {
 
1507
                        pgm_rwlock_reader_unlock (&sock->peers_lock);
 
1508
                        context->list = context->list->next;
 
1509
                        sock = context->list->data;
 
1510
                        pgm_rwlock_reader_lock (&sock->peers_lock);
 
1511
                        context->node = sock->peers_list;
 
1512
                        if (context->node) {
 
1513
/* keep lock */
 
1514
                                break;
 
1515
                        }
 
1516
                }
 
1517
        }
 
1518
 
 
1519
        return put_index_data;
 
1520
}
 
1521
 
 
1522
static
 
1523
void
 
1524
pgmReceiverTable_free_loop_context (
 
1525
        void*                   my_loop_context,
 
1526
        netsnmp_iterator_info*  mydata
 
1527
        )
 
1528
{
 
1529
/* pre-conditions */
 
1530
        pgm_assert (NULL != my_loop_context);
 
1531
        pgm_assert (NULL != mydata);
 
1532
 
 
1533
        pgm_debug ("pgmReceiverTable_free_loop_context (my_loop_context:%p mydata:%p)",
 
1534
                (const void*)my_loop_context,
 
1535
                (const void*)mydata);
 
1536
 
 
1537
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)my_loop_context;
 
1538
 
 
1539
/* check for intra-peer state */
 
1540
        if (context->list) {
 
1541
                pgm_sock_t* sock = context->list->data;
 
1542
                pgm_rwlock_reader_unlock (&sock->peers_lock);
 
1543
        }
 
1544
 
 
1545
        pgm_free (context);
 
1546
        my_loop_context = NULL;
 
1547
 
 
1548
        pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
1549
}
 
1550
 
 
1551
static
 
1552
int
 
1553
pgmReceiverTable_handler (
 
1554
        netsnmp_mib_handler*            handler,
 
1555
        netsnmp_handler_registration*   reginfo,
 
1556
        netsnmp_agent_request_info*     reqinfo,
 
1557
        netsnmp_request_info*           requests
 
1558
        )
 
1559
{
 
1560
/* pre-conditions */
 
1561
        pgm_assert (NULL != handler);
 
1562
        pgm_assert (NULL != reginfo);
 
1563
        pgm_assert (NULL != reqinfo);
 
1564
        pgm_assert (NULL != requests);
 
1565
 
 
1566
        pgm_debug ("pgmReceiverTable_handler (handler:%p reginfo:%p reqinfo:%p requests:%p)",
 
1567
                (const void*)handler,
 
1568
                (const void*)reginfo,
 
1569
                (const void*)reqinfo,
 
1570
                (const void*)requests);
 
1571
 
 
1572
        switch (reqinfo->mode) {
 
1573
 
 
1574
/* Read-support (also covers GetNext requests) */
 
1575
 
 
1576
        case MODE_GET:
 
1577
                for (netsnmp_request_info* request = requests;
 
1578
                     request;
 
1579
                     request = request->next)
 
1580
                {
 
1581
                        const pgm_snmp_data_context_t* data_context = (pgm_snmp_data_context_t*)netsnmp_extract_iterator_context (request);
 
1582
                        if (!data_context) {
 
1583
                                netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE);
 
1584
                                continue;
 
1585
                        }
 
1586
 
 
1587
                        const pgm_sock_t* sock = data_context->sock;
 
1588
                        const pgm_peer_t* peer = data_context->peer;
 
1589
 
 
1590
                        netsnmp_variable_list *var = request->requestvb;
 
1591
                        netsnmp_table_request_info* table_info = netsnmp_extract_table_info(request);
 
1592
 
 
1593
                        if (table_info == NULL) {
 
1594
                                snmp_log (LOG_ERR, "pgmReceiverTable_handler: empty table request info.\n");
 
1595
                                continue;
 
1596
                        }
 
1597
 
 
1598
                        switch (table_info->colnum) {
 
1599
 
 
1600
                        case COLUMN_PGMRECEIVERGROUPADDRESS:
 
1601
                                {
 
1602
                                        struct sockaddr_in s4;
 
1603
                                        if (AF_INET == peer->group_nla.ss_family)
 
1604
                                                memcpy (&s4, &peer->group_nla, sizeof(s4));
 
1605
                                        else
 
1606
                                                memset (&s4, 0, sizeof(s4));
 
1607
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
1608
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
1609
                                                                  sizeof(struct in_addr) );
 
1610
                                }
 
1611
                                break;
 
1612
 
 
1613
/* by definition same as sock */
 
1614
                        case COLUMN_PGMRECEIVERDESTPORT:
 
1615
                                {
 
1616
                                        const unsigned dport = ntohs (sock->dport);
 
1617
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1618
                                                                  (const u_char*)&dport, sizeof(dport) );
 
1619
                                }
 
1620
                                break;
 
1621
 
 
1622
                        case COLUMN_PGMRECEIVERSOURCEADDRESS:
 
1623
                                {
 
1624
                                        struct sockaddr_in s4;
 
1625
                                        if (AF_INET == peer->nla.ss_family)
 
1626
                                                memcpy (&s4, &peer->nla, sizeof(s4));
 
1627
                                        else
 
1628
                                                memset (&s4, 0, sizeof(s4));
 
1629
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
1630
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
1631
                                                                  sizeof(struct in_addr) );
 
1632
                                }
 
1633
                                break;
 
1634
 
 
1635
                        case COLUMN_PGMRECEIVERLASTHOP:
 
1636
                                {
 
1637
                                        struct sockaddr_in s4;
 
1638
                                        if (AF_INET == peer->local_nla.ss_family)
 
1639
                                                memcpy (&s4, &peer->local_nla, sizeof(s4));
 
1640
                                        else
 
1641
                                                memset (&s4, 0, sizeof(s4));
 
1642
                                        snmp_set_var_typed_value (var, ASN_IPADDRESS,
 
1643
                                                                  (const u_char*)&s4.sin_addr.s_addr,
 
1644
                                                                  sizeof(struct in_addr) );
 
1645
                                }
 
1646
                                break;
 
1647
 
 
1648
/* copy index[0] */
 
1649
                        case COLUMN_PGMRECEIVERSOURCEGSI:
 
1650
                                snmp_set_var_typed_value (var, ASN_OCTET_STR,
 
1651
                                                          (const u_char*)table_info->indexes->val.string,
 
1652
                                                          table_info->indexes->val_len);
 
1653
                                break;
 
1654
 
 
1655
/* copy index[1] */
 
1656
                        case COLUMN_PGMRECEIVERSOURCEPORTNUMBER:
 
1657
                                snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1658
                                                          (const u_char*)table_info->indexes->next_variable->val.integer,
 
1659
                                                          table_info->indexes->next_variable->val_len);
 
1660
                                break;
 
1661
 
 
1662
/* copy index[2] */
 
1663
                        case COLUMN_PGMRECEIVERUNIQUEINSTANCE:
 
1664
                                snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1665
                                                          (const u_char*)table_info->indexes->next_variable->next_variable->val.integer,
 
1666
                                                          table_info->indexes->next_variable->next_variable->val_len);
 
1667
                                break;
 
1668
 
 
1669
                        default:
 
1670
                                snmp_log (LOG_ERR, "pgmReceiverTable_handler: unknown column.\n");
 
1671
                                break;
 
1672
                        }
 
1673
                }
 
1674
                break;
 
1675
 
 
1676
        case MODE_SET_RESERVE1:
 
1677
        default:
 
1678
                snmp_log (LOG_ERR, "pgmReceiverTable_handler: unsupported mode.\n");
 
1679
                break;
 
1680
 
 
1681
        }
 
1682
 
 
1683
        return SNMP_ERR_NOERROR;
 
1684
}
 
1685
 
 
1686
/*
 
1687
 * pgmReceiverConfigTable
 
1688
 *
 
1689
 */
 
1690
 
 
1691
static
 
1692
int
 
1693
initialize_table_pgmReceiverConfigTable(void)
 
1694
{
 
1695
        pgm_debug ("initialize_table_pgmReceiverConfigTable ()");
 
1696
 
 
1697
        static const oid pgmReceiverConfigTable_oid[] = {1,3,6,1,3,112,1,3,100,3};
 
1698
        netsnmp_table_registration_info* table_info = NULL;
 
1699
        netsnmp_iterator_info* iinfo = NULL;
 
1700
        netsnmp_handler_registration* reg = NULL;
 
1701
 
 
1702
        reg = netsnmp_create_handler_registration ("pgmReceiverConfigTable",    pgmReceiverConfigTable_handler,
 
1703
                                                   pgmReceiverConfigTable_oid,  OID_LENGTH(pgmReceiverConfigTable_oid),
 
1704
                                                   HANDLER_CAN_RONLY);
 
1705
        if (NULL == reg)
 
1706
                goto error;
 
1707
 
 
1708
        table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
 
1709
        if (NULL == table_info)
 
1710
                goto error;
 
1711
 
 
1712
        table_info->min_column = COLUMN_PGMRECEIVERNAKBACKOFFIVL;
 
1713
        table_info->max_column = COLUMN_PGMRECEIVERNAKFAILURETHRESHOLD;
 
1714
 
 
1715
        netsnmp_table_helper_add_indexes (table_info,
 
1716
                                          ASN_OCTET_STR, /* index: pgmReceiverConfigGlobalId */
 
1717
                                          ASN_UNSIGNED,  /* index: pgmReceiverConfigSourcePort */
 
1718
                                          ASN_UNSIGNED,  /* index: pgmReceiverInstance */
 
1719
                                          0);
 
1720
 
 
1721
        iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
 
1722
        if (NULL == iinfo)
 
1723
                goto error;
 
1724
 
 
1725
        iinfo->get_first_data_point     = pgmReceiverConfigTable_get_first_data_point;
 
1726
        iinfo->get_next_data_point      = pgmReceiverConfigTable_get_next_data_point;
 
1727
        iinfo->free_loop_context_at_end = pgmReceiverConfigTable_free_loop_context;
 
1728
        iinfo->table_reginfo            = table_info;
 
1729
 
 
1730
        return netsnmp_register_table_iterator (reg, iinfo);
 
1731
 
 
1732
error:
 
1733
        if (table_info && table_info->indexes)          /* table_data_free_func() is internal */
 
1734
                snmp_free_var (table_info->indexes);
 
1735
        SNMP_FREE( table_info );
 
1736
        SNMP_FREE( iinfo );
 
1737
        netsnmp_handler_registration_free (reg);
 
1738
 
 
1739
        return -1;
 
1740
}
 
1741
 
 
1742
/* called for first row of data in SNMP table
 
1743
 *
 
1744
 * goal is to cache all the relevant data for subsequent get_next_data_point (row) calls in my_loop_context,
 
1745
 * optionally returns my_data_context.
 
1746
 *
 
1747
 * returns answer or NULL
 
1748
 */
 
1749
 
 
1750
static
 
1751
netsnmp_variable_list*
 
1752
pgmReceiverConfigTable_get_first_data_point(
 
1753
        void**                  my_loop_context,        /* valid through one query of multiple "data points" */
 
1754
        void**                  my_data_context,        /* answer blob which is passed to handler() */
 
1755
        netsnmp_variable_list*  put_index_data,         /* answer */
 
1756
        netsnmp_iterator_info*  mydata                  /* iinfo on init() */
 
1757
        )
 
1758
{
 
1759
/* pre-conditions */
 
1760
        pgm_assert (NULL != my_loop_context);
 
1761
        pgm_assert (NULL != my_data_context);
 
1762
        pgm_assert (NULL != put_index_data);
 
1763
        pgm_assert (NULL != mydata);
 
1764
 
 
1765
        pgm_debug ("pgmReceiverConfigTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
1766
                (const void*)my_loop_context,
 
1767
                (const void*)my_data_context,
 
1768
                (const void*)put_index_data,
 
1769
                (const void*)mydata);
 
1770
 
 
1771
        pgm_rwlock_reader_lock (&pgm_sock_list_lock);
 
1772
 
 
1773
        if (NULL == pgm_sock_list) {
 
1774
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
1775
                return NULL;
 
1776
        }
 
1777
 
 
1778
/* create our own context for this SNMP loop */
 
1779
        pgm_snmp_context_t* context = pgm_new0 (pgm_snmp_context_t, 1);
 
1780
 
 
1781
/* hunt to find first node, through all socks */
 
1782
        for (context->list = pgm_sock_list;
 
1783
             context->list;
 
1784
             context->list = context->list->next)
 
1785
        {
 
1786
/* and through all peers for each sock */
 
1787
                pgm_sock_t* sock = (pgm_sock_t*)context->list->data;
 
1788
                pgm_rwlock_reader_lock (&sock->peers_lock);
 
1789
                context->node = sock->peers_list;
 
1790
                if (context->node)
 
1791
                        break;
 
1792
 
 
1793
                pgm_rwlock_reader_unlock (&sock->peers_lock);
 
1794
        }
 
1795
 
 
1796
/* no node found */
 
1797
        if (NULL == context->node) {
 
1798
                pgm_free (context);
 
1799
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
1800
                return NULL;
 
1801
        }
 
1802
 
 
1803
        *my_loop_context = context; 
 
1804
        *my_data_context = NULL;
 
1805
 
 
1806
/* pass on for generic row access */
 
1807
        return pgmReceiverConfigTable_get_next_data_point (my_loop_context, my_data_context, put_index_data, mydata);
 
1808
}
 
1809
 
 
1810
static
 
1811
netsnmp_variable_list*
 
1812
pgmReceiverConfigTable_get_next_data_point(
 
1813
        void**                  my_loop_context,
 
1814
        void**                  my_data_context,
 
1815
        netsnmp_variable_list*  put_index_data,
 
1816
        netsnmp_iterator_info*  mydata
 
1817
        )
 
1818
{
 
1819
/* pre-conditions */
 
1820
        pgm_assert (NULL != my_loop_context);
 
1821
        pgm_assert (NULL != my_data_context);
 
1822
        pgm_assert (NULL != put_index_data);
 
1823
        pgm_assert (NULL != mydata);
 
1824
 
 
1825
        pgm_debug ("pgmReceiverConfigTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
1826
                (const void*)my_loop_context,
 
1827
                (const void*)my_data_context,
 
1828
                (const void*)put_index_data,
 
1829
                (const void*)mydata);
 
1830
 
 
1831
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)*my_loop_context;
 
1832
        netsnmp_variable_list *idx = put_index_data;
 
1833
 
 
1834
        if (NULL == context->list)
 
1835
                return NULL;
 
1836
 
 
1837
        pgm_sock_t* sock = context->list->data;
 
1838
        *my_data_context = sock;
 
1839
 
 
1840
        if (NULL == context->node)
 
1841
                return NULL;
 
1842
 
 
1843
        pgm_peer_t* peer = context->node->data;
 
1844
 
 
1845
/* pgmReceiverGlobalId */
 
1846
        char gsi[ PGM_GSISTRLEN ];
 
1847
        pgm_gsi_print_r (&peer->tsi.gsi, gsi, sizeof(gsi));
 
1848
        snmp_set_var_typed_value (idx, ASN_OCTET_STR, (const u_char*)&gsi, strlen (gsi));
 
1849
        idx = idx->next_variable;
 
1850
 
 
1851
/* pgmReceiverSourcePort */
 
1852
        const unsigned sport = ntohs (peer->tsi.sport);
 
1853
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&sport, sizeof(sport));
 
1854
        idx = idx->next_variable;
 
1855
 
 
1856
/* pgmReceiverInstance */
 
1857
        const unsigned instance = context->instance++;
 
1858
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&instance, sizeof(instance));
 
1859
 
 
1860
/* hunt for next valid node */
 
1861
        if (context->node->next) {
 
1862
                context->node = context->node->next;
 
1863
        }
 
1864
        else
 
1865
        {
 
1866
                context->node = NULL;
 
1867
                while (context->list->next) {
 
1868
                        pgm_rwlock_reader_unlock (&sock->peers_lock);
 
1869
                        context->list = context->list->next;
 
1870
                        sock = context->list->data;
 
1871
                        pgm_rwlock_reader_lock (&sock->peers_lock);
 
1872
                        context->node = sock->peers_list;
 
1873
                        if (context->node) {
 
1874
/* keep lock */
 
1875
                                break;
 
1876
                        }
 
1877
                }
 
1878
        }
 
1879
 
 
1880
        return put_index_data;
 
1881
}
 
1882
 
 
1883
static
 
1884
void
 
1885
pgmReceiverConfigTable_free_loop_context (
 
1886
        void*                   my_loop_context,
 
1887
        netsnmp_iterator_info*  mydata
 
1888
        )
 
1889
{
 
1890
/* pre-conditions */
 
1891
        pgm_assert (NULL != my_loop_context);
 
1892
        pgm_assert (NULL != mydata);
 
1893
 
 
1894
        pgm_debug ("pgmReceiverConfigTable_free_loop_context (my_loop_context:%p mydata:%p)",
 
1895
                (const void*)my_loop_context,
 
1896
                (const void*)mydata);
 
1897
 
 
1898
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)my_loop_context;
 
1899
 
 
1900
/* check for intra-peer state */
 
1901
        if (context->list) {
 
1902
                pgm_sock_t* sock = context->list->data;
 
1903
                pgm_rwlock_reader_unlock (&sock->peers_lock);
 
1904
        }
 
1905
 
 
1906
        pgm_free (context);
 
1907
        my_loop_context = NULL;
 
1908
 
 
1909
        pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
1910
}
 
1911
 
 
1912
static
 
1913
int
 
1914
pgmReceiverConfigTable_handler (
 
1915
        netsnmp_mib_handler*            handler,
 
1916
        netsnmp_handler_registration*   reginfo,
 
1917
        netsnmp_agent_request_info*     reqinfo,
 
1918
        netsnmp_request_info*           requests
 
1919
        )
 
1920
{
 
1921
/* pre-conditions */
 
1922
        pgm_assert (NULL != handler);
 
1923
        pgm_assert (NULL != reginfo);
 
1924
        pgm_assert (NULL != reqinfo);
 
1925
        pgm_assert (NULL != requests);
 
1926
 
 
1927
        pgm_debug ("pgmReceiverConfigTable_handler (handler:%p reginfo:%p reqinfo:%p requests:%p)",
 
1928
                (const void*)handler,
 
1929
                (const void*)reginfo,
 
1930
                (const void*)reqinfo,
 
1931
                (const void*)requests);
 
1932
 
 
1933
        switch (reqinfo->mode) {
 
1934
 
 
1935
/* Read-support (also covers GetNext requests) */
 
1936
 
 
1937
        case MODE_GET:
 
1938
                for (netsnmp_request_info* request = requests;
 
1939
                     request;
 
1940
                     request = request->next)
 
1941
                {
 
1942
                        const pgm_sock_t* sock = (pgm_sock_t*)netsnmp_extract_iterator_context(request);
 
1943
                        if (NULL == sock) {
 
1944
                                netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE);
 
1945
                                continue;
 
1946
                        }
 
1947
 
 
1948
                        netsnmp_variable_list *var = request->requestvb;
 
1949
                        netsnmp_table_request_info* table_info = netsnmp_extract_table_info(request);
 
1950
 
 
1951
                        if (NULL == table_info) {
 
1952
                                snmp_log (LOG_ERR, "pgmReceiverTable_handler: empty table request info.\n");
 
1953
                                continue;
 
1954
                        }
 
1955
 
 
1956
                        switch (table_info->colnum) {
 
1957
 
 
1958
/* nak_bo_ivl from sock */
 
1959
                        case COLUMN_PGMRECEIVERNAKBACKOFFIVL:
 
1960
                                {
 
1961
                                        const unsigned nak_bo_ivl = sock->nak_bo_ivl;
 
1962
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1963
                                                                  (const u_char*)&nak_bo_ivl, sizeof(nak_bo_ivl) );
 
1964
                                }
 
1965
                                break;
 
1966
 
 
1967
/* nak_rpt_ivl from sock */
 
1968
                        case COLUMN_PGMRECEIVERNAKREPEATIVL:
 
1969
                                {
 
1970
                                        const unsigned nak_rpt_ivl = sock->nak_rpt_ivl;
 
1971
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1972
                                                                  (const u_char*)&nak_rpt_ivl, sizeof(nak_rpt_ivl) );
 
1973
                                }
 
1974
                                break;
 
1975
 
 
1976
/* nak_ncf_retries from sock */
 
1977
                        case COLUMN_PGMRECEIVERNAKNCFRETRIES:
 
1978
                                {
 
1979
                                        const unsigned nak_ncf_retries = sock->nak_ncf_retries;
 
1980
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1981
                                                                  (const u_char*)&nak_ncf_retries, sizeof(nak_ncf_retries) );
 
1982
                                }
 
1983
                                break;
 
1984
 
 
1985
/* nak_rdata_ivl from sock */
 
1986
                        case COLUMN_PGMRECEIVERNAKRDATAIVL:
 
1987
                                {
 
1988
                                        const unsigned nak_rdata_ivl = sock->nak_rdata_ivl;
 
1989
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1990
                                                                  (const u_char*)&nak_rdata_ivl, sizeof(nak_rdata_ivl) );
 
1991
                                }
 
1992
                                break;
 
1993
 
 
1994
/* nak_data_retries from sock */
 
1995
                        case COLUMN_PGMRECEIVERNAKDATARETRIES:
 
1996
                                {
 
1997
                                        const unsigned nak_data_retries = sock->nak_data_retries;
 
1998
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
1999
                                                                  (const u_char*)&nak_data_retries, sizeof(nak_data_retries) );
 
2000
                                }
 
2001
                                break;
 
2002
 
 
2003
/* FIXED: pgmReceiverSendNaks = enabled(1) */
 
2004
                        case COLUMN_PGMRECEIVERSENDNAKS:
 
2005
                                {
 
2006
                                        const unsigned send_naks = PGMRECEIVERSENDNAKS_ENABLED;
 
2007
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
2008
                                                                  (const u_char*)&send_naks, sizeof(send_naks) );
 
2009
                                }
 
2010
                                break;
 
2011
 
 
2012
/* FIXED: pgmReceiverLateJoin = disabled(2) */
 
2013
                        case COLUMN_PGMRECEIVERLATEJOIN:
 
2014
                                {
 
2015
                                        const unsigned late_join = PGMRECEIVERLATEJOIN_DISABLED;
 
2016
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
2017
                                                                  (const u_char*)&late_join, sizeof(late_join) );
 
2018
                                }
 
2019
                                break;
 
2020
 
 
2021
/* FIXED: 1 for multicast */
 
2022
                        case COLUMN_PGMRECEIVERNAKTTL:
 
2023
                                {
 
2024
                                        const unsigned nak_hops = 1;
 
2025
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
2026
                                                                  (const u_char*)&nak_hops, sizeof(nak_hops) );
 
2027
                                }
 
2028
                                break;
 
2029
 
 
2030
/* FIXED: pgmReceiverDeliveryOrder = ordered(2) */
 
2031
                        case COLUMN_PGMRECEIVERDELIVERYORDER:
 
2032
                                {
 
2033
                                        const unsigned delivery_order = PGMRECEIVERDELIVERYORDER_ORDERED;
 
2034
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
2035
                                                                  (const u_char*)&delivery_order, sizeof(delivery_order) );
 
2036
                                }
 
2037
                                break;
 
2038
 
 
2039
/* FIXED: pgmReceiverMcastNaks = disabled(2) */
 
2040
                        case COLUMN_PGMRECEIVERMCASTNAKS:
 
2041
                                {
 
2042
                                        const unsigned mcast_naks = PGMRECEIVERMCASTNAKS_DISABLED;
 
2043
                                        snmp_set_var_typed_value (var, ASN_INTEGER,
 
2044
                                                                  (const u_char*)&mcast_naks, sizeof(mcast_naks) );
 
2045
                                }
 
2046
                                break;
 
2047
 
 
2048
/* TODO: traps */
 
2049
                        case COLUMN_PGMRECEIVERNAKFAILURETHRESHOLDTIMER:
 
2050
                        case COLUMN_PGMRECEIVERNAKFAILURETHRESHOLD:
 
2051
                                {
 
2052
                                        const unsigned threshold = 0;
 
2053
                                        snmp_set_var_typed_value (var, ASN_UNSIGNED,
 
2054
                                                                  (const u_char*)&threshold, sizeof(threshold) );
 
2055
                                }
 
2056
                                break;
 
2057
 
 
2058
                        default:
 
2059
                                snmp_log (LOG_ERR, "pgmReceiverTable_handler: unknown column.\n");
 
2060
                                break;
 
2061
                        }
 
2062
                }
 
2063
                break;
 
2064
 
 
2065
        case MODE_SET_RESERVE1:
 
2066
        default:
 
2067
                snmp_log (LOG_ERR, "pgmReceiverTable_handler: unsupported mode.\n");
 
2068
                break;
 
2069
 
 
2070
        }
 
2071
 
 
2072
        return SNMP_ERR_NOERROR;
 
2073
}
 
2074
 
 
2075
/*
 
2076
 * pgmReceiverPerformanceTable
 
2077
 */
 
2078
 
 
2079
static
 
2080
int
 
2081
initialize_table_pgmReceiverPerformanceTable (void)
 
2082
{
 
2083
        pgm_debug ("initialize_table_pgmReceiverPerformanceTable ()");
 
2084
 
 
2085
        static const oid pgmReceiverPerformanceTable_oid[] = {1,3,6,1,3,112,1,3,100,4};
 
2086
        netsnmp_table_registration_info* table_info = NULL;
 
2087
        netsnmp_iterator_info* iinfo = NULL;
 
2088
        netsnmp_handler_registration* reg = NULL;
 
2089
 
 
2090
        reg = netsnmp_create_handler_registration ("pgmReceiverPerformanceTable",       pgmReceiverPerformanceTable_handler,
 
2091
                                                   pgmReceiverPerformanceTable_oid,     OID_LENGTH( pgmReceiverPerformanceTable_oid ),
 
2092
                                                   HANDLER_CAN_RONLY);
 
2093
        if (NULL == reg)
 
2094
                goto error;
 
2095
 
 
2096
        table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
 
2097
        if (NULL == table_info)
 
2098
                goto error;
 
2099
 
 
2100
        table_info->min_column = COLUMN_PGMRECEIVERDATABYTESRECEIVED;
 
2101
        table_info->max_column = COLUMN_PGMRECEIVERLASTINTERVALNAKFAILURES;
 
2102
 
 
2103
        netsnmp_table_helper_add_indexes (table_info,
 
2104
                                          ASN_OCTET_STR,  /* index: pgmReceiverGlobalId */
 
2105
                                          ASN_UNSIGNED,  /* index: pgmReceiverSourcePort */
 
2106
                                          ASN_UNSIGNED,  /* index: pgmReceiverInstance */
 
2107
                                          0);
 
2108
 
 
2109
        iinfo = SNMP_MALLOC_TYPEDEF( netsnmp_iterator_info );
 
2110
        if (NULL == iinfo)
 
2111
                goto error;
 
2112
 
 
2113
        iinfo->get_first_data_point     = pgmReceiverPerformanceTable_get_first_data_point;
 
2114
        iinfo->get_next_data_point      = pgmReceiverPerformanceTable_get_next_data_point;
 
2115
        iinfo->free_loop_context_at_end = pgmReceiverPerformanceTable_free_loop_context;
 
2116
        iinfo->table_reginfo            = table_info;
 
2117
 
 
2118
        return netsnmp_register_table_iterator (reg, iinfo);
 
2119
 
 
2120
error:
 
2121
        if (table_info && table_info->indexes)          /* table_data_free_func() is internal */
 
2122
                snmp_free_var (table_info->indexes);
 
2123
        SNMP_FREE( table_info );
 
2124
        SNMP_FREE( iinfo );
 
2125
        netsnmp_handler_registration_free (reg);
 
2126
 
 
2127
        return -1;
 
2128
}
 
2129
 
 
2130
/* called for first row of data in SNMP table
 
2131
 *
 
2132
 * goal is to cache all the relevant data for subsequent get_next_data_point (row) calls in my_loop_context,
 
2133
 * optionally returns my_data_context.
 
2134
 *
 
2135
 * returns answer or NULL
 
2136
 */
 
2137
 
 
2138
static
 
2139
netsnmp_variable_list*
 
2140
pgmReceiverPerformanceTable_get_first_data_point (
 
2141
        void**                  my_loop_context,        /* valid through one query of multiple "data points" */
 
2142
        void**                  my_data_context,        /* answer blob which is passed to handler() */
 
2143
        netsnmp_variable_list*  put_index_data,         /* answer */
 
2144
        netsnmp_iterator_info*  mydata                  /* iinfo on init() */
 
2145
        )
 
2146
{
 
2147
/* pre-conditions */
 
2148
        pgm_assert (NULL != my_loop_context);
 
2149
        pgm_assert (NULL != my_data_context);
 
2150
        pgm_assert (NULL != put_index_data);
 
2151
        pgm_assert (NULL != mydata);
 
2152
 
 
2153
        pgm_debug ("pgmReceiverPerformanceTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
2154
                (const void*)my_loop_context,
 
2155
                (const void*)my_data_context,
 
2156
                (const void*)put_index_data,
 
2157
                (const void*)mydata);
 
2158
 
 
2159
        pgm_rwlock_reader_lock (&pgm_sock_list_lock);
 
2160
 
 
2161
        if (NULL == pgm_sock_list) {
 
2162
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
2163
                return NULL;
 
2164
        }
 
2165
 
 
2166
/* create our own context for this SNMP loop */
 
2167
        pgm_snmp_context_t* context = pgm_new0 (pgm_snmp_context_t, 1);
 
2168
 
 
2169
/* hunt to find first node, through all socks */
 
2170
        for (context->list = pgm_sock_list;
 
2171
             context->list;
 
2172
             context->list = context->list->next)
 
2173
        {
 
2174
/* and through all peers for each sock */
 
2175
                pgm_sock_t* sock = (pgm_sock_t*)context->list->data;
 
2176
                pgm_rwlock_reader_lock (&sock->peers_lock);
 
2177
                context->node = sock->peers_list;
 
2178
                if (context->node)
 
2179
                        break;
 
2180
 
 
2181
                pgm_rwlock_reader_unlock (&sock->peers_lock);
 
2182
        }
 
2183
 
 
2184
/* no node found */
 
2185
        if (NULL == context->node) {
 
2186
                pgm_free (context);
 
2187
                pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
2188
                return NULL;
 
2189
        }
 
2190
 
 
2191
        *my_loop_context = context; 
 
2192
        *my_data_context = &context->data_context;
 
2193
 
 
2194
/* pass on for generic row access */
 
2195
        return pgmReceiverPerformanceTable_get_next_data_point (my_loop_context, my_data_context, put_index_data, mydata);
 
2196
}
 
2197
 
 
2198
static
 
2199
netsnmp_variable_list*
 
2200
pgmReceiverPerformanceTable_get_next_data_point (
 
2201
        void**                  my_loop_context,
 
2202
        void**                  my_data_context,
 
2203
        netsnmp_variable_list*  put_index_data,
 
2204
        netsnmp_iterator_info*  mydata
 
2205
        )
 
2206
{
 
2207
/* pre-conditions */
 
2208
        pgm_assert (NULL != my_loop_context);
 
2209
        pgm_assert (NULL != my_data_context);
 
2210
        pgm_assert (NULL != put_index_data);
 
2211
        pgm_assert (NULL != mydata);
 
2212
 
 
2213
        pgm_debug ("pgmReceiverPerformanceTable_get_first_data_point (my_loop_context:%p my_data_context:%p put_index_data:%p mydata:%p)",
 
2214
                (const void*)my_loop_context,
 
2215
                (const void*)my_data_context,
 
2216
                (const void*)put_index_data,
 
2217
                (const void*)mydata);
 
2218
 
 
2219
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)*my_loop_context;
 
2220
        pgm_snmp_data_context_t* data_context = (pgm_snmp_data_context_t*)*my_data_context;
 
2221
        netsnmp_variable_list *idx = put_index_data;
 
2222
 
 
2223
        if (NULL == context->list)
 
2224
                return NULL;
 
2225
 
 
2226
        pgm_sock_t* sock = context->list->data;
 
2227
        data_context->sock = sock;
 
2228
 
 
2229
        if (NULL == context->node)
 
2230
                return NULL;
 
2231
 
 
2232
        pgm_peer_t* peer = context->node->data;
 
2233
        data_context->peer = peer;
 
2234
 
 
2235
/* pgmReceiverGlobalId */
 
2236
        char gsi[ PGM_GSISTRLEN ];
 
2237
        pgm_gsi_print_r (&peer->tsi.gsi, gsi, sizeof(gsi));
 
2238
        snmp_set_var_typed_value (idx, ASN_OCTET_STR, (const u_char*)&gsi, strlen (gsi));
 
2239
        idx = idx->next_variable;
 
2240
 
 
2241
/* pgmReceiverSourcePort */
 
2242
        const unsigned sport = ntohs (peer->tsi.sport);
 
2243
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&sport, sizeof(sport));
 
2244
        idx = idx->next_variable;
 
2245
 
 
2246
/* pgmReceiverInstance */
 
2247
        const unsigned instance = context->instance++;
 
2248
        snmp_set_var_typed_value (idx, ASN_UNSIGNED, (const u_char*)&instance, sizeof(instance));
 
2249
 
 
2250
/* hunt for next valid node */
 
2251
        if (context->node->next) {
 
2252
                context->node = context->node->next;
 
2253
        }
 
2254
        else
 
2255
        {
 
2256
                context->node = NULL;
 
2257
                while (context->list->next) {
 
2258
                        pgm_rwlock_reader_unlock (&sock->peers_lock);
 
2259
                        context->list = context->list->next;
 
2260
                        sock = context->list->data;
 
2261
                        pgm_rwlock_reader_lock (&sock->peers_lock);
 
2262
                        context->node = sock->peers_list;
 
2263
 
 
2264
                        if (context->node)
 
2265
                                break;
 
2266
                }
 
2267
        }
 
2268
 
 
2269
        return put_index_data;
 
2270
}
 
2271
 
 
2272
static
 
2273
void
 
2274
pgmReceiverPerformanceTable_free_loop_context (
 
2275
        void*                   my_loop_context,
 
2276
        netsnmp_iterator_info*  mydata
 
2277
        )
 
2278
{
 
2279
/* pre-conditions */
 
2280
        pgm_assert (NULL != my_loop_context);
 
2281
        pgm_assert (NULL != mydata);
 
2282
 
 
2283
        pgm_debug ("pgmReceiverPerformanceTable_free_loop_context (my_loop_context:%p mydata:%p)",
 
2284
                (const void*)my_loop_context,
 
2285
                (const void*)mydata);
 
2286
 
 
2287
        pgm_snmp_context_t* context = (pgm_snmp_context_t*)my_loop_context;
 
2288
 
 
2289
/* check for intra-peer state */
 
2290
        if (context->list) {
 
2291
                pgm_sock_t* sock = context->list->data;
 
2292
                pgm_rwlock_reader_unlock (&sock->peers_lock);
 
2293
        }
 
2294
 
 
2295
        pgm_free (context);
 
2296
        my_loop_context = NULL;
 
2297
 
 
2298
        pgm_rwlock_reader_unlock (&pgm_sock_list_lock);
 
2299
}
 
2300
 
 
2301
static
 
2302
int
 
2303
pgmReceiverPerformanceTable_handler (
 
2304
        netsnmp_mib_handler*            handler,
 
2305
        netsnmp_handler_registration*   reginfo,
 
2306
        netsnmp_agent_request_info*     reqinfo,
 
2307
        netsnmp_request_info*           requests
 
2308
        )
 
2309
{
 
2310
/* pre-conditions */
 
2311
        pgm_assert (NULL != handler);
 
2312
        pgm_assert (NULL != reginfo);
 
2313
        pgm_assert (NULL != reqinfo);
 
2314
        pgm_assert (NULL != requests);
 
2315
 
 
2316
        pgm_debug ("pgmReceiverPerformanceTable_handler (handler:%p reginfo:%p reqinfo:%p requests:%p)",
 
2317
                (const void*)handler,
 
2318
                (const void*)reginfo,
 
2319
                (const void*)reqinfo,
 
2320
                (const void*)requests);
 
2321
 
 
2322
        switch (reqinfo->mode) {
 
2323
 
 
2324
/* Read-support (also covers GetNext requests) */
 
2325
 
 
2326
        case MODE_GET:
 
2327
                for (netsnmp_request_info* request = requests;
 
2328
                     request;
 
2329
                     request = request->next)
 
2330
                {
 
2331
                        const pgm_snmp_data_context_t* data_context = (pgm_snmp_data_context_t*)netsnmp_extract_iterator_context (request);
 
2332
                        if (NULL == data_context) {
 
2333
                                netsnmp_set_request_error (reqinfo, request, SNMP_NOSUCHINSTANCE);
 
2334
                                continue;
 
2335
                        }
 
2336
 
 
2337
                        const pgm_sock_t* sock = data_context->sock;
 
2338
                        const pgm_peer_t* peer = data_context->peer;
 
2339
                        const pgm_rxw_t* window = peer->window;
 
2340
 
 
2341
                        netsnmp_variable_list *var = request->requestvb;
 
2342
                        netsnmp_table_request_info* table_info = netsnmp_extract_table_info (request);
 
2343
 
 
2344
                        if (NULL == table_info) {
 
2345
                                snmp_log (LOG_ERR, "pgmReceiverTable_handler: empty table request info.\n");
 
2346
                                continue;
 
2347
                        }
 
2348
 
 
2349
                        switch (table_info->colnum) {
 
2350
 
 
2351
                        case COLUMN_PGMRECEIVERDATABYTESRECEIVED:
 
2352
                                {
 
2353
                                        const unsigned data_bytes = peer->cumulative_stats[PGM_PC_RECEIVER_DATA_BYTES_RECEIVED];
 
2354
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2355
                                                                  (const u_char*)&data_bytes, sizeof(data_bytes) );
 
2356
                                }
 
2357
                                break;
 
2358
                
 
2359
                        case COLUMN_PGMRECEIVERDATAMSGSRECEIVED:
 
2360
                                {
 
2361
                                        const unsigned data_msgs = peer->cumulative_stats[PGM_PC_RECEIVER_DATA_MSGS_RECEIVED];
 
2362
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2363
                                                                  (const u_char*)&data_msgs, sizeof(data_msgs) );
 
2364
                                }
 
2365
                                break;
 
2366
 
 
2367
/* total */
 
2368
                        case COLUMN_PGMRECEIVERNAKSSENT:
 
2369
                                {
 
2370
                                        const unsigned naks_sent = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_SENT];
 
2371
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2372
                                                                  (const u_char*)&naks_sent, sizeof(naks_sent) );
 
2373
                                }
 
2374
                                break;
 
2375
        
 
2376
/* total */     
 
2377
                        case COLUMN_PGMRECEIVERNAKSRETRANSMITTED:
 
2378
                                {
 
2379
                                        const unsigned naks_resent = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_RETRANSMITTED];
 
2380
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2381
                                                                  (const u_char*)&naks_resent, sizeof(naks_resent) );
 
2382
                                }
 
2383
                                break;
 
2384
        
 
2385
/* total */     
 
2386
                        case COLUMN_PGMRECEIVERNAKFAILURES:
 
2387
                                {
 
2388
                                        const unsigned nak_failures = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_FAILED];
 
2389
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2390
                                                                  (const u_char*)&nak_failures, sizeof(nak_failures) );
 
2391
                                }
 
2392
                                break;
 
2393
                
 
2394
                        case COLUMN_PGMRECEIVERBYTESRECEIVED:
 
2395
                                {
 
2396
                                        const unsigned bytes_received = peer->cumulative_stats[PGM_PC_RECEIVER_BYTES_RECEIVED];
 
2397
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2398
                                                                  (const u_char*)&bytes_received, sizeof(bytes_received) );
 
2399
                                }
 
2400
                                break;
 
2401
        
 
2402
/* total */     
 
2403
                        case COLUMN_PGMRECEIVERNAKSSUPPRESSED:
 
2404
                                {
 
2405
                                        const unsigned naks_suppressed = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_SUPPRESSED];
 
2406
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2407
                                                                  (const u_char*)&naks_suppressed, sizeof(naks_suppressed) );
 
2408
                                }
 
2409
                                break;
 
2410
        
 
2411
/* bogus: same as source checksum errors */     
 
2412
                        case COLUMN_PGMRECEIVERCKSUMERRORS:
 
2413
                                {
 
2414
                                        const unsigned cksum_errors = sock->cumulative_stats[PGM_PC_SOURCE_CKSUM_ERRORS];
 
2415
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2416
                                                                  (const u_char*)&cksum_errors, sizeof(cksum_errors) );
 
2417
                                }
 
2418
                                break;
 
2419
                
 
2420
                        case COLUMN_PGMRECEIVERMALFORMEDSPMS:
 
2421
                                {
 
2422
                                        const unsigned malformed_spms = peer->cumulative_stats[PGM_PC_RECEIVER_MALFORMED_SPMS];
 
2423
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2424
                                                                  (const u_char*)&malformed_spms, sizeof(malformed_spms) );
 
2425
                                }
 
2426
                                break;
 
2427
                
 
2428
                        case COLUMN_PGMRECEIVERMALFORMEDODATA:
 
2429
                                {
 
2430
                                        const unsigned malformed_odata = peer->cumulative_stats[PGM_PC_RECEIVER_MALFORMED_ODATA];
 
2431
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2432
                                                                  (const u_char*)&malformed_odata, sizeof(malformed_odata) );
 
2433
                                }
 
2434
                                break;
 
2435
                
 
2436
                        case COLUMN_PGMRECEIVERMALFORMEDRDATA:
 
2437
                                {
 
2438
                                        const unsigned malformed_rdata = peer->cumulative_stats[PGM_PC_RECEIVER_MALFORMED_RDATA];
 
2439
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2440
                                                                  (const u_char*)&malformed_rdata, sizeof(malformed_rdata) );
 
2441
                                }
 
2442
                                break;
 
2443
                
 
2444
                        case COLUMN_PGMRECEIVERMALFORMEDNCFS:
 
2445
                                {
 
2446
                                        const unsigned malformed_ncfs = peer->cumulative_stats[PGM_PC_RECEIVER_MALFORMED_NCFS];
 
2447
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2448
                                                                  (const u_char*)&malformed_ncfs, sizeof(malformed_ncfs) );
 
2449
                                }
 
2450
                                break;
 
2451
                
 
2452
                        case COLUMN_PGMRECEIVERPACKETSDISCARDED:
 
2453
                                {
 
2454
                                        const unsigned packets_discarded = peer->cumulative_stats[PGM_PC_RECEIVER_PACKETS_DISCARDED];
 
2455
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2456
                                                                  (const u_char*)&packets_discarded, sizeof(packets_discarded) );
 
2457
                                }
 
2458
                                break;
 
2459
                
 
2460
                        case COLUMN_PGMRECEIVERLOSSES:
 
2461
                                {
 
2462
                                        const unsigned losses = window->cumulative_losses;
 
2463
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2464
                                                                  (const u_char*)&losses, sizeof(losses) );
 
2465
                                }
 
2466
                                break;
 
2467
                
 
2468
                        case COLUMN_PGMRECEIVERBYTESDELIVEREDTOAPP:
 
2469
                                {
 
2470
                                        const unsigned bytes_delivered = window->bytes_delivered;
 
2471
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2472
                                                                  (const u_char*)&bytes_delivered, sizeof(bytes_delivered) );
 
2473
                                }
 
2474
                                break;
 
2475
                
 
2476
                        case COLUMN_PGMRECEIVERMSGSDELIVEREDTOAPP:
 
2477
                                {
 
2478
                                        const unsigned msgs_delivered = window->msgs_delivered;
 
2479
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2480
                                                                  (const u_char*)&msgs_delivered, sizeof(msgs_delivered) );
 
2481
                                }
 
2482
                                break;
 
2483
                
 
2484
                        case COLUMN_PGMRECEIVERDUPSPMS:
 
2485
                                {
 
2486
                                        const unsigned dup_spms = peer->cumulative_stats[PGM_PC_RECEIVER_DUP_SPMS];
 
2487
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2488
                                                                  (const u_char*)&dup_spms, sizeof(dup_spms) );
 
2489
                                }
 
2490
                                break;
 
2491
                
 
2492
                        case COLUMN_PGMRECEIVERDUPDATAS:
 
2493
                                {
 
2494
                                        const unsigned dup_data = peer->cumulative_stats[PGM_PC_RECEIVER_DUP_DATAS];
 
2495
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2496
                                                                  (const u_char*)&dup_data, sizeof(dup_data) );
 
2497
                                }
 
2498
                                break;
 
2499
        
 
2500
/* FIXED: 0 */  
 
2501
                        case COLUMN_PGMRECEIVERDUPPARITIES:
 
2502
                                {
 
2503
                                        const unsigned dup_parity = 0;
 
2504
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2505
                                                                  (const u_char*)&dup_parity, sizeof(dup_parity) );
 
2506
                                }
 
2507
                                break;
 
2508
        
 
2509
/* COLUMN_PGMRECEIVERPARITYNAKPACKETSSENT + COLUMN_PGMRECEIVERSELECTIVENAKPACKETSSENT */        
 
2510
                        case COLUMN_PGMRECEIVERNAKPACKETSSENT:
 
2511
                                {
 
2512
                                        const unsigned nak_packets = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAK_PACKETS_SENT];
 
2513
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2514
                                                                  (const u_char*)&nak_packets, sizeof(nak_packets) );
 
2515
                                }
 
2516
                                break;
 
2517
        
 
2518
/* FIXED: 0 */  
 
2519
                        case COLUMN_PGMRECEIVERPARITYNAKPACKETSSENT:
 
2520
                                {
 
2521
                                        const unsigned parity_naks = 0;
 
2522
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2523
                                                                  (const u_char*)&parity_naks, sizeof(parity_naks) );
 
2524
                                }
 
2525
                                break;
 
2526
                
 
2527
                        case COLUMN_PGMRECEIVERSELECTIVENAKPACKETSSENT:
 
2528
                                {
 
2529
                                        const unsigned nak_packets = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAK_PACKETS_SENT];
 
2530
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2531
                                                                  (const u_char*)&nak_packets, sizeof(nak_packets) );
 
2532
                                }
 
2533
                                break;
 
2534
        
 
2535
/* FIXED: 0 */  
 
2536
                        case COLUMN_PGMRECEIVERPARITYNAKSSENT:
 
2537
                                {
 
2538
                                        const unsigned parity_naks = 0;
 
2539
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2540
                                                                  (const u_char*)&parity_naks, sizeof(parity_naks) );
 
2541
                                }
 
2542
                                break;
 
2543
                
 
2544
                        case COLUMN_PGMRECEIVERSELECTIVENAKSSENT:
 
2545
                                {
 
2546
                                        const unsigned naks_sent = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_SENT];
 
2547
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2548
                                                                  (const u_char*)&naks_sent, sizeof(naks_sent) );
 
2549
                                }
 
2550
                                break;
 
2551
        
 
2552
/* FIXED: 0 */  
 
2553
                        case COLUMN_PGMRECEIVERPARITYNAKSRETRANSMITTED:
 
2554
                                {
 
2555
                                        const unsigned parity_resent = 0;
 
2556
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2557
                                                                  (const u_char*)&parity_resent, sizeof(parity_resent) );
 
2558
                                }
 
2559
                                break;
 
2560
                
 
2561
                        case COLUMN_PGMRECEIVERSELECTIVENAKSRETRANSMITTED:
 
2562
                                {
 
2563
                                        const unsigned naks_resent = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_RETRANSMITTED];
 
2564
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2565
                                                                  (const u_char*)&naks_resent, sizeof(naks_resent) );
 
2566
                                }
 
2567
                                break;
 
2568
        
 
2569
/* COLUMN_PGMRECEIVERPARITYNAKSFAILED + COLUMN_PGMRECEIVERSELECTIVENAKSFAILED */        
 
2570
                        case COLUMN_PGMRECEIVERNAKSFAILED:
 
2571
                                {
 
2572
                                        const unsigned naks_failed = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_FAILED];
 
2573
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2574
                                                                  (const u_char*)&naks_failed, sizeof(naks_failed) );
 
2575
                                }
 
2576
                                break;
 
2577
        
 
2578
/* FIXED: 0 */  
 
2579
                        case COLUMN_PGMRECEIVERPARITYNAKSFAILED:
 
2580
                                {
 
2581
                                        const unsigned parity_failed = 0;
 
2582
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2583
                                                                  (const u_char*)&parity_failed, sizeof(parity_failed) );
 
2584
                                }
 
2585
                                break;
 
2586
                
 
2587
                        case COLUMN_PGMRECEIVERSELECTIVENAKSFAILED:
 
2588
                                {
 
2589
                                        const unsigned naks_failed = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_FAILED];
 
2590
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2591
                                                                  (const u_char*)&naks_failed, sizeof(naks_failed) );
 
2592
                                }
 
2593
                                break;
 
2594
                
 
2595
                        case COLUMN_PGMRECEIVERNAKSFAILEDRXWADVANCED:
 
2596
                                {
 
2597
                                        const unsigned rxw_failed = peer->cumulative_stats[PGM_PC_RECEIVER_NAKS_FAILED_RXW_ADVANCED];
 
2598
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2599
                                                                  (const u_char*)&rxw_failed, sizeof(rxw_failed) );
 
2600
                                }
 
2601
                                break;
 
2602
                
 
2603
                        case COLUMN_PGMRECEIVERNAKSFALEDNCFRETRIESEXCEEDED:
 
2604
                                {
 
2605
                                        const unsigned ncf_retries = peer->cumulative_stats[PGM_PC_RECEIVER_NAKS_FAILED_NCF_RETRIES_EXCEEDED];
 
2606
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2607
                                                                  (const u_char*)&ncf_retries, sizeof(ncf_retries) );
 
2608
                                }
 
2609
                                break;
 
2610
                
 
2611
                        case COLUMN_PGMRECEIVERNAKSFAILEDDATARETRIESEXCEEDED:
 
2612
                                {
 
2613
                                        const unsigned data_retries = peer->cumulative_stats[PGM_PC_RECEIVER_NAKS_FAILED_DATA_RETRIES_EXCEEDED];
 
2614
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2615
                                                                  (const u_char*)&data_retries, sizeof(data_retries) );
 
2616
                                }
 
2617
                                break;
 
2618
        
 
2619
/* FIXED: 0 - absolutely no idea what this means */     
 
2620
                        case COLUMN_PGMRECEIVERNAKSFAILEDGENEXPIRED:
 
2621
                                {
 
2622
                                        const unsigned happy_pandas = 0;
 
2623
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2624
                                                                  (const u_char*)&happy_pandas, sizeof(happy_pandas) );
 
2625
                                }
 
2626
                                break;
 
2627
                
 
2628
                        case COLUMN_PGMRECEIVERNAKFAILURESDELIVERED:
 
2629
                                {
 
2630
                                        const unsigned delivered = peer->cumulative_stats[PGM_PC_RECEIVER_NAK_FAILURES_DELIVERED];
 
2631
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2632
                                                                  (const u_char*)&delivered, sizeof(delivered) );
 
2633
                                }
 
2634
                                break;
 
2635
        
 
2636
/* FIXED: 0 */  
 
2637
                        case COLUMN_PGMRECEIVERPARITYNAKSSUPPRESSED:
 
2638
                                {
 
2639
                                        const unsigned suppressed = 0;
 
2640
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2641
                                                                  (const u_char*)&suppressed, sizeof(suppressed) );
 
2642
                                }
 
2643
                                break;
 
2644
                
 
2645
                        case COLUMN_PGMRECEIVERSELECTIVENAKSSUPPRESSED:
 
2646
                                {
 
2647
                                        const unsigned suppressed = peer->cumulative_stats[PGM_PC_RECEIVER_SELECTIVE_NAKS_SUPPRESSED];
 
2648
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2649
                                                                  (const u_char*)&suppressed, sizeof(suppressed) );
 
2650
                                }
 
2651
                                break;
 
2652
                
 
2653
                        case COLUMN_PGMRECEIVERNAKERRORS:
 
2654
                                {
 
2655
                                        const unsigned malformed_naks = peer->cumulative_stats[PGM_PC_RECEIVER_NAK_ERRORS];
 
2656
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2657
                                                                  (const u_char*)&malformed_naks, sizeof(malformed_naks) );
 
2658
                                }
 
2659
                                break;
 
2660
        
 
2661
/* FIXED: 0 */  
 
2662
                        case COLUMN_PGMRECEIVEROUTSTANDINGPARITYNAKS:
 
2663
                                {
 
2664
                                        const unsigned outstanding_parity = 0;
 
2665
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2666
                                                                  (const u_char*)&outstanding_parity, sizeof(outstanding_parity) );
 
2667
                                }
 
2668
                                break;
 
2669
                
 
2670
                        case COLUMN_PGMRECEIVEROUTSTANDINGSELECTIVENAKS:
 
2671
                                {
 
2672
                                        const unsigned outstanding_selective = window->nak_backoff_queue.length +
 
2673
                                                                                window->wait_ncf_queue.length +
 
2674
                                                                                window->wait_data_queue.length;
 
2675
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2676
                                                                  (const u_char*)&outstanding_selective, sizeof(outstanding_selective) );
 
2677
                                }
 
2678
                                break;
 
2679
                
 
2680
                        case COLUMN_PGMRECEIVERLASTACTIVITY:
 
2681
                                {
 
2682
                                        union {
 
2683
                                                unsigned        uint_value;
 
2684
                                                time_t          time_t_value;
 
2685
                                        } last_activity;
 
2686
                                        pgm_time_since_epoch (&peer->last_packet, &last_activity.time_t_value);
 
2687
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2688
                                                                  (const u_char*)&last_activity.uint_value, sizeof(last_activity.uint_value) );
 
2689
                                }
 
2690
                                break;
 
2691
                
 
2692
                        case COLUMN_PGMRECEIVERNAKSVCTIMEMIN:
 
2693
                                {
 
2694
                                        const unsigned min_repair_time = window->min_fill_time;
 
2695
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2696
                                                                  (const u_char*)&min_repair_time, sizeof(min_repair_time) );
 
2697
                                }
 
2698
                                break;
 
2699
                
 
2700
                        case COLUMN_PGMRECEIVERNAKSVCTIMEMEAN:
 
2701
                                {
 
2702
                                        const unsigned mean_repair_time = peer->cumulative_stats[PGM_PC_RECEIVER_NAK_SVC_TIME_MEAN];
 
2703
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2704
                                                                  (const u_char*)&mean_repair_time, sizeof(mean_repair_time) );
 
2705
                                }
 
2706
                                break;
 
2707
                
 
2708
                        case COLUMN_PGMRECEIVERNAKSVCTIMEMAX:
 
2709
                                {
 
2710
                                        const unsigned max_repair_time = window->max_fill_time;
 
2711
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2712
                                                                  (const u_char*)&max_repair_time, sizeof(max_repair_time) );
 
2713
                                }
 
2714
                                break;
 
2715
                
 
2716
                        case COLUMN_PGMRECEIVERNAKFAILTIMEMIN:
 
2717
                                {
 
2718
                                        const unsigned min_fail_time = peer->min_fail_time;
 
2719
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2720
                                                                  (const u_char*)&min_fail_time, sizeof(min_fail_time) );
 
2721
                                }
 
2722
                                break;
 
2723
                
 
2724
                        case COLUMN_PGMRECEIVERNAKFAILTIMEMEAN:
 
2725
                                {
 
2726
                                        const unsigned mean_fail_time = peer->cumulative_stats[PGM_PC_RECEIVER_NAK_FAIL_TIME_MEAN];
 
2727
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2728
                                                                  (const u_char*)&mean_fail_time, sizeof(mean_fail_time) );
 
2729
                                }
 
2730
                                break;
 
2731
                
 
2732
                        case COLUMN_PGMRECEIVERNAKFAILTIMEMAX:
 
2733
                                {
 
2734
                                        const unsigned max_fail_time = peer->max_fail_time;
 
2735
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2736
                                                                  (const u_char*)&max_fail_time, sizeof(max_fail_time) );
 
2737
                                }
 
2738
                                break;
 
2739
                
 
2740
                        case COLUMN_PGMRECEIVERNAKTRANSMITMIN:
 
2741
                                {
 
2742
                                        const unsigned min_transmit_count = window->min_nak_transmit_count;
 
2743
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2744
                                                                  (const u_char*)&min_transmit_count, sizeof(min_transmit_count) );
 
2745
                                }
 
2746
                                break;
 
2747
                
 
2748
                        case COLUMN_PGMRECEIVERNAKTRANSMITMEAN:
 
2749
                                {
 
2750
                                        const unsigned mean_transmit_count = peer->cumulative_stats[PGM_PC_RECEIVER_TRANSMIT_MEAN];
 
2751
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2752
                                                                  (const u_char*)&mean_transmit_count, sizeof(mean_transmit_count) );
 
2753
                                }
 
2754
                                break;
 
2755
                
 
2756
                        case COLUMN_PGMRECEIVERNAKTRANSMITMAX:
 
2757
                                {
 
2758
                                        const unsigned max_transmit_count = window->max_nak_transmit_count;
 
2759
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2760
                                                                  (const u_char*)&max_transmit_count, sizeof(max_transmit_count) );
 
2761
                                }
 
2762
                                break;
 
2763
        
 
2764
                        case COLUMN_PGMRECEIVERACKSSENT:
 
2765
                                {
 
2766
                                        const unsigned acks_sent = peer->cumulative_stats[PGM_PC_RECEIVER_ACKS_SENT];
 
2767
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2768
                                                                  (const u_char*)&acks_sent, sizeof(acks_sent) );
 
2769
                                }
 
2770
                                break;
 
2771
                
 
2772
                        case COLUMN_PGMRECEIVERRXWTRAIL:
 
2773
                                {
 
2774
                                        const unsigned rxw_trail = window->rxw_trail;
 
2775
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2776
                                                                  (const u_char*)&rxw_trail, sizeof(rxw_trail) );
 
2777
                                }
 
2778
                                break;
 
2779
                
 
2780
                        case COLUMN_PGMRECEIVERRXWLEAD:
 
2781
                                {
 
2782
                                        const unsigned rxw_lead = window->lead;
 
2783
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2784
                                                                  (const u_char*)&rxw_lead, sizeof(rxw_lead) );
 
2785
                                }
 
2786
                                break;
 
2787
        
 
2788
/* TODO: traps */       
 
2789
                        case COLUMN_PGMRECEIVERNAKFAILURESLASTINTERVAL:
 
2790
                        case COLUMN_PGMRECEIVERLASTINTERVALNAKFAILURES:
 
2791
                                {
 
2792
                                        const unsigned failures = 0;
 
2793
                                        snmp_set_var_typed_value (var, ASN_COUNTER, /* ASN_COUNTER32 */
 
2794
                                                                  (const u_char*)&failures, sizeof(failures) );
 
2795
                                }
 
2796
                                break;
 
2797
 
 
2798
                        default:
 
2799
                                snmp_log (LOG_ERR, "pgmReceiverTable_handler: unknown column.\n");
 
2800
                                break;
 
2801
                        }
 
2802
                }
 
2803
                break;
 
2804
 
 
2805
        case MODE_SET_RESERVE1:
 
2806
        default:
 
2807
                snmp_log (LOG_ERR, "pgmReceiverTable_handler: unsupported mode.\n");
 
2808
                break;
 
2809
 
 
2810
        }
 
2811
 
 
2812
        return SNMP_ERR_NOERROR;
 
2813
}
 
2814
 
 
2815
/*
 
2816
 * SNMP TRAPS
 
2817
 */
 
2818
 
 
2819
PGM_GNUC_INTERNAL
 
2820
int
 
2821
send_pgmStart_trap (void)
 
2822
{
 
2823
        pgm_debug ("send_pgmStart_trap ()");
 
2824
 
 
2825
        netsnmp_variable_list  *var_list = NULL;
 
2826
        static const oid pgmStart_oid[] = { 1,3,6,1,3,112,2,0,1 };
 
2827
 
 
2828
/*
 
2829
 * Set the snmpTrapOid.0 value
 
2830
 */
 
2831
        snmp_varlist_add_variable (&var_list,
 
2832
                                   snmptrap_oid, OID_LENGTH( snmptrap_oid ),
 
2833
                                   ASN_OBJECT_ID,
 
2834
                                   (const u_char*)pgmStart_oid, sizeof(pgmStart_oid));
 
2835
/*
 
2836
 * Add any extra (optional) objects here
 
2837
 */
 
2838
 
 
2839
/*
 
2840
 * Send the trap to the list of configured destinations
 
2841
 *  and clean up
 
2842
 */
 
2843
        send_v2trap (var_list);
 
2844
        snmp_free_varbind (var_list);
 
2845
        return SNMP_ERR_NOERROR;
 
2846
}
 
2847
 
 
2848
PGM_GNUC_INTERNAL
 
2849
int
 
2850
send_pgmStop_trap (void)
 
2851
{
 
2852
        pgm_debug ("send_pgmStop_trap ()");
 
2853
 
 
2854
        netsnmp_variable_list  *var_list = NULL;
 
2855
        static const oid pgmStop_oid[] = { 1,3,6,1,3,112,2,0,2 };
 
2856
 
 
2857
/*
 
2858
 * Set the snmpTrapOid.0 value
 
2859
 */
 
2860
        snmp_varlist_add_variable (&var_list,
 
2861
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
2862
                                   ASN_OBJECT_ID,
 
2863
                                   (const u_char*)pgmStop_oid, sizeof(pgmStop_oid));
 
2864
    
 
2865
 
 
2866
/*
 
2867
 * Add any extra (optional) objects here
 
2868
 */
 
2869
 
 
2870
/*
 
2871
 * Send the trap to the list of configured destinations
 
2872
 *  and clean up
 
2873
 */
 
2874
        send_v2trap (var_list);
 
2875
        snmp_free_varbind (var_list);
 
2876
        return SNMP_ERR_NOERROR;
 
2877
}
 
2878
 
 
2879
PGM_GNUC_INTERNAL
 
2880
int
 
2881
send_pgmNewSourceTrap_trap (void)
 
2882
{
 
2883
        pgm_debug ("send_pgmNewSourceTrap_trap ()");
 
2884
 
 
2885
        netsnmp_variable_list  *var_list = NULL;
 
2886
        static const oid pgmNewSourceTrap_oid[] = { 1,3,6,1,3,112,2,0,3 };
 
2887
        static const oid pgmSourceSourceGsi_oid[] = { 1,3,6,1,3,112,1,2,100,2,1,6, /* insert index here */ };
 
2888
        static const oid pgmSourceSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,2,100,2,1,7, /* insert index here */ };
 
2889
 
 
2890
/*
 
2891
 * Set the snmpTrapOid.0 value
 
2892
 */
 
2893
        snmp_varlist_add_variable (&var_list,
 
2894
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
2895
                                   ASN_OBJECT_ID,
 
2896
                                   (const u_char*)pgmNewSourceTrap_oid, sizeof(pgmNewSourceTrap_oid));
 
2897
/*
 
2898
 * Add any objects from the trap definition
 
2899
 */
 
2900
        snmp_varlist_add_variable (&var_list,
 
2901
                                   pgmSourceSourceGsi_oid, OID_LENGTH(pgmSourceSourceGsi_oid),
 
2902
                                   ASN_OCTET_STR,
 
2903
/* Set an appropriate value for pgmSourceSourceGsi */
 
2904
                                   NULL, 0);
 
2905
        snmp_varlist_add_variable (&var_list,
 
2906
                                   pgmSourceSourcePortNumber_oid, OID_LENGTH(pgmSourceSourcePortNumber_oid),
 
2907
                                   ASN_UNSIGNED,
 
2908
/* Set an appropriate value for pgmSourceSourcePortNumber */
 
2909
                                   NULL, 0);
 
2910
/*
 
2911
 * Add any extra (optional) objects here
 
2912
 */
 
2913
 
 
2914
/*
 
2915
 * Send the trap to the list of configured destinations
 
2916
 *  and clean up
 
2917
 */
 
2918
        send_v2trap (var_list);
 
2919
        snmp_free_varbind (var_list);
 
2920
        return SNMP_ERR_NOERROR;
 
2921
}
 
2922
 
 
2923
PGM_GNUC_INTERNAL
 
2924
int
 
2925
send_pgmClosedSourceTrap_trap (void)
 
2926
{
 
2927
        pgm_debug ("send_pgmClosedSourceTrap_trap ()");
 
2928
 
 
2929
        netsnmp_variable_list  *var_list = NULL;
 
2930
        static const oid pgmClosedSourceTrap_oid[] = { 1,3,6,1,3,112,2,0,4 };
 
2931
        static const oid pgmSourceSourceGsi_oid[] = { 1,3,6,1,3,112,1,2,100,2,1,6, /* insert index here */ };
 
2932
        static const oid pgmSourceSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,2,100,2,1,7, /* insert index here */ };
 
2933
 
 
2934
/*
 
2935
 * Set the snmpTrapOid.0 value
 
2936
 */
 
2937
        snmp_varlist_add_variable (&var_list,
 
2938
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
2939
                                   ASN_OBJECT_ID,
 
2940
                                   (const u_char*)pgmClosedSourceTrap_oid, sizeof(pgmClosedSourceTrap_oid));
 
2941
/*
 
2942
 * Add any objects from the trap definition
 
2943
 */
 
2944
        snmp_varlist_add_variable (&var_list,
 
2945
                                   pgmSourceSourceGsi_oid, OID_LENGTH(pgmSourceSourceGsi_oid),
 
2946
                                   ASN_OCTET_STR,
 
2947
/* Set an appropriate value for pgmSourceSourceGsi */
 
2948
                                   NULL, 0);
 
2949
        snmp_varlist_add_variable (&var_list,
 
2950
                                   pgmSourceSourcePortNumber_oid, OID_LENGTH(pgmSourceSourcePortNumber_oid),
 
2951
                                   ASN_UNSIGNED,
 
2952
/* Set an appropriate value for pgmSourceSourcePortNumber */
 
2953
                                   NULL, 0);
 
2954
/*
 
2955
 * Add any extra (optional) objects here
 
2956
 */
 
2957
 
 
2958
/*
 
2959
 * Send the trap to the list of configured destinations
 
2960
 *  and clean up
 
2961
 */
 
2962
        send_v2trap (var_list);
 
2963
        snmp_free_varbind (var_list);
 
2964
        return SNMP_ERR_NOERROR;
 
2965
}
 
2966
 
 
2967
PGM_GNUC_INTERNAL
 
2968
int
 
2969
send_pgmNewReceiverTrap_trap (void)
 
2970
{
 
2971
        pgm_debug ("send_pgmNewReceiverTrap_trap ()");
 
2972
 
 
2973
        netsnmp_variable_list  *var_list = NULL;
 
2974
        static const oid pgmNewReceiverTrap_oid[] = { 1,3,6,1,3,112,2,0,5 };
 
2975
        static const oid pgmReceiverSourceGsi_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,8, /* insert index here */ };
 
2976
        static const oid pgmReceiverSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,9, /* insert index here */ };
 
2977
        static const oid pgmReceiverUniqueInstance_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,10, /* insert index here */ };
 
2978
 
 
2979
/*
 
2980
 * Set the snmpTrapOid.0 value
 
2981
 */
 
2982
        snmp_varlist_add_variable (&var_list,
 
2983
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
2984
                                   ASN_OBJECT_ID,
 
2985
                                   (const u_char*)pgmNewReceiverTrap_oid, sizeof(pgmNewReceiverTrap_oid));
 
2986
/*
 
2987
 * Add any objects from the trap definition
 
2988
 */
 
2989
        snmp_varlist_add_variable (&var_list,
 
2990
                                   pgmReceiverSourceGsi_oid, OID_LENGTH(pgmReceiverSourceGsi_oid),
 
2991
                                   ASN_OCTET_STR,
 
2992
/* Set an appropriate value for pgmReceiverSourceGsi */
 
2993
                                   NULL, 0);
 
2994
        snmp_varlist_add_variable (&var_list,
 
2995
                                   pgmReceiverSourcePortNumber_oid, OID_LENGTH(pgmReceiverSourcePortNumber_oid),
 
2996
                                   ASN_UNSIGNED,
 
2997
/* Set an appropriate value for pgmReceiverSourcePortNumber */
 
2998
                                   NULL, 0);
 
2999
        snmp_varlist_add_variable (&var_list,
 
3000
                                   pgmReceiverUniqueInstance_oid, OID_LENGTH(pgmReceiverUniqueInstance_oid),
 
3001
                                   ASN_UNSIGNED,
 
3002
/* Set an appropriate value for pgmReceiverUniqueInstance */
 
3003
                                   NULL, 0);
 
3004
/*
 
3005
 * Add any extra (optional) objects here
 
3006
 */
 
3007
 
 
3008
/*
 
3009
 * Send the trap to the list of configured destinations
 
3010
 *  and clean up
 
3011
 */
 
3012
        send_v2trap (var_list);
 
3013
        snmp_free_varbind (var_list);
 
3014
        return SNMP_ERR_NOERROR;
 
3015
}
 
3016
 
 
3017
PGM_GNUC_INTERNAL
 
3018
int
 
3019
send_pgmClosedReceiverTrap_trap (void)
 
3020
{
 
3021
        pgm_debug ("send_pgmClosedReceiverTrap_trap ()");
 
3022
 
 
3023
        netsnmp_variable_list  *var_list = NULL;
 
3024
        static const oid pgmClosedReceiverTrap_oid[] = { 1,3,6,1,3,112,2,0,6 };
 
3025
        static const oid pgmReceiverSourceGsi_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,8, /* insert index here */ };
 
3026
        static const oid pgmReceiverSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,9, /* insert index here */ };
 
3027
        static const oid pgmReceiverUniqueInstance_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,10, /* insert index here */ };
 
3028
 
 
3029
/*
 
3030
 * Set the snmpTrapOid.0 value
 
3031
 */
 
3032
        snmp_varlist_add_variable (&var_list,
 
3033
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
3034
                                   ASN_OBJECT_ID,
 
3035
                                   (const u_char*)pgmClosedReceiverTrap_oid, sizeof(pgmClosedReceiverTrap_oid));
 
3036
/*
 
3037
 * Add any objects from the trap definition
 
3038
 */
 
3039
        snmp_varlist_add_variable (&var_list,
 
3040
                                   pgmReceiverSourceGsi_oid, OID_LENGTH(pgmReceiverSourceGsi_oid),
 
3041
                                   ASN_OCTET_STR,
 
3042
/* Set an appropriate value for pgmReceiverSourceGsi */
 
3043
                                   NULL, 0);
 
3044
        snmp_varlist_add_variable (&var_list,
 
3045
                                   pgmReceiverSourcePortNumber_oid, OID_LENGTH(pgmReceiverSourcePortNumber_oid),
 
3046
                                   ASN_UNSIGNED,
 
3047
/* Set an appropriate value for pgmReceiverSourcePortNumber */
 
3048
                                   NULL, 0);
 
3049
        snmp_varlist_add_variable (&var_list,
 
3050
                                   pgmReceiverUniqueInstance_oid, OID_LENGTH(pgmReceiverUniqueInstance_oid),
 
3051
                                   ASN_UNSIGNED,
 
3052
/* Set an appropriate value for pgmReceiverUniqueInstance */
 
3053
                                   NULL, 0);
 
3054
/*
 
3055
 * Add any extra (optional) objects here
 
3056
 */
 
3057
 
 
3058
/*
 
3059
 * Send the trap to the list of configured destinations
 
3060
 *  and clean up
 
3061
 */
 
3062
        send_v2trap (var_list);
 
3063
        snmp_free_varbind (var_list);
 
3064
        return SNMP_ERR_NOERROR;
 
3065
}
 
3066
 
 
3067
PGM_GNUC_INTERNAL
 
3068
int
 
3069
send_pgmNakFailuresTrap_trap (void)
 
3070
{
 
3071
        pgm_debug ("send_pgmNakFailuresTrap_trap ()");
 
3072
 
 
3073
        netsnmp_variable_list  *var_list = NULL;
 
3074
        static const oid pgmNakFailuresTrap_oid[] = { 1,3,6,1,3,112,2,0,7 };
 
3075
        static const oid pgmReceiverSourceGsi_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,8, /* insert index here */ };
 
3076
        static const oid pgmReceiverSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,9, /* insert index here */ };
 
3077
        static const oid pgmReceiverUniqueInstance_oid[] = { 1,3,6,1,3,112,1,3,100,2,1,10, /* insert index here */ };
 
3078
        static const oid pgmReceiverNakFailureThresholdTimer_oid[] = { 1,3,6,1,3,112,1,3,100,3,1,14, /* insert index here */ };
 
3079
        static const oid pgmReceiverNakFailureThreshold_oid[] = { 1,3,6,1,3,112,1,3,100,3,1,15, /* insert index here */ };
 
3080
        static const oid pgmReceiverNakFailuresLastInterval_oid[] = { 1,3,6,1,3,112,1,3,100,4,1,56, /* insert index here */ };
 
3081
        static const oid pgmReceiverLastIntervalNakFailures_oid[] = { 1,3,6,1,3,112,1,3,100,4,1,57, /* insert index here */ };
 
3082
 
 
3083
/*
 
3084
 * Set the snmpTrapOid.0 value
 
3085
 */
 
3086
        snmp_varlist_add_variable (&var_list,
 
3087
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
3088
                                   ASN_OBJECT_ID,
 
3089
                                   (const u_char*)pgmNakFailuresTrap_oid, sizeof(pgmNakFailuresTrap_oid));
 
3090
/*
 
3091
 * Add any objects from the trap definition
 
3092
 */
 
3093
        snmp_varlist_add_variable (&var_list,
 
3094
                                   pgmReceiverSourceGsi_oid, OID_LENGTH(pgmReceiverSourceGsi_oid),
 
3095
                                   ASN_OCTET_STR,
 
3096
/* Set an appropriate value for pgmReceiverSourceGsi */
 
3097
                                   NULL, 0);
 
3098
        snmp_varlist_add_variable (&var_list,
 
3099
                                   pgmReceiverSourcePortNumber_oid, OID_LENGTH(pgmReceiverSourcePortNumber_oid),
 
3100
                                   ASN_UNSIGNED,
 
3101
/* Set an appropriate value for pgmReceiverSourcePortNumber */
 
3102
        NULL, 0);
 
3103
        snmp_varlist_add_variable (&var_list,
 
3104
                                   pgmReceiverUniqueInstance_oid, OID_LENGTH(pgmReceiverUniqueInstance_oid),
 
3105
                                   ASN_UNSIGNED,
 
3106
/* Set an appropriate value for pgmReceiverUniqueInstance */
 
3107
                                   NULL, 0);
 
3108
        snmp_varlist_add_variable (&var_list,
 
3109
                                   pgmReceiverNakFailureThresholdTimer_oid, OID_LENGTH(pgmReceiverNakFailureThresholdTimer_oid),
 
3110
                                   ASN_UNSIGNED,
 
3111
/* Set an appropriate value for pgmReceiverNakFailureThresholdTimer */
 
3112
                                   NULL, 0);
 
3113
        snmp_varlist_add_variable (&var_list,
 
3114
                                   pgmReceiverNakFailureThreshold_oid, OID_LENGTH(pgmReceiverNakFailureThreshold_oid),
 
3115
                                   ASN_UNSIGNED,
 
3116
/* Set an appropriate value for pgmReceiverNakFailureThreshold */
 
3117
                                   NULL, 0);
 
3118
        snmp_varlist_add_variable (&var_list,
 
3119
                                   pgmReceiverNakFailuresLastInterval_oid, OID_LENGTH(pgmReceiverNakFailuresLastInterval_oid),
 
3120
                                   ASN_COUNTER,
 
3121
/* Set an appropriate value for pgmReceiverNakFailuresLastInterval */
 
3122
                                   NULL, 0);
 
3123
        snmp_varlist_add_variable (&var_list,
 
3124
                                   pgmReceiverLastIntervalNakFailures_oid, OID_LENGTH(pgmReceiverLastIntervalNakFailures_oid),
 
3125
                                   ASN_COUNTER,
 
3126
/* Set an appropriate value for pgmReceiverLastIntervalNakFailures */
 
3127
                                   NULL, 0);
 
3128
/*
 
3129
 * Add any extra (optional) objects here
 
3130
 */
 
3131
 
 
3132
/*
 
3133
 * Send the trap to the list of configured destinations
 
3134
 *  and clean up
 
3135
 */
 
3136
        send_v2trap (var_list);
 
3137
        snmp_free_varbind (var_list);
 
3138
        return SNMP_ERR_NOERROR;
 
3139
}
 
3140
 
 
3141
PGM_GNUC_INTERNAL
 
3142
int
 
3143
send_pgmNewDlrSourceTrap_trap (void)
 
3144
{
 
3145
        pgm_debug ("send_pgmNewDlrSourceTrap_trap ()");
 
3146
 
 
3147
        netsnmp_variable_list  *var_list = NULL;
 
3148
        static const oid pgmNewDlrSourceTrap_oid[] = { 1,3,6,1,3,112,2,0,8 };
 
3149
        static const oid pgmDlrSourceSourceGsi_oid[] = { 1,3,6,1,3,112,1,4,100,2,1,4, /* insert index here */ };
 
3150
        static const oid pgmDlrSourceSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,4,100,2,1,5, /* insert index here */ };
 
3151
 
 
3152
/*
 
3153
 * Set the snmpTrapOid.0 value
 
3154
 */
 
3155
        snmp_varlist_add_variable (&var_list,
 
3156
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
3157
                                   ASN_OBJECT_ID,
 
3158
                                   (const u_char*)pgmNewDlrSourceTrap_oid, sizeof(pgmNewDlrSourceTrap_oid));
 
3159
/*
 
3160
 * Add any objects from the trap definition
 
3161
 */
 
3162
        snmp_varlist_add_variable (&var_list,
 
3163
                                   pgmDlrSourceSourceGsi_oid, OID_LENGTH(pgmDlrSourceSourceGsi_oid),
 
3164
                                   ASN_OCTET_STR,
 
3165
/* Set an appropriate value for pgmDlrSourceSourceGsi */
 
3166
                                   NULL, 0);
 
3167
        snmp_varlist_add_variable (&var_list,
 
3168
                                   pgmDlrSourceSourcePortNumber_oid, OID_LENGTH(pgmDlrSourceSourcePortNumber_oid),
 
3169
                                   ASN_UNSIGNED,
 
3170
/* Set an appropriate value for pgmDlrSourceSourcePortNumber */
 
3171
                                   NULL, 0);
 
3172
/*
 
3173
 * Add any extra (optional) objects here
 
3174
 */
 
3175
 
 
3176
/*
 
3177
 * Send the trap to the list of configured destinations
 
3178
 *  and clean up
 
3179
 */
 
3180
        send_v2trap (var_list);
 
3181
        snmp_free_varbind (var_list);
 
3182
        return SNMP_ERR_NOERROR;
 
3183
}
 
3184
 
 
3185
PGM_GNUC_INTERNAL
 
3186
int
 
3187
send_pgmClosedDlrSourceTrap_trap (void)
 
3188
{
 
3189
        pgm_debug ("send_pgmClosedDlrSourceTrap_trap ()");
 
3190
 
 
3191
        netsnmp_variable_list  *var_list = NULL;
 
3192
        static const oid pgmClosedDlrSourceTrap_oid[] = { 1,3,6,1,3,112,2,0,9 };
 
3193
        static const oid pgmDlrSourceSourceGsi_oid[] = { 1,3,6,1,3,112,1,4,100,2,1,4, /* insert index here */ };
 
3194
        static const oid pgmDlrSourceSourcePortNumber_oid[] = { 1,3,6,1,3,112,1,4,100,2,1,5, /* insert index here */ };
 
3195
 
 
3196
/*
 
3197
 * Set the snmpTrapOid.0 value
 
3198
 */
 
3199
        snmp_varlist_add_variable (&var_list,
 
3200
                                   snmptrap_oid, OID_LENGTH(snmptrap_oid),
 
3201
                                   ASN_OBJECT_ID,
 
3202
                                   (const u_char*)pgmClosedDlrSourceTrap_oid, sizeof(pgmClosedDlrSourceTrap_oid));
 
3203
    
 
3204
/*
 
3205
 * Add any objects from the trap definition
 
3206
 */
 
3207
        snmp_varlist_add_variable (&var_list,
 
3208
                                   pgmDlrSourceSourceGsi_oid, OID_LENGTH(pgmDlrSourceSourceGsi_oid),
 
3209
                                   ASN_OCTET_STR,
 
3210
/* Set an appropriate value for pgmDlrSourceSourceGsi */
 
3211
                                   NULL, 0);
 
3212
        snmp_varlist_add_variable (&var_list,
 
3213
                                   pgmDlrSourceSourcePortNumber_oid, OID_LENGTH(pgmDlrSourceSourcePortNumber_oid),
 
3214
                                   ASN_UNSIGNED,
 
3215
/* Set an appropriate value for pgmDlrSourceSourcePortNumber */
 
3216
                                   NULL, 0);
 
3217
/*
 
3218
 * Add any extra (optional) objects here
 
3219
 */
 
3220
 
 
3221
/*
 
3222
 * Send the trap to the list of configured destinations
 
3223
 *  and clean up
 
3224
 */
 
3225
        send_v2trap (var_list);
 
3226
        snmp_free_varbind (var_list);
 
3227
        return SNMP_ERR_NOERROR;
 
3228
}
 
3229
 
 
3230
/* eof */