Reputation: 13
this year i'll start my final undegraduate project, basically i'll implement a simple server-based load balancer for Linux. The intention is to make it application independent (Web server, FTP server, Email Server, etc) at OSI Layer 4 (TCP). The load balancer needs to listen all ports and forward the packages to the configured real servers, to his respective requested port (following an algorithm like round-robin).
Another intention is to make this Load Balancer as a Kernel Module (Like LVS, a native load balancer for Linux), and make another user-space administrative application to make configuration.
But i'm with a lot of doubts,
The only way to do this load balancer this is with a Kernel Module? It can't be only an user-space program?
It can't be at Layer 3 (IP)? Where I acess it the IP packets and process all the logic?
Please, help me with these doubts, it's important to guide me in the start of the project.
Upvotes: 0
Views: 981
Reputation: 1137
I'll be quite technical as you are talking about implementing a kernel module. You said "forward the packages" at TCP layer. But then you said "listen to all ports and forward the packages". So in order to implement this first you need to know the differences:
"forward the packages" At TCP level, means that the Linux should be able to intercept and forward packages (basically doing NAT) and the only way to accomplish this is using the netfilters just like iptables
and LVS does (it doesn't listen to any port). iptables
is an application that allows you to configure the tables provided by the Linux kernel firewall, which uses the netfilter's hooks. So, yes, it can't be a user-space program unless you mean a front-end that uses iptables
for configuring NAT, but I don't think this is the point.
"listen to all ports and forward the packages" means that your load balancer will work at Application Layer 4 and probably what you want is a TCP Proxy. TCP Proxy applications runs on user-space and you can implement it to listen to a set of ports, then forward what comes in/back to/from another, like HAProxy and Balance.
Balance is very simple and open source so it is a good start point.
The l3dsr and lnlb are good references too.
Besides layer 4 and layer 7, there are network load balance at layer 2 (link aggregation, port aggregation, etherchannel or gigabit etherchannel port bundling), and layer 3 like Cisco Express Forwarding
EDIT: Nftables works different. nftables
is the userspace part of a new general-purpose in-kernel packet classification engine. "nftables
adds a simple virtual machine into the Linux kernel, which is able inspect a network packet and make decisions on how that packet should be handled".
Upvotes: 0