]>
git.proxmox.com Git - mirror_frr.git/blob - lib/pbr.h
1 /* Policy Based Routing (PBR) main header
2 * Copyright (C) 2018 6WIND
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
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.
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
31 #define PBR_STR "Policy Based Routing\n"
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
42 uint32_t filter_bm
; /* not encoded by zapi
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)
52 #define PBR_FILTER_DSFIELD (1 << 8)
53 #define PBR_FILTER_IP_PROTOCOL (1 << 9)
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 */
58 /* Source and Destination IP address with masks. */
62 /* Source and Destination higher-layer (TCP/UDP) port numbers. */
66 /* Filter by Differentiated Services field */
67 uint8_t dsfield
; /* DSCP (6 bits) & ECN (2 bits) */
69 /* Filter with fwmark */
72 /* Filter with the ip protocol */
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.
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.
109 struct pbr_filter filter
;
110 struct pbr_action action
;
112 char ifname
[INTERFACE_NAMSIZ
+ 1];
115 /* TCP flags value shared
116 * those are values of byte 13 of TCP header
117 * as mentioned in rfc793
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)
129 /* Pbr IPTable defines
130 * those are common flags shared between BGP and Zebra
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)
138 #define MATCH_DSCP_SET (1 << 6)
139 #define MATCH_DSCP_INVERSE_SET (1 << 7)
140 #define MATCH_PKT_LEN_INVERSE_SET (1 << 8)
141 #define MATCH_FRAGMENT_INVERSE_SET (1 << 9)
142 #define MATCH_ICMP_SET (1 << 10)
143 #define MATCH_PROTOCOL_SET (1 << 11)
144 #define MATCH_FLOW_LABEL_SET (1 << 12)
145 #define MATCH_FLOW_LABEL_INVERSE_SET (1 << 13)
147 extern int zapi_pbr_rule_encode(uint8_t cmd
, struct stream
*s
,
148 struct pbr_rule
*zrule
);