@push.rocks/smartnftables 1.2.1 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +27 -0
- package/dist_rust/smartnftables_linux_amd64_musl +0 -0
- package/dist_rust/smartnftables_linux_amd64_musl.tsrust-build.json +14 -0
- package/dist_rust/smartnftables_linux_arm64_musl +0 -0
- package/dist_rust/smartnftables_linux_arm64_musl.tsrust-build.json +14 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.managednftables.d.ts +21 -0
- package/dist_ts/classes.managednftables.js +176 -0
- package/dist_ts/index.d.ts +2 -0
- package/dist_ts/index.js +2 -1
- package/dist_ts/managed.types.d.ts +99 -0
- package/dist_ts/managed.types.js +2 -0
- package/dist_ts/plugins.d.ts +5 -2
- package/dist_ts/plugins.js +6 -3
- package/native-notices/crates/block-buffer-0.10.4/license-apache +201 -0
- package/native-notices/crates/block-buffer-0.10.4/license-mit +25 -0
- package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
- package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
- package/native-notices/crates/cpufeatures-0.2.17/license-apache +201 -0
- package/native-notices/crates/cpufeatures-0.2.17/license-mit +25 -0
- package/native-notices/crates/crypto-common-0.1.7/license-apache +201 -0
- package/native-notices/crates/crypto-common-0.1.7/license-mit +25 -0
- package/native-notices/crates/digest-0.10.7/license-apache +201 -0
- package/native-notices/crates/digest-0.10.7/license-mit +25 -0
- package/native-notices/crates/generic-array-0.14.7/license +21 -0
- package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
- package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
- package/native-notices/crates/libc-0.2.189/license-apache +176 -0
- package/native-notices/crates/libc-0.2.189/license-mit +25 -0
- package/native-notices/crates/memchr-2.8.3/copying +3 -0
- package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
- package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
- package/native-notices/crates/quote-1.0.47/license-apache +176 -0
- package/native-notices/crates/quote-1.0.47/license-mit +23 -0
- package/native-notices/crates/serde-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
- package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
- package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
- package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
- package/native-notices/crates/sha2-0.10.9/license-apache +201 -0
- package/native-notices/crates/sha2-0.10.9/license-mit +27 -0
- package/native-notices/crates/syn-3.0.5/license-apache +176 -0
- package/native-notices/crates/syn-3.0.5/license-mit +23 -0
- package/native-notices/crates/typenum-1.20.1/license +1 -0
- package/native-notices/crates/typenum-1.20.1/license-apache +201 -0
- package/native-notices/crates/typenum-1.20.1/license-mit +21 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
- package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
- package/native-notices/crates/version_check-0.9.5/license-apache +201 -0
- package/native-notices/crates/version_check-0.9.5/license-mit +19 -0
- package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
- package/native-notices/manifest.json +520 -0
- package/native-notices/readme.md +36 -0
- package/native-notices/rust-standard-library/addr2line-0.25.1-license-apache +201 -0
- package/native-notices/rust-standard-library/addr2line-0.25.1-license-mit +25 -0
- package/native-notices/rust-standard-library/cargo.lock +522 -0
- package/native-notices/rust-standard-library/compiler-builtins-license.txt +275 -0
- package/native-notices/rust-standard-library/dependency-notices.html +9072 -0
- package/native-notices/rust-standard-library/license-apache +176 -0
- package/native-notices/rust-standard-library/license-mit +25 -0
- package/native-notices/rust-standard-library/llvm-libunwind-license.txt +311 -0
- package/native-notices/rust-standard-library/musl-1.2.5-copyright.txt +193 -0
- package/native-notices/rust-standard-library/unicode-license.txt +39 -0
- package/package.json +22 -7
- package/readme.md +137 -2
- package/rust/.cargo/config.toml +2 -0
- package/rust/Cargo.lock +192 -0
- package/rust/Cargo.toml +13 -0
- package/rust/src/main.rs +141 -0
- package/rust/src/owner.rs +604 -0
- package/rust/src/owner_tests.rs +795 -0
- package/rust/src/policy.rs +427 -0
- package/rust/src/tests.rs +97 -0
- package/rust/src/wire.rs +437 -0
- package/scripts/check-native-notices.mjs +27 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.managednftables.ts +148 -0
- package/ts/index.ts +2 -0
- package/ts/managed.types.ts +87 -0
- package/ts/plugins.ts +6 -0
- /package/{license → license.md} +0 -0
package/rust/src/main.rs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
mod owner;
|
|
2
|
+
mod policy;
|
|
3
|
+
#[cfg(test)]
|
|
4
|
+
mod tests;
|
|
5
|
+
mod wire;
|
|
6
|
+
|
|
7
|
+
use serde::Deserialize;
|
|
8
|
+
use std::io::{BufRead, Read, Write};
|
|
9
|
+
|
|
10
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
11
|
+
pub enum Error {
|
|
12
|
+
Invalid,
|
|
13
|
+
Unsupported,
|
|
14
|
+
Permission,
|
|
15
|
+
ForeignOwner,
|
|
16
|
+
Conflict,
|
|
17
|
+
Absent,
|
|
18
|
+
Protocol,
|
|
19
|
+
Unavailable,
|
|
20
|
+
}
|
|
21
|
+
pub type Result<T> = std::result::Result<T, Error>;
|
|
22
|
+
impl Error {
|
|
23
|
+
pub fn code(self) -> &'static str {
|
|
24
|
+
match self {
|
|
25
|
+
Self::Invalid => "INVALID",
|
|
26
|
+
Self::Unsupported => "UNSUPPORTED_KERNEL",
|
|
27
|
+
Self::Permission => "PERMISSION",
|
|
28
|
+
Self::ForeignOwner => "FOREIGN_OWNER",
|
|
29
|
+
Self::Conflict => "CONFLICT",
|
|
30
|
+
Self::Absent => "ABSENT",
|
|
31
|
+
Self::Protocol => "PROTOCOL",
|
|
32
|
+
Self::Unavailable => "UNAVAILABLE",
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
pub fn kernel(code: i32) -> Self {
|
|
36
|
+
match -code {
|
|
37
|
+
libc::ENOENT => Self::Absent,
|
|
38
|
+
libc::EPERM | libc::EACCES => Self::Permission,
|
|
39
|
+
libc::EEXIST | libc::EBUSY | libc::ERESTART => Self::Conflict,
|
|
40
|
+
libc::EOPNOTSUPP => Self::Unsupported,
|
|
41
|
+
_ => Self::Unavailable,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#[derive(Deserialize)]
|
|
47
|
+
#[serde(deny_unknown_fields)]
|
|
48
|
+
struct Request {
|
|
49
|
+
id: String,
|
|
50
|
+
method: String,
|
|
51
|
+
params: Box<serde_json::value::RawValue>,
|
|
52
|
+
}
|
|
53
|
+
fn decode<T: serde::de::DeserializeOwned>(value: Box<serde_json::value::RawValue>) -> Result<T> {
|
|
54
|
+
serde_json::from_str(value.get()).map_err(|_| Error::Invalid)
|
|
55
|
+
}
|
|
56
|
+
fn encode(value: impl serde::Serialize) -> Result<serde_json::Value> {
|
|
57
|
+
serde_json::to_value(value).map_err(|_| Error::Protocol)
|
|
58
|
+
}
|
|
59
|
+
fn dispatch(owner: &mut Option<owner::Owner>, request: Request) -> Result<serde_json::Value> {
|
|
60
|
+
match request.method.as_str() {
|
|
61
|
+
"preparePolicy" => encode(decode::<policy::Policy>(request.params)?.prepare()?),
|
|
62
|
+
"openOwner" => {
|
|
63
|
+
if owner.is_some() {
|
|
64
|
+
return Err(Error::Conflict);
|
|
65
|
+
}
|
|
66
|
+
*owner = Some(owner::Owner::new(decode(request.params)?)?);
|
|
67
|
+
encode(owner.as_mut().unwrap().inspect())
|
|
68
|
+
}
|
|
69
|
+
"reconcilePolicy" => encode(
|
|
70
|
+
owner
|
|
71
|
+
.as_mut()
|
|
72
|
+
.ok_or(Error::Conflict)?
|
|
73
|
+
.reconcile(decode(request.params)?)?,
|
|
74
|
+
),
|
|
75
|
+
"inspectPolicy" => {
|
|
76
|
+
if decode::<serde_json::Value>(request.params)? != serde_json::json!({}) {
|
|
77
|
+
return Err(Error::Invalid);
|
|
78
|
+
}
|
|
79
|
+
encode(owner.as_mut().ok_or(Error::Conflict)?.inspect())
|
|
80
|
+
}
|
|
81
|
+
"releasePolicy" => {
|
|
82
|
+
owner
|
|
83
|
+
.as_mut()
|
|
84
|
+
.ok_or(Error::Conflict)?
|
|
85
|
+
.release(decode(request.params)?)?;
|
|
86
|
+
Ok(serde_json::json!({"released":true}))
|
|
87
|
+
}
|
|
88
|
+
"closeOwner" => {
|
|
89
|
+
if decode::<serde_json::Value>(request.params)? != serde_json::json!({}) {
|
|
90
|
+
return Err(Error::Invalid);
|
|
91
|
+
}
|
|
92
|
+
owner.as_mut().ok_or(Error::Conflict)?.close()?;
|
|
93
|
+
Ok(serde_json::json!({"released":true}))
|
|
94
|
+
}
|
|
95
|
+
_ => Err(Error::Invalid),
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn main() {
|
|
100
|
+
if std::env::args().skip(1).collect::<Vec<_>>() != ["--management"] {
|
|
101
|
+
std::process::exit(2);
|
|
102
|
+
}
|
|
103
|
+
let mut output = std::io::stdout().lock();
|
|
104
|
+
writeln!(output, "{{\"event\":\"ready\",\"data\":{{}}}}").unwrap();
|
|
105
|
+
output.flush().unwrap();
|
|
106
|
+
let mut input = std::io::stdin().lock();
|
|
107
|
+
let mut owner = None;
|
|
108
|
+
loop {
|
|
109
|
+
let mut bytes = Vec::new();
|
|
110
|
+
let read = std::io::Read::by_ref(&mut input)
|
|
111
|
+
.take(262_145)
|
|
112
|
+
.read_until(b'\n', &mut bytes);
|
|
113
|
+
if matches!(read, Ok(0)) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if read.is_err() || bytes.len() > 262_144 || bytes.last() != Some(&b'\n') {
|
|
117
|
+
std::process::exit(2);
|
|
118
|
+
}
|
|
119
|
+
let request: Request = match serde_json::from_slice(&bytes) {
|
|
120
|
+
Ok(request) => request,
|
|
121
|
+
Err(_) => std::process::exit(2),
|
|
122
|
+
};
|
|
123
|
+
if request.id.is_empty() || request.id.len() > 128 {
|
|
124
|
+
std::process::exit(2);
|
|
125
|
+
}
|
|
126
|
+
let id = request.id.clone();
|
|
127
|
+
let response = match dispatch(&mut owner, request) {
|
|
128
|
+
Ok(result) => serde_json::json!({"id":id,"success":true,"result":result}),
|
|
129
|
+
Err(error) => {
|
|
130
|
+
serde_json::json!({"id":id,"success":false,"error":"Managed policy operation failed.","errorCode":error.code()})
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
if writeln!(output, "{response}")
|
|
134
|
+
.and_then(|_| output.flush())
|
|
135
|
+
.is_err()
|
|
136
|
+
{
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// EOF/process loss only drops socket ownership. PERSIST retains packet policy.
|
|
141
|
+
}
|