]>
git.proxmox.com Git - mirror_frr.git/blob - lib/pbr.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Policy Based Routing (PBR) main header
3 * Copyright (C) 2018 6WIND
17 #define PBR_STR "Policy Based Routing\n"
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
28 uint32_t filter_bm
; /* not encoded by zapi
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)
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 */
44 /* Source and Destination IP address with masks. */
48 /* Source and Destination higher-layer (TCP/UDP) port numbers. */
52 /* Filter by Differentiated Services field */
53 uint8_t dsfield
; /* DSCP (6 bits) & ECN (2 bits) */
55 /* Filter with fwmark */
58 /* Filter with the ip protocol */
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.
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.
95 struct pbr_filter filter
;
96 struct pbr_action action
;
98 char ifname
[INTERFACE_NAMSIZ
+ 1];
101 /* TCP flags value shared
102 * those are values of byte 13 of TCP header
103 * as mentioned in rfc793
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)
115 /* Pbr IPTable defines
116 * those are common flags shared between BGP and Zebra
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)
133 extern int zapi_pbr_rule_encode(uint8_t cmd
, struct stream
*s
,
134 struct pbr_rule
*zrule
);