Maciej Żenczykowski | b70da76 | 2019-01-28 15:20:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Maciej Żenczykowski | eec7208 | 2020-02-04 23:29:41 -0800 | [diff] [blame] | 17 | #include "OffloadUtils.h" |
Maciej Żenczykowski | b70da76 | 2019-01-28 15:20:48 -0800 | [diff] [blame] | 18 | |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 19 | #include <arpa/inet.h> |
Maciej Żenczykowski | 0a7dce8 | 2019-01-28 15:31:55 -0800 | [diff] [blame] | 20 | #include <linux/if.h> |
Maciej Żenczykowski | 7330b02 | 2019-01-28 17:30:24 -0800 | [diff] [blame] | 21 | #include <linux/netlink.h> |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 22 | #include <linux/pkt_cls.h> |
Maciej Żenczykowski | ff3308d | 2019-02-12 19:10:55 -0800 | [diff] [blame] | 23 | #include <linux/pkt_sched.h> |
Maciej Żenczykowski | 0a7dce8 | 2019-01-28 15:31:55 -0800 | [diff] [blame] | 24 | #include <sys/ioctl.h> |
| 25 | #include <sys/socket.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <unistd.h> |
| 28 | |
Maciej Żenczykowski | eec7208 | 2020-02-04 23:29:41 -0800 | [diff] [blame] | 29 | #define LOG_TAG "OffloadUtils" |
Maciej Żenczykowski | b70da76 | 2019-01-28 15:20:48 -0800 | [diff] [blame] | 30 | #include <log/log.h> |
| 31 | |
Maciej Żenczykowski | 7330b02 | 2019-01-28 17:30:24 -0800 | [diff] [blame] | 32 | #include "NetlinkCommands.h" |
Maciej Żenczykowski | 0a7dce8 | 2019-01-28 15:31:55 -0800 | [diff] [blame] | 33 | #include "android-base/unique_fd.h" |
| 34 | |
Maciej Żenczykowski | b70da76 | 2019-01-28 15:20:48 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | namespace net { |
| 37 | |
Maciej Żenczykowski | 0a7dce8 | 2019-01-28 15:31:55 -0800 | [diff] [blame] | 38 | int hardwareAddressType(const std::string& interface) { |
| 39 | base::unique_fd ufd(socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)); |
| 40 | |
| 41 | if (ufd < 0) { |
| 42 | const int err = errno; |
| 43 | ALOGE("socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0)"); |
| 44 | return -err; |
| 45 | }; |
| 46 | |
| 47 | struct ifreq ifr = {}; |
| 48 | // We use strncpy() instead of strlcpy() since kernel has to be able |
| 49 | // to handle non-zero terminated junk passed in by userspace anyway, |
| 50 | // and this way too long interface names (more than IFNAMSIZ-1 = 15 |
| 51 | // characters plus terminating NULL) will not get truncated to 15 |
| 52 | // characters and zero-terminated and thus potentially erroneously |
| 53 | // match a truncated interface if one were to exist. |
| 54 | strncpy(ifr.ifr_name, interface.c_str(), sizeof(ifr.ifr_name)); |
| 55 | |
| 56 | if (ioctl(ufd, SIOCGIFHWADDR, &ifr, sizeof(ifr))) return -errno; |
| 57 | |
| 58 | return ifr.ifr_hwaddr.sa_family; |
| 59 | } |
| 60 | |
Maciej Żenczykowski | 7330b02 | 2019-01-28 17:30:24 -0800 | [diff] [blame] | 61 | // TODO: use //system/netd/server/NetlinkCommands.cpp:openNetlinkSocket(protocol) |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 62 | // and //system/netd/server/SockDiag.cpp:checkError(fd) |
| 63 | static int sendAndProcessNetlinkResponse(const void* req, int len) { |
Maciej Żenczykowski | 7330b02 | 2019-01-28 17:30:24 -0800 | [diff] [blame] | 64 | base::unique_fd fd(socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE)); |
| 65 | if (fd == -1) { |
| 66 | const int err = errno; |
| 67 | ALOGE("socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE)"); |
| 68 | return -err; |
| 69 | } |
| 70 | |
Maciej Żenczykowski | 7330b02 | 2019-01-28 17:30:24 -0800 | [diff] [blame] | 71 | const int on = 1; |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 72 | int rv = setsockopt(fd, SOL_NETLINK, NETLINK_CAP_ACK, &on, sizeof(on)); |
Maciej Żenczykowski | 7330b02 | 2019-01-28 17:30:24 -0800 | [diff] [blame] | 73 | if (rv) ALOGE("setsockopt(fd, SOL_NETLINK, NETLINK_CAP_ACK, %d)", on); |
| 74 | |
| 75 | // this is needed to get sane strace netlink parsing, it allocates the pid |
| 76 | rv = bind(fd, (const struct sockaddr*)&KERNEL_NLADDR, sizeof(KERNEL_NLADDR)); |
| 77 | if (rv) { |
| 78 | const int err = errno; |
| 79 | ALOGE("bind(fd, {AF_NETLINK, 0, 0})"); |
| 80 | return -err; |
| 81 | } |
| 82 | |
| 83 | // we do not want to receive messages from anyone besides the kernel |
| 84 | rv = connect(fd, (const struct sockaddr*)&KERNEL_NLADDR, sizeof(KERNEL_NLADDR)); |
| 85 | if (rv) { |
| 86 | const int err = errno; |
| 87 | ALOGE("connect(fd, {AF_NETLINK, 0, 0})"); |
| 88 | return -err; |
| 89 | } |
| 90 | |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 91 | rv = send(fd, req, len, 0); |
Maciej Żenczykowski | 841ec72 | 2020-02-12 03:52:28 -0800 | [diff] [blame] | 92 | if (rv == -1) return -errno; |
| 93 | if (rv != len) return -EMSGSIZE; |
| 94 | |
Maciej Żenczykowski | 992a51d | 2019-02-11 18:06:56 -0800 | [diff] [blame] | 95 | struct { |
| 96 | nlmsghdr h; |
| 97 | nlmsgerr e; |
| 98 | char buf[256]; |
| 99 | } resp = {}; |
| 100 | |
Maciej Żenczykowski | 841ec72 | 2020-02-12 03:52:28 -0800 | [diff] [blame] | 101 | rv = recv(fd, &resp, sizeof(resp), MSG_TRUNC); |
Maciej Żenczykowski | 992a51d | 2019-02-11 18:06:56 -0800 | [diff] [blame] | 102 | |
| 103 | if (rv == -1) { |
| 104 | const int err = errno; |
| 105 | ALOGE("recv() failed"); |
| 106 | return -err; |
| 107 | } |
| 108 | |
| 109 | if (rv < (int)NLMSG_SPACE(sizeof(struct nlmsgerr))) { |
| 110 | ALOGE("recv() returned short packet: %d", rv); |
| 111 | return -EMSGSIZE; |
| 112 | } |
| 113 | |
| 114 | if (resp.h.nlmsg_len != (unsigned)rv) { |
| 115 | ALOGE("recv() returned invalid header length: %d != %d", resp.h.nlmsg_len, rv); |
| 116 | return -EBADMSG; |
| 117 | } |
| 118 | |
| 119 | if (resp.h.nlmsg_type != NLMSG_ERROR) { |
| 120 | ALOGE("recv() did not return NLMSG_ERROR message: %d", resp.h.nlmsg_type); |
| 121 | return -EBADMSG; |
| 122 | } |
| 123 | |
| 124 | return resp.e.error; // returns 0 on success |
| 125 | } |
| 126 | |
Maciej Żenczykowski | ff3308d | 2019-02-12 19:10:55 -0800 | [diff] [blame] | 127 | // ADD: nlMsgType=RTM_NEWQDISC nlMsgFlags=NLM_F_EXCL|NLM_F_CREATE |
| 128 | // REPLACE: nlMsgType=RTM_NEWQDISC nlMsgFlags=NLM_F_CREATE|NLM_F_REPLACE |
| 129 | // DEL: nlMsgType=RTM_DELQDISC nlMsgFlags=0 |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 130 | int doTcQdiscClsact(int ifIndex, uint16_t nlMsgType, uint16_t nlMsgFlags) { |
Maciej Żenczykowski | ff3308d | 2019-02-12 19:10:55 -0800 | [diff] [blame] | 131 | // This is the name of the qdisc we are attaching. |
| 132 | // Some hoop jumping to make this compile time constant with known size, |
| 133 | // so that the structure declaration is well defined at compile time. |
| 134 | #define CLSACT "clsact" |
| 135 | static const char clsact[] = CLSACT; |
| 136 | // sizeof() includes the terminating NULL |
| 137 | #define ASCIIZ_LEN_CLSACT sizeof(clsact) |
| 138 | |
| 139 | const struct { |
| 140 | nlmsghdr n; |
| 141 | tcmsg t; |
| 142 | struct { |
| 143 | nlattr attr; |
| 144 | char str[NLMSG_ALIGN(ASCIIZ_LEN_CLSACT)]; |
| 145 | } kind; |
| 146 | } req = { |
| 147 | .n = |
| 148 | { |
| 149 | .nlmsg_len = sizeof(req), |
| 150 | .nlmsg_type = nlMsgType, |
| 151 | .nlmsg_flags = static_cast<__u16>(NETLINK_REQUEST_FLAGS | nlMsgFlags), |
| 152 | }, |
| 153 | .t = |
| 154 | { |
| 155 | .tcm_family = AF_UNSPEC, |
| 156 | .tcm_ifindex = ifIndex, |
| 157 | .tcm_handle = TC_H_MAKE(TC_H_CLSACT, 0), |
| 158 | .tcm_parent = TC_H_CLSACT, |
| 159 | }, |
| 160 | .kind = |
| 161 | { |
| 162 | .attr = |
| 163 | { |
| 164 | .nla_len = NLA_HDRLEN + ASCIIZ_LEN_CLSACT, |
| 165 | .nla_type = TCA_KIND, |
| 166 | }, |
| 167 | .str = CLSACT, |
| 168 | }, |
| 169 | }; |
| 170 | #undef ASCIIZ_LEN_CLSACT |
| 171 | #undef CLSACT |
| 172 | |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 173 | return sendAndProcessNetlinkResponse(&req, sizeof(req)); |
Maciej Żenczykowski | ff3308d | 2019-02-12 19:10:55 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 176 | // tc filter add dev .. in/egress prio 1 protocol ipv6/ip bpf object-pinned /sys/fs/bpf/... |
| 177 | // direct-action |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 178 | int tcFilterAddDevBpf(int ifIndex, int bpfFd, bool ethernet, bool ingress, bool ipv6) { |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 179 | // The priority doesn't matter until we actually start attaching multiple |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 180 | // things to the same interface's in/egress point. |
| 181 | const __u32 prio = 1; |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 182 | |
| 183 | // This is the name of the filter we're attaching (ie. this is the 'bpf' |
| 184 | // packet classifier enabled by kernel config option CONFIG_NET_CLS_BPF. |
| 185 | // |
| 186 | // We go through some hoops in order to make this compile time constants |
| 187 | // so that we can define the struct further down the function with the |
| 188 | // field for this sized correctly already during the build. |
| 189 | #define BPF "bpf" |
| 190 | const char bpf[] = BPF; |
| 191 | // sizeof() includes the terminating NULL |
| 192 | #define ASCIIZ_LEN_BPF sizeof(bpf) |
| 193 | |
| 194 | // This is to replicate program name suffix used by 'tc' Linux cli |
| 195 | // when it attaches programs. |
| 196 | #define FSOBJ_SUFFIX ":[*fsobj]" |
| 197 | |
| 198 | // This macro expands (from header files) to: |
| 199 | // prog_clatd_schedcls_ingress_clat_rawip:[*fsobj] |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 200 | // and is the name of the pinned ingress ebpf program for ARPHRD_RAWIP interfaces. |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 201 | // (also compatible with anything that has 0 size L2 header) |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 202 | #define NAME_RX_RAWIP CLAT_INGRESS_PROG_RAWIP_NAME FSOBJ_SUFFIX |
| 203 | const char name_rx_rawip[] = NAME_RX_RAWIP; |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 204 | |
| 205 | // This macro expands (from header files) to: |
| 206 | // prog_clatd_schedcls_ingress_clat_ether:[*fsobj] |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 207 | // and is the name of the pinned ingress ebpf program for ARPHRD_ETHER interfaces. |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 208 | // (also compatible with anything that has standard ethernet header) |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 209 | #define NAME_RX_ETHER CLAT_INGRESS_PROG_ETHER_NAME FSOBJ_SUFFIX |
| 210 | const char name_rx_ether[] = NAME_RX_ETHER; |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 211 | |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 212 | // This macro expands (from header files) to: |
| 213 | // prog_clatd_schedcls_egress_clat_rawip:[*fsobj] |
| 214 | // and is the name of the pinned egress ebpf program for ARPHRD_RAWIP interfaces. |
| 215 | // (also compatible with anything that has 0 size L2 header) |
| 216 | #define NAME_TX_RAWIP CLAT_EGRESS_PROG_RAWIP_NAME FSOBJ_SUFFIX |
| 217 | const char name_tx_rawip[] = NAME_TX_RAWIP; |
| 218 | |
| 219 | // This macro expands (from header files) to: |
| 220 | // prog_clatd_schedcls_egress_clat_ether:[*fsobj] |
| 221 | // and is the name of the pinned egress ebpf program for ARPHRD_ETHER interfaces. |
| 222 | // (also compatible with anything that has standard ethernet header) |
| 223 | #define NAME_TX_ETHER CLAT_EGRESS_PROG_ETHER_NAME FSOBJ_SUFFIX |
| 224 | const char name_tx_ether[] = NAME_TX_ETHER; |
| 225 | |
| 226 | // The actual name we'll use is determined at run time via 'ethernet' and 'ingress' |
| 227 | // booleans. We need to compile time allocate enough space in the struct |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 228 | // hence this macro magic to make sure we have enough space for either |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 229 | // possibility. In practice some of these are actually the same size. |
| 230 | #define ASCIIZ_MAXLEN_NAME_RX \ |
| 231 | ((sizeof(name_rx_rawip) > sizeof(name_rx_ether)) ? sizeof(name_rx_rawip) \ |
| 232 | : sizeof(name_rx_ether)) |
| 233 | #define ASCIIZ_MAXLEN_NAME_TX \ |
| 234 | ((sizeof(name_tx_rawip) > sizeof(name_tx_ether)) ? sizeof(name_tx_rawip) \ |
| 235 | : sizeof(name_tx_ether)) |
| 236 | #define ASCIIZ_MAXLEN_NAME \ |
| 237 | ((ASCIIZ_MAXLEN_NAME_RX > ASCIIZ_MAXLEN_NAME_TX) ? ASCIIZ_MAXLEN_NAME_RX \ |
| 238 | : ASCIIZ_MAXLEN_NAME_TX) |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 239 | |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 240 | // These are not compile time constants: NAME is used in strncpy below |
| 241 | #define NAME_RX (ethernet ? NAME_RX_ETHER : NAME_RX_RAWIP) |
| 242 | #define NAME_TX (ethernet ? NAME_TX_ETHER : NAME_TX_RAWIP) |
| 243 | #define NAME (ingress ? NAME_RX : NAME_TX) |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 244 | |
| 245 | struct { |
| 246 | nlmsghdr n; |
| 247 | tcmsg t; |
| 248 | struct { |
| 249 | nlattr attr; |
| 250 | char str[NLMSG_ALIGN(ASCIIZ_LEN_BPF)]; |
| 251 | } kind; |
| 252 | struct { |
| 253 | nlattr attr; |
| 254 | struct { |
| 255 | nlattr attr; |
| 256 | __u32 u32; |
| 257 | } fd; |
| 258 | struct { |
| 259 | nlattr attr; |
| 260 | char str[NLMSG_ALIGN(ASCIIZ_MAXLEN_NAME)]; |
| 261 | } name; |
| 262 | struct { |
| 263 | nlattr attr; |
| 264 | __u32 u32; |
| 265 | } flags; |
| 266 | } options; |
| 267 | } req = { |
| 268 | .n = |
| 269 | { |
| 270 | .nlmsg_len = sizeof(req), |
| 271 | .nlmsg_type = RTM_NEWTFILTER, |
| 272 | .nlmsg_flags = NETLINK_REQUEST_FLAGS | NLM_F_EXCL | NLM_F_CREATE, |
| 273 | }, |
| 274 | .t = |
| 275 | { |
| 276 | .tcm_family = AF_UNSPEC, |
| 277 | .tcm_ifindex = ifIndex, |
| 278 | .tcm_handle = TC_H_UNSPEC, |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 279 | .tcm_parent = TC_H_MAKE(TC_H_CLSACT, |
| 280 | ingress ? TC_H_MIN_INGRESS : TC_H_MIN_EGRESS), |
| 281 | .tcm_info = (prio << 16) | |
| 282 | (__u32)(ipv6 ? htons(ETH_P_IPV6) : htons(ETH_P_IP)), |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 283 | }, |
| 284 | .kind = |
| 285 | { |
| 286 | .attr = |
| 287 | { |
| 288 | .nla_len = sizeof(req.kind), |
| 289 | .nla_type = TCA_KIND, |
| 290 | }, |
| 291 | .str = BPF, |
| 292 | }, |
| 293 | .options = |
| 294 | { |
| 295 | .attr = |
| 296 | { |
| 297 | .nla_len = sizeof(req.options), |
| 298 | .nla_type = TCA_OPTIONS, |
| 299 | }, |
| 300 | .fd = |
| 301 | { |
| 302 | .attr = |
| 303 | { |
| 304 | .nla_len = sizeof(req.options.fd), |
| 305 | .nla_type = TCA_BPF_FD, |
| 306 | }, |
| 307 | .u32 = static_cast<__u32>(bpfFd), |
| 308 | }, |
| 309 | .name = |
| 310 | { |
| 311 | .attr = |
| 312 | { |
| 313 | .nla_len = sizeof(req.options.name), |
| 314 | .nla_type = TCA_BPF_NAME, |
| 315 | }, |
| 316 | // Visible via 'tc filter show', but |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 317 | // is overwritten by strncpy below |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 318 | .str = "placeholder", |
| 319 | }, |
| 320 | .flags = |
| 321 | { |
| 322 | .attr = |
| 323 | { |
| 324 | .nla_len = sizeof(req.options.flags), |
| 325 | .nla_type = TCA_BPF_FLAGS, |
| 326 | }, |
| 327 | .u32 = TCA_BPF_FLAG_ACT_DIRECT, |
| 328 | }, |
| 329 | }, |
| 330 | }; |
| 331 | |
| 332 | strncpy(req.options.name.str, NAME, sizeof(req.options.name.str)); |
| 333 | |
| 334 | #undef NAME |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 335 | #undef NAME_TX |
| 336 | #undef NAME_RX |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 337 | #undef ASCIIZ_MAXLEN_NAME |
Maciej Żenczykowski | a06943c | 2019-12-15 11:57:42 -0800 | [diff] [blame] | 338 | #undef ASCIIZ_MAXLEN_NAME_TX |
| 339 | #undef ASCIIZ_MAXLEN_NAME_RX |
| 340 | #undef NAME_TX_ETHER |
| 341 | #undef NAME_TX_RAWIP |
| 342 | #undef NAME_RX_ETHER |
| 343 | #undef NAME_RX_RAWIP |
| 344 | #undef FSOBJ_SUFFIX |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 345 | #undef ASCIIZ_LEN_BPF |
| 346 | #undef BPF |
| 347 | |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 348 | return sendAndProcessNetlinkResponse(&req, sizeof(req)); |
Maciej Żenczykowski | 2f8ff89 | 2019-03-25 13:57:20 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Maciej Żenczykowski | f124738 | 2020-02-05 00:44:14 -0800 | [diff] [blame] | 351 | // tc filter del dev .. in/egress prio .. protocol .. |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 352 | int tcFilterDelDev(int ifIndex, bool ingress, uint16_t prio, uint16_t proto) { |
Maciej Żenczykowski | f124738 | 2020-02-05 00:44:14 -0800 | [diff] [blame] | 353 | struct { |
| 354 | nlmsghdr n; |
| 355 | tcmsg t; |
| 356 | } req = { |
| 357 | .n = |
| 358 | { |
| 359 | .nlmsg_len = sizeof(req), |
| 360 | .nlmsg_type = RTM_DELTFILTER, |
| 361 | .nlmsg_flags = NETLINK_REQUEST_FLAGS, |
| 362 | }, |
| 363 | .t = |
| 364 | { |
| 365 | .tcm_family = AF_UNSPEC, |
| 366 | .tcm_ifindex = ifIndex, |
| 367 | .tcm_handle = TC_H_UNSPEC, |
| 368 | .tcm_parent = TC_H_MAKE(TC_H_CLSACT, |
| 369 | ingress ? TC_H_MIN_INGRESS : TC_H_MIN_EGRESS), |
| 370 | .tcm_info = static_cast<__u32>((prio << 16) | htons(proto)), |
| 371 | }, |
| 372 | }; |
| 373 | |
Maciej Żenczykowski | f89e911 | 2020-02-12 05:22:56 -0800 | [diff] [blame^] | 374 | return sendAndProcessNetlinkResponse(&req, sizeof(req)); |
Maciej Żenczykowski | f124738 | 2020-02-05 00:44:14 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Maciej Żenczykowski | b70da76 | 2019-01-28 15:20:48 -0800 | [diff] [blame] | 377 | } // namespace net |
| 378 | } // namespace android |