Date: Tue, 23 Nov 2004 20:54:57 GMT From: Sam Leffler <sam@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 65728 for review Message-ID: <200411232054.iANKsvX6073882@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=65728 Change 65728 by sam@sam_ebb on 2004/11/23 20:54:22 o replace dual command function pointers with a single pointer wrapped in an anonymous union o add convenience defines for declaring callback functions and for initializing command structures s.t. the correct arm of the union is used should be no functional changes Affected files ... .. //depot/projects/wifi/sbin/ifconfig/af_atalk.c#2 edit .. //depot/projects/wifi/sbin/ifconfig/af_inet6.c#3 edit .. //depot/projects/wifi/sbin/ifconfig/ifclone.c#3 edit .. //depot/projects/wifi/sbin/ifconfig/ifconfig.c#4 edit .. //depot/projects/wifi/sbin/ifconfig/ifconfig.h#4 edit .. //depot/projects/wifi/sbin/ifconfig/ifmac.c#3 edit .. //depot/projects/wifi/sbin/ifconfig/ifmedia.c#3 edit .. //depot/projects/wifi/sbin/ifconfig/ifvlan.c#3 edit Differences ... ==== //depot/projects/wifi/sbin/ifconfig/af_atalk.c#2 (text+ko) ==== @@ -155,8 +155,8 @@ } static struct cmd atalk_cmds[] = { - { "range", NEXTARG, setatrange }, - { "phase", NEXTARG, setatphase }, + DEF_CMD_ARG("range", setatrange), + DEF_CMD_ARG("phase", setatphase), }; static struct afswtch af_atalk = { ==== //depot/projects/wifi/sbin/ifconfig/af_inet6.c#3 (text+ko) ==== @@ -498,17 +498,17 @@ } static struct cmd inet6_cmds[] = { - { "prefixlen", NEXTARG, setifprefixlen }, - { "anycast", IN6_IFF_ANYCAST, setip6flags }, - { "tentative", IN6_IFF_TENTATIVE, setip6flags }, - { "-tentative", -IN6_IFF_TENTATIVE, setip6flags }, - { "deprecated", IN6_IFF_DEPRECATED, setip6flags }, - { "-deprecated", -IN6_IFF_DEPRECATED, setip6flags }, - { "autoconf", IN6_IFF_AUTOCONF, setip6flags }, - { "-autoconf", -IN6_IFF_AUTOCONF, setip6flags }, - { "pltime", NEXTARG, setip6pltime }, - { "vltime", NEXTARG, setip6vltime }, - { "eui64", 0, setip6eui64 }, + DEF_CMD_ARG("prefixlen", setifprefixlen), + DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags), + DEF_CMD("tentative", IN6_IFF_TENTATIVE, setip6flags), + DEF_CMD("-tentative", -IN6_IFF_TENTATIVE, setip6flags), + DEF_CMD("deprecated", IN6_IFF_DEPRECATED, setip6flags), + DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags), + DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags), + DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags), + DEF_CMD_ARG("pltime", setip6pltime), + DEF_CMD_ARG("vltime", setip6vltime), + DEF_CMD("eui64", 0, setip6eui64), }; static struct afswtch af_inet6 = { ==== //depot/projects/wifi/sbin/ifconfig/ifclone.c#3 (text+ko) ==== @@ -130,8 +130,8 @@ } static struct cmd clone_cmds[] = { - { "destroy", 0, clone_destroy }, - { "unplumb", 0, clone_destroy }, + DEF_CMD("destroy", 0, clone_destroy), + DEF_CMD("unplumb", 0, clone_destroy), }; static void ==== //depot/projects/wifi/sbin/ifconfig/ifconfig.c#4 (text+ko) ==== @@ -448,10 +448,11 @@ /* specially-handled comamnds */ static void setifaddr(const char *, int, int, const struct afswtch *); -static const struct cmd setifaddr_cmd = { "ifaddr", 0, setifaddr }; +static const struct cmd setifaddr_cmd = DEF_CMD("ifaddr", 0, setifaddr); static void setifdstaddr(const char *, int, int, const struct afswtch *); -static const struct cmd setifdstaddr_cmd = { "ifdstaddr", 0, setifdstaddr }; +static const struct cmd setifdstaddr_cmd = + DEF_CMD("ifdstaddr", 0, setifdstaddr); static int ifconfig(int argc, char *const *argv, const struct afswtch *afp) @@ -951,53 +952,53 @@ } static struct cmd basic_cmds[] = { - { "up", IFF_UP, setifflags } , - { "down", -IFF_UP, setifflags }, - { "arp", -IFF_NOARP, setifflags }, - { "-arp", IFF_NOARP, setifflags }, - { "debug", IFF_DEBUG, setifflags }, - { "-debug", -IFF_DEBUG, setifflags }, - { "promisc", IFF_PPROMISC, setifflags }, - { "-promisc", -IFF_PPROMISC, setifflags }, - { "add", IFF_UP, notealias }, - { "alias", IFF_UP, notealias }, - { "-alias", -IFF_UP, notealias }, - { "delete", -IFF_UP, notealias }, - { "remove", -IFF_UP, notealias }, + DEF_CMD("up", IFF_UP, setifflags), + DEF_CMD("down", -IFF_UP, setifflags), + DEF_CMD("arp", -IFF_NOARP, setifflags), + DEF_CMD("-arp", IFF_NOARP, setifflags), + DEF_CMD("debug", IFF_DEBUG, setifflags), + DEF_CMD("-debug", -IFF_DEBUG, setifflags), + DEF_CMD("promisc", IFF_PPROMISC, setifflags), + DEF_CMD("-promisc", -IFF_PPROMISC, setifflags), + DEF_CMD("add", IFF_UP, notealias), + DEF_CMD("alias", IFF_UP, notealias), + DEF_CMD("-alias", -IFF_UP, notealias), + DEF_CMD("delete", -IFF_UP, notealias), + DEF_CMD("remove", -IFF_UP, notealias), #ifdef notdef #define EN_SWABIPS 0x1000 - { "swabips", EN_SWABIPS, setifflags }, - { "-swabips", -EN_SWABIPS, setifflags }, + DEF_CMD("swabips", EN_SWABIPS, setifflags), + DEF_CMD("-swabips", -EN_SWABIPS, setifflags), #endif - { "netmask", NEXTARG, setifnetmask }, - { "metric", NEXTARG, setifmetric }, - { "broadcast", NEXTARG, setifbroadaddr }, - { "ipdst", NEXTARG, setifipdst }, - { "tunnel", NEXTARG2, NULL, settunnel }, - { "deletetunnel", 0, deletetunnel }, - { "link0", IFF_LINK0, setifflags }, - { "-link0", -IFF_LINK0, setifflags }, - { "link1", IFF_LINK1, setifflags }, - { "-link1", -IFF_LINK1, setifflags }, - { "link2", IFF_LINK2, setifflags }, - { "-link2", -IFF_LINK2, setifflags }, - { "monitor", IFF_MONITOR, setifflags }, - { "-monitor", -IFF_MONITOR, setifflags }, - { "staticarp", IFF_STATICARP, setifflags }, - { "-staticarp", -IFF_STATICARP, setifflags }, - { "rxcsum", IFCAP_RXCSUM, setifcap }, - { "-rxcsum", -IFCAP_RXCSUM, setifcap }, - { "txcsum", IFCAP_TXCSUM, setifcap }, - { "-txcsum", -IFCAP_TXCSUM, setifcap }, - { "netcons", IFCAP_NETCONS, setifcap }, - { "-netcons", -IFCAP_NETCONS, setifcap }, - { "polling", IFCAP_POLLING, setifcap }, - { "-polling", -IFCAP_POLLING, setifcap }, - { "normal", -IFF_LINK0, setifflags }, - { "compress", IFF_LINK0, setifflags }, - { "noicmp", IFF_LINK1, setifflags }, - { "mtu", NEXTARG, setifmtu }, - { "name", NEXTARG, setifname }, + DEF_CMD_ARG("netmask", setifnetmask), + DEF_CMD_ARG("metric", setifmetric), + DEF_CMD_ARG("broadcast", setifbroadaddr), + DEF_CMD_ARG("ipdst", setifipdst), + DEF_CMD_ARG2("tunnel", settunnel), + DEF_CMD("deletetunnel", 0, deletetunnel), + DEF_CMD("link0", IFF_LINK0, setifflags), + DEF_CMD("-link0", -IFF_LINK0, setifflags), + DEF_CMD("link1", IFF_LINK1, setifflags), + DEF_CMD("-link1", -IFF_LINK1, setifflags), + DEF_CMD("link2", IFF_LINK2, setifflags), + DEF_CMD("-link2", -IFF_LINK2, setifflags), + DEF_CMD("monitor", IFF_MONITOR, setifflags), + DEF_CMD("-monitor", -IFF_MONITOR, setifflags), + DEF_CMD("staticarp", IFF_STATICARP, setifflags), + DEF_CMD("-staticarp", -IFF_STATICARP, setifflags), + DEF_CMD("rxcsum", IFCAP_RXCSUM, setifcap), + DEF_CMD("-rxcsum", -IFCAP_RXCSUM, setifcap), + DEF_CMD("txcsum", IFCAP_TXCSUM, setifcap), + DEF_CMD("-txcsum", -IFCAP_TXCSUM, setifcap), + DEF_CMD("netcons", IFCAP_NETCONS, setifcap), + DEF_CMD("-netcons", -IFCAP_NETCONS, setifcap), + DEF_CMD("polling", IFCAP_POLLING, setifcap), + DEF_CMD("-polling", -IFCAP_POLLING, setifcap), + DEF_CMD("normal", -IFF_LINK0, setifflags), + DEF_CMD("compress", IFF_LINK0, setifflags), + DEF_CMD("noicmp", IFF_LINK1, setifflags), + DEF_CMD_ARG("mtu", setifmtu), + DEF_CMD_ARG("name", setifname), }; static __constructor void ==== //depot/projects/wifi/sbin/ifconfig/ifconfig.h#4 (text+ko) ==== @@ -40,7 +40,7 @@ struct cmd; typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp); -typedef void c_func2(const char *arg, const char *arg2, int s, const struct afswtch *afp); +typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp); struct cmd { const char *c_name; @@ -48,12 +48,27 @@ #define NEXTARG 0xffffff /* has following arg */ #define NEXTARG2 0xfffffe /* has 2 following args */ #define OPTARG 0xfffffd /* has optional following arg */ - c_func *c_func; - c_func2 *c_func2; + union { + c_func *c_func; + c_func2 *c_func2; + }; struct cmd *c_next; }; void cmd_register(struct cmd *); +/* + * Macros for declaring command functions and initializing entries. + */ +#define DECL_CMD_FUNC(name, cmd, arg) \ + void name(const char *cmd, int arg, int s, const struct afswtch *afp) +#define DECL_CMD_FUNC2(name, arg1, arg2) \ + void name(const char *arg1, const char *arg2, int s, const struct afswtch *afp) + +#define DEF_CMD(name, param, func) { name, param, { .c_func = func } } +#define DEF_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func } } +#define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func } } +#define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func } } + struct rt_addrinfo; struct addrinfo; ==== //depot/projects/wifi/sbin/ifconfig/ifmac.c#3 (text+ko) ==== @@ -100,7 +100,7 @@ } static struct cmd mac_cmds[] = { - { "maclabel", NEXTARG, setifmaclabel }, + DEF_CMD_ARG("maclabel", setifmaclabel), }; static struct afswtch af_mac = { .af_name = "maclabel", ==== //depot/projects/wifi/sbin/ifconfig/ifmedia.c#3 (text+ko) ==== @@ -779,10 +779,10 @@ **********************************************************************/ static struct cmd media_cmds[] = { - { "media", NEXTARG, setmedia }, - { "mode", NEXTARG, setmediamode }, - { "mediaopt", NEXTARG, setmediaopt }, - { "-mediaopt", NEXTARG, unsetmediaopt }, + DEF_CMD_ARG("media", setmedia), + DEF_CMD_ARG("mode", setmediamode), + DEF_CMD_ARG("mediaopt", setmediaopt), + DEF_CMD_ARG("-mediaopt",unsetmediaopt), }; static struct afswtch af_media = { .af_name = "media", ==== //depot/projects/wifi/sbin/ifconfig/ifvlan.c#3 (text+ko) ==== @@ -146,13 +146,13 @@ } static struct cmd vlan_cmds[] = { - { "vlan", NEXTARG, setvlantag }, - { "vlandev", NEXTARG, setvlandev }, - { "-vlandev", NEXTARG, unsetvlandev }, - { "vlanmtu", IFCAP_VLAN_MTU, setifcap }, - { "-vlanmtu", -IFCAP_VLAN_MTU, setifcap }, - { "vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap }, - { "-vlanhwtag", -IFCAP_VLAN_HWTAGGING, setifcap }, + DEF_CMD_ARG("vlan", setvlantag), + DEF_CMD_ARG("vlandev", setvlandev), + DEF_CMD_ARG("-vlandev", unsetvlandev), + DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap), + DEF_CMD("-vlanmtu", -IFCAP_VLAN_MTU, setifcap), + DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap), + DEF_CMD("-vlanhwtag", -IFCAP_VLAN_HWTAGGING, setifcap), }; static struct afswtch af_vlan = { .af_name = "vlan",
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411232054.iANKsvX6073882>