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