chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.72k stars 1.19k forks source link

IP_TRANSPARENT socket option #1490

Closed gunzino closed 2 weeks ago

gunzino commented 2 weeks ago

Hello,

I'm working on adding transparent proxying support to our application based on Boost ASIO. To achieve this, Linux supports IP_TRANSPARENT socket option (option number 19). Based on docs, there is no current support for this in ASIO. Can you recommend some workaround (maybe using SettableSocketOption?) or are you planning to add this in the future?

Inspiration from this repo: https://github.com/cloudflare/mmproxy/

EDIT: Found inspiration in tcp_delay code which makes it clear how to implement this.

#include <sys/socket.h>
typedef boost::asio::detail::socket_option::boolean<IPPROTO_IP, IP_TRANSPARENT> ip_transparent_option;
typedef boost::asio::detail::socket_option::boolean<IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT> ip_bind_address_no_port_option;
typedef boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_MARK> ip_mark_option;