1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 The full GNU General Public License is included in this distribution in the
21 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 ******************************************************************************/
28 #include <sys/types.h>
31 #include "ctl_functions.h"
40 #define set_socket_address(sa, string) \
42 (sa)->sun_family = AF_UNIX; \
43 memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \
44 strcpy((sa)->sun_path + 1, (string)); \
47 #define RSTP_SERVER_SOCK_NAME ".rstp_server"
52 int CTL_enable_bridge_rstp(int br_index
, int enable
);
54 #define CMD_CODE_enable_bridge_rstp 101
55 #define enable_bridge_rstp_ARGS (int br_index, int enable)
56 struct enable_bridge_rstp_IN
{
60 struct enable_bridge_rstp_OUT
{
62 #define enable_bridge_rstp_COPY_IN \
63 ({ in->br_index = br_index; in->enable = enable; })
64 #define enable_bridge_rstp_COPY_OUT ({ (void)0; })
65 #define enable_bridge_rstp_CALL (in->br_index, in->enable)
68 int CTL_get_bridge_state(int br_index
,
69 UID_STP_CFG_T
* cfg
, UID_STP_STATE_T
* state
);
71 #define CMD_CODE_get_bridge_state 102
72 #define get_bridge_state_ARGS (int br_index, UID_STP_CFG_T *cfg, UID_STP_STATE_T *state)
73 struct get_bridge_state_IN
{
76 struct get_bridge_state_OUT
{
78 UID_STP_STATE_T state
;
80 #define get_bridge_state_COPY_IN \
81 ({ in->br_index = br_index; })
82 #define get_bridge_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; })
83 #define get_bridge_state_CALL (in->br_index, &out->cfg, &out->state)
86 int CTL_set_bridge_config(int br_index
, UID_STP_CFG_T
* cfg
);
88 #define CMD_CODE_set_bridge_config 103
89 #define set_bridge_config_ARGS (int br_index, UID_STP_CFG_T *cfg)
90 struct set_bridge_config_IN
{
94 struct set_bridge_config_OUT
{
96 #define set_bridge_config_COPY_IN \
97 ({ in->br_index = br_index; in->cfg = *cfg; })
98 #define set_bridge_config_COPY_OUT ({ (void)0; })
99 #define set_bridge_config_CALL (in->br_index, &in->cfg)
102 int CTL_get_port_state(int br_index
, int port_index
,
103 UID_STP_PORT_CFG_T
* cfg
, UID_STP_PORT_STATE_T
* state
);
105 #define CMD_CODE_get_port_state 104
106 #define get_port_state_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg, UID_STP_PORT_STATE_T *state)
107 struct get_port_state_IN
{
111 struct get_port_state_OUT
{
112 UID_STP_PORT_CFG_T cfg
;
113 UID_STP_PORT_STATE_T state
;
115 #define get_port_state_COPY_IN \
116 ({ in->br_index = br_index; in->port_index = port_index; })
117 #define get_port_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; })
118 #define get_port_state_CALL (in->br_index, in->port_index, &out->cfg, &out->state)
121 int CTL_set_port_config(int br_index
, int port_index
, UID_STP_PORT_CFG_T
* cfg
);
123 #define CMD_CODE_set_port_config 105
124 #define set_port_config_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg)
125 struct set_port_config_IN
{
128 UID_STP_PORT_CFG_T cfg
;
130 struct set_port_config_OUT
{
132 #define set_port_config_COPY_IN \
133 ({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; })
134 #define set_port_config_COPY_OUT ({ (void)0; })
135 #define set_port_config_CALL (in->br_index, in->port_index, &in->cfg)
138 int CTL_set_debug_level(int level
);
140 #define CMD_CODE_set_debug_level 106
141 #define set_debug_level_ARGS (int level)
142 struct set_debug_level_IN
{
145 struct set_debug_level_OUT
{
147 #define set_debug_level_COPY_IN \
148 ({ in->level = level; })
149 #define set_debug_level_COPY_OUT ({ (void)0; })
150 #define set_debug_level_CALL (in->level)
152 /* General case part in ctl command server switch */
153 #define SERVER_MESSAGE_CASE(name) \
154 case CMD_CODE_ ## name : do { \
155 if (0) LOG("CTL command " #name); \
156 struct name ## _IN in0, *in = &in0; \
157 struct name ## _OUT out0, *out = &out0; \
158 if (sizeof(*in) != lin || sizeof(*out) != (outbuf?*lout:0)) { \
159 LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
160 lin, sizeof(*in), lout?*lout:0, sizeof(*out)); \
163 memcpy(in, inbuf, lin); \
164 int r = CTL_ ## name name ## _CALL; \
166 if (outbuf) memcpy(outbuf, out, *lout); \
170 /* Wraper for the control functions in the control command client */
171 #define CLIENT_SIDE_FUNCTION(name) \
172 int CTL_ ## name name ## _ARGS \
174 struct name ## _IN in0, *in=&in0; \
175 struct name ## _OUT out0, *out = &out0; \
176 int l = sizeof(*out); \
179 int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), out, &l, \
181 if (r || res) LOG("Got return code %d, %d", r, res); \
183 if (res) return res; \