]>
Commit | Line | Data |
---|---|---|
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 |
28 | extern "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 | */ | |
41 | struct 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) | |
0031a6bb PG |
52 | |
53 | /* Source and Destination IP address with masks. */ | |
54 | struct prefix src_ip; | |
55 | struct prefix dst_ip; | |
56 | ||
57 | /* Source and Destination higher-layer (TCP/UDP) port numbers. */ | |
58 | uint16_t src_port; | |
59 | uint16_t dst_port; | |
60 | ||
61 | /* Filter with fwmark */ | |
62 | uint32_t fwmark; | |
63 | }; | |
64 | ||
65 | /* | |
66 | * A PBR action | |
67 | * | |
68 | * The action corresponding to a PBR rule. | |
69 | * While the user specifies the action in a particular way, the forwarding | |
70 | * plane implementation (Linux only) requires that to be encoded into a | |
71 | * route table and the rule then point to that route table; in some cases, | |
72 | * the user criteria may directly point to a table too. | |
73 | */ | |
74 | struct pbr_action { | |
75 | uint32_t table; | |
76 | }; | |
77 | ||
78 | /* | |
79 | * A PBR rule | |
80 | * | |
81 | * This is a combination of the filter criteria and corresponding action. | |
82 | * Rules also have a user-defined sequence number which defines the relative | |
83 | * order amongst rules. | |
84 | */ | |
85 | struct pbr_rule { | |
86 | vrf_id_t vrf_id; | |
87 | ||
88 | uint32_t seq; | |
89 | uint32_t priority; | |
90 | uint32_t unique; | |
91 | struct pbr_filter filter; | |
92 | struct pbr_action action; | |
3dabc387 | 93 | ifindex_t ifindex; |
0031a6bb PG |
94 | }; |
95 | ||
2da7d62e PG |
96 | /* TCP flags value shared |
97 | * those are values of byte 13 of TCP header | |
98 | * as mentioned in rfc793 | |
99 | */ | |
100 | #define TCP_HEADER_FIN (0x01) | |
101 | #define TCP_HEADER_SYN (0x02) | |
102 | #define TCP_HEADER_RST (0x04) | |
103 | #define TCP_HEADER_PSH (0x08) | |
104 | #define TCP_HEADER_ACK (0x10) | |
105 | #define TCP_HEADER_URG (0x20) | |
106 | #define TCP_HEADER_ALL_FLAGS (TCP_HEADER_FIN | TCP_HEADER_SYN \ | |
107 | | TCP_HEADER_RST | TCP_HEADER_PSH \ | |
108 | | TCP_HEADER_ACK | TCP_HEADER_URG) | |
109 | ||
2e1f721e PG |
110 | /* Pbr IPTable defines |
111 | * those are common flags shared between BGP and Zebra | |
112 | */ | |
113 | #define MATCH_IP_SRC_SET (1 << 0) | |
114 | #define MATCH_IP_DST_SET (1 << 1) | |
115 | #define MATCH_PORT_SRC_SET (1 << 2) | |
116 | #define MATCH_PORT_DST_SET (1 << 3) | |
117 | #define MATCH_PORT_SRC_RANGE_SET (1 << 4) | |
118 | #define MATCH_PORT_DST_RANGE_SET (1 << 5) | |
4977bd6c PG |
119 | #define MATCH_DSCP_SET (1 << 6) |
120 | #define MATCH_DSCP_INVERSE_SET (1 << 7) | |
cfaf18ce | 121 | #define MATCH_PKT_LEN_INVERSE_SET (1 << 8) |
6f5617d8 | 122 | #define MATCH_FRAGMENT_INVERSE_SET (1 << 9) |
3bed2363 | 123 | #define MATCH_ICMP_SET (1 << 10) |
f449d223 | 124 | #define MATCH_PROTOCOL_SET (1 << 11) |
2e1f721e | 125 | |
0031a6bb PG |
126 | extern int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s, |
127 | struct pbr_rule *zrule); | |
128 | ||
5e244469 RW |
129 | #ifdef __cplusplus |
130 | } | |
131 | #endif | |
132 | ||
0031a6bb | 133 | #endif /* _PBR_H */ |