Skip to content

Commit

Permalink
Add app for static ND
Browse files Browse the repository at this point in the history
apps.ipv6.nd_static fills in static src/dst MAC addresses in packets
transmitted on a L3 port.  Together with the nd_light and ns_responder
apps, it covers all cases of bidirectional dynamic ND, inbound
dynamic, outbound static and bidirectional static neighbor discovery.

The ns_responder app has been adapted to optionally fill in the
src/dst MAC addresses as well to allow for upper-layer protocols to be
agnostic of MAC addresses no matter which ND discipline is being used
on the interface.
  • Loading branch information
alexandergall authored and lukego committed Aug 11, 2016
1 parent 0f5f76e commit 244b0a2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/apps/ipv6/nd_static.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- Use of this source code is governed by the Apache 2.0 license; see COPYING.

-- This app relays packets between its "nort" and "south" links and
-- copies fixed src and dst MAC addresses to the Ethernet header of
-- all packets coming in from "north".

module(..., package.seeall)
local ffi = require("ffi")
local link = require("core.link")
local ethernet = require("lib.protocol.ethernet")

nd_static = subClass(nil)
nd_static._name = "static ND"

function nd_static:new (config)
assert(config and config.local_mac and config.remote_mac)
local o = nd_static:superClass().new(self)
o._eth = ethernet:new({ src = config.local_mac,
dst = config.remote_mac })
o._header = o._eth:header()
return o
end

local empty, receive, transmit = link.empty, link.receive, link.transmit
function nd_static:push()
local l_in = self.input.north
local l_out = self.output.south
if l_in and l_out then
while not empty(l_in) do
-- Insert the static MAC addresses
local p = receive(l_in)
ffi.copy(p.data, self._header, 12)
transmit(l_out, p)
end
end
l_in = self.input.south
l_out = self.output.north
while not empty(l_in) do
-- Pass all packets unchanged souh -> north
transmit(l_out, receive(l_in))
end
end
13 changes: 11 additions & 2 deletions src/apps/ipv6/ns_responder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function ns_responder:new(config)
o._filter = filter
o._dgram = datagram:new()
packet.free(o._dgram:packet())
if config.remote_mac then
o._eth = ethernet:new({ src = config.local_mac,
dst = config.remote_mac })
o._header = o._eth:header()
end
return o
end

Expand Down Expand Up @@ -89,8 +94,12 @@ function ns_responder:push()
local l_out = self.output.south
if l_in and l_out then
while not link.empty(l_in) and not link.full(l_out) do
-- Pass everything on north -> south
link.transmit(l_out, link.receive(l_in))
local p = link.receive(l_in)
if self._header then
-- Insert the static MAC header
ffi.copy(p.data, self._header, 12)
end
link.transmit(l_out, p)
end
end
l_in = self.input.south
Expand Down

0 comments on commit 244b0a2

Please sign in to comment.