@push.rocks/smartnftables 1.0.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 (43) hide show
  1. package/changelog.md +10 -0
  2. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  3. package/dist_ts/00_commitinfo_data.js +9 -0
  4. package/dist_ts/index.d.ts +10 -0
  5. package/dist_ts/index.js +14 -0
  6. package/dist_ts/nft.executor.d.ts +32 -0
  7. package/dist_ts/nft.executor.js +59 -0
  8. package/dist_ts/nft.manager.d.ts +59 -0
  9. package/dist_ts/nft.manager.firewall.d.ts +49 -0
  10. package/dist_ts/nft.manager.firewall.js +121 -0
  11. package/dist_ts/nft.manager.js +132 -0
  12. package/dist_ts/nft.manager.nat.d.ts +34 -0
  13. package/dist_ts/nft.manager.nat.js +61 -0
  14. package/dist_ts/nft.manager.ratelimit.d.ts +26 -0
  15. package/dist_ts/nft.manager.ratelimit.js +39 -0
  16. package/dist_ts/nft.rulebuilder.firewall.d.ts +30 -0
  17. package/dist_ts/nft.rulebuilder.firewall.js +119 -0
  18. package/dist_ts/nft.rulebuilder.nat.d.ts +15 -0
  19. package/dist_ts/nft.rulebuilder.nat.js +51 -0
  20. package/dist_ts/nft.rulebuilder.ratelimit.d.ts +16 -0
  21. package/dist_ts/nft.rulebuilder.ratelimit.js +61 -0
  22. package/dist_ts/nft.rulebuilder.table.d.ts +13 -0
  23. package/dist_ts/nft.rulebuilder.table.js +27 -0
  24. package/dist_ts/nft.types.d.ts +88 -0
  25. package/dist_ts/nft.types.js +2 -0
  26. package/dist_ts/plugins.d.ts +6 -0
  27. package/dist_ts/plugins.js +9 -0
  28. package/license +21 -0
  29. package/package.json +57 -0
  30. package/readme.md +357 -0
  31. package/ts/00_commitinfo_data.ts +8 -0
  32. package/ts/index.ts +59 -0
  33. package/ts/nft.executor.ts +74 -0
  34. package/ts/nft.manager.firewall.ts +148 -0
  35. package/ts/nft.manager.nat.ts +76 -0
  36. package/ts/nft.manager.ratelimit.ts +43 -0
  37. package/ts/nft.manager.ts +157 -0
  38. package/ts/nft.rulebuilder.firewall.ts +173 -0
  39. package/ts/nft.rulebuilder.nat.ts +82 -0
  40. package/ts/nft.rulebuilder.ratelimit.ts +89 -0
  41. package/ts/nft.rulebuilder.table.ts +30 -0
  42. package/ts/nft.types.ts +102 -0
  43. package/ts/plugins.ts +16 -0
@@ -0,0 +1,102 @@
1
+ // ─── Protocol & Family ────────────────────────────────────────────
2
+ export type TNftProtocol = 'tcp' | 'udp' | 'both';
3
+ export type TNftFamily = 'ip' | 'ip6' | 'inet';
4
+ export type TNftChainHook = 'prerouting' | 'postrouting' | 'input' | 'output' | 'forward';
5
+ export type TNftChainType = 'nat' | 'filter';
6
+ export type TNftPolicy = 'accept' | 'drop';
7
+ export type TFirewallAction = 'accept' | 'drop' | 'reject';
8
+ export type TCtState = 'new' | 'established' | 'related' | 'invalid';
9
+
10
+ // ─── NAT ──────────────────────────────────────────────────────────
11
+ export interface INftDnatRule {
12
+ sourcePort: number;
13
+ targetHost: string;
14
+ targetPort: number;
15
+ protocol?: TNftProtocol;
16
+ preserveSourceIP?: boolean;
17
+ }
18
+
19
+ export interface INftSnatRule {
20
+ sourceAddress: string;
21
+ targetPort: number;
22
+ protocol?: TNftProtocol;
23
+ }
24
+
25
+ export interface INftMasqueradeRule {
26
+ targetPort: number;
27
+ protocol?: TNftProtocol;
28
+ }
29
+
30
+ // ─── Rate Limiting ────────────────────────────────────────────────
31
+ export interface INftRateLimitRule {
32
+ /** Port to rate-limit on. If omitted, applies to all ports. */
33
+ port?: number;
34
+ protocol?: TNftProtocol;
35
+ /** Rate expression, e.g. "100/second", "10 mbytes/second" */
36
+ rate: string;
37
+ /** Burst allowance in packets or bytes */
38
+ burst?: number;
39
+ /** If true, track rate per source IP using nft meters */
40
+ perSourceIP?: boolean;
41
+ /** Action for packets exceeding rate. Default: 'drop' */
42
+ action?: TFirewallAction;
43
+ /** Chain to apply the rule to. Default: 'input' */
44
+ chain?: 'input' | 'forward' | 'prerouting';
45
+ }
46
+
47
+ export interface INftConnectionRateRule {
48
+ /** Port to limit new connections on */
49
+ port?: number;
50
+ protocol?: TNftProtocol;
51
+ /** New connection rate, e.g. "10/second" */
52
+ rate: string;
53
+ /** If true, track per source IP */
54
+ perSourceIP?: boolean;
55
+ }
56
+
57
+ // ─── Firewall ─────────────────────────────────────────────────────
58
+ export interface INftFirewallRule {
59
+ direction: 'input' | 'output' | 'forward';
60
+ action: TFirewallAction;
61
+ sourceIP?: string;
62
+ destIP?: string;
63
+ sourcePort?: number;
64
+ destPort?: number;
65
+ protocol?: TNftProtocol;
66
+ ctStates?: TCtState[];
67
+ comment?: string;
68
+ }
69
+
70
+ export interface INftIPSetConfig {
71
+ name: string;
72
+ type: 'ipv4_addr' | 'ipv6_addr' | 'inet_service';
73
+ elements?: string[];
74
+ comment?: string;
75
+ }
76
+
77
+ // ─── Rule Group (tracking unit) ───────────────────────────────────
78
+ export interface INftRuleGroup {
79
+ id: string;
80
+ commands: string[];
81
+ createdAt: number;
82
+ }
83
+
84
+ // ─── Manager Options ──────────────────────────────────────────────
85
+ export interface ISmartNftablesOptions {
86
+ /** nftables table name. Default: 'smartnftables' */
87
+ tableName?: string;
88
+ /** Address family. Default: 'ip' */
89
+ family?: TNftFamily;
90
+ /** If true, generate commands but never execute them */
91
+ dryRun?: boolean;
92
+ }
93
+
94
+ // ─── Status / Reporting ───────────────────────────────────────────
95
+ export interface INftStatus {
96
+ initialized: boolean;
97
+ tableName: string;
98
+ family: TNftFamily;
99
+ isRoot: boolean;
100
+ activeGroups: number;
101
+ groups: Record<string, { ruleCount: number; createdAt: number }>;
102
+ }
package/ts/plugins.ts ADDED
@@ -0,0 +1,16 @@
1
+ // node native scope
2
+ import * as childProcess from 'node:child_process';
3
+ import * as util from 'node:util';
4
+
5
+ export {
6
+ childProcess,
7
+ util,
8
+ };
9
+
10
+ // @push.rocks scope
11
+ import * as smartlog from '@push.rocks/smartlog';
12
+ import * as smartpromise from '@push.rocks/smartpromise';
13
+ export {
14
+ smartlog,
15
+ smartpromise,
16
+ };