1 /*
2  * Copyright (c) 2013, 2014
3  *      Inferno Nettverk A/S, Norway.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. The above copyright notice, this list of conditions and the following
9  *    disclaimer must appear in all copies of the software, derivative works
10  *    or modified versions, and any portions thereof, aswell as in all
11  *    supporting documentation.
12  * 2. All advertising materials mentioning features or use of this software
13  *    must display the following acknowledgement:
14  *      This product includes software developed by
15  *      Inferno Nettverk A/S, Norway.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Inferno Nettverk A/S requests users of this software to return to
31  *
32  *  Software Distribution Coordinator  or  sdc@inet.no
33  *  Inferno Nettverk A/S
34  *  Oslo Research Park
35  *  Gaustadall�en 21
36  *  NO-0349 Oslo
37  *  Norway
38  *
39  * any improvements or extensions that they make and grant Inferno Nettverk A/S
40  * the rights to redistribute these changes.
41  */
42 
43 #include "common.h"
44 
45 static const char rcsid[] =
46 "$Id: fmt_customer.c,v 1.13.4.1 2014/08/15 18:16:40 karls Exp $";
47 
48 /*
49  * Nothing here should be changed without regression-testing against
50  * the appropriate customer-test.
51  */
52 
53 void
log_connectfailed(side,dststr)54 log_connectfailed(side, dststr)
55    const interfaceside_t side;
56    const char *dststr;
57 {
58    const char *function = "log_connectfailed()";
59    const int ll = loglevel_errno(errno, side);
60 
61    if (ERRNOISNOROUTE(errno))
62       slog(ll, "no route to %s: %s", dststr, strerror(errno));
63    else if (errno == EINPROGRESS)
64       slog(ll, "connect to host %s is now in progress", dststr);
65    else
66       slog(ll, "connect to host %s failed: %s", dststr, strerror(errno));
67 }
68 
69 void
log_writefailed(side,s,dst)70 log_writefailed(side, s, dst)
71    const interfaceside_t side;
72    const int s;
73    const struct sockaddr_storage *dst;
74 {
75    const int ll = loglevel_errno(errno, side);
76    const int errno_s = errno;
77    char dststr[MAXSOCKADDRSTRING];
78 
79    if (dst != NULL)
80       sockaddr2string(dst, dststr, sizeof(dststr));
81    else {
82       struct sockaddr_storage p;
83       socklen_t len;
84 
85       len = sizeof(p);
86       if (getpeername(s, TOSA(&p), &len) == -1)
87          snprintf(dststr, sizeof(dststr), "N/A");
88       else
89          sockaddr2string(&p, dststr, sizeof(dststr));
90    }
91 
92    errno = errno_s;
93 
94    if (ERRNOISNOROUTE(errno))
95       slog(ll, "no route to %s: %s", dststr, strerror(errno));
96    else
97       slog(ll, "send to host %s failed: %s", dststr, strerror(errno));
98 }
99 
100 void
log_resolvefailed(hostname,side,gaierr)101 log_resolvefailed(hostname, side, gaierr)
102    const char *hostname;
103    const interfaceside_t side;
104    const int gaierr;
105 {
106    const int ll = loglevel_gaierr(gaierr, side);
107    char visbuf[MAXHOSTNAMELEN * 4];
108 
109    slog(ll, "could not DNS-resolve \"%s\": %s",
110         str2vis(hostname, strlen(hostname), visbuf, sizeof(visbuf)),
111         gaierr == EAI_SYSTEM ? strerror(errno) : gai_strerror(gaierr));
112 }
113 
114 void
log_reversemapfailed(addr,side,gaierr)115 log_reversemapfailed(addr, side, gaierr)
116    const struct sockaddr_storage *addr;
117    const interfaceside_t side;
118    const int gaierr;
119 {
120    const int ll = loglevel_gaierr(gaierr, side);
121    char addrstring[256];
122 
123    switch (socks_inet_pton(addr->ss_family,
124                            GET_SOCKADDRADDR(addr),
125                            addrstring,
126                            NULL)) {
127       case 1:
128          break;
129 
130       case 0:
131          STRCPY_ASSERTSIZE(addrstring, "<nonsense address>");
132          break;
133 
134       case -1:
135       default:
136          strncpy(addrstring, strerror(errno), sizeof(addrstring) - 1);
137          addrstring[sizeof(addrstring) - 1] = NUL;
138          break;
139    }
140 
141    slog(ll, "could not DNS reversemap address %s: %s",
142         addrstring,
143         gaierr == EAI_SYSTEM ? strerror(errno) : gai_strerror(gaierr));
144 }
145 
146 #if !SOCKS_CLIENT
147 
148 void
log_clientdropped(client)149 log_clientdropped(client)
150    const struct sockaddr_storage *client;
151 {
152 
153    slog(LOG_WARNING, "new client from %s dropped: no resources",
154         sockaddr2string(client, NULL, 0));
155 }
156 
157 void
log_addchild_failed(void)158 log_addchild_failed(void)
159 {
160 
161    slog(LOG_WARNING, "failed to add a new child to handle new clients");
162 }
163 
164 #endif /* !SOCKS_CLIENT */
165