Apache Mesos
basic.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __LINUX_ROUTING_FILTER_BASIC_HPP__
18 #define __LINUX_ROUTING_FILTER_BASIC_HPP__
19 
20 #include <stdint.h>
21 
22 #include <string>
23 
24 #include <stout/option.hpp>
25 #include <stout/try.hpp>
26 
27 #include "linux/routing/handle.hpp"
28 
32 
33 // This is a work around. Including <linux/if_ether.h> causes
34 // duplicated definitions on some platforms with old glibc.
35 #ifndef ETH_P_ALL
36 #define ETH_P_ALL 0x0003
37 #endif
38 #ifndef ETH_P_ARP
39 #define ETH_P_ARP 0x0806
40 #endif
41 
42 namespace routing {
43 namespace filter {
44 namespace basic {
45 
46 // The classifier for the basic filter only contains a protocol.
47 struct Classifier
48 {
49  explicit Classifier(uint16_t _protocol)
50  : protocol(_protocol) {}
51 
52  bool operator==(const Classifier& that) const
53  {
54  return protocol == that.protocol;
55  }
56 
57  uint16_t protocol;
58 };
59 
60 
61 // Returns true if a basic packet filter with given protocol attached
62 // to the given parent exists on the link.
64  const std::string& link,
65  const Handle& parent,
66  uint16_t protocol);
67 
68 
69 // Creates a basic packet filter with given protocol attached to the
70 // given parent on the link which will set the classid for packets.
71 // Returns false if a basic packet filter with the given protocol
72 // attached to the given parent already exists on the link. The user
73 // can choose to specify an optional priority for the filter.
75  const std::string& link,
76  const Handle& parent,
77  uint16_t protocol,
78  const Option<Priority>& priority,
79  const Option<Handle>& classid);
80 
81 
82 // Creates a basic packet filter with given protocol attached to the
83 // given parent on the link which will redirect all matched packets to
84 // the target link. Returns false if a basic packet filter with the
85 // given protocol attached to the given parent already exists on the
86 // link. The user can choose to specify an optional priority for the
87 // filter.
89  const std::string& link,
90  const Handle& parent,
91  uint16_t protocol,
92  const Option<Priority>& priority,
93  const action::Redirect& redirect);
94 
95 
96 // Creates a basic packet filter with given protocol attached to the
97 // given parent on the link which will mirror all matched packets to a
98 // set of links (specified in the mirror action). Returns false if a
99 // basic packet filter with the give protocol attached to the given
100 // parent already exists on the link. The user can choose to specify
101 // an optional priority for the filter.
103  const std::string& link,
104  const Handle& parent,
105  uint16_t protocol,
106  const Option<Priority>& priority,
107  const action::Mirror& mirror);
108 
109 
110 // Removes the basic packet filter with given protocol attached to
111 // the parent from the link. Returns false if no basic packet filter
112 // with the given protocol attached to the given parent is found on
113 // the link.
114 Try<bool> remove(
115  const std::string& link,
116  const Handle& parent,
117  uint16_t protocol);
118 
119 
120 // Updates the action of a basic packet filter with give protocol
121 // attached to the given parent on the link. Returns false if no
122 // basic packet filter with the given protocol attached to the parent
123 // is found on the link.
125  const std::string& link,
126  const Handle& parent,
127  uint16_t protocol,
128  const action::Mirror& mirror);
129 
130 } // namespace basic {
131 } // namespace filter {
132 } // namespace routing {
133 
134 #endif // __LINUX_ROUTING_FILTER_BASIC_HPP__
Definition: option.hpp:29
Try< bool > update(const std::string &link, const Handle &parent, uint16_t protocol, const action::Mirror &mirror)
Definition: check.hpp:33
Definition: handle.hpp:38
Try< bool > exists(const std::string &link, const Handle &parent, uint16_t protocol)
Future< Nothing > redirect(int_fd from, Option< int_fd > to, size_t chunk=4096, const std::vector< lambda::function< void(const std::string &)>> &hooks={})
Redirect output from the &#39;from&#39; file descriptor to the &#39;to&#39; file descriptor (or /dev/null if &#39;to&#39; is ...
Definition: action.hpp:41
Classifier(uint16_t _protocol)
Definition: basic.hpp:49
Try< bool > create(const std::string &link, const Handle &parent, uint16_t protocol, const Option< Priority > &priority, const Option< Handle > &classid)
uint16_t protocol
Definition: basic.hpp:57
bool operator==(const Classifier &that) const
Definition: basic.hpp:52
Definition: diagnosis.hpp:30
Try< uint32_t > classid(const std::string &hierarchy, const std::string &cgroup)
Definition: action.hpp:54
Definition: basic.hpp:47
void filter(Filter *filter)