summaryrefslogtreecommitdiff
path: root/docs/configuration/service/conntrack-sync.md
blob: 6c47172038fae0628300d7e18a2246ba33c3b1b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
---
myst:
  html_meta:
    description: |
      Conntrack sync preserves active sessions during failover between
      active and backup routers in a VyOS high-availability pair by
      continuously syncing conntrack entries between them.
    keywords: conntrack-sync, connection-tracking, ha, high-availability, vrrp
---

(conntrack-sync)=

# Conntrack sync

Conntrack Sync (Connection Tracking Synchronization) is used to
preserve active sessions during a failover between the active and
backup routers in a high-availability
({abbr}`HA (High Availability)`) pair.

Each active session on the active router is tracked as a local conntrack
entry, and for some protocols, expect entries are also created for
anticipated follow-up connections (for example, the FTP data channel
or SIP media streams). Conntrack sync continuously copies these
entries to backup routers over one or more dedicated interfaces, so it
holds a current picture of every active session in near real time.
This traffic is carried over IPv4, either as multicast (the default)
or unicast to a configured peer address.

When a failover occurs, a backup router takes over all active
sessions and maintains them in their current state, without dropping
or resetting them. A takeover is triggered by VRRP (Virtual Router
Redundancy Protocol), which detects when the current active becomes
unavailable and transitions one of the backup routers to active.

## Configuration

### Failover integration

```{cfgcmd} set service conntrack-sync failover-mechanism vrrp sync-group \<name\>

**Bind the conntrack-sync service to the specified VRRP sync-group.**

This setting is mandatory. The referenced group must already be
configured under `high-availability vrrp sync-group`.
```

Example:

```none
set service conntrack-sync failover-mechanism vrrp sync-group syncgrp
```

### Sync transport

```{cfgcmd} set service conntrack-sync interface \<name\>

**Configure the interface used to exchange conntrack state with the
peer.**

The interface must have an IPv4 address assigned.

Repeat the command to configure multiple interfaces. In this case,
interfaces must use the same transport mode (either all multicast or
all unicast).
```

Example:

```none
set service conntrack-sync interface eth1
```

```{cfgcmd} set service conntrack-sync interface \<name\> peer \<address\>

**Configure the peer's IPv4 address for unicast sync on the specified
interface.**

Setting `peer` switches this interface from multicast (the default) to
unicast mode.

Repeat the command for all interfaces configured for conntrack state
exchange, since mixing unicast and multicast interfaces causes commit
to fail.
```

Example:

```none
set service conntrack-sync interface eth1 peer 192.0.2.2
```

```{cfgcmd} set service conntrack-sync interface \<name\> port \<1-65535\>

**Configure the UDP port used on the specified sync interface.**

In multicast mode, it is the UDP port used by the multicast group. In
unicast mode, it is the UDP destination port on the peer.

The default port is 3780.
```

Example:

```none
set service conntrack-sync interface eth1 port 3781
```

```{cfgcmd} set service conntrack-sync listen-address \<address\>

**Configure the local IPv4 address the router listens on for unicast
sync traffic.**

The command applies only when conntrack sync operates in unicast mode.

The listen address must be assigned to the sync interface. Using an
address from another interface may cause conntrack sync to fail
silently.

Repeat the command to configure multiple listen addresses.
```

Example:

```none
set service conntrack-sync listen-address 192.0.2.1
```

```{cfgcmd} set service conntrack-sync mcast-group \<ipv4-multicast-address\>

**Configure the IPv4 multicast group both routers in the HA pair join
to exchange sync traffic.**

The command applies only when conntrack sync operates in multicast
mode. All routers must be configured with the same group.

The default is 225.0.0.50.
```

Example:

```none
set service conntrack-sync mcast-group 225.0.0.60
```

### Sync scope

```{cfgcmd} set service conntrack-sync accept-protocol \<tcp | udp | icmp | icmp6 | sctp | dccp\>

**Configure the protocol whose local conntrack entries are
synchronized with the HA peer.**

Repeat the command to configure multiple protocols. When omitted,
conntrack entries for all tracked protocols are synchronized.
```

Example:

```none
set service conntrack-sync accept-protocol tcp
set service conntrack-sync accept-protocol udp
set service conntrack-sync accept-protocol icmp
```

```{cfgcmd} set service conntrack-sync ignore-address \<address | prefix\>

**Exclude local conntrack entries involving the specified IP address
or prefix from being synchronized with the HA peer.**

Accepts IPv4 and IPv6 addresses or prefixes.

Repeat the command to configure multiple values.
```

Example:

```none
set service conntrack-sync ignore-address 192.0.2.0/24
set service conntrack-sync ignore-address 2001:db8::/32
```

```{cfgcmd} set service conntrack-sync expect-sync \<all | ftp | h323 | nfs | sip | sqlnet\>

**Configure the protocol whose expect entries are synchronized with
the HA peer.**

Repeat the command to configure multiple protocols. Use `all` to
synchronize expect entries for all supported protocols. `all` cannot
be combined with any other value.

When omitted, no expect entries are synchronized.
```

Example:

```none
set service conntrack-sync expect-sync ftp
set service conntrack-sync expect-sync sip
```

### Buffers and timers

```{cfgcmd} set service conntrack-sync event-listen-queue-size \<0-4294967295\>

**Configure the maximum size of the conntrack event buffer (in megabytes).**

The buffer starts at 2 MB and grows up to the specified value if
events arrive faster than they can be processed.

The default is 8.
```

Example:

```none
set service conntrack-sync event-listen-queue-size 16
```

```{cfgcmd} set service conntrack-sync sync-queue-size \<0-4294967295\>

**Configure the size of the queue that holds sync messages sent between peers (in megabytes)**

The same value is applied to both directions, in either multicast or
unicast mode.

The default is 1.
```

Example:

```none
set service conntrack-sync sync-queue-size 4
```

```{cfgcmd} set service conntrack-sync purge-timeout \<1-2147483647\>

**Configure the delay, in seconds, before synchronized entries are
purged after a handover.**

The default is 60.
```

```{note}
If your setup allows a recovered router to reclaim the active role,
set the VRRP `preempt-delay` to at least this value on the VRRP
`sync-group` bound to the conntrack sync service. This gives the
recovered router time to receive the current conntrack entries before
taking over.
```

Example:

```none
set service conntrack-sync purge-timeout 60
```

### Behavior

```{cfgcmd} set service conntrack-sync disable-external-cache

**Inject conntrack entries directly to backup routers' kernel connection
tracking table as they arrive, rather than holding them in the
external cache used by default.**
```

Example:

```none
set service conntrack-sync disable-external-cache
```

```{cfgcmd} set service conntrack-sync disable-syslog

**Disable syslog logging of conntrack-sync operational events.**
```

Example:

```none
set service conntrack-sync disable-syslog
```

```{cfgcmd} set service conntrack-sync startup-resync

**Request a full copy of conntrack entries from the HA peer when the
conntrack sync service starts.**
```

Example:

```none
set service conntrack-sync startup-resync
```

## Operation

### Show

```{opcmd} show conntrack table \<ipv4 | ipv6\>

**Show conntrack entries for the specified address family (IPv4 or
IPv6).**
```

Example output:

```none
vyos@vyos:~$ show conntrack table ipv4
Id          Original src      Original dst      Original packets    Original bytes    Reply src         Reply dst         Reply packets    Reply bytes    Protocol    State        Timeout    Mark    Zone
----------  ----------------  ----------------  ------------------  ----------------  ----------------  ----------------  ---------------  -------------  ----------  -----------  ---------  ------  ------
282920088   192.0.2.2:41724   192.0.2.15:22     79                  8741              192.0.2.15:22     192.0.2.2:41724   52               8495           tcp         TIME_WAIT    3          0
102466872   198.51.100.1      198.51.100.4      31953               2684052           198.51.100.4      198.51.100.1      31953            2684052        icmp                     29         0       110
1445684978  192.0.2.2:37762   192.0.2.15:22     111                 9969              192.0.2.15:22     192.0.2.2:37762   86               13323          tcp         ESTABLISHED  431999     0
3302843234  192.0.2.2:37758   192.0.2.15:22     2612                3845685           192.0.2.15:22     192.0.2.2:37758   254              17447          tcp         TIME_WAIT    11         0
```

```{note}
If the table is empty and you see a warning message, conntrack is
not enabled. To enable it, create a NAT or a firewall rule, for
example: `set firewall global-options state-policy established
action accept`.
```

```{opcmd} show conntrack-sync cache external [main]

**Show the regular conntrack entries in the external cache.**

The `main` keyword is optional and produces the same output.
```

```{opcmd} show conntrack-sync cache external expect

**Show the expect entries in the external cache.**
```

```{opcmd} show conntrack-sync cache internal [main]

**Show the regular conntrack entries in the internal cache.**

The `main` keyword is optional and produces the same output.
```

```{opcmd} show conntrack-sync cache internal expect

**Show the expect entries in the internal cache.**
```

```{opcmd} show conntrack-sync statistics

**Show operational statistics for the conntrack sync service.**
```

Example output:

```none
vyos@vyos:~$ show conntrack-sync statistics
Main Table Statistics:

cache internal:
current active connections:            19606
connections created:                 6298470    failed:            0
connections updated:                 3786793    failed:            0
connections destroyed:               6278864    failed:            0

cache external:
current active connections:            15771
connections created:                 1660193    failed:            0
connections updated:                   77204    failed:            0
connections destroyed:               1644422    failed:            0

traffic processed:
0 Bytes                         0 Pckts

multicast traffic (active device=eth0.5):
976826240 Bytes sent            212898000 Bytes recv
8302333 Pckts sent              2009929 Pckts recv
0 Error send                    0 Error recv

message tracking:
0 Malformed msgs                  263 Lost msgs
```

```{opcmd} show conntrack statistics

**Show operational statistics for the kernel connection tracking
subsystem.**
```

```{opcmd} show conntrack-sync status

**Show the current operational status of the conntrack sync
service.**
```

Example output:

```none
vyos@vyos:~$ show conntrack-sync status
sync-interface        : eth0.5
failover-mechanism    : vrrp [sync-group GEFOEKOM]
last state transition : no transition yet!
ExpectationSync       : disabled
```

### Restart/reset

```{opcmd} restart conntrack-sync

**Restart the conntrack sync service. On restart, the local cache is
cleared.**
```

```{opcmd} reset conntrack-sync external-cache

**Clear the external cache and request a fresh copy of conntrack
entries from the HA peer.**
```

```{opcmd} reset conntrack-sync internal-cache

**Clear the internal cache and request a fresh copy of conntrack
entries from the HA peer.**
```

## Example

The following shows how to configure a two-node HA pair with
conntrack sync.

:::{figure} /_static/images/service_conntrack_sync-schema.webp
:alt: Conntrack sync example
:scale: 80 %
Conntrack sync example
:::

Apply the following configuration on both `router1` and `router2`. The
only difference between the two nodes is the VRRP priority: use `200`
on `router1` (which becomes VRRP master, i.e., active) and `100` on `router2` (which
becomes backup).

```none
set high-availability vrrp group internal interface 'eth1'
set high-availability vrrp group internal vrid '10'
set high-availability vrrp group internal priority '200'
set high-availability vrrp group internal virtual-address '192.0.2.254/24'
set high-availability vrrp sync-group syncgrp member 'internal'
set service conntrack-sync accept-protocol 'tcp'
set service conntrack-sync accept-protocol 'udp'
set service conntrack-sync accept-protocol 'icmp'
set service conntrack-sync failover-mechanism vrrp sync-group 'syncgrp'
set service conntrack-sync interface 'eth0'
set service conntrack-sync mcast-group '225.0.0.50'
```

After commit, the active router populates its internal cache with
local conntrack entries and sends them to the backup, which stores
them in its external cache. Running `show conntrack-sync statistics`
on each peer reflects this asymmetry.

On the active router:

```none
$ show conntrack-sync statistics

Main Table Statistics:

cache internal:
current active connections:               10
connections created:                    8517    failed:            0
connections updated:                     127    failed:            0
connections destroyed:                  8507    failed:            0

cache external:
current active connections:                0
connections created:                       0    failed:            0
connections updated:                       0    failed:            0
connections destroyed:                     0    failed:            0

traffic processed:
                   0 Bytes                         0 Pckts

multicast traffic (active device=eth0):
              868780 Bytes sent               224136 Bytes recv
               20595 Pckts sent                14034 Pckts recv
                   0 Error send                    0 Error recv

message tracking:
                   0 Malformed msgs                    0 Lost msgs
```

On the backup router:

```none
$ show conntrack-sync statistics

Main Table Statistics:

cache internal:
current active connections:                0
connections created:                       0    failed:            0
connections updated:                       0    failed:            0
connections destroyed:                     0    failed:            0

cache external:
current active connections:               10
connections created:                     888    failed:            0
connections updated:                     134    failed:            0
connections destroyed:                   878    failed:            0

traffic processed:
                   0 Bytes                         0 Pckts

multicast traffic (active device=eth0):
              234184 Bytes sent               907504 Bytes recv
               14663 Pckts sent                21495 Pckts recv
                   0 Error send                    0 Error recv

message tracking:
                   0 Malformed msgs                    0 Lost msgs
```