-
-
Notifications
You must be signed in to change notification settings - Fork 249
proxy experiments
svinota edited this page Sep 4, 2014
·
1 revision
iproute2 call:
[root@localhost iproute2-2.6.31]# strace -f -e trace=socket,bind,connect -s 4096 -x ./ip/ip ad show
socket(PF_FILE, SOCK_DGRAM, 0) = 3
bind(3, {sa_family=AF_FILE, path="/tmp/cl"}, 110) = 0
connect(3, {sa_family=AF_FILE, path="/tmp/rtnl_proxy"}, 110) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc htb state UP qlen 1000
link/ether 52:54:00:91:f7:e6 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.60/24 brd 192.168.122.255 scope global eth0
inet6 fe80::5054:ff:fe91:f7e6/64 scope link
valid_lft forever preferred_lft forever
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN
link/ether 0e:8b:ac:29:58:ca brd ff:ff:ff:ff:ff:ff
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
4: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
quick'n'dirty proxy code:
import socket
import select
from pyroute2.netlink.rtnl import RtnlSocket
client = b'/tmp/cl'
server = b'/tmp/rtnl_proxy'
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM, 0)
s.bind(server)
r = RtnlSocket()
poll = select.epoll()
poll.register(s.fileno(), select.EPOLLIN)
poll.register(r.fileno(), select.EPOLLIN)
poll.register(r.bypass.fileno(), select.EPOLLIN)
connected = False
while True:
fds = poll.poll()
for (fd, event) in fds:
if fd == s.fileno():
print("got data from client")
data = s.recv(16384)
r.sendto(data, (0, 0))
elif fd == r.fileno():
print("got data from proxy")
data = r.recv(16384)
if not connected:
s.connect(client)
connected = True
s.sendto(data, client)
else:
print("got data from netlink")
data = r.get(r.bypass, 16384)
if not connected:
s.connect(client)
connected = True
s.sendto(data, client)