libbgp  0.6
A C++ BGP Library.
bgp-filter.h
Go to the documentation of this file.
1 
11 #ifndef BGP_FILTER_H_
12 #define BGP_FILTER_H_
13 #include <vector>
14 #include <memory>
15 #include "bgp-afi.h"
16 #include "prefix4.h"
17 #include "prefix6.h"
18 #include "bgp-path-attrib.h"
19 
20 namespace libbgp {
21 
30 };
31 
37  M_EQ,
38  M_NE,
39  M_GT,
40  M_LT,
41  M_GE,
43 };
44 
54 };
55 
63 };
64 
70  NOP,
73 };
74 
80 public:
81  uint8_t filter_type;
82  uint8_t match_type;
83  BgpFilterOP op;
84 
92  virtual BgpFilterOP apply(const Prefix &prefix, const std::vector<std::shared_ptr<BgpPathAttrib>> &attribs) = 0;
93  virtual ~BgpFilterRule();
94 };
95 
101 template <typename T>
103 public:
109  filter_type = F_ROUTE;
110  }
111 
117 
118  BgpFilterOP apply(const Prefix &prefix, __attribute__((unused)) const std::vector<std::shared_ptr<BgpPathAttrib>> &attribs) {
119  if (prefix.afi != this->prefix.afi) return NOP;
120  const T &prefix_t = dynamic_cast<const T &>(prefix);
121  switch (match_type) {
122  case M_EQ: return prefix_t == this->prefix ? op : NOP;
123  case M_NE: return prefix_t != this->prefix ? op : NOP;
124  case M_GT: return prefix_t != this->prefix && prefix_t.includes(this->prefix) ? op : NOP;
125  case M_LT: return prefix_t != this->prefix && this->prefix.includes(prefix_t) ? op : NOP;
126  case M_GE: return prefix_t.includes(this->prefix) ? op : NOP;
127  case M_LE: return this->prefix.includes(prefix_t) ? op : NOP;
128  }
129 
130  return NOP;
131  }
132 
137  virtual ~BgpFilterRuleRoute() {}
138 };
139 #ifdef SWIG
140 %template(Prefix4RouteFilterRule) BgpFilterRuleRoute<Prefix4>;
141 %template(Prefix6RouteFilterRule) BgpFilterRuleRoute<Prefix6>;
142 #endif
143 
149 public:
151 };
152 
158 public:
160 };
161 
167 public:
169 
174  uint32_t asn;
175 
176  BgpFilterOP apply(const Prefix &prefix, const std::vector<std::shared_ptr<BgpPathAttrib>> &attribs);
177 };
178 
184  NO_EXPORT = 0xFFFFFF01,
185  NO_ADVERTISE = 0xFFFFFF02,
186  NO_EXPORT_SUBCONFED = 0xFFFFFF03
187 };
188 
194 public:
195  BgpFilterRuleCommunity(BgpFilterOP op, BgpFilterRuleCommunityMatchType type, uint16_t asn, uint16_t keyword);
197 
202  uint32_t community;
203 
204  BgpFilterOP apply(const Prefix &prefix, const std::vector<std::shared_ptr<BgpPathAttrib>> &attribs);
205 };
206 
212 public:
213 
214  BgpFilterRules();
215  BgpFilterRules(BgpFilterOP default_op);
216 
223  template <typename T>
224  void append(const BgpFilterRule &rule) {
225  const T &rule_typed = dynamic_cast<const T&> (rule);
226  rules.push_back(std::shared_ptr<BgpFilterRule>(new T(rule_typed)));
227  }
228 #ifdef SWIG
229 %template(appendAsPathRule) append<BgpFilterRuleAsPath>;
230 %template(appendCommunityRule) append<BgpFilterRuleCommunity>;
231 %template(appendRoute4Rule) append<BgpFilterRuleRoute4>;
232 %template(appendRoute6Rule) append<BgpFilterRuleRoute6>;
233 #endif
234 
235  BgpFilterOP apply(const Prefix &prefix, const std::vector<std::shared_ptr<BgpPathAttrib>> &attribs);
236 private:
237  std::vector<std::shared_ptr<BgpFilterRule>> rules;
238  BgpFilterOP default_op;
239 };
240 
241 }
242 
243 #endif // BGP_FILTER_H_
IPv6 Route/Prefix related utilities.
Definition: prefix6.h:27
The BGP path attributes.
BgpFilterOP
The filter operation.
Definition: bgp-filter.h:69
The AS_PATH filtering rule.
Definition: bgp-filter.h:166
BgpFilterRuleRouteMatchType
Matching type of IP prefix rule.
Definition: bgp-filter.h:36
virtual BgpFilterOP apply(const Prefix &prefix, const std::vector< std::shared_ptr< BgpPathAttrib >> &attribs)=0
Apply the rule on a route.
The IPv4 route filtering rule.
Definition: bgp-filter.h:148
virtual ~BgpFilterRuleRoute()
Destroy the BgpFilterRuleRoute object.
Definition: bgp-filter.h:137
virtual bool includes(const Prefix &other) const =0
Test if another prefix is inside this prefix.
The BGP AFI/SAFI.
The base of BgpFilterRule.
Definition: bgp-filter.h:79
BgpFilterRuleCommunityMatchType
Matching type of COMMUNITY rule.
Definition: bgp-filter.h:60
BgpFilterRuleRoute()
Construct a new BgpFilterRuleRoute object.
Definition: bgp-filter.h:108
IPv4 Route/Prefix related utilities.
Definition: prefix4.h:25
Definition: bgp-afi.h:14
IPv4 Route/Prefix related utilities.
BgpFilterRuleType
Type of filter rule.
Definition: bgp-filter.h:26
uint32_t asn
The ASN of this entry.
Definition: bgp-filter.h:174
IPv6 Route/Prefix related utilities.
Route/Prefix related utilities.
Definition: prefix.h:25
BgpFilterRuleAsPathMatchType
Matching type of AS_PATH rule.
Definition: bgp-filter.h:49
uint32_t community
community for this entry.
Definition: bgp-filter.h:202
The prefix filtering rule.
Definition: bgp-filter.h:102
T prefix
The route prefix.
Definition: bgp-filter.h:116
The BGP filtering rules set.
Definition: bgp-filter.h:211
void append(const BgpFilterRule &rule)
Append a rule to the rule set.
Definition: bgp-filter.h:224
BgpWellKnownCommunity
BGP well-known communities.
Definition: bgp-filter.h:183
The COMMUNITY filtering rule.
Definition: bgp-filter.h:193
The IPv6 route filtering rule.
Definition: bgp-filter.h:157