Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
wr-switch-sw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
white-rabbit
wr-switch-sw
Commits
f7d750c7
Commit
f7d750c7
authored
Mar 19, 2015
by
Adam Wujek
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
userspace/snmpd: create wrsTableTemplate
Signed-off-by:
Adam Wujek
<
adam.wujek@cern.ch
>
parent
7a050885
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
0 deletions
+136
-0
wrsTableTemplate.h
userspace/snmpd/wrsTableTemplate.h
+136
-0
No files found.
userspace/snmpd/wrsTableTemplate.h
0 → 100644
View file @
f7d750c7
static
netsnmp_variable_list
*
table_next_entry
(
void
**
loop_context
,
void
**
data_context
,
netsnmp_variable_list
*
index
,
netsnmp_iterator_info
*
data
)
{
intptr_t
i
;
unsigned
int
n_rows
;
TT_DATA_FILL_FUNC
(
&
n_rows
);
/* create the line ID from counter number */
i
=
(
intptr_t
)
*
loop_context
;
if
(
i
>=
n_rows
)
return
NULL
;
/* no more */
i
++
;
/* Create the row OID: only the counter index */
snmp_set_var_value
(
index
,
(
u_char
*
)
&
i
,
sizeof
(
i
));
/* Set the data context (1..4)
* Cannot be set to 0, because netsnmp_extract_iterator_context returns
* NULL in function wrsPstats_handler when table is over */
*
data_context
=
(
void
*
)
i
;
/* and set the loop context for the next iteration */
*
loop_context
=
(
void
*
)
i
;
return
index
;
}
static
netsnmp_variable_list
*
table_first_entry
(
void
**
loop_context
,
void
**
data_context
,
netsnmp_variable_list
*
index
,
netsnmp_iterator_info
*
data
)
{
/* reset internal position, so "next" is "first" */
*
loop_context
=
(
void
*
)
0
;
/* first counter */
return
table_next_entry
(
loop_context
,
data_context
,
index
,
data
);
}
static
int
table_handler
(
netsnmp_mib_handler
*
handler
,
netsnmp_handler_registration
*
reginfo
,
netsnmp_agent_request_info
*
reqinfo
,
netsnmp_request_info
*
requests
)
{
netsnmp_request_info
*
request
;
netsnmp_variable_list
*
requestvb
;
netsnmp_table_request_info
*
table_info
;
struct
pickinfo
*
pi
;
int
row
,
subid
;
int
len
;
void
*
ptr
;
switch
(
reqinfo
->
mode
)
{
case
MODE_GET
:
/* "break;" so read code is not indented too much */
break
;
case
MODE_GETNEXT
:
case
MODE_GETBULK
:
case
MODE_SET_RESERVE1
:
case
MODE_SET_RESERVE2
:
case
MODE_SET_ACTION
:
case
MODE_SET_COMMIT
:
case
MODE_SET_FREE
:
case
MODE_SET_UNDO
:
/* unsupported mode */
return
SNMP_ERR_NOERROR
;
default:
/* unknown mode */
return
SNMP_ERR_NOERROR
;
}
for
(
request
=
requests
;
request
;
request
=
request
->
next
)
{
requestvb
=
request
->
requestvb
;
/* "context" is the row number */
row
=
(
intptr_t
)
netsnmp_extract_iterator_context
(
request
);
if
(
!
row
)
/* NULL returned from
* netsnmp_extract_iterator_context shuld be
* interpreted as end of table */
break
;
/* change range of row (1..X (snmp is 1 based) ->
* 0..X (wrs_t_table_array/data array is 0 based)) */
row
--
;
table_info
=
netsnmp_extract_table_info
(
request
);
subid
=
table_info
->
colnum
-
1
;
pi
=
TT_PICKINFO
+
subid
;
ptr
=
(
void
*
)(
TT_DATA_ARRAY
+
row
)
+
pi
->
offset
;
len
=
pi
->
len
;
if
(
len
>
8
)
/* special case for strings */
len
=
strnlen
(
ptr
,
len
);
snmp_set_var_typed_value
(
requestvb
,
pi
->
type
,
ptr
,
len
);
}
return
SNMP_ERR_NOERROR
;
}
void
TT_INIT_FUNC
(
void
)
{
const
oid
wrsTT_oid
[]
=
{
TT_OID
};
netsnmp_table_registration_info
*
table_info
;
netsnmp_iterator_info
*
iinfo
;
netsnmp_handler_registration
*
reginfo
;
/* do the registration for the table/per-port */
table_info
=
SNMP_MALLOC_TYPEDEF
(
netsnmp_table_registration_info
);
if
(
!
table_info
)
return
;
/* Add indexes: we only use one integer OID member as line identifier */
netsnmp_table_helper_add_indexes
(
table_info
,
ASN_INTEGER
,
0
);
table_info
->
min_column
=
1
;
table_info
->
max_column
=
ARRAY_SIZE
(
TT_PICKINFO
);
/* Iterator info */
iinfo
=
SNMP_MALLOC_TYPEDEF
(
netsnmp_iterator_info
);
if
(
!
iinfo
)
return
;
/* free table_info? */
iinfo
->
get_first_data_point
=
table_first_entry
;
iinfo
->
get_next_data_point
=
table_next_entry
;
iinfo
->
table_reginfo
=
table_info
;
/* register the table */
reginfo
=
netsnmp_create_handler_registration
(
TT_GROUP_NAME
,
table_handler
,
wrsTT_oid
,
OID_LENGTH
(
wrsTT_oid
),
HANDLER_CAN_RONLY
);
netsnmp_register_table_iterator
(
reginfo
,
iinfo
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment