]> git.proxmox.com Git - mirror_frr.git/blob - lib/pbr.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / pbr.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Policy Based Routing (PBR) main header
3 * Copyright (C) 2018 6WIND
4 */
5
6 #ifndef _PBR_H
7 #define _PBR_H
8
9 #include <zebra.h>
10 #include "stream.h"
11 #include "prefix.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #define PBR_STR "Policy Based Routing\n"
18
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 */
27 struct pbr_filter {
28 uint32_t filter_bm; /* not encoded by zapi
29 */
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)
38 #define PBR_FILTER_DSFIELD (1 << 8)
39 #define PBR_FILTER_IP_PROTOCOL (1 << 9)
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 */
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
52 /* Filter by Differentiated Services field */
53 uint8_t dsfield; /* DSCP (6 bits) & ECN (2 bits) */
54
55 /* Filter with fwmark */
56 uint32_t fwmark;
57
58 /* Filter with the ip protocol */
59 uint8_t ip_proto;
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 */
71 struct pbr_action {
72 /* VLAN */
73 uint8_t pcp;
74 uint16_t vlan_id;
75 uint16_t vlan_flags;
76
77 uint32_t queue_id;
78
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 */
89 struct 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;
97
98 char ifname[INTERFACE_NAMSIZ + 1];
99 };
100
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
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)
124 #define MATCH_DSCP_SET (1 << 6)
125 #define MATCH_DSCP_INVERSE_SET (1 << 7)
126 #define MATCH_PKT_LEN_INVERSE_SET (1 << 8)
127 #define MATCH_FRAGMENT_INVERSE_SET (1 << 9)
128 #define MATCH_ICMP_SET (1 << 10)
129 #define MATCH_PROTOCOL_SET (1 << 11)
130 #define MATCH_FLOW_LABEL_SET (1 << 12)
131 #define MATCH_FLOW_LABEL_INVERSE_SET (1 << 13)
132
133 extern int zapi_pbr_rule_encode(uint8_t cmd, struct stream *s,
134 struct pbr_rule *zrule);
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* _PBR_H */