summaryrefslogtreecommitdiff
path: root/agent/mibgroup/sctp-mib/sctpScalars_common.c
blob: 2a895a86a3418897a1cac6c5d7041a0854af0e1e (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
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

#include "sctpScalars_common.h"

netsnmp_sctp_stats sctp_stats;
static netsnmp_sctp_stats prev_sctp_stats;

netsnmp_sctp_params sctp_params;

static int      need_wrap_check = 1;

void
netsnmp_access_sctp_stats_init()
{
    netsnmp_access_sctp_stats_arch_init();
}

int
netsnmp_access_sctp_stats_load(netsnmp_cache * cache, void *magic)
{
    netsnmp_sctp_stats new_stats;
    int             ret;

    DEBUGMSGTL(("sctp:scalars:stats:load", "called\n"));

    ret = netsnmp_access_sctp_stats_arch_load(&new_stats);
    if (ret < 0) {
        DEBUGMSGTL(("sctp:scalars:stats:load", "arch load failed\n"));
        return ret;
    }

    /*
     * If we've determined that we have 64 bit counters, just copy them.
     */
    if (0 == need_wrap_check) {
        memcpy(&sctp_stats, &new_stats, sizeof(new_stats));
        return 0;
    }

    /*
     * Update 32 bit counters
     */
    sctp_stats.curr_estab = new_stats.curr_estab;
    sctp_stats.active_estabs = new_stats.active_estabs;
    sctp_stats.passive_estabs = new_stats.passive_estabs;
    sctp_stats.aborteds = new_stats.aborteds;
    sctp_stats.shutdowns = new_stats.shutdowns;
    sctp_stats.out_of_blues = new_stats.out_of_blues;
    sctp_stats.checksum_errors = new_stats.checksum_errors;
    sctp_stats.discontinuity_time = new_stats.discontinuity_time;

    /*
     * Update 64 bit counters
     */
    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.out_ctrl_chunks,
                                   &new_stats.out_ctrl_chunks,
                                   &prev_sctp_stats.out_ctrl_chunks,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpOutCtrlChunks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.out_order_chunks,
                                   &new_stats.out_order_chunks,
                                   &prev_sctp_stats.out_order_chunks,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpOutOrderChunks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.out_unorder_chunks,
                                   &new_stats.out_unorder_chunks,
                                   &prev_sctp_stats.out_unorder_chunks,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpOutUnorderChunks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.in_ctrl_chunks,
                                   &new_stats.in_ctrl_chunks,
                                   &prev_sctp_stats.in_ctrl_chunks,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpInCtrlChunks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.in_order_chunks,
                                   &new_stats.in_order_chunks,
                                   &prev_sctp_stats.in_order_chunks,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpInOrderChunks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.in_unorder_chunks,
                                   &new_stats.in_unorder_chunks,
                                   &prev_sctp_stats.in_unorder_chunks,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpInUnorderChunks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.frag_usr_msgs,
                                   &new_stats.frag_usr_msgs,
                                   &prev_sctp_stats.frag_usr_msgs,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpFragUsrMsgs to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.reasm_usr_msgs,
                                   &new_stats.reasm_usr_msgs,
                                   &prev_sctp_stats.reasm_usr_msgs,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpReasmUsrMsgs to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.out_sctp_packs,
                                   &new_stats.out_sctp_packs,
                                   &prev_sctp_stats.out_sctp_packs,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpOutSCTPPacks to 64bits\n"));

    if (0 != netsnmp_c64_check32_and_update(&sctp_stats.in_sctp_packs,
                                   &new_stats.in_sctp_packs,
                                   &prev_sctp_stats.in_sctp_packs,
                                   &need_wrap_check))
        NETSNMP_LOGONCE((LOG_ERR,
                "SCTP: Error expanding sctpInSCTPPacks to 64bits\n"));

    /*
     * Update prev_stats for next computation.
     */
    memcpy(&prev_sctp_stats, &new_stats, sizeof(new_stats));
    return 0;
}

void
netsnmp_access_sctp_stats_free(netsnmp_cache * cache, void *magic)
{
    /*
     * Do nothing 
     */
}

void
netsnmp_access_sctp_params_init()
{
    netsnmp_access_sctp_params_arch_init();
}

int
netsnmp_access_sctp_params_load(netsnmp_cache * cache, void *magic)
{
    int             ret;

    DEBUGMSGTL(("sctp:scalars:params:load", "called\n"));

    ret = netsnmp_access_sctp_params_arch_load(&sctp_params);
    if (ret < 0) {
        DEBUGMSGTL(("sctp:scalars:params:load", "arch load failed\n"));
        return ret;
    }
    return 0;
}

void
netsnmp_access_sctp_params_free(netsnmp_cache * cache, void *magic)
{
    /*
     * Do nothing 
     */
}