Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/man5/tinyproxy.conf.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ This allows you to specify which address Tinyproxy will bind
to for outgoing connections.
This parameter may be specified multiple times, then Tinyproxy
will try all the specified addresses in order.
When SO_BINDTODEVICE present, this parameter allows interface
names.

=item B<BindSame>

Expand Down
2 changes: 1 addition & 1 deletion etc/tinyproxy.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Port 8888
# Bind: This allows you to specify which interface will be used for
# outgoing connections. This is useful for multi-home'd machines where
# you want all traffic to appear outgoing from one particular interface.
#
# This allows using the name of an interface, useful for tun devices.
#Bind 192.168.0.1

#
Expand Down
6 changes: 5 additions & 1 deletion src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ struct {
handle_allow),
STDCONF (deny, "(" "(" IPMASK "|" IPV6MASK ")" "|" ALNUM ")",
handle_deny),
STDCONF (bind, "(" IP "|" IPV6 ")", handle_bind),
STDCONF (bind, "(" IP "|" IPV6
#ifdef SO_BINDTODEVICE
"|" INTERFACE
#endif
")", handle_bind),
/* other */
STDCONF (basicauth, USERNAME WS PASSWORD, handle_basicauth),
STDCONF (errorfile, INT WS STR, handle_errorfile),
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ display_usage (void)
printf (" Upstream proxy support\n");
features++;
#endif /* UPSTREAM_SUPPORT */
#ifdef SO_BINDTODEVICE
printf (" BindToDevice\n");
features++;
#endif

if (0 == features)
printf (" None\n");
Expand Down
5 changes: 2 additions & 3 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ ssize_t readline (int fd, char **whole_buffer)
struct read_lines_s *first_line, *line_ptr;

first_line =
(struct read_lines_s *) safecalloc (sizeof (struct read_lines_s),
1);
(struct read_lines_s *) safecalloc (1, sizeof (struct read_lines_s));
if (!first_line)
return -ENOMEM;

Expand Down Expand Up @@ -206,7 +205,7 @@ ssize_t readline (int fd, char **whole_buffer)

line_ptr->next =
(struct read_lines_s *)
safecalloc (sizeof (struct read_lines_s), 1);
safecalloc (1, sizeof (struct read_lines_s));
if (!line_ptr->next) {
ret = -ENOMEM;
goto CLEANUP;
Expand Down
17 changes: 17 additions & 0 deletions src/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ bind_socket (int sockfd, const char *addr, int family)
assert (sockfd >= 0);
assert (addr != NULL && strlen (addr) != 0);

#ifdef SO_BINDTODEVICE
if (addr && if_nametoindex(addr)) {
struct ifreq interface = {};

strcpy(interface.ifr_name, addr);
n = setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
&interface, sizeof(interface));
if (n < 0) {
log_message (LOG_INFO,
"bind_socket: SO_BINDTODEVICE to %s %s",
addr, get_gai_error (n));
return n;
}
return sockfd;
}
#endif

memset (&hints, 0, sizeof (struct addrinfo));
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
Expand Down