~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/net/UnixNetPages.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
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
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
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.
 
22
 */
 
23
 
 
24
#include "libts.h"
 
25
 
 
26
#ifdef NON_MODULAR
 
27
 
 
28
#include "P_Net.h"
 
29
#include "Show.h"
 
30
 
 
31
struct ShowNet;
 
32
typedef int (ShowNet::*ShowNetEventHandler) (int event, Event * data);
 
33
struct ShowNet: public ShowCont
 
34
{
 
35
  int ithread;
 
36
  int port;
 
37
  unsigned int ip;
 
38
 
 
39
  int showMain(int event, Event * e)
 
40
  {
 
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"
 
47
                    "</form>\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);
 
52
  }
 
53
 
 
54
  int showConnectionsOnThread(int event, Event * e)
 
55
  {
 
56
    EThread *ethread = e->ethread;
 
57
    NetHandler *nh = get_NetHandler(ethread);
 
58
    MUTEX_TRY_LOCK(lock, nh->mutex, ethread);
 
59
    if (!lock) {
 
60
      ethread->schedule_in(this, NET_RETRY_DELAY);
 
61
      return EVENT_DONE;
 
62
    }
 
63
 
 
64
    ink_hrtime now = ink_get_hrtime();
 
65
    forl_LL(UnixNetVConnection, vc, nh->open_list) {
 
66
      if (ip && ip != vc->ip)
 
67
        continue;
 
68
      if (port && port != vc->port && port != vc->accept_port)
 
69
        continue;
 
70
      char ipbuf[80];
 
71
      snprintf(ipbuf, sizeof(ipbuf), "%hhu.%hhu.%hhu.%hhu", PRINT_IP(vc->ip));
 
72
      char interbuf[80];
 
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
 
77
                      "<td>%d</td>"     // port
 
78
                      "<td>%d</td>"     // fd
 
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,
 
94
                      ipbuf,
 
95
                      vc->port,
 
96
                      vc->con.fd,
 
97
                      interbuf,
 
98
                      vc->accept_port,
 
99
                      (int) ((now - vc->submit_time) / HRTIME_SECOND),
 
100
                      ethread->id,
 
101
                      vc->read.enabled,
 
102
                      vc->read.vio.nbytes,
 
103
                      vc->read.vio.ndone,
 
104
                      vc->write.enabled,
 
105
                      vc->write.vio.nbytes,
 
106
                      vc->write.vio.ndone,
 
107
                      (int) (vc->inactivity_timeout_in / HRTIME_SECOND),
 
108
                      (int) (vc->active_timeout_in / HRTIME_SECOND), vc->f.shutdown, vc->closed ? "closed " : ""));
 
109
    }
 
110
    ithread++;
 
111
    if (ithread < eventProcessor.n_threads_for_type[ET_NET])
 
112
      eventProcessor.eventthread[ET_NET][ithread]->schedule_imm(this);
 
113
    else {
 
114
      CHECK_SHOW(show("</table>\n"));
 
115
      return complete(event, e);
 
116
    }
 
117
    return EVENT_CONT;
 
118
  }
 
119
 
 
120
  int showConnections(int event, Event * e)
 
121
  {
 
122
    CHECK_SHOW(begin("Net Connections"));
 
123
    CHECK_SHOW(show("<H3>Connections</H3>\n"
 
124
                    "<table border=1><tr>"
 
125
                    "<th>ID</th>"
 
126
                    "<th>IP</th>"
 
127
                    "<th>Port</th>"
 
128
                    "<th>FD</th>"
 
129
                    "<th>Interface</th>"
 
130
                    "<th>Accept Port</th>"
 
131
                    "<th>Time Started</th>"
 
132
                    "<th>Thread</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);
 
145
    return EVENT_CONT;
 
146
  }
 
147
 
 
148
  int showSingleThread(int event, Event * e)
 
149
  {
 
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);
 
154
    if (!lock) {
 
155
      ethread->schedule_in(this, NET_RETRY_DELAY);
 
156
      return EVENT_DONE;
 
157
    }
 
158
 
 
159
    CHECK_SHOW(show("<H3>Thread: %d</H3>\n", ithread));
 
160
    CHECK_SHOW(show("<table border=1>\n"));
 
161
    int connections = 0;
 
162
    forl_LL(UnixNetVConnection, vc, nh->open_list)
 
163
      connections++;
 
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"));
 
169
    CHECK_SHOW(show
 
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"));
 
172
    ithread++;
 
173
    if (ithread < eventProcessor.n_threads_for_type[ET_NET])
 
174
      eventProcessor.eventthread[ET_NET][ithread]->schedule_imm(this);
 
175
    else
 
176
      return complete(event, e);
 
177
    return EVENT_CONT;
 
178
  }
 
179
 
 
180
  int showThreads(int event, Event * e)
 
181
  {
 
182
    CHECK_SHOW(begin("Net Threads"));
 
183
    SET_HANDLER(&ShowNet::showSingleThread);
 
184
    eventProcessor.eventthread[ET_NET][0]->schedule_imm(this);
 
185
    return EVENT_CONT;
 
186
  }
 
187
  int showSingleConnection(int event, Event * e)
 
188
  {
 
189
    CHECK_SHOW(begin("Net Connection"));
 
190
    return complete(event, e);
 
191
  }
 
192
  int showHostnames(int event, Event * e)
 
193
  {
 
194
    CHECK_SHOW(begin("Net Connections to/from Host"));
 
195
    return complete(event, e);
 
196
  }
 
197
 
 
198
ShowNet(Continuation * c, HTTPHdr * h):
 
199
  ShowCont(c, h), ithread(0), port(0), ip(0) {
 
200
    SET_HANDLER(&ShowNet::showMain);
 
201
  }
 
202
};
 
203
 
 
204
#undef STREQ_PREFIX
 
205
#define STREQ_PREFIX(_x,_n,_s) (!ptr_len_ncasecmp(_x,_n,_s,sizeof(_s)-1))
 
206
Action *
 
207
register_ShowNet(Continuation * c, HTTPHdr * h)
 
208
{
 
209
  ShowNet *s = NEW(new ShowNet(c, h));
 
210
  int path_len;
 
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")) {
 
218
    int query_len;
 
219
    const char *query = h->url_get()->query_get(&query_len);
 
220
    s->sarg = xstrndup(query, query_len);
 
221
    char *gn = NULL;
 
222
    if (s->sarg)
 
223
      gn = (char *) ink_memchr(s->sarg, '=', strlen(s->sarg));
 
224
    if (gn)
 
225
      s->ip = ink_inet_addr(gn + 1);
 
226
    SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
 
227
  } else if (STREQ_PREFIX(path, path_len, "ports")) {
 
228
    int query_len;
 
229
    const char *query = h->url_get()->query_get(&query_len);
 
230
    s->sarg = xstrndup(query, query_len);
 
231
    char *gn = NULL;
 
232
    if (s->sarg)
 
233
      gn = (char *) ink_memchr(s->sarg, '=', strlen(s->sarg));
 
234
    if (gn)
 
235
      s->port = atoi(gn + 1);
 
236
    SET_CONTINUATION_HANDLER(s, &ShowNet::showConnections);
 
237
  }
 
238
  eventProcessor.schedule_imm(s, ET_NET);
 
239
  return &s->action;
 
240
}
 
241
 
 
242
#endif