[go: up one dir, main page]

File: q-bridge-mib.c

package info (click to toggle)
scli 0.3.1-3.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,872 kB
  • ctags: 8,627
  • sloc: ansic: 32,657; sh: 7,388; makefile: 321
file content (360 lines) | stat: -rw-r--r-- 11,944 bytes parent folder | download
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
/*							-- DO NOT EDIT --
 * Generated by smidump version 0.4.5:
 *   smidump -f scli \
 *     --scli-include='dot1qBase|dot1qVlanStaticEntry' Q-BRIDGE-MIB
 *
 * Derived from Q-BRIDGE-MIB:
 *   The VLAN Bridge MIB module for managing Virtual Bridged
 *   Local Area Networks, as defined by IEEE 802.1Q-2003,
 *   including Restricted Vlan Registration defined by
 *   IEEE 802.1u-2001 and Vlan Classification defined by
 *   IEEE 802.1v-2001.
 *   
 *   Copyright (C) The Internet Society (2006).  This version of
 *   this MIB module is part of RFC 4363; See the RFC itself for
 *   full legal notices.
 *
 * Revision 2006-01-09 00:00:
 *   Added Vlan TEXTUAL-CONVENTIONs,
 *   dot1qPortRestrictedVlanRegistration, dot1vProtocol subtree,
 *   qBridgeClassificationDeviceGroup, qBridgePortGroup2,
 *   qBridgeClassificationPortGroup, and qBridgeCompliance2.
 *   Clarified dot1qForwardAllStaticPorts,
 *   qPortAcceptableFrameTypes, and qBridgeCompliance.
 *   Deprecated qBridgePortGroup and qBridgeCompliance.
 *
 * Revision 1999-08-25 00:00:
 *   The VLAN Bridge MIB module for managing Virtual Bridged
 *   Local Area Networks, as defined by IEEE 802.1Q-1998.
 *   
 *   Initial version, published as RFC 2674.
 *
 * $Id: q-bridge-mib.c 2078 2006-10-23 16:50:25Z schoenw $
 */

#include "q-bridge-mib.h"

GNetSnmpEnum const q_bridge_mib_enums_dot1qVlanVersionNumber[] = {
    { Q_BRIDGE_MIB_DOT1QVLANVERSIONNUMBER_VERSION1, "version1" },
    { 0, NULL }
};


static gint32 dot1qMaxVlanId_constraints[] = {1L, 4094L, 0, 0};
static guint16 dot1qVlanStaticName_constraints[] = {0U, 32U, 0, 0};


static guint32 const dot1qBase_oid[] = {1, 3, 6, 1, 2, 1, 17, 7, 1, 1};

static GNetSnmpAttribute dot1qBase_attr[] = {
    { 1, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      Q_BRIDGE_MIB_DOT1QVLANVERSIONNUMBER, "dot1qVlanVersionNumber",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qBase_t, dot1qVlanVersionNumber),
      0,
      0 },
    { 2, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      Q_BRIDGE_MIB_DOT1QMAXVLANID, "dot1qMaxVlanId",
       dot1qMaxVlanId_constraints,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qBase_t, dot1qMaxVlanId),
      0,
      0 },
    { 3, GNET_SNMP_VARBIND_TYPE_UNSIGNED32,
      Q_BRIDGE_MIB_DOT1QMAXSUPPORTEDVLANS, "dot1qMaxSupportedVlans",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qBase_t, dot1qMaxSupportedVlans),
      0,
      0 },
    { 4, GNET_SNMP_VARBIND_TYPE_UNSIGNED32,
      Q_BRIDGE_MIB_DOT1QNUMVLANS, "dot1qNumVlans",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qBase_t, dot1qNumVlans),
      0,
      0 },
    { 5, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      Q_BRIDGE_MIB_DOT1QGVRPSTATUS, "dot1qGvrpStatus",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qBase_t, dot1qGvrpStatus),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};

static guint32 const dot1qVlanStaticEntry_oid[] = {1, 3, 6, 1, 2, 1, 17, 7, 1, 4, 3, 1};

static GNetSnmpAttribute dot1qVlanStaticEntry_attr[] = {
    { 1, GNET_SNMP_VARBIND_TYPE_OCTETSTRING,
      Q_BRIDGE_MIB_DOT1QVLANSTATICNAME, "dot1qVlanStaticName",
       dot1qVlanStaticName_constraints,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, dot1qVlanStaticName),
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, _dot1qVlanStaticNameLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 2, GNET_SNMP_VARBIND_TYPE_OCTETSTRING,
      Q_BRIDGE_MIB_DOT1QVLANSTATICEGRESSPORTS, "dot1qVlanStaticEgressPorts",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, dot1qVlanStaticEgressPorts),
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, _dot1qVlanStaticEgressPortsLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 3, GNET_SNMP_VARBIND_TYPE_OCTETSTRING,
      Q_BRIDGE_MIB_DOT1QVLANFORBIDDENEGRESSPORTS, "dot1qVlanForbiddenEgressPorts",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, dot1qVlanForbiddenEgressPorts),
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, _dot1qVlanForbiddenEgressPortsLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 4, GNET_SNMP_VARBIND_TYPE_OCTETSTRING,
      Q_BRIDGE_MIB_DOT1QVLANSTATICUNTAGGEDPORTS, "dot1qVlanStaticUntaggedPorts",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, dot1qVlanStaticUntaggedPorts),
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, _dot1qVlanStaticUntaggedPortsLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 5, GNET_SNMP_VARBIND_TYPE_INTEGER32,
      Q_BRIDGE_MIB_DOT1QVLANSTATICROWSTATUS, "dot1qVlanStaticRowStatus",
       NULL,
      G_STRUCT_OFFSET(q_bridge_mib_dot1qVlanStaticEntry_t, dot1qVlanStaticRowStatus),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};


q_bridge_mib_dot1qBase_t *
q_bridge_mib_new_dot1qBase()
{
    q_bridge_mib_dot1qBase_t *dot1qBase;

    dot1qBase = (q_bridge_mib_dot1qBase_t *) g_malloc0(sizeof(q_bridge_mib_dot1qBase_t) + sizeof(gpointer));
    return dot1qBase;
}

static inline q_bridge_mib_dot1qBase_t *
assign_dot1qBase(GList *vbl)
{
    q_bridge_mib_dot1qBase_t *dot1qBase;
    char *p;

    dot1qBase = q_bridge_mib_new_dot1qBase();
    p = (char *) dot1qBase + sizeof(q_bridge_mib_dot1qBase_t);
    * (GList **) p = vbl;

    gnet_snmp_attr_assign(vbl, dot1qBase_oid, G_N_ELEMENTS(dot1qBase_oid),
                      dot1qBase_attr, dot1qBase);

    return dot1qBase;
}

void
q_bridge_mib_get_dot1qBase(GNetSnmp *s, q_bridge_mib_dot1qBase_t **dot1qBase, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 17, 7, 1, 1, 0};

    *dot1qBase = NULL;

    gnet_snmp_attr_get(s, &in, base, 11, 10, dot1qBase_attr, mask);

    out = gnet_snmp_sync_getnext(s, in);
    g_list_foreach(in, (GFunc) gnet_snmp_varbind_delete, NULL);
    g_list_free(in);
    if (out) {
        if (s->error_status != GNET_SNMP_PDU_ERR_NOERROR) {
            g_list_foreach(out, (GFunc) gnet_snmp_varbind_delete, NULL);
            g_list_free(out);
            return;
        }
        *dot1qBase = assign_dot1qBase(out);
    }
}

void
q_bridge_mib_set_dot1qBase(GNetSnmp *s, q_bridge_mib_dot1qBase_t *dot1qBase, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 17, 7, 1, 1, 0, 0};

    gnet_snmp_attr_set(s, &in, base, 12, 10, dot1qBase_attr, mask, dot1qBase);

    out = gnet_snmp_sync_set(s, in);
    g_list_foreach(in, (GFunc) gnet_snmp_varbind_delete, NULL);
    g_list_free(in);
    if (out) {
        g_list_foreach(out, (GFunc) gnet_snmp_varbind_delete, NULL);
        g_list_free(out);
    }
}

void
q_bridge_mib_free_dot1qBase(q_bridge_mib_dot1qBase_t *dot1qBase)
{
    GList *vbl;
    char *p;

    if (dot1qBase) {
        p = (char *) dot1qBase + sizeof(q_bridge_mib_dot1qBase_t);
        vbl = * (GList **) p;
        g_list_foreach(vbl, (GFunc) gnet_snmp_varbind_delete, NULL);
        g_list_free(vbl);
        g_free(dot1qBase);
    }
}

q_bridge_mib_dot1qVlanStaticEntry_t *
q_bridge_mib_new_dot1qVlanStaticEntry()
{
    q_bridge_mib_dot1qVlanStaticEntry_t *dot1qVlanStaticEntry;

    dot1qVlanStaticEntry = (q_bridge_mib_dot1qVlanStaticEntry_t *) g_malloc0(sizeof(q_bridge_mib_dot1qVlanStaticEntry_t) + sizeof(gpointer));
    return dot1qVlanStaticEntry;
}

static inline int
unpack_dot1qVlanStaticEntry(GNetSnmpVarBind *vb, q_bridge_mib_dot1qVlanStaticEntry_t *dot1qVlanStaticEntry)
{
    guint8 idx = 13;

    if (vb->oid_len < idx) return -1;
    dot1qVlanStaticEntry->dot1qVlanIndex = vb->oid[idx++];
    if (vb->oid_len > idx) return -1;
    return 0;
}

static inline gint8
pack_dot1qVlanStaticEntry(guint32 *base, guint32 dot1qVlanIndex)
{
    guint8 idx = 13;

    base[idx++] = dot1qVlanIndex;
    return idx;
}

static inline q_bridge_mib_dot1qVlanStaticEntry_t *
assign_dot1qVlanStaticEntry(GList *vbl)
{
    q_bridge_mib_dot1qVlanStaticEntry_t *dot1qVlanStaticEntry;
    char *p;

    dot1qVlanStaticEntry = q_bridge_mib_new_dot1qVlanStaticEntry();
    p = (char *) dot1qVlanStaticEntry + sizeof(q_bridge_mib_dot1qVlanStaticEntry_t);
    * (GList **) p = vbl;

    if (unpack_dot1qVlanStaticEntry((GNetSnmpVarBind *) vbl->data, dot1qVlanStaticEntry) < 0) {
        g_warning("%s: invalid instance identifier", "dot1qVlanStaticEntry");
        g_free(dot1qVlanStaticEntry);
        return NULL;
    }

    gnet_snmp_attr_assign(vbl, dot1qVlanStaticEntry_oid, G_N_ELEMENTS(dot1qVlanStaticEntry_oid),
                      dot1qVlanStaticEntry_attr, dot1qVlanStaticEntry);

    return dot1qVlanStaticEntry;
}

void
q_bridge_mib_get_dot1qVlanStaticTable(GNetSnmp *s, q_bridge_mib_dot1qVlanStaticEntry_t ***dot1qVlanStaticEntry, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    GList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 2, 1, 17, 7, 1, 4, 3, 1, 0};

    *dot1qVlanStaticEntry = NULL;

    gnet_snmp_attr_get(s, &in, base, 13, 12, dot1qVlanStaticEntry_attr, mask);

    out = gnet_snmp_sync_table(s, in);
    /* gnet_snmp_varbind_list_free(in); */

    if (out) {
        *dot1qVlanStaticEntry = (q_bridge_mib_dot1qVlanStaticEntry_t **) g_malloc0((g_list_length(out) + 1) * sizeof(q_bridge_mib_dot1qVlanStaticEntry_t *));
        for (row = out, i = 0; row; row = g_list_next(row), i++) {
            (*dot1qVlanStaticEntry)[i] = assign_dot1qVlanStaticEntry(row->data);
        }
    }
}

void
q_bridge_mib_get_dot1qVlanStaticEntry(GNetSnmp *s, q_bridge_mib_dot1qVlanStaticEntry_t **dot1qVlanStaticEntry, guint32 dot1qVlanIndex, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memcpy(base, dot1qVlanStaticEntry_oid, sizeof(dot1qVlanStaticEntry_oid));
    len = pack_dot1qVlanStaticEntry(base, dot1qVlanIndex);
    if (len < 0) {
        g_warning("%s: invalid index values", "dot1qVlanStaticEntry");
        s->error_status = GNET_SNMP_PDU_ERR_INTERNAL;
        return;
    }

    *dot1qVlanStaticEntry = NULL;

    gnet_snmp_attr_get(s, &in, base, len, 12, dot1qVlanStaticEntry_attr, mask);

    out = gnet_snmp_sync_get(s, in);
    g_list_foreach(in, (GFunc) gnet_snmp_varbind_delete, NULL);
    g_list_free(in);
    if (out) {
        if (s->error_status != GNET_SNMP_PDU_ERR_NOERROR) {
            g_list_foreach(out, (GFunc) gnet_snmp_varbind_delete, NULL);
            g_list_free(out);
            return;
        }
        *dot1qVlanStaticEntry = assign_dot1qVlanStaticEntry(out);
    }
}

void
q_bridge_mib_set_dot1qVlanStaticEntry(GNetSnmp *s, q_bridge_mib_dot1qVlanStaticEntry_t *dot1qVlanStaticEntry, gint64 mask)
{
    GList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memcpy(base, dot1qVlanStaticEntry_oid, sizeof(dot1qVlanStaticEntry_oid));
    len = pack_dot1qVlanStaticEntry(base, dot1qVlanStaticEntry->dot1qVlanIndex);
    if (len < 0) {
        g_warning("%s: invalid index values", "dot1qVlanStaticEntry");
        s->error_status = GNET_SNMP_PDU_ERR_INTERNAL;
        return;
    }

    gnet_snmp_attr_set(s, &in, base, len, 12, dot1qVlanStaticEntry_attr, mask, dot1qVlanStaticEntry);

    out = gnet_snmp_sync_set(s, in);
    g_list_foreach(in, (GFunc) gnet_snmp_varbind_delete, NULL);
    g_list_free(in);
    if (out) {
        g_list_foreach(out, (GFunc) gnet_snmp_varbind_delete, NULL);
        g_list_free(out);
    }
}

void
q_bridge_mib_free_dot1qVlanStaticEntry(q_bridge_mib_dot1qVlanStaticEntry_t *dot1qVlanStaticEntry)
{
    GList *vbl;
    char *p;

    if (dot1qVlanStaticEntry) {
        p = (char *) dot1qVlanStaticEntry + sizeof(q_bridge_mib_dot1qVlanStaticEntry_t);
        vbl = * (GList **) p;
        g_list_foreach(vbl, (GFunc) gnet_snmp_varbind_delete, NULL);
        g_list_free(vbl);
        g_free(dot1qVlanStaticEntry);
    }
}

void
q_bridge_mib_free_dot1qVlanStaticTable(q_bridge_mib_dot1qVlanStaticEntry_t **dot1qVlanStaticEntry)
{
    int i;

    if (dot1qVlanStaticEntry) {
        for (i = 0; dot1qVlanStaticEntry[i]; i++) {
            q_bridge_mib_free_dot1qVlanStaticEntry(dot1qVlanStaticEntry[i]);
        }
        g_free(dot1qVlanStaticEntry);
    }
}