]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_pbr.h
Merge pull request #5703 from ton31337/feature/limit_outgoing_prefixes
[mirror_frr.git] / bgpd / bgp_pbr.h
index e869d0106d6f6d24c76506d7057fef4af6c171ff..393b08da4819285da0f92111b98635e487b76c80 100644 (file)
@@ -57,17 +57,13 @@ struct bgp_pbr_match_val {
        uint16_t value;
        uint8_t compare_operator;
        uint8_t unary_operator;
-} bgp_pbr_value_t;
+};
 
 #define FRAGMENT_DONT  1
 #define FRAGMENT_IS    2
 #define FRAGMENT_FIRST 4
 #define FRAGMENT_LAST  8
 
-struct bgp_pbr_fragment_val {
-       uint8_t bitmask;
-};
-
 struct bgp_pbr_entry_action {
        /* used to store enum bgp_pbr_action_enum enumerate */
        uint8_t action;
@@ -91,12 +87,10 @@ struct bgp_pbr_entry_action {
 
 /* BGP Policy Route structure */
 struct bgp_pbr_entry_main {
+#define BGP_PBR_UNDEFINED      0
+#define BGP_PBR_IPSET          1
+#define BGP_PBR_IPRULE         2
        uint8_t type;
-       uint16_t instance;
-
-       uint32_t flags;
-
-       uint8_t message;
 
        /*
         * This is an enum but we are going to treat it as a uint8_t
@@ -107,7 +101,7 @@ struct bgp_pbr_entry_main {
 
 #define PREFIX_SRC_PRESENT (1 << 0)
 #define PREFIX_DST_PRESENT (1 << 1)
-#define FRAGMENT_PRESENT   (1 << 2)
+       uint8_t match_bitmask_iprule;
        uint8_t match_bitmask;
 
        uint8_t match_src_port_num;
@@ -119,6 +113,7 @@ struct bgp_pbr_entry_main {
        uint8_t match_packet_length_num;
        uint8_t match_dscp_num;
        uint8_t match_tcpflags_num;
+       uint8_t match_fragment_num;
 
        struct prefix src_prefix;
        struct prefix dst_prefix;
@@ -134,20 +129,13 @@ struct bgp_pbr_entry_main {
        struct bgp_pbr_match_val icmp_code[BGP_PBR_MATCH_VAL_MAX];
        struct bgp_pbr_match_val packet_length[BGP_PBR_MATCH_VAL_MAX];
        struct bgp_pbr_match_val dscp[BGP_PBR_MATCH_VAL_MAX];
+
        struct bgp_pbr_match_val tcpflags[BGP_PBR_MATCH_VAL_MAX];
-       struct bgp_pbr_fragment_val fragment;
+       struct bgp_pbr_match_val fragment[BGP_PBR_MATCH_VAL_MAX];
 
        uint16_t action_num;
        struct bgp_pbr_entry_action actions[ACTIONS_MAX_NUM];
 
-       uint8_t distance;
-
-       uint32_t metric;
-
-       route_tag_t tag;
-
-       uint32_t mtu;
-
        vrf_id_t vrf_id;
 };
 
@@ -170,6 +158,19 @@ struct bgp_pbr_config {
 
 extern struct bgp_pbr_config *bgp_pbr_cfg;
 
+struct bgp_pbr_rule {
+       uint32_t flags;
+       struct prefix src;
+       struct prefix dst;
+       struct bgp_pbr_action *action;
+       vrf_id_t vrf_id;
+       uint32_t unique;
+       uint32_t priority;
+       bool installed;
+       bool install_in_progress;
+       void *path;
+};
+
 struct bgp_pbr_match {
        char ipset_name[ZEBRA_IPSET_NAME_SIZE];
 
@@ -177,14 +178,16 @@ struct bgp_pbr_match {
         */
        uint32_t type;
 
-#define MATCH_IP_SRC_SET               (1 << 0)
-#define MATCH_IP_DST_SET               (1 << 1)
-#define MATCH_PORT_SRC_SET             (1 << 2)
-#define MATCH_PORT_DST_SET             (1 << 3)
-#define MATCH_PORT_SRC_RANGE_SET       (1 << 4)
-#define MATCH_PORT_DST_RANGE_SET       (1 << 5)
        uint32_t flags;
 
+       uint16_t pkt_len_min;
+       uint16_t pkt_len_max;
+       uint16_t tcp_flags;
+       uint16_t tcp_mask_flags;
+       uint8_t dscp_value;
+       uint8_t fragment;
+       uint8_t protocol;
+
        vrf_id_t vrf_id;
 
        /* unique identifier for ipset create transaction
@@ -221,7 +224,7 @@ struct bgp_pbr_match_entry {
        uint16_t dst_port_max;
        uint8_t proto;
 
-       void *bgp_info;
+       void *path;
 
        bool installed;
        bool install_in_progress;
@@ -253,6 +256,9 @@ struct bgp_pbr_action {
        struct bgp *bgp;
 };
 
+extern struct bgp_pbr_rule *bgp_pbr_rule_lookup(vrf_id_t vrf_id,
+                                               uint32_t unique);
+
 extern struct bgp_pbr_action *bgp_pbr_action_rule_lookup(vrf_id_t vrf_id,
                                                         uint32_t unique);
 
@@ -268,24 +274,26 @@ extern struct bgp_pbr_match *bgp_pbr_match_iptable_lookup(vrf_id_t vrf_id,
 extern void bgp_pbr_cleanup(struct bgp *bgp);
 extern void bgp_pbr_init(struct bgp *bgp);
 
-extern uint32_t bgp_pbr_action_hash_key(void *arg);
-extern int bgp_pbr_action_hash_equal(const void *arg1,
+extern uint32_t bgp_pbr_rule_hash_key(const void *arg);
+extern bool bgp_pbr_rule_hash_equal(const void *arg1,
+                                  const void *arg2);
+extern uint32_t bgp_pbr_action_hash_key(const void *arg);
+extern bool bgp_pbr_action_hash_equal(const void *arg1,
                                     const void *arg2);
-extern uint32_t bgp_pbr_match_entry_hash_key(void *arg);
-extern int bgp_pbr_match_entry_hash_equal(const void *arg1,
+extern uint32_t bgp_pbr_match_entry_hash_key(const void *arg);
+extern bool bgp_pbr_match_entry_hash_equal(const void *arg1,
                                          const void *arg2);
-extern uint32_t bgp_pbr_match_hash_key(void *arg);
-extern int bgp_pbr_match_hash_equal(const void *arg1,
+extern uint32_t bgp_pbr_match_hash_key(const void *arg);
+extern bool bgp_pbr_match_hash_equal(const void *arg1,
                                    const void *arg2);
 
 void bgp_pbr_print_policy_route(struct bgp_pbr_entry_main *api);
 
 struct bgp_node;
-struct bgp_info;
+struct bgp_path_info;
 extern void bgp_pbr_update_entry(struct bgp *bgp, struct prefix *p,
-                                struct bgp_info *new_select,
-                               afi_t afi, safi_t safi,
-                               bool nlri_update);
+                                struct bgp_path_info *new_select, afi_t afi,
+                                safi_t safi, bool nlri_update);
 
 /* bgp pbr utilities */
 extern struct bgp_pbr_interface *pbr_interface_lookup(const char *name);
@@ -293,4 +301,7 @@ extern void bgp_pbr_reset(struct bgp *bgp, afi_t afi);
 extern struct bgp_pbr_interface *bgp_pbr_interface_lookup(const char *name,
                                   struct bgp_pbr_interface_head *head);
 
+extern int bgp_pbr_build_and_validate_entry(struct prefix *p,
+                                           struct bgp_path_info *path,
+                                           struct bgp_pbr_entry_main *api);
 #endif /* __BGP_PBR_H__ */