Skip to content

Commit

Permalink
Add protocol header for ICMPv6 Packet-Too-Big type
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandergall committed Jun 18, 2018
1 parent b9da7ca commit c7d772c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/protocol/icmp/header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ local icmp = subClass(header)
-- Class variables
icmp._name = "icmp"
icmp._ulp = {
class_map = { [135] = "lib.protocol.icmp.nd.ns",
class_map = { [2] = "lib.protocol.icmp.ptb",
[135] = "lib.protocol.icmp.nd.ns",
[136] = "lib.protocol.icmp.nd.na" },
method = "type" }
icmp:init(
Expand Down
37 changes: 37 additions & 0 deletions src/lib/protocol/icmp/ptb.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Use of this source code is governed by the Apache 2.0 license; see COPYING.

module(..., package.seeall)
local ffi = require("ffi")
local C = ffi.C
local lib = require("core.lib")
local proto_header = require("lib.protocol.header")

local ptb = subClass(proto_header)

-- Class variables
ptb._name = "packet too big"
ptb._ulp = { method = nil }
proto_header.init(ptb,
{
-- The original packet follows the mtu. Because
-- it is of variable size, it is considered as
-- payload rather than part of the ICMP message
-- so it can be retrieved with the datagram
-- payload() method.
[1] = ffi.typeof[[
struct {
uint32_t mtu;
} __attribute__((packed))
]]
})

-- Instance methods

function ptb:mtu (mtu)
if mtu ~= nil then
self:header().mtu = lib.htonl(mtu)
end
return lib.ntohl(self:header().mtu)
end

return ptb

0 comments on commit c7d772c

Please sign in to comment.