Patrick Rohr | 776c40c | 2022-01-12 21:05:26 +0100 | [diff] [blame] | 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> |
Patrick Rohr | 42b58ae | 2022-01-17 13:09:12 +0100 | [diff] [blame] | 20 | #include <linux/rtnetlink.h> |
Patrick Rohr | 776c40c | 2022-01-12 21:05:26 +0100 | [diff] [blame] | 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | int isEthernet(const char *iface, bool &isEthernet); |
Patrick Rohr | 42b58ae | 2022-01-17 13:09:12 +0100 | [diff] [blame] | 25 | |
| 26 | int doTcQdiscClsact(int ifIndex, uint16_t nlMsgType, uint16_t nlMsgFlags); |
| 27 | |
| 28 | static inline int tcAddQdiscClsact(int ifIndex) { |
| 29 | return doTcQdiscClsact(ifIndex, RTM_NEWQDISC, NLM_F_EXCL | NLM_F_CREATE); |
| 30 | } |
| 31 | |
| 32 | static inline int tcReplaceQdiscClsact(int ifIndex) { |
| 33 | return doTcQdiscClsact(ifIndex, RTM_NEWQDISC, NLM_F_CREATE | NLM_F_REPLACE); |
| 34 | } |
| 35 | |
| 36 | static inline int tcDeleteQdiscClsact(int ifIndex) { |
| 37 | return doTcQdiscClsact(ifIndex, RTM_DELQDISC, 0); |
| 38 | } |
| 39 | |
Patrick Rohr | 776c40c | 2022-01-12 21:05:26 +0100 | [diff] [blame] | 40 | int tcAddBpfFilter(int ifIndex, bool ingress, uint16_t prio, uint16_t proto, |
| 41 | const char *bpfProgPath); |
Patrick Rohr | e815a74 | 2022-01-17 10:37:40 +0100 | [diff] [blame] | 42 | int tcAddIngressPoliceFilter(int ifIndex, uint16_t prio, uint16_t proto, |
| 43 | unsigned rateInBytesPerSec, |
| 44 | const char *bpfProgPath); |
Patrick Rohr | 776c40c | 2022-01-12 21:05:26 +0100 | [diff] [blame] | 45 | int tcDeleteFilter(int ifIndex, bool ingress, uint16_t prio, uint16_t proto); |
| 46 | |
| 47 | } // namespace android |