summaryrefslogtreecommitdiffhomepage
path: root/src/sock.c
AgeCommit message (Collapse)Author
2020-01-15access config via a pointer, not a hardcoded struct addressrofl0r
this is required so we can elegantly swap out an old config for a new one in the future and remove lots of boilerplate from config initialization code. unfortunately this is a quite intrusive change as the config struct was accessed in numerous places, but frankly it should have been done via a pointer right from the start. right now, we simply point to a static struct in main.c, so there shouldn't be any noticeable changes in behaviour.
2019-12-21implement detection and denial of endless connection loopsrofl0r
it is quite easy to bring down a proxy server by forcing it to make connections to one of its own ports, because this will result in an endless loop spawning more and more connections, until all available fds are exhausted. since there's a potentially infinite number of potential DNS/ip addresses resolving to the proxy, it is impossible to detect an endless loop by simply looking at the destination ip address and port. what *is* possible though is to record the ip/port tuples assigned to outgoing connections, and then compare them against new incoming connections. if they match, the sender was the proxy itself and therefore needs to reject that connection. fixes #199.
2019-12-21do hostname resolution only when it is absolutely necessary for ACL checkrofl0r
tinyproxy used to do a full hostname resolution whenever a new client connection happened, which could cause very long delays (as reported in #198). there's only a single place/scenario that actually requires a hostname, and that is when an Allow/Deny rule exists for a hostname or domain, rather than a raw IP address. since it is very likely this feature is not very widely used, it makes absolute sense to only do the costly resolution when it is unavoidable.
2019-11-27Use gai_strerror() to report errors of getaddrinfo() and getnameinfo()Martin Kutschker
2013-11-16sock: add debug messages to opensock()Michael Adam
log entering opensock and successful return of getaddrinfo. This allows to detect dns timeouts from looking at the logs. Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09[BB#81] allow listening on multiple families when no Listen is provided in ↵Michael Adam
config This is achieved by not stopping at the first result of getaddrinfo that we managed to listen on: Without "Listen" in the config, we call getraddrinfo with NULL address. With AI_PASSIVE, this gives results for both IPv4 and IPv6 wildcard addresses (if both are supported). This lets tinyproxy listen on both IPv4 and IPv6 wildcard if the system supports them. Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: add a starting debug message to listen_sock()Michael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: update introductory comment for listen_sock()Michael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: set IPV6_V6ONLY on the socket before binding an IPv6 addressMichael Adam
so that we can bind wildcard for both IPv4 and IPv6. Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: factor listening on one socket out of the gai-result-loop in listen_sock()Michael Adam
for clarity of the code Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: in listen_sock(), move variable for setsockopt() into scopeMichael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: log each result of getaddrinfo() in listen_sock()Michael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: in listen_sock(), add a log message for when bind() has failedMichael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: in listen_sock(), detect and log failure to call setsockopt()Michael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: in listen_sock(), add debug message when socket() call failed.Michael Adam
Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: move listen() into the getaddrinfo result loop in listen_sock()Michael Adam
This also reverses the exit logic of the loop. It prepares listening on multiple addresses. Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09child: use a list of listen_fds instead of one single listenfd.Michael Adam
This prepares listenting on multiple sockets, which will be ussed to fix listening on the wildcard (listen on both ipv6 and ipv4) and help add the support for multiple Listen statements in the config Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock: add addr argument to listen_sock()Michael Adam
instead of using config.ipAddr internally. This is in preparation to make it possible to call it for multiple addresses. Signed-off-by: Michael Adam <obnox@samba.org>
2013-11-09sock/child: remove global variable addrlen.Michael Adam
This changes listen_sock() to not return the addrlen of the used address from getaddrinfo call to the caller, stored in global addrlen in child.c. This was only used to be able to allocate enough space for the arguments to the later accept call depending on whether IPv4 or IPv6 is used. This removes the need to pass this info by always allocating sizeof(struct sockaddr_storage) instead, which is enough to carry both sockaddr_in and sockaddr_in6. Signed-off-by: Michael Adam <obnox@samba.org>
2010-03-09Revert "Revert "Pass address family when binding to outgoing socket""Mukund Sivaraman
This reverts commit 70885bf029a6f857684f99618f867b5c47767ae0. It looks like bug #69 needs this fix after all.
2010-03-03Use AI_PASSIVE flag to make tinyproxy listen on wildcard interfaceMukund Sivaraman
Signed-off-by: Michael Adam <obnox@samba.org>
2010-01-21Revert "Pass address family when binding to outgoing socket"Mukund Sivaraman
This reverts commit 65ef313cc4601b5ad84d1da1800ff38bf8f046a9. This patch could've been the reason for BB#69.
2010-01-10Pass address family when binding to outgoing socketMukund Sivaraman
2009-12-08Fix restarting of tinyproxy: call setsockopt with REUSEADDR _before_ calling ↵Michael Adam
bind Somehow this got moved too far down in the ipv6 changes. Thanks to Mathew Mrosko for helping me debugging this. Michael
2009-12-07Move definition of "struct config_s" from main.h to conf.hMichael Adam
Michael
2009-11-17Use snprintf() with size of the portstr bufMukund Sivaraman
2009-11-09Close listenfd upon errorsMukund Sivaraman
2009-11-09Add IPV6 support to listen_sock()Mukund Sivaraman
2009-09-15Indent code to Tinyproxy coding styleMukund Sivaraman
The modified files were indented with GNU indent using the following command: indent -npro -kr -i8 -ts8 -sob -l80 -ss -cs -cp1 -bs -nlps -nprs -pcs \ -saf -sai -saw -sc -cdw -ce -nut -il0 No other changes of any sort were made.
2009-08-07Rename tinyproxy.[ch] to main.[ch]Mukund Sivaraman
2008-12-08Convert tabs to spacesMukund Sivaraman
2008-12-01Reformat code to GNU coding styleMukund Sivaraman
This is a commit which simply ran all C source code files through GNU indent. No other modifications were made.
2008-05-24Updated copyright, license notices in source codeMukund Sivaraman
The notices have been changed to a more GNU look. Documentation comments have been separated from the copyright header. I've tried to keep all copyright notices intact. Some author contact details have been updated.
2008-03-13Corrected datatype of salen to fix compiler warningMukund Sivaraman
2005-08-15* [Indent] Ran Source Through indentRobert James Kaes
I re-indented the source code using indent with the following options: indent -kr -bad -bap -nut -i8 -l80 -psl -sob -ss -ncs There are now _no_ tabs in the source files, and all indentation is eight spaces. Lines are 80 characters long, and the procedure type is on it's own line. Read the indent manual for more information about what each option means.
2005-07-12* Specified Correct typedef in getsock_ip()Robert James Kaes
Changed the variable type for the namelen variable to the correct socklen_t type. The configure script already checked for it, but for some reason I never got around to actually using it in this function.
2004-04-27Added the "BindSame" configure directive from Oswald Buddenhagen.Robert James Kaes
This allows tinyproxy to respond to a request bound to the same interface that the request came in on. As Oswald explains: "attached is a patch that adds the BindSame option. it causes binding an outgoing connection to the ip address of the respective incoming connection. that way one can simulate an entire proxy farm with a single instance of tinyproxy on a multi-homed machine." Cool.
2004-02-18Converted the various socket functions to work with both IPv4 and IPv6Robert James Kaes
addresses.
2002-10-03#Style formatting change.Robert James Kaes
2002-05-31(getpeer_information): Fixed a problem retrieving the FQDN of a host because ↵Robert James Kaes
I was passing in an incorrect parameter to gethostbyaddr(). D'oh.
2002-05-27(opensock): Changed a comment around to better state what the code is ↵Robert James Kaes
actually doing.
2002-05-26Removed the DNS API calls and replaced them with the standardRobert James Kaes
gethostbyname() and gethostbyaddr() functions. This is possible because tinyproxy now uses a standard pre-forked() method.
2002-05-24Fixed some spelling mistakes, and removed the getpeer_ip() andRobert James Kaes
getpeer_string() functions as they've been replaced by the getpeer_information() function.
2002-05-23Changed the lookup_domain() function to use the new "dnsserver" API.Robert James Kaes
Also moved safe_write(), safe_read(), readline(), and write_message() functions into their own file.
2002-04-24bind_address has been moved inside the config structure. Fixed up aRobert James Kaes
problem where "data" was being freed even if it had not been allocated (because of an error condition.)
2002-04-22The "Bind" directive sets a binding address which the outgoing connectionsRobert James Kaes
will use.
2002-04-18Whoops. The previous include only had the code conditionally removed.Robert James Kaes
Remove for real this time.
2002-04-18Removed the call to inet_aton() since the gethostbyname() function handlesRobert James Kaes
the dotted-decimal case itself.
2002-04-18Removed the call to hstrerror() in the getpeer_string() function. It'sRobert James Kaes
not available on all machines.
2002-04-17Removed the LOOKUP_LOCK() and LOOKUP_UNLOCK() macros since I believe IRobert James Kaes
need locking around both gethostbyname() and gethostbyaddr() at the same time.