]> git.proxmox.com Git - mirror_frr.git/blame - lib/pbr.h
zebra: Allow ns delete to happen after under/over flow checks
[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
8c28c034
QY
27#define PBR_STR "Policy Based Routing\n"
28
0031a6bb
PG
29/*
30 * A PBR filter
31 *
32 * The filter or match criteria in a PBR rule.
33 * For simplicity, all supported filters are grouped into a structure rather
34 * than delineating further. A bitmask denotes which filters are actually
35 * specified.
36 */
37struct pbr_filter {
38 uint32_t filter_bm; /* not encoded by zapi
39 */
25d760c5
PG
40#define PBR_FILTER_SRC_IP (1 << 0)
41#define PBR_FILTER_DST_IP (1 << 1)
42#define PBR_FILTER_SRC_PORT (1 << 2)
43#define PBR_FILTER_DST_PORT (1 << 3)
44#define PBR_FILTER_FWMARK (1 << 4)
45#define PBR_FILTER_PROTO (1 << 5)
46#define PBR_FILTER_SRC_PORT_RANGE (1 << 6)
47#define PBR_FILTER_DST_PORT_RANGE (1 << 7)
0031a6bb
PG
48
49 /* Source and Destination IP address with masks. */
50 struct prefix src_ip;
51 struct prefix dst_ip;
52
53 /* Source and Destination higher-layer (TCP/UDP) port numbers. */
54 uint16_t src_port;
55 uint16_t dst_port;
56
57 /* Filter with fwmark */
58 uint32_t fwmark;
59};
60
61/*
62 * A PBR action
63 *
64 * The action corresponding to a PBR rule.
65 * While the user specifies the action in a particular way, the forwarding
66 * plane implementation (Linux only) requires that to be encoded into a
67 * route table and the rule then point to that route table; in some cases,
68 * the user criteria may directly point to a table too.
69 */
70struct pbr_action {
71 uint32_t table;
72};
73
74/*
75 * A PBR rule
76 *
77 * This is a combination of the filter criteria and corresponding action.
78 * Rules also have a user-defined sequence number which defines the relative
79 * order amongst rules.
80 */
81struct pbr_rule {
82 vrf_id_t vrf_id;
83
84 uint32_t seq;
85 uint32_t priority;
86 uint32_t unique;
87 struct pbr_filter filter;
88 struct pbr_action action;
89 uint32_t ifindex;
90};
91
2da7d62e
PG
92/* TCP flags value shared
93 * those are values of byte 13 of TCP header
94 * as mentioned in rfc793
95 */
96#define TCP_HEADER_FIN (0x01)
97#define TCP_HEADER_SYN (0x02)
98#define TCP_HEADER_RST (0x04)
99#define TCP_HEADER_PSH (0x08)
100#define TCP_HEADER_ACK (0x10)
101#define TCP_HEADER_URG (0x20)
102#define TCP_HEADER_ALL_FLAGS (TCP_HEADER_FIN | TCP_HEADER_SYN \
103 | TCP_HEADER_RST | TCP_HEADER_PSH \
104 | TCP_HEADER_ACK | TCP_HEADER_URG)
105
2e1f721e
PG
106/* Pbr IPTable defines
107 * those are common flags shared between BGP and Zebra
108 */
109#define MATCH_IP_SRC_SET (1 << 0)
110#define MATCH_IP_DST_SET (1 << 1)
111#define MATCH_PORT_SRC_SET (1 << 2)
112#define MATCH_PORT_DST_SET (1 << 3)
113#define MATCH_PORT_SRC_RANGE_SET (1 << 4)
114#define MATCH_PORT_DST_RANGE_SET (1 << 5)
4977bd6c
PG
115#define MATCH_DSCP_SET (1 << 6)
116#define MATCH_DSCP_INVERSE_SET (1 << 7)
cfaf18ce 117#define MATCH_PKT_LEN_INVERSE_SET (1 << 8)
6f5617d8 118#define MATCH_FRAGMENT_INVERSE_SET (1 << 9)
3bed2363 119#define MATCH_ICMP_SET (1 << 10)
2e1f721e 120
0031a6bb
PG
121extern int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s,
122 struct pbr_rule *zrule);
123
124#endif /* _PBR_H */