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 set_socket_address(sa, string) \
43 (sa)->sun_family = AF_UNIX; \
44 memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \
45 strcpy((sa)->sun_path + 1, (string)); \
48 #define RSTP_SERVER_SOCK_NAME ".rstp_server"
53 int CTL_enable_bridge_rstp(int br_index
, int enable
);
55 #define CMD_CODE_enable_bridge_rstp 101
56 #define enable_bridge_rstp_ARGS (int br_index, int enable)
57 struct enable_bridge_rstp_IN
{ int br_index
; int enable
; };
58 struct enable_bridge_rstp_OUT
{ };
59 #define enable_bridge_rstp_COPY_IN \
60 ({ in->br_index = br_index; in->enable = enable; })
61 #define enable_bridge_rstp_COPY_OUT ({ (void)0; })
62 #define enable_bridge_rstp_CALL (in->br_index, in->enable)
65 int CTL_get_bridge_state(int br_index
,
66 UID_STP_CFG_T
*cfg
, UID_STP_STATE_T
*state
);
68 #define CMD_CODE_get_bridge_state 102
69 #define get_bridge_state_ARGS (int br_index, UID_STP_CFG_T *cfg, UID_STP_STATE_T *state)
70 struct get_bridge_state_IN
{ int br_index
; };
71 struct get_bridge_state_OUT
{ UID_STP_CFG_T cfg
; UID_STP_STATE_T state
; };
72 #define get_bridge_state_COPY_IN \
73 ({ in->br_index = br_index; })
74 #define get_bridge_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; })
75 #define get_bridge_state_CALL (in->br_index, &out->cfg, &out->state)
78 int CTL_set_bridge_config(int br_index
,
81 #define CMD_CODE_set_bridge_config 103
82 #define set_bridge_config_ARGS (int br_index, UID_STP_CFG_T *cfg)
83 struct set_bridge_config_IN
{ int br_index
; UID_STP_CFG_T cfg
; };
84 struct set_bridge_config_OUT
{ };
85 #define set_bridge_config_COPY_IN \
86 ({ in->br_index = br_index; in->cfg = *cfg; })
87 #define set_bridge_config_COPY_OUT ({ (void)0; })
88 #define set_bridge_config_CALL (in->br_index, &in->cfg)
91 int CTL_get_port_state(int br_index
, int port_index
,
92 UID_STP_PORT_CFG_T
*cfg
, UID_STP_PORT_STATE_T
*state
);
94 #define CMD_CODE_get_port_state 104
95 #define get_port_state_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg, UID_STP_PORT_STATE_T *state)
96 struct get_port_state_IN
{ int br_index
; int port_index
; };
97 struct get_port_state_OUT
{ UID_STP_PORT_CFG_T cfg
; UID_STP_PORT_STATE_T state
; };
98 #define get_port_state_COPY_IN \
99 ({ in->br_index = br_index; in->port_index = port_index; })
100 #define get_port_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; })
101 #define get_port_state_CALL (in->br_index, in->port_index, &out->cfg, &out->state)
104 int CTL_set_port_config(int br_index
, int port_index
,
105 UID_STP_PORT_CFG_T
*cfg
);
107 #define CMD_CODE_set_port_config 105
108 #define set_port_config_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg)
109 struct set_port_config_IN
{ int br_index
; int port_index
; UID_STP_PORT_CFG_T cfg
; };
110 struct set_port_config_OUT
{ };
111 #define set_port_config_COPY_IN \
112 ({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; })
113 #define set_port_config_COPY_OUT ({ (void)0; })
114 #define set_port_config_CALL (in->br_index, in->port_index, &in->cfg)
118 int CTL_set_debug_level(int level
);
120 #define CMD_CODE_set_debug_level 106
121 #define set_debug_level_ARGS (int level)
122 struct set_debug_level_IN
{ int level
; };
123 struct set_debug_level_OUT
{ };
124 #define set_debug_level_COPY_IN \
125 ({ in->level = level; })
126 #define set_debug_level_COPY_OUT ({ (void)0; })
127 #define set_debug_level_CALL (in->level)
129 /* General case part in ctl command server switch */
130 #define SERVER_MESSAGE_CASE(name) \
131 case CMD_CODE_ ## name : do { \
132 if (0) LOG("CTL command " #name); \
133 struct name ## _IN in0, *in = &in0; \
134 struct name ## _OUT out0, *out = &out0; \
135 if (sizeof(*in) != lin || sizeof(*out) != (outbuf?*lout:0)) { \
136 LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
137 lin, sizeof(*in), lout?*lout:0, sizeof(*out)); \
140 memcpy(in, inbuf, lin); \
141 int r = CTL_ ## name name ## _CALL; \
143 if (outbuf) memcpy(outbuf, out, *lout); \
147 /* Wraper for the control functions in the control command client */
148 #define CLIENT_SIDE_FUNCTION(name) \
149 int CTL_ ## name name ## _ARGS \
151 struct name ## _IN in0, *in=&in0; \
152 struct name ## _OUT out0, *out = &out0; \
153 int l = sizeof(*out); \
156 int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), out, &l, \
158 if (r || res) LOG("Got return code %d, %d", r, res); \
160 if (res) return res; \