AirVantage / sbulb

UDP load balancer prototype using bcc (XDP/Bpf)
36 stars 9 forks source link

Add minimal log support #22

Closed sbernard31 closed 5 years ago

sbernard31 commented 5 years ago

This PR aims to implements #4. This differs a lot from what it was specify initialy. Finally there is 6 log levels :

CRITICAL => should never happened, ERROR => unexpected state, WARNING => unwanted traffic (invalid packet), INFO => not supported traffic (fragmented ip, ip option used), DEBUG => all about NAT, TRACE => all output we can.

A new CLI option is added :

 -l {CRITICAL,ERROR,WARNING,INFO,DEBUG,TRACE}, --loglevel {CRITICAL,ERROR,WARNING,INFO,DEBUG,TRACE}
                        Use to set logging verbosity.

The output looks like this :

Loading real servers from ulb.ini file ...
...real servers loaded : 10.0.0.1, 10.0.0.2, 10.0.0.3.

Compiling & attaching bpf code ...
... compilation and attachement succeed.

Applying config to bpf ...
Add 10.0.0.1 at index 0
Add 10.0.0.2 at index 1
Add 10.0.0.3 at index 2
[1]=10.0.0.2
[2]=10.0.0.3
[0]=10.0.0.1
[10.0.0.2]=10.0.0.2
[10.0.0.1]=10.0.0.1
[10.0.0.3]=10.0.0.3
... config applied to bpf.

Load balancing UDP traffic over lo interface for port(s) [5683] from :
 Virtual Server           Real Server(s) 
      127.0.0.1 <───┬───> 10.0.0.1       
                    ├───> 10.0.0.2       
                    └───> 10.0.0.3 

                                    ┌ 00:00:00:00:00:00/10.0.0.1        Source NAT
    00:00:00:00:00:00/10.41.44.15 <─┘ 00:00:00:00:00:00/127.0.0.1       (NEW ASSOCIATION)
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/10.41.44.15     Unhandled traffic
    00:00:00:00:00:00/10.41.44.15 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
      00:00:00:00:00:00/127.0.0.1 ─┐  00:00:00:00:00:00/127.0.0.1       Destination NAT
                                   └> 00:00:00:00:00:00/10.0.0.2        (NEW ASSOCIATION)
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/10.0.0.2        Unhandled traffic
      00:00:00:00:00:00/127.0.0.1 ─┐  00:00:00:00:00:00/127.0.0.1       Destination NAT
                                   └> 00:00:00:00:00:00/10.0.0.2        (REUSED ASSOCIATION)
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/10.0.0.2        Unhandled traffic
                                    ┌ 00:00:00:00:00:00/10.0.0.1        Source NAT
    00:00:00:00:00:00/10.41.44.15 <─┘ 00:00:00:00:00:00/127.0.0.1       (REUSED ASSOCIATION)
      00:00:00:00:00:00/127.0.0.1 <─> 00:00:00:00:00:00/10.41.44.15     Unhandled traffic
    00:00:00:00:00:00/10.41.44.15 <─> 00:00:00:00:00:00/127.0.0.1       Not UDP packet
    00:00:00:00:00:00/10.41.44.15 <── 00:00:00:00:00:00/10.0.0.2        Not associated real server
    00:00:00:00:00:00/10.41.44.15 <── 00:00:00:00:00:00/10.0.0.2        Not associated real server

Stopping by signal SIGINT(2)...
Detaching bpf code ...
... code detached.
... sbulb stopped.

Of course more could/should? be done : #21