Add support for UBNT ER-12 (Debian 9)
Diff
Cargo.lock | 169 +----------------------------------------------------
Cargo.toml | 2 +-
Dockerfile.ubnt-er12 | 18 ++++++-
src/main.rs | 2 +-
src/parser.rs | 36 +++++++----
5 files changed, 43 insertions(+), 184 deletions(-)
@@ -75,12 +75,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1"
[[package]]
name = "cc"
version = "1.0.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -140,22 +134,6 @@ dependencies = [
]
[[package]]
name = "core-foundation"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
[[package]]
name = "crossbeam-channel"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -235,21 +213,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
dependencies = [
"foreign-types-shared",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
[[package]]
name = "fsevent"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -463,19 +426,6 @@ dependencies = [
]
[[package]]
name = "hyper-tls"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed"
dependencies = [
"bytes",
"hyper",
"native-tls",
"tokio",
"tokio-tls",
]
[[package]]
name = "idna"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -737,24 +687,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8883adfde9756c1d30b0f519c9b8c502a94b41ac62f696453c37c7fc0a958ce"
[[package]]
name = "native-tls"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d"
dependencies = [
"lazy_static",
"libc",
"log",
"openssl",
"openssl-probe",
"openssl-sys",
"schannel",
"security-framework",
"security-framework-sys",
"tempfile",
]
[[package]]
name = "net2"
version = "0.2.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -827,49 +759,6 @@ dependencies = [
]
[[package]]
name = "openssl"
version = "0.10.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4"
dependencies = [
"bitflags",
"cfg-if",
"foreign-types",
"lazy_static",
"libc",
"openssl-sys",
]
[[package]]
name = "openssl-probe"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
[[package]]
name = "openssl-src"
version = "111.10.2+1.1.1g"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a287fdb22e32b5b60624d4a5a7a02dbe82777f730ec0dbc42a0554326fef5a70"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de"
dependencies = [
"autocfg",
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]
[[package]]
name = "os_str_bytes"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -955,12 +844,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "ppv-lite86"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1192,20 +1075,17 @@ dependencies = [
"http",
"http-body",
"hyper",
"hyper-tls",
"js-sys",
"lazy_static",
"log",
"mime",
"mime_guess",
"native-tls",
"percent-encoding",
"pin-project-lite",
"serde",
"serde_urlencoded",
"time",
"tokio",
"tokio-tls",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -1229,39 +1109,6 @@ dependencies = [
]
[[package]]
name = "schannel"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [
"lazy_static",
"winapi 0.3.8",
]
[[package]]
name = "security-framework"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535"
dependencies = [
"bitflags",
"core-foundation",
"core-foundation-sys",
"libc",
"security-framework-sys",
]
[[package]]
name = "security-framework-sys"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "serde"
version = "1.0.110"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1477,16 +1324,6 @@ dependencies = [
]
[[package]]
name = "tokio-tls"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343"
dependencies = [
"native-tls",
"tokio",
]
[[package]]
name = "tokio-util"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1578,12 +1415,6 @@ dependencies = [
]
[[package]]
name = "vcpkg"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -22,7 +22,7 @@ nom = "6.0.0-alpha1"
chrono = "0.4"
tokio = { version = "0.2", features = ["full"] }
reqwest = { version = "0.10", default-features = false, features = ["native-tls-vendored"] }
reqwest = { version = "0.10", default-features = false }
prost = "0.6"
prost-types = "0.6"
@@ -0,0 +1,18 @@
FROM debian:stretch
RUN apt-get update && apt-get install -y --no-install-recommends \
linux-headers-amd64 \
gcc libc6-dev qemu-user ca-certificates \
gcc-mips-linux-gnu libc6-dev-mips-cross \
qemu-system-mips linux-headers-amd64 \
curl
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
RUN /root/.cargo/bin/rustup target add mips-unknown-linux-gnu
ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \
CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu" \
TARGET=mips-unknown-linux-gnu \
QEMU_LD_PREFIX=/usr/mips-linux-gnu \
RUST_TEST_THREADS=1 \
PATH=/root/.cargo/bin:$PATH
@@ -58,8 +58,8 @@ fn open_log_file(path: &Path) -> Result<LogReader> {
}) => {
let _ = send.try_send(ModifyType::Rotate);
}
Ok(Event { .. }) => {}
Err(e) => error!("Error watching file: {:?}", e),
_ => {}
})?;
watcher.watch(path, RecursiveMode::NonRecursive)?;
@@ -3,7 +3,10 @@ use std::collections::HashMap;
use chrono::offset::TimeZone;
use chrono::{DateTime, Datelike, Utc};
use nom::{
bytes::complete::{tag, take, take_till, take_until},
bytes::complete::{is_a, is_not, tag, take, take_till, take_until},
character::complete::char,
combinator::opt,
sequence::delimited,
IResult,
};
@@ -31,7 +34,7 @@ fn parse_month<'a>((i, s): (&'a str, &str)) -> IResult<&'a str, u32> {
fn take_n_digits(i: &str, n: usize) -> IResult<&str, u32> {
let (i, digits) = take(n)(i)?;
match digits.parse() {
match digits.trim().parse() {
Ok(res) => Ok((i, res)),
Err(_) => Err(nom::Err::Failure(nom::error_position!(
"Invalid string, expected ASCII representation of a number",
@@ -62,14 +65,6 @@ fn parse_hostname(i: &str) -> IResult<&str, &str> {
take_until(" ")(i)
}
fn parse_bracketed_param(i: &str) -> IResult<&str, &str> {
let (i, _) = tag("[")(i)?;
let (i, time) = take_until("]")(i)?;
let (i, _) = tag("]")(i)?;
Ok((i, time))
}
fn parse_kvs(i: &str) -> IResult<&str, HashMap<&str, &str>> {
let (i, kvs) = nom::multi::separated_list0(
nom::character::complete::char(' '),
@@ -89,9 +84,9 @@ pub fn parse_log_line(i: &str) -> IResult<&str, Log> {
let (i, _) = tag(" ")(i)?;
let (i, hostname) = parse_hostname(i)?;
let (i, _) = tag(" kernel: ")(i)?;
let (i, _) = parse_bracketed_param(i)?; let (i, _) = tag(" ")(i)?;
let (i, rule) = parse_bracketed_param(i)?;
let (i, _) = opt(delimited(char('['), is_a("1234567890."), char(']')))(i)?; let (i, _) = opt(tag(" "))(i)?;
let (i, rule) = delimited(char('['), is_not("]"), char(']'))(i)?;
let (i, values) = parse_kvs(i)?;
Ok((
@@ -148,4 +143,19 @@ mod tests {
assert_eq!(parsed.values.get("DST"), Some(&"80.80.80.80"));
assert_eq!(rest, "");
}
#[test]
fn test_parse_ubnt_line() {
let (rest, parsed) = parse_log_line("Aug 6 13:26:46 ubnt kernel: [WAN-IN-V6-default-D]IN=tun0 OUT=bond1 MAC=00:00 TUNNEL=224.61.82.50->81.81.82.82 SRC=240e:00f7:4f01:000c:0000:0000:0000:0002 DST=2a01:be30:3411:0330:0051:00ff:fe23:f991 LEN=64 TC=0 HOPLIMIT=241 FLOWLBL=0 PROTO=TCP SPT=8695 DPT=8086 WINDOW=29200 RES=0x00 SYN URGP=0").unwrap();
assert_eq!(parsed.time.hour(), 13);
assert_eq!(parsed.hostname, "ubnt");
assert_eq!(parsed.rule, "WAN-IN-V6-default-D");
assert_eq!(parsed.values.get("IN"), Some(&"tun0"));
assert_eq!(parsed.values.get("MAC"), Some(&"00:00"));
assert_eq!(
parsed.values.get("TUNNEL"),
Some(&"224.61.82.50->81.81.82.82")
);
assert_eq!(rest, "");
}
}