Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #260

Merged
merged 3 commits into from
Sep 16, 2014
Merged

Fixes #260

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/lib/hardware/pci.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,14 @@ function set_bus_master (device, enable)
assert(C.pwrite(fd, value, 2, 0x4) == 2)
end

--- ### Open a device
---
--- Load a device driver for a devie. A fresh copy of the device
--- driver's Lua module is loaded for each device and the module is
--- told at load-time the PCI address of the device it is controlling.
--- This makes the driver source code short because it can assume that
--- it's always talking to the same device.
---
--- This is achieved with our own require()-like function that loads a
--- fresh copy and passes the PCI address as an argument.

open_devices = {}

-- Load a new instance of the 'driver' module for 'pciaddress'.
function open_device(pciaddress, driver)
return require(driver).new(pciaddress)
end

--- ### Selftest
---
--- PCI selftest scans for available devices and performs our driver's
--- self-test on each of them.

function selftest ()
print("selftest: pci")
scan_devices()
print_device_summary()
end

Expand Down
18 changes: 2 additions & 16 deletions src/lib/pcap/pcap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ struct pcap_record {
uint32_t incl_len; /* number of octets of packet saved in file */
uint32_t orig_len; /* actual length of packet */
};

struct pcap_record_extra {
/* Extra metadata that we append to the pcap record, after the payload. */
uint32_t port_id; /* port the packet is captured on */
uint32_t flags; /* bit 0 set means input, bit 0 clear means output */
uint64_t reserved0, reserved1, reserved2, reserved3;
};
]]

function write_file_header(file)
Expand All @@ -42,9 +35,6 @@ function write_file_header(file)
file:flush()
end

local pcap_extra = ffi.new("struct pcap_record_extra")
ffi.fill(pcap_extra, ffi.sizeof(pcap_extra), 0)

function write_record (file, ffi_buffer, length)
write_record_header(file, length)
file:write(ffi.string(ffi_buffer, length))
Expand Down Expand Up @@ -73,11 +63,7 @@ function records (filename)
if record == nil then return nil end
local datalen = math.min(record.orig_len, record.incl_len)
local packet = file:read(datalen)
local extra = nil
if record.incl_len == #packet + ffi.sizeof("struct pcap_record_extra") then
extra = readc(file, "struct pcap_record_extra")
end
return packet, record, extra
return packet, record
end
return pcap_records_it, true, true
end
Expand All @@ -90,6 +76,6 @@ function readc(file, type)
error("short read of " .. type .. " from " .. tostring(file))
end
local obj = ffi.new(type)
ffi.copy(obj, string)
ffi.copy(obj, string, ffi.sizeof(type))
return obj
end