Raizo62 / vwifi

Simulator of WiFi (802.11) interfaces to communicate between several Virtual Machines
GNU Lesser General Public License v3.0
57 stars 8 forks source link

New svm_flags property of the sockaddr_vm structure #6

Closed maxstarkov closed 1 year ago

maxstarkov commented 2 years ago

On 5.10.133-1-MANJARO, the code compiles, but the vwifi-server does not start. When starting the server, an EINVAL error appears. I figured out that the error occurs on the AF_VSOCK socket bind operation. The /usr/include/linux/vm_sockets.h file contains another definition of the sockaddr_vm structure. In this definition, the structure has the svm_flags property. I fixed the source code, compiled the project and the server started working, but the client part in the Ubuntu 20.04 virtual machine stopped working. The client must use the old version of the sockaddr_vm structure. Maybe it is possible to provide different sockaddr_vm structures in the source code?

Raizo62 commented 2 years ago

Hi

In Manjaro, what is the package who contains the file /usr/include/linux/vm_sockets.h and what is his number of version ?

Could you copy here your patch to fixe the source code ?

Could a "#define" in "config.h" be a good solution?

maxstarkov commented 2 years ago

Hi. The file belongs to the package:

pacman -F /usr/include/linux/vm_sockets.h
usr/include/linux/vm_sockets.h is owned by core/linux-api-headers 5.17.5-2

I made the following changes to the source code:

diff --git a/src/cselect.cc b/src/cselect.cc
index e8cb253..108ad25 100644
--- a/src/cselect.cc
+++ b/src/cselect.cc
@@ -1,5 +1,6 @@
 #include <errno.h> // errno
 #include <assert.h> // assert
+#include <cstddef> // NULL

 #include "cselect.h"

diff --git a/src/csocketclientvtcp.cc b/src/csocketclientvtcp.cc
index 910975e..f0cb40e 100644
--- a/src/csocketclientvtcp.cc
+++ b/src/csocketclientvtcp.cc
@@ -20,7 +20,7 @@ CSocketClientVTCP::CSocketClientVTCP() : CSocketClient()
 void CSocketClientVTCP::Init(TPort port)
 {
        Server.svm_family = AF_VSOCK;
-       Server.svm_reserved1 = 0;
+       Server.svm_flags = 0;
        Server.svm_port = port;
        Server.svm_cid = 2;
 }
diff --git a/src/csocketserverfunctionvtcp.cc b/src/csocketserverfunctionvtcp.cc
index 521811c..f359254 100644
--- a/src/csocketserverfunctionvtcp.cc
+++ b/src/csocketserverfunctionvtcp.cc
@@ -39,7 +39,7 @@ bool CSocketServerFunctionVTCP::_Listen(TDescriptor& master, TPort port)
        //type of socket created
        struct sockaddr_vm address;
        address.svm_family = AF_VSOCK;
-       address.svm_reserved1 = 0;
+       address.svm_flags = 0;
        address.svm_port = port;
        address.svm_cid = VMADDR_CID_ANY;
        memset(address.svm_zero, 0, sizeof(address.svm_zero));

Yes, "#define" would be a good solution.

Raizo62 commented 2 years ago

I believe that the problem comes from Ubuntu 20.04 which is a little too old. The last stable Debian has also the flag "svm_flags"

Could you test the branch svm_flags ? His code is more generic.

Raizo62 commented 2 years ago

I optimized the svm_flags branch a bit. If you can test too. Thanks.

maxstarkov commented 2 years ago

I tested the fixes in the source code. When building the project in Manjaro, I had to make corrections to the file src/cselect.cc:

src/cselect.cc: In member function ‘TDescriptor CSelect::Wait()’:
src/cselect.cc:69:21: error: ‘NULL’ was not declared in this scope
   69 |         return Wait(NULL);
      |                     ^~~~
src/cselect.cc:5:1: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
    4 | #include "cselect.h"
  +++ |+#include <cstddef>
    5 | 
src/cselect.cc: In member function ‘TDescriptor CSelect::Wait(const sigset_t*)’:
src/cselect.cc:79:58: error: ‘NULL’ was not declared in this scope
   79 |         int activity=pselect( MaxDescriptor + 1 , &Dup , NULL , NULL , NULL, sigmask);
      |                                                          ^~~~
src/cselect.cc:79:58: note: ‘NULL’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
make: *** [Makefile:51: obj/cselect.o] Error 1

I added a line of code #include <cstddef> to the file and the project was built successfully. On Ubuntu, the project is built without any errors and additional fixes.

But the client built on Manjaro doesn't work on Ubuntu:

vagrant@ubuntu2004:~$ sudo ./vwifi-client 
./vwifi-client: /lib/x86_64-linux-gnu/libnl-genl-3.so.200: no version information available (required by ./vwifi-client)
./vwifi-client: /lib/x86_64-linux-gnu/libnl-3.so.200: no version information available (required by ./vwifi-client)
./vwifi-client: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by ./vwifi-client)
./vwifi-client: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./vwifi-client)
./vwifi-client: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ./vwifi-client)
./vwifi-client: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by ./vwifi-client)
./vwifi-client: /lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.13' not found (required by ./vwifi-client)

This problem is solved by building the client in the Ubuntu virtual machine.

As a result, I successfully launched the project components - the server on Manjaro and the client on Ubuntu.

Thanks!

Raizo62 commented 2 years ago

(sorry i was offline for 1 week)

In the Makefile, if you add -static in the variable MODE, could you build in MANJARO and use it in Ubuntu ? I have tested in a docker image of MANJARO but i have this error :

/usr/bin/ld: cannot find -lnl-genl-3: No such file or directory
/usr/bin/ld: cannot find -lnl-3: No such file or directory
maxstarkov commented 2 years ago

It seems that the problem is in Manjaro. It is based on Arch Linux, but static linking is not supported there ("It is generally Arch policy to not ship static libraries as it is considered bad practice" - https://bugs.archlinux.org/task/35257).

I will try to build a project with static linking in Ubuntu to use binaries in Manjaro.

Raizo62 commented 2 years ago

To help, i added in Makefile the keywords dyn/static to change the state dynamic/static

Raizo62 commented 1 year ago

Thanks for your help :-)