Skip to content

Commit c2e5f4f

Browse files
committed
Merge branch 'netconsole-enable-compile-time-configuration'
Breno Leitao says: ==================== netconsole: Enable compile time configuration Enable netconsole features to be set at compilation time. Create two Kconfig options that allow users to set extended logs and release prepending features at compilation time. The first patch de-duplicates the initialization code, and the second patch adds the support in the de-duplicated code, avoiding touching two different functions with the same change. ==================== Link: https://lore.kernel.org/r/20230811093158.1678322-1-leitao@debian.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents f3add6d + fad361a commit c2e5f4f

2 files changed

Lines changed: 50 additions & 20 deletions

File tree

drivers/net/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,28 @@ config NETCONSOLE_DYNAMIC
332332
at runtime through a userspace interface exported using configfs.
333333
See <file:Documentation/networking/netconsole.rst> for details.
334334

335+
config NETCONSOLE_EXTENDED_LOG
336+
bool "Set kernel extended message by default"
337+
depends on NETCONSOLE
338+
default n
339+
help
340+
Set extended log support for netconsole message. If this option is
341+
set, log messages are transmitted with extended metadata header in a
342+
format similar to /dev/kmsg. See
343+
<file:Documentation/networking/netconsole.rst> for details.
344+
345+
config NETCONSOLE_PREPEND_RELEASE
346+
bool "Prepend kernel release version in the message by default"
347+
depends on NETCONSOLE_EXTENDED_LOG
348+
default n
349+
help
350+
Set kernel release to be prepended to each netconsole message by
351+
default. If this option is set, the kernel release is prepended into
352+
the first field of every netconsole message, so, the netconsole
353+
server/peer can easily identify what kernel release is logging each
354+
message. See <file:Documentation/networking/netconsole.rst> for
355+
details.
356+
335357
config NETPOLL
336358
def_bool NETCONSOLE
337359

drivers/net/netconsole.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,43 @@ static void netconsole_target_put(struct netconsole_target *nt)
167167

168168
#endif /* CONFIG_NETCONSOLE_DYNAMIC */
169169

170-
/* Allocate new target (from boot/module param) and setup netpoll for it */
171-
static struct netconsole_target *alloc_param_target(char *target_config)
170+
/* Allocate and initialize with defaults.
171+
* Note that these targets get their config_item fields zeroed-out.
172+
*/
173+
static struct netconsole_target *alloc_and_init(void)
172174
{
173-
int err = -ENOMEM;
174175
struct netconsole_target *nt;
175176

176-
/*
177-
* Allocate and initialize with defaults.
178-
* Note that these targets get their config_item fields zeroed-out.
179-
*/
180177
nt = kzalloc(sizeof(*nt), GFP_KERNEL);
181178
if (!nt)
182-
goto fail;
179+
return nt;
180+
181+
if (IS_ENABLED(CONFIG_NETCONSOLE_EXTENDED_LOG))
182+
nt->extended = true;
183+
if (IS_ENABLED(CONFIG_NETCONSOLE_PREPEND_RELEASE))
184+
nt->release = true;
183185

184186
nt->np.name = "netconsole";
185187
strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);
186188
nt->np.local_port = 6665;
187189
nt->np.remote_port = 6666;
188190
eth_broadcast_addr(nt->np.remote_mac);
189191

192+
return nt;
193+
}
194+
195+
/* Allocate new target (from boot/module param) and setup netpoll for it */
196+
static struct netconsole_target *alloc_param_target(char *target_config)
197+
{
198+
struct netconsole_target *nt;
199+
int err;
200+
201+
nt = alloc_and_init();
202+
if (!nt) {
203+
err = -ENOMEM;
204+
goto fail;
205+
}
206+
190207
if (*target_config == '+') {
191208
nt->extended = true;
192209
target_config++;
@@ -195,6 +212,7 @@ static struct netconsole_target *alloc_param_target(char *target_config)
195212
if (*target_config == 'r') {
196213
if (!nt->extended) {
197214
pr_err("Netconsole configuration error. Release feature requires extended log message");
215+
err = -EINVAL;
198216
goto fail;
199217
}
200218
nt->release = true;
@@ -664,23 +682,13 @@ static const struct config_item_type netconsole_target_type = {
664682
static struct config_item *make_netconsole_target(struct config_group *group,
665683
const char *name)
666684
{
667-
unsigned long flags;
668685
struct netconsole_target *nt;
686+
unsigned long flags;
669687

670-
/*
671-
* Allocate and initialize with defaults.
672-
* Target is disabled at creation (!enabled).
673-
*/
674-
nt = kzalloc(sizeof(*nt), GFP_KERNEL);
688+
nt = alloc_and_init();
675689
if (!nt)
676690
return ERR_PTR(-ENOMEM);
677691

678-
nt->np.name = "netconsole";
679-
strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);
680-
nt->np.local_port = 6665;
681-
nt->np.remote_port = 6666;
682-
eth_broadcast_addr(nt->np.remote_mac);
683-
684692
/* Initialize the config_item member */
685693
config_item_init_type_name(&nt->item, name, &netconsole_target_type);
686694

0 commit comments

Comments
 (0)