Debian Codegraph @

posix/unix_socket.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2006-2012 BATMAN contributors:
3 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22
23
24 #include <sys/time.h>
25 #include <stdio.h>
26 #include <fcntl.h>
27 #include <stdarg.h>
28 #include <errno.h>
29 #include <syslog.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <sys/socket.h>
34 #include <arpa/inet.h>
35 #include <netinet/in.h>
36 #include <pthread.h>
37 #include <stdint.h>
38 #include <sys/select.h>
39 #include <sys/un.h>
40 #include <sys/types.h>
41
42 #include "../os.h"cxx . . $ `<file>/os.h`/
43 #include "../batman.h"cxx . . $ `<file>/batman.h`/
44 #include "../hna.h"cxx . . $ `<file>/hna.h`/
45 #include "../allocate.h"cxx . . $ `<file>/allocate.h`/
46 #include "../list-batman.h"cxx . . $ `<file>/list-batman.h`/
47 #include "../packet.h"cxx . . $ `<file>/packet.h`/
48 #include "../types.h"cxx . . $ `<file>/types.h`/
49
50
51 void debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).(int8_tcxx . . $ int8_t# debug_prio, const char *format, ...) {
52
53 struct list_headcxx . . $ list_head# *debug_pos;
54 struct debug_level_infocxx . . $ debug_level_info# *debug_level_info;
55 int8_tcxx . . $ int8_t# debug_prio_intern;
56 va_listcxx . . $ va_list# args;
57
58
59 if (!log_facility_activecxx . . $ log_facility_active.) {
60 va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, format);
61 vprintfcxx . . $ vprintf(5c80dbd47e6ebfbb).(format, args);
62 va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args);
63 return;
64 }
65
66 if (debug_prio == 0) {
67
68 if (debug_levelcxx . . $ debug_level. == 0) {
69
70 va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, format);
71 vsyslogcxx . . $ vsyslog(7aa579bceef62d01).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, format, args);
72 va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args);
73
74 } else if ((debug_levelcxx . . $ debug_level. == 3) || (debug_levelcxx . . $ debug_level. == 4)) {
75
76 if (debug_levelcxx . . $ debug_level. == 4)
77 printfcxx . . $ printf(581fddd72a8db8fc).("[%10u] ", get_time_mseccxx . . $ get_time_msec(db52760e79bf9054).());
78
79 va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, format);
80 vprintfcxx . . $ vprintf(5c80dbd47e6ebfbb).(format, args);
81 va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args);
82
83 }
84
85 debug_prio_intern = 3;
86
87 } else {
88
89 debug_prio_intern = debug_prio - 1;
90
91 }
92
93 if (debug_clientscxx . . $ debug_clients..clients_numcxx . . $ debug_clients#clients_num.[debug_prio_intern] < 1)
94 return;
95
96 if (pthread_mutex_trylockcxx . . $ pthread_mutex_trylock(d89ae235521888f9).((pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[debug_prio_intern] ) != 0) {
97 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).(0, "Warning - could not trylock mutex (debug_output): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).(EBUSYcxx . . $ `<external>/8987895939074593727/errno-base.h:20:9`!));
98 return;
99 }
100
101 va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, format);
102
103 list_for_eachcxx . . $ `list-batman.h:75:9`!(debug_pos, (struct list_head *)debug_clients.fd_list[debug_prio_intern]) {
104
105 debug_level_info = list_entrycxx . . $ `list-batman.h:67:9`!(debug_pos, struct debug_level_info, list);
106
107 /* batman debug gets milliseconds prepended for better debugging */
108 if (debug_prio_intern == 3)
109 dprintfcxx . . $ dprintf(811d273381043e7b).(debug_level_info->fdcxx . . $ debug_level_info#fd., "[%10u] ", get_time_mseccxx . . $ get_time_msec(db52760e79bf9054).());
110
111 if (((debug_levelcxx . . $ debug_level. == 1) || (debug_levelcxx . . $ debug_level. == 2)) && (debug_level_info->fdcxx . . $ debug_level_info#fd. == 1) && (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(format, "BOD", 3) == 0))
112 /* clear screen, set cursor back to 0,0 */
113 printfcxx . . $ printf(581fddd72a8db8fc).("\033[2J\033[0;0f");
114
115 if (((debug_levelcxx . . $ debug_level. != 1) && (debug_levelcxx . . $ debug_level. != 2)) || (debug_level_info->fdcxx . . $ debug_level_info#fd. != 1) || (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(format, "EOD", 3) != 0))
116 vdprintfcxx . . $ vdprintf(b374854d4d7f936e).(debug_level_info->fdcxx . . $ debug_level_info#fd., format, args);
117
118 }
119
120 va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args);
121
122 if (pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).((pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[debug_prio_intern]) < 0)
123 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).(0, "Error - could not unlock mutex (debug_output): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
124 }
125
126
127
128 void internal_outputcxx . . $ internal_output(cb2f890c2fdad230).(uint32_tcxx . . $ uint32_t# sock)
129 {
130 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "source_version=%s\n", SOURCE_VERSIONcxx . . $ `batman.h:39:9`!);
131 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "compat_version=%i\n", COMPAT_VERSIONcxx . . $ `packet.h:27:9`!);
132 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "vis_compat_version=%i\n", VIS_COMPAT_VERSIONcxx . . $ `packet.h:28:9`!);
133 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "ogm_port=%i\n", PORTcxx . . $ `packet.h:34:9`!);
134 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "gw_port=%i\n", GW_PORTcxx . . $ `packet.h:35:9`!);
135 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "vis_port=%i\n", PORTcxx . . $ `packet.h:34:9`! + 2);
136 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "unix_socket_path=%s\n", UNIX_PATHcxx . . $ `batman.h:44:9`!);
137 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "own_ogm_jitter=%i\n", JITTERcxx . . $ `batman.h:67:9`!);
138 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "default_ttl=%i\n", TTLcxx . . $ `batman.h:68:9`!);
139 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "originator_timeout=%u (default: %u)\n", purge_timeoutcxx . . $ purge_timeout., PURGE_TIMEOUTcxx . . $ `batman.h:69:9`!);
140 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_local_window_size=%i\n", TQ_LOCAL_WINDOW_SIZEcxx . . $ `batman.h:70:9`!);
141 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_global_window_size=%i\n", TQ_GLOBAL_WINDOW_SIZEcxx . . $ `batman.h:71:9`!);
142 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_local_bidirect_send_minimum=%i\n", TQ_LOCAL_BIDRECT_SEND_MINIMUMcxx . . $ `batman.h:72:9`!);
143 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_local_bidirect_recv_minimum=%i\n", TQ_LOCAL_BIDRECT_RECV_MINIMUMcxx . . $ `batman.h:73:9`!);
144 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_hop_penalty=%i (default: %i)\n", hop_penaltycxx . . $ hop_penalty., TQ_HOP_PENALTYcxx . . $ `batman.h:80:9`!);
145 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_total_limit=%i\n", TQ_TOTAL_BIDRECT_LIMITcxx . . $ `batman.h:74:9`!);
146 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "tq_max_value=%i\n", TQ_MAX_VALUEcxx . . $ `batman.h:42:9`!);
147 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_table_networks=%i\n", BATMAN_RT_TABLE_NETWORKScxx . . $ `batman.h:116:9`!);
148 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_table_hosts=%i\n", BATMAN_RT_TABLE_HOSTScxx . . $ `batman.h:117:9`!);
149 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_table_unreach=%i\n", BATMAN_RT_TABLE_UNREACHcxx . . $ `batman.h:118:9`!);
150 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_table_tunnel=%i\n", BATMAN_RT_TABLE_TUNNELcxx . . $ `batman.h:119:9`!);
151 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_prio_default=%i\n", BATMAN_RT_PRIO_DEFAULTcxx . . $ `batman.h:121:9`!);
152 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_prio_unreach=%i\n", BATMAN_RT_PRIO_UNREACHcxx . . $ `batman.h:122:9`!);
153 dprintfcxx . . $ dprintf(811d273381043e7b).(sock, "rt_prio_tunnel=%i\n", BATMAN_RT_PRIO_TUNNELcxx . . $ `batman.h:123:9`!);
154 }
155
156
157
158 void *unix_listencxx . . $ unix_listen(9f162e79bfc6c74).(void * BATMANUNUSEDcxx . . $ `batman.h:136:9`!(arg)) {
159
160 struct unix_clientcxx . . $ unix_client# *unix_client;
161 struct debug_level_infocxx . . $ debug_level_info# *debug_level_info;
162 struct list_headcxx . . $ list_head# *list_pos, *unix_pos_tmp, *debug_pos, *debug_pos_tmp, *prev_list_head, *prev_list_head_unix;
163 struct hna_local_entrycxx . . $ hna_local_entry# *hna_local_entry;
164 struct batman_ifcxx . . $ batman_if# *batman_if;
165 struct timevalcxx . . $ timeval# tv;
166 struct sockaddr_uncxx . . $ sockaddr_un# sun_addr;
167 struct in_addrcxx . . $ in_addr# tmp_ip_holder;
168 int32_tcxx . . $ int32_t# status, max_sock, unix_opts, download_speed, upload_speed;
169 int8_tcxx . . $ int8_t# res;
170 char buff[100], str[16], was_gateway, tmp_unix_value;
171 fd_setcxx . . $ fd_set# wait_sockets, tmp_wait_sockets;
172 socklen_tcxx . . $ socklen_t# sun_size = sizeof(struct sockaddr_uncxx . . $ sockaddr_un#);
173
174
175 INIT_LIST_HEAD_FIRSTcxx . . $ `list-batman.h:57:9`!(unix_if.client_list);
176
177 FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&wait_sockets);
178 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(unix_if.unix_sock, &wait_sockets);
179
180 max_sock = unix_ifcxx . . $ unix_if..unix_sockcxx . . $ unix_if#unix_sock.;
181
182 while (!is_abortedcxx . . $ is_aborted(f1c002f0206d8350).()) {
183
184 tv.tv_seccxx . . $ timeval#tv_sec. = 1;
185 tv.tv_useccxx . . $ timeval#tv_usec. = 0;
186 memcpycxx . . $ memcpy(cc817cb175f282d).(&tmp_wait_sockets, &wait_sockets, sizeof(fd_setcxx . . $ fd_set#));
187
188 res = selectcxx . . $ select(6d24c7514c8a5b88).(max_sock + 1, &tmp_wait_sockets, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, &tv);
189
190 if ( res > 0 ) {
191
192 /* new client */
193 if ( FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!( unix_if.unix_sock, &tmp_wait_sockets ) ) {
194
195 unix_client = debugMalloccxx . . $ debugMalloc(11d176b806cb4e70).( sizeof(struct unix_clientcxx . . $ unix_client#), 201 );
196 memsetcxx . . $ memset(d1de1e4fb215f1c6).( unix_client, 0, sizeof(struct unix_clientcxx . . $ unix_client#) );
197
198 if ( ( unix_client->sockcxx . . $ unix_client#sock. = acceptcxx . . $ accept(ff9054838cdf4227).( unix_ifcxx . . $ unix_if..unix_sockcxx . . $ unix_if#unix_sock., (struct sockaddrcxx . . $ sockaddr# *)&sun_addr, &sun_size) ) == -1 ) {
199 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - can't accept unix client: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) );
200 continue;
201 }
202
203 INIT_LIST_HEADcxx . . $ `list-batman.h:53:9`!( &unix_client->list );
204
205 FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!( unix_client->sock, &wait_sockets );
206 if ( unix_client->sockcxx . . $ unix_client#sock. > max_sock )
207 max_sock = unix_client->sockcxx . . $ unix_client#sock.;
208
209 /* make unix socket non blocking */
210 unix_opts = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).( unix_client->sockcxx . . $ unix_client#sock., F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0 );
211 fcntlcxx . . $ fcntl(cac4efb70f20a0fb).( unix_client->sockcxx . . $ unix_client#sock., F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, unix_opts | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`! );
212
213 list_add_tailcxx . . $ list_add_tail(c9932e5dfcae05fa).( &unix_client->listcxx . . $ unix_client#list., &unix_ifcxx . . $ unix_if..client_listcxx . . $ unix_if#client_list. );
214
215 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 3, "Unix socket: got connection\n" );
216
217 /* client sent data */
218 } else {
219
220 max_sock = unix_ifcxx . . $ unix_if..unix_sockcxx . . $ unix_if#unix_sock.;
221
222 prev_list_head_unix = (struct list_headcxx . . $ list_head# *)&unix_ifcxx . . $ unix_if..client_listcxx . . $ unix_if#client_list.;
223
224 list_for_each_safecxx . . $ `list-batman.h:85:9`!( list_pos, unix_pos_tmp, &unix_if.client_list ) {
225
226 unix_client = list_entrycxx . . $ `list-batman.h:67:9`!( list_pos, struct unix_client, list );
227
228 if ( FD_ISSETcxx . . $ `<external>/946878812840035423/select.h:87:9`!( unix_client->sock, &tmp_wait_sockets ) ) {
229
230 status = readcxx . . $ read(7e34d0a36f355389).( unix_client->sockcxx . . $ unix_client#sock., buff, sizeof( buff ) );
231
232 if ( status > 0 ) {
233
234 if ( unix_client->sockcxx . . $ unix_client#sock. > max_sock )
235 max_sock = unix_client->sockcxx . . $ unix_client#sock.;
236
237 /* debug_output( 3, "gateway: client sent data via unix socket: %s\n", buff ); */
238
239 if (buff[0] == 'a') {
240
241 if (status > 2) {
242 hna_local_task_add_strcxx . . $ hna_local_task_add_str(8a75a5628e33726e).(buff + 2, ROUTE_ADDcxx . . $ `batman.h:91:9`!, 1);
243 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., "EOD\n");
244 }
245
246 } else if (buff[0] == 'A') {
247
248 if (status > 2) {
249 hna_local_task_add_strcxx . . $ hna_local_task_add_str(8a75a5628e33726e).(buff + 2, ROUTE_DELcxx . . $ `batman.h:92:9`!, 1);
250 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., "EOD\n");
251 }
252
253 } else if ( buff[0] == 'd' ) {
254
255 if ( ( status > 2 ) && ( ( buff[2] > 0 ) && ( buff[2] <= debug_level_maxcxx . . $ debug_level_max. ) ) ) {
256
257 if ( unix_client->debug_levelcxx . . $ unix_client#debug_level. != 0 ) {
258
259 prev_list_head = (struct list_headcxx . . $ list_head# *)debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1];
260
261 if ( pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] ) != 0 )
262 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not lock mutex (unix_listen => 1): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
263
264 list_for_each_safecxx . . $ `list-batman.h:85:9`!( debug_pos, debug_pos_tmp, (struct list_head *)debug_clients.fd_list[unix_client->debug_level - 1] ) {
265
266 debug_level_info = list_entrycxx . . $ `list-batman.h:67:9`!( debug_pos, struct debug_level_info, list );
267
268 if ( debug_level_info->fdcxx . . $ debug_level_info#fd. == unix_client->sockcxx . . $ unix_client#sock. ) {
269
270 list_delcxx . . $ list_del(68233758eccab105).( prev_list_head, debug_pos, debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] );
271 debug_clientscxx . . $ debug_clients..clients_numcxx . . $ debug_clients#clients_num.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1]--;
272
273 debugFreecxx . . $ debugFree(d0320739773070f2).( debug_pos, 1201 );
274
275 break;
276
277 }
278
279 prev_list_head = &debug_level_info->listcxx . . $ debug_level_info#list.;
280
281 }
282
283 if ( pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] ) != 0 )
284 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not unlock mutex (unix_listen => 1): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
285
286 }
287
288 if ( unix_client->debug_levelcxx . . $ unix_client#debug_level. != buff[2] ) {
289
290 if ( pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[buff[2] - 1] ) != 0 )
291 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not lock mutex (unix_listen => 2): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
292
293 debug_level_info = debugMalloccxx . . $ debugMalloc(11d176b806cb4e70).( sizeof(struct debug_level_infocxx . . $ debug_level_info#), 202 );
294 INIT_LIST_HEADcxx . . $ `list-batman.h:53:9`!( &debug_level_info->list );
295 debug_level_info->fdcxx . . $ debug_level_info#fd. = unix_client->sockcxx . . $ unix_client#sock.;
296 list_addcxx . . $ list_add(c9932e5dfcae05fa).( &debug_level_info->listcxx . . $ debug_level_info#list., (struct list_head_firstcxx . . $ list_head_first# *)debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[buff[2] - 1] );
297 debug_clientscxx . . $ debug_clients..clients_numcxx . . $ debug_clients#clients_num.[buff[2] - 1]++;
298
299 unix_client->debug_levelcxx . . $ unix_client#debug_level. = buff[2];
300
301 if ( pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[buff[2] - 1] ) != 0 )
302 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not unlock mutex (unix_listen => 2): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
303
304 } else {
305
306 unix_client->debug_levelcxx . . $ unix_client#debug_level. = 0;
307
308 }
309
310 }
311
312 } else if ( buff[0] == 'i' ) {
313
314 internal_outputcxx . . $ internal_output(cb2f890c2fdad230).(unix_client->sockcxx . . $ unix_client#sock.);
315 dprintfcxx . . $ dprintf(811d273381043e7b).( unix_client->sockcxx . . $ unix_client#sock., "EOD\n" );
316
317 } else if ( buff[0] == 'g' ) {
318
319 if ( status > 2 ) {
320
321 if ((buff[2] == 0) || (probe_tuncxx . . $ probe_tun(bea2bd53c861b042).(0))) {
322
323 was_gateway = ( gateway_classcxx . . $ gateway_class. > 0 ? 1 : 0 );
324
325 gateway_classcxx . . $ gateway_class. = buff[2];
326 ((struct batman_ifcxx . . $ batman_if# *)if_listcxx . . $ if_list..nextcxx . . $ list_head_first#next.)->outcxx . . $ batman_if#out..gwflagscxx . . $ bat_packet#gwflags. = gateway_classcxx . . $ gateway_class.;
327
328 if ( ( gateway_classcxx . . $ gateway_class. > 0 ) && ( routing_classcxx . . $ routing_class. > 0 ) ) {
329
330 if ((routing_classcxx . . $ routing_class. != 0) && (curr_gatewaycxx . . $ curr_gateway. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!))
331 del_default_routecxx . . $ del_default_route(49f6e7a06ebc5aa8).();
332
333 add_del_interface_rulescxx . . $ add_del_interface_rules(8bcc8e5e37f2ab65).(RULE_DELcxx . . $ `batman.h:98:9`!);
334 routing_classcxx . . $ routing_class. = 0;
335
336 }
337
338 if ( ( !was_gateway ) && ( gateway_classcxx . . $ gateway_class. > 0 ) )
339 init_interface_gwcxx . . $ init_interface_gw(49f6e7a06ebc5aa8).();
340 else if ((was_gateway) && (gateway_classcxx . . $ gateway_class. == 0))
341 del_gw_interfacecxx . . $ del_gw_interface(49f6e7a06ebc5aa8).();
342 }
343
344 }
345
346 dprintfcxx . . $ dprintf(811d273381043e7b).( unix_client->sockcxx . . $ unix_client#sock., "EOD\n" );
347
348 } else if ( buff[0] == 'm' ) {
349
350 if ( status > 2 ) {
351 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).(3, "Unix socket: changing hop penalty points from: %i to: %i\n", hop_penaltycxx . . $ hop_penalty., buff[2]);
352 hop_penaltycxx . . $ hop_penalty. = buff[2];
353 }
354
355 dprintfcxx . . $ dprintf(811d273381043e7b).( unix_client->sockcxx . . $ unix_client#sock., "EOD\n" );
356
357 } else if ( buff[0] == 'q' ) {
358
359 if ( status > 2 ) {
360 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).(3, "Unix socket: changing purge timeout from: %i to: %li\n", purge_timeoutcxx . . $ purge_timeout., strtolcxx . . $ strtol(44bbb87609b212fc).(buff + 2, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 10));
361 purge_timeoutcxx . . $ purge_timeout. = strtolcxx . . $ strtol(44bbb87609b212fc).(buff + 2, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 10);
362 }
363
364 dprintfcxx . . $ dprintf(811d273381043e7b).( unix_client->sockcxx . . $ unix_client#sock., "EOD\n" );
365
366 } else if ( buff[0] == 'r' ) {
367
368 if ( status > 2 ) {
369
370 if ((buff[2] == 0) || (probe_tuncxx . . $ probe_tun(bea2bd53c861b042).(0))) {
371
372 tmp_unix_value = buff[2];
373
374 if ( ( tmp_unix_value >= 0 ) && ( tmp_unix_value <= 3 ) && (tmp_unix_value != routing_classcxx . . $ routing_class.) ) {
375
376 if ((routing_classcxx . . $ routing_class. != 0) && (curr_gatewaycxx . . $ curr_gateway. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!))
377 del_default_routecxx . . $ del_default_route(49f6e7a06ebc5aa8).();
378
379 if ( ( tmp_unix_value > 0 ) && ( gateway_classcxx . . $ gateway_class. > 0 ) ) {
380
381 gateway_classcxx . . $ gateway_class. = 0;
382 ((struct batman_ifcxx . . $ batman_if# *)if_listcxx . . $ if_list..nextcxx . . $ list_head_first#next.)->outcxx . . $ batman_if#out..gwflagscxx . . $ bat_packet#gwflags. = gateway_classcxx . . $ gateway_class.;
383 del_gw_interfacecxx . . $ del_gw_interface(49f6e7a06ebc5aa8).();
384
385 }
386
387 if ((tmp_unix_value > 0) && (routing_classcxx . . $ routing_class. == 0))
388 add_del_interface_rulescxx . . $ add_del_interface_rules(8bcc8e5e37f2ab65).(RULE_ADDcxx . . $ `batman.h:97:9`!);
389 else if ((tmp_unix_value == 0) && (routing_classcxx . . $ routing_class. > 0))
390 add_del_interface_rulescxx . . $ add_del_interface_rules(8bcc8e5e37f2ab65).(RULE_DELcxx . . $ `batman.h:98:9`!);
391
392 routing_classcxx . . $ routing_class. = tmp_unix_value;
393
394 }
395
396 }
397
398 }
399
400 dprintfcxx . . $ dprintf(811d273381043e7b).( unix_client->sockcxx . . $ unix_client#sock., "EOD\n" );
401
402 } else if ( buff[0] == 'p' ) {
403
404 if ( status > 2 ) {
405
406 if ( inet_ptoncxx . . $ inet_pton(8d303d671d73812).( AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, buff + 2, &tmp_ip_holder ) > 0 ) {
407
408 pref_gatewaycxx . . $ pref_gateway. = tmp_ip_holder.s_addrcxx . . $ in_addr#s_addr.;
409
410 if ( curr_gatewaycxx . . $ curr_gateway. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! )
411 del_default_routecxx . . $ del_default_route(49f6e7a06ebc5aa8).();
412
413 } else {
414
415 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 3, "Unix socket: rejected new preferred gw (%s) - invalid IP specified\n", buff + 2 );
416
417 }
418
419 }
420
421 dprintfcxx . . $ dprintf(811d273381043e7b).( unix_client->sockcxx . . $ unix_client#sock., "EOD\n" );
422
423 } else if (buff[0] == 'y') {
424
425 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., "%s", prog_namecxx . . $ prog_name.);
426
427 if (routing_classcxx . . $ routing_class. > 0)
428 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -r %i", routing_classcxx . . $ routing_class.);
429
430 if (pref_gatewaycxx . . $ pref_gateway. > 0) {
431
432 addr_to_stringcxx . . $ addr_to_string(9afcfc0fcf0b0c1d).( pref_gatewaycxx . . $ pref_gateway., str, sizeof (str) );
433
434 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -p %s", str);
435
436 }
437
438 if (gateway_classcxx . . $ gateway_class. > 0) {
439
440 get_gw_speedscxx . . $ get_gw_speeds(ba57c8ffa4804e83).(gateway_classcxx . . $ gateway_class., &download_speed, &upload_speed);
441
442 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -g %i%s/%i%s", (download_speed > 2048 ? download_speed / 1024 : download_speed), (download_speed > 2048 ? "MBit" : "KBit"), (upload_speed > 2048 ? upload_speed / 1024 : upload_speed), (upload_speed > 2048 ? "MBit" : "KBit"));
443
444 }
445
446 list_for_eachcxx . . $ `list-batman.h:75:9`!(debug_pos, &hna_list) {
447
448 hna_local_entry = list_entrycxx . . $ `list-batman.h:67:9`!(debug_pos, struct hna_local_entry, list);
449
450 addr_to_stringcxx . . $ addr_to_string(9afcfc0fcf0b0c1d).(hna_local_entry->addrcxx . . $ hna_local_entry#addr., str, sizeof (str));
451 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -a %s/%i", str, hna_local_entry->netmaskcxx . . $ hna_local_entry#netmask.);
452 }
453
454 if (debug_levelcxx . . $ debug_level. != 0)
455 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -d %i", debug_levelcxx . . $ debug_level.);
456
457 if (originator_intervalcxx . . $ originator_interval. != 1000)
458 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -o %i", originator_intervalcxx . . $ originator_interval.);
459
460 if (vis_ifcxx . . $ vis_if..sockcxx . . $ vis_if#sock.) {
461 addr_to_stringcxx . . $ addr_to_string(9afcfc0fcf0b0c1d).(vis_ifcxx . . $ vis_if..addrcxx . . $ vis_if#addr..sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr., str, sizeof(str));
462 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " -s %s", str);
463 }
464
465 if (policy_routing_scriptcxx . . $ policy_routing_script. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
466 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " --policy-routing-script %s", policy_routing_scriptcxx . . $ policy_routing_script.);
467
468 if (hop_penaltycxx . . $ hop_penalty. != TQ_HOP_PENALTYcxx . . $ `batman.h:80:9`!)
469 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " --hop-penalty %i", hop_penaltycxx . . $ hop_penalty.);
470
471 if (!aggregation_enabledcxx . . $ aggregation_enabled.)
472 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " --disable-aggregation");
473
474 if (purge_timeoutcxx . . $ purge_timeout. != PURGE_TIMEOUTcxx . . $ `batman.h:69:9`!)
475 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " --purge-timeout %u", purge_timeoutcxx . . $ purge_timeout.);
476
477 list_for_eachcxx . . $ `list-batman.h:75:9`!(debug_pos, &if_list) {
478
479 batman_if = list_entrycxx . . $ `list-batman.h:67:9`!(debug_pos, struct batman_if, list);
480
481 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., " %s", batman_if->devcxx . . $ batman_if#dev.);
482
483 }
484
485 dprintfcxx . . $ dprintf(811d273381043e7b).(unix_client->sockcxx . . $ unix_client#sock., "\nEOD\n");
486
487 }
488
489 prev_list_head_unix = &unix_client->listcxx . . $ unix_client#list.;
490
491 } else {
492
493 if ( status < 0 )
494 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - can't read unix message: %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) );
495
496 if ( unix_client->debug_levelcxx . . $ unix_client#debug_level. != 0 ) {
497
498 prev_list_head = (struct list_headcxx . . $ list_head# *)debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1];
499
500 if ( pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] ) != 0 )
501 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not lock mutex (unix_listen => 3): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
502
503 list_for_each_safecxx . . $ `list-batman.h:85:9`!( debug_pos, debug_pos_tmp, (struct list_head *)debug_clients.fd_list[unix_client->debug_level - 1] ) {
504
505 debug_level_info = list_entrycxx . . $ `list-batman.h:67:9`!( debug_pos, struct debug_level_info, list );
506
507 if ( debug_level_info->fdcxx . . $ debug_level_info#fd. == unix_client->sockcxx . . $ unix_client#sock. ) {
508
509 list_delcxx . . $ list_del(68233758eccab105).( prev_list_head, debug_pos, debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] );
510 debug_clientscxx . . $ debug_clients..clients_numcxx . . $ debug_clients#clients_num.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1]--;
511
512 debugFreecxx . . $ debugFree(d0320739773070f2).( debug_pos, 1202 );
513
514 break;
515
516 }
517
518 prev_list_head = &debug_level_info->listcxx . . $ debug_level_info#list.;
519
520 }
521
522 if ( pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] ) != 0 )
523 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not unlock mutex (unix_listen => 3): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
524
525 }
526
527 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 3, "Unix client closed connection ...\n" );
528
529 FD_CLRcxx . . $ `<external>/946878812840035423/select.h:86:9`!(unix_client->sock, &wait_sockets);
530 closecxx . . $ close(7864480464b09eea).( unix_client->sockcxx . . $ unix_client#sock. );
531
532 list_delcxx . . $ list_del(68233758eccab105).( prev_list_head_unix, list_pos, &unix_ifcxx . . $ unix_if..client_listcxx . . $ unix_if#client_list. );
533 debugFreecxx . . $ debugFree(d0320739773070f2).( list_pos, 1203 );
534
535 }
536
537 } else {
538
539 if ( unix_client->sockcxx . . $ unix_client#sock. > max_sock )
540 max_sock = unix_client->sockcxx . . $ unix_client#sock.;
541
542 }
543
544 }
545
546 }
547
548 } else if ((res < 0) && (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!)) {
549
550 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).(0, "Error - can't select (unix_listen): %s\n", strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
551 break;
552
553 }
554
555 }
556
557 list_for_each_safecxx . . $ `list-batman.h:85:9`!( list_pos, unix_pos_tmp, &unix_if.client_list ) {
558
559 unix_client = list_entrycxx . . $ `list-batman.h:67:9`!( list_pos, struct unix_client, list );
560
561 if ( unix_client->debug_levelcxx . . $ unix_client#debug_level. != 0 ) {
562
563 prev_list_head = (struct list_headcxx . . $ list_head# *)debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1];
564
565 if ( pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] ) != 0 )
566 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not lock mutex (unix_listen => 4): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
567
568 list_for_each_safecxx . . $ `list-batman.h:85:9`!( debug_pos, debug_pos_tmp, (struct list_head *)debug_clients.fd_list[unix_client->debug_level - 1] ) {
569
570 debug_level_info = list_entrycxx . . $ `list-batman.h:67:9`!(debug_pos, struct debug_level_info, list);
571
572 if ( debug_level_info->fdcxx . . $ debug_level_info#fd. == unix_client->sockcxx . . $ unix_client#sock. ) {
573
574 list_delcxx . . $ list_del(68233758eccab105).( prev_list_head, debug_pos, debug_clientscxx . . $ debug_clients..fd_listcxx . . $ debug_clients#fd_list.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] );
575 debug_clientscxx . . $ debug_clients..clients_numcxx . . $ debug_clients#clients_num.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1]--;
576
577 debugFreecxx . . $ debugFree(d0320739773070f2).( debug_pos, 1204 );
578
579 break;
580
581 }
582
583 prev_list_head = &debug_level_info->listcxx . . $ debug_level_info#list.;
584
585 }
586
587 if ( pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).( (pthread_mutex_tcxx . . $ pthread_mutex_t# *)debug_clientscxx . . $ debug_clients..mutexcxx . . $ debug_clients#mutex.[unix_client->debug_levelcxx . . $ unix_client#debug_level. - 1] ) != 0 )
588 debug_outputcxx . . $ debug_output(6b28886a2b5d9da9).( 0, "Error - could not unlock mutex (unix_listen => 4): %s \n", strerrorcxx . . $ strerror(ff224f080444ee45).( errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! ) );
589
590 }
591
592 list_delcxx . . $ list_del(68233758eccab105).( (struct list_headcxx . . $ list_head# *)&unix_ifcxx . . $ unix_if..client_listcxx . . $ unix_if#client_list., list_pos, &unix_ifcxx . . $ unix_if..client_listcxx . . $ unix_if#client_list. );
593 debugFreecxx . . $ debugFree(d0320739773070f2).( list_pos, 1205 );
594
595 }
596
597 return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
598
599 }
600