@push.rocks/smartnftables 1.2.0 → 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.
Files changed (91) hide show
  1. package/changelog.md +38 -1
  2. package/dist_rust/smartnftables_linux_amd64_musl +0 -0
  3. package/dist_rust/smartnftables_linux_amd64_musl.tsrust-build.json +14 -0
  4. package/dist_rust/smartnftables_linux_arm64_musl +0 -0
  5. package/dist_rust/smartnftables_linux_arm64_musl.tsrust-build.json +14 -0
  6. package/dist_ts/00_commitinfo_data.js +1 -1
  7. package/dist_ts/classes.managednftables.d.ts +21 -0
  8. package/dist_ts/classes.managednftables.js +176 -0
  9. package/dist_ts/index.d.ts +2 -0
  10. package/dist_ts/index.js +2 -1
  11. package/dist_ts/managed.types.d.ts +99 -0
  12. package/dist_ts/managed.types.js +2 -0
  13. package/dist_ts/nft.executor.d.ts +1 -0
  14. package/dist_ts/nft.executor.js +66 -4
  15. package/dist_ts/nft.rulebuilder.firewall.js +16 -31
  16. package/dist_ts/plugins.d.ts +5 -2
  17. package/dist_ts/plugins.js +6 -3
  18. package/native-notices/crates/block-buffer-0.10.4/license-apache +201 -0
  19. package/native-notices/crates/block-buffer-0.10.4/license-mit +25 -0
  20. package/native-notices/crates/cfg-if-1.0.4/license-apache +201 -0
  21. package/native-notices/crates/cfg-if-1.0.4/license-mit +25 -0
  22. package/native-notices/crates/cpufeatures-0.2.17/license-apache +201 -0
  23. package/native-notices/crates/cpufeatures-0.2.17/license-mit +25 -0
  24. package/native-notices/crates/crypto-common-0.1.7/license-apache +201 -0
  25. package/native-notices/crates/crypto-common-0.1.7/license-mit +25 -0
  26. package/native-notices/crates/digest-0.10.7/license-apache +201 -0
  27. package/native-notices/crates/digest-0.10.7/license-mit +25 -0
  28. package/native-notices/crates/generic-array-0.14.7/license +21 -0
  29. package/native-notices/crates/itoa-1.0.18/license-apache +176 -0
  30. package/native-notices/crates/itoa-1.0.18/license-mit +23 -0
  31. package/native-notices/crates/libc-0.2.189/license-apache +176 -0
  32. package/native-notices/crates/libc-0.2.189/license-mit +25 -0
  33. package/native-notices/crates/memchr-2.8.3/copying +3 -0
  34. package/native-notices/crates/memchr-2.8.3/license-mit +21 -0
  35. package/native-notices/crates/proc-macro2-1.0.107/license-apache +176 -0
  36. package/native-notices/crates/proc-macro2-1.0.107/license-mit +23 -0
  37. package/native-notices/crates/quote-1.0.47/license-apache +176 -0
  38. package/native-notices/crates/quote-1.0.47/license-mit +23 -0
  39. package/native-notices/crates/serde-1.0.229/license-apache +176 -0
  40. package/native-notices/crates/serde-1.0.229/license-mit +23 -0
  41. package/native-notices/crates/serde_core-1.0.229/license-apache +176 -0
  42. package/native-notices/crates/serde_core-1.0.229/license-mit +23 -0
  43. package/native-notices/crates/serde_derive-1.0.229/license-apache +176 -0
  44. package/native-notices/crates/serde_derive-1.0.229/license-mit +23 -0
  45. package/native-notices/crates/serde_json-1.0.151/license-apache +176 -0
  46. package/native-notices/crates/serde_json-1.0.151/license-mit +23 -0
  47. package/native-notices/crates/sha2-0.10.9/license-apache +201 -0
  48. package/native-notices/crates/sha2-0.10.9/license-mit +27 -0
  49. package/native-notices/crates/syn-3.0.5/license-apache +176 -0
  50. package/native-notices/crates/syn-3.0.5/license-mit +23 -0
  51. package/native-notices/crates/typenum-1.20.1/license +1 -0
  52. package/native-notices/crates/typenum-1.20.1/license-apache +201 -0
  53. package/native-notices/crates/typenum-1.20.1/license-mit +21 -0
  54. package/native-notices/crates/unicode-ident-1.0.24/license-apache +176 -0
  55. package/native-notices/crates/unicode-ident-1.0.24/license-mit +23 -0
  56. package/native-notices/crates/unicode-ident-1.0.24/license-unicode +39 -0
  57. package/native-notices/crates/version_check-0.9.5/license-apache +201 -0
  58. package/native-notices/crates/version_check-0.9.5/license-mit +19 -0
  59. package/native-notices/crates/zmij-1.0.23/license-mit +23 -0
  60. package/native-notices/manifest.json +520 -0
  61. package/native-notices/readme.md +36 -0
  62. package/native-notices/rust-standard-library/addr2line-0.25.1-license-apache +201 -0
  63. package/native-notices/rust-standard-library/addr2line-0.25.1-license-mit +25 -0
  64. package/native-notices/rust-standard-library/cargo.lock +522 -0
  65. package/native-notices/rust-standard-library/compiler-builtins-license.txt +275 -0
  66. package/native-notices/rust-standard-library/dependency-notices.html +9072 -0
  67. package/native-notices/rust-standard-library/license-apache +176 -0
  68. package/native-notices/rust-standard-library/license-mit +25 -0
  69. package/native-notices/rust-standard-library/llvm-libunwind-license.txt +311 -0
  70. package/native-notices/rust-standard-library/musl-1.2.5-copyright.txt +193 -0
  71. package/native-notices/rust-standard-library/unicode-license.txt +39 -0
  72. package/package.json +32 -16
  73. package/readme.md +140 -3
  74. package/rust/.cargo/config.toml +2 -0
  75. package/rust/Cargo.lock +192 -0
  76. package/rust/Cargo.toml +13 -0
  77. package/rust/src/main.rs +141 -0
  78. package/rust/src/owner.rs +604 -0
  79. package/rust/src/owner_tests.rs +795 -0
  80. package/rust/src/policy.rs +427 -0
  81. package/rust/src/tests.rs +97 -0
  82. package/rust/src/wire.rs +437 -0
  83. package/scripts/check-native-notices.mjs +27 -0
  84. package/ts/00_commitinfo_data.ts +1 -1
  85. package/ts/classes.managednftables.ts +148 -0
  86. package/ts/index.ts +2 -0
  87. package/ts/managed.types.ts +87 -0
  88. package/ts/nft.executor.ts +71 -4
  89. package/ts/nft.rulebuilder.firewall.ts +16 -31
  90. package/ts/plugins.ts +6 -0
  91. /package/{license → license.md} +0 -0
@@ -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
+ }