blob: a8ec2e87c484e2f32dbd9204a060d20c8179de53 [file] [log] [blame]
Patrick Rohr776c40c2022-01-12 21:05:26 +01001/*
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>
Patrick Rohr42b58ae2022-01-17 13:09:12 +010020#include <linux/rtnetlink.h>
Patrick Rohr776c40c2022-01-12 21:05:26 +010021
22namespace android {
23
24int isEthernet(const char *iface, bool &isEthernet);
Patrick Rohr42b58ae2022-01-17 13:09:12 +010025
26int doTcQdiscClsact(int ifIndex, uint16_t nlMsgType, uint16_t nlMsgFlags);
27
28static inline int tcAddQdiscClsact(int ifIndex) {
29 return doTcQdiscClsact(ifIndex, RTM_NEWQDISC, NLM_F_EXCL | NLM_F_CREATE);
30}
31
32static inline int tcReplaceQdiscClsact(int ifIndex) {
33 return doTcQdiscClsact(ifIndex, RTM_NEWQDISC, NLM_F_CREATE | NLM_F_REPLACE);
34}
35
36static inline int tcDeleteQdiscClsact(int ifIndex) {
37 return doTcQdiscClsact(ifIndex, RTM_DELQDISC, 0);
38}
39
Patrick Rohr776c40c2022-01-12 21:05:26 +010040int tcAddBpfFilter(int ifIndex, bool ingress, uint16_t prio, uint16_t proto,
41 const char *bpfProgPath);
Patrick Rohre815a742022-01-17 10:37:40 +010042int tcAddIngressPoliceFilter(int ifIndex, uint16_t prio, uint16_t proto,
43 unsigned rateInBytesPerSec,
44 const char *bpfProgPath);
Patrick Rohr776c40c2022-01-12 21:05:26 +010045int tcDeleteFilter(int ifIndex, bool ingress, uint16_t prio, uint16_t proto);
46
47} // namespace android