]>
git.ipfire.org Git - people/ms/rstp.git/blob - ctl_socket.h
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"
41 #define LOG_STRING_LEN 256
43 typedef struct _log_string
45 char buf
[LOG_STRING_LEN
];
48 #define set_socket_address(sa, string) \
50 (sa)->sun_family = AF_UNIX; \
51 memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \
52 strcpy((sa)->sun_path + 1, (string)); \
55 #define RSTP_SERVER_SOCK_NAME ".rstp_server"
60 int CTL_enable_bridge_rstp(int br_index
, int enable
);
62 #define CMD_CODE_enable_bridge_rstp 101
63 #define enable_bridge_rstp_ARGS (int br_index, int enable)
64 struct enable_bridge_rstp_IN
{
68 struct enable_bridge_rstp_OUT
{
70 #define enable_bridge_rstp_COPY_IN \
71 ({ in->br_index = br_index; in->enable = enable; })
72 #define enable_bridge_rstp_COPY_OUT ({ (void)0; })
73 #define enable_bridge_rstp_CALL (in->br_index, in->enable)
76 int CTL_get_bridge_status(int br_index
, STP_BridgeStatus
*status
);
78 #define CMD_CODE_get_bridge_status 102
79 #define get_bridge_status_ARGS (int br_index, STP_BridgeStatus *status)
80 struct get_bridge_status_IN
{
83 struct get_bridge_status_OUT
{
84 STP_BridgeStatus status
;
86 #define get_bridge_status_COPY_IN \
87 ({ in->br_index = br_index; })
88 #define get_bridge_status_COPY_OUT ({ *status = out->status; })
89 #define get_bridge_status_CALL (in->br_index, &out->status)
92 int CTL_set_bridge_config(int br_index
, STP_BridgeConfig
*cfg
);
94 #define CMD_CODE_set_bridge_config 103
95 #define set_bridge_config_ARGS (int br_index, STP_BridgeConfig *cfg)
96 struct set_bridge_config_IN
{
100 struct set_bridge_config_OUT
{
102 #define set_bridge_config_COPY_IN \
103 ({ in->br_index = br_index; in->cfg = *cfg; })
104 #define set_bridge_config_COPY_OUT ({ (void)0; })
105 #define set_bridge_config_CALL (in->br_index, &in->cfg)
108 int CTL_get_port_status(int br_index
, int port_index
, STP_PortStatus
*status
);
110 #define CMD_CODE_get_port_status 104
111 #define get_port_status_ARGS (int br_index, int port_index, STP_PortStatus *status)
112 struct get_port_status_IN
{
116 struct get_port_status_OUT
{
117 STP_PortStatus status
;
119 #define get_port_status_COPY_IN \
120 ({ in->br_index = br_index; in->port_index = port_index; })
121 #define get_port_status_COPY_OUT ({ *status = out->status; })
122 #define get_port_status_CALL (in->br_index, in->port_index, &out->status)
125 int CTL_set_port_config(int br_index
, int port_index
, STP_PortConfig
*cfg
);
127 #define CMD_CODE_set_port_config 105
128 #define set_port_config_ARGS (int br_index, int port_index, STP_PortConfig *cfg)
129 struct set_port_config_IN
{
134 struct set_port_config_OUT
{
136 #define set_port_config_COPY_IN \
137 ({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; })
138 #define set_port_config_COPY_OUT ({ (void)0; })
139 #define set_port_config_CALL (in->br_index, in->port_index, &in->cfg)
142 int CTL_port_mcheck(int br_index
, int port_index
);
144 #define CMD_CODE_port_mcheck 106
145 #define port_mcheck_ARGS (int br_index, int port_index)
146 struct port_mcheck_IN
{
150 struct port_mcheck_OUT
{
152 #define port_mcheck_COPY_IN \
153 ({ in->br_index = br_index; in->port_index = port_index; })
154 #define port_mcheck_COPY_OUT ({ (void)0; })
155 #define port_mcheck_CALL (in->br_index, in->port_index)
158 int CTL_set_debug_level(int level
);
160 #define CMD_CODE_set_debug_level 107
161 #define set_debug_level_ARGS (int level)
162 struct set_debug_level_IN
{
165 struct set_debug_level_OUT
{
167 #define set_debug_level_COPY_IN \
168 ({ in->level = level; })
169 #define set_debug_level_COPY_OUT ({ (void)0; })
170 #define set_debug_level_CALL (in->level)
172 /* General case part in ctl command server switch */
173 #define SERVER_MESSAGE_CASE(name) \
174 case CMD_CODE_ ## name : do { \
175 if (0) LOG("CTL command " #name); \
176 struct name ## _IN in0, *in = &in0; \
177 struct name ## _OUT out0, *out = &out0; \
178 if (sizeof(*in) != lin || sizeof(*out) != lout) { \
179 LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
180 lin, sizeof(*in), lout, sizeof(*out)); \
183 memcpy(in, inbuf, lin); \
184 int r = CTL_ ## name name ## _CALL; \
186 if (outbuf) memcpy(outbuf, out, lout); \
190 /* Wraper for the control functions in the control command client */
191 #define CLIENT_SIDE_FUNCTION(name) \
192 int CTL_ ## name name ## _ARGS \
194 struct name ## _IN in0, *in=&in0; \
195 struct name ## _OUT out0, *out = &out0; \
198 LogString log = { .buf = "" }; \
199 int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), \
200 out, sizeof(*out), &log, &res); \
201 if (r || res) LOG("Got return code %d, %d\n%s", r, res, log.buf); \
203 if (res) return res; \