aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-12-15 03:04:35 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2022-05-24 20:59:33 +0000
commit42d5cb0927f8a2ef0be2dc0630d5520555131c95 (patch)
tree71d9e979ebb76cf38433b242049db7a38ebd7636
parent7aecd12d9cbd9419dc07f7847055977cfbc8131f (diff)
downloadsrc-42d5cb0927f8a2ef0be2dc0630d5520555131c95.tar.gz
src-42d5cb0927f8a2ef0be2dc0630d5520555131c95.zip
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
-rw-r--r--sbin/ifconfig/ifconfig.c2
-rw-r--r--sbin/ifconfig/ifconfig.h15
2 files changed, 16 insertions, 1 deletions
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), \