1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 #include <cstdint>
20 #include <linux/rtnetlink.h>
21
22 namespace android {
23
24 int isEthernet(const char *iface, bool &isEthernet);
25
26 int doTcQdiscClsact(int ifIndex, uint16_t nlMsgType, uint16_t nlMsgFlags);
27
tcAddQdiscClsact(int ifIndex)28 static inline int tcAddQdiscClsact(int ifIndex) {
29 return doTcQdiscClsact(ifIndex, RTM_NEWQDISC, NLM_F_EXCL | NLM_F_CREATE);
30 }
31
tcReplaceQdiscClsact(int ifIndex)32 static inline int tcReplaceQdiscClsact(int ifIndex) {
33 return doTcQdiscClsact(ifIndex, RTM_NEWQDISC, NLM_F_CREATE | NLM_F_REPLACE);
34 }
35
tcDeleteQdiscClsact(int ifIndex)36 static inline int tcDeleteQdiscClsact(int ifIndex) {
37 return doTcQdiscClsact(ifIndex, RTM_DELQDISC, 0);
38 }
39
40 int tcAddBpfFilter(int ifIndex, bool ingress, uint16_t prio, uint16_t proto,
41 const char *bpfProgPath);
42 int tcAddIngressPoliceFilter(int ifIndex, uint16_t prio, uint16_t proto,
43 unsigned rateInBytesPerSec,
44 const char *bpfProgPath);
45 int tcDeleteFilter(int ifIndex, bool ingress, uint16_t prio, uint16_t proto);
46
47 } // namespace android
48