@@ -1354,6 +1354,96 @@ netsnmp_create_session_v3(PyObject *self, PyObject *args)
1354
1354
return Py_BuildValue ("i" , (int )ss );
1355
1355
}
1356
1356
1357
+ static PyObject *
1358
+ netsnmp_create_session_tunneled (PyObject * self , PyObject * args )
1359
+ {
1360
+ int version ;
1361
+ char * peer ;
1362
+ int lport ;
1363
+ int retries ;
1364
+ int timeout ;
1365
+ char * sec_name ;
1366
+ int sec_level ;
1367
+ char * sec_eng_id ;
1368
+ char * context_eng_id ;
1369
+ char * context ;
1370
+ char * our_identity ;
1371
+ char * their_identity ;
1372
+ char * their_hostname ;
1373
+ char * trust_cert ;
1374
+ SnmpSession session = {0 };
1375
+ SnmpSession * ss = NULL ;
1376
+ int verbose = py_netsnmp_verbose ();
1377
+
1378
+ if (!PyArg_ParseTuple (args , "isiiisissssss" , & version ,
1379
+ & peer , & lport , & retries , & timeout ,
1380
+ & sec_name , & sec_level ,
1381
+ & context_eng_id , & context ,
1382
+ & our_identity , & their_identity ,
1383
+ & their_hostname , & trust_cert ))
1384
+ return NULL ;
1385
+
1386
+ __libraries_init ("python" );
1387
+ snmp_sess_init (& session );
1388
+
1389
+ if (version != 3 ) {
1390
+ session .version = SNMP_VERSION_3 ;
1391
+ if (verbose )
1392
+ printf ("Using version 3 as it's the only version that supports tunneling\n" );
1393
+ }
1394
+
1395
+ session .peername = peer ;
1396
+ session .retries = retries ; /* 5 */
1397
+ session .timeout = timeout ; /* 1000000L */
1398
+ session .contextNameLen = STRLEN (context );
1399
+ session .contextName = context ;
1400
+ session .securityNameLen = STRLEN (sec_name );
1401
+ session .securityName = sec_name ;
1402
+ session .securityLevel = sec_level ;
1403
+ session .securityModel = NETSNMP_TSM_SECURITY_MODEL ;
1404
+
1405
+ /* create the transport configuration store */
1406
+ if (!session .transport_configuration ) {
1407
+ netsnmp_container_init_list ();
1408
+ session .transport_configuration =
1409
+ netsnmp_container_find ("transport_configuration:fifo" );
1410
+ if (!session .transport_configuration ) {
1411
+ fprintf (stderr , "failed to initialize the transport configuration container\n" );
1412
+ return NULL ;
1413
+ }
1414
+
1415
+ session .transport_configuration -> compare =
1416
+ (netsnmp_container_compare * )
1417
+ netsnmp_transport_config_compare ;
1418
+ }
1419
+
1420
+ if (our_identity && our_identity [0 ] != '\0' )
1421
+ CONTAINER_INSERT (session .transport_configuration ,
1422
+ netsnmp_transport_create_config ("our_identity" ,
1423
+ our_identity ));
1424
+
1425
+ if (their_identity && their_identity [0 ] != '\0' )
1426
+ CONTAINER_INSERT (session .transport_configuration ,
1427
+ netsnmp_transport_create_config ("their_identity" ,
1428
+ their_identity ));
1429
+
1430
+ if (their_hostname && their_hostname [0 ] != '\0' )
1431
+ CONTAINER_INSERT (session .transport_configuration ,
1432
+ netsnmp_transport_create_config ("their_hostname" ,
1433
+ their_hostname ));
1434
+
1435
+ if (trust_cert && trust_cert [0 ] != '\0' )
1436
+ CONTAINER_INSERT (session .transport_configuration ,
1437
+ netsnmp_transport_create_config ("trust_cert" ,
1438
+ trust_cert ));
1439
+
1440
+ ss = snmp_sess_open (& session );
1441
+
1442
+ if (!ss )
1443
+ return NULL ;
1444
+ return Py_BuildValue ("i" , (int )ss );
1445
+ }
1446
+
1357
1447
static PyObject *
1358
1448
netsnmp_delete_session (PyObject * self , PyObject * args )
1359
1449
{
@@ -2539,6 +2629,8 @@ static PyMethodDef ClientMethods[] = {
2539
2629
"create a netsnmp session." },
2540
2630
{"session_v3" , netsnmp_create_session_v3 , METH_VARARGS ,
2541
2631
"create a netsnmp session." },
2632
+ {"session_tunneled" , netsnmp_create_session_tunneled , METH_VARARGS ,
2633
+ "create a tunneled netsnmp session over tls, dtls or ssh." },
2542
2634
{"delete_session" , netsnmp_delete_session , METH_VARARGS ,
2543
2635
"create a netsnmp session." },
2544
2636
{"get" , netsnmp_get , METH_VARARGS ,
0 commit comments