Code Monkey home page Code Monkey logo

udpproxy's Introduction

udpproxy

udpproxy is a Server Type plugin for Caddy https://caddyserver.com, it is modified from https://github.com/pieterlouw/caddy-net by @pieterlouw.

It proxies UDP traffic to a specified destination, and listen the reply on multiple addresses (defined via the reply-addr-alias directive in Caddyfile).

It helps in the situation when a service replies via a different interface (and probably with a different source IP address) than where it receives the request from, mostly in a multi-homed environment like what is described here https://lists.zx2c4.com/pipermail/wireguard/2017-November/002016.html

SO_REUSEADDR and SO_REUSEPORT are used when creating connections. Multiple connections are created with all possible IP addresses defined in the Caddyfile which the service will use to reply. And these connections are all binded to the same local IP address and port opened when the request first gets forwarded to the destination. By doing this we can catch the reply from the service even it has been sent via a different interface (and a different source IP address).

Build with Caddy

Follow the guide here https://github.com/caddyserver/caddy/wiki/Plugging-in-Plugins-Yourself

The line to be added to run.go in the import section is

_ "github.com/def1oyd/udpproxy"

Example

Suppose

  • The service recives requests at 10.0.0.254:12345
  • 10.0.0.254 is a VIP, floating between 10.0.0.252 and 10.0.0.253
  • The service is not able to use the VIP to send reply since it lacks capability of interface binding
  • The reply may come from 10.0.0.252 or 10.0.0.253

The Caddyfile will look like

proxy :12345 10.0.0.254:12345 {
    reply-addr-alias 10.0.0.253:12345 10.0.0.252:12345
}

Then start caddy with the following command

$ caddy -type=udpproxy

References

  1. https://lists.zx2c4.com/pipermail/wireguard/2017-November/002016.html
  2. https://utcc.utoronto.ca/~cks/space/blog/linux/WireGuardEarlyNotes
  3. https://blog.kechako.com/entry/create-udp-conn-each-client

udpproxy's People

Contributors

fltd avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.