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