Skip to content

Commit d5adfd6

Browse files
authored
Merge pull request #401 from xcp-ng/dml-openflow-rules
doc: Add OpenFlow plugin section
2 parents aedaf3a + d0c1d0e commit d5adfd6

File tree

1 file changed

+102
-2
lines changed

1 file changed

+102
-2
lines changed

docs/networking/networking.md

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,112 @@ To be able to encrypt the networks, `openvswitch-ipsec` package must be installe
217217

218218
More information available on [XO official documentation for SDN controller](https://xen-orchestra.com/docs/sdn_controller.html).
219219

220-
### OpenFlow rules
220+
### OpenFlow Rules
221221

222222
:::tip
223-
This feature is coming very soon!
223+
`xcp-ng-xapi-plugins` >= 0.15.0 is required. To check the version, run `yum info xcp-ng-xapi-plugins`.
224224
:::
225225

226+
Using Open vSwitch OpenFlow rules, you can setup traffic rules limiting some network accesses directly at the hypervisor vswitch level. No need for an additional layer of firewalling or filtering setup or equipment.
227+
228+
There are 3 ways to configure OpenFlow rules:
229+
- Through [Xen Orchestra](https://docs.xen-orchestra.com/sdn_controller#openflow-rules)'s web UI (currently only available for per VIF rules)
230+
- Using `xo-cli` as explained in the [Xen Orchestra documentation](https://docs.xen-orchestra.com/sdn_controller#xapi-plugin)
231+
- Manually, by using the `xe` command on your hosts
232+
233+
We recommend using Xen Orchestra or `xo-cli`, depending on your use case. This documentation will focus on how to set up rules manually.
234+
235+
:::warning
236+
The procedure below explains how to set up rules temporarily, but the rules won't persist after reboot.
237+
:::
238+
239+
Keep in mind that these steps must be performed on every host where you want the rules applied. For non-cross-pool private networks, you can run the commands from one host for each host UUID in your pool. For cross-pool private networks, repeat the process for each pool involved.
240+
241+
To set rules manually, you can call the plugin using `xe`:
242+
243+
```
244+
xe host-call-plugin host-uuid<uuid> plugin=sdncontroller.py \
245+
fn=<function> \
246+
args:<key>="<value>" [args:…] …`
247+
```
248+
249+
The `<fuction>` parameter can be:
250+
- `add-rule` to add a new rule
251+
- `del-rule` to delete an existing rule
252+
- `dump-flows` to dump the current flow table from Open vSwitch
253+
254+
#### Adding a rule
255+
256+
Parameters for adding a rule:
257+
- *bridge*: The name of the bridge to add rule to
258+
- *priority* (optional): A number between 0 and 65535 for the rule priority
259+
- *mac* (optional): The MAC address of the VIF to create the rule for (if not specified, a network-wide rule will be created)
260+
- *ipRange*: An IP or range of IPs in CIDR notation (for example `192.168.1.0/24`)
261+
- *direction*: can be **from**, **to** or **from/to**
262+
- *to*: means the parameters for **port** and **ipRange** are to be used as destination
263+
- *from*: means they will be use as source
264+
- *from/to*: 2 rules will be created, one per direction
265+
- *protocol*: IP, TCP, UDP, ICMP or ARP
266+
- *port*: required for TCP/UDP protocol
267+
- *allow*: If set to false, the packets are dropped.
268+
269+
Example to block SSH access to/from the 192.168.1.0/24 subnet, for a VM with MAC address `6e:0b:9e:72:ab:c6` on bridge `xenbr0`:
270+
271+
```
272+
$ xe host-call-plugin host-uuid<uuid> plugin=sdncontroller.py \
273+
fn=add-rule \
274+
args:bridge="xenbr0" \
275+
args:mac="6e:0b:9e:72:ab:c6" \
276+
args:ipRange="192.168.1.0/24" \
277+
args:direction="from/to" \
278+
args:protocol="tcp" \
279+
args:port="22" \
280+
args:allow="false"
281+
```
282+
283+
284+
#### Deleting a rule
285+
286+
Parameters for removing a rule:
287+
- *bridge* : The name of the bridge to delete the rule from
288+
- *mac* (optional): The MAC address of the VIF to delete the rule for
289+
- *ipRange*: An IP or range of IPs in CIDR notation, for example `192.168.1.0/24`
290+
- *direction*: can be **from**, **to** or **from/to**
291+
- *to*: means the parameters for **port** and **ipRange** are to be used as destination
292+
- *from*: means they will be use as source
293+
- *from/to*: 2 rules will be created, one per direction
294+
- *protocol*: IP, TCP, UDP, ICMP or ARP
295+
- *port*: required for TCP/UDP protocol
296+
297+
Example to remove the rule created in the previous section:
298+
299+
```
300+
$ xe host-call-plugin host-uuid<uuid> plugin=sdncontroller.py \
301+
fn=del-rule \
302+
args:bridge="xenbr0" \
303+
args:mac="6e:0b:9e:72:ab:c6" \
304+
args:ipRange="192.168.1.0/24" \
305+
args:direction="from/to" \
306+
args:protocol="tcp" \
307+
args:port="22"
308+
```
309+
#### Dumping the flow table
310+
311+
This command will return all flows entries in the bridge passed as a parameter.
312+
```
313+
$ xe host-call-plugin host-uuid=<uuid> plugin=sdncontroller.py fn=dump-flows args:bridge=xenbr0 | jq .
314+
{
315+
"returncode": 0,
316+
"command": [
317+
"ovs-ofctl",
318+
"dump-flows",
319+
"xenbr0"
320+
],
321+
"stderr": "",
322+
"stdout": "NXST_FLOW reply (xid=0x4):\n cookie=0x0, duration=248977.339s, table=0, n_packets=24591786, n_bytes=3278442075, idle_age=0, hard_age=65534, priority=0 actions=NORMAL\n"
323+
}
324+
```
325+
226326
### Common errors
227327

228328
#### TLS connection issue

0 commit comments

Comments
 (0)