mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00

This is an implementation of PBR for FRR. This implemenation uses a combination of rules and tables to determine how packets will flow. PBR introduces a new concept of 'nexthop-groups' to specify a group of nexthops that will be used for ecmp. Nexthop-groups are specified on the cli via: nexthop-group DONNA nexthop 192.168.208.1 nexthop 192.168.209.1 nexthop 192.168.210.1 ! PBR sees the nexthop-group and installs these as a default route with these nexthops starting at table 10000 robot# show pbr nexthop-groups Nexthop-Group: DONNA Table: 10001 Valid: 1 Installed: 1 Valid: 1 nexthop 192.168.209.1 Valid: 1 nexthop 192.168.210.1 Valid: 1 nexthop 192.168.208.1 I have also introduced the ability to specify a table in a 'show ip route table XXX' to see the specified tables. robot# show ip route table 10001 Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF, I - IS-IS, B - BGP, P - PIM, E - EIGRP, N - NHRP, T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP, F - PBR, > - selected route, * - FIB route F>* 0.0.0.0/0 [0/0] via 192.168.208.1, enp0s8, 00:14:25 * via 192.168.209.1, enp0s9, 00:14:25 * via 192.168.210.1, enp0s10, 00:14:25 PBR tracks PBR-MAPS via the pbr-map command: ! pbr-map EVA seq 10 match src-ip 4.3.4.0/24 set nexthop-group DONNA ! pbr-map EVA seq 20 match dst-ip 4.3.5.0/24 set nexthop-group DONNA ! pbr-maps can have 'match src-ip <prefix>' and 'match dst-ip <prefix>' to affect decisions about incoming packets. Additionally if you only have one nexthop to use for a pbr-map you do not need to setup a nexthop-group and can specify 'set nexthop XXXX'. To apply the pbr-map to an incoming interface you do this: interface enp0s10 pbr-policy EVA ! When a pbr-map is applied to interfaces it can be installed into the kernel as a rule: [sharpd@robot frr1]$ ip rule show 0: from all lookup local 309: from 4.3.4.0/24 iif enp0s10 lookup 10001 319: from all to 4.3.5.0/24 iif enp0s10 lookup 10001 1000: from all lookup [l3mdev-table] 32766: from all lookup main 32767: from all lookup default [sharpd@robot frr1]$ ip route show table 10001 default proto pbr metric 20 nexthop via 192.168.208.1 dev enp0s8 weight 1 nexthop via 192.168.209.1 dev enp0s9 weight 1 nexthop via 192.168.210.1 dev enp0s10 weight 1 The linux kernel now will use the rules and tables to properly apply these policies. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Signed-off-by: Don Slice <dslice@cumulusnetworks.com> Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
138 lines
2.8 KiB
C
138 lines
2.8 KiB
C
/*
|
|
* PBR-event Header
|
|
* Copyright (C) 2018 Cumulus Networks, Inc.
|
|
* Donald Sharp
|
|
*
|
|
* This file is part of FRR.
|
|
*
|
|
* FRR is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
* later version.
|
|
*
|
|
* FRR is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
#ifndef __PBR_EVENT_H__
|
|
#define __PBR_EVENT_H__
|
|
|
|
enum pbr_events {
|
|
/*
|
|
* A NHG has been added to the system, handle it
|
|
*/
|
|
PBR_NHG_NEW,
|
|
|
|
/*
|
|
* A NHG has been modified( added a new nexthop )
|
|
*/
|
|
PBR_NHG_ADD_NEXTHOP,
|
|
|
|
/*
|
|
* A NHG has been modified( deleted a nexthop )
|
|
*/
|
|
PBR_NHG_DEL_NEXTHOP,
|
|
|
|
/*
|
|
* A NHG has been deleted from the system
|
|
*/
|
|
PBR_NHG_DELETE,
|
|
|
|
/*
|
|
* A individual nexthop has been added
|
|
*/
|
|
PBR_MAP_NEXTHOP_ADD,
|
|
|
|
/*
|
|
* A individual nexthop has been deleted
|
|
*/
|
|
PBR_MAP_NEXTHOP_DELETE,
|
|
|
|
/*
|
|
* A nexthop group has been added to a pbr-map
|
|
*/
|
|
PBR_MAP_NHG_ADD,
|
|
|
|
/*
|
|
* A nexthop group has been deleted from a pbr-map
|
|
*/
|
|
PBR_MAP_NHG_DELETE,
|
|
|
|
/*
|
|
* A new pbr-map has been created
|
|
*/
|
|
PBR_MAP_ADD,
|
|
|
|
/*
|
|
* The pbr-map has been modified in some fashion
|
|
*/
|
|
PBR_MAP_MODIFY,
|
|
|
|
/*
|
|
* The pbr-map has been deleted from the system
|
|
*/
|
|
PBR_MAP_DELETE,
|
|
|
|
/*
|
|
* Start the sequence of events to install/remove the policy
|
|
* from being installed
|
|
*/
|
|
PBR_MAP_INSTALL,
|
|
|
|
/*
|
|
* We believe we have gotten enough information to actually
|
|
* install the rule portion, since the nexthops are installed
|
|
*/
|
|
PBR_MAP_POLICY_INSTALL,
|
|
|
|
/*
|
|
* Callbacks for a Nexthop in a nexthop group has been
|
|
* changed in some fashion
|
|
*/
|
|
PBR_NH_CHANGED,
|
|
|
|
/*
|
|
* Callback for when a policy has been applied to an interface
|
|
*/
|
|
PBR_POLICY_CHANGED,
|
|
|
|
/*
|
|
* Callback for when a interface has been issued a no
|
|
* policy command
|
|
*/
|
|
PBR_POLICY_DELETED,
|
|
};
|
|
|
|
struct pbr_event {
|
|
enum pbr_events event;
|
|
|
|
char name[100];
|
|
union g_addr addr;
|
|
uint32_t seqno;
|
|
};
|
|
|
|
/*
|
|
* Return a event structure that can be filled in and enqueued.
|
|
* Assume this memory is owned by the event subsystem.
|
|
*/
|
|
extern struct pbr_event *pbr_event_new(enum pbr_events ev, const char *name);
|
|
|
|
/*
|
|
* Free the associated pbr_event item
|
|
*/
|
|
extern void pbr_event_free(struct pbr_event **pbre);
|
|
|
|
/*
|
|
* Enqueue an event for later processing
|
|
*/
|
|
void pbr_event_enqueue(struct pbr_event *pbre);
|
|
|
|
extern void pbr_event_init(void);
|
|
extern void pbr_event_stop(void);
|
|
#endif
|