yumapro  24.10-3
YumaPro SDK
Loading...
Searching...
No Matches
agt_ypsnmp_util.h
Go to the documentation of this file.
1/*****************************************************************************
2Various copyrights apply to this package, listed in various separate
3parts below. Please make sure that you read all the parts.
4
5---- Part 1: Sparta, Inc (BSD) -----
6
7Copyright (c) 2003-2010, Sparta, Inc
8All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13* Redistributions of source code must retain the above copyright notice,
14 this list of conditions and the following disclaimer.
15
16* Redistributions in binary form must reproduce the above copyright
17 notice, this list of conditions and the following disclaimer in the
18 documentation and/or other materials provided with the distribution.
19
20* Neither the name of Sparta, Inc nor the names of its contributors may
21 be used to endorse or promote products derived from this software
22 without specific prior written permission.
23
24THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
25IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
28CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
36---- Part 2: ScienceLogic, LLC (BSD) ----
37
38Copyright (c) 2006, ScienceLogic, LLC
39All rights reserved.
40
41Redistribution and use in source and binary forms, with or without
42modification, are permitted provided that the following conditions are
43met:
44
45* Redistributions of source code must retain the above copyright notice,
46 this list of conditions and the following disclaimer.
47
48* Redistributions in binary form must reproduce the above copyright
49 notice, this list of conditions and the following disclaimer in the
50 documentation and/or other materials provided with the distribution.
51
52* Neither the name of ScienceLogic, LLC nor the names of its
53 contributors may be used to endorse or promote products derived
54 from this software without specific prior written permission.
55
56THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
61INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
62BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
63OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
64ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
65TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
66USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
67DAMAGE.
68*************************************************************************/
69
70
71/*************************************************************************
72 OVERVIEW
73
74 This module implements Utility Functions for YP SNMP
75
76*************************************************************************/
77
78
79/*
80 * Copyright (c) 2017 - 2020, YumaWorks. Inc., All Rights Reserved.
81 *
82 * Unless required by applicable law or agreed to in writing,
83 * software distributed under the License is distributed on an
84 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
85 * KIND, either express or implied. See the License for the
86 * specific language governing permissions and limitations
87 * under the License.
88 */
89
90#if defined(WITH_SNMP) && defined(WITH_RESTCONF)
91#ifndef _H_agt_ypsnmp_util
92#define _H_agt_ypsnmp_util
93
94/* FILE: agt_ypsnmp_util.h
95*********************************************************************
96* *
97* P U R P O S E *
98* *
99*********************************************************************/
100
107/*********************************************************************
108* *
109* C H A N G E H I S T O R Y *
110* *
111*********************************************************************
112
113date init comment
114----------------------------------------------------------------------
11510May17 am begun;
116
117*/
118
119#ifndef _H_status_enum
120#include "status_enum.h"
121#endif
122
123#ifndef _H_yangapi
124#include "yangapi.h"
125#endif
126
127#ifdef __cplusplus
128extern "C" {
129#endif
130
131/********************************************************************
132* *
133* C O N S T A N T S *
134* *
135*********************************************************************/
136
137#define YPSNMP_TYPE_GAUGE32 (const xmlChar *)"gauge32"
138#define YPSNMP_TYPE_GAUGE64 (const xmlChar *)"gauge64"
139#define YPSNMP_TYPE_PHYS_ADDR (const xmlChar *)"phys-address"
140#define YPSNMP_TYPE_TIMETICKS (const xmlChar *)"timeticks"
141#define YPSNMP_TYPE_TIMESTAMP (const xmlChar *)"timestamp"
142#define YPSNMP_TYPE_COUNTER32 (const xmlChar *)"counter32"
143#define YPSNMP_TYPE_ZBCOUNTER32 (const xmlChar *)"zero-based-counter32"
144#define YPSNMP_TYPE_COUNTER64 (const xmlChar *)"counter64"
145#define YPSNMP_TYPE_ZBCOUNTER64 (const xmlChar *)"zero-based-counter64"
146#define YPSNMP_TYPE_OID128 (const xmlChar *)"object-identifier-128"
147
148#define YPSNMP_APP_NAME (const char *)"snmpd"
149
150
151/* max number of cache_entry_t in snmp_cacheQ */
152#define MAX_SNMP_CACHE_SIZE 32
153#define ADDR_BUFLEN 128
154
155/* mac address */
156#define YPSNMP_PHYS_ADDR_LEN 6
157
158/* work around for the way fd_set is accessed in
159 * net-snmp/include/net-snmp/library/large_fd_set.h
160 */
161#define fds_bits __fds_bits
162
163 /*
164 * Definitions for Agent Extensibility Protocol (RFC 2257)
165 *
166 */
167
168/* currently only TCP endpoint is available
169 UDP is not working for AgentX protocol, the master cannot
170 trasfer packets via UDP.
171 The AgentX default socket is /var/agentx/master which
172 has to be changed to TCP type socket!!!!!! (tcp:localhost:705)
173
174*/
175#define YPSNMP_AGENTX_SOCKET (const char *)"tcp:localhost:705"
176#define YPSNMP_AGENTX_NAME (const char *)"agentx"
177
178 /*
179 * AgentX versions
180 */
181 /*
182 * Use values distinct from those used to represent SNMP versions
183 */
184
185#define AGENTX_VERSION_BASE 192 /* Binary: 11xxxxxx */
186#define AGENTX_VERSION_1 (AGENTX_VERSION_BASE | 0x1)
187
188#define IS_AGENTX_VERSION(v) (((v)&AGENTX_VERSION_BASE) == AGENTX_VERSION_BASE)
189
190 /*
191 * PDU types in AgentX
192 */
193#define AGENTX_MSG_OPEN ((u_char)1)
194#define AGENTX_MSG_CLOSE ((u_char)2)
195#define AGENTX_MSG_REGISTER ((u_char)3)
196#define AGENTX_MSG_UNREGISTER ((u_char)4)
197#define AGENTX_MSG_GET ((u_char)5)
198#define AGENTX_MSG_GETNEXT ((u_char)6)
199#define AGENTX_MSG_GETBULK ((u_char)7)
200#define AGENTX_MSG_TESTSET ((u_char)8)
201#define AGENTX_MSG_COMMITSET ((u_char)9)
202#define AGENTX_MSG_UNDOSET ((u_char)10)
203#define AGENTX_MSG_CLEANUPSET ((u_char)11)
204#define AGENTX_MSG_NOTIFY ((u_char)12)
205#define AGENTX_MSG_PING ((u_char)13)
206#define AGENTX_MSG_INDEX_ALLOCATE ((u_char)14)
207#define AGENTX_MSG_INDEX_DEALLOCATE ((u_char)15)
208#define AGENTX_MSG_ADD_AGENT_CAPS ((u_char)16)
209#define AGENTX_MSG_REMOVE_AGENT_CAPS ((u_char)17)
210#define AGENTX_MSG_RESPONSE ((u_char)18)
211
212 /*
213 * Error codes from RFC 2257
214 */
215#define AGENTX_ERR_OPEN_FAILED (256)
216#define AGENTX_ERR_NOT_OPEN (257)
217#define AGENTX_ERR_INDEX_WRONG_TYPE (258)
218#define AGENTX_ERR_INDEX_ALREADY_ALLOCATED (259)
219#define AGENTX_ERR_INDEX_NONE_AVAILABLE (260)
220#define AGENTX_ERR_INDEX_NOT_ALLOCATED (261)
221#define AGENTX_ERR_UNSUPPORTED_CONTEXT (262)
222#define AGENTX_ERR_DUPLICATE_REGISTRATION (263)
223#define AGENTX_ERR_UNKNOWN_REGISTRATION (264)
224#define AGENTX_ERR_UNKNOWN_AGENTCAPS (265)
225
226 /*
227 * added in 1999 revision
228 */
229#define AGENTX_ERR_NOERROR SNMP_ERR_NOERROR
230#define AGENTX_ERR_PARSE_FAILED (266)
231#define AGENTX_ERR_REQUEST_DENIED (267)
232#define AGENTX_ERR_PROCESSING_ERROR (268)
233
234 /*
235 * Message processing models
236 */
237#define AGENTX_MP_MODEL_AGENTXv1 (257)
238
239
240 /*
241 * PDU Flags
242 */
243#define AGENTX_MSG_FLAG_INSTANCE_REGISTER 0x01
244#define AGENTX_MSG_FLAG_NEW_INSTANCE 0x02
245#define AGENTX_MSG_FLAG_ANY_INSTANCE 0x04
246#define AGENTX_MSG_FLAG_NON_DEFAULT_CONTEXT 0x08
247#define AGENTX_MSG_FLAG_NETWORK_BYTE_ORDER 0x10
248
249#define AGENTX_MSG_FLAGS_MASK 0xff
250
251 /*
252 * Session Flags
253 */
254#define AGENTX_FLAGS_NETWORK_BYTE_ORDER AGENTX_MSG_FLAG_NETWORK_BYTE_ORDER
255
256
257/********************************************************************
258* *
259* T Y P E S *
260* *
261*********************************************************************/
262
276typedef enum ypsnmp_getnext_mode_t_ {
279
282
285
288
291
295
296
298typedef struct agent_nsap_t_ {
299
302
304 netsnmp_transport *transport;
305
308
310 struct agent_nsap_t_ *next;
312
313
315typedef struct ypsnmp_agent_session_t_ {
317 int mode;
318
320 netsnmp_session *session;
321
323 netsnmp_pdu *pdu;
324
326 int rw;
327
329 int exact;
330
333
335 int index;
336
339
342
345
347
348
349/********************************************************************
350* *
351* F U N C T I O N S *
352* *
353*********************************************************************/
354
355
376extern val_value_t *
378
379
388extern val_value_t *
390
391
400extern val_value_t *
402
403
414extern boolean
416 obj_template_t *curobj);
417
418
429extern boolean
431 val_value_t *keyval);
432
433
447extern obj_template_t *
449
450
464extern obj_template_t *
466
467
477extern boolean
479
480
491extern boolean
493
494
504extern xmlChar *
506
507
523extern netsnmp_variable_list *
525 size_t name_length,
526 u_char type,
527 const void *value,
528 size_t len);
529
530
540extern void
541 agt_ypsnmp_append_varbind_to_list (netsnmp_variable_list **list,
542 netsnmp_variable_list *var);
543
544
554extern obj_oid_t *
555 agt_ypsnmp_convert_varbind_to_oid (netsnmp_variable_list *var_ptr);
556
557
573extern status_t
575 netsnmp_pdu *pdu,
576 val_value_t *val,
577 const obj_oid_t *oid_obj);
578
579
589extern status_t
591 netsnmp_pdu *pdu);
592
593
602extern yangapi_method_t
603 agt_ypsnmp_get_yangapi_method (uint8 msg_code);
604
605
615extern xmlChar *
617
618
626extern void
627 agt_ypsnmp_log_pdu (netsnmp_pdu *pdu);
628
629
638extern const void *
639 agt_ypsnmp_get_varbind_value (netsnmp_variable_list *var);
640
641
650extern const xmlChar *
652
653
663extern obj_oid_t *
665 uint32 index_length);
666
667
680extern status_t
681 agt_ypsnmp_convert_oid2chars (xmlChar *str,
682 uint32 len,
683 const oid_t *useoid);
684
685
699extern status_t
700 agt_ypsnmp_convert_str_oid2str (xmlChar *str,
701 uint32 len,
702 oid_t *useoid);
703
704
717extern status_t
718 agt_ypsnmp_convert_str2oid (const xmlChar *str,
719 oid_t *useoid,
720 uint32 len);
721
722
780extern status_t
782 obj_template_t *obj,
783 uint32 index_length);
784
785
798extern status_t
800 val_value_t *list);
801
802
813 agt_ypsnmp_init_agent_session (netsnmp_session * session,
814 netsnmp_pdu *pdu);
815
816
824extern void
826
827
835extern void free_varbind (netsnmp_variable_list *var);
836
837
847void free_varbind_yp (netsnmp_variable_list *var);
848
849
853#ifdef __cplusplus
854} /* end extern 'C' */
855#endif
856
857#endif // _H_agt_ypsnmp_util
858#endif // defined(WITH_SNMP) && defined(WITH_RESTCONF)
ypsnmp_getnext_mode_t
There are several possible requests that can be sent to the netconfd SNMP server:
Definition: agt_ypsnmp_util.h:276
@ YPSNMP_MODE_TAB_INDEXED
table indexed
Definition: agt_ypsnmp_util.h:284
@ YPSNMP_MODE_SCAL_INDEXED
scal indexed
Definition: agt_ypsnmp_util.h:290
@ YPSNMP_MODE_TAB_NOINDEX
table no index
Definition: agt_ypsnmp_util.h:281
@ YPSNMP_MODE_NONE
not set
Definition: agt_ypsnmp_util.h:278
@ YPSNMP_MODE_COMPLEX
complex
Definition: agt_ypsnmp_util.h:293
@ YPSNMP_MODE_SCAL_NOINDEX
scal no index
Definition: agt_ypsnmp_util.h:287
void free_varbind(netsnmp_variable_list *var)
Frees the variable and any malloc'd data associated with it.
Definition: agt_ypsnmp_util.c:2641
boolean agt_ypsnmp_is_augmented_obj(obj_template_t *curobj)
Check if the object is an augmented object.
Definition: agt_ypsnmp_util.c:968
status_t agt_ypsnmp_value_to_indexoid(yangapi_cb_t *rcb, val_value_t *list)
Converts val_value list with keys into index OID.
Definition: agt_ypsnmp_util.c:2284
netsnmp_variable_list * agt_ypsnmp_create_snmp_varbind_object(const oid *name, size_t name_length, u_char type, const void *value, size_t len)
Allocates and creates a new netsnmp variable binding object.
Definition: agt_ypsnmp_util.c:1053
status_t agt_ypsnmp_convert_str_oid2str(xmlChar *str, uint32 len, oid_t *useoid)
Converts a string OID to its string form.
Definition: agt_ypsnmp_util.c:1884
val_value_t * agt_ypsnmp_get_next_getnextlist(val_value_t *list)
Get the next list val_value structure in getnext_listQ.
Definition: agt_ypsnmp_util.c:737
boolean agt_ypsnmp_is_scalar_obj(obj_template_t *curobj)
Check if the object is a scalar object.
Definition: agt_ypsnmp_util.c:937
const xmlChar * agt_ypsnmp_get_getnext_modename(ypsnmp_getnext_mode_t getnextmode)
Get the getnext mode name from its enum.
Definition: agt_ypsnmp_util.c:1746
val_value_t * agt_ypsnmp_bestmatch_next_index(yangapi_cb_t *rcb)
Find the next best matching list entry in the Queue.
Definition: agt_ypsnmp_util.c:603
void free_varbind_yp(netsnmp_variable_list *var)
Frees the variable and any malloc'd data associated with it.
Definition: agt_ypsnmp_util.c:2680
status_t agt_ypsnmp_indexoid_to_value(yangapi_cb_t *rcb, obj_template_t *obj, uint32 index_length)
Parse requested OID and strip out index OID.
Definition: agt_ypsnmp_util.c:2017
status_t agt_ypsnmp_convert_str2oid(const xmlChar *str, oid_t *useoid, uint32 len)
Converts a string to its OID form.
Definition: agt_ypsnmp_util.c:1925
status_t agt_ypsnmp_setup_peeraddr(ses_cb_t *scb, netsnmp_pdu *pdu)
Setup the scb->peeraddr for debugging and auditing.
Definition: agt_ypsnmp_util.c:1508
val_value_t * agt_ypsnmp_get_first_getnextlist(yangapi_cb_t *rcb)
Get the first list val_value structure in getnext_listQ.
Definition: agt_ypsnmp_util.c:714
void agt_ypsnmp_append_varbind_to_list(netsnmp_variable_list **list, netsnmp_variable_list *var)
Adds the given netsnmp variable binding object to the end of the list of given pdu.
Definition: agt_ypsnmp_util.c:1116
yangapi_method_t agt_ypsnmp_get_yangapi_method(uint8 msg_code)
Get the YANGAPI method from the SNMP method.
Definition: agt_ypsnmp_util.c:1670
boolean agt_ypsnmp_match_obj(obj_template_t *targetobj, obj_template_t *curobj)
Checks if the current object in the walker is the target object for the request.
Definition: agt_ypsnmp_util.c:766
obj_template_t * agt_ypsnmp_get_table_obj(obj_template_t *obj)
Find the Table object of the current object.
Definition: agt_ypsnmp_util.c:848
const void * agt_ypsnmp_get_varbind_value(netsnmp_variable_list *var)
Get the Varbind value.
Definition: agt_ypsnmp_util.c:1704
boolean agt_ypsnmp_match_index(yangapi_cb_t *rcb, val_value_t *keyval)
Checks if the current index in the walker is the target index for the request.
Definition: agt_ypsnmp_util.c:811
status_t agt_ypsnmp_set_varbind(ses_cb_t *scb, netsnmp_pdu *pdu, val_value_t *val, const obj_oid_t *oid_obj)
Set the return Varbind based on the found value.
Definition: agt_ypsnmp_util.c:1196
ypsnmp_agent_session_t * agt_ypsnmp_init_agent_session(netsnmp_session *session, netsnmp_pdu *pdu)
Allocate new ypsnmp session context.
Definition: agt_ypsnmp_util.c:2576
obj_oid_t * agt_ypsnmp_convert_varbind_to_oid(netsnmp_variable_list *var_ptr)
Converts an SNMP OID string into an internal object.
Definition: agt_ypsnmp_util.c:1149
obj_oid_t * agt_ypsnmp_get_index_oid(obj_oid_t *full_oid, uint32 index_length)
parse requested OID and strip out index OID
Definition: agt_ypsnmp_util.c:1786
xmlChar * agt_ypsnmp_make_restconf_uri(obj_template_t *obj)
Make a RESTCONF URI string from the specified OID string.
Definition: agt_ypsnmp_util.c:1550
void agt_ypsnmp_log_pdu(netsnmp_pdu *pdu)
logs the received SNMP PDU packet contents
Definition: agt_ypsnmp_util.c:1593
xmlChar * agt_ypsnmp_convert_physaddr(val_value_t *val)
Converts the value of ifPhysAddress leaf element from yang syntax to SMI syntax expected by snmp clie...
Definition: agt_ypsnmp_util.c:1004
obj_template_t * agt_ypsnmp_get_parent_obj(obj_template_t *obj)
Find the complex parent of the current leaf object.
Definition: agt_ypsnmp_util.c:894
void agt_ypsnmp_free_agent_session(ypsnmp_agent_session_t *asp)
free the ypsnmp session and deallocate any associated memory
Definition: agt_ypsnmp_util.c:2614
status_t agt_ypsnmp_convert_oid2chars(xmlChar *str, uint32 len, const oid_t *useoid)
Converts an OID to its character form.
Definition: agt_ypsnmp_util.c:1833
yangapi_method_t
HTTP methods used by YANG-API and RESTCONF.
Definition: yangapi.h:111
status_t
global error return code
Definition: status_enum.h:210
unsigned long oid_t
data type used in SNMP
Definition: obj.h:1207
global error status code enumerations
NSAP for the agent.
Definition: agt_ypsnmp_util.h:298
int handle
handle
Definition: agt_ypsnmp_util.h:301
struct agent_nsap_t_ * next
next entry
Definition: agt_ypsnmp_util.h:310
netsnmp_transport * transport
transport info
Definition: agt_ypsnmp_util.h:304
void * opaque_ses
Opaque internal session pointer.
Definition: agt_ypsnmp_util.h:307
defines the snmp oid value, stored as an array of integers for easier comparision when performing AVL...
Definition: obj.h:1215
One YANG data-def-stmt.
Definition: obj.h:1229
Session Control Block.
Definition: ses.h:573
one value to match one type
Definition: val.h:912
Restapi Control Block Used by RESTCONF to hold parse and request processing state.
Definition: yangapi.h:351
agent session
Definition: agt_ypsnmp_util.h:315
int original_command
agentX specific pointers
Definition: agt_ypsnmp_util.h:344
int mode
session mode
Definition: agt_ypsnmp_util.h:317
netsnmp_pdu * pdu
PDU pointer.
Definition: agt_ypsnmp_util.h:323
int rw
RW flag.
Definition: agt_ypsnmp_util.h:326
int vbcount
varbind count
Definition: agt_ypsnmp_util.h:341
int exact
exact flag
Definition: agt_ypsnmp_util.h:329
int status
status flag
Definition: agt_ypsnmp_util.h:332
int index
index flag
Definition: agt_ypsnmp_util.h:335
netsnmp_session * session
session pointer
Definition: agt_ypsnmp_util.h:320
int oldmode
old mode
Definition: agt_ypsnmp_util.h:338
YANG-API definitions (pre-RESTCONF)