summaryrefslogtreecommitdiff
path: root/agent/helpers/watcher.c
blob: 9b3933b0811e3f8de36c4fdfe6c06dd25763cb12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-features.h>

#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

#include <net-snmp/agent/watcher.h>

#include <net-snmp/agent/instance.h>
#include <net-snmp/agent/scalar.h>

#include <string.h>

#ifdef HAVE_DMALLOC_H
static void free_wrapper(void * p)
{
    free(p);
}
#else
#define free_wrapper free
#endif

netsnmp_feature_provide(watcher_all)
netsnmp_feature_child_of(watcher_all, mib_helpers)
netsnmp_feature_child_of(watcher_create_info6, watcher_all)
netsnmp_feature_child_of(watcher_register_timestamp, watcher_all)
netsnmp_feature_child_of(watcher_ulong_scalar, watcher_all)
netsnmp_feature_child_of(watcher_read_only_ulong_scalar, watcher_all)
netsnmp_feature_child_of(watcher_read_only_int_scalar, watcher_all)
netsnmp_feature_child_of(watcher_long_scalar, watcher_all)
netsnmp_feature_child_of(watcher_read_only_long_scalar, watcher_all)
netsnmp_feature_child_of(watcher_int_scalar, watcher_all)
netsnmp_feature_child_of(read_only_counter32_scalar, watcher_all)
netsnmp_feature_child_of(watcher_spinlock, watcher_all)

/** @defgroup watcher watcher
 *  Watch a specified variable and process it as an instance or scalar object
 *  @ingroup leaf
 *  @{
 */
netsnmp_mib_handler *
netsnmp_get_watcher_handler(void)
{
    netsnmp_mib_handler *ret = NULL;
    
    ret = netsnmp_create_handler("watcher",
                                 netsnmp_watcher_helper_handler);
    if (ret) {
        ret->flags |= MIB_HANDLER_AUTO_NEXT;
    }
    return ret;
}

netsnmp_watcher_info *
netsnmp_init_watcher_info6(netsnmp_watcher_info *winfo,
                           void *data, size_t size, u_char type,
                           int flags, size_t max_size, size_t* size_p)
{
    winfo->data = data;
    winfo->data_size = size;
    winfo->max_size = max_size;
    winfo->type = type;
    winfo->flags = flags;
    winfo->data_size_p = size_p;
    return winfo;
}

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_CREATE_INFO6
netsnmp_watcher_info *
netsnmp_create_watcher_info6(void *data, size_t size, u_char type,
                             int flags, size_t max_size, size_t* size_p)
{
    netsnmp_watcher_info *winfo = SNMP_MALLOC_TYPEDEF(netsnmp_watcher_info);
    if (winfo)
        netsnmp_init_watcher_info6(winfo, data, size, type, flags, max_size,
                                   size_p);
    return winfo;
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_CREATE_INFO6 */

netsnmp_watcher_info *
netsnmp_init_watcher_info(netsnmp_watcher_info *winfo,
                          void *data, size_t size, u_char type, int flags)
{
  return netsnmp_init_watcher_info6(winfo, data, size,
				    type, (flags ? flags : WATCHER_FIXED_SIZE),
				    size,  /* Probably wrong for non-fixed
					    * size data */
				    NULL);
}

netsnmp_watcher_info *
netsnmp_create_watcher_info(void *data, size_t size, u_char type, int flags)
{
    netsnmp_watcher_info *winfo = SNMP_MALLOC_TYPEDEF(netsnmp_watcher_info);
    if (winfo)
        netsnmp_init_watcher_info(winfo, data, size, type, flags);
    return winfo;
}

/**
 * Register a watched scalar. The caller remains the owner of watchinfo.
 *
 * @see netsnmp_register_watched_instance2()
 */
int
netsnmp_register_watched_instance(netsnmp_handler_registration *reginfo,
                                  netsnmp_watcher_info         *watchinfo)
{
    netsnmp_mib_handler *whandler;

    whandler         = netsnmp_get_watcher_handler();
    whandler->myvoid = (void *)watchinfo;

    netsnmp_inject_handler(reginfo, whandler);
    return netsnmp_register_instance(reginfo);
}

/**
 * Register a watched scalar. Ownership of watchinfo is transferred to the handler.
 *
 * @see netsnmp_register_watched_instance()
 */
int
netsnmp_register_watched_instance2(netsnmp_handler_registration *reginfo,
				   netsnmp_watcher_info         *watchinfo)
{
    netsnmp_mib_handler *whandler;

    whandler         = netsnmp_get_watcher_handler();
    whandler->myvoid = (void *)watchinfo;
    netsnmp_owns_watcher_info(whandler);

    netsnmp_inject_handler(reginfo, whandler);
    return netsnmp_register_instance(reginfo);
}

/**
 * Register a watched scalar. The caller remains the owner of watchinfo.
 *
 * @see netsnmp_register_watched_scalar2()
 */
int
netsnmp_register_watched_scalar(netsnmp_handler_registration *reginfo,
                                  netsnmp_watcher_info         *watchinfo)
{
    netsnmp_mib_handler *whandler;

    whandler         = netsnmp_get_watcher_handler();
    whandler->myvoid = (void *)watchinfo;

    netsnmp_inject_handler(reginfo, whandler);
    return netsnmp_register_scalar(reginfo);
}

/**
 * Register a watched scalar. Ownership of watchinfo is transferred to the handler.
 *
 * @see netsnmp_register_watched_scalar()
 */
int
netsnmp_register_watched_scalar2(netsnmp_handler_registration *reginfo,
                                  netsnmp_watcher_info         *watchinfo)
{
    netsnmp_mib_handler *whandler;

    whandler         = netsnmp_get_watcher_handler();
    whandler->myvoid = (void *)watchinfo;
    netsnmp_owns_watcher_info(whandler);

    netsnmp_inject_handler(reginfo, whandler);
    return netsnmp_register_scalar(reginfo);
}

void
netsnmp_owns_watcher_info(netsnmp_mib_handler *handler)
{
    netsnmp_assert(handler);
    netsnmp_assert(handler->myvoid);
    handler->data_clone = (void *(*)(void *))netsnmp_clone_watcher_info;
    handler->data_free = free;
}

/** @cond */

NETSNMP_STATIC_INLINE size_t
get_data_size(const netsnmp_watcher_info* winfo)
{
    if (winfo->flags & WATCHER_SIZE_STRLEN)
        return strlen((const char*)winfo->data);
    else {
        size_t res;
        if (winfo->flags & WATCHER_SIZE_IS_PTR)
            res = *winfo->data_size_p;
        else
            res = winfo->data_size;
        if (winfo->flags & WATCHER_SIZE_UNIT_OIDS)
          res *= sizeof(oid);
        return res;
    }
}

NETSNMP_STATIC_INLINE void
set_data(netsnmp_watcher_info* winfo, void* data, size_t size)
{
    memcpy(winfo->data, data, size);
    if (winfo->flags & WATCHER_SIZE_STRLEN)
        ((char*)winfo->data)[size] = '\0';
    else {
        if (winfo->flags & WATCHER_SIZE_UNIT_OIDS)
          size /= sizeof(oid);
        if (winfo->flags & WATCHER_SIZE_IS_PTR)
            *winfo->data_size_p = size;
        else
            winfo->data_size = size;
    }
}

typedef struct {
    size_t size;
    char data[1];
} netsnmp_watcher_cache;

NETSNMP_STATIC_INLINE netsnmp_watcher_cache*
netsnmp_watcher_cache_create(const void* data, size_t size)
{
    netsnmp_watcher_cache *res = (netsnmp_watcher_cache*)
        malloc(sizeof(netsnmp_watcher_cache) + size - 1);
    if (res) {
        res->size = size;
        memcpy(res->data, data, size);
    }
    return res;
}

/** @endcond */

int
netsnmp_watcher_helper_handler(netsnmp_mib_handler *handler,
                               netsnmp_handler_registration *reginfo,
                               netsnmp_agent_request_info *reqinfo,
                               netsnmp_request_info *requests)
{
    netsnmp_watcher_info  *winfo = (netsnmp_watcher_info *) handler->myvoid;
    netsnmp_watcher_cache *old_data;

    DEBUGMSGTL(("helper:watcher", "Got request:  %d\n", reqinfo->mode));
    DEBUGMSGTL(( "helper:watcher", "  oid:"));
    DEBUGMSGOID(("helper:watcher", requests->requestvb->name,
                                   requests->requestvb->name_length));
    DEBUGMSG((   "helper:watcher", "\n"));

    switch (reqinfo->mode) {
        /*
         * data requests 
         */
    case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb,
                                 winfo->type,
                                 winfo->data,
                                 get_data_size(winfo));
        break;

        /*
         * SET requests.  Should only get here if registered RWRITE 
         */
#ifndef NETSNMP_NO_WRITE_SUPPORT
    case MODE_SET_RESERVE1:
        if (requests->requestvb->type != winfo->type) {
            netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGTYPE);
            handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
        } else if (((winfo->flags & WATCHER_MAX_SIZE) &&
                     requests->requestvb->val_len > winfo->max_size) ||
            ((winfo->flags & WATCHER_FIXED_SIZE) &&
                requests->requestvb->val_len != get_data_size(winfo))) {
            netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGLENGTH);
            handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
        } else if ((winfo->flags & WATCHER_SIZE_STRLEN) &&
            (memchr(requests->requestvb->val.string, '\0',
                requests->requestvb->val_len) != NULL)) {
            netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);
            handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
        }
        break;

    case MODE_SET_RESERVE2:
        /*
         * store old info for undo later 
         */
        old_data =
            netsnmp_watcher_cache_create(winfo->data, get_data_size(winfo));
        if (old_data == NULL) {
            netsnmp_set_request_error(reqinfo, requests,
                                      SNMP_ERR_RESOURCEUNAVAILABLE);
            handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
        } else
            netsnmp_request_add_list_data(requests,
                                          netsnmp_create_data_list
                                          ("watcher", old_data, &free_wrapper));
        break;

    case MODE_SET_FREE:
        /*
         * nothing to do 
         */
        break;

    case MODE_SET_ACTION:
        /*
         * update current 
         */
        set_data(winfo, (void *)requests->requestvb->val.string,
                                requests->requestvb->val_len);
        break;

    case MODE_SET_UNDO:
        old_data = (netsnmp_watcher_cache*)netsnmp_request_get_list_data(requests, "watcher");
        set_data(winfo, old_data->data, old_data->size);
        break;

    case MODE_SET_COMMIT:
        break;
#endif /* NETSNMP_NO_WRITE_SUPPORT */

    default:
        snmp_log(LOG_ERR, "watcher handler called with an unknown mode: %d\n",
                 reqinfo->mode);
        return SNMP_ERR_GENERR;

    }

    /* next handler called automatically - 'AUTO_NEXT' */
    return SNMP_ERR_NOERROR;
}


    /***************************
     *
     * A specialised form of the above, reporting
     *   the sysUpTime indicated by a given timestamp
     *
     ***************************/

netsnmp_mib_handler *
netsnmp_get_watched_timestamp_handler(void)
{
    netsnmp_mib_handler *ret = NULL;
    
    ret = netsnmp_create_handler("watcher-timestamp",
                                 netsnmp_watched_timestamp_handler);
    if (ret) {
        ret->flags |= MIB_HANDLER_AUTO_NEXT;
    }
    return ret;
}

int
netsnmp_watched_timestamp_register(netsnmp_mib_handler *whandler,
                                   netsnmp_handler_registration *reginfo,
                                   marker_t timestamp)
{
    whandler->myvoid = (void *)timestamp;
    netsnmp_inject_handler(reginfo, whandler);
    return netsnmp_register_scalar(reginfo);   /* XXX - or instance? */
}

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_REGISTER_TIMESTAMP
int
netsnmp_register_watched_timestamp(netsnmp_handler_registration *reginfo,
                                   marker_t timestamp)
{
    netsnmp_mib_handler *whandler;

    whandler         = netsnmp_get_watched_timestamp_handler();

    return netsnmp_watched_timestamp_register(whandler, reginfo, timestamp);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_REGISTER_TIMESTAMP */


int
netsnmp_watched_timestamp_handler(netsnmp_mib_handler *handler,
                               netsnmp_handler_registration *reginfo,
                               netsnmp_agent_request_info *reqinfo,
                               netsnmp_request_info *requests)
{
    marker_t timestamp = (marker_t) handler->myvoid;
    long     uptime;

    DEBUGMSGTL(("helper:watcher:timestamp",
                               "Got request:  %d\n", reqinfo->mode));
    DEBUGMSGTL(( "helper:watcher:timestamp", "  oid:"));
    DEBUGMSGOID(("helper:watcher:timestamp", requests->requestvb->name,
                                   requests->requestvb->name_length));
    DEBUGMSG((   "helper:watcher:timestamp", "\n"));

    switch (reqinfo->mode) {
        /*
         * data requests 
         */
    case MODE_GET:
        if (handler->flags & NETSNMP_WATCHER_DIRECT)
            uptime = * (long*)timestamp;
        else
            uptime = netsnmp_marker_uptime( timestamp );
        snmp_set_var_typed_value(requests->requestvb,
                                 ASN_TIMETICKS,
                                 (u_char *) &uptime,
                                 sizeof(uptime));
        break;

        /*
         * Timestamps are inherently Read-Only,
         *  so don't need to support SET requests.
         */
#ifndef NETSNMP_NO_WRITE_SUPPORT
    case MODE_SET_RESERVE1:
        netsnmp_set_request_error(reqinfo, requests,
                                  SNMP_ERR_NOTWRITABLE);
        handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
        return SNMP_ERR_NOTWRITABLE;
#endif /* NETSNMP_NO_WRITE_SUPPORT */
    }

    /* next handler called automatically - 'AUTO_NEXT' */
    return SNMP_ERR_NOERROR;
}

    /***************************
     *
     * Another specialised form of the above,
     *   implementing a 'TestAndIncr' spinlock
     *
     ***************************/

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_SPINLOCK

netsnmp_mib_handler *
netsnmp_get_watched_spinlock_handler(void)
{
    netsnmp_mib_handler *ret = NULL;
    
    ret = netsnmp_create_handler("watcher-spinlock",
                                 netsnmp_watched_spinlock_handler);
    if (ret) {
        ret->flags |= MIB_HANDLER_AUTO_NEXT;
    }
    return ret;
}

int
netsnmp_register_watched_spinlock(netsnmp_handler_registration *reginfo,
                                   int *spinlock)
{
    netsnmp_mib_handler  *whandler;
    netsnmp_watcher_info *winfo;

    whandler         = netsnmp_get_watched_spinlock_handler();
    whandler->myvoid = (void *)spinlock;
    winfo            = netsnmp_create_watcher_info((void *)spinlock,
		           sizeof(int), ASN_INTEGER, WATCHER_FIXED_SIZE);
    netsnmp_inject_handler(reginfo, whandler);
    return netsnmp_register_watched_scalar2(reginfo, winfo);
}


int
netsnmp_watched_spinlock_handler(netsnmp_mib_handler *handler,
                               netsnmp_handler_registration *reginfo,
                               netsnmp_agent_request_info *reqinfo,
                               netsnmp_request_info *requests)
{
    int     *spinlock = (int *) handler->myvoid;
    netsnmp_request_info *request;

    DEBUGMSGTL(("helper:watcher:spinlock",
                               "Got request:  %d\n", reqinfo->mode));
    DEBUGMSGTL(( "helper:watcher:spinlock", "  oid:"));
    DEBUGMSGOID(("helper:watcher:spinlock", requests->requestvb->name,
                                   requests->requestvb->name_length));
    DEBUGMSG((   "helper:watcher:spinlock", "\n"));

    switch (reqinfo->mode) {
        /*
         * Ensure the assigned value matches the current one
         */
#ifndef NETSNMP_NO_WRITE_SUPPORT
    case MODE_SET_RESERVE1:
        for (request=requests; request; request=request->next) {
            if (request->processed)
                continue;

            if (*request->requestvb->val.integer != *spinlock) {
                netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_WRONGVALUE);
                handler->flags |= MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE;
                return SNMP_ERR_WRONGVALUE;

            }
        }
        break;

        /*
         * Everything else worked, so increment the spinlock
         */
    case MODE_SET_COMMIT:
	(*spinlock)++;
	break;
#endif /* NETSNMP_NO_WRITE_SUPPORT */
    }

    /* next handler called automatically - 'AUTO_NEXT' */
    return SNMP_ERR_NOERROR;
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_SPINLOCK */

    /***************************
     *
     *   Convenience registration routines - modelled on
     *   the equivalent netsnmp_register_*_instance() calls
     *
     ***************************/

netsnmp_watcher_info *
netsnmp_clone_watcher_info(netsnmp_watcher_info *winfo)
{
    netsnmp_watcher_info *copy = malloc(sizeof(*copy));
    if (copy)
	*copy = *winfo;
    return copy;
}

static int
register_scalar_watcher(const char* name,
                        const oid* reg_oid, size_t reg_oid_len,
                        void *data, size_t size, u_char type,
                        Netsnmp_Node_Handler * subhandler, int mode)
{
    netsnmp_handler_registration *reginfo = NULL;
    netsnmp_mib_handler *whandler = NULL;
    netsnmp_watcher_info* watchinfo =
        netsnmp_create_watcher_info(data, size, type, WATCHER_FIXED_SIZE);
    if (watchinfo)
        whandler = netsnmp_get_watcher_handler();
    if (watchinfo && whandler) {
        whandler->myvoid = watchinfo;
	netsnmp_owns_watcher_info(whandler);
        reginfo =
            netsnmp_create_handler_registration(
                name, subhandler, reg_oid, reg_oid_len, mode);
    }
    if (watchinfo && whandler && reginfo) {
        netsnmp_inject_handler(reginfo, whandler);
        return netsnmp_register_scalar(reginfo);
    }
    if (whandler)
        netsnmp_handler_free(whandler);
    else if (watchinfo)
        free(watchinfo);
    return SNMP_ERR_RESOURCEUNAVAILABLE;
}

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_ULONG_SCALAR
int
netsnmp_register_ulong_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              u_long * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( u_long ),
        ASN_UNSIGNED, subhandler, HANDLER_CAN_RWRITE);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_ULONG_SCALAR */

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_READ_ONLY_ULONG_SCALAR
int
netsnmp_register_read_only_ulong_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              u_long * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( u_long ),
        ASN_UNSIGNED, subhandler, HANDLER_CAN_RONLY);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_READ_ONLY_ULONG_SCALAR */

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_LONG_SCALAR
int
netsnmp_register_long_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              long * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( long ),
        ASN_INTEGER, subhandler, HANDLER_CAN_RWRITE);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_LONG_SCALAR */

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_READ_ONLY_LONG_SCALAR
int
netsnmp_register_read_only_long_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              long * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( long ),
        ASN_INTEGER, subhandler, HANDLER_CAN_RONLY);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_READ_ONLY_LONG_SCALAR */


#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_INT_SCALAR
int
netsnmp_register_int_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              int * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( int ),
        ASN_INTEGER, subhandler, HANDLER_CAN_RWRITE);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_INT_SCALAR */

#ifndef NETSNMP_FEATURE_REMOVE_WATCHER_READ_ONLY_INT_SCALAR
int
netsnmp_register_read_only_int_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              int * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( int ),
        ASN_INTEGER, subhandler, HANDLER_CAN_RONLY);
}
#endif /* NETSNMP_FEATURE_REMOVE_WATCHER_READ_ONLY_INT_SCALAR */

#ifndef NETSNMP_FEATURE_REMOVE_READ_ONLY_COUNTER32_SCALAR
int
netsnmp_register_read_only_counter32_scalar(const char *name,
                              const oid * reg_oid, size_t reg_oid_len,
                              u_long * it,
                              Netsnmp_Node_Handler * subhandler)
{
    return register_scalar_watcher(
        name, reg_oid, reg_oid_len,
        (void *)it, sizeof( u_long ),
        ASN_COUNTER, subhandler, HANDLER_CAN_RONLY);
}
#endif /* NETSNMP_FEATURE_REMOVE_READ_ONLY_COUNTER32_SCALAR */
/**  @} */