39
39
#include <ip_address.h>
40
40
#include <file_lib.h>
41
41
#include <cleanup.h>
42
+ #include <unix.h> /* GetRelocatedProcdirRoot() and GetProcdirPid() */
42
43
43
44
#ifdef HAVE_SYS_JAIL_H
44
45
# include <sys/jail.h>
@@ -1283,6 +1284,10 @@ static JsonElement* GetNetworkingStatsInfo(const char *filename)
1283
1284
1284
1285
fclose (fin );
1285
1286
}
1287
+ else
1288
+ {
1289
+ Log (LOG_LEVEL_VERBOSE , "netstat file not found at '%s'" , filename );
1290
+ }
1286
1291
1287
1292
return stats ;
1288
1293
}
@@ -1390,20 +1395,21 @@ JsonElement* GetProcFileInfo(EvalContext *ctx, const char* filename, const char*
1390
1395
void GetNetworkingInfo (EvalContext * ctx )
1391
1396
{
1392
1397
const char * procdir_root = GetRelocatedProcdirRoot ();
1398
+ int promiser_pid = GetProcdirPid ();
1393
1399
1394
1400
Buffer * pbuf = BufferNew ();
1395
1401
1396
1402
JsonElement * inet = JsonObjectCreate (2 );
1397
1403
1398
- BufferPrintf (pbuf , "%s/proc/net/netstat" , procdir_root );
1404
+ BufferPrintf (pbuf , "%s/proc/%d/ net/netstat" , procdir_root , promiser_pid );
1399
1405
JsonElement * inet_stats = GetNetworkingStatsInfo (BufferData (pbuf ));
1400
1406
1401
1407
if (inet_stats != NULL )
1402
1408
{
1403
1409
JsonObjectAppendElement (inet , "stats" , inet_stats );
1404
1410
}
1405
1411
1406
- BufferPrintf (pbuf , "%s/proc/net/route" , procdir_root );
1412
+ BufferPrintf (pbuf , "%s/proc/%d/ net/route" , procdir_root , promiser_pid );
1407
1413
JsonElement * routes = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , & NetworkingRoutesPostProcessInfo , NULL ,
1408
1414
// format: Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
1409
1415
// eth0 00000000 0102A8C0 0003 0 0 1024 00000000 0 0 0
@@ -1451,7 +1457,7 @@ void GetNetworkingInfo(EvalContext *ctx)
1451
1457
1452
1458
JsonElement * inet6 = JsonObjectCreate (3 );
1453
1459
1454
- BufferPrintf (pbuf , "%s/proc/net/snmp6" , procdir_root );
1460
+ BufferPrintf (pbuf , "%s/proc/%d/ net/snmp6" , procdir_root , promiser_pid );
1455
1461
JsonElement * inet6_stats = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , NULL , NULL ,
1456
1462
"^\\s*(?<key>\\S+)\\s+(?<value>\\d+)" );
1457
1463
@@ -1477,7 +1483,7 @@ void GetNetworkingInfo(EvalContext *ctx)
1477
1483
JsonDestroy (inet6_stats );
1478
1484
}
1479
1485
1480
- BufferPrintf (pbuf , "%s/proc/net/ipv6_route" , procdir_root );
1486
+ BufferPrintf (pbuf , "%s/proc/%d/ net/ipv6_route" , procdir_root , promiser_pid );
1481
1487
JsonElement * inet6_routes = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , & NetworkingIPv6RoutesPostProcessInfo , NULL ,
1482
1488
// format: dest dest_prefix source source_prefix next_hop metric refcnt use flags interface
1483
1489
// fe800000000000000000000000000000 40 00000000000000000000000000000000 00 00000000000000000000000000000000 00000100 00000000 00000000 00000001 eth0
@@ -1492,7 +1498,7 @@ void GetNetworkingInfo(EvalContext *ctx)
1492
1498
JsonObjectAppendElement (inet6 , "routes" , inet6_routes );
1493
1499
}
1494
1500
1495
- BufferPrintf (pbuf , "%s/proc/net/if_inet6" , procdir_root );
1501
+ BufferPrintf (pbuf , "%s/proc/%d/ net/if_inet6" , procdir_root , promiser_pid );
1496
1502
JsonElement * inet6_addresses = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , "interface" , & NetworkingIPv6AddressesPostProcessInfo , & NetworkingIPv6AddressesTiebreaker ,
1497
1503
// format: address device_number prefix_length scope flags interface_name
1498
1504
// 00000000000000000000000000000001 01 80 10 80 lo
@@ -1515,7 +1521,7 @@ void GetNetworkingInfo(EvalContext *ctx)
1515
1521
// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
1516
1522
// eth0: 74850544807 75236137 0 0 0 0 0 1108775 63111535625 74696758 0 0 0 0 0 0
1517
1523
1518
- BufferPrintf (pbuf , "%s/proc/net/dev" , procdir_root );
1524
+ BufferPrintf (pbuf , "%s/proc/%d/ net/dev" , procdir_root , promiser_pid );
1519
1525
JsonElement * interfaces_data =
1520
1526
GetProcFileInfo (ctx , BufferData (pbuf ), "interfaces_data" , "device" , NULL , NULL ,
1521
1527
"^\\s*(?<device>[^:]+)\\s*:\\s*"
@@ -1543,34 +1549,35 @@ void GetNetworkingInfo(EvalContext *ctx)
1543
1549
JsonElement * GetNetworkingConnections (EvalContext * ctx )
1544
1550
{
1545
1551
const char * procdir_root = GetRelocatedProcdirRoot ();
1552
+ int promiser_pid = GetProcdirPid ();
1546
1553
JsonElement * json = JsonObjectCreate (5 );
1547
1554
const char * ports_regex = "^\\s*\\d+:\\s+(?<raw_local>[0-9A-F:]+)\\s+(?<raw_remote>[0-9A-F:]+)\\s+(?<raw_state>[0-9]+)" ;
1548
1555
1549
1556
JsonElement * data = NULL ;
1550
1557
Buffer * pbuf = BufferNew ();
1551
1558
1552
- BufferPrintf (pbuf , "%s/proc/net/tcp" , procdir_root );
1559
+ BufferPrintf (pbuf , "%s/proc/%d/ net/tcp" , procdir_root , promiser_pid );
1553
1560
data = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , & NetworkingPortsPostProcessInfo , NULL , ports_regex );
1554
1561
if (data != NULL )
1555
1562
{
1556
1563
JsonObjectAppendElement (json , "tcp" , data );
1557
1564
}
1558
1565
1559
- BufferPrintf (pbuf , "%s/proc/net/tcp6" , procdir_root );
1566
+ BufferPrintf (pbuf , "%s/proc/%d/ net/tcp6" , procdir_root , promiser_pid );
1560
1567
data = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , & NetworkingPortsPostProcessInfo , NULL , ports_regex );
1561
1568
if (data != NULL )
1562
1569
{
1563
1570
JsonObjectAppendElement (json , "tcp6" , data );
1564
1571
}
1565
1572
1566
- BufferPrintf (pbuf , "%s/proc/net/udp" , procdir_root );
1573
+ BufferPrintf (pbuf , "%s/proc/%d/ net/udp" , procdir_root , promiser_pid );
1567
1574
data = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , & NetworkingPortsPostProcessInfo , NULL , ports_regex );
1568
1575
if (data != NULL )
1569
1576
{
1570
1577
JsonObjectAppendElement (json , "udp" , data );
1571
1578
}
1572
1579
1573
- BufferPrintf (pbuf , "%s/proc/net/udp6" , procdir_root );
1580
+ BufferPrintf (pbuf , "%s/proc/%d/ net/udp6" , procdir_root , promiser_pid );
1574
1581
data = GetProcFileInfo (ctx , BufferData (pbuf ), NULL , NULL , & NetworkingPortsPostProcessInfo , NULL , ports_regex );
1575
1582
if (data != NULL )
1576
1583
{
0 commit comments