]>
Commit | Line | Data |
---|---|---|
ad02a0eb SH |
1 | /***************************************************************************** |
2 | Copyright (c) 2006 EMC Corporation. | |
3 | ||
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) | |
7 | any later version. | |
8 | ||
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 | |
12 | more details. | |
13 | ||
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. | |
17 | ||
18 | The full GNU General Public License is included in this distribution in the | |
19 | file called LICENSE. | |
20 | ||
21 | Authors: Srinivas Aji <Aji_Srinivas@emc.com> | |
22 | ||
23 | ******************************************************************************/ | |
24 | ||
25 | #ifndef CTL_SOCKET_H | |
26 | #define CTL_SOCKET_H | |
27 | ||
28 | #include <sys/types.h> | |
29 | #include <string.h> | |
30 | ||
31 | #include "ctl_functions.h" | |
32 | ||
33 | struct ctl_msg_hdr | |
34 | { | |
35 | int cmd; | |
36 | int lin; | |
37 | int lout; | |
38 | int res; | |
39 | }; | |
40 | ||
41 | #define set_socket_address(sa, string) \ | |
42 | do {\ | |
43 | (sa)->sun_family = AF_UNIX; \ | |
44 | memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \ | |
45 | strcpy((sa)->sun_path + 1, (string)); \ | |
46 | } while (0) | |
47 | ||
48 | #define RSTP_SERVER_SOCK_NAME ".rstp_server" | |
49 | ||
50 | /* COMMANDS */ | |
51 | ||
52 | #if 0 | |
53 | int CTL_enable_bridge_rstp(int br_index, int enable); | |
54 | #endif | |
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) | |
63 | ||
64 | #if 0 | |
65 | int CTL_get_bridge_state(int br_index, | |
66 | UID_STP_CFG_T *cfg, UID_STP_STATE_T *state); | |
67 | #endif | |
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) | |
76 | ||
77 | #if 0 | |
78 | int CTL_set_bridge_config(int br_index, | |
79 | UID_STP_CFG_T *cfg); | |
80 | #endif | |
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) | |
89 | ||
90 | #if 0 | |
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); | |
93 | #endif | |
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) | |
102 | ||
103 | #if 0 | |
104 | int CTL_set_port_config(int br_index, int port_index, | |
105 | UID_STP_PORT_CFG_T *cfg); | |
106 | #endif | |
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) | |
115 | ||
116 | ||
117 | #if 0 | |
118 | int CTL_set_debug_level(int level); | |
119 | #endif | |
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) | |
128 | ||
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)); \ | |
138 | return -1; \ | |
139 | } \ | |
140 | memcpy(in, inbuf, lin); \ | |
141 | int r = CTL_ ## name name ## _CALL; \ | |
142 | if (r) return r; \ | |
143 | if (outbuf) memcpy(outbuf, out, *lout); \ | |
144 | return r; \ | |
145 | } while (0) | |
146 | ||
147 | /* Wraper for the control functions in the control command client */ | |
148 | #define CLIENT_SIDE_FUNCTION(name) \ | |
149 | int CTL_ ## name name ## _ARGS \ | |
150 | { \ | |
151 | struct name ## _IN in0, *in=&in0; \ | |
152 | struct name ## _OUT out0, *out = &out0; \ | |
153 | int l = sizeof(*out); \ | |
154 | name ## _COPY_IN; \ | |
155 | int res = 0; \ | |
156 | int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), out, &l, \ | |
157 | &res); \ | |
158 | if (r || res) LOG("Got return code %d, %d", r, res); \ | |
159 | if (r) return r; \ | |
160 | if (res) return res; \ | |
161 | name ## _COPY_OUT; \ | |
162 | return r; \ | |
163 | } | |
164 | ||
165 | ||
166 | ||
167 | #endif |