libknot 3.3.10__tar.gz → 3.3.11.dev0__tar.gz

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.
@@ -0,0 +1,314 @@
1
+ Metadata-Version: 2.1
2
+ Name: libknot
3
+ Version: 3.3.11.dev0
4
+ Summary: Python bindings for libknot
5
+ Home-page: https://gitlab.nic.cz/knot/knot-dns/-/tree/master/python/libknot
6
+ Author: CZ.NIC, z.s.p.o.
7
+ Author-email: "CZ.NIC, z.s.p.o." <knot-dns@labs.nic.cz>
8
+ License: GPL-3.0
9
+ Project-URL: Documentation, https://www.knot-dns.cz/documentation
10
+ Project-URL: Issues, https://gitlab.nic.cz/knot/knot-dns/-/issues
11
+ Project-URL: Source, https://gitlab.nic.cz/knot/knot-dns/-/tree/master/python/libknot
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Internet :: Name Service (DNS)
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Requires-Python: >=3.5
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Libknot API in Python
24
+
25
+ A Python interface for managing the Knot DNS daemon.
26
+
27
+ # Table of contents
28
+
29
+ * [Introduction](#introduction)
30
+ * [Control module](#control-module)
31
+ + [Control usage](#control-usage)
32
+ + [CTL protocol reference](#kctl-proto)
33
+ + [CTL commands reference](#kctl-cmds)
34
+ + [Control examples](#control-examples)
35
+ * [Probe module](#probe-module)
36
+ + [Probe usage](#probe-usage)
37
+ + [Probe examples](#probe-examples)
38
+ * [Dname module](#dname-module)
39
+ + [Dname usage](#dname-usage)
40
+ + [Dname examples](#dname-examples)
41
+
42
+ ## Introduction<a id="introduction"></a>
43
+
44
+ If the shared `libknot.so` library isn't available in the library search path, it's
45
+ necessary to load the library first, e.g.:
46
+
47
+ ```python3
48
+ import libknot
49
+ libknot.Knot("/usr/lib/libknot.so")
50
+ ```
51
+
52
+ ## Control module<a id="control-module"></a>
53
+
54
+ Using this module it's possible to create scripts for efficient tasks that
55
+ would require complex shell scripts with multiple calls of `knotc`. For
56
+ communication with the daemon it uses the same mechanism as the `knotc` utility,
57
+ i.e. communication via a Unix socket.
58
+
59
+ The module API is stored in `libknot.control`.
60
+
61
+ ### Control usage<a id="control-usage"></a>
62
+
63
+ The module usage consists of several steps:
64
+
65
+ * Initialization and connection to the daemon control socket.
66
+ * One or more control operations. An operation is called by sending a command
67
+ with optional data to the daemon. The operation result has to be received
68
+ afterwards.
69
+ * Closing the connection and deinitialization.
70
+
71
+ ### KnotCTL protocol overview<a id="kctl-proto"></a>
72
+
73
+ Connections are supposed to be short-lived, because maintaining a passive
74
+ connection is costly for the server. Therefore the expected usage of the ctl
75
+ interface is to always open a new connection on demand, then close it once it's
76
+ not immediately needed.
77
+
78
+ Messages are composed of units. These are of four types whose identifiers are
79
+ defined in `libknot.control.KnotCtlType`:
80
+
81
+ | Type | Description | IO action |
82
+ | ------- | ---------------------------------------------------------- | --------- |
83
+ | `END` | Signals intent to terminate connection. | flush |
84
+ | `DATA` | Holds various information - see about data sections below. | cache |
85
+ | `EXTRA` | Additional data. | cache |
86
+ | `BLOCK` | End of data block. | flush |
87
+
88
+ A unit can optionaly hold data, though this is only meaningful for the `DATA`
89
+ and `EXTRA` types. The data consists of several sections of which usually only
90
+ a few at a time will be present. For example when a unit issuing a `stats`
91
+ command is sent, there is no reason for it to contain an `ERROR` section.
92
+
93
+ The data section identifiers are defined in `libknot.control.KnotCtlDataIdx`:
94
+
95
+ | Section name | Description |
96
+ | ------------ | ------------------------------------------------------ |
97
+ | `COMMAND` | Command name. |
98
+ | `FLAGS` | Command flags. |
99
+ | `ERROR` | Error message. |
100
+ | `SECTION` | Configuration section name. |
101
+ | `ITEM` | Configuration item name. |
102
+ | `ID` | Configuration item identifier. |
103
+ | `ZONE` | Zone name. |
104
+ | `OWNER` | Zone record owner |
105
+ | `TTL` | Zone record TTL. |
106
+ | `TYPE` | Zone record type name. |
107
+ | `DATA` | Configuration item/zone record data. |
108
+ | `FILTERS` | Command options or filters for output data processing. |
109
+
110
+ ### CTL commands reference<a id="kctl-cmds"></a>
111
+
112
+ The following is a reference for the low-level CTL API. In case you're unsure
113
+ of the commands' semantics, please consult the
114
+ <a href="https://knot.pages.nic.cz/knot-dns/master/html/man_knotc.html#actions">knotc documentation</a>.
115
+
116
+ A concise notation is used for command synopsis:
117
+
118
+ <pre>
119
+ cmd-name(SECTION_NAME:<i>section's purpouse</i>,
120
+ [OPTIONAL_SECTION=<b>"literal value"</b><i>:literal's purpouse</i>],
121
+ [OPT_SECTION1, OPT_SECTION2], <i># Sections must be present together or not at all</i>
122
+ [OPT_MASTER, [OPT_SLAVE]], <i># OPT_SLAVE may only appear if OPT_MASTER is present</i>
123
+ SECTION_NAME2=<b>"option1"</b>|<b>"option2"</b>, <i># Either one or the other literal may be used</i>
124
+ SECTION_NAME3={<b>"asdf"</b>}, <i># any subset of characters</i>
125
+ SECTION_NAME4={<b>"a"</b><i>:flag's purpouse</i>,<b>"s"</b>,<b>"d"</b>,<b>"f"</b>} <i># any subset of characters</i>
126
+ )
127
+ </pre>
128
+
129
+ The **`"B"`** flag always represents an option to execute in blocking mode.
130
+
131
+ #### Server
132
+
133
+ * `status([TYPE=`<b>`"cert-key"`</b>`|`<b>`"configure"`</b>`|`<b>`"version"`</b>`|`<b>`"workers"`</b>`])`
134
+ * `stop()`
135
+ * `reload()`
136
+ * `stats([SECTION:`<i>`module`</i>`], [ITEM:`<i>`counter`</i>`], [FLAGS=`<b>`"F"`</b>`:`<i>`include 0 counters`</i>`])`
137
+
138
+ #### Zone events
139
+
140
+ `ZONE`: if none applies to all zones
141
+
142
+ * `zone-status([ZONE], [FILTERS={`<b>`"rstefc"`</b>`}])`
143
+ + `FILTERS`: role `(r)`, serial `(s)`, transaction `(t)`, events `(e)`, freeze `(f)`, catalog `(c)`
144
+ * `zone-reload([ZONE], [FLAGS=`<b>`"B"`</b>`,`<b>`"F"`</b><i>`:reload modules`</i>`])`
145
+ * `zone-refresh([ZONE], [FLAGS=`<b>`"B"`</b>`])`
146
+ * `zone-retransfer([ZONE], [FLAGS=`<b>`"B"`</b>`])`
147
+ * `zone-notify([ZONE], [FLAGS=`<b>`"B"`</b>`])`
148
+ * `zone-flush([ZONE], [FILTERS=`<b>`"d"`</b><i>`:specify output directory`</i>`, DATA:`<i>`output directory`</i>`], [FLAGS=`<b>`"B"`</b>`])`
149
+ * `zone-backup([ZONE], [FILTERS={`<b>`"dzjtkocq"`</b>`}, [DATA:`<i>`if "d" filter present; output directory`</i>`]], [FLAGS=`<b>`"B"`</b>`])`
150
+ + `FILTERS`
151
+ - zonefile `(z)`, journal `(j)`, timers `(t)`, kaspdb `(k)`, keysonly `(o)`, catalog `(c)`, quic `(q)`
152
+ - negative counterparts (eg. `nozonefile`) are symmetrical and capitalized
153
+ * `zone-restore` <i>analogous to `zone-backup`</i>
154
+ * `zone-sign([ZONE], [FLAGS=`<b>`"B"`</b>`])`
155
+ * `zone-validate([ZONE], [FLAGS=`<b>`"B"`</b>`])`
156
+ * `zone-keys-load([ZONE], [FLAGS=`<b>`"B"`</b>`])`
157
+ * `zone-key-rollover([ZONE], TYPE=`<b>`"ksk"`</b>`|`<b>`"zsk"`</b>`, [FLAGS=`<b>`"B"`</b>`])`
158
+ * `zone-ksk-submitted([ZONE], [FLAGS=`<b>`"B"`</b>`])`
159
+ * `zone-freeze([ZONE], [FLAGS=`<b>`"B"`</b>`])`
160
+ * `zone-thaw([ZONE], [FLAGS=`<b>`"B"`</b>`])`
161
+ * `zone-xfr-freeze([ZONE], [FLAGS=`<b>`"B"`</b>`])`
162
+ * `zone-xfr-thaw([ZONE], [FLAGS=`<b>`"B"`</b>`])`
163
+
164
+ #### Zone editing
165
+
166
+ Use `"@"` as `OWNER` if you want to denote `ZONE` itself as the owner.
167
+
168
+ * `zone-read([ZONE`<i>`:if none read all`</i>`], [OWNER], [TYPE])`
169
+ * `zone-begin(ZONE)`
170
+ * `zone-commit(ZONE)`
171
+ * `zone-abort(ZONE)`
172
+ * `zone-diff(ZONE)`
173
+ * `zone-get(ZONE, [OWNER], [TYPE])` <!-- TODO: test if OWNER and TYPE may be specified independently -->
174
+ * `zone-set(ZONE, OWNER, [TTL], TYPE, DATA)`
175
+ * `zone-unset(ZONE, OWNER, [TYPE, [DATA]])`
176
+ * `zone-purge(ZONE, [FILTERS={`<b>`"o"`</b>`:orphan,`<b>`"c"`</b>`:catalog,`<b>`"e"`</b>`:expire,`<b>`"j"`</b>`:journal,`<b>`"k"`</b>`:kaspdb,`<b>`"t"`</b>`:timers,`<b>`"f"`</b>`:zonefile}], [FLAGS=`<b>`"B"`</b>`])`
177
+ * `zone-stats(ZONE, [SECTION`<i>`:module`</i>`], [ITEM`<i>`:counter`</i>`], [FLAGS=`<b>`"F"`</b>`:`<i>`include 0 counters`</i>`])`
178
+
179
+ #### Configuration
180
+
181
+ optional list schema option ('s') in FILTERS <!-- TODO: k cemu to je? -->
182
+
183
+ * `conf-list([SECTION, [ITEM], [ID]], [FILTERS=`<b>`"s"`</b>`])`
184
+ * `conf-read([SECTION, [ITEM], [ID]])`
185
+ * `conf-begin()`
186
+ * `conf-commit()`
187
+ * `conf-abort()`
188
+ * `conf-diff([SECTION, [ITEM], [ID]])`
189
+ * `conf-get([SECTION, [ITEM], [ID]])`
190
+ * `conf-set(SECTION, ITEM, ID, [DATA], [FILTERS=`<b>`"s"`</b>`])`
191
+ * `conf-unset([SECTION, [ITEM], [ID]], [DATA])`
192
+
193
+ ### Control examples<a id="control-examples"></a>
194
+
195
+ ```python3
196
+ import json
197
+ import libknot.control
198
+
199
+ # Initialization
200
+ ctl = libknot.control.KnotCtl()
201
+ ctl.connect("/var/run/knot/knot.sock")
202
+ ctl.set_timeout(60)
203
+
204
+ try:
205
+ # Operation without parameters
206
+ ctl.send_block(cmd="conf-begin")
207
+ resp = ctl.receive_block()
208
+
209
+ # Operation with parameters
210
+ ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test")
211
+ resp = ctl.receive_block()
212
+
213
+ ctl.send_block(cmd="conf-commit")
214
+ resp = ctl.receive_block()
215
+
216
+ # Operation with a result displayed in JSON format
217
+ ctl.send_block(cmd="conf-read", section="zone", item="domain")
218
+ resp = ctl.receive_block()
219
+ print(json.dumps(resp, indent=4))
220
+ except libknot.control.KnotCtlError as exc:
221
+ # Print libknot error
222
+ print(exc)
223
+ finally:
224
+ # Deinitialization
225
+ ctl.send(libknot.control.KnotCtlType.END)
226
+ ctl.close()
227
+ ```
228
+
229
+ ```python3
230
+ # List configured zones (including catalog member ones)
231
+ ctl.send_block(cmd="conf-list", filters="z")
232
+ resp = ctl.receive_block()
233
+ for zone in resp['zone']:
234
+ print(zone)
235
+ ```
236
+
237
+ ```python3
238
+ # Print expirations as unixtime for all secondary zones
239
+ ctl.send_block(cmd="zone-status", filters="u")
240
+ resp = ctl.receive_block()
241
+ for zone in resp:
242
+ if resp[zone]["role"] == "master":
243
+ continue
244
+
245
+ expiration = resp[zone]["expiration"]
246
+ if expiration == "-":
247
+ print("Zone %s not loaded" % zone)
248
+ else:
249
+ print("Zone %s expires at %s" % (zone, resp[zone]["expiration"]))
250
+ ```
251
+
252
+ ## Probe module<a id="probe module"></a>
253
+
254
+ Using this module it's possible to receive traffic data from a running daemon with
255
+ active probe module.
256
+
257
+ The module API is stored in `libknot.probe`.
258
+
259
+ ### Probe usage<a id="probe-usage"></a>
260
+
261
+ The module usage consists of several steps:
262
+
263
+ * Initialization of one or more probe channels
264
+ * Periodical receiving of data units from the channels and data processing
265
+
266
+ ### Probe examples<a id="probe-examples"></a>
267
+
268
+ ```python3
269
+ import libknot.probe
270
+
271
+ # Initialization of the first probe channel stored in `/run/knot`
272
+ probe = libknot.probe.KnotProbe("/run/knot", 1)
273
+
274
+ # Array for storing up to 8 data units
275
+ data = libknot.probe.KnotProbeDataArray(8)
276
+ while (True):
277
+ # Receiving data units with timeout of 1000 ms
278
+ if probe.consume(data, 1000) > 0:
279
+ # Printing received data units in the default format
280
+ for item in data:
281
+ print(item)
282
+ ```
283
+
284
+ ## Dname module<a id="dname-module"></a>
285
+
286
+ This module provides a few dname-related operations.
287
+
288
+ The module API is stored in `libknot.dname`.
289
+
290
+ ### Dname usage<a id="dname-usage"></a>
291
+
292
+ The dname object is initialized from a string with textual dname.
293
+ Then the dname can be reformatted to wire format or back to textual format.
294
+
295
+ ### Dname examples<a id="dname-examples"></a>
296
+
297
+ ```python3
298
+ import libknot.dname
299
+
300
+ dname1 = libknot.dname.KnotDname("knot-dns.cz")
301
+ print("%s: wire: %s size: %u" % (dname1.str(), dname1.wire(), dname1.size()))
302
+
303
+ dname2 = libknot.dname.KnotDname("e\\120ample.c\om.")
304
+ print("%s: wire: %s size: %u" % (dname2.str(), dname2.wire(), dname2.size()))
305
+
306
+ dname3 = libknot.dname.KnotDname(dname_wire=b'\x02cz\x00')
307
+ print("%s: wire: %s size: %u" % (dname3.str(), dname3.wire(), dname3.size()))
308
+ ```
309
+
310
+ ```bash
311
+ knot-dns.cz.: wire: b'\x08knot-dns\x02cz\x00' size: 13
312
+ example.com.: wire: b'\x07example\x03com\x00' size: 13
313
+ cz.: wire: b'\x02cz\x00' size: 4
314
+ ```
@@ -0,0 +1,292 @@
1
+ # Libknot API in Python
2
+
3
+ A Python interface for managing the Knot DNS daemon.
4
+
5
+ # Table of contents
6
+
7
+ * [Introduction](#introduction)
8
+ * [Control module](#control-module)
9
+ + [Control usage](#control-usage)
10
+ + [CTL protocol reference](#kctl-proto)
11
+ + [CTL commands reference](#kctl-cmds)
12
+ + [Control examples](#control-examples)
13
+ * [Probe module](#probe-module)
14
+ + [Probe usage](#probe-usage)
15
+ + [Probe examples](#probe-examples)
16
+ * [Dname module](#dname-module)
17
+ + [Dname usage](#dname-usage)
18
+ + [Dname examples](#dname-examples)
19
+
20
+ ## Introduction<a id="introduction"></a>
21
+
22
+ If the shared `libknot.so` library isn't available in the library search path, it's
23
+ necessary to load the library first, e.g.:
24
+
25
+ ```python3
26
+ import libknot
27
+ libknot.Knot("/usr/lib/libknot.so")
28
+ ```
29
+
30
+ ## Control module<a id="control-module"></a>
31
+
32
+ Using this module it's possible to create scripts for efficient tasks that
33
+ would require complex shell scripts with multiple calls of `knotc`. For
34
+ communication with the daemon it uses the same mechanism as the `knotc` utility,
35
+ i.e. communication via a Unix socket.
36
+
37
+ The module API is stored in `libknot.control`.
38
+
39
+ ### Control usage<a id="control-usage"></a>
40
+
41
+ The module usage consists of several steps:
42
+
43
+ * Initialization and connection to the daemon control socket.
44
+ * One or more control operations. An operation is called by sending a command
45
+ with optional data to the daemon. The operation result has to be received
46
+ afterwards.
47
+ * Closing the connection and deinitialization.
48
+
49
+ ### KnotCTL protocol overview<a id="kctl-proto"></a>
50
+
51
+ Connections are supposed to be short-lived, because maintaining a passive
52
+ connection is costly for the server. Therefore the expected usage of the ctl
53
+ interface is to always open a new connection on demand, then close it once it's
54
+ not immediately needed.
55
+
56
+ Messages are composed of units. These are of four types whose identifiers are
57
+ defined in `libknot.control.KnotCtlType`:
58
+
59
+ | Type | Description | IO action |
60
+ | ------- | ---------------------------------------------------------- | --------- |
61
+ | `END` | Signals intent to terminate connection. | flush |
62
+ | `DATA` | Holds various information - see about data sections below. | cache |
63
+ | `EXTRA` | Additional data. | cache |
64
+ | `BLOCK` | End of data block. | flush |
65
+
66
+ A unit can optionaly hold data, though this is only meaningful for the `DATA`
67
+ and `EXTRA` types. The data consists of several sections of which usually only
68
+ a few at a time will be present. For example when a unit issuing a `stats`
69
+ command is sent, there is no reason for it to contain an `ERROR` section.
70
+
71
+ The data section identifiers are defined in `libknot.control.KnotCtlDataIdx`:
72
+
73
+ | Section name | Description |
74
+ | ------------ | ------------------------------------------------------ |
75
+ | `COMMAND` | Command name. |
76
+ | `FLAGS` | Command flags. |
77
+ | `ERROR` | Error message. |
78
+ | `SECTION` | Configuration section name. |
79
+ | `ITEM` | Configuration item name. |
80
+ | `ID` | Configuration item identifier. |
81
+ | `ZONE` | Zone name. |
82
+ | `OWNER` | Zone record owner |
83
+ | `TTL` | Zone record TTL. |
84
+ | `TYPE` | Zone record type name. |
85
+ | `DATA` | Configuration item/zone record data. |
86
+ | `FILTERS` | Command options or filters for output data processing. |
87
+
88
+ ### CTL commands reference<a id="kctl-cmds"></a>
89
+
90
+ The following is a reference for the low-level CTL API. In case you're unsure
91
+ of the commands' semantics, please consult the
92
+ <a href="https://knot.pages.nic.cz/knot-dns/master/html/man_knotc.html#actions">knotc documentation</a>.
93
+
94
+ A concise notation is used for command synopsis:
95
+
96
+ <pre>
97
+ cmd-name(SECTION_NAME:<i>section's purpouse</i>,
98
+ [OPTIONAL_SECTION=<b>"literal value"</b><i>:literal's purpouse</i>],
99
+ [OPT_SECTION1, OPT_SECTION2], <i># Sections must be present together or not at all</i>
100
+ [OPT_MASTER, [OPT_SLAVE]], <i># OPT_SLAVE may only appear if OPT_MASTER is present</i>
101
+ SECTION_NAME2=<b>"option1"</b>|<b>"option2"</b>, <i># Either one or the other literal may be used</i>
102
+ SECTION_NAME3={<b>"asdf"</b>}, <i># any subset of characters</i>
103
+ SECTION_NAME4={<b>"a"</b><i>:flag's purpouse</i>,<b>"s"</b>,<b>"d"</b>,<b>"f"</b>} <i># any subset of characters</i>
104
+ )
105
+ </pre>
106
+
107
+ The **`"B"`** flag always represents an option to execute in blocking mode.
108
+
109
+ #### Server
110
+
111
+ * `status([TYPE=`<b>`"cert-key"`</b>`|`<b>`"configure"`</b>`|`<b>`"version"`</b>`|`<b>`"workers"`</b>`])`
112
+ * `stop()`
113
+ * `reload()`
114
+ * `stats([SECTION:`<i>`module`</i>`], [ITEM:`<i>`counter`</i>`], [FLAGS=`<b>`"F"`</b>`:`<i>`include 0 counters`</i>`])`
115
+
116
+ #### Zone events
117
+
118
+ `ZONE`: if none applies to all zones
119
+
120
+ * `zone-status([ZONE], [FILTERS={`<b>`"rstefc"`</b>`}])`
121
+ + `FILTERS`: role `(r)`, serial `(s)`, transaction `(t)`, events `(e)`, freeze `(f)`, catalog `(c)`
122
+ * `zone-reload([ZONE], [FLAGS=`<b>`"B"`</b>`,`<b>`"F"`</b><i>`:reload modules`</i>`])`
123
+ * `zone-refresh([ZONE], [FLAGS=`<b>`"B"`</b>`])`
124
+ * `zone-retransfer([ZONE], [FLAGS=`<b>`"B"`</b>`])`
125
+ * `zone-notify([ZONE], [FLAGS=`<b>`"B"`</b>`])`
126
+ * `zone-flush([ZONE], [FILTERS=`<b>`"d"`</b><i>`:specify output directory`</i>`, DATA:`<i>`output directory`</i>`], [FLAGS=`<b>`"B"`</b>`])`
127
+ * `zone-backup([ZONE], [FILTERS={`<b>`"dzjtkocq"`</b>`}, [DATA:`<i>`if "d" filter present; output directory`</i>`]], [FLAGS=`<b>`"B"`</b>`])`
128
+ + `FILTERS`
129
+ - zonefile `(z)`, journal `(j)`, timers `(t)`, kaspdb `(k)`, keysonly `(o)`, catalog `(c)`, quic `(q)`
130
+ - negative counterparts (eg. `nozonefile`) are symmetrical and capitalized
131
+ * `zone-restore` <i>analogous to `zone-backup`</i>
132
+ * `zone-sign([ZONE], [FLAGS=`<b>`"B"`</b>`])`
133
+ * `zone-validate([ZONE], [FLAGS=`<b>`"B"`</b>`])`
134
+ * `zone-keys-load([ZONE], [FLAGS=`<b>`"B"`</b>`])`
135
+ * `zone-key-rollover([ZONE], TYPE=`<b>`"ksk"`</b>`|`<b>`"zsk"`</b>`, [FLAGS=`<b>`"B"`</b>`])`
136
+ * `zone-ksk-submitted([ZONE], [FLAGS=`<b>`"B"`</b>`])`
137
+ * `zone-freeze([ZONE], [FLAGS=`<b>`"B"`</b>`])`
138
+ * `zone-thaw([ZONE], [FLAGS=`<b>`"B"`</b>`])`
139
+ * `zone-xfr-freeze([ZONE], [FLAGS=`<b>`"B"`</b>`])`
140
+ * `zone-xfr-thaw([ZONE], [FLAGS=`<b>`"B"`</b>`])`
141
+
142
+ #### Zone editing
143
+
144
+ Use `"@"` as `OWNER` if you want to denote `ZONE` itself as the owner.
145
+
146
+ * `zone-read([ZONE`<i>`:if none read all`</i>`], [OWNER], [TYPE])`
147
+ * `zone-begin(ZONE)`
148
+ * `zone-commit(ZONE)`
149
+ * `zone-abort(ZONE)`
150
+ * `zone-diff(ZONE)`
151
+ * `zone-get(ZONE, [OWNER], [TYPE])` <!-- TODO: test if OWNER and TYPE may be specified independently -->
152
+ * `zone-set(ZONE, OWNER, [TTL], TYPE, DATA)`
153
+ * `zone-unset(ZONE, OWNER, [TYPE, [DATA]])`
154
+ * `zone-purge(ZONE, [FILTERS={`<b>`"o"`</b>`:orphan,`<b>`"c"`</b>`:catalog,`<b>`"e"`</b>`:expire,`<b>`"j"`</b>`:journal,`<b>`"k"`</b>`:kaspdb,`<b>`"t"`</b>`:timers,`<b>`"f"`</b>`:zonefile}], [FLAGS=`<b>`"B"`</b>`])`
155
+ * `zone-stats(ZONE, [SECTION`<i>`:module`</i>`], [ITEM`<i>`:counter`</i>`], [FLAGS=`<b>`"F"`</b>`:`<i>`include 0 counters`</i>`])`
156
+
157
+ #### Configuration
158
+
159
+ optional list schema option ('s') in FILTERS <!-- TODO: k cemu to je? -->
160
+
161
+ * `conf-list([SECTION, [ITEM], [ID]], [FILTERS=`<b>`"s"`</b>`])`
162
+ * `conf-read([SECTION, [ITEM], [ID]])`
163
+ * `conf-begin()`
164
+ * `conf-commit()`
165
+ * `conf-abort()`
166
+ * `conf-diff([SECTION, [ITEM], [ID]])`
167
+ * `conf-get([SECTION, [ITEM], [ID]])`
168
+ * `conf-set(SECTION, ITEM, ID, [DATA], [FILTERS=`<b>`"s"`</b>`])`
169
+ * `conf-unset([SECTION, [ITEM], [ID]], [DATA])`
170
+
171
+ ### Control examples<a id="control-examples"></a>
172
+
173
+ ```python3
174
+ import json
175
+ import libknot.control
176
+
177
+ # Initialization
178
+ ctl = libknot.control.KnotCtl()
179
+ ctl.connect("/var/run/knot/knot.sock")
180
+ ctl.set_timeout(60)
181
+
182
+ try:
183
+ # Operation without parameters
184
+ ctl.send_block(cmd="conf-begin")
185
+ resp = ctl.receive_block()
186
+
187
+ # Operation with parameters
188
+ ctl.send_block(cmd="conf-set", section="zone", item="domain", data="test")
189
+ resp = ctl.receive_block()
190
+
191
+ ctl.send_block(cmd="conf-commit")
192
+ resp = ctl.receive_block()
193
+
194
+ # Operation with a result displayed in JSON format
195
+ ctl.send_block(cmd="conf-read", section="zone", item="domain")
196
+ resp = ctl.receive_block()
197
+ print(json.dumps(resp, indent=4))
198
+ except libknot.control.KnotCtlError as exc:
199
+ # Print libknot error
200
+ print(exc)
201
+ finally:
202
+ # Deinitialization
203
+ ctl.send(libknot.control.KnotCtlType.END)
204
+ ctl.close()
205
+ ```
206
+
207
+ ```python3
208
+ # List configured zones (including catalog member ones)
209
+ ctl.send_block(cmd="conf-list", filters="z")
210
+ resp = ctl.receive_block()
211
+ for zone in resp['zone']:
212
+ print(zone)
213
+ ```
214
+
215
+ ```python3
216
+ # Print expirations as unixtime for all secondary zones
217
+ ctl.send_block(cmd="zone-status", filters="u")
218
+ resp = ctl.receive_block()
219
+ for zone in resp:
220
+ if resp[zone]["role"] == "master":
221
+ continue
222
+
223
+ expiration = resp[zone]["expiration"]
224
+ if expiration == "-":
225
+ print("Zone %s not loaded" % zone)
226
+ else:
227
+ print("Zone %s expires at %s" % (zone, resp[zone]["expiration"]))
228
+ ```
229
+
230
+ ## Probe module<a id="probe module"></a>
231
+
232
+ Using this module it's possible to receive traffic data from a running daemon with
233
+ active probe module.
234
+
235
+ The module API is stored in `libknot.probe`.
236
+
237
+ ### Probe usage<a id="probe-usage"></a>
238
+
239
+ The module usage consists of several steps:
240
+
241
+ * Initialization of one or more probe channels
242
+ * Periodical receiving of data units from the channels and data processing
243
+
244
+ ### Probe examples<a id="probe-examples"></a>
245
+
246
+ ```python3
247
+ import libknot.probe
248
+
249
+ # Initialization of the first probe channel stored in `/run/knot`
250
+ probe = libknot.probe.KnotProbe("/run/knot", 1)
251
+
252
+ # Array for storing up to 8 data units
253
+ data = libknot.probe.KnotProbeDataArray(8)
254
+ while (True):
255
+ # Receiving data units with timeout of 1000 ms
256
+ if probe.consume(data, 1000) > 0:
257
+ # Printing received data units in the default format
258
+ for item in data:
259
+ print(item)
260
+ ```
261
+
262
+ ## Dname module<a id="dname-module"></a>
263
+
264
+ This module provides a few dname-related operations.
265
+
266
+ The module API is stored in `libknot.dname`.
267
+
268
+ ### Dname usage<a id="dname-usage"></a>
269
+
270
+ The dname object is initialized from a string with textual dname.
271
+ Then the dname can be reformatted to wire format or back to textual format.
272
+
273
+ ### Dname examples<a id="dname-examples"></a>
274
+
275
+ ```python3
276
+ import libknot.dname
277
+
278
+ dname1 = libknot.dname.KnotDname("knot-dns.cz")
279
+ print("%s: wire: %s size: %u" % (dname1.str(), dname1.wire(), dname1.size()))
280
+
281
+ dname2 = libknot.dname.KnotDname("e\\120ample.c\om.")
282
+ print("%s: wire: %s size: %u" % (dname2.str(), dname2.wire(), dname2.size()))
283
+
284
+ dname3 = libknot.dname.KnotDname(dname_wire=b'\x02cz\x00')
285
+ print("%s: wire: %s size: %u" % (dname3.str(), dname3.wire(), dname3.size()))
286
+ ```
287
+
288
+ ```bash
289
+ knot-dns.cz.: wire: b'\x08knot-dns\x02cz\x00' size: 13
290
+ example.com.: wire: b'\x07example\x03com\x00' size: 13
291
+ cz.: wire: b'\x02cz\x00' size: 4
292
+ ```
@@ -20,7 +20,7 @@ class Knot(object):
20
20
  """Basic libknot interface."""
21
21
 
22
22
  LIBKNOT = None
23
- LIBKNOT_VERSION = "14"
23
+ LIBKNOT_VERSION = "15"
24
24
 
25
25
  RCODE_NAMES = None
26
26
 
@@ -37,7 +37,7 @@ class KnotCtlDataIdx(enum.IntEnum):
37
37
  TTL = 8
38
38
  TYPE = 9
39
39
  DATA = 10
40
- FILTER = 11
40
+ FILTERS = 11
41
41
 
42
42
 
43
43
  class KnotCtlData(object):
@@ -207,7 +207,7 @@ class KnotCtl(object):
207
207
  query[KnotCtlDataIdx.TYPE] = rtype
208
208
  query[KnotCtlDataIdx.DATA] = data
209
209
  query[KnotCtlDataIdx.FLAGS] = flags
210
- query[KnotCtlDataIdx.FILTER] = filters
210
+ query[KnotCtlDataIdx.FILTERS] = filters
211
211
 
212
212
  self.send(KnotCtlType.DATA, query)
213
213
  self.send(KnotCtlType.BLOCK)
@@ -12,9 +12,9 @@ class KnotProbeDataProto(enum.IntEnum):
12
12
 
13
13
  UDP = 0
14
14
  TCP = 1
15
- QUIC = 3
16
- TLS = 4
17
- HTTPS = 5
15
+ QUIC = 2
16
+ TLS = 3
17
+ HTTPS = 4
18
18
 
19
19
 
20
20
  class KnotProbeDataDNSHdr(ctypes.BigEndianStructure):
@@ -132,8 +132,10 @@ class KnotProbeData(ctypes.Structure):
132
132
  string += COL("UDP", GRN)
133
133
  elif self.proto == KnotProbeDataProto.TCP:
134
134
  string += COL("TCP", RED)
135
- else:
135
+ elif self.proto == KnotProbeDataProto.QUIC:
136
136
  string += COL("QUIC", ORG)
137
+ else:
138
+ string += COL("TLS", YELW)
137
139
  if self.tcp_rtt > 0:
138
140
  string += ", RTT %.2f ms" % (self.tcp_rtt / 1000)
139
141
  string += "\n ID %u, " % self.query_hdr.id