From 3c3c41b3c4dae15f4cd6cb119a3f25b95256ed79 Mon Sep 17 00:00:00 2001 From: Marcel Wiget Date: Sat, 27 Aug 2016 17:37:43 +0200 Subject: [PATCH] check and use linux interface via rawSocket --- src/program/snabbvmx/lwaftr/README | 6 +++--- src/program/snabbvmx/lwaftr/setup.lua | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/program/snabbvmx/lwaftr/README b/src/program/snabbvmx/lwaftr/README index b7ca135d96..6d9755a1dd 100644 --- a/src/program/snabbvmx/lwaftr/README +++ b/src/program/snabbvmx/lwaftr/README @@ -7,7 +7,7 @@ Arguments: --conf configuration file for lwaftr service --id port_id for virtio socket - --pci PCI device number for NIC + --pci PCI device number for NIC (or Linux interface name) --mac Ethernet address of virtio interface --sock Socket path for virtio-user interfaces @@ -18,9 +18,9 @@ Optional: Example config file: -# cat snabbvmx-lwaftr-em3-em4.cfg +# cat snabbvmx-lwaftr-xe0.cfg return { - lwaftr = "snabbvmx-lwaftr-em3-em4.conf", + lwaftr = "snabbvmx-lwaftr-xe0.conf", ipv6_interface = { ipv6_address = "fc00::100", mtu = 9500, diff --git a/src/program/snabbvmx/lwaftr/setup.lua b/src/program/snabbvmx/lwaftr/setup.lua index 7765e55063..c1df048860 100644 --- a/src/program/snabbvmx/lwaftr/setup.lua +++ b/src/program/snabbvmx/lwaftr/setup.lua @@ -15,6 +15,7 @@ local lwcounter = require("apps.lwaftr.lwcounter") local nh_fwd = require("apps.nh_fwd.nh_fwd") local pci = require("lib.hardware.pci") local tap = require("apps.tap.tap") +local raw = require("apps.socket.raw") local yesno = lib.yesno @@ -31,6 +32,11 @@ local function nic_exists (pci_addr) dir_exists(("%s/0000:%s"):format(devices, pci_addr)) end +local function net_exists (pci_addr) + local devices="/sys/class/net" + return dir_exists(("%s/%s"):format(devices, pci_addr)) +end + local function fatal (msg) print(msg) main.exit(1) @@ -58,6 +64,13 @@ local function load_phy (c, nic_id, interface) }, macaddr = interface.mac_address, mtu = interface.mtu }) chain_input, chain_output = nic_id .. ".rx", nic_id .. ".tx" + elseif net_exists(interface.pci) then + print(("%s network interface %s"):format(nic_id, interface.pci)) + if vlan then + print(("WARNING: VLAN not supported over %s. %s vlan %d"):format(interface.pci, nic_id, vlan)) + end + config.app(c, nic_id, raw.RawSocket, interface.pci) + chain_input, chain_output = nic_id .. ".rx", nic_id .. ".tx" else print(("Couldn't find device info for PCI address '%s'"):format(interface.pci)) if not interface.mirror_id then