Skip to content

Commit 7aa3f99

Browse files
committed
Merge branch 'netpoll-untangle-netconsole-and-netpoll'
Breno Leitao says: ==================== netpoll: Untangle netconsole and netpoll Initially netpoll and netconsole were created together, and some functions are in the wrong file. Seperate netconsole-only functions in netconsole, avoiding exports. 1. Expose netpoll logging macros in the public header to enable consistent log formatting across netpoll consumers. 2. Relocate netconsole-specific functions from netpoll to the netconsole module where they are actually used, reducing unnecessary coupling. 3. Remove unnecessary function exports 4. Rename netpoll parsing functions in netconsole to better reflect their specific usage. 5. Create a test to check that cmdline works fine. This was in my todo list since [1], this was a good time to add it here to make sure this patchset doesn't regress. PS: The code was split in a way that it is easy to review. When copying the functions from netpoll to netconsole, I do not change than other than adding `static`. This will make checkpatch unhappy, but, further patches will address the issues. It is done this way to make it easy for reviewers. Link: https://lore.kernel.org/netdev/[email protected]/ [1] v2: https://lore.kernel.org/[email protected] v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents e9a7795 + 69d094e commit 7aa3f99

File tree

6 files changed

+240
-155
lines changed

6 files changed

+240
-155
lines changed

drivers/net/netconsole.c

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,23 @@ static void netconsole_process_cleanups_core(void)
278278
mutex_unlock(&target_cleanup_list_lock);
279279
}
280280

281+
static void netconsole_print_banner(struct netpoll *np)
282+
{
283+
np_info(np, "local port %d\n", np->local_port);
284+
if (np->ipv6)
285+
np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);
286+
else
287+
np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip);
288+
np_info(np, "interface name '%s'\n", np->dev_name);
289+
np_info(np, "local ethernet address '%pM'\n", np->dev_mac);
290+
np_info(np, "remote port %d\n", np->remote_port);
291+
if (np->ipv6)
292+
np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6);
293+
else
294+
np_info(np, "remote IPv4 address %pI4\n", &np->remote_ip.ip);
295+
np_info(np, "remote ethernet address %pM\n", np->remote_mac);
296+
}
297+
281298
#ifdef CONFIG_NETCONSOLE_DYNAMIC
282299

283300
/*
@@ -534,10 +551,10 @@ static ssize_t enabled_store(struct config_item *item,
534551
}
535552

536553
/*
537-
* Skip netpoll_parse_options() -- all the attributes are
554+
* Skip netconsole_parser_cmdline() -- all the attributes are
538555
* already configured via configfs. Just print them out.
539556
*/
540-
netpoll_print_options(&nt->np);
557+
netconsole_print_banner(&nt->np);
541558

542559
ret = netpoll_setup(&nt->np);
543560
if (ret)
@@ -1659,6 +1676,120 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
16591676
spin_unlock_irqrestore(&target_list_lock, flags);
16601677
}
16611678

1679+
static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
1680+
{
1681+
const char *end;
1682+
1683+
if (!strchr(str, ':') &&
1684+
in4_pton(str, -1, (void *)addr, -1, &end) > 0) {
1685+
if (!*end)
1686+
return 0;
1687+
}
1688+
if (in6_pton(str, -1, addr->in6.s6_addr, -1, &end) > 0) {
1689+
#if IS_ENABLED(CONFIG_IPV6)
1690+
if (!*end)
1691+
return 1;
1692+
#else
1693+
return -1;
1694+
#endif
1695+
}
1696+
return -1;
1697+
}
1698+
1699+
static int netconsole_parser_cmdline(struct netpoll *np, char *opt)
1700+
{
1701+
bool ipversion_set = false;
1702+
char *cur = opt;
1703+
char *delim;
1704+
int ipv6;
1705+
1706+
if (*cur != '@') {
1707+
delim = strchr(cur, '@');
1708+
if (!delim)
1709+
goto parse_failed;
1710+
*delim = 0;
1711+
if (kstrtou16(cur, 10, &np->local_port))
1712+
goto parse_failed;
1713+
cur = delim;
1714+
}
1715+
cur++;
1716+
1717+
if (*cur != '/') {
1718+
ipversion_set = true;
1719+
delim = strchr(cur, '/');
1720+
if (!delim)
1721+
goto parse_failed;
1722+
*delim = 0;
1723+
ipv6 = netpoll_parse_ip_addr(cur, &np->local_ip);
1724+
if (ipv6 < 0)
1725+
goto parse_failed;
1726+
else
1727+
np->ipv6 = (bool)ipv6;
1728+
cur = delim;
1729+
}
1730+
cur++;
1731+
1732+
if (*cur != ',') {
1733+
/* parse out dev_name or dev_mac */
1734+
delim = strchr(cur, ',');
1735+
if (!delim)
1736+
goto parse_failed;
1737+
*delim = 0;
1738+
1739+
np->dev_name[0] = '\0';
1740+
eth_broadcast_addr(np->dev_mac);
1741+
if (!strchr(cur, ':'))
1742+
strscpy(np->dev_name, cur, sizeof(np->dev_name));
1743+
else if (!mac_pton(cur, np->dev_mac))
1744+
goto parse_failed;
1745+
1746+
cur = delim;
1747+
}
1748+
cur++;
1749+
1750+
if (*cur != '@') {
1751+
/* dst port */
1752+
delim = strchr(cur, '@');
1753+
if (!delim)
1754+
goto parse_failed;
1755+
*delim = 0;
1756+
if (*cur == ' ' || *cur == '\t')
1757+
np_info(np, "warning: whitespace is not allowed\n");
1758+
if (kstrtou16(cur, 10, &np->remote_port))
1759+
goto parse_failed;
1760+
cur = delim;
1761+
}
1762+
cur++;
1763+
1764+
/* dst ip */
1765+
delim = strchr(cur, '/');
1766+
if (!delim)
1767+
goto parse_failed;
1768+
*delim = 0;
1769+
ipv6 = netpoll_parse_ip_addr(cur, &np->remote_ip);
1770+
if (ipv6 < 0)
1771+
goto parse_failed;
1772+
else if (ipversion_set && np->ipv6 != (bool)ipv6)
1773+
goto parse_failed;
1774+
else
1775+
np->ipv6 = (bool)ipv6;
1776+
cur = delim + 1;
1777+
1778+
if (*cur != 0) {
1779+
/* MAC address */
1780+
if (!mac_pton(cur, np->remote_mac))
1781+
goto parse_failed;
1782+
}
1783+
1784+
netconsole_print_banner(np);
1785+
1786+
return 0;
1787+
1788+
parse_failed:
1789+
np_info(np, "couldn't parse config at '%s'!\n", cur);
1790+
return -1;
1791+
}
1792+
16621793
/* Allocate new target (from boot/module param) and setup netpoll for it */
16631794
static struct netconsole_target *alloc_param_target(char *target_config,
16641795
int cmdline_count)
@@ -1688,7 +1819,7 @@ static struct netconsole_target *alloc_param_target(char *target_config,
16881819
}
16891820

16901821
/* Parse parameters and setup netpoll */
1691-
err = netpoll_parse_options(&nt->np, target_config);
1822+
err = netconsole_parser_cmdline(&nt->np, target_config);
16921823
if (err)
16931824
goto fail;
16941825

include/linux/netpoll.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ struct netpoll {
4242
struct work_struct refill_wq;
4343
};
4444

45+
#define np_info(np, fmt, ...) \
46+
pr_info("%s: " fmt, np->name, ##__VA_ARGS__)
47+
#define np_err(np, fmt, ...) \
48+
pr_err("%s: " fmt, np->name, ##__VA_ARGS__)
49+
#define np_notice(np, fmt, ...) \
50+
pr_notice("%s: " fmt, np->name, ##__VA_ARGS__)
51+
4552
struct netpoll_info {
4653
refcount_t refcnt;
4754

@@ -65,11 +72,8 @@ static inline void netpoll_poll_enable(struct net_device *dev) { return; }
6572
#endif
6673

6774
int netpoll_send_udp(struct netpoll *np, const char *msg, int len);
68-
void netpoll_print_options(struct netpoll *np);
69-
int netpoll_parse_options(struct netpoll *np, char *opt);
7075
int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
7176
int netpoll_setup(struct netpoll *np);
72-
void __netpoll_cleanup(struct netpoll *np);
7377
void __netpoll_free(struct netpoll *np);
7478
void netpoll_cleanup(struct netpoll *np);
7579
void do_netpoll_cleanup(struct netpoll *np);

net/core/netpoll.c

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ static void zap_completion_queue(void);
5858
static unsigned int carrier_timeout = 4;
5959
module_param(carrier_timeout, uint, 0644);
6060

61-
#define np_info(np, fmt, ...) \
62-
pr_info("%s: " fmt, np->name, ##__VA_ARGS__)
63-
#define np_err(np, fmt, ...) \
64-
pr_err("%s: " fmt, np->name, ##__VA_ARGS__)
65-
#define np_notice(np, fmt, ...) \
66-
pr_notice("%s: " fmt, np->name, ##__VA_ARGS__)
67-
6861
static netdev_tx_t netpoll_start_xmit(struct sk_buff *skb,
6962
struct net_device *dev,
7063
struct netdev_queue *txq)
@@ -499,43 +492,6 @@ int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
499492
}
500493
EXPORT_SYMBOL(netpoll_send_udp);
501494

502-
void netpoll_print_options(struct netpoll *np)
503-
{
504-
np_info(np, "local port %d\n", np->local_port);
505-
if (np->ipv6)
506-
np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);
507-
else
508-
np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip);
509-
np_info(np, "interface name '%s'\n", np->dev_name);
510-
np_info(np, "local ethernet address '%pM'\n", np->dev_mac);
511-
np_info(np, "remote port %d\n", np->remote_port);
512-
if (np->ipv6)
513-
np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6);
514-
else
515-
np_info(np, "remote IPv4 address %pI4\n", &np->remote_ip.ip);
516-
np_info(np, "remote ethernet address %pM\n", np->remote_mac);
517-
}
518-
EXPORT_SYMBOL(netpoll_print_options);
519-
520-
static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
521-
{
522-
const char *end;
523-
524-
if (!strchr(str, ':') &&
525-
in4_pton(str, -1, (void *)addr, -1, &end) > 0) {
526-
if (!*end)
527-
return 0;
528-
}
529-
if (in6_pton(str, -1, addr->in6.s6_addr, -1, &end) > 0) {
530-
#if IS_ENABLED(CONFIG_IPV6)
531-
if (!*end)
532-
return 1;
533-
#else
534-
return -1;
535-
#endif
536-
}
537-
return -1;
538-
}
539495

540496
static void skb_pool_flush(struct netpoll *np)
541497
{
@@ -546,95 +502,6 @@ static void skb_pool_flush(struct netpoll *np)
546502
skb_queue_purge_reason(skb_pool, SKB_CONSUMED);
547503
}
548504

549-
int netpoll_parse_options(struct netpoll *np, char *opt)
550-
{
551-
char *cur=opt, *delim;
552-
int ipv6;
553-
bool ipversion_set = false;
554-
555-
if (*cur != '@') {
556-
if ((delim = strchr(cur, '@')) == NULL)
557-
goto parse_failed;
558-
*delim = 0;
559-
if (kstrtou16(cur, 10, &np->local_port))
560-
goto parse_failed;
561-
cur = delim;
562-
}
563-
cur++;
564-
565-
if (*cur != '/') {
566-
ipversion_set = true;
567-
if ((delim = strchr(cur, '/')) == NULL)
568-
goto parse_failed;
569-
*delim = 0;
570-
ipv6 = netpoll_parse_ip_addr(cur, &np->local_ip);
571-
if (ipv6 < 0)
572-
goto parse_failed;
573-
else
574-
np->ipv6 = (bool)ipv6;
575-
cur = delim;
576-
}
577-
cur++;
578-
579-
if (*cur != ',') {
580-
/* parse out dev_name or dev_mac */
581-
if ((delim = strchr(cur, ',')) == NULL)
582-
goto parse_failed;
583-
*delim = 0;
584-
585-
np->dev_name[0] = '\0';
586-
eth_broadcast_addr(np->dev_mac);
587-
if (!strchr(cur, ':'))
588-
strscpy(np->dev_name, cur, sizeof(np->dev_name));
589-
else if (!mac_pton(cur, np->dev_mac))
590-
goto parse_failed;
591-
592-
cur = delim;
593-
}
594-
cur++;
595-
596-
if (*cur != '@') {
597-
/* dst port */
598-
if ((delim = strchr(cur, '@')) == NULL)
599-
goto parse_failed;
600-
*delim = 0;
601-
if (*cur == ' ' || *cur == '\t')
602-
np_info(np, "warning: whitespace is not allowed\n");
603-
if (kstrtou16(cur, 10, &np->remote_port))
604-
goto parse_failed;
605-
cur = delim;
606-
}
607-
cur++;
608-
609-
/* dst ip */
610-
if ((delim = strchr(cur, '/')) == NULL)
611-
goto parse_failed;
612-
*delim = 0;
613-
ipv6 = netpoll_parse_ip_addr(cur, &np->remote_ip);
614-
if (ipv6 < 0)
615-
goto parse_failed;
616-
else if (ipversion_set && np->ipv6 != (bool)ipv6)
617-
goto parse_failed;
618-
else
619-
np->ipv6 = (bool)ipv6;
620-
cur = delim + 1;
621-
622-
if (*cur != 0) {
623-
/* MAC address */
624-
if (!mac_pton(cur, np->remote_mac))
625-
goto parse_failed;
626-
}
627-
628-
netpoll_print_options(np);
629-
630-
return 0;
631-
632-
parse_failed:
633-
np_info(np, "couldn't parse config at '%s'!\n", cur);
634-
return -1;
635-
}
636-
EXPORT_SYMBOL(netpoll_parse_options);
637-
638505
static void refill_skbs_work_handler(struct work_struct *work)
639506
{
640507
struct netpoll *np =
@@ -863,7 +730,7 @@ static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
863730
kfree(npinfo);
864731
}
865732

866-
void __netpoll_cleanup(struct netpoll *np)
733+
static void __netpoll_cleanup(struct netpoll *np)
867734
{
868735
struct netpoll_info *npinfo;
869736

@@ -885,7 +752,6 @@ void __netpoll_cleanup(struct netpoll *np)
885752

886753
skb_pool_flush(np);
887754
}
888-
EXPORT_SYMBOL_GPL(__netpoll_cleanup);
889755

890756
void __netpoll_free(struct netpoll *np)
891757
{

tools/testing/selftests/drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ TEST_GEN_FILES := \
1212
TEST_PROGS := \
1313
napi_id.py \
1414
netcons_basic.sh \
15+
netcons_cmdline.sh \
1516
netcons_fragmented_msg.sh \
1617
netcons_overflow.sh \
1718
netcons_sysdata.sh \

0 commit comments

Comments
 (0)