3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
32
typedef int (ShowNet::*ShowNetEventHandler) (int event, Event * data);
33
struct ShowNet: public ShowCont
39
int showMain(int event, Event * e)
41
CHECK_SHOW(begin("Net"));
42
CHECK_SHOW(show("<H3>Show <A HREF=\"./connections\">Connections</A></H3>\n"
43
"<H3>Show <A HREF=\"./threads\">Net Threads</A></H3>\n"
44
"<form method = GET action = \"./ips\">\n"
45
"Show Connections to/from IP (e.g. 127.0.0.1):<br>\n"
46
"<input type=text name=ip size=64 maxlength=256>\n"
48
"<form method = GET action = \"./ports\">\n"
49
"Show Connections to/from Port (e.g. 80):<br>\n"
50
"<input type=text name=name size=64 maxlength=256>\n" "</form>\n"));
51
return complete(event, e);
54
int showConnectionsOnThread(int event, Event * e)
56
EThread *ethread = e->ethread;
57
NetHandler *nh = get_NetHandler(ethread);
58
MUTEX_TRY_LOCK(lock, nh->mutex, ethread);
60
ethread->schedule_in(this, NET_RETRY_DELAY);
64
ink_hrtime now = ink_get_hrtime();
65
forl_LL(UnixNetVConnection, vc, nh->open_list) {
66
if (ip && ip != vc->ip)
68
if (port && port != vc->port && port != vc->accept_port)
71
snprintf(ipbuf, sizeof(ipbuf), "%hhu.%hhu.%hhu.%hhu", PRINT_IP(vc->ip));
73
snprintf(interbuf, sizeof(interbuf), "[%s] %hhu.%hhu.%hhu.%hhu", vc->options.toString(vc->options.addr_binding), PRINT_IP(vc->options.local_addr));
74
CHECK_SHOW(show("<tr>"
75
// "<td><a href=\"/connection/%d\">%d</a></td>"
76
"<td>%d</td>" "<td>%s</td>" // ipbuf
79
"<td>%s</td>" // interbuf
80
"<td>%d</td>" // accept port
81
"<td>%d secs ago</td>" // start time
82
"<td>%d</td>" // thread id
83
"<td>%d</td>" // read enabled
84
"<td>%d</td>" // read NBytes
85
"<td>%d</td>" // read NDone
86
"<td>%d</td>" // write enabled
87
"<td>%d</td>" // write nbytes
88
"<td>%d</td>" // write ndone
89
"<td>%d secs</td>" // Inactivity timeout at
90
"<td>%d secs</td>" // Activity timeout at
91
"<td>%d</td>" // shutdown
92
"<td>-%s</td>" // comments
93
"</tr>\n", vc->id, // vc->id,
99
(int) ((now - vc->submit_time) / HRTIME_SECOND),
105
vc->write.vio.nbytes,
107
(int) (vc->inactivity_timeout_in / HRTIME_SECOND),
108
(int) (vc->active_timeout_in / HRTIME_SECOND), vc->f.shutdown, vc->closed ? "closed " : ""));
111
if (ithread < eventProcessor.n_threads_for_type[ET_NET])
112
eventProcessor.eventthread[ET_NET][ithread]->schedule_imm(this);
114
CHECK_SHOW(show("</table>\n"));
115
return complete(event, e);
120
int showConnections(int event, Event * e)
122
CHECK_SHOW(begin("Net Connections"));
123
CHECK_SHOW(show("<H3>Connections</H3>\n"
124
"<table border=1><tr>"
130
"<th>Accept Port</th>"
131
"<th>Time Started</th>"
133
"<th>Read Enabled</th>"
134
"<th>Read Priority</th>"
135
"<th>Read NBytes</th>"
136
"<th>Read NDone</th>"
137
"<th>Write Enabled</th>"
138
"<th>Write Priority</th>"
139
"<th>Write NBytes</th>"
140
"<th>Write NDone</th>"
141
"<th>Inactive Timeout</th>"
142
"<th>Active Timeout</th>" "<th>Shutdown</th>" "<th>Comments</th>" "</tr>\n"));
143
SET_HANDLER(&ShowNet::showConnectionsOnThread);
144
eventProcessor.eventthread[ET_NET][0]->schedule_imm(this);
148
int showSingleThread(int event, Event * e)
150
EThread *ethread = e->ethread;
151
NetHandler *nh = get_NetHandler(ethread);
152
PollDescriptor *pollDescriptor = get_PollDescriptor(ethread);
153
MUTEX_TRY_LOCK(lock, nh->mutex, ethread);
155
ethread->schedule_in(this, NET_RETRY_DELAY);
159
CHECK_SHOW(show("<H3>Thread: %d</H3>\n", ithread));
160
CHECK_SHOW(show("<table border=1>\n"));
162
forl_LL(UnixNetVConnection, vc, nh->open_list)
164
CHECK_SHOW(show("<tr><td>%s</td><td>%d</td></tr>\n", "Connections", connections));
165
//CHECK_SHOW(show("<tr><td>%s</td><td>%d</td></tr>\n", "Last Poll Size", pollDescriptor->nfds));
166
CHECK_SHOW(show("<tr><td>%s</td><td>%d</td></tr>\n", "Last Poll Ready", pollDescriptor->result));
167
CHECK_SHOW(show("</table>\n"));
168
CHECK_SHOW(show("<table border=1>\n"));
170
("<tr><th>#</th><th>Read Priority</th><th>Read Bucket</th><th>Write Priority</th><th>Write Bucket</th></tr>\n"));
171
CHECK_SHOW(show("</table>\n"));
173
if (ithread < eventProcessor.n_threads_for_type[ET_NET])
174
eventProcessor.eventthread[ET_NET][ithread]->schedule_imm(this);
176
return complete(event, e);
180
int showThreads(int event, Event * e)
182
CHECK_SHOW(begin("Net Threads"));
183
SET_HANDLER(&ShowNet::showSingleThread);
184
eventProcessor.eventthread[ET_NET][0]->schedule_imm(this);
187
int showSingleConnection(int event, Event * e)
189
CHECK_SHOW(begin("Net Connection"));
190
return complete(event, e);
192
int showHostnames(int event, Event * e)
194
CHECK_SHOW(begin("Net Connections to/from Host"));
195
return complete(event, e);
198
ShowNet(Continuation * c, HTTPHdr * h):
199
ShowCont(c, h), ithread(0), port(0), ip(0) {
200
SET_HANDLER(&ShowNet::showMain);
205
#define STREQ_PREFIX(_x,_n,_s) (!ptr_len_ncasecmp(_x,_n,_s,sizeof(_s)-1))
207
register_ShowNet(Continuation * c, HTTPHdr * h)
209
ShowNet *s = NEW(new ShowNet(c, h));
211
const char *path = h->url_get()->path_get(&path_len);
212
SET_CONTINUATION_HANDLER(s, &ShowNet::showMain);
213
if (STREQ_PREFIX(path, path_len, "connections")) {
214
SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
215
} else if (STREQ_PREFIX(path, path_len, "threads")) {
216
SET_CONTINUATION_HANDLER(s, &ShowNet::showThreads);
217
} else if (STREQ_PREFIX(path, path_len, "ips")) {
219
const char *query = h->url_get()->query_get(&query_len);
220
s->sarg = xstrndup(query, query_len);
223
gn = (char *) ink_memchr(s->sarg, '=', strlen(s->sarg));
225
s->ip = ink_inet_addr(gn + 1);
226
SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
227
} else if (STREQ_PREFIX(path, path_len, "ports")) {
229
const char *query = h->url_get()->query_get(&query_len);
230
s->sarg = xstrndup(query, query_len);
233
gn = (char *) ink_memchr(s->sarg, '=', strlen(s->sarg));
235
s->port = atoi(gn + 1);
236
SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
238
eventProcessor.schedule_imm(s, ET_NET);