git: 42d5cb0927f8 - main - ifconfig: add glue for specifying functions taking static string parameter
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 24 May 2022 20:59:50 UTC
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=42d5cb0927f8a2ef0be2dc0630d5520555131c95 commit 42d5cb0927f8a2ef0be2dc0630d5520555131c95 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-12-15 03:04:35 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2022-05-24 20:59:33 +0000 ifconfig: add glue for specifying functions taking static string parameter Reviewed by: hselasky, jhb, kp Sponsored by: NVIDIA Networking MFC after: 3 weeks Differential revision: https://reviews.freebsd.org/D32551 --- sbin/ifconfig/ifconfig.c | 2 ++ sbin/ifconfig/ifconfig.h | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 9e7d38d4c2a4..37ce0fb18943 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -991,6 +991,8 @@ top: p->c_name); p->c_u.c_func2(argv[1], argv[2], s, afp); argc -= 2, argv += 2; + } else if (p->c_parameter == SPARAM && p->c_u.c_func3) { + p->c_u.c_func3(*argv, p->c_sparameter, s, afp); } else if (p->c_u.c_func) p->c_u.c_func(*argv, p->c_parameter, s, afp); argc--, argv++; diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 76f6ef926a5c..4a9fb380fbab 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -48,6 +48,8 @@ struct cmd; typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp); typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp); +typedef void c_func3(const char *cmd, const char *arg, int s, + const struct afswtch *afp); struct cmd { const char *c_name; @@ -55,9 +57,12 @@ struct cmd { #define NEXTARG 0xffffff /* has following arg */ #define NEXTARG2 0xfffffe /* has 2 following args */ #define OPTARG 0xfffffd /* has optional following arg */ +#define SPARAM 0xfffffc /* parameter is string c_sparameter */ + const char *c_sparameter; union { c_func *c_func; c_func2 *c_func2; + c_func3 *c_func3; } c_u; int c_iscloneop; struct cmd *c_next; @@ -81,7 +86,7 @@ void callback_register(callback_func *, void *); .c_parameter = (param), \ .c_u = { .c_func = (func) }, \ .c_iscloneop = 0, \ - .c_next = NULL, + .c_next = NULL, \ } #define DEF_CMD_ARG(name, func) { \ .c_name = (name), \ @@ -104,6 +109,14 @@ void callback_register(callback_func *, void *); .c_iscloneop = 0, \ .c_next = NULL, \ } +#define DEF_CMD_SARG(name, sparam, func) { \ + .c_name = (name), \ + .c_parameter = SPARAM, \ + .c_sparameter = (sparam), \ + .c_u = { .c_func3 = (func) }, \ + .c_iscloneop = 0, \ + .c_next = NULL, \ +} #define DEF_CLONE_CMD(name, param, func) { \ .c_name = (name), \ .c_parameter = (param), \