Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to bind littleproxy to a specific interface? #135

Closed
PatrickHuetter opened this issue Feb 22, 2014 · 30 comments
Closed

Is it possible to bind littleproxy to a specific interface? #135

PatrickHuetter opened this issue Feb 22, 2014 · 30 comments

Comments

@PatrickHuetter
Copy link

I have two or more physical network interfaces, connected to the internet and i would like to create a proxy for each of them. Is this possible with littleproxy? (using linux)

@oxtoacart
Copy link
Collaborator

Yes, just use bootstrap.withAddress() to specify the address of whatever interface you want to use.

@PatrickHuetter
Copy link
Author

@oxtoacart The documentation says that this method binds for incoming connections, but i want to bind for outgoing connections. I have two modems connection with pppd to the internet. My ifconfig says that i have two network interfaces then: ppp0 and ppp1. I would like to setup or decide within the proxy wich connection should be used for outgoing access (to the internet). Is this possible?

For example like in tinyproxy:
http://ie.archive.ubuntu.com/disk1/disk1/download.sourceforge.net/pub/sourceforge/k/project/ko/kosubuntu/CONF%20FILES/tinyproxy.conf

#
# 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.
#
#Bind 192.168.0.1

If it's possible or a feature you plan, it would be fine to also bind by network interface name and not only by ip-address.

@oxtoacart oxtoacart reopened this Feb 22, 2014
@oxtoacart
Copy link
Collaborator

Ahh, sorry, I misunderstood.

We already have a facility for doing this when using a chained proxy. It should be possible to add some configurability (perhaps through the HttpFilters abstraction) to support your use case.

https://github.com/adamfisk/LittleProxy/blob/master/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java#L671

https://github.com/adamfisk/LittleProxy/blob/master/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java#L543

Do you have any interest in giving it a shot?

@PatrickHuetter
Copy link
Author

I'm not so familiar with LittleProxy yet. So i have to create a chained proxy and configure it via HttpFilters abstraction? Or do i have to change littleproxy project code?

@oxtoacart
Copy link
Collaborator

You'll need to take a look at the LittleProxy source code.

I just added a new HostResolver abstraction per bug #136. You might be able to change that to return both the remote address as well as a local listen address, and then use that here.

@PatrickHuetter
Copy link
Author

If i understand right: I have to change the return type of the resolve method to return two objects (local and remote)

return new InetSocketAddress(addr, port);

and then use the connect() method with both parameters to connect with the given interface?
I already have littleProxy in my IDE working and only have to understand the code.

@oxtoacart
Copy link
Collaborator

Yes, you've got it! Alternately, you could provide an additional method on
HostResolver like (getLocalAddress) which would typically return null but
you could use to return whatever local address you want.

Cheers,
Ox


"I love people who harness themselves, an ox to a heavy cart,
who pull like water buffalo, with massive patience,
who strain in the mud and the muck to move things forward,
who do what has to be done, again and again."

  • Marge Piercy

On Sat, Feb 22, 2014 at 10:56 AM, Patrick Hütter
notifications@github.comwrote:

If i understand right: I have to change the return type of the resolve
method to return two objects (local and remote)

return new InetSocketAddress(addr, port);

and then use the connect() method with both parameters to connect with the
given interface?
I already have littleProxy in my IDE working and only have to understand
the code.

Reply to this email directly or view it on GitHubhttps://github.com//issues/135#issuecomment-35807568
.

@PatrickHuetter
Copy link
Author

@oxtoacart Why do i have to use ProxyToServerConnection.java ? I already created the getLocalAddress method. Is this correct? PatrickHuetter@e0416a5

My further temptations failed because of Gateway errors (Bad Gateway). This is my code: https://github.com/PatrickHuetter/LittleProxy

@oxtoacart
Copy link
Collaborator

Yes, you've added the getLocalAddress() method to HostResolver, but now LittleProxy needs to actually use that method to get the local address. The current localAddress in ProxyToServerConnection is only populated if you're using a ChainedProxy. You need to populate it from your HostResolver.

See here

Regarding the bad gateway problem - if you create a unit test reproducing the issue, I'd be happy to take a look.

@PatrickHuetter
Copy link
Author

@oxtoacart I did this without using ChainedProxy (i think). I added it to the else-part:
https://github.com/PatrickHuetter/LittleProxy/blob/master/src/main/java/org/littleshoot/proxy/impl/ProxyToServerConnection.java#L680

Using your ChainedProxyWithoutFallbackTest seems to work partly until getting Bad Gateway as response for some requests of the unit test.

I hardcoded the interface name and port here (for first tests):
https://github.com/PatrickHuetter/LittleProxy/blob/master/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java#L237

bildschirmfoto 2014-03-06 um 18 42 01

For your interest: I have to choose the second element of the inetAddress collection in DefaultHostResolver.getLocalAddress(), because the first one is IPv6 on Mac OS X.

@oxtoacart
Copy link
Collaborator

@PatrickHuetter - seems like a good approach. If you pull request this (preferably with a unit test), I'd love to get it merged into LittleProxy.

@PatrickHuetter
Copy link
Author

@oxtoacart Unfortunately I couldn't get it working. So there is nothing to merge this time.

@jibijose
Copy link

jibijose commented May 8, 2014

oxtocart. Any progress on this? I badly need this. Is there any other software that supports this?

@oxtoacart
Copy link
Collaborator

@jibijose You could try looking at @PatrickHuetter's attempt and see if you can get it to work.

@jibijose
Copy link

jibijose commented May 8, 2014

http://docs.oracle.com/javase/tutorial/networking/nifs/definition.html
This is java api doc for that. For me it would take more time as I am not familiar with its design and coding.

@PatrickHuetter
Copy link
Author

@oxtoacart Maybe we could donate to you, if you would take some time to build this feature :-)
I also would send you some german beers ;)

@jibijose
Copy link

jibijose commented May 9, 2014

I succeeded :-) If I let you know changes, can you check it in?
Below is how it is tested. Started proxy with NIC1, hit "whatismyipaddress.com" and saw IP1, then restarted with another NIC2 and saw IP2.

@PatrickHuetter
Copy link
Author

@jibijose You can create a pull-request to this repository, so @oxtoacart can merge it into the main branch. I'm very happy that you succeeded and i'll test it as soon as i can! :-) Could you push it into a repository on github?

@oxtoacart
Copy link
Collaborator

That's great news! I'm looking forward to integrating a pull request for
this.

Cheers,
Ox


"I love people who harness themselves, an ox to a heavy cart,
who pull like water buffalo, with massive patience,
who strain in the mud and the muck to move things forward,
who do what has to be done, again and again."

  • Marge Piercy

On Fri, May 9, 2014 at 6:11 AM, Patrick Hütter notifications@github.comwrote:

@jibijose https://github.com/jibijose You can create a pull-request to
this repository, so @oxtoacart https://github.com/oxtoacart can merge
it into the main branch. I'm very happy that you succeeded and i'll test it
as soon as i can! :-) Could you push it into a repository on github?


Reply to this email directly or view it on GitHubhttps://github.com//issues/135#issuecomment-42655363
.

@PatrickHuetter
Copy link
Author

@jibijose Could you please create a pull request for this ? :-)

@PatrickHuetter
Copy link
Author

@jibijose Are you going to create a pull request for this?

@jibijose
Copy link

Back after long vacation. Tied up with few stuff. Will surely get this done. Please give me some time.

@PatrickHuetter
Copy link
Author

Hi @jibijose, this sounds great! I hope to hear from you soon :-)

@PatrickHuetter
Copy link
Author

@jibijose Are there some news on this?

@PatrickHuetter
Copy link
Author

@jibijose Please create a pull request for this feature...you would help me a lot!

@jibijose
Copy link

New to GIT. Tried few softwares with help of my team mate. Could you summarize steps involved in pull and checkin?

@PatrickHuetter
Copy link
Author

@jibijose You have to "fork" this project with the fork button at the top right at this page. After that you've to clone your forked repository. Than you make your changes in your cloned project. When you're ready you do a git commit. Example in terminal: git commit -m "added feature issue #135 interface binding"
After you did your commit, you've to push your changes to the github server with git push origin master. Now you've pushed your changes to your fork repository in your account. Using the webinterface of github you're able to create a pull-request to the main repository (this one).

It's also possible using the terminal but using the webinterface is more easy. If you've problems i'll help you, just send me a message. You could also send me your project as zip archive and i'll create a pull request for you.

@jibijose
Copy link

Done. Please check. Read comments properly.

@PatrickHuetter
Copy link
Author

@jibijose I'll check it out. Could you please send me your e-mail address or contact me by email? I would like to stay in contact with you. I think i have the same setup like you.

@jekh
Copy link
Collaborator

jekh commented May 25, 2015

Since this feature was implemented by PR #172, I'll go ahead and close it. I've been successfully using this feature for some time. Thanks for reporting it, and thanks to everyone who implemented it!

@jekh jekh closed this as completed May 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants