Client implementation of the 9P protocol for constrained devices
git clone https://git.8pit.net/ninenano.git
1**GEFAHR ACHTUNG GEFAHR:** THIS CODE IS WRITTEN IN A MEMORY UNSAFE 2PROGRAMMING LANGUAGE AND ACCEPTS ARBITRARY INPUT FROM A NETWORK 3CONNECTION. I AM PRETTY SURE THAT I AM NOT CAPABLE OF WRITING BUG-FREE C 4CODE SO PLEASE DON'T BLAME ME IF YOUR CONSTRAINED DEVICE BECOMES PART OF 5THE NEXT INTERNET OF THINGS BOTNET. KTHXBYE! 6 7ninenano 8======== 9 10ninenano is a client implementation of the 9P network for [constrained 11devices][7]. It currently consists of two separated components: 12 131. 9p: A client implementation of the 9P network protocol 142. 9pfs: Virtual 9P file system using RIOTs VFS layer 15 16The 9p component works on the [RIOT][3] operating system and on various 17POSIX compatible operating systems. It uses only a small subset of the 18functions provided by the libc and should therefore also be portable to 19other operating systems and microcontroller frameworks. The 9pfs 20component uses RIOT's [VFS layer][5] and thus only works on RIOT. 21 22However, even on RIOT you might consider using the 9p component directly 23instead of 9pfs component since doing so will spare you some bytes in 24the text segment. 25 26Status 27------ 28 29This implementation of the 9P protocol has the following limitations: 30 311. It only sends one T-message at a time and waits for an R-message from 32 the server before sending additional T-messages. 332. `flush(5)` is not implemented because it wasn't needed due to the 34 first limitation. 353. Only files with a maximum amount of sixteen path elements can be 36 accessed using `_9pwalk`. 374. Proper handling of `Rerror` messages is not implemented. 385. `Twstat` is currently not implemented. 39 40*The fourth and fifth limitation might be resolved in feature releases.* 41 42Supported compilers 43------------------- 44 45In theory this code should compile with any C99 compiler, however, the 46compatibility layer for POSIX compatible operating systems uses gcc 47builtins for byteswapping. Therefore the code only compiles with recent 48version of gcc and clang. 49 50Compilation 51----------- 52 53For using this library on RIOT you should use the provided RIOT ninenano 54pkg. For compiling a static library for POSIX operating systems run the 55following command: 56 57 $ make -f Makefile.posix 58 59A few CPP macros are provided for tweaking the size of the library, 60these can be passed by modifying the `CFLAGS` environment variable 61accordingly. Currently the following macros can be redefined: 62 631. `_9P_MSIZE`: Maximum message size and therefore also equal to the 64 buffer size used to store 9P messages. 652. `_9P_MAXFIDS`: Maximum amount of open fids for a 9P connection. 66 67In addition to that you can define `NDEBUG` to prevent some optional 68sanity checks form being included in the resulting binary. Your 69application should be fine without them they only detect violations of 70invariants caused by programming errors. 71 72Usage 73----- 74 75**Disclaimer:** This library requires a basic understanding of the 9P 76network protocol. If you don't know how 9P works start by reading the 77`intro(5)` [man page][6] shipped with the fourth edition of Plan 9 78operating system. 79 80The API is very straight forward and shouldn't change a lot anymore. If 81you want to use 9P in combination with the provided VFS layer start by 82reading the [VFS documentation][5]. In order to use 9pfs you need to 83point the `private_data` member of your `vfs_mount_t` to an allocated 84`_9pfs` superblock in addition to that the `ctx` member of the 85superblock needs to be initialized using `_9pinit`. 86 87If you want to use the 9P component directly all you have to do is 88allocate memory for a `_9pctx` and afterwards initialize it with 89`_9pinit`. Consult the documentation or the examples in `examples/` and 90`tests/` if you need additional help. 91 92Documentation 93------------- 94 95The source code is documented in a format that can be parsed by 96[Doxygen][4]. A `Doxyfile` is also provided. To generate source code 97documentation using the supplied `Doxyfile` run the following command: 98 99 $ doxygen Doxyfile100101Afterwards the documentation will be located in a newly created folder102called `docs`, view the docs by opening `docs/index.html` in your103favorite web browser.104105Tests106-----107108ninenano comes with both unit and integration tests utilising RIOT's109test framework. The unit tests use the 9p component directly while the110integration tests use the 9p component indirectly through the 9pfs111component.112113In order to run the tests you need to setup the toolchain for RIOT's114[native family][1]. Besides you need to install go `>= 1.5`, python115`3.X` and the [pexpect][2] python package.116117In addition to that a tun devices needs to created:118119 # ip tuntap add tap0 mode tap120 # ip addr add fe80::e42a:1aff:feca:10ec dev tap0121 # ip link set tap0 up122123After creating the tun devices you can run the tests:124125 $ export TESTADDR="fe80::e42a:1aff:feca:10ec"126 $ make test127128**Note:** RIOT will add an additional IP address to the interface when129you run the tests for the first time. However, it doesn't matter which130one you use as a value for the `TESTADDR` environment variable, meaning131you can ignore the additional IP address.132133License134-------135136This program is free software: you can redistribute it and/or modify it137under the terms of the GNU General Public License as published by the138Free Software Foundation, either version 3 of the License, or (at your139option) any later version.140141This program is distributed in the hope that it will be useful, but142WITHOUT ANY WARRANTY; without even the implied warranty of143MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General144Public License for more details.145146You should have received a copy of the GNU General Public License along147with this program. If not, see <http://www.gnu.org/licenses/>.148149[1]: https://github.com/RIOT-OS/RIOT/wiki/Family:-native#toolchains150[2]: https://pypi.python.org/pypi/pexpect151[3]: http://riot-os.org/152[4]: http://www.stack.nl/~dimitri/doxygen/153[5]: http://riot-os.org/api/group__sys__vfs.html154[6]: http://man.cat-v.org/plan_9/5/intro155[7]: https://tools.ietf.org/html/rfc7228