troglobit / smcroute

Static multicast routing for UNIX
https://troglobit.com/projects/smcroute/
GNU General Public License v2.0
244 stars 63 forks source link

IPC: daemon: add batch-mode support #185

Closed alexeys85 closed 2 years ago

alexeys85 commented 2 years ago

Add support to read multiple commands from client and invoke them. Example of possible (but not yet implemented) usage of smcroutectl:

smcroutectl --batch - << EOF join eth0 225.1.2.3 add eth0 192.168.1.42 225.1.2.3 eth1 eth2 rem eth1 225.3.4.5 eth3 leave eth1 225.3.4.5 EOF

Signed-off-by: Alexey Smirnov s.alexey@gmail.com

troglobit commented 2 years ago

Before you force-pushed the follow-up changes, the tests passed. Now they no longer pass, you'll have to look into why your PR introduces a regression.

Other than that it looks good in general. Some minor coding style issues, but those I can fix up myself later. Only caveat I have is that I'd like ipc_receive() to return -1 instead of 0 on error, as we talked about earlier, i.e., change to ssize_t return type and fix the behavior of the callee. Returning zero is fine on timeout when the client disconnects.

alexeys85 commented 2 years ago

Before force-push PR wasn't quite complete and didn't support receiving arbitrary number of commands. ipc_receive() should fixed now! Failed CI tests run fine locally, weird...

alexeys85 commented 2 years ago

By the way, locally test gre.sh was skipped:

>> Checking dependencies ...                                                       
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:    22.04
Codename:   jammy
Linux scuderia-pc 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
>> TEST: SKIP                                                                      
grep -q ip_gre /proc/modules is not supported on this system.

SKIP gre.sh (exit status: 77)

However, after modprobe ip_gre:

enzo@scuderia-pc:~$ grep ip_gre /proc/modules
ip_gre 28672 0 - Live 0x0000000000000000
ip_tunnel 32768 1 ip_gre, Live 0x0000000000000000
gre 16384 1 ip_gre, Live 0x0000000000000000

enzo@scuderia-pc:~$ lsmod | grep gre
ip_gre                 28672  0
ip_tunnel              32768  1 ip_gre
gre                    16384  1 ip_gre
troglobit commented 2 years ago

There's some memory corruption being introduced. See near the end of the last run:

 >> Phase 3: Join group from multiple sources (IPC)                                 
malloc(): unsorted double linked list corrupted

Re: GRE. Yeah, I've set up my tests using unshare so it's possible to do networking ops unprivileged. The gre.sh test however cannot load a module, that has to be done by the real root of the system, hence it's set to go to SKIP (not FAIL) if the kernel doesn't support IP-GRE.

alexeys85 commented 2 years ago

In last force-push I got rid of malloc usage but seems still no go, same as broken pipe errors :(

However locally I have: ```bash enzo@scuderia-pc:/media/enzo/Data/work/workspace/smcroute$ make check Making check in man make[1]: Entering directory '/media/enzo/Data/work/workspace/smcroute/man' make[1]: Nothing to be done for 'check'. make[1]: Leaving directory '/media/enzo/Data/work/workspace/smcroute/man' Making check in src make[1]: Entering directory '/media/enzo/Data/work/workspace/smcroute/src' make[1]: Nothing to be done for 'check'. make[1]: Leaving directory '/media/enzo/Data/work/workspace/smcroute/src' Making check in test make[1]: Entering directory '/media/enzo/Data/work/workspace/smcroute/test' make check-TESTS make[2]: Entering directory '/media/enzo/Data/work/workspace/smcroute/test' make[3]: Entering directory '/media/enzo/Data/work/workspace/smcroute/test' PASS: expire.sh PASS: adv.sh PASS: basic.sh PASS: bridge.sh PASS: dyn.sh PASS: gre.sh PASS: include.sh PASS: ipv6.sh PASS: isolated.sh PASS: join.sh PASS: joinlen.sh PASS: lost.sh PASS: mem.sh PASS: mrcache.sh PASS: mrcache6.sh PASS: mrdisc.sh PASS: multi.sh PASS: poison.sh PASS: reload.sh PASS: reload6.sh PASS: vlan.sh PASS: vrfy.sh ============================================================================ Testsuite summary for SMCRoute 2.5.5 ============================================================================ # TOTAL: 22 # PASS: 22 # SKIP: 0 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============================================================================ make[3]: Leaving directory '/media/enzo/Data/work/workspace/smcroute/test' make[2]: Leaving directory '/media/enzo/Data/work/workspace/smcroute/test' make[1]: Leaving directory '/media/enzo/Data/work/workspace/smcroute/test' make[1]: Entering directory '/media/enzo/Data/work/workspace/smcroute' make[1]: Leaving directory '/media/enzo/Data/work/workspace/smcroute' ```
alexeys85 commented 2 years ago

Should be good now!

troglobit commented 2 years ago

Looks much better, thank you for hanging in there! :smiley::+1:

I'll do a deep review of the changes probably sometime tomorrow morning (CET). But I don't expect anything major to pop up at this stage.

troglobit commented 2 years ago

Merged this morning. Now, before the next release it'd be great to have support for

$ smcroutectl --batch - << EOF
...
EOF

And a tiny little test to verify the same.

alexeys85 commented 2 years ago

Hop to get to it soon!

troglobit commented 2 years ago

Cool thanks! I created a couple of issues to track it so we don't forget.