Menu

#118 user-mode networking using SLiRP as a backend

Unstable_(example)
pending
None
5
2014-10-27
2013-06-27
No

Hi,

I managed to implement my taprouter software into DOSemu (taprouter is my standalone project: http://www.viste-family.net/mateusz/software/taprouter )

It means that it's possible for users to get an internet connectivity
inside DOSemu that 'just works', without needing to play with bridges,
routing, nat, etc etc etc, and without having to run anything with root
privileges.

The only required actions are:

  • having the slirp binary installed somewhere in the system
  • changing the dosemu configuration file

The DOSemu configuration file would need to be changed as follows:

$_vnet = "slirp"
$_netdev = "/usr/bin/slirp"

How does it work?

when the $_vnet="slirp" backend is used, DOSemu calls my
librouter_init() function, that creates a unix socket pair, and forks
itself. Since then, DOSemu uses a 'normal' dgram socket to tunnel
ethernet-level communications, thus from the DOSemu point of view, it's
almost identical to using a tun interface.
the librouter code handles all the ARP-level connectivity, DHCP requests
interception, SLIP encapsulation and DNS forwarding on its own, routing
all traffic for non-local destinations to the slirp executable
configured in $_netdev.

I hope I haven't broken anything in the process, but I believe I have
not, since my modifications on DOSemu are minimal (mostly recognizing
the new configuration file token, and adding a new 'VNET_TYPE_SLIRP'
case here and there.
99% of my modifications are inside new files, that I've put in a
dedicated directory in src/dosext/net/net/librouter

Do not hesitate to ask me should you have any questions, doubts, or
suggestions about improving the quality of this contribution.

Known bugs

It only works for udp/tcp traffic. this is a 'by design' limitation of
SLIRP, due to the fact that it uses unprivileged user sockets to emulate
a routed environment. This simply means that you won't be able to ping
anything from within DOSemu, but wget, htget, fdnpkg etc tools will work
just fine.

cheers,
Mateusz Viste

1 Attachments

Discussion

1 2 3 4 > >> (Page 1 of 4)
  • Mateusz Viste

    Mateusz Viste - 2013-06-27

    Here is a new version of the patch - I explicitely added GNU GPL headers to all new files.

     
  • Mateusz Viste

    Mateusz Viste - 2013-06-27

    I don't know how I did it, but it looks like at some point git reverted all my changes in /src/base/init/parser.c ... (and maybe others, don't know yet)... will redo all modifications and repost a patch very soon.

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-27

    I am not in a hurry, and I won't test
    them too soon anyway. :)
    If you screwed up something, do
    git reset --h origin/devel
    to get the clean state, and then
    git am your-patch.patch
    to get everything back.

     
  • Mateusz Viste

    Mateusz Viste - 2013-06-27

    I have no idea what happened... but in the patches the parser.c file is also in its 'clean' state (without my modifications). It's okay in my 'hard' copy here, though: http://www.viste-family.net/mateusz/temp/dosemu-slirp/

    Is by any chance src/base/init/parser.c computed automatically during the build process?

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-27

    Ah, yes!
    So you modify parser.y.in and lexer.l.in

     
  • Mateusz Viste

    Mateusz Viste - 2013-06-27

    Okay, that's a good thing to know then - I was starting to think that git is playing some nasty jokes on me :)

    I modified the parser.y.in file and redone a new patch (hopefully this one is good now).

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-27

    I created a "slirp" branch in git and
    pushed your patch there with some changes.
    So you can do the further work based on
    that branch from now on.

     
    • Mateusz Viste

      Mateusz Viste - 2013-06-27

      that's cool, thanks! But I have to admit I don't really know what to do with this information :) Do I have to re-checkout the dosemu project from git, but specifying some special 'slirp' parameter?

       
  • Stas Sergeev

    Stas Sergeev - 2013-06-27

    git pull
    git checkout slirp

     
  • Mateusz Viste

    Mateusz Viste - 2013-06-27

    got it. thanks!

     
  • Mateusz Viste

    Mateusz Viste - 2013-06-28

    Hello, I noticed you haven't patched one file in git: src/dosext/net/net/Makefile

    This file is having such line:
    CFILES = ipx.c ipxglt.c libpacket.c pktnew.c

    altough in my patch, it has this:
    CFILES = ipx.c ipxglt.c libpacket.c pktnew.c librouter/librouter.c

    Also, I see now that during build, the building thing tries to find a Makefile in librouter/ - I guess you declared this new directory somewhere, and I should add a separate Makefile there, am I right?

    make[2]: Entering directory /home/mateusz/git/dosemu/src/dosext/net/net/librouter' make[2]: *** No targets specified and no makefile found. Stop. make[2]: Leaving directory/home/mateusz/git/dosemu/src/dosext/net/net/librouter'

    I'm sorry for the trouble, I don't understand very well how the whole building process works yet.

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-28

    Arr, I have forgot to do 'git add'. :)
    Fixed now.

     
    • Mateusz Viste

      Mateusz Viste - 2013-06-28

      Now it makes more sense indeed.

      However my building stops with such message:

      lib/libdosext_net_net_librouter.a(librouter.o): In function librouter_init': librouter.c:(.text+0x0): multiple definition oflibrouter_init'
      lib/libdosext_net_net.a(librouter.o):librouter.c:(.text+0x0): first defined here
      collect2: ld returned 1 exit status

      I really have no clue what to do.. Could you tell me please what is wrong here? I understand that you transformed librouter into a static library, and that's nice, but why is the librouter_init() function appearing twice now - in the static libdosext_net_net_librouter.a AND in libdosext_net_net.a ? As I see it, it should not be present in the libdosext_net_net.a anymore, since this lib doesn't include librouter.c, but only a header of it (librouter.h) with prototypes..

       
  • Stas Sergeev

    Stas Sergeev - 2013-06-28

    make clean
    autoconf
    ./default-configure -d
    make -j 2

     
    • Mateusz Viste

      Mateusz Viste - 2013-06-28

      networking works again :) thanks!

       
  • Mateusz Viste

    Mateusz Viste - 2013-06-29

    Hi, I fixed a bug in librouter that was causing a dosemu instance to stay alive even after the user quited the visible dosemu instance, and I made librouter a bit more intelligent, so if the slirp executable is not configured (or not configured properly), it tries to fallback to any slirp in the $PATH.

    I tried to recreate the slirp patch, and followed your instructions about git and amending commits, but it seems that I have done something wrong, because my 'amendment' was attached to one of your commits:

    git commit -a --amend
    [slirp 3134e6f] Merge branch 'devel' into slirp

    Could you please advise what I should do to make things straight?

    If I understand correctly, my commits are not 'real' (as in svn), and are not landing anywhere on the repo, so I have to go through the 'creating a patch' procedure anyway, right?

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-29

    Hi, you don't need to amend any more,
    since the commits that were pushed to
    remote, can no longer be amended.
    Now you just need to create a small
    patches on top of the "slirp" branch.

     
  • Mateusz Viste

    Mateusz Viste - 2013-06-29

    Okay, I understand the idea now. Any chance I could 'uncommit' my local amendment, without loosing my modifications in the process?

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-29

    Probably not directly with git...
    The simplest thing that comes to mind,
    is to format-patch for your amended
    commit, format-patch for the original
    commit, and the do 'interdiff' on them.

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-29

    Or maybe you actually can.
    Try
    git reset origin/slirp
    Without --h it will not remove your changes.

     
    • Mateusz Viste

      Mateusz Viste - 2013-06-29

      this worked perfectly. thanks again :)

      here I am attaching the newest patch (might be the last one, since it all seem to work pretty well now).

       
  • Stas Sergeev

    Stas Sergeev - 2013-06-29

    Looks like you forgot -a option
    to git commit

     
  • Stas Sergeev

    Stas Sergeev - 2013-06-29

    Thanks, applied.
    For the future, the changelog should be
    written the following way in git:


    short log msg
    <empty line="">
    full description


     
  • Stas Sergeev

    Stas Sergeev - 2013-06-29

    Hmm, I don't think I like your last patch.
    Would it be possible to exit on EOF, instead
    of PR_SET_PDEATHSIG?
    Or, if you really need SIGHUP (why would you),
    then you can use pty which sends sighup
    automatically.
    But I think EOF solution would be enough.
    prctl() is something not to use on a regular
    basis.

     
1 2 3 4 > >> (Page 1 of 4)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.