pax_global_header00006660000000000000000000000064137542725440014527gustar00rootroot0000000000000052 comment=2d87c9b1dc05cb344fc159a6c7d255393beb8dea vdeplug-vdesl-0.1.0/000077500000000000000000000000001375427254400143065ustar00rootroot00000000000000vdeplug-vdesl-0.1.0/CMakeLists.txt000066400000000000000000000023121375427254400170440ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.1) project("vdeplug_vdesl" DESCRIPTION "libvdeplug plugin module for vdesl" HOMEPAGE_URL "https://github.com/virtualsquare/vdeplug_vdesl" VERSION 0.1.0 LANGUAGES C) include(GNUInstallDirs) include(CheckIncludeFile) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2 -O2 -pedantic -Wall -Wextra") set(CMAKE_REQUIRED_QUIET TRUE) set(LIBS_REQUIRED vdeplug_mod) set(HEADERS_REQUIRED libvdeplug.h) foreach(THISLIB IN LISTS LIBS_REQUIRED) find_library(LIB${THISLIB}_OK ${THISLIB}) if(NOT LIB${THISLIB}_OK) message(FATAL_ERROR "library lib${THISLIB} not found") endif() endforeach(THISLIB) foreach(HEADER IN LISTS HEADERS_REQUIRED) check_include_file(${HEADER} ${HEADER}_OK) if(NOT ${HEADER}_OK) message(FATAL_ERROR "header file ${HEADER} not found") endif() endforeach(HEADER) add_definitions(-D_GNU_SOURCE) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_library(vdeplug_vdesl SHARED libvdeplug_vdesl.c) target_link_libraries(vdeplug_vdesl vdeplug_mod) install(TARGETS vdeplug_vdesl DESTINATION ${CMAKE_INSTALL_LIBDIR}/vdeplug) add_subdirectory(man) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_SOURCE_DIR}/Uninstall.cmake") vdeplug-vdesl-0.1.0/README.md000066400000000000000000000035661375427254400155770ustar00rootroot00000000000000# `vdeplug_vdesl` This libvdeplug plugin module adds the support of vde over serial lines. This module of libvdeplug4 can be used in any program supporting VDE like `vde_plug, vdens, kvm, qemu, user-mode-linux` and `virtualbox`. ## install `vdeplug_vdesl` Requirements: [vdeplug4](https://github.com/rd235/vdeplug4), `vdeplug_vdesl` uses cmake, so the standard procedure to build and install this vdeplug plugin module is the following: ```sh $ mkdir build $ cd build $ cmake .. $ make $ sudo make install ``` ## usage examples (tutorial) ### create a point to point ethernet on a serial line Create a physical serial link between two linux hosts. e.g.: * connect two raspberry PIs using the UART pins: pin6 to pin6 (ground), pin 8 to pin 10 and pin 10 to pin 8 (RTX to TXD and viceversa). * connect two /dev/ttyS0 ports using a null-modem cable * use two usb-to-ttl cables: connect RXD to TXD and viceversa (+ ground) (If needed, disable the login prompt from the serial lines) On both hosts run: ``` $ sudo vde_plug tap://vdesl vdesl:///dev/ttyAMA0 ``` (change the name of the serial port to suit your scenario, it could be `/dev/ttyS0` or `/dev/ttyUSB0`). The virtual ethernet interfaces named `vdesl` on the two linux hosts will be connected as if it were a point-to-point ethernet cable between them. The default baud rate is 38400. The `speed` option sets a different baud rate. ``` $ sudo vde_plug tap://vdesl vdesl:///dev/ttyAMA0[speed=2000000] ``` `vdesl` supports the following baud rates: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000. High baud rates may not be supported by the uart hardware or could provide an unreliable service due to communication errors. In order to achieve high speeds the cables should be short and properly shielded against electro-magnetic noise. vdeplug-vdesl-0.1.0/Uninstall.cmake000066400000000000000000000010361375427254400172610ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.13) set(MANIFEST "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt") if(NOT EXISTS ${MANIFEST}) message(FATAL_ERROR "Cannot find install manifest: '${MANIFEST}'") endif() file(STRINGS ${MANIFEST} files) foreach(file ${files}) if(EXISTS ${file} OR IS_SYMLINK ${file}) message(STATUS "Removing: ${file}") execute_process( COMMAND rm -f ${file} RESULT_VARIABLE retcode ) if(NOT "${retcode}" STREQUAL "0") message(WARNING "Failed to remove: ${file}") endif() endif() endforeach(file) vdeplug-vdesl-0.1.0/libvdeplug_vdesl.c000066400000000000000000000153551375427254400200150ustar00rootroot00000000000000/* * libvdeplug - A library to connect to a VDE Switch. * Copyright (C) 2020 Renzo Davoli, University of Bologna * * Stream vde to a serial line * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation version 2.1 of the License, or (at * your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #define SIMULATE_NOISY_LINE #define VDESL_DEFAULT_SPEED B38400 static VDECONN *vde_sl_open(char *given_vde_url, char *descr, int interface_version, struct vde_open_args *open_args); static ssize_t vde_sl_recv(VDECONN *conn, void *buf, size_t len, int flags); static ssize_t vde_sl_send(VDECONN *conn, const void *buf, size_t len, int flags); static int vde_sl_datafd(VDECONN *conn); static int vde_sl_ctlfd(VDECONN *conn); static int vde_sl_close(VDECONN *conn); struct vdeplug_module vdeplug_ops={ .vde_open_real=vde_sl_open, .vde_recv=vde_sl_recv, .vde_send=vde_sl_send, .vde_datafd=vde_sl_datafd, .vde_ctlfd=vde_sl_ctlfd, .vde_close=vde_sl_close}; struct vde_sl_conn { void *handle; struct vdeplug_module *module; int fd; }; static speed_t itospeed(int ispeed) { switch (ispeed) { case 9600: return B9600; // POSIX values case 19200: return B19200; case 38400: return B38400; #ifdef B57600 case 57600: return B57600; #endif #ifdef B115200 case 115200: return B115200; #endif #ifdef B230400 case 230400: return B230400; #endif #ifdef B460800 case 460800: return B460800; #endif #ifdef B500000 case 500000: return B500000; #endif #ifdef B576000 case 576000: return B576000; #endif #ifdef B921600 case 921600: return B921600; #endif #ifdef B1000000 case 1000000: return B1000000; #endif #ifdef B1152000 case 1152000: return B1152000; #endif #ifdef B1500000 case 1500000: return B1500000; #endif #ifdef B2000000 case 2000000: return B2000000; #endif #ifdef B2500000 case 2500000: return B2500000; #endif #ifdef B3000000 case 3000000: return B3000000; #endif #ifdef B3500000 case 3500000: return B3500000; #endif #ifdef B4000000 case 4000000: return B4000000; #endif default: return B0; } } static VDECONN *vde_sl_open(char *vde_url, char *descr, int interface_version, struct vde_open_args *open_args) { (void) descr; (void) interface_version; (void) open_args; struct vde_sl_conn *newconn; struct termios tty; char *speedstr = NULL; speed_t speed = VDESL_DEFAULT_SPEED; struct vdeparms parms[] = { {"speed", &speedstr}, {NULL, NULL}}; #ifdef SIMULATE_NOISY_LINE srandom(time(NULL)); #endif if (vde_parsepathparms(vde_url, parms) != 0) return NULL; if (speedstr) { if ((speed = itospeed(atoi(speedstr))) == B0) { errno = EINVAL; return NULL; } } if ((newconn=calloc(1, sizeof(struct vde_sl_conn)))==NULL) { errno=ENOMEM; goto abort; } // options // newconn->fd = open args // goto free_abort in case of error newconn->fd = open(vde_url, O_RDWR); if (newconn->fd < 0) goto free_abort; memset(&tty, 0, sizeof tty); if(tcgetattr(newconn->fd, &tty) != 0) goto close_abort; /* cflags turn off: PARENB (no parity) CSTOPB (one stop) CRTSCTS(no hw RTS/CTS) cflags turn on: CS8 (8bit per char) CREAD (enable recv) CLOCAL (ignore ctl lines) */ tty.c_cflag &= ~(PARENB | CSTOPB | CRTSCTS); tty.c_cflag |= CS8 | CREAD | CLOCAL; /* lflags turn off ICANON, all echoes, special chars(ISIG) */ tty.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHONL | ISIG); /* iflags turn off sw flow control, special processing of received bytes */ tty.c_iflag &= ~(IXON | IXOFF | IXANY | IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); /* oflags no processing of CR/NL */ tty.c_oflag &= ~(OPOST | ONLCR); tty.c_cc[VTIME] = 1; // 100ms next byte max delay tty.c_cc[VMIN] = 0; if (cfsetispeed(&tty, speed) != 0 || cfsetospeed(&tty, speed) != 0 || tcsetattr(newconn->fd, TCSANOW, &tty) != 0) goto close_abort; return (VDECONN *)newconn; close_abort: close(newconn->fd); free_abort: free(newconn); abort: return NULL; } static ssize_t vde_sl_recv(VDECONN *conn, void *buf, size_t len, int flags) { (void) flags; struct vde_sl_conn *vde_conn = (struct vde_sl_conn *)conn; unsigned char header[2]; unsigned int pktlen; unsigned int taillen; ssize_t rv; unsigned int pos; if ((rv = read(vde_conn->fd, header, 2)) <= 0) goto error_or_skip; else if (rv == 1) { if ((rv = read(vde_conn->fd, header + 1, 1)) <= 0) goto error_or_skip; } pktlen = (header[0]<<8) + header[1]; if (pktlen > VDE_ETHBUFSIZE) { rv = 0; goto error_or_skip; } if (pktlen <= len) taillen = 0; else { taillen = pktlen - len; pktlen = len; } for (pos = 0; pos < pktlen; pos += rv) { if ((rv = read(vde_conn->fd, ((char *) buf) + pos, pktlen - pos)) <= 0) goto error_or_skip; } for (pos = 0; pos < taillen; pos += rv) { char fakebuf[taillen]; if ((rv = read(vde_conn->fd, fakebuf, taillen - pos)) < 0) goto error_or_skip; } return pktlen; error_or_skip: if (rv == 0) { #ifdef SIMULATE_NOISY_LINE printf("skip\n"); #endif errno = EAGAIN; return 1; } else { #ifdef SIMULATE_NOISY_LINE printf("err\n"); #endif return rv; } } static ssize_t vde_sl_send(VDECONN *conn, const void *buf, size_t len, int flags) { (void) flags; struct vde_sl_conn *vde_conn = (struct vde_sl_conn *)conn; #ifdef SIMULATE_NOISY_LINE if (random() % 10 == 0) { char dirty = random(); write(vde_conn->fd, &dirty, 1); printf("Fault!\n"); } #endif if (len <= VDE_ETHBUFSIZE) { unsigned char header[2]; struct iovec iov[2]={{header, 2},{(void *)buf, len}}; header[0]=len >> 8; header[1]=len & 0xff; return writev(vde_conn->fd, iov, 2); } else return 0; } static int vde_sl_datafd(VDECONN *conn) { struct vde_sl_conn *vde_conn = (struct vde_sl_conn *)conn; return vde_conn->fd; } static int vde_sl_ctlfd(VDECONN *conn) { (void) conn; return -1; } static int vde_sl_close(VDECONN *conn) { struct vde_sl_conn *vde_conn = (struct vde_sl_conn *)conn; close(vde_conn->fd); free(vde_conn); return 0; } vdeplug-vdesl-0.1.0/man/000077500000000000000000000000001375427254400150615ustar00rootroot00000000000000vdeplug-vdesl-0.1.0/man/CMakeLists.txt000066400000000000000000000020101375427254400176120ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.7) set(RONN_ORGANIZATION "VirtualSquare") set(RONN_ARGS --organization=${RONN_ORGANIZATION}) # ### ronn pages file(GLOB VU_RONN_PAGES ${CMAKE_CURRENT_SOURCE_DIR}/*.[1-8].ronn) set(VU_MAN_FILES) foreach(VU_RONN_PATH IN LISTS VU_RONN_PAGES) # VU_RONNPAGE: basename of VU_RONN_PATH get_filename_component(VU_RONNPAGE ${VU_RONN_PATH} NAME) # VU_MANPAGE: VU_RONNPAGE without the suffix string(REGEX REPLACE "\.ronn$" "" VU_MANPAGE ${VU_RONNPAGE}) list(APPEND VU_MAN_FILES ${VU_MANPAGE}) endforeach(VU_RONN_PATH) add_custom_target(${PROJECT_NAME}_manpages ALL make RONN_ARGS="${RONN_ARGS}" ${VU_MAN_FILES} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) ### man pages file(GLOB VU_MAN_PAGES ${CMAKE_CURRENT_SOURCE_DIR}/*.[1-8]) foreach(VU_MAN_PATH IN LISTS VU_MAN_PAGES) get_filename_component(VU_MANPAGE ${VU_MAN_PATH} NAME) string(REGEX REPLACE ".*\\." "" MAN_CHAPTER ${VU_MANPAGE}) install(FILES ${VU_MAN_PATH} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${MAN_CHAPTER}) endforeach(VU_MAN_PATH) vdeplug-vdesl-0.1.0/man/Makefile000066400000000000000000000005551375427254400165260ustar00rootroot00000000000000RONN=ronn RONNOK := $(shell command -v ${RONN} 2> /dev/null) none: % : %.ronn ifdef RONNOK # copy copyright notice grep "^\.\\\\\"" $< > $@ || true # run ronn $(RONN) -r ${RONN_ARGS} --pipe $< >> $@ # delete useless trailing "" in .TH sed -i '/^\.TH /s/ ""$$//' $@ else echo "${RONN} is not available. Manpage $@ cannot be updated" >/dev/stderr >&2 endif vdeplug-vdesl-0.1.0/man/libvdeplug_vdesl.1000066400000000000000000000070751375427254400205060ustar00rootroot00000000000000.\" Copyright (C) 2020 VirtualSquare. Project Leader: Renzo Davoli .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License, .\" as published by the Free Software Foundation, either version 2 .\" of the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, write to the Free .\" Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, .\" MA 02110-1301 USA. .\" .\" generated with Ronn-NG/v0.10.0 .\" http://github.com/apjanke/ronn-ng/tree/0.10.0-SNAPSHOT .TH "LIBVDEPLUG_VDESL" "1" "November 2020" "VirtualSquare" .SH "NAME" \fBlibvdeplug_vdesl\fR \- vdesl vdeplug module: ethernet over serial link .SH "SYNOPSIS" libvdeplug_vdesl\.so .SH "DESCRIPTION" This libvdeplug module creates point\-to\-point virtual ethernet networks over serial links\. .P This module of libvdeplug4 can be used in any program supporting vde like \fBvde_plug\fR, \fBvdens\fR, \fBkvm\fR, \fBqemu\fR, \fBuser\-mode\-linux\fR and \fBvirtualbox\fR\. .P The vde_plug_url syntax of this module is the following: .P \fBvdesl://\fR\fIdevice_path\fR [ \fB[\fR OPTION [ /OPTION]\|\.\|\.\|\.\fB]\fR ] .SH "OPTIONS" .TP \fBspeed\fR=\fIbaudrate\fR Set the baud rate of the serial link\. This plugin supports the following baud rates: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000\. High baud rates may not be supported by the uart hardware or could provide an unreliable service due to communication errors\. In order to achieve high speeds the cables should be short and properly shielded from electro\-magnetic noise\. .SH "EXAMPLES" Scenario: two hosts connected by a serial line\. e\.g\.: RS\-232 serial ports connected by a null modem cable, USB\-ttl cables or USB\-FTDI boards or UART pins of System\-on\-Chip point\-to\-point connected so that the RXD on one end is connected to TXD on the other and viceversa\. .P In the following we use the device \fB/dev/ttyAMA0\fR, this may be changed to address the actual device (e\.g\. \fB/dev/ttyS0\fR, \fB/dev/ttyS1\fR, \fB/dev/ttyUSB0\fR, \fB/dev/ttyACM0\fR\|\.\|\.\|\.)\. No other processes should be using the serial port (e\.g\. no getty\-login process should be active on it)\. .P The following command (on both hosts) creates two vde namespaces connected by a virtual point\-to\-point ethernet network\. .IP "" 4 .nf vdens vdesl:///dev/ttyAMA0 .fi .IP "" 0 .P Run the following command on both hosts to create a virtual interface named \fBvdesl0\fR on each end\. The two interfaces are connected by a 4Mbaud link\. .IP "" 4 .nf sudo vde_plug \-d tap://vdesl0 vdesl:///dev/ttyAMA0[speed=4000000] .fi .IP "" 0 .SH "NOTICE" Virtual Distributed Ethernet is not related in any way with www\.vde\.com ("Verband der Elektrotechnik, Elektronik und Informationstechnik" i\.e\. the German "Association for Electrical, Electronic & Information Technologies")\. .SH "SEE ALSO" \fBvde_plug\fR(1), \fBvdens\fR(1) .SH "AUTHOR" VirtualSquare\. Project leader: Renzo Davoli vdeplug-vdesl-0.1.0/man/libvdeplug_vdesl.1.ronn000066400000000000000000000064051375427254400214550ustar00rootroot00000000000000libvdeplug_vdesl(1) -- vdesl vdeplug module: ethernet over serial link ==== ## SYNOPSIS libvdeplug_vdesl.so ## DESCRIPTION This libvdeplug module creates point-to-point virtual ethernet networks over serial links. This module of libvdeplug4 can be used in any program supporting vde like `vde_plug`, `vdens`, `kvm`, `qemu`, `user-mode-linux` and `virtualbox`. The vde_plug_url syntax of this module is the following: `vdesl://`*device_path* [ `[` OPTION [ /OPTION]...`]` ] ## OPTIONS * `speed`=_baudrate_: Set the baud rate of the serial link. This plugin supports the following baud rates: 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000. High baud rates may not be supported by the uart hardware or could provide an unreliable service due to communication errors. In order to achieve high speeds the cables should be short and properly shielded from electro-magnetic noise. ## EXAMPLES Scenario: two hosts connected by a serial line. e.g.: RS-232 serial ports connected by a null modem cable, USB-ttl cables or USB-FTDI boards or UART pins of System-on-Chip point-to-point connected so that the RXD on one end is connected to TXD on the other and viceversa. In the following we use the device `/dev/ttyAMA0`, this may be changed to address the actual device (e.g. `/dev/ttyS0`, `/dev/ttyS1`, `/dev/ttyUSB0`, `/dev/ttyACM0`...). No other processes should be using the serial port (e.g. no getty-login process should be active on it). The following command (on both hosts) creates two vde namespaces connected by a virtual point-to-point ethernet network. ``` vdens vdesl:///dev/ttyAMA0 ``` Run the following command on both hosts to create a virtual interface named `vdesl0` on each end. The two interfaces are connected by a 4Mbaud link. ``` sudo vde_plug -d tap://vdesl0 vdesl:///dev/ttyAMA0[speed=4000000] ``` ## NOTICE Virtual Distributed Ethernet is not related in any way with www.vde.com ("Verband der Elektrotechnik, Elektronik und Informationstechnik" i.e. the German "Association for Electrical, Electronic & Information Technologies"). ## SEE ALSO `vde_plug`(1), `vdens`(1) ## AUTHOR VirtualSquare. Project leader: Renzo Davoli