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

Implement passthrough mod #2

Merged
merged 32 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8e9ef2c
passthrough implementation
bparli Jan 14, 2019
67fa75e
connection tracker size
bparli Jan 19, 2019
0821472
backend failures and RST replies
bparli Jan 21, 2019
4906fc5
fix update status bug
bparli Jan 23, 2019
72711a0
update stats page
bparli Jan 24, 2019
e4519d4
limit conn tracker lock
bparli Jan 25, 2019
ce96344
perf and dsr
bparli Jan 27, 2019
bfe5d2a
use multiple transmitters
bparli Jan 27, 2019
aed1ec8
test perf improvements
bparli Jan 27, 2019
83f788c
dsr testing
bparli Jan 30, 2019
a19074b
use to_owned for ethernetpacket
bparli Jan 30, 2019
f648537
update stats counters only every so often
bparli Jan 31, 2019
0fd1168
add unit tests passthrough backend
bparli Feb 1, 2019
bae92d5
add tx thread and channel
bparli Feb 2, 2019
ef6275a
unit tests and re-use tcp_header
bparli Feb 4, 2019
4c4d9a3
unit tests
bparli Feb 4, 2019
898334f
unit tests
bparli Feb 5, 2019
473499d
re-use tcp packet
bparli Feb 5, 2019
47efd00
perf tweaks
bparli Feb 6, 2019
141aa29
perf tweaks
bparli Feb 6, 2019
4818f5f
perf tweaks
bparli Feb 6, 2019
fe6c394
some clean up
bparli Feb 6, 2019
af8cb38
make port mapper a rw lock
bparli Feb 6, 2019
6fd7f22
improve health checking
bparli Feb 7, 2019
d78a16c
more perf tweaking
bparli Feb 8, 2019
87739c4
fix tests
bparli Feb 8, 2019
cf39025
bump version
bparli Feb 8, 2019
036c8f5
fix cmd line opts
bparli Feb 8, 2019
84bf410
Update README.md
bparli Feb 8, 2019
4d66145
update samples
bparli Feb 8, 2019
0c96373
update readme with samples
bparli Feb 8, 2019
394cc18
extra spaces
bparli Feb 8, 2019
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
Prev Previous commit
Next Next commit
dsr testing
  • Loading branch information
bparli committed Jan 30, 2019
commit 83f788c8d4fbf372337b95c6f7f5170134f26442
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,20 @@ Options:

### Passthrough mode

`sudo iptables -t raw -A PREROUTING -p tcp --sport 8080 --dport 32768:61000 -j DROP`
`sudo iptables -A OUTPUT -p tcp --tcp-flags RST RST --dport 8000:8090 -j DROP`
```
For passthrough and dsr
sudo iptables -t raw -A PREROUTING -p tcp --sport 8080 --dport 32768:61000 -j DROP

Only for passthrough
sudo iptables -A OUTPUT -p tcp --tcp-flags RST RST --dport 8000:8090 -j DROP

Required on backend servers for dsr to work
sudo tc qdisc add dev enp0s8 root handle 10: htb

sudo tc filter add dev enp0s8 parent 10: protocol ip prio 1 u32 match ip src 192.168.1.117 match ip sport 3000 0xffff match ip dst 192.168.1.136 action ok

sudo tc filter add dev enp0s8 parent 10: protocol ip prio 10 u32 match ip src 192.168.1.117 match ip sport 3000 0xffff action nat egress 192.168.1.117 192.168.1.136
```

<!-- references -->
[tokio]: https://tokio.rs
24 changes: 16 additions & 8 deletions src/passthrough/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ impl LB {

match tx.send_to(new_ipv4, client_addr.ip()) {
Ok(n) => {
debug!("Sent {} bytes to Client", n);
// update stats connections
let mut mssg = StatsMssg{frontend: Some(self.name.clone()),
backend: self.backend.name.clone(),
Expand Down Expand Up @@ -311,14 +312,16 @@ impl LB {
IpAddr::V4(node_ipv4) => {
let fwd_ipv4 = node_ipv4.clone();
if self.backend.get_server_health(conn.backend_srv.clone()) {
new_tcp.set_destination(conn.backend_srv.port);

// leave original tcp source if dsr
if !self.dsr {
new_tcp.set_source(conn.ephem_port);
new_tcp.set_checksum(tcp::ipv4_checksum(&new_tcp.to_immutable(), &self.listen_ip, &fwd_ipv4));
} else {
new_tcp.set_checksum(tcp::ipv4_checksum(&new_tcp.to_immutable(), &ip_header.get_source(), &fwd_ipv4));
}

new_tcp.set_destination(conn.backend_srv.port);
new_tcp.set_checksum(tcp::ipv4_checksum(&new_tcp.to_immutable(), &self.listen_ip, &fwd_ipv4));

new_ipv4.set_payload(&new_tcp.packet());
new_ipv4.set_destination(fwd_ipv4);
new_ipv4.set_checksum(checksum(&new_ipv4.to_immutable()));
Expand Down Expand Up @@ -362,6 +365,7 @@ impl LB {
match node.host {
IpAddr::V4(node_ipv4) => {
let fwd_ipv4 = node_ipv4.clone();
new_tcp.set_destination(node.port);

// leave original tcp source if dsr
let mut ephem_port = 0 as u16;
Expand All @@ -373,11 +377,11 @@ impl LB {
self.port_mapper.lock().unwrap().insert(ephem_port, Client{ip: IpAddr::V4(ip_header.get_source()), port: tcp_header.get_source()});
}
new_tcp.set_source(ephem_port);
new_tcp.set_checksum(tcp::ipv4_checksum(&new_tcp.to_immutable(), &self.listen_ip, &fwd_ipv4));
} else {
new_tcp.set_checksum(tcp::ipv4_checksum(&new_tcp.to_immutable(), &ip_header.get_source(), &fwd_ipv4));
}

new_tcp.set_destination(node.port);
new_tcp.set_checksum(tcp::ipv4_checksum(&new_tcp.to_immutable(), &self.listen_ip, &fwd_ipv4));

new_ipv4.set_payload(&new_tcp.packet());
new_ipv4.set_destination(fwd_ipv4);
new_ipv4.set_checksum(checksum(&new_ipv4.to_immutable()));
Expand Down Expand Up @@ -434,9 +438,13 @@ impl LB {
Ok(n) => debug!("Sent {} bytes to Client", n),
Err(e) => error!("failed to send packet: {}", e),
}
let mut connections = 0;
if !self.dsr {
connections = -1;
}
let mssg = StatsMssg{frontend: Some(self.name.clone()),
backend: self.backend.name.clone(),
connections: -1,
connections: connections,
bytes_tx: 0,
bytes_rx: 0,
servers: None};
Expand Down Expand Up @@ -480,7 +488,7 @@ fn process_packets(lb: &mut LB, rx: crossbeam_channel::Receiver<EthernetPacket>,
loop {
match rx.recv() {
Ok(ethernet) => {
match Ipv4Packet::new(ethernet.payload()) {
match Ipv4Packet::owned(ethernet.payload().iter().cloned().collect()) {
Some(ip_header) => {
let ip_addr = ip_header.get_destination();
if ip_addr == lb.listen_ip {
Expand Down