2019-10-05 02:19:24 +03:00
|
|
|
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
|
|
|
|
/* Copyright (C) 2019 Netronome Systems, Inc. */
|
|
|
|
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <net/snmp.h>
|
|
|
|
#include <net/tls.h>
|
|
|
|
|
2019-11-14 10:39:46 +03:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2019-10-05 02:19:24 +03:00
|
|
|
static const struct snmp_mib tls_mib_list[] = {
|
2019-10-05 02:19:25 +03:00
|
|
|
SNMP_MIB_ITEM("TlsCurrTxSw", LINUX_MIB_TLSCURRTXSW),
|
|
|
|
SNMP_MIB_ITEM("TlsCurrRxSw", LINUX_MIB_TLSCURRRXSW),
|
|
|
|
SNMP_MIB_ITEM("TlsCurrTxDevice", LINUX_MIB_TLSCURRTXDEVICE),
|
|
|
|
SNMP_MIB_ITEM("TlsCurrRxDevice", LINUX_MIB_TLSCURRRXDEVICE),
|
|
|
|
SNMP_MIB_ITEM("TlsTxSw", LINUX_MIB_TLSTXSW),
|
|
|
|
SNMP_MIB_ITEM("TlsRxSw", LINUX_MIB_TLSRXSW),
|
|
|
|
SNMP_MIB_ITEM("TlsTxDevice", LINUX_MIB_TLSTXDEVICE),
|
|
|
|
SNMP_MIB_ITEM("TlsRxDevice", LINUX_MIB_TLSRXDEVICE),
|
2019-10-05 02:19:26 +03:00
|
|
|
SNMP_MIB_ITEM("TlsDecryptError", LINUX_MIB_TLSDECRYPTERROR),
|
2019-10-05 02:19:27 +03:00
|
|
|
SNMP_MIB_ITEM("TlsRxDeviceResync", LINUX_MIB_TLSRXDEVICERESYNC),
|
2019-10-05 02:19:24 +03:00
|
|
|
SNMP_MIB_SENTINEL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int tls_statistics_seq_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
unsigned long buf[LINUX_MIB_TLSMAX] = {};
|
|
|
|
struct net *net = seq->private;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
snmp_get_cpu_field_batch(buf, tls_mib_list, net->mib.tls_statistics);
|
|
|
|
for (i = 0; tls_mib_list[i].name; i++)
|
|
|
|
seq_printf(seq, "%-32s\t%lu\n", tls_mib_list[i].name, buf[i]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-14 10:39:46 +03:00
|
|
|
#endif
|
2019-10-05 02:19:24 +03:00
|
|
|
|
|
|
|
int __net_init tls_proc_init(struct net *net)
|
|
|
|
{
|
net: fix proc_fs init handling in af_packet and tls
proc_fs was used, in af_packet, without a surrounding #ifdef,
although there is no hard dependency on proc_fs.
That caused the initialization of the af_packet module to fail
when CONFIG_PROC_FS=n.
Specifically, proc_create_net() was used in af_packet.c,
and when it fails, packet_net_init() returns -ENOMEM.
It will always fail when the kernel is compiled without proc_fs,
because, proc_create_net() for example always returns NULL.
The calling order that starts in af_packet.c is as follows:
packet_init()
register_pernet_subsys()
register_pernet_operations()
__register_pernet_operations()
ops_init()
ops->init() (packet_net_ops.init=packet_net_init())
proc_create_net()
It worked in the past because register_pernet_subsys()'s return value
wasn't checked before this Commit 36096f2f4fa0 ("packet: Fix error path in
packet_init.").
It always returned an error, but was not checked before, so everything
was working even when CONFIG_PROC_FS=n.
The fix here is simply to add the necessary #ifdef.
This also fixes a similar error in tls_proc.c, that was found by Jakub
Kicinski.
Fixes: d26b698dd3cd ("net/tls: add skeleton of MIB statistics")
Fixes: 36096f2f4fa0 ("packet: Fix error path in packet_init")
Signed-off-by: Yonatan Linik <yonatanlinik@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-12-14 23:25:50 +03:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2019-10-05 02:19:24 +03:00
|
|
|
if (!proc_create_net_single("tls_stat", 0444, net->proc_net,
|
|
|
|
tls_statistics_seq_show, NULL))
|
|
|
|
return -ENOMEM;
|
net: fix proc_fs init handling in af_packet and tls
proc_fs was used, in af_packet, without a surrounding #ifdef,
although there is no hard dependency on proc_fs.
That caused the initialization of the af_packet module to fail
when CONFIG_PROC_FS=n.
Specifically, proc_create_net() was used in af_packet.c,
and when it fails, packet_net_init() returns -ENOMEM.
It will always fail when the kernel is compiled without proc_fs,
because, proc_create_net() for example always returns NULL.
The calling order that starts in af_packet.c is as follows:
packet_init()
register_pernet_subsys()
register_pernet_operations()
__register_pernet_operations()
ops_init()
ops->init() (packet_net_ops.init=packet_net_init())
proc_create_net()
It worked in the past because register_pernet_subsys()'s return value
wasn't checked before this Commit 36096f2f4fa0 ("packet: Fix error path in
packet_init.").
It always returned an error, but was not checked before, so everything
was working even when CONFIG_PROC_FS=n.
The fix here is simply to add the necessary #ifdef.
This also fixes a similar error in tls_proc.c, that was found by Jakub
Kicinski.
Fixes: d26b698dd3cd ("net/tls: add skeleton of MIB statistics")
Fixes: 36096f2f4fa0 ("packet: Fix error path in packet_init")
Signed-off-by: Yonatan Linik <yonatanlinik@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-12-14 23:25:50 +03:00
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
2019-10-05 02:19:24 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __net_exit tls_proc_fini(struct net *net)
|
|
|
|
{
|
|
|
|
remove_proc_entry("tls_stat", net->proc_net);
|
|
|
|
}
|