]> git.proxmox.com Git - mirror_frr.git/blame - lib/pbr.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / pbr.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
0031a6bb
PG
2/* Policy Based Routing (PBR) main header
3 * Copyright (C) 2018 6WIND
0031a6bb
PG
4 */
5
6#ifndef _PBR_H
7#define _PBR_H
8
56c6f60c
QY
9#include <zebra.h>
10#include "stream.h"
11#include "prefix.h"
12
5e244469
RW
13#ifdef __cplusplus
14extern "C" {
15#endif
16
8c28c034
QY
17#define PBR_STR "Policy Based Routing\n"
18
0031a6bb
PG
19/*
20 * A PBR filter
21 *
22 * The filter or match criteria in a PBR rule.
23 * For simplicity, all supported filters are grouped into a structure rather
24 * than delineating further. A bitmask denotes which filters are actually
25 * specified.
26 */
27struct pbr_filter {
28 uint32_t filter_bm; /* not encoded by zapi
29 */
25d760c5
PG
30#define PBR_FILTER_SRC_IP (1 << 0)
31#define PBR_FILTER_DST_IP (1 << 1)
32#define PBR_FILTER_SRC_PORT (1 << 2)
33#define PBR_FILTER_DST_PORT (1 << 3)
34#define PBR_FILTER_FWMARK (1 << 4)
35#define PBR_FILTER_PROTO (1 << 5)
36#define PBR_FILTER_SRC_PORT_RANGE (1 << 6)
37#define PBR_FILTER_DST_PORT_RANGE (1 << 7)
8096bd72 38#define PBR_FILTER_DSFIELD (1 << 8)
d70a31a3 39#define PBR_FILTER_IP_PROTOCOL (1 << 9)
01f23aff
WC
40
41#define PBR_DSFIELD_DSCP (0xfc) /* Upper 6 bits of DS field: DSCP */
42#define PBR_DSFIELD_ECN (0x03) /* Lower 2 bits of DS field: BCN */
0031a6bb
PG
43
44 /* Source and Destination IP address with masks. */
45 struct prefix src_ip;
46 struct prefix dst_ip;
47
48 /* Source and Destination higher-layer (TCP/UDP) port numbers. */
49 uint16_t src_port;
50 uint16_t dst_port;
51
01f23aff
WC
52 /* Filter by Differentiated Services field */
53 uint8_t dsfield; /* DSCP (6 bits) & ECN (2 bits) */
54
0031a6bb
PG
55 /* Filter with fwmark */
56 uint32_t fwmark;
b94683f0
DS
57
58 /* Filter with the ip protocol */
59 uint8_t ip_proto;
0031a6bb
PG
60};
61
62/*
63 * A PBR action
64 *
65 * The action corresponding to a PBR rule.
66 * While the user specifies the action in a particular way, the forwarding
67 * plane implementation (Linux only) requires that to be encoded into a
68 * route table and the rule then point to that route table; in some cases,
69 * the user criteria may directly point to a table too.
70 */
71struct pbr_action {
d70a31a3
EB
72 /* VLAN */
73 uint8_t pcp;
74 uint16_t vlan_id;
75 uint16_t vlan_flags;
76
77 uint32_t queue_id;
78
0031a6bb
PG
79 uint32_t table;
80};
81
82/*
83 * A PBR rule
84 *
85 * This is a combination of the filter criteria and corresponding action.
86 * Rules also have a user-defined sequence number which defines the relative
87 * order amongst rules.
88 */
89struct pbr_rule {
90 vrf_id_t vrf_id;
91
92 uint32_t seq;
93 uint32_t priority;
94 uint32_t unique;
95 struct pbr_filter filter;
96 struct pbr_action action;
58a1d249
DS
97
98 char ifname[INTERFACE_NAMSIZ + 1];
0031a6bb
PG
99};
100
2da7d62e
PG
101/* TCP flags value shared
102 * those are values of byte 13 of TCP header
103 * as mentioned in rfc793
104 */
105#define TCP_HEADER_FIN (0x01)
106#define TCP_HEADER_SYN (0x02)
107#define TCP_HEADER_RST (0x04)
108#define TCP_HEADER_PSH (0x08)
109#define TCP_HEADER_ACK (0x10)
110#define TCP_HEADER_URG (0x20)
111#define TCP_HEADER_ALL_FLAGS (TCP_HEADER_FIN | TCP_HEADER_SYN \
112 | TCP_HEADER_RST | TCP_HEADER_PSH \
113 | TCP_HEADER_ACK | TCP_HEADER_URG)
114
2e1f721e
PG
115/* Pbr IPTable defines
116 * those are common flags shared between BGP and Zebra
117 */
118#define MATCH_IP_SRC_SET (1 << 0)
119#define MATCH_IP_DST_SET (1 << 1)
120#define MATCH_PORT_SRC_SET (1 << 2)
121#define MATCH_PORT_DST_SET (1 << 3)
122#define MATCH_PORT_SRC_RANGE_SET (1 << 4)
123#define MATCH_PORT_DST_RANGE_SET (1 << 5)
4977bd6c
PG
124#define MATCH_DSCP_SET (1 << 6)
125#define MATCH_DSCP_INVERSE_SET (1 << 7)
cfaf18ce 126#define MATCH_PKT_LEN_INVERSE_SET (1 << 8)
6f5617d8 127#define MATCH_FRAGMENT_INVERSE_SET (1 << 9)
3bed2363 128#define MATCH_ICMP_SET (1 << 10)
f449d223 129#define MATCH_PROTOCOL_SET (1 << 11)
40881800
PG
130#define MATCH_FLOW_LABEL_SET (1 << 12)
131#define MATCH_FLOW_LABEL_INVERSE_SET (1 << 13)
2e1f721e 132
0031a6bb
PG
133extern int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s,
134 struct pbr_rule *zrule);
135
5e244469
RW
136#ifdef __cplusplus
137}
138#endif
139
0031a6bb 140#endif /* _PBR_H */