-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #953 (Misc NFV stats counters) into kbara-next
- Loading branch information
Showing
17 changed files
with
398 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# IPsec Apps | ||
|
||
## AES128gcm (apps.ipsec.esp) | ||
|
||
The `AES128gcm` implements an ESP transport tunnel using the AES-GCM-128 | ||
cipher. It encrypts packets received on its `decapsulated` port and transmits | ||
them on its `encapsulated` port, and vice-versa. Packets arriving on the | ||
`decapsulated` port must have an IPv6 header, and packets arriving on the | ||
`encapsulated` port must have an IPv6 header followed by an ESP header, | ||
otherwise they will be discarded. | ||
|
||
References: | ||
|
||
- `lib.ipsec.esp` | ||
|
||
DIAGRAM: AES128gcm | ||
+-----------+ | ||
encapsulated | | | ||
---->* AES128gcm *<---- | ||
<----* *----> | ||
| | decapsulated | ||
+-----------+ | ||
|
||
encapsulated | ||
--------\ /---------- | ||
<-------|---/ /-------> | ||
\-----/ decapsulated | ||
|
||
### Configuration | ||
|
||
The `AES128gcm` app accepts a table as its configuration argument. The | ||
following keys are defined: | ||
|
||
— Key **spi** | ||
|
||
*Required*. Security Parameter Index. A 32 bit integer. | ||
|
||
— Key **key** | ||
|
||
*Required*. 20 bytes in form of a hex encoded string. | ||
|
||
— Key **replay_window** | ||
|
||
*Optional*. Size of the “Anti-Replay Window”. Defaults to 128. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
-- Use of this source code is governed by the Apache 2.0 license; see COPYING. | ||
|
||
-- This app implements a point-to-point encryption tunnel using ESP with | ||
-- AES-128-GCM. | ||
|
||
module(..., package.seeall) | ||
local esp = require("lib.ipsec.esp") | ||
local counter = require("core.counter") | ||
local C = require("ffi").C | ||
|
||
AES128gcm = {} | ||
|
||
local provided_counters = { | ||
'type', 'dtime', 'txerrors', 'rxerrors' | ||
} | ||
|
||
function AES128gcm:new (arg) | ||
local conf = arg and config.parse_app_arg(arg) or {} | ||
local self = {} | ||
self.encrypt = esp.esp_v6_encrypt:new{ | ||
mode = "aes-128-gcm", | ||
spi = conf.spi, | ||
keymat = conf.key:sub(1, 32), | ||
salt = conf.key:sub(33, 40)} | ||
self.decrypt = esp.esp_v6_decrypt:new{ | ||
mode = "aes-128-gcm", | ||
spi = conf.spi, | ||
keymat = conf.key:sub(1, 32), | ||
salt = conf.key:sub(33, 40), | ||
window_size = conf.replay_window} | ||
self.counters = {} | ||
for _, name in ipairs(provided_counters) do | ||
self.counters[name] = counter.open(name) | ||
end | ||
counter.set(self.counters.type, 0x1001) -- Virtual interface | ||
counter.set(self.counters.dtime, C.get_unix_time()) | ||
return setmetatable(self, {__index = AES128gcm}) | ||
end | ||
|
||
function AES128gcm:push () | ||
-- Encapsulation path | ||
local input = self.input.decapsulated | ||
local output = self.output.encapsulated | ||
for _=1,link.nreadable(input) do | ||
local p = link.receive(input) | ||
if self.encrypt:encapsulate(p) then | ||
link.transmit(output, p) | ||
else | ||
packet.free(p) | ||
counter.add(self.counters.txerrors) | ||
end | ||
end | ||
-- Decapsulation path | ||
local input = self.input.encapsulated | ||
local output = self.output.decapsulated | ||
for _=1,link.nreadable(input) do | ||
local p = link.receive(input) | ||
if self.decrypt:decapsulate(p) then | ||
link.transmit(output, p) | ||
else | ||
packet.free(p) | ||
counter.add(self.counters.rxerrors) | ||
end | ||
end | ||
end | ||
|
||
function AES128gcm:stop () | ||
-- delete counters | ||
for name, _ in pairs(self.counters) do counter.delete(name) end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.