From a5c48756b5029163e37f63d030595d7457dd5bf5 Mon Sep 17 00:00:00 2001 From: Michal Wasiak <michal.wasiak@gmail.com> Date: Thu, 8 Oct 2020 12:09:17 +0200 Subject: [PATCH] snmp/bridge_mib: generate dot1dStaticTable dot1dStaticTable with a command: mib2c -c mib2c.mfd.conf BRIDGE-MIB::dot1dStaticTable Signed-off-by: Michal Wasiak <michal.wasiak@gmail.com> --- .../defaults/node-dot1dStaticAddress.m2d | 43 + .../node-dot1dStaticAllowedToGoTo.m2d | 43 + .../defaults/node-dot1dStaticReceivePort.m2d | 35 + .../defaults/node-dot1dStaticStatus.m2d | 35 + .../defaults/table-dot1dStaticTable.m2d | 103 ++ .../dot1dStaticTable-README-FIRST.txt | 167 ++++ ...t1dStaticTable-README-dot1dStaticTable.txt | 555 +++++++++++ .../dot1dStaticTable/dot1dStaticTable.c | 202 ++++ .../dot1dStaticTable/dot1dStaticTable.h | 201 ++++ .../dot1dStaticTable_Makefile | 57 ++ .../dot1dStaticTable_data_access.c | 431 ++++++++ .../dot1dStaticTable_data_access.h | 76 ++ .../dot1dStaticTable_data_get.c | 357 +++++++ .../dot1dStaticTable_data_get.h | 64 ++ .../dot1dStaticTable_data_set.c | 25 + .../dot1dStaticTable_data_set.h | 27 + .../dot1dStaticTable/dot1dStaticTable_enums.h | 69 ++ .../dot1dStaticTable_interface.c | 920 ++++++++++++++++++ .../dot1dStaticTable_interface.h | 84 ++ .../dot1dStaticTable/dot1dStaticTable_oids.h | 41 + .../dot1dStaticTable_subagent.c | 177 ++++ 21 files changed, 3712 insertions(+) create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAddress.m2d create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAllowedToGoTo.m2d create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticReceivePort.m2d create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticStatus.m2d create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/table-dot1dStaticTable.m2d create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-FIRST.txt create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-dot1dStaticTable.txt create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.c create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_Makefile create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.c create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.c create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.c create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_enums.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.c create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_oids.h create mode 100644 userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_subagent.c diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAddress.m2d b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAddress.m2d new file mode 100644 index 000000000..1d83234ef --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAddress.m2d @@ -0,0 +1,43 @@ +######################################################################## +## +## mib2c node setting for dot1dStaticAddress +## +## Remove the '##' comment delimeter to change settings +## +######################################################################## +## Node declaration type? This is the C type to be used when +## declaring a variable to hold a value for this column. It +## is strongly recommended that you do not change this value. +## If you do, it is likely to break lots of generated code that +## you will have to fix. +## +## @eval $m2c_decl = char@ +## +######################################################################## +## Generate/use mapping functions? Useful if the MIB defines +## a different format or enumerations than you data store uses. +## +## @eval $m2c_node_skip_mapping = -1@ +## +######################################################################## +## Need a length for the value? Most OCTET-STRING based values will +## need a length, most other types will not. Do not change this one +## unless you know what you are doing! You will almost certainly need +## to fix lots of generated code if you do. +## +## @eval $m2c_node_needlength = 1@ +## +######################################################################## +## Skip get? Set this to 1 if you do not want to implement a value +## for this column. +## +## @eval $m2c_node_skip_get = 0@ +## +######################################################################## +## Allow realloc when data size exceeds length? If your data +## store for this node is a pointer allocated with one of the +## alloc family functions, you can set this to 1 to use realloc +## when a new value length exceeds the old lenght. If you are +## using a fixed size buffer, this value should be 0. +## +## @eval $m2c_node_realloc = 0@ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAllowedToGoTo.m2d b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAllowedToGoTo.m2d new file mode 100644 index 000000000..ed8b94c49 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticAllowedToGoTo.m2d @@ -0,0 +1,43 @@ +######################################################################## +## +## mib2c node setting for dot1dStaticAllowedToGoTo +## +## Remove the '##' comment delimeter to change settings +## +######################################################################## +## Node declaration type? This is the C type to be used when +## declaring a variable to hold a value for this column. It +## is strongly recommended that you do not change this value. +## If you do, it is likely to break lots of generated code that +## you will have to fix. +## +## @eval $m2c_decl = char@ +## +######################################################################## +## Generate/use mapping functions? Useful if the MIB defines +## a different format or enumerations than you data store uses. +## +## @eval $m2c_node_skip_mapping = -1@ +## +######################################################################## +## Need a length for the value? Most OCTET-STRING based values will +## need a length, most other types will not. Do not change this one +## unless you know what you are doing! You will almost certainly need +## to fix lots of generated code if you do. +## +## @eval $m2c_node_needlength = 1@ +## +######################################################################## +## Skip get? Set this to 1 if you do not want to implement a value +## for this column. +## +## @eval $m2c_node_skip_get = 0@ +## +######################################################################## +## Allow realloc when data size exceeds length? If your data +## store for this node is a pointer allocated with one of the +## alloc family functions, you can set this to 1 to use realloc +## when a new value length exceeds the old lenght. If you are +## using a fixed size buffer, this value should be 0. +## +## @eval $m2c_node_realloc = 0@ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticReceivePort.m2d b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticReceivePort.m2d new file mode 100644 index 000000000..6acfff14f --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticReceivePort.m2d @@ -0,0 +1,35 @@ +######################################################################## +## +## mib2c node setting for dot1dStaticReceivePort +## +## Remove the '##' comment delimeter to change settings +## +######################################################################## +## Node declaration type? This is the C type to be used when +## declaring a variable to hold a value for this column. It +## is strongly recommended that you do not change this value. +## If you do, it is likely to break lots of generated code that +## you will have to fix. +## +## @eval $m2c_decl = long@ +## +######################################################################## +## Generate/use mapping functions? Useful if the MIB defines +## a different format or enumerations than you data store uses. +## +## @eval $m2c_node_skip_mapping = -1@ +## +######################################################################## +## Need a length for the value? Most OCTET-STRING based values will +## need a length, most other types will not. Do not change this one +## unless you know what you are doing! You will almost certainly need +## to fix lots of generated code if you do. +## +## @eval $m2c_node_needlength = 0@ +## +######################################################################## +## Skip get? Set this to 1 if you do not want to implement a value +## for this column. +## +## @eval $m2c_node_skip_get = 0@ +## diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticStatus.m2d b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticStatus.m2d new file mode 100644 index 000000000..9cb6ddec8 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/node-dot1dStaticStatus.m2d @@ -0,0 +1,35 @@ +######################################################################## +## +## mib2c node setting for dot1dStaticStatus +## +## Remove the '##' comment delimeter to change settings +## +######################################################################## +## Node declaration type? This is the C type to be used when +## declaring a variable to hold a value for this column. It +## is strongly recommended that you do not change this value. +## If you do, it is likely to break lots of generated code that +## you will have to fix. +## +## @eval $m2c_decl = u_long@ +## +######################################################################## +## Generate/use mapping functions? Useful if the MIB defines +## a different format or enumerations than you data store uses. +## +## @eval $m2c_node_skip_mapping = 0@ +## +######################################################################## +## Need a length for the value? Most OCTET-STRING based values will +## need a length, most other types will not. Do not change this one +## unless you know what you are doing! You will almost certainly need +## to fix lots of generated code if you do. +## +## @eval $m2c_node_needlength = 0@ +## +######################################################################## +## Skip get? Set this to 1 if you do not want to implement a value +## for this column. +## +## @eval $m2c_node_skip_get = 0@ +## diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/table-dot1dStaticTable.m2d b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/table-dot1dStaticTable.m2d new file mode 100644 index 000000000..d6c3b274f --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/defaults/table-dot1dStaticTable.m2d @@ -0,0 +1,103 @@ +## ######################################################################## +## +## mib2c Table setting for dot1dStaticTable +## +## ######################################################################## +## +## User context structure type +## +@eval $m2c_context_reg = "netsnmp_data_list"@ +## +## ######################################################################## +## +## Allocate data structure in row structure? (vs embedd) +## +@eval $m2c_data_allocate = 0@ +## +## ######################################################################## +## +## Generate code to cache data? +## +@eval $m2c_data_cache = 1@ +## +## ######################################################################## +## +## Data context structure type +## +@eval $m2c_data_context = "generated"@ [generated|NAME] +## +## ######################################################################## +## +## Generate function to initialize row context when created? +## +@eval $m2c_data_init = 1@ +## +## ######################################################################## +## +## Persistence of data context +## // 0:persistent, 1:semi-transient, 2:transient +## +@eval $m2c_data_transient = 2@ +## +## ######################################################################## +## +## Include some example code? +## +@eval $m2c_include_examples = 1@ +## +## ######################################################################## +## +## Generate code for irreversible_commit mode? +## +@eval $m2c_irreversible_commit = 0@ +## +## ######################################################################## +## +## Data access method +## +@eval $m2c_table_access = "container-cached"@ +## +## ######################################################################## +## +## Generate row dependency function? +## +@eval $m2c_table_dependencies = 0@ +## +## ######################################################################## +## +## Generate data store/restore functions for persistent storage? +## +@eval $m2c_table_persistent = 0@ +## +## ######################################################################## +## +## Generate code for dynamic row creation? +## +@eval $m2c_table_row_creation = 0@ +## +## ######################################################################## +## +## Generate code for settable objects? +## +@eval $m2c_table_settable = 0@ +## +## ######################################################################## +## +## Skip mapping between data context and MIB formats? +## // 0:generate maps, 1:skip maps, -1:skip unless enum/oid +## +@eval $m2c_table_skip_mapping = -1@ +## +## ######################################################################## +## +## Generate code for sparse tables? +## +@eval $m2c_table_sparse = 0@ +## +## ######################################################################## +## +## Generate Makefile/AgentX code? +## +@eval $mfd_generate_makefile = 1@ +@eval $mfd_generate_subagent = 1@ +## diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-FIRST.txt b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-FIRST.txt new file mode 100644 index 000000000..9b0283d83 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-FIRST.txt @@ -0,0 +1,167 @@ +************************************************************************ +dot1dStaticTable README +------------------------------------------------------------------------ +This document describes the results of the mib2c code generation +system using the mfd code generation template. The resulting files +are documented both in this README file as well as per-table specific +README files. All of the files generated by this run of mib2c will +begin with the dot1dStaticTable prefix. + +Quick Start +----------- +For those interested in a quick start, to get a pseudo-todo list, try +this command in directory with the generated code: + + grep -n "TODO:" *.[ch] | sed 's/\([^ ]*\) \(.*\)TODO\(.*\)/\3 (\1)/' | sort -n + +Key: + :o: Optional + :r: Recommended + :M: Mandatory + :A: Advanced users + +This will give you and ordered list of places in the code that you +may (or must) take a closer look at). + +You may also want to take a look at the on-line tutorial, found here: + + http://www.net-snmp.org/tutorial/tutorial-5/toolkit/mfd/index.html + + +MIBs For Dummies Overview +------------------------- +The MIBs For Dummies (MFD) configuration files have been written to help +SNMP novices implement SNMP MIBs. This section will be a brief +introduction to some of the general concepts you should be familar with. + + Managed Information Base (MIB) + ------------------------------ + A SNMP MIB (Managed information base) is a text file that describes the + syntax for some set of data objects. The MIB creates a correlation + between an ASCII name for an object and a number OID (Object Identifier). + The SNMP protocol communicates information using the OIDs, and the MIB + allows tools to display a name, which we humans find easier to deal with. + + To use an analogy, a MIB is much like a menu at a restaurant. If you've + ever been to a reataurant and ordered a meal, and later received a bill + that simply had '#6' on it, you get the idea. The name is easier for + the customers to remember, and the waiters and chefs use the number for + efficency. + + + Scalars + ------- + A scalar variable is a unique object in a MIB which can represent + a single value. For example, the SNMP standard MIB-II defines a + variable, sysContact.0, which is a string containing the contact + information for the person in charge of a particular agent. Note + that scalar variable always end with '.0'. + + + Rows and Tables + --------------- + When a group of related attributes occur more than once, they can be + grouped together in a table. A table has an index, which uniquely + identifies a particular row, and data columns, which contain the + attributes for that row. + + For example, the SNMP standard MIB-II defines a table, ifTable, which + contains information on the ethernet interfaces on a system. + + + Data Structures + --------------- + The code generated by the MFD configuration files has a few important + structures. + + + The Data Context + ---------------- + The data context structure should contain the necessary information + to provide the data for the columns in a given row. As long as you + can extract the data for a column for the data context, the data context + can be anything you want: a pointer to an existing structure, the + parameters needed for a function call or an actual copy of the data. + + By default, a data context structure is generated with storage for + all the data in a row. Information on changing the default is presented + later on in this help. + + + The MIB Context + --------------- + The MIB context structure is generated with storage for all the + indexes of a table. This data will be used when searching for the + correct row to process for a request. + + + The Row Request Context + ----------------------- + Each table will have a unique data structure for holding data during + the processing of a particular row. The row request context contains + the registration context (that you supply during initilization), + the data context, the MIB context, the undo context (for settable + tables) and other data. There is also a netsnmp_data_list, which can + be used to temporary storage during processing. + + + The Table Registration Pointer + ------------------------------ + During initilization, you may provide a pointer to arbitrary data for + you own use. This pointer will be saved in the row request context, + and is passed as a parameter to several functions. It is not required, + and is provided as a way for you to access table specific data in + the generated code. + + + +These files are top-level files potentially useful for all the tables: +------------------------------------------------------------------------ + + File : dot1dStaticTable_Makefile + ---------------------------------------------------------------------- + Purpose : Make file for compiling a (sub)agent. This file is only + useful if you don't want to compile your code directly + into the Net-SNMP master agent. + Editable: Optional + Usage : make -f dot1dStaticTable_Makefile + + + File : dot1dStaticTable_subagent.c + ---------------------------------------------------------------------- + Purpose : This file contains a main() function for an agent or + sub-agent and is compiled using the Makefile above. + + + + +Table specific README files +------------------------------------------------------------------------ +Each table for which code was generated has its own README file +describing the files specifically associated with each table. You +should probably read these next: + + dot1dStaticTable-README-dot1dStaticTable.txt + + + +These are miscellaneous auto-generated code files you generally +shouldn't edit. They contain code that ties your code together with +the Net-SNMP agent. +------------------------------------------------------------------------ + File : dot1dStaticTable.h + Purpose : Header file for the module set. Includes config_require + macros to auto-load the other code pieces when compiled + into the agent. + + File : dot1dStaticTable_oids.h + Purpose : C #define definitions of the tables, columns, and OIDs + + File : dot1dStaticTable_enums.h + Purpose : C #define definitions of the enumerated type values for + each column of each table that requires them. + + File : dot1dStaticTable_interface.c + Purpose : MFD interface to Net-SNMP. This auto-generated code ties the + functions you will fill out to the code that the agent needs. + diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-dot1dStaticTable.txt b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-dot1dStaticTable.txt new file mode 100644 index 000000000..4ccd4661e --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable-README-dot1dStaticTable.txt @@ -0,0 +1,555 @@ +************************************************************************ +dot1dStaticTable README +------------------------------------------------------------------------ + This readme file describes the code generated by mib2c (using the MIBs + for Dummies (MFD) configuration file). The code generated was + generated specifically for the following SNMP table: + + dot1dStaticTable + + Your code will be called when the snmp agent receives requests for + the dot1dStaticTable table. The agent will start by looking for the right + row in your existing data to operate on, if one exists. + + + Configuration Variables + ------------------------------------------------------------ + Some variables used for code generation may be set to affect the code + generation. You may override these variables by setting them in the + file defaults/table-dot1dStaticTable.m2d, and then re-running mib2c. + + m2c_table_settable (currently '0') + -------------------------------------------------------- + This variable determines whether or not code is generated to support + MIB object which have an access of read-write or read-create. The + default is set based on whether or not the table contains writable + objects, but can be over-ridden. + + Syntax: @eval $m2c_table_settable = 0@ + + + m2c_table_dependencies (currently '0') + -------------------------------------------------------- + This variable determines whether or not code is generated to support + checking dependencies between columns, rows or tables. The default + is set based on whether or not the table contains writable objects, + but can be over-ridden. + + Syntax: @eval $m2c_table_dependencies = 0@ + + + m2c_table_row_creation (currently '0') + -------------------------------------------------------- + This variable determines whether or not code is generated to support + checking creation of new rows via SNMP. The default is set based on + whether or not the table contains read-create objects, but can be + over-ridden. + + Syntax: @eval $m2c_table_row_creation = 0@ + + + m2c_context_reg (currently 'netsnmp_data_list') + -------------------------------------------------------- + This variable contains the structure name to typedef for the + dot1dStaticTable_registration. + + During initilization, you will provide a pointer to a structure of + this type. This pointer is used as a parameter to many functions so + that you have access to your registration data. The default is a + netsnmp_data_list pointer, which will allow you to keep multiple + pointers tagged by a text name. If you have a new or existing structure + you would rather use, you can redefine this variable. + + + To avoid regenerating code, you may also change this typedef directly + in the dot1dStaticTable.h header. + + Syntax: @eval $m2c_context_reg = "struct my_registration_context@ + + + m2c_data_context (currently 'generated') + -------------------------------------------------------- + This variable contains the structure name to typedef for the + dot1dStaticTable_data. + + This typedef is used in the row request context structure for the table, + dot1dStaticTable_rowreq_ctx. + + The typedef in the primary table context will be used for the data and + undo structure types. This structure should contain all the data + needed for all the columns in the table. The default is 'generated', + which will cuase a new data strcuture to be generated with data members + for each column. + + To avoid regenerating code, you may also change this typedef directly + in the dot1dStaticTable.h header. + + Syntax: @eval $m2c_data_context = "struct my_data_context"@ + + + m2c_data_allocate (currently '0') + -------------------------------------------------------- + This variable determines whether or not the data context (see above) + requires memory to be allocated. The default generated data structure + does not. If you are using a custom data context which needs to + allocate memory, override this value and two additional functions + will be generated: + + dot1dStaticTable_allocate_data + dot1dStaticTable_release_data + + Syntax: @eval $m2c_data_allocate = 1@ + + + m2c_data_init (currently '1') + -------------------------------------------------------- + This variable determines whether or not the data context (see above) + or any other items you have added to the table context requires + initialization. The default generated data structure does not. If you + are using a custom data context or have added items needing initialization + to the table context, override this value and two additional functions + will be generated: + + dot1dStaticTable_rowreq_ctx_init + dot1dStaticTable_rowreq_ctx_cleanup + + Syntax: @eval 1 = 1@ + + + m2c_table_access (currently 'container-cached') + ------------------------------------------------------------------ + This variable determines which data interface will be use to generate + code for looking up data for a given index. The default is the + 'container-cached' access code, which caches the data in a netsnmp- + container (usually a sorted array). + + Available options can be determined by checking for mib2c configuration + files that begin with 'mfd-access-*'. + + Syntax: @eval $m2c_table_access = 'container-cached'@ + + + m2c_include_examples (currently '1') + ------------------------------------------------------------------ + This variable determines whether or not to generate example code. The + default is to generate example code. + + Syntax: @eval $m2c_include_examples = 0@ + + + m2c_data_transient (currently '2') + ------------------------------------------------------------------ + This variable determines how the generated example code deals with the + data during data lookup. See the table readme file for details on how + the current table access method interprets this value. In general, + a value of 0 indicates persistent data, 1 indicates semi-transient and + 2 indicates transient data. + + Syntax: @eval $m2c_data_transient = 0@ + + + Index(es) for the dot1dStaticTable table + ------------------------------------------------------------ + The index(es) for the dot1dStaticTable table are: + + dot1dStaticAddress: + Syntax: MacAddress + DataType: OCTETSTR + ASN type: ASN_OCTET_STR + C-code type: char + dot1dStaticReceivePort: + Syntax: INTEGER32 + DataType: INTEGER32 + ASN type: ASN_INTEGER + C-code type: long + + You should know how to set all these values from your data context, + dot1dStaticTable_data. + + +************************************************************************ +dot1dStaticTable File Overview +------------------------------------------------------------------------ + Several files have been generated to implement the dot1dStaticTable + table. We'll go through these files, one by one, explaining each and + letting you know which you need to edit. + + +File: dot1dStaticTable_data_access.[c|h] +------------------------------------------------------------------------ + The dot1dStaticTable_data_access file contains the interface to your data in + its raw format. These functions are used to build the row cache or + locate the row (depending on the table access method). + + Set MIB context + ----------------- + TODO : Set MIB index values + FUNC : dot1dStaticTable_indexes_set + WHERE: dot1dStaticTable_data_access.c + + This is a convenience function for setting the index context from + the native C data. Where necessary, value mapping should be done. + + This function should update the table index values (found in + tbl_idx) for the given raw data. + + + container summary + ------------------------ + The container data access code is for cases when you want to + store your data in the agent/sub-agent. + + ... to be continued... + + + cache summary + ------------------------ + The container-cached data access code is for cases when you want to + cache your data in the agent/sub-agent. + + ... to be continued... + + + + +File: dot1dStaticTable_enums.h +------------------------------------------------------------------------ + This file contains macros for mapping enumeration values when the + enumerated values defined by the MIB do not match the values used + internally. + + Review this file to see if any values need to be updated. + + +File: dot1dStaticTable_data_get.c +------------------------------------------------------------------------ + Get data for column + ------------------- + TODO : retrieve column data from raw data + FUNC : dot1dStaticAllowedToGoTo_get + + Get data for column + ------------------- + TODO : retrieve column data from raw data + FUNC : dot1dStaticStatus_get + + + +File: dot1dStaticTable_data_set.c +------------------------------------------------------------------------ + + This table does not support set requests. + + +************************************************************************ +dot1dStaticTable Reference +------------------------------------------------------------------------ + +Function flow +---------------------------------------------------- +To give you the general idea of how the functions flow works, this +example flow is from a complete table implementation. + +NOTE: Depending on your configuration, some of the functions used in the + examples below may not have been generated for the + dot1dStaticTable table. + + Conversely, the examples below may not include some functions that + were generated for the dot1dStaticTable table. + +To watch the flow of the dot1dStaticTable table, use the +following debug tokens: + + snmp_agent + helper:table:req + dot1dStaticTable + verbose:dot1dStaticTable + internal:dot1dStaticTable + +e.g. + snmpd -f -Le -Ddot1dStaticTable,verbose:dot1dStaticTable,internal:dot1dStaticTable + + +Initialization +-------------------------------- +init_xxxTable: called xxx.c + initialize_table_xxxTable xxx.c + _xxxTable_initialize_interface xxx_interface.c + xxxTable_init_data xxx_data_access.c + _xxxTable_container_init xxx_interface.c + xxxTable_container_init xxx_data_access.c + + +GET Request +-------------------------------- +_cache_load xxx_interface.c + xxxTable_cache_load xxx_data_access.c + xxxTable_allocate_rowreq_ctx xxx_interface.c + xxxTable_allocate_data xxx_data_get.c + xxxTable_rowreq_ctx_init xxx_data_get.c + xxxTable_indexes_set xxx_data_get.c + xxxTable_indexes_set_tbl_idx xxx_data_get.c + +xxxTable_pre_request + +_mfd_xxxTable_object_lookup xxx_interface.c + xxxTable_row_prep xxx_data_access.c + +_mfd_xxxTable_get_values xxx_interface.c + _mfd_xxxTable_get_column xxx_interface.c + yyy_get xxx_data_get.c + +xxxTable_post_request + + +GETNEXT Request +-------------------------------- +_cache_load ... +xxxTable_pre_request ... +_mfd_xxxTable_object_lookup ... +_mfd_xxxTable_get_values ... +xxxTable_post_request ... + + +SET Request: success +-------------------------------- +_cache_load ... +xxxTable_pre_request +_mfd_xxxTable_object_lookup ... + +_mfd_xxxTable_check_objects xxx_interface.c + _xxxTable_check_column xxx_interface.c + yyy_check_value xxx_data_set.c + +_mfd_xxxTable_undo_setup xxx_interface.c + xxxTable_allocate_data ... + xxxTable_undo_setup xxx_interface.c + _xxxTable_undo_setup_column xxx_interface.c + yyy_undo_setup xxx_data_set.c + +_mfd_xxxTable_set_values xxx_interface.c + _xxxTable_set_column xxx_interface.c + yyy_set xxx_data_set.c + +_mfd_xxxTable_check_dependencies xxx_interface.c + xxxTable_check_dependencies xxx_data_set.c + +_mfd_xxxTable_commit xxx_interface.c + xxxTable_commit xxx_data_set.c + +_mfd_xxxTable_undo_cleanup xxx_interface.c + xxxTable_undo_cleanup xxx_data_set.c + xxxTable_release_data ... + +xxxTable_post_request ... + + +SET Request: row creation +-------------------------------- +_cache_load ... +xxxTable_pre_request + +_mfd_xxxTable_object_lookup ... + xxxTable_index_from_oid xxx_interface.c + xxxTable_allocate_rowreq_ctx ... + ... + _xxxTable_check_indexes xxx_interface.c + yyy_check_index xxx_data_set.c + xxxTable_validate_index xxx_data_set.c + +_mfd_xxxTable_check_objects ... + _xxxTable_check_column ... + yyy_check_value ... + _xxxTable_check_column ... + yyy_check_value ... + +_mfd_xxxTable_undo_setup ... +_mfd_xxxTable_set_values ... +_mfd_xxxTable_check_dependencies ... +_mfd_xxxTable_commit ... +_mfd_xxxTable_undo_cleanup ... +xxxTable_post_request ... + + +SET Resuest: value error +-------------------------------- +_cache_load ... +xxxTable_pre_request ... +_mfd_xxxTable_object_lookup ... + +_mfd_xxxTable_check_objects ... + _xxxTable_check_column ... + yyy_check_value ... + ERROR:"yyy value not supported" + +xxxTable_post_request ... + + +SET Request: commit failure +-------------------------------- +_cache_load ... +xxxTable_pre_request ... +_mfd_xxxTable_object_lookup ... +_mfd_xxxTable_check_objects ... +_mfd_xxxTable_undo_setup ... +_mfd_xxxTable_set_values ... +_mfd_xxxTable_check_dependencies ... + +_mfd_xxxTable_commit ... + xxxTable_commit ... + ERROR: bad rc -1 + +_mfd_xxxTable_undo_commit xxx_interface.c + xxxTable_undo_commit xxx_data_set.c + +_mfd_xxxTable_undo_values xxx_interface.c + _xxxTable_undo_column xxx_interface.c + yyy_undo xxx_data_set.c + +_mfd_xxxTable_undo_cleanup ... +xxxTable_post_request ... + + +Row release (user initiated) +-------------------------------- +xxxTable_release_rowreq_ctx xxx_interface.c + xxxTable_rowreq_ctx_cleanup xxx_data_get.c + xxxTable_release_data xxx_data_get.c + + + +Table / column details +---------------------------------------------------- +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ + +/*--------------------------------------------------------------------- + * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticAddress + * dot1dStaticAddress is subid 1 of dot1dStaticEntry. + * Its status is Current, and its access level is Create. + * OID: .1.3.6.1.2.1.17.5.1.1.1 + * Description: +The destination MAC address in a frame to which this + entry's filtering information applies. This object can + take the value of a unicast address, a group address, or + the broadcast address. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 1 + * settable 1 + * hint: 1x: + * + * Ranges: 6; + * + * Its syntax is MacAddress (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 6) + */ +/*--------------------------------------------------------------------- + * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticReceivePort + * dot1dStaticReceivePort is subid 2 of dot1dStaticEntry. + * Its status is Current, and its access level is Create. + * OID: .1.3.6.1.2.1.17.5.1.1.2 + * Description: +Either the value '0', or the port number of the port + from which a frame must be received in order for this + entry's filtering information to apply. A value of zero + indicates that this entry applies on all ports of the + bridge for which there is no other applicable entry. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 1 + * + * Ranges: 0 - 65535; + * + * Its syntax is INTEGER32 (based on perltype INTEGER32) + * The net-snmp type is ASN_INTEGER. The C type decl is long (long) + */ +/*--------------------------------------------------------------------- + * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticAllowedToGoTo + * dot1dStaticAllowedToGoTo is subid 3 of dot1dStaticEntry. + * Its status is Current, and its access level is Create. + * OID: .1.3.6.1.2.1.17.5.1.1.3 + * Description: +The set of ports to which frames received from a + specific port and destined for a specific MAC address, + are allowed to be forwarded. Each octet within the + value of this object specifies a set of eight ports, + with the first octet specifying ports 1 through 8, the + second octet specifying ports 9 through 16, etc. Within + each octet, the most significant bit represents the + lowest numbered port, and the least significant bit + represents the highest numbered port. Thus, each port + of the bridge is represented by a single bit within the + value of this object. If that bit has a value of '1', + then that port is included in the set of ports; the port + is not included if its bit has a value of '0'. (Note + that the setting of the bit corresponding to the port + from which a frame is received is irrelevant.) The + default value of this object is a string of ones of + appropriate length. + + The value of this object may exceed the required minimum + maximum message size of some SNMP transport (484 bytes, + in the case of SNMP over UDP, see RFC 3417, section 3.2). + SNMP engines on bridges supporting a large number of + ports must support appropriate maximum message sizes. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 1 + * + * Ranges: 0 - 512; + * + * Its syntax is OCTETSTR (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 512) + */ +/*--------------------------------------------------------------------- + * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticStatus + * dot1dStaticStatus is subid 4 of dot1dStaticEntry. + * Its status is Current, and its access level is Create. + * OID: .1.3.6.1.2.1.17.5.1.1.4 + * Description: +This object indicates the status of this entry. + The default value is permanent(3). + other(1) - this entry is currently in use but the + conditions under which it will remain so are + different from each of the following values. + invalid(2) - writing this value to the object + removes the corresponding entry. + permanent(3) - this entry is currently in use and + will remain so after the next reset of the + bridge. + deleteOnReset(4) - this entry is currently in use + and will remain so until the next reset of the + bridge. + deleteOnTimeout(5) - this entry is currently in use + and will remain so until it is aged out. + * + * Attributes: + * accessible 1 isscalar 0 enums 1 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 1 + * + * Enum range: 3/8. Values: other(1), invalid(2), permanent(3), deleteOnReset(4), deleteOnTimeout(5) + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) + */ + + diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.c b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.c new file mode 100644 index 000000000..23c4e0660 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.c @@ -0,0 +1,202 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +/** \page MFD helper for dot1dStaticTable + * + * \section intro Introduction + * Introductory text. + * + */ +/* standard Net-SNMP includes */ +#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 our parent header */ +#include "dot1dStaticTable.h" + +#include <net-snmp/agent/mib_modules.h> + +#include "dot1dStaticTable_interface.h" + +const oid dot1dStaticTable_oid[] = { DOT1DSTATICTABLE_OID }; +const int dot1dStaticTable_oid_size = OID_LENGTH(dot1dStaticTable_oid); + + dot1dStaticTable_registration dot1dStaticTable_user_context; + +void initialize_table_dot1dStaticTable(void); +void shutdown_table_dot1dStaticTable(void); + + +/** + * Initializes the dot1dStaticTable module + */ +void +init_dot1dStaticTable(void) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:init_dot1dStaticTable","called\n")); + + /* + * TODO:300:o: Perform dot1dStaticTable one-time module initialization. + */ + + /* + * here we initialize all the tables we're planning on supporting + */ + if (should_init("dot1dStaticTable")) + initialize_table_dot1dStaticTable(); + +} /* init_dot1dStaticTable */ + +/** + * Shut-down the dot1dStaticTable module (agent is exiting) + */ +void +shutdown_dot1dStaticTable(void) +{ + if (should_init("dot1dStaticTable")) + shutdown_table_dot1dStaticTable(); + +} + +/** + * Initialize the table dot1dStaticTable + * (Define its contents and how it's structured) + */ +void +initialize_table_dot1dStaticTable(void) +{ + dot1dStaticTable_registration * user_context; + u_long flags; + + DEBUGMSGTL(("verbose:dot1dStaticTable:initialize_table_dot1dStaticTable","called\n")); + + /* + * TODO:301:o: Perform dot1dStaticTable one-time table initialization. + */ + + /* + * TODO:302:o: |->Initialize dot1dStaticTable user context + * if you'd like to pass in a pointer to some data for this + * table, allocate or set it up here. + */ + /* + * a netsnmp_data_list is a simple way to store void pointers. A simple + * string token is used to add, find or remove pointers. + */ + user_context = netsnmp_create_data_list("dot1dStaticTable", NULL, NULL); + + /* + * No support for any flags yet, but in the future you would + * set any flags here. + */ + flags = 0; + + /* + * call interface initialization code + */ + _dot1dStaticTable_initialize_interface(user_context, flags); +} /* initialize_table_dot1dStaticTable */ + +/** + * Shutdown the table dot1dStaticTable + */ +void +shutdown_table_dot1dStaticTable(void) +{ + /* + * call interface shutdown code + */ + _dot1dStaticTable_shutdown_interface(&dot1dStaticTable_user_context); +} + +/** + * extra context initialization (eg default values) + * + * @param rowreq_ctx : row request context + * @param user_init_ctx : void pointer for user (parameter to rowreq_ctx_allocate) + * + * @retval MFD_SUCCESS : no errors + * @retval MFD_ERROR : error (context allocate will fail) + */ +int +dot1dStaticTable_rowreq_ctx_init(dot1dStaticTable_rowreq_ctx *rowreq_ctx, + void *user_init_ctx) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_rowreq_ctx_init","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:210:o: |-> Perform extra dot1dStaticTable rowreq initialization. (eg DEFVALS) + */ + + return MFD_SUCCESS; +} /* dot1dStaticTable_rowreq_ctx_init */ + +/** + * extra context cleanup + * + */ +void dot1dStaticTable_rowreq_ctx_cleanup(dot1dStaticTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_rowreq_ctx_cleanup","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:211:o: |-> Perform extra dot1dStaticTable rowreq cleanup. + */ +} /* dot1dStaticTable_rowreq_ctx_cleanup */ + +/** + * pre-request callback + * + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error + */ +int +dot1dStaticTable_pre_request(dot1dStaticTable_registration * user_context) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_pre_request","called\n")); + + /* + * TODO:510:o: Perform dot1dStaticTable pre-request actions. + */ + + return MFD_SUCCESS; +} /* dot1dStaticTable_pre_request */ + +/** + * post-request callback + * + * Note: + * New rows have been inserted into the container, and + * deleted rows have been removed from the container and + * released. + * + * @param user_context + * @param rc : MFD_SUCCESS if all requests succeeded + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error (ignored) + */ +int +dot1dStaticTable_post_request(dot1dStaticTable_registration * user_context, int rc) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_post_request","called\n")); + + /* + * TODO:511:o: Perform dot1dStaticTable post-request actions. + */ + + return MFD_SUCCESS; +} /* dot1dStaticTable_post_request */ + + +/** @{ */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.h new file mode 100644 index 000000000..284727eac --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable.h @@ -0,0 +1,201 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +#ifndef DOT1DSTATICTABLE_H +#define DOT1DSTATICTABLE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/** @addtogroup misc misc: Miscellaneous routines + * + * @{ + */ +#include <net-snmp/library/asn1.h> + +/* other required module components */ + /* *INDENT-OFF* */ +config_add_mib(BRIDGE-MIB) +config_require(BRIDGE-MIB/dot1dStaticTable/dot1dStaticTable_interface) +config_require(BRIDGE-MIB/dot1dStaticTable/dot1dStaticTable_data_access) +config_require(BRIDGE-MIB/dot1dStaticTable/dot1dStaticTable_data_get) +config_require(BRIDGE-MIB/dot1dStaticTable/dot1dStaticTable_data_set) + /* *INDENT-ON* */ + +/* OID and column number definitions for dot1dStaticTable */ +#include "dot1dStaticTable_oids.h" + +/* enum definions */ +#include "dot1dStaticTable_enums.h" + +/* ********************************************************************* + * function declarations + */ +void init_dot1dStaticTable(void); +void shutdown_dot1dStaticTable(void); + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ +/* ********************************************************************* + * When you register your mib, you get to provide a generic + * pointer that will be passed back to you for most of the + * functions calls. + * + * TODO:100:r: Review all context structures + */ + /* + * TODO:101:o: |-> Review dot1dStaticTable registration context. + */ +typedef netsnmp_data_list dot1dStaticTable_registration; + +/**********************************************************************/ +/* + * TODO:110:r: |-> Review dot1dStaticTable data context structure. + * This structure is used to represent the data for dot1dStaticTable. + */ +/* + * This structure contains storage for all the columns defined in the + * dot1dStaticTable. + */ +typedef struct dot1dStaticTable_data_s { + + /* + * dot1dStaticAllowedToGoTo(3)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/h + */ + char dot1dStaticAllowedToGoTo[512]; +size_t dot1dStaticAllowedToGoTo_len; /* # of char elements, not bytes */ + + /* + * dot1dStaticStatus(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h + */ + u_long dot1dStaticStatus; + +} dot1dStaticTable_data; + + +/* + * TODO:120:r: |-> Review dot1dStaticTable mib index. + * This structure is used to represent the index for dot1dStaticTable. + */ +typedef struct dot1dStaticTable_mib_index_s { + + /* + * dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char dot1dStaticAddress[6]; + size_t dot1dStaticAddress_len; + + /* + * dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + long dot1dStaticReceivePort; + + +} dot1dStaticTable_mib_index; + + /* + * TODO:121:r: | |-> Review dot1dStaticTable max index length. + * If you KNOW that your indexes will never exceed a certain + * length, update this macro to that length. + * + * BE VERY CAREFUL TO TAKE INTO ACCOUNT THE MAXIMUM + * POSSIBLE LENGHT FOR EVERY VARIABLE LENGTH INDEX! + * Guessing 128 - col/entry(2) - oid len(9) +*/ +#define MAX_dot1dStaticTable_IDX_LEN 8 + + +/* ********************************************************************* + * TODO:130:o: |-> Review dot1dStaticTable Row request (rowreq) context. + * When your functions are called, you will be passed a + * dot1dStaticTable_rowreq_ctx pointer. + */ +typedef struct dot1dStaticTable_rowreq_ctx_s { + + /** this must be first for container compare to work */ + netsnmp_index oid_idx; + oid oid_tmp[MAX_dot1dStaticTable_IDX_LEN]; + + dot1dStaticTable_mib_index tbl_idx; + + dot1dStaticTable_data data; + + /* + * flags per row. Currently, the first (lower) 8 bits are reserved + * for the user. See mfd.h for other flags. + */ + u_int rowreq_flags; + + /* + * TODO:131:o: | |-> Add useful data to dot1dStaticTable rowreq context. + */ + + /* + * storage for future expansion + */ + netsnmp_data_list *dot1dStaticTable_data_list; + +} dot1dStaticTable_rowreq_ctx; + +typedef struct dot1dStaticTable_ref_rowreq_ctx_s { + dot1dStaticTable_rowreq_ctx *rowreq_ctx; +} dot1dStaticTable_ref_rowreq_ctx; + +/* ********************************************************************* + * function prototypes + */ + int dot1dStaticTable_pre_request(dot1dStaticTable_registration * user_context); + int dot1dStaticTable_post_request(dot1dStaticTable_registration * user_context, + int rc); + + int dot1dStaticTable_rowreq_ctx_init(dot1dStaticTable_rowreq_ctx *rowreq_ctx, + void *user_init_ctx); + void dot1dStaticTable_rowreq_ctx_cleanup(dot1dStaticTable_rowreq_ctx *rowreq_ctx); + + + dot1dStaticTable_rowreq_ctx * + dot1dStaticTable_row_find_by_mib_index(dot1dStaticTable_mib_index *mib_idx); + +extern const oid dot1dStaticTable_oid[]; +extern const int dot1dStaticTable_oid_size; + + +#include "dot1dStaticTable_interface.h" +#include "dot1dStaticTable_data_access.h" +#include "dot1dStaticTable_data_get.h" +#include "dot1dStaticTable_data_set.h" + +/* + * DUMMY markers, ignore + * + * TODO:099:x: ************************************************************* + * TODO:199:x: ************************************************************* + * TODO:299:x: ************************************************************* + * TODO:399:x: ************************************************************* + * TODO:499:x: ************************************************************* + */ + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_H */ +/** @} */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_Makefile b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_Makefile new file mode 100644 index 000000000..6e7c3b8d1 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_Makefile @@ -0,0 +1,57 @@ + +CC=gcc +TABLE_PREFIX=dot1dStaticTable + +NETSNMPCONFIG=net-snmp-config + + +# uncomment this if you have GNU make +#NETSNMPCFLAGS := $(shell $(NETSNMPCONFIG) --base-cflags) +#NETSNMPLIBS := $(shell $(NETSNMPCONFIG) --agent-libs) +NETSNMPCFLAGS=`$(NETSNMPCONFIG) --base-cflags` +NETSNMPLIBS=`$(NETSNMPCONFIG) --agent-libs` + +LIBS=$(NETSNMPLIBS) + + +STRICT_FLAGS = -Wall -Wstrict-prototypes +CFLAGS=-I. $(NETSNMPCFLAGS) $(STRICT_FLAGS) + +USER_SRCS = \ + $(TABLE_PREFIX)_data_get.c \ + $(TABLE_PREFIX)_data_set.c \ + $(TABLE_PREFIX)_data_access.c + +SRCS = $(USER_SRCS) \ + $(TABLE_PREFIX).c \ + $(TABLE_PREFIX)_subagent.c \ + $(TABLE_PREFIX)_interface.c + +USER_OBJS = \ + $(TABLE_PREFIX)_data_get.o \ + $(TABLE_PREFIX)_data_set.o \ + $(TABLE_PREFIX)_data_access.o + +OBJS = $(USER_OBJS) \ + $(TABLE_PREFIX).o \ + $(TABLE_PREFIX)_subagent.o \ + $(TABLE_PREFIX)_interface.o + +TARGETS=$(TABLE_PREFIX) + +.SUFFIXES: +.SUFFIXES: .c .o .deps + + +all: $(TARGETS) + +user: $(USER_OBJS) + +$(TARGETS): $(LIB_DEPS) + +$(TABLE_PREFIX): $(OBJS) $(TABLE_PREFIX)_Makefile + $(CC) -o $(TABLE_PREFIX) $(OBJS) $(LIBS) + +clean: + rm -f $(OBJS) $(TARGETS) + diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.c b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.c new file mode 100644 index 000000000..590bbff66 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.c @@ -0,0 +1,431 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +/* standard Net-SNMP includes */ +#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 our parent header */ +#include "dot1dStaticTable.h" + + +#include "dot1dStaticTable_data_access.h" + +/** @ingroup interface + * @addtogroup data_access data_access: Routines to access data + * + * These routines are used to locate the data used to satisfy + * requests. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ + +/** + * initialization for dot1dStaticTable data access + * + * This function is called during startup to allow you to + * allocate any resources you need for the data table. + * + * @param dot1dStaticTable_reg + * Pointer to dot1dStaticTable_registration + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : unrecoverable error. + */ +int +dot1dStaticTable_init_data(dot1dStaticTable_registration * dot1dStaticTable_reg) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_init_data","called\n")); + + /* + * TODO:303:o: Initialize dot1dStaticTable data. + */ + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ + /* + * if you are the sole writer for the file, you could + * open it here. However, as stated earlier, we are assuming + * the worst case, which in this case means that the file is + * written to by someone else, and might not even exist when + * we start up. So we can't do anything here. + */ + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + + return MFD_SUCCESS; +} /* dot1dStaticTable_init_data */ + +/** + * container overview + * + */ + +/** + * container initialization + * + * @param container_ptr_ptr A pointer to a container pointer. If you + * create a custom container, use this parameter to return it + * to the MFD helper. If set to NULL, the MFD helper will + * allocate a container for you. + * @param cache A pointer to a cache structure. You can set the timeout + * and other cache flags using this pointer. + * + * This function is called at startup to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. If no custom + * container is allocated, the MFD code will create one for your. + * + * This is also the place to set up cache behavior. The default, to + * simply set the cache timeout, will work well with the default + * container. If you are using a custom container, you may want to + * look at the cache helper documentation to see if there are any + * flags you want to set. + * + * @remark + * This would also be a good place to do any initialization needed + * for you data source. For example, opening a connection to another + * process that will supply the data, opening a database, etc. + */ +void +dot1dStaticTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_container_init","called\n")); + + if (NULL == container_ptr_ptr) { + snmp_log(LOG_ERR,"bad container param to dot1dStaticTable_container_init\n"); + return; + } + + /* + * For advanced users, you can use a custom container. If you + * do not create one, one will be created for you. + */ + *container_ptr_ptr = NULL; + + if (NULL == cache) { + snmp_log(LOG_ERR,"bad cache param to dot1dStaticTable_container_init\n"); + return; + } + + /* + * TODO:345:A: Set up dot1dStaticTable cache properties. + * + * Also for advanced users, you can set parameters for the + * cache. Do not change the magic pointer, as it is used + * by the MFD helper. To completely disable caching, set + * cache->enabled to 0. + */ + cache->timeout = DOT1DSTATICTABLE_CACHE_TIMEOUT; /* seconds */ +} /* dot1dStaticTable_container_init */ + +/** + * container shutdown + * + * @param container_ptr A pointer to the container. + * + * This function is called at shutdown to allow you to customize certain + * aspects of the access method. For the most part, it is for advanced + * users. The default code should suffice for most cases. + * + * This function is called before dot1dStaticTable_container_free(). + * + * @remark + * This would also be a good place to do any cleanup needed + * for you data source. For example, closing a connection to another + * process that supplied the data, closing a database, etc. + */ +void +dot1dStaticTable_container_shutdown(netsnmp_container *container_ptr) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_container_shutdown","called\n")); + + if (NULL == container_ptr) { + snmp_log(LOG_ERR,"bad params to dot1dStaticTable_container_shutdown\n"); + return; + } + +} /* dot1dStaticTable_container_shutdown */ + +/** + * load initial data + * + * TODO:350:M: Implement dot1dStaticTable data load + * This function will also be called by the cache helper to load + * the container again (after the container free function has been + * called to free the previous contents). + * + * @param container container to which items should be inserted + * + * @retval MFD_SUCCESS : success. + * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source + * @retval MFD_ERROR : other error. + * + * This function is called to load the index(es) (and data, optionally) + * for the every row in the data set. + * + * @remark + * While loading the data, the only important thing is the indexes. + * If access to your data is cheap/fast (e.g. you have a pointer to a + * structure in memory), it would make sense to update the data here. + * If, however, the accessing the data invovles more work (e.g. parsing + * some other existing data, or peforming calculations to derive the data), + * then you can limit yourself to setting the indexes and saving any + * information you will need later. Then use the saved information in + * dot1dStaticTable_row_prep() for populating data. + * + * @note + * If you need consistency between rows (like you want statistics + * for each row to be from the same time frame), you should set all + * data here. + * + */ +int +dot1dStaticTable_container_load(netsnmp_container *container) +{ + dot1dStaticTable_rowreq_ctx *rowreq_ctx; + size_t count = 0; + + /* + * temporary storage for index values + */ + /* + * dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + char dot1dStaticAddress[6]; + size_t dot1dStaticAddress_len; + /* + * dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + long dot1dStaticReceivePort; + + + /* + * this example code is based on a data source that is a + * text file to be read and parsed. + */ + FILE *filep; + char line[MAX_LINE_SIZE]; + + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_container_load","called\n")); + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ + /* + * open our data file. + */ + filep = fopen("/etc/dummy.conf", "r"); + if(NULL == filep) { + return MFD_RESOURCE_UNAVAILABLE; + } + + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + /* + * TODO:351:M: |-> Load/update data in the dot1dStaticTable container. + * loop over your dot1dStaticTable data, allocate a rowreq context, + * set the index(es) [and data, optionally] and insert into + * the container. + */ + while( 1 ) { + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ + /* + * get a line (skip blank lines) + */ + do { + if (!fgets(line, sizeof(line), filep)) { + /* we're done */ + fclose(filep); + filep = NULL; + } + } while (filep && (line[0] == '\n')); + + /* + * check for end of data + */ + if(NULL == filep) + break; + + /* + * parse line into variables + */ + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + + /* + * TODO:352:M: | |-> set indexes in new dot1dStaticTable rowreq context. + * data context will be set from the param (unless NULL, + * in which case a new data context will be allocated) + */ + rowreq_ctx = dot1dStaticTable_allocate_rowreq_ctx(NULL); + if (NULL == rowreq_ctx) { + snmp_log(LOG_ERR, "memory allocation failed\n"); + return MFD_RESOURCE_UNAVAILABLE; + } + if(MFD_SUCCESS != dot1dStaticTable_indexes_set(rowreq_ctx + , dot1dStaticAddress, dot1dStaticAddress_len + , dot1dStaticReceivePort + )) { + snmp_log(LOG_ERR,"error setting index while loading " + "dot1dStaticTable data.\n"); + dot1dStaticTable_release_rowreq_ctx(rowreq_ctx); + continue; + } + + /* + * TODO:352:r: | |-> populate dot1dStaticTable data context. + * Populate data context here. (optionally, delay until row prep) + */ + /* + * TRANSIENT or semi-TRANSIENT data: + * copy data or save any info needed to do it in row_prep. + */ + /* + * setup/save data for dot1dStaticAllowedToGoTo + * dot1dStaticAllowedToGoTo(3)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/h + */ + /* + * TODO:246:r: |-> Define dot1dStaticAllowedToGoTo mapping. + * Map values between raw/native values and MIB values + * + * if(MFD_SUCCESS != + * dot1dStaticAllowedToGoTo_map(&rowreq_ctx->data.dot1dStaticAllowedToGoTo, &rowreq_ctx->data.dot1dStaticAllowedToGoTo_len, + * dot1dStaticAllowedToGoTo, dot1dStaticAllowedToGoTo_len, 0)) { + * return MFD_ERROR; + * } + */ + /* + * make sure there is enough space for dot1dStaticAllowedToGoTo data + */ + if ((NULL == rowreq_ctx->data.dot1dStaticAllowedToGoTo) || + (rowreq_ctx->data.dot1dStaticAllowedToGoTo_len < + (dot1dStaticAllowedToGoTo_len* sizeof(dot1dStaticAllowedToGoTo[0])))) { + snmp_log(LOG_ERR,"not enough space for value (dot1dStaticAllowedToGoTo)\n"); + return MFD_ERROR; + } + rowreq_ctx->data.dot1dStaticAllowedToGoTo_len = dot1dStaticAllowedToGoTo_len* sizeof(dot1dStaticAllowedToGoTo[0]); + memcpy( rowreq_ctx->data.dot1dStaticAllowedToGoTo, dot1dStaticAllowedToGoTo, dot1dStaticAllowedToGoTo_len* sizeof(dot1dStaticAllowedToGoTo[0]) ); + + /* + * setup/save data for dot1dStaticStatus + * dot1dStaticStatus(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h + */ + /* + * TODO:246:r: |-> Define dot1dStaticStatus mapping. + * Map values between raw/native values and MIB values + * + * enums usually need mapping. + */ + if(MFD_SUCCESS != + dot1dStaticStatus_map(&rowreq_ctx->data.dot1dStaticStatus, dot1dStaticStatus )) { + return MFD_ERROR; + } + + + /* + * insert into table container + */ + CONTAINER_INSERT(container, rowreq_ctx); + ++count; + } + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ + if(NULL != filep) + fclose(filep); + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + + DEBUGMSGT(("verbose:dot1dStaticTable:dot1dStaticTable_container_load", + "inserted %d records\n", count)); + + return MFD_SUCCESS; +} /* dot1dStaticTable_container_load */ + +/** + * container clean up + * + * @param container container with all current items + * + * This optional callback is called prior to all + * item's being removed from the container. If you + * need to do any processing before that, do it here. + * + * @note + * The MFD helper will take care of releasing all the row contexts. + * + */ +void +dot1dStaticTable_container_free(netsnmp_container *container) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_container_free","called\n")); + + /* + * TODO:380:M: Free dot1dStaticTable container data. + */ +} /* dot1dStaticTable_container_free */ + +/** + * prepare row for processing. + * + * When the agent has located the row for a request, this function is + * called to prepare the row for processing. If you fully populated + * the data context during the index setup phase, you may not need to + * do anything. + * + * @param rowreq_ctx pointer to a context. + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + */ +int +dot1dStaticTable_row_prep( dot1dStaticTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_row_prep","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + /* + * TODO:390:o: Prepare row for request. + * If populating row data was delayed, this is the place to + * fill in the row for this request. + */ + + return MFD_SUCCESS; +} /* dot1dStaticTable_row_prep */ + +/** @} */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.h new file mode 100644 index 000000000..373b0adbe --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_access.h @@ -0,0 +1,76 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +#ifndef DOT1DSTATICTABLE_DATA_ACCESS_H +#define DOT1DSTATICTABLE_DATA_ACCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* ********************************************************************* + * function declarations + */ + +/* ********************************************************************* + * Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ + + + int dot1dStaticTable_init_data(dot1dStaticTable_registration * dot1dStaticTable_reg); + + + /* + * TODO:180:o: Review dot1dStaticTable cache timeout. + * The number of seconds before the cache times out + */ +#define DOT1DSTATICTABLE_CACHE_TIMEOUT 60 + +void dot1dStaticTable_container_init(netsnmp_container **container_ptr_ptr, + netsnmp_cache *cache); +void dot1dStaticTable_container_shutdown(netsnmp_container *container_ptr); + +int dot1dStaticTable_container_load(netsnmp_container *container); +void dot1dStaticTable_container_free(netsnmp_container *container); + +int dot1dStaticTable_cache_load(netsnmp_container *container); +void dot1dStaticTable_cache_free(netsnmp_container *container); + + /* + *************************************************** + *** START EXAMPLE CODE *** + ***---------------------------------------------***/ +/* ********************************************************************* + * Since we have no idea how you really access your data, we'll go with + * a worst case example: a flat text file. + */ +#define MAX_LINE_SIZE 256 + /* + ***---------------------------------------------*** + *** END EXAMPLE CODE *** + ***************************************************/ + int dot1dStaticTable_row_prep( dot1dStaticTable_rowreq_ctx *rowreq_ctx); + + + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_DATA_ACCESS_H */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.c b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.c new file mode 100644 index 000000000..47ca4fc95 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.c @@ -0,0 +1,357 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +/* standard Net-SNMP includes */ +#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 our parent header */ +#include "dot1dStaticTable.h" + + +/** @defgroup data_get data_get: Routines to get data + * + * TODO:230:M: Implement dot1dStaticTable get routines. + * TODO:240:M: Implement dot1dStaticTable mapping routines (if any). + * + * These routine are used to get the value for individual objects. The + * row context is passed, along with a pointer to the memory where the + * value should be copied. + * + * @{ + */ +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ + +/* --------------------------------------------------------------------- + * TODO:200:r: Implement dot1dStaticTable data context functions. + */ + + +/** + * set mib index(es) + * + * @param tbl_idx mib index structure + * @param dot1dStaticAddress_ptr + * @param dot1dStaticAddress_ptr_len + * @param dot1dStaticReceivePort_val + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This convenience function is useful for setting all the MIB index + * components with a single function call. It is assume that the C values + * have already been mapped from their native/rawformat to the MIB format. + */ +int +dot1dStaticTable_indexes_set_tbl_idx(dot1dStaticTable_mib_index *tbl_idx, char *dot1dStaticAddress_val_ptr, size_t dot1dStaticAddress_val_ptr_len, long dot1dStaticReceivePort_val) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_indexes_set_tbl_idx","called\n")); + + /* dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + tbl_idx->dot1dStaticAddress_len = sizeof(tbl_idx->dot1dStaticAddress)/sizeof(tbl_idx->dot1dStaticAddress[0]); /* max length */ + /* + * make sure there is enough space for dot1dStaticAddress data + */ + if ((NULL == tbl_idx->dot1dStaticAddress) || + (tbl_idx->dot1dStaticAddress_len < + (dot1dStaticAddress_val_ptr_len))) { + snmp_log(LOG_ERR,"not enough space for value (dot1dStaticAddress_val_ptr)\n"); + return MFD_ERROR; + } + tbl_idx->dot1dStaticAddress_len = dot1dStaticAddress_val_ptr_len; + memcpy( tbl_idx->dot1dStaticAddress, dot1dStaticAddress_val_ptr, dot1dStaticAddress_val_ptr_len* sizeof(dot1dStaticAddress_val_ptr[0]) ); + + /* dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */ + tbl_idx->dot1dStaticReceivePort = dot1dStaticReceivePort_val; + + + return MFD_SUCCESS; +} /* dot1dStaticTable_indexes_set_tbl_idx */ + +/** + * @internal + * set row context indexes + * + * @param reqreq_ctx the row context that needs updated indexes + * + * @retval MFD_SUCCESS : success. + * @retval MFD_ERROR : other error. + * + * @remark + * This function sets the mib indexs, then updates the oid indexs + * from the mib index. + */ +int +dot1dStaticTable_indexes_set(dot1dStaticTable_rowreq_ctx *rowreq_ctx, char *dot1dStaticAddress_val_ptr, size_t dot1dStaticAddress_val_ptr_len, long dot1dStaticReceivePort_val) +{ + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_indexes_set","called\n")); + + if(MFD_SUCCESS != dot1dStaticTable_indexes_set_tbl_idx(&rowreq_ctx->tbl_idx + , dot1dStaticAddress_val_ptr, dot1dStaticAddress_val_ptr_len + , dot1dStaticReceivePort_val + )) + return MFD_ERROR; + + /* + * convert mib index to oid index + */ + rowreq_ctx->oid_idx.len = sizeof(rowreq_ctx->oid_tmp) / sizeof(oid); + if(0 != dot1dStaticTable_index_to_oid(&rowreq_ctx->oid_idx, + &rowreq_ctx->tbl_idx)) { + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* dot1dStaticTable_indexes_set */ + + +/*--------------------------------------------------------------------- + * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticAllowedToGoTo + * dot1dStaticAllowedToGoTo is subid 3 of dot1dStaticEntry. + * Its status is Current, and its access level is Create. + * OID: .1.3.6.1.2.1.17.5.1.1.3 + * Description: +The set of ports to which frames received from a + specific port and destined for a specific MAC address, + are allowed to be forwarded. Each octet within the + value of this object specifies a set of eight ports, + with the first octet specifying ports 1 through 8, the + second octet specifying ports 9 through 16, etc. Within + each octet, the most significant bit represents the + lowest numbered port, and the least significant bit + represents the highest numbered port. Thus, each port + of the bridge is represented by a single bit within the + value of this object. If that bit has a value of '1', + then that port is included in the set of ports; the port + is not included if its bit has a value of '0'. (Note + that the setting of the bit corresponding to the port + from which a frame is received is irrelevant.) The + default value of this object is a string of ones of + appropriate length. + + The value of this object may exceed the required minimum + maximum message size of some SNMP transport (484 bytes, + in the case of SNMP over UDP, see RFC 3417, section 3.2). + SNMP engines on bridges supporting a large number of + ports must support appropriate maximum message sizes. + * + * Attributes: + * accessible 1 isscalar 0 enums 0 hasdefval 0 + * readable 1 iscolumn 1 ranges 1 hashint 0 + * settable 1 + * + * Ranges: 0 - 512; + * + * Its syntax is OCTETSTR (based on perltype OCTETSTR) + * The net-snmp type is ASN_OCTET_STR. The C type decl is char (char) + * This data type requires a length. (Max 512) + */ +/** + * Extract the current value of the dot1dStaticAllowedToGoTo data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param dot1dStaticAllowedToGoTo_val_ptr_ptr + * Pointer to storage for a char variable + * @param dot1dStaticAllowedToGoTo_val_ptr_len_ptr + * Pointer to a size_t. On entry, it will contain the size (in bytes) + * pointed to by dot1dStaticAllowedToGoTo. + * On exit, this value should contain the data size (in bytes). + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error +* + * @note If you need more than (*dot1dStaticAllowedToGoTo_val_ptr_len_ptr) bytes of memory, + * allocate it using malloc() and update dot1dStaticAllowedToGoTo_val_ptr_ptr. + * <b>DO NOT</b> free the previous pointer. + * The MFD helper will release the memory you allocate. + * + * @remark If you call this function yourself, you are responsible + * for checking if the pointer changed, and freeing any + * previously allocated memory. (Not necessary if you pass + * in a pointer to static memory, obviously.) + */ +int +dot1dStaticAllowedToGoTo_get( dot1dStaticTable_rowreq_ctx *rowreq_ctx, char **dot1dStaticAllowedToGoTo_val_ptr_ptr, size_t *dot1dStaticAllowedToGoTo_val_ptr_len_ptr ) +{ + /** we should have a non-NULL pointer and enough storage */ + netsnmp_assert( (NULL != dot1dStaticAllowedToGoTo_val_ptr_ptr) && (NULL != *dot1dStaticAllowedToGoTo_val_ptr_ptr)); + netsnmp_assert( NULL != dot1dStaticAllowedToGoTo_val_ptr_len_ptr ); + + + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticAllowedToGoTo_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the dot1dStaticAllowedToGoTo data. + * copy (* dot1dStaticAllowedToGoTo_val_ptr_ptr ) data and (* dot1dStaticAllowedToGoTo_val_ptr_len_ptr ) from rowreq_ctx->data + */ + /* + * make sure there is enough space for dot1dStaticAllowedToGoTo data + */ + if ((NULL == (* dot1dStaticAllowedToGoTo_val_ptr_ptr )) || + ((* dot1dStaticAllowedToGoTo_val_ptr_len_ptr ) < + (rowreq_ctx->data.dot1dStaticAllowedToGoTo_len* sizeof(rowreq_ctx->data.dot1dStaticAllowedToGoTo[0])))) { + /* + * allocate space for dot1dStaticAllowedToGoTo data + */ + (* dot1dStaticAllowedToGoTo_val_ptr_ptr ) = malloc(rowreq_ctx->data.dot1dStaticAllowedToGoTo_len* sizeof(rowreq_ctx->data.dot1dStaticAllowedToGoTo[0])); + if(NULL == (* dot1dStaticAllowedToGoTo_val_ptr_ptr )) { + snmp_log(LOG_ERR,"could not allocate memory (rowreq_ctx->data.dot1dStaticAllowedToGoTo)\n"); + return MFD_ERROR; + } + } + (* dot1dStaticAllowedToGoTo_val_ptr_len_ptr ) = rowreq_ctx->data.dot1dStaticAllowedToGoTo_len* sizeof(rowreq_ctx->data.dot1dStaticAllowedToGoTo[0]); + memcpy( (* dot1dStaticAllowedToGoTo_val_ptr_ptr ), rowreq_ctx->data.dot1dStaticAllowedToGoTo, rowreq_ctx->data.dot1dStaticAllowedToGoTo_len* sizeof(rowreq_ctx->data.dot1dStaticAllowedToGoTo[0]) ); + + return MFD_SUCCESS; +} /* dot1dStaticAllowedToGoTo_get */ + +/*--------------------------------------------------------------------- + * BRIDGE-MIB::dot1dStaticEntry.dot1dStaticStatus + * dot1dStaticStatus is subid 4 of dot1dStaticEntry. + * Its status is Current, and its access level is Create. + * OID: .1.3.6.1.2.1.17.5.1.1.4 + * Description: +This object indicates the status of this entry. + The default value is permanent(3). + other(1) - this entry is currently in use but the + conditions under which it will remain so are + different from each of the following values. + invalid(2) - writing this value to the object + removes the corresponding entry. + permanent(3) - this entry is currently in use and + will remain so after the next reset of the + bridge. + deleteOnReset(4) - this entry is currently in use + and will remain so until the next reset of the + bridge. + deleteOnTimeout(5) - this entry is currently in use + and will remain so until it is aged out. + * + * Attributes: + * accessible 1 isscalar 0 enums 1 hasdefval 0 + * readable 1 iscolumn 1 ranges 0 hashint 0 + * settable 1 + * + * Enum range: 3/8. Values: other(1), invalid(2), permanent(3), deleteOnReset(4), deleteOnTimeout(5) + * + * Its syntax is INTEGER (based on perltype INTEGER) + * The net-snmp type is ASN_INTEGER. The C type decl is long (u_long) + */ +/** + * map a value from its original native format to the MIB format. + * + * @retval MFD_SUCCESS : success + * @retval MFD_ERROR : Any other error + * + * @note parameters follow the memset convention (dest, src). + * + * @note generation and use of this function can be turned off by re-running + * mib2c after adding the following line to the file + * defaults/node-dot1dStaticStatus.m2d : + * @eval $m2c_node_skip_mapping = 1@ + * + * @remark + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them here. + * Otherwise, just do a direct copy. + */ +int +dot1dStaticStatus_map(u_long *mib_dot1dStaticStatus_val_ptr, u_long raw_dot1dStaticStatus_val) +{ + netsnmp_assert(NULL != mib_dot1dStaticStatus_val_ptr); + + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticStatus_map","called\n")); + + /* + * TODO:241:o: |-> Implement dot1dStaticStatus enum mapping. + * uses INTERNAL_* macros defined in the header files + */ + switch(raw_dot1dStaticStatus_val) { + case INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_OTHER: + *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_OTHER; + break; + + case INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_INVALID: + *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_INVALID; + break; + + case INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_PERMANENT: + *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_PERMANENT; + break; + + case INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_DELETEONRESET: + *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_DELETEONRESET; + break; + + case INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_DELETEONTIMEOUT: + *mib_dot1dStaticStatus_val_ptr = DOT1DSTATICSTATUS_DELETEONTIMEOUT; + break; + + default: + snmp_log(LOG_ERR, "couldn't map value %ld for dot1dStaticStatus\n", raw_dot1dStaticStatus_val ); + return MFD_ERROR; + } + + return MFD_SUCCESS; +} /* dot1dStaticStatus_map */ + +/** + * Extract the current value of the dot1dStaticStatus data. + * + * Set a value using the data context for the row. + * + * @param rowreq_ctx + * Pointer to the row request context. + * @param dot1dStaticStatus_val_ptr + * Pointer to storage for a long variable + * + * @retval MFD_SUCCESS : success + * @retval MFD_SKIP : skip this node (no value for now) + * @retval MFD_ERROR : Any other error + */ +int +dot1dStaticStatus_get( dot1dStaticTable_rowreq_ctx *rowreq_ctx, u_long * dot1dStaticStatus_val_ptr ) +{ + /** we should have a non-NULL pointer */ + netsnmp_assert( NULL != dot1dStaticStatus_val_ptr ); + + + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticStatus_get","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + +/* + * TODO:231:o: |-> Extract the current value of the dot1dStaticStatus data. + * copy (* dot1dStaticStatus_val_ptr ) from rowreq_ctx->data + */ + (* dot1dStaticStatus_val_ptr ) = rowreq_ctx->data.dot1dStaticStatus; + + return MFD_SUCCESS; +} /* dot1dStaticStatus_get */ + + + +/** @} */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.h new file mode 100644 index 000000000..516a8a255 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_get.h @@ -0,0 +1,64 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + * + * @file dot1dStaticTable_data_get.h + * + * @addtogroup get + * + * Prototypes for get functions + * + * @{ + */ +#ifndef DOT1DSTATICTABLE_DATA_GET_H +#define DOT1DSTATICTABLE_DATA_GET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * GET function declarations + */ + +/* ********************************************************************* + * GET Table declarations + */ +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ + /* + * indexes + */ + int dot1dStaticAddress_map(char **mib_dot1dStaticAddress_val_ptr_ptr, size_t *mib_dot1dStaticAddress_val_ptr_len_ptr, char *raw_dot1dStaticAddress_val_ptr, size_t raw_dot1dStaticAddress_val_ptr_len, int allow_realloc); + int dot1dStaticReceivePort_map(long *mib_dot1dStaticReceivePort_val_ptr, long raw_dot1dStaticReceivePort_val); + + int dot1dStaticAllowedToGoTo_map(char **mib_dot1dStaticAllowedToGoTo_val_ptr_ptr, size_t *mib_dot1dStaticAllowedToGoTo_val_ptr_len_ptr, char *raw_dot1dStaticAllowedToGoTo_val_ptr, size_t raw_dot1dStaticAllowedToGoTo_val_ptr_len, int allow_realloc); + int dot1dStaticAllowedToGoTo_get( dot1dStaticTable_rowreq_ctx *rowreq_ctx, char **dot1dStaticAllowedToGoTo_val_ptr_ptr, size_t *dot1dStaticAllowedToGoTo_val_ptr_len_ptr ); + int dot1dStaticStatus_map(u_long *mib_dot1dStaticStatus_val_ptr, u_long raw_dot1dStaticStatus_val); + int dot1dStaticStatus_get( dot1dStaticTable_rowreq_ctx *rowreq_ctx, u_long * dot1dStaticStatus_val_ptr ); + + +int dot1dStaticTable_indexes_set_tbl_idx(dot1dStaticTable_mib_index *tbl_idx, char *dot1dStaticAddress_val_ptr, size_t dot1dStaticAddress_val_ptr_len, long dot1dStaticReceivePort_val); +int dot1dStaticTable_indexes_set(dot1dStaticTable_rowreq_ctx *rowreq_ctx, char *dot1dStaticAddress_val_ptr, size_t dot1dStaticAddress_val_ptr_len, long dot1dStaticReceivePort_val); + + + + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_DATA_GET_H */ +/** @} */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.c b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.c new file mode 100644 index 000000000..c859d8bbc --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.c @@ -0,0 +1,25 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + * + */ +/* standard Net-SNMP includes */ +#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 our parent header */ +#include "dot1dStaticTable.h" + + +/** @defgroup data_set data_set: Routines to set data + * + * These routines are used to set the value for individual objects. The + * row context is passed, along with the new value. + * + * @{ + */ +/** @} */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.h new file mode 100644 index 000000000..487a8589e --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_data_set.h @@ -0,0 +1,27 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +#ifndef DOT1DSTATICTABLE_DATA_SET_H +#define DOT1DSTATICTABLE_DATA_SET_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* ********************************************************************* + * SET function declarations + */ + +/* ********************************************************************* + * SET Table declarations + */ + + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_DATA_SET_H */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_enums.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_enums.h new file mode 100644 index 000000000..36e61a8b8 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_enums.h @@ -0,0 +1,69 @@ +/* + * Note: this file originally auto-generated by mib2c using + * $ + * + * $Id:$ + */ +#ifndef DOT1DSTATICTABLE_ENUMS_H +#define DOT1DSTATICTABLE_ENUMS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * NOTES on enums + * ============== + * + * Value Mapping + * ------------- + * If the values for your data type don't exactly match the + * possible values defined by the mib, you should map them + * below. For example, a boolean flag (1/0) is usually represented + * as a TruthValue in a MIB, which maps to the values (1/2). + * + */ +/************************************************************************* + ************************************************************************* + * + * enum definitions for table dot1dStaticTable + * + ************************************************************************* + *************************************************************************/ + +/************************************************************* + * constants for enums for the MIB node + * dot1dStaticStatus (INTEGER / ASN_INTEGER) + * + * since a Textual Convention may be referenced more than once in a + * MIB, protect againt redefinitions of the enum values. + */ +#ifndef DOT1DSTATICSTATUS_ENUMS +#define DOT1DSTATICSTATUS_ENUMS + +#define DOT1DSTATICSTATUS_OTHER 1 +#define DOT1DSTATICSTATUS_INVALID 2 +#define DOT1DSTATICSTATUS_PERMANENT 3 +#define DOT1DSTATICSTATUS_DELETEONRESET 4 +#define DOT1DSTATICSTATUS_DELETEONTIMEOUT 5 + +#endif /* DOT1DSTATICSTATUS_ENUMS */ + + /* + * TODO:140:o: Define your interal representation of dot1dStaticStatus enums. + * (used for value mapping; see notes at top of file) + */ +#define INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_OTHER 1 +#define INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_INVALID 2 +#define INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_PERMANENT 3 +#define INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_DELETEONRESET 4 +#define INTERNAL_DOT1DSTATICTABLE_DOT1DSTATICSTATUS_DELETEONTIMEOUT 5 + + + + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_ENUMS_H */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.c b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.c new file mode 100644 index 000000000..33609982d --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.c @@ -0,0 +1,920 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +/* + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + * *** *** + * *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE *** + * *** *** + * *** *** + * *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. *** + * *** *** + * *** *** + * *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND *** + * *** *** + * *** *** + * *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. *** + * *** *** + * *** *** + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + */ + +/* standard Net-SNMP includes */ +#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 our parent header */ +#include "dot1dStaticTable.h" + + +#include <net-snmp/agent/table_container.h> +#include <net-snmp/library/container.h> + +#include "dot1dStaticTable_interface.h" + +netsnmp_feature_require(baby_steps) +netsnmp_feature_require(row_merge) +netsnmp_feature_require(check_all_requests_error) + +#include <ctype.h> + +/********************************************************************** + ********************************************************************** + *** + *** Table dot1dStaticTable + *** + ********************************************************************** + **********************************************************************/ +/* + * BRIDGE-MIB::dot1dStaticTable is subid 1 of dot1dStatic. + * Its status is Current. + * OID: .1.3.6.1.2.1.17.5.1, length: 9 +*/ +typedef struct dot1dStaticTable_interface_ctx_s { + + netsnmp_container *container; + netsnmp_cache *cache; + + dot1dStaticTable_registration * user_ctx; + + netsnmp_table_registration_info tbl_info; + + netsnmp_baby_steps_access_methods access_multiplexer; + +} dot1dStaticTable_interface_ctx; + +static dot1dStaticTable_interface_ctx dot1dStaticTable_if_ctx; + +static void _dot1dStaticTable_container_init( + dot1dStaticTable_interface_ctx *if_ctx); +static void _dot1dStaticTable_container_shutdown( + dot1dStaticTable_interface_ctx *if_ctx); + + +netsnmp_container * +dot1dStaticTable_container_get( void ) +{ + return dot1dStaticTable_if_ctx.container; +} + +dot1dStaticTable_registration * +dot1dStaticTable_registration_get( void ) +{ + return dot1dStaticTable_if_ctx.user_ctx; +} + +dot1dStaticTable_registration * +dot1dStaticTable_registration_set( dot1dStaticTable_registration * newreg ) +{ + dot1dStaticTable_registration * old = dot1dStaticTable_if_ctx.user_ctx; + dot1dStaticTable_if_ctx.user_ctx = newreg; + return old; +} + +int +dot1dStaticTable_container_size( void ) +{ + return CONTAINER_SIZE(dot1dStaticTable_if_ctx.container); +} + +/* + * mfd multiplexer modes + */ +static Netsnmp_Node_Handler _mfd_dot1dStaticTable_pre_request; +static Netsnmp_Node_Handler _mfd_dot1dStaticTable_post_request; +static Netsnmp_Node_Handler _mfd_dot1dStaticTable_object_lookup; +static Netsnmp_Node_Handler _mfd_dot1dStaticTable_get_values; +/** + * @internal + * Initialize the table dot1dStaticTable + * (Define its contents and how it's structured) + */ +void +_dot1dStaticTable_initialize_interface(dot1dStaticTable_registration * reg_ptr, u_long flags) +{ + netsnmp_baby_steps_access_methods *access_multiplexer = + &dot1dStaticTable_if_ctx.access_multiplexer; + netsnmp_table_registration_info *tbl_info = &dot1dStaticTable_if_ctx.tbl_info; + netsnmp_handler_registration *reginfo; + netsnmp_mib_handler *handler; + int mfd_modes = 0; + + DEBUGMSGTL(("internal:dot1dStaticTable:_dot1dStaticTable_initialize_interface","called\n")); + + + /************************************************* + * + * save interface context for dot1dStaticTable + */ + /* + * Setting up the table's definition + */ + netsnmp_table_helper_add_indexes(tbl_info, + ASN_OCTET_STR, /** index: dot1dStaticAddress */ + ASN_INTEGER, /** index: dot1dStaticReceivePort */ + 0); + + /* Define the minimum and maximum accessible columns. This + optimizes retrieval. */ + tbl_info->min_column = DOT1DSTATICTABLE_MIN_COL; + tbl_info->max_column = DOT1DSTATICTABLE_MAX_COL; + + /* + * save users context + */ + dot1dStaticTable_if_ctx.user_ctx = reg_ptr; + + /* + * call data access initialization code + */ + dot1dStaticTable_init_data(reg_ptr); + + /* + * set up the container + */ + _dot1dStaticTable_container_init(&dot1dStaticTable_if_ctx); + if (NULL == dot1dStaticTable_if_ctx.container) { + snmp_log(LOG_ERR,"could not initialize container for dot1dStaticTable\n"); + return; + } + + /* + * access_multiplexer: REQUIRED wrapper for get request handling + */ + access_multiplexer->object_lookup = _mfd_dot1dStaticTable_object_lookup; + access_multiplexer->get_values = _mfd_dot1dStaticTable_get_values; + + /* + * no wrappers yet + */ + access_multiplexer->pre_request = _mfd_dot1dStaticTable_pre_request; + access_multiplexer->post_request = _mfd_dot1dStaticTable_post_request; + +#ifndef NETSNMP_DISABLE_SET_SUPPORT +#endif + + /************************************************* + * + * Create a registration, save our reg data, register table. + */ + DEBUGMSGTL(("dot1dStaticTable:init_dot1dStaticTable", + "Registering dot1dStaticTable as a mibs-for-dummies table.\n")); + handler = netsnmp_baby_steps_access_multiplexer_get(access_multiplexer); + reginfo = netsnmp_handler_registration_create("dot1dStaticTable", handler, + dot1dStaticTable_oid, + dot1dStaticTable_oid_size, + HANDLER_CAN_BABY_STEP | +#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) + HANDLER_CAN_RONLY +#else + HANDLER_CAN_RONLY +#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ + ); + if(NULL == reginfo) { + snmp_log(LOG_ERR,"error registering table dot1dStaticTable\n"); + return; + } + reginfo->my_reg_void = &dot1dStaticTable_if_ctx; + + /************************************************* + * + * set up baby steps handler, create it and inject it + */ + if( access_multiplexer->object_lookup ) + mfd_modes |= BABY_STEP_OBJECT_LOOKUP; + if( access_multiplexer->pre_request ) + mfd_modes |= BABY_STEP_PRE_REQUEST; + if( access_multiplexer->post_request ) + mfd_modes |= BABY_STEP_POST_REQUEST; + +#if !(defined(NETSNMP_NO_WRITE_SUPPORT) || defined(NETSNMP_DISABLE_SET_SUPPORT)) + if( access_multiplexer->set_values ) + mfd_modes |= BABY_STEP_SET_VALUES; + if( access_multiplexer->irreversible_commit ) + mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT; + if( access_multiplexer->object_syntax_checks ) + mfd_modes |= BABY_STEP_CHECK_OBJECT; + + if( access_multiplexer->undo_setup ) + mfd_modes |= BABY_STEP_UNDO_SETUP; + if( access_multiplexer->undo_cleanup ) + mfd_modes |= BABY_STEP_UNDO_CLEANUP; + if( access_multiplexer->undo_sets ) + mfd_modes |= BABY_STEP_UNDO_SETS; + + if( access_multiplexer->row_creation ) + mfd_modes |= BABY_STEP_ROW_CREATE; + if( access_multiplexer->consistency_checks ) + mfd_modes |= BABY_STEP_CHECK_CONSISTENCY; + if( access_multiplexer->commit ) + mfd_modes |= BABY_STEP_COMMIT; + if( access_multiplexer->undo_commit ) + mfd_modes |= BABY_STEP_UNDO_COMMIT; +#endif /* NETSNMP_NO_WRITE_SUPPORT || NETSNMP_DISABLE_SET_SUPPORT */ + + handler = netsnmp_baby_steps_handler_get(mfd_modes); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject row_merge helper with prefix rootoid_len + 2 (entry.col) + */ + handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2); + netsnmp_inject_handler(reginfo, handler); + + /************************************************* + * + * inject container_table helper + */ + handler = + netsnmp_container_table_handler_get(tbl_info, + dot1dStaticTable_if_ctx.container, + TABLE_CONTAINER_KEY_NETSNMP_INDEX); + netsnmp_inject_handler( reginfo, handler ); + + /************************************************* + * + * inject cache helper + */ + if(NULL != dot1dStaticTable_if_ctx.cache) { + handler = netsnmp_cache_handler_get(dot1dStaticTable_if_ctx.cache); + netsnmp_inject_handler( reginfo, handler ); + } + + /* + * register table + */ + netsnmp_register_table(reginfo, tbl_info); + +} /* _dot1dStaticTable_initialize_interface */ + +/** + * @internal + * Shutdown the table dot1dStaticTable + */ +void +_dot1dStaticTable_shutdown_interface(dot1dStaticTable_registration * reg_ptr) +{ + /* + * shutdown the container + */ + _dot1dStaticTable_container_shutdown(&dot1dStaticTable_if_ctx); +} + +void +dot1dStaticTable_valid_columns_set(netsnmp_column_info *vc) +{ + dot1dStaticTable_if_ctx.tbl_info.valid_columns = vc; +} /* dot1dStaticTable_valid_columns_set */ + +/** + * @internal + * convert the index component stored in the context to an oid + */ +int +dot1dStaticTable_index_to_oid(netsnmp_index *oid_idx, + dot1dStaticTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + netsnmp_variable_list var_dot1dStaticAddress; + /* + * dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + netsnmp_variable_list var_dot1dStaticReceivePort; + + /* + * set up varbinds + */ + memset( &var_dot1dStaticAddress, 0x00, sizeof(var_dot1dStaticAddress) ); + var_dot1dStaticAddress.type = ASN_OCTET_STR; + memset( &var_dot1dStaticReceivePort, 0x00, sizeof(var_dot1dStaticReceivePort) ); + var_dot1dStaticReceivePort.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_dot1dStaticAddress.next_variable = &var_dot1dStaticReceivePort; var_dot1dStaticReceivePort.next_variable = NULL; + + + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_index_to_oid","called\n")); + + /* dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + snmp_set_var_value(&var_dot1dStaticAddress, &mib_idx->dot1dStaticAddress, + mib_idx->dot1dStaticAddress_len * sizeof(mib_idx->dot1dStaticAddress[0])); + + /* dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */ + snmp_set_var_value(&var_dot1dStaticReceivePort, &mib_idx->dot1dStaticReceivePort, sizeof(mib_idx->dot1dStaticReceivePort)); + + + err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len, + NULL, 0, &var_dot1dStaticAddress); + if(err) + snmp_log(LOG_ERR,"error %d converting index to oid\n", err); + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_dot1dStaticAddress ); + + return err; +} /* dot1dStaticTable_index_to_oid */ + +/** + * extract dot1dStaticTable indexes from a netsnmp_index + * + * @retval SNMP_ERR_NOERROR : no error + * @retval SNMP_ERR_GENERR : error + */ +int +dot1dStaticTable_index_from_oid(netsnmp_index *oid_idx, + dot1dStaticTable_mib_index *mib_idx) +{ + int err = SNMP_ERR_NOERROR; + + /* + * temp storage for parsing indexes + */ + /* + * dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H + */ + netsnmp_variable_list var_dot1dStaticAddress; + /* + * dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h + */ + netsnmp_variable_list var_dot1dStaticReceivePort; + + /* + * set up varbinds + */ + memset( &var_dot1dStaticAddress, 0x00, sizeof(var_dot1dStaticAddress) ); + var_dot1dStaticAddress.type = ASN_OCTET_STR; + memset( &var_dot1dStaticReceivePort, 0x00, sizeof(var_dot1dStaticReceivePort) ); + var_dot1dStaticReceivePort.type = ASN_INTEGER; + + /* + * chain temp index varbinds together + */ + var_dot1dStaticAddress.next_variable = &var_dot1dStaticReceivePort; var_dot1dStaticReceivePort.next_variable = NULL; + + + DEBUGMSGTL(("verbose:dot1dStaticTable:dot1dStaticTable_index_from_oid","called\n")); + + /* + * parse the oid into the individual index components + */ + err = parse_oid_indexes( oid_idx->oids, oid_idx->len, + &var_dot1dStaticAddress ); + if (err == SNMP_ERR_NOERROR) { + /* + * copy out values + */ + /* + * NOTE: val_len is in bytes, dot1dStaticAddress_len might not be + */ + if(var_dot1dStaticAddress.val_len > sizeof(mib_idx->dot1dStaticAddress)) + err = SNMP_ERR_GENERR; + else { + memcpy(mib_idx->dot1dStaticAddress, var_dot1dStaticAddress.val.string, var_dot1dStaticAddress.val_len); + mib_idx->dot1dStaticAddress_len = var_dot1dStaticAddress.val_len / sizeof(mib_idx->dot1dStaticAddress[0]); + } + mib_idx->dot1dStaticReceivePort = *((long *)var_dot1dStaticReceivePort.val.string); + + + } + + /* + * parsing may have allocated memory. free it. + */ + snmp_reset_var_buffers( &var_dot1dStaticAddress ); + + return err; +} /* dot1dStaticTable_index_from_oid */ + + +/* ********************************************************************* + * @internal + * allocate resources for a dot1dStaticTable_rowreq_ctx + */ +dot1dStaticTable_rowreq_ctx * +dot1dStaticTable_allocate_rowreq_ctx(void *user_init_ctx) +{ + dot1dStaticTable_rowreq_ctx *rowreq_ctx = + SNMP_MALLOC_TYPEDEF(dot1dStaticTable_rowreq_ctx); + + DEBUGMSGTL(("internal:dot1dStaticTable:dot1dStaticTable_allocate_rowreq_ctx","called\n")); + + if(NULL == rowreq_ctx) { + snmp_log(LOG_ERR,"Couldn't allocate memory for a " + "dot1dStaticTable_rowreq_ctx.\n"); + return NULL; + } + + rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp; + + rowreq_ctx->dot1dStaticTable_data_list = NULL; + + /* + * if we allocated data, call init routine + */ + if (!(rowreq_ctx->rowreq_flags & MFD_ROW_DATA_FROM_USER)) { + if(SNMPERR_SUCCESS != + dot1dStaticTable_rowreq_ctx_init(rowreq_ctx, user_init_ctx)) { + dot1dStaticTable_release_rowreq_ctx(rowreq_ctx); + rowreq_ctx = NULL; + } + } + + return rowreq_ctx; +} /* dot1dStaticTable_allocate_rowreq_ctx */ + +/* + * @internal + * release resources for a dot1dStaticTable_rowreq_ctx + */ +void +dot1dStaticTable_release_rowreq_ctx(dot1dStaticTable_rowreq_ctx *rowreq_ctx) +{ + DEBUGMSGTL(("internal:dot1dStaticTable:dot1dStaticTable_release_rowreq_ctx","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + dot1dStaticTable_rowreq_ctx_cleanup(rowreq_ctx); + + /* + * free index oid pointer + */ + if(rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp) + free(rowreq_ctx->oid_idx.oids); + + SNMP_FREE(rowreq_ctx); +} /* dot1dStaticTable_release_rowreq_ctx */ + +/** + * @internal + * wrapper + */ +static int +_mfd_dot1dStaticTable_pre_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc; + + DEBUGMSGTL(("internal:dot1dStaticTable:_mfd_dot1dStaticTable_pre_request", + "called\n")); + + if (1 != netsnmp_row_merge_status_first(reginfo, agtreq_info)) { + DEBUGMSGTL(("internal:dot1dStaticTable", + "skipping additional pre_request\n")); + return SNMP_ERR_NOERROR; + } + + rc = dot1dStaticTable_pre_request(dot1dStaticTable_if_ctx.user_ctx); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("dot1dStaticTable","error %d from " + "dot1dStaticTable_pre_request\n", rc)); + netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_dot1dStaticTable_pre_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_dot1dStaticTable_post_request(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + dot1dStaticTable_rowreq_ctx *rowreq_ctx = (dot1dStaticTable_rowreq_ctx*) + netsnmp_container_table_row_extract(requests); + int rc, packet_rc; + + DEBUGMSGTL(("internal:dot1dStaticTable:_mfd_dot1dStaticTable_post_request", + "called\n")); + + /* + * release row context, if deleted + */ + if (rowreq_ctx && (rowreq_ctx->rowreq_flags & MFD_ROW_DELETED)) + dot1dStaticTable_release_rowreq_ctx(rowreq_ctx); + + /* + * wait for last call before calling user + */ + if (1 != netsnmp_row_merge_status_last(reginfo, agtreq_info)) { + DEBUGMSGTL(("internal:dot1dStaticTable", + "waiting for last post_request\n")); + return SNMP_ERR_NOERROR; + } + + packet_rc = netsnmp_check_all_requests_error(agtreq_info->asp, 0); + rc = dot1dStaticTable_post_request(dot1dStaticTable_if_ctx.user_ctx,packet_rc); + if (MFD_SUCCESS != rc) { + /* + * nothing we can do about it but log it + */ + DEBUGMSGTL(("dot1dStaticTable","error %d from " + "dot1dStaticTable_post_request\n", rc)); + } + + return SNMP_ERR_NOERROR; +} /* _mfd_dot1dStaticTable_post_request */ + +/** + * @internal + * wrapper + */ +static int +_mfd_dot1dStaticTable_object_lookup(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + int rc = SNMP_ERR_NOERROR; + dot1dStaticTable_rowreq_ctx *rowreq_ctx = (dot1dStaticTable_rowreq_ctx*) + netsnmp_container_table_row_extract(requests); + + DEBUGMSGTL(("internal:dot1dStaticTable:_mfd_dot1dStaticTable_object_lookup","called\n")); + + /* + * get our context from mfd + * dot1dStaticTable_interface_ctx *if_ctx = + * (dot1dStaticTable_interface_ctx *)reginfo->my_reg_void; + */ + + if(NULL == rowreq_ctx) { + rc = SNMP_ERR_NOCREATION; + } + + if (MFD_SUCCESS != rc) + netsnmp_request_set_error_all(requests, rc); + else + dot1dStaticTable_row_prep(rowreq_ctx); + + return SNMP_VALIDATE_ERR(rc); +} /* _mfd_dot1dStaticTable_object_lookup */ + +/*********************************************************************** + * + * GET processing + * + ***********************************************************************/ +/* + * @internal + * Retrieve the value for a particular column + */ +NETSNMP_STATIC_INLINE int +_dot1dStaticTable_get_column( dot1dStaticTable_rowreq_ctx *rowreq_ctx, + netsnmp_variable_list *var, int column ) +{ + int rc = SNMPERR_SUCCESS; + + DEBUGMSGTL(("internal:dot1dStaticTable:_mfd_dot1dStaticTable_get_column", + "called for %d\n", column)); + + + netsnmp_assert(NULL != rowreq_ctx); + + switch(column) { + + /* (INDEX) dot1dStaticAddress(1)/MacAddress/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */ + case COLUMN_DOT1DSTATICADDRESS: + var->type = ASN_OCTET_STR; + /* + * NOTE: val_len is in bytes, dot1dStaticAddress_len might not be (e.g. oids) + */ + if (var->val_len < (rowreq_ctx->tbl_idx.dot1dStaticAddress_len * + sizeof(rowreq_ctx->tbl_idx.dot1dStaticAddress[0]))) { + var->val.string = malloc(rowreq_ctx->tbl_idx.dot1dStaticAddress_len * + sizeof(rowreq_ctx->tbl_idx.dot1dStaticAddress[0])); + } + var->val_len = rowreq_ctx->tbl_idx.dot1dStaticAddress_len * sizeof(rowreq_ctx->tbl_idx.dot1dStaticAddress[0]); + memcpy( var->val.string, rowreq_ctx->tbl_idx.dot1dStaticAddress, var->val_len ); + break; + + /* (INDEX) dot1dStaticReceivePort(2)/INTEGER32/ASN_INTEGER/long(long)//l/A/W/e/R/d/h */ + case COLUMN_DOT1DSTATICRECEIVEPORT: + var->type = ASN_INTEGER; + var->val_len = sizeof(long); + (*var->val.integer) = rowreq_ctx->tbl_idx.dot1dStaticReceivePort; + break; + + /* dot1dStaticAllowedToGoTo(3)/OCTETSTR/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/h */ + case COLUMN_DOT1DSTATICALLOWEDTOGOTO: + var->type = ASN_OCTET_STR; +rc = dot1dStaticAllowedToGoTo_get(rowreq_ctx, (char **)&var->val.string, &var->val_len ); + break; + + /* dot1dStaticStatus(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */ + case COLUMN_DOT1DSTATICSTATUS: + var->val_len = sizeof(u_long); + var->type = ASN_INTEGER; +rc = dot1dStaticStatus_get(rowreq_ctx, (u_long *)var->val.string ); + break; + + default: + if (DOT1DSTATICTABLE_MIN_COL <= column && column <= DOT1DSTATICTABLE_MAX_COL) { + DEBUGMSGTL(("internal:dot1dStaticTable:_mfd_dot1dStaticTable_get_column", + "assume column %d is reserved\n", column)); + rc = MFD_SKIP; + } else { + snmp_log(LOG_ERR, + "unknown column %d in _dot1dStaticTable_get_column\n", column); + } + break; + } + + return rc; +} /* _dot1dStaticTable_get_column */ + +int +_mfd_dot1dStaticTable_get_values(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *agtreq_info, + netsnmp_request_info *requests) +{ + dot1dStaticTable_rowreq_ctx *rowreq_ctx = (dot1dStaticTable_rowreq_ctx*) + netsnmp_container_table_row_extract(requests); + netsnmp_table_request_info * tri; + u_char * old_string; + void (*dataFreeHook)(void *); + int rc; + + DEBUGMSGTL(("internal:dot1dStaticTable:_mfd_dot1dStaticTable_get_values","called\n")); + + netsnmp_assert(NULL != rowreq_ctx); + + for(;requests; requests = requests->next) { + /* + * save old pointer, so we can free it if replaced + */ + old_string = requests->requestvb->val.string; + dataFreeHook = requests->requestvb->dataFreeHook; + if(NULL == requests->requestvb->val.string) { + requests->requestvb->val.string = requests->requestvb->buf; + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + else if(requests->requestvb->buf == requests->requestvb->val.string) { + if(requests->requestvb->val_len != sizeof(requests->requestvb->buf)) + requests->requestvb->val_len = sizeof(requests->requestvb->buf); + } + + /* + * get column data + */ + tri = netsnmp_extract_table_info(requests); + if(NULL == tri) + continue; + + rc = _dot1dStaticTable_get_column(rowreq_ctx, requests->requestvb, tri->colnum); + if(rc) { + if(MFD_SKIP == rc) { + requests->requestvb->type = SNMP_NOSUCHINSTANCE; + rc = SNMP_ERR_NOERROR; + } + } + else if (NULL == requests->requestvb->val.string) { + snmp_log(LOG_ERR,"NULL varbind data pointer!\n"); + rc = SNMP_ERR_GENERR; + } + if(rc) + netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc)); + + /* + * if the buffer wasn't used previously for the old data (i.e. it + * was allcoated memory) and the get routine replaced the pointer, + * we need to free the previous pointer. + */ + if(old_string && (old_string != requests->requestvb->buf) && + (requests->requestvb->val.string != old_string)) { + if(dataFreeHook) + (*dataFreeHook)(old_string); + else + free(old_string); + } + } /* for results */ + + return SNMP_ERR_NOERROR; +} /* _mfd_dot1dStaticTable_get_values */ + +/*********************************************************************** + * + * SET processing + * + ***********************************************************************/ + +/* + * SET PROCESSING NOT APPLICABLE (per MIB or user setting) + */ +/*********************************************************************** + * + * DATA ACCESS + * + ***********************************************************************/ +static void _container_free(netsnmp_container *container); + +/** + * @internal + */ +static int +_cache_load(netsnmp_cache *cache, void *vmagic) +{ + DEBUGMSGTL(("internal:dot1dStaticTable:_cache_load","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache for dot1dStaticTable_cache_load\n"); + return -1; + } + + /** should only be called for an invalid or expired cache */ + netsnmp_assert((0 == cache->valid) || (1 == cache->expired)); + + /* + * call user code + */ + return dot1dStaticTable_container_load((netsnmp_container*)cache->magic); +} /* _cache_load */ + +/** + * @internal + */ +static void +_cache_free(netsnmp_cache *cache, void *magic) +{ + netsnmp_container *container; + + DEBUGMSGTL(("internal:dot1dStaticTable:_cache_free","called\n")); + + if((NULL == cache) || (NULL == cache->magic)) { + snmp_log(LOG_ERR, "invalid cache in dot1dStaticTable_cache_free\n"); + return; + } + + container = (netsnmp_container*)cache->magic; + + _container_free(container); +} /* _cache_free */ + +/** + * @internal + */ +static void +_container_item_free(dot1dStaticTable_rowreq_ctx *rowreq_ctx, void *context) +{ + DEBUGMSGTL(("internal:dot1dStaticTable:_container_item_free","called\n")); + + if(NULL == rowreq_ctx) + return; + + dot1dStaticTable_release_rowreq_ctx(rowreq_ctx); +} /* _container_item_free */ + +/** + * @internal + */ +static void +_container_free(netsnmp_container *container) +{ + DEBUGMSGTL(("internal:dot1dStaticTable:_container_free","called\n")); + + if (NULL == container) { + snmp_log(LOG_ERR, "invalid container in dot1dStaticTable_container_free\n"); + return; + } + + /* + * call user code + */ + dot1dStaticTable_container_free(container); + + /* + * free all items. inefficient, but easy. + */ + CONTAINER_CLEAR(container, + (netsnmp_container_obj_func *)_container_item_free, + NULL); +} /* _container_free */ + +/** + * @internal + * initialize the container with functions or wrappers + */ +void +_dot1dStaticTable_container_init(dot1dStaticTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:dot1dStaticTable:_dot1dStaticTable_container_init","called\n")); + + /* + * cache init + */ + if_ctx->cache = netsnmp_cache_create(30, /* timeout in seconds */ + _cache_load, _cache_free, + dot1dStaticTable_oid, + dot1dStaticTable_oid_size); + + if(NULL == if_ctx->cache) { + snmp_log(LOG_ERR, "error creating cache for dot1dStaticTable\n"); + return; + } + + if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET; + + dot1dStaticTable_container_init(&if_ctx->container, if_ctx->cache); + if(NULL == if_ctx->container) + if_ctx->container = netsnmp_container_find("dot1dStaticTable:table_container"); + if(NULL == if_ctx->container) { + snmp_log(LOG_ERR,"error creating container in " + "dot1dStaticTable_container_init\n"); + return; + } + + if (NULL != if_ctx->cache) + if_ctx->cache->magic = (void*)if_ctx->container; +} /* _dot1dStaticTable_container_init */ + +/** + * @internal + * shutdown the container with functions or wrappers + */ +void +_dot1dStaticTable_container_shutdown(dot1dStaticTable_interface_ctx *if_ctx) +{ + DEBUGMSGTL(("internal:dot1dStaticTable:_dot1dStaticTable_container_shutdown","called\n")); + + dot1dStaticTable_container_shutdown(if_ctx->container); + + _container_free(if_ctx->container); + +} /* _dot1dStaticTable_container_shutdown */ + + +dot1dStaticTable_rowreq_ctx * +dot1dStaticTable_row_find_by_mib_index(dot1dStaticTable_mib_index *mib_idx) +{ + dot1dStaticTable_rowreq_ctx *rowreq_ctx; + oid oid_tmp[MAX_OID_LEN]; + netsnmp_index oid_idx; + int rc; + + /* + * set up storage for OID + */ + oid_idx.oids = oid_tmp; + oid_idx.len = sizeof(oid_tmp)/sizeof(oid); + + /* + * convert + */ + rc = dot1dStaticTable_index_to_oid(&oid_idx, mib_idx); + if (MFD_SUCCESS != rc) + return NULL; + + rowreq_ctx = (dot1dStaticTable_rowreq_ctx*)CONTAINER_FIND(dot1dStaticTable_if_ctx.container, &oid_idx); + + return rowreq_ctx; +} + diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.h new file mode 100644 index 000000000..e15bc8065 --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_interface.h @@ -0,0 +1,84 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + * + * $Id:$ + */ +/** @ingroup interface: Routines to interface to Net-SNMP + * + * \warning This code should not be modified, called directly, + * or used to interpret functionality. It is subject to + * change at any time. + * + * @{ + */ +/* + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + * *** *** + * *** NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE *** + * *** *** + * *** *** + * *** THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE. *** + * *** *** + * *** *** + * *** THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND *** + * *** *** + * *** *** + * *** IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES. *** + * *** *** + * *** *** + * ********************************************************************* + * ********************************************************************* + * ********************************************************************* + */ +#ifndef DOT1DSTATICTABLE_INTERFACE_H +#define DOT1DSTATICTABLE_INTERFACE_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#include "dot1dStaticTable.h" + + +/* ******************************************************************** + * Table declarations + */ + +/* PUBLIC interface initialization routine */ +void _dot1dStaticTable_initialize_interface(dot1dStaticTable_registration * user_ctx, + u_long flags); +void _dot1dStaticTable_shutdown_interface(dot1dStaticTable_registration * user_ctx); + +dot1dStaticTable_registration * +dot1dStaticTable_registration_get( void ); + +dot1dStaticTable_registration * +dot1dStaticTable_registration_set( dot1dStaticTable_registration * newreg ); + +netsnmp_container *dot1dStaticTable_container_get( void ); +int dot1dStaticTable_container_size( void ); + + dot1dStaticTable_rowreq_ctx * dot1dStaticTable_allocate_rowreq_ctx(void *); +void dot1dStaticTable_release_rowreq_ctx(dot1dStaticTable_rowreq_ctx *rowreq_ctx); + +int dot1dStaticTable_index_to_oid(netsnmp_index *oid_idx, + dot1dStaticTable_mib_index *mib_idx); +int dot1dStaticTable_index_from_oid(netsnmp_index *oid_idx, + dot1dStaticTable_mib_index *mib_idx); + +/* + * access to certain internals. use with caution! + */ +void dot1dStaticTable_valid_columns_set(netsnmp_column_info *vc); + + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_INTERFACE_H */ +/** @} */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_oids.h b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_oids.h new file mode 100644 index 000000000..0062d0c2f --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_oids.h @@ -0,0 +1,41 @@ +/* + * Note: this file originally auto-generated by mib2c using + * $ + * + * $Id:$ + */ +#ifndef DOT1DSTATICTABLE_OIDS_H +#define DOT1DSTATICTABLE_OIDS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* column number definitions for table dot1dStaticTable */ +#define DOT1DSTATICTABLE_OID 1,3,6,1,2,1,17,5,1 + + +#define COLUMN_DOT1DSTATICADDRESS 1 +#define COLUMN_DOT1DSTATICADDRESS_FLAG (0x1 << 0) + +#define COLUMN_DOT1DSTATICRECEIVEPORT 2 +#define COLUMN_DOT1DSTATICRECEIVEPORT_FLAG (0x1 << 1) + +#define COLUMN_DOT1DSTATICALLOWEDTOGOTO 3 +#define COLUMN_DOT1DSTATICALLOWEDTOGOTO_FLAG (0x1 << 2) + +#define COLUMN_DOT1DSTATICSTATUS 4 +#define COLUMN_DOT1DSTATICSTATUS_FLAG (0x1 << 3) + + +#define DOT1DSTATICTABLE_MIN_COL COLUMN_DOT1DSTATICADDRESS +#define DOT1DSTATICTABLE_MAX_COL COLUMN_DOT1DSTATICSTATUS + + + +#ifdef __cplusplus +} +#endif + +#endif /* DOT1DSTATICTABLE_OIDS_H */ diff --git a/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_subagent.c b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_subagent.c new file mode 100644 index 000000000..ada262b8d --- /dev/null +++ b/userspace/snmpd/bridge_mib/dot1dStaticTable/dot1dStaticTable_subagent.c @@ -0,0 +1,177 @@ +/* + * Note: this file originally auto-generated by mib2c using + * version $ of $ + */ +/* standard Net-SNMP includes */ +#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 our parent header */ +#include "dot1dStaticTable.h" + +#include <signal.h> + +/* + * If compiling within the net-snmp source code, this will trigger the feature + * detection mechansim to ensure the agent_check_and_process() function + * is left available even if --enable-minimialist is turned on. If you + * have configured net-snmp using --enable-minimialist and want to compile + * this code externally to the Net-SNMP code base, then please add + * --with-features="agent_check_and_process enable_stderrlog" to your + * configure line. + */ +netsnmp_feature_require(agent_check_and_process) +netsnmp_feature_require(enable_stderrlog) + +static int keep_running; + +static RETSIGTYPE +stop_server(int a) { + keep_running = 0; +} + +static void usage(void) { + printf("usage: dot1dStaticTable [-D<tokens>] [-f] [-L] [-M] [-H] [LISTENING ADDRESSES]\n" + "\t-f Do not fork() from the calling shell.\n" + "\t-DTOKEN[,TOKEN,...]\n" + "\t\tTurn on debugging output for the given TOKEN(s).\n" + "\t\tWithout any tokens specified, it defaults to printing\n" + "\t\tall the tokens (which is equivalent to the keyword 'ALL').\n" + "\t\tYou might want to try ALL for extremely verbose output.\n" + "\t\tNote: You can't put a space between the -D and the TOKENs.\n" + "\t-H\tDisplay a list of configuration file directives\n" + "\t\tunderstood by the agent and then exit.\n" + "\t-M\tRun as a normal SNMP Agent instead of an AgentX sub-agent.\n" + "\t-x ADDRESS\tconnect to master agent at ADDRESS (default /var/agentx/master).\n" + "\t-L\tDo not open a log file; print all messages to stderr.\n"); + exit(0); +} + +int +main (int argc, char **argv) { + int agentx_subagent=1; /* change this if you want to be a SNMP master agent */ + /* Defs for arg-handling code: handles setting of policy-related variables */ + int ch; + extern char *optarg; + int dont_fork = 0, use_syslog = 0; + char *agentx_socket = NULL; + + while ((ch = getopt(argc, argv, "D:fHLMx:")) != EOF) + switch(ch) { + case 'D': + debug_register_tokens(optarg); + snmp_set_do_debugging(1); + break; + case 'f': + dont_fork = 1; + break; + case 'H': + netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1); + init_agent("dot1dStaticTable"); /* register our .conf handlers */ + init_dot1dStaticTable(); + init_snmp("dot1dStaticTable"); + fprintf(stderr, "Configuration directives understood:\n"); + read_config_print_usage(" "); + exit(0); + case 'M': + agentx_subagent = 0; + break; + case 'L': + use_syslog = 0; /* use stderr */ + break; + case 'x': + agentx_socket = optarg; + break; + default: + fprintf(stderr,"unknown option %c\n", ch); + usage(); + } + + if (optind < argc) { + int i; + /* + * There are optional transport addresses on the command line. + */ + DEBUGMSGTL(("snmpd/main", "optind %d, argc %d\n", optind, argc)); + for (i = optind; i < argc; i++) { + char *c, *astring; + if ((c = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_PORTS))) { + astring = malloc(strlen(c) + 2 + strlen(argv[i])); + if (astring == NULL) { + fprintf(stderr, "malloc failure processing argv[%d]\n", i); + exit(1); + } + sprintf(astring, "%s,%s", c, argv[i]); + netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_PORTS, astring); + SNMP_FREE(astring); + } else { + netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_PORTS, argv[i]); + } + } + DEBUGMSGTL(("snmpd/main", "port spec: %s\n", + netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_PORTS))); + } + + /* we're an agentx subagent? */ + if (agentx_subagent) { + /* make us a agentx client. */ + netsnmp_enable_subagent(); + if (NULL != agentx_socket) + netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_X_SOCKET, agentx_socket); + } + + snmp_disable_log(); + if (use_syslog) + snmp_enable_calllog(); + else + snmp_enable_stderrlog(); + + /* daemonize */ + if(!dont_fork) { + int rc = netsnmp_daemonize(1,!use_syslog); + if(rc) + exit(-1); + } + + /* initialize tcp/ip if necessary */ + SOCK_STARTUP; + + /* initialize the agent library */ + init_agent("dot1dStaticTable"); + + /* init dot1dStaticTable mib code */ + init_dot1dStaticTable(); + + /* read dot1dStaticTable.conf files. */ + init_snmp("dot1dStaticTable"); + + /* If we're going to be a snmp master agent, initial the ports */ + if (!agentx_subagent) + init_master_agent(); /* open the port to listen on (defaults to udp:161) */ + + /* In case we recevie a request to stop (kill -TERM or kill -INT) */ + keep_running = 1; + signal(SIGTERM, stop_server); + signal(SIGINT, stop_server); + + /* you're main loop here... */ + while(keep_running) { + /* if you use select(), see snmp_select_info() in snmp_api(3) */ + /* --- OR --- */ + agent_check_and_process(1); /* 0 == don't block */ + } + + /* at shutdown time */ + snmp_shutdown("dot1dStaticTable"); + SOCK_CLEANUP; + exit(0); +} + -- GitLab