[efa4154] | 1 | diff -Naupr linux-4.14_orig/drivers/net/imq.c linux-4.14/drivers/net/imq.c |
---|
| 2 | --- linux-4.14_orig/drivers/net/imq.c 1970-01-01 07:00:00.000000000 +0700 |
---|
| 3 | +++ linux-4.14/drivers/net/imq.c 2017-11-13 11:46:45.844089945 +0700 |
---|
| 4 | @@ -0,0 +1,962 @@ |
---|
[6936b89] | 5 | +/* |
---|
| 6 | + * Pseudo-driver for the intermediate queue device. |
---|
| 7 | + * |
---|
| 8 | + * This program is free software; you can redistribute it and/or |
---|
| 9 | + * modify it under the terms of the GNU General Public License |
---|
| 10 | + * as published by the Free Software Foundation; either version |
---|
| 11 | + * 2 of the License, or (at your option) any later version. |
---|
| 12 | + * |
---|
| 13 | + * Authors: Patrick McHardy, <kaber@trash.net> |
---|
| 14 | + * |
---|
| 15 | + * The first version was written by Martin Devera, <devik@cdi.cz> |
---|
| 16 | + * |
---|
[efa4154] | 17 | + * See Credits.txt |
---|
[6936b89] | 18 | + */ |
---|
| 19 | + |
---|
| 20 | +#include <linux/module.h> |
---|
| 21 | +#include <linux/kernel.h> |
---|
| 22 | +#include <linux/moduleparam.h> |
---|
| 23 | +#include <linux/list.h> |
---|
| 24 | +#include <linux/skbuff.h> |
---|
| 25 | +#include <linux/netdevice.h> |
---|
| 26 | +#include <linux/etherdevice.h> |
---|
| 27 | +#include <linux/rtnetlink.h> |
---|
| 28 | +#include <linux/if_arp.h> |
---|
| 29 | +#include <linux/netfilter.h> |
---|
| 30 | +#include <linux/netfilter_ipv4.h> |
---|
| 31 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
---|
[efa4154] | 32 | +#include <linux/netfilter_ipv6.h> |
---|
[6936b89] | 33 | +#endif |
---|
| 34 | +#include <linux/imq.h> |
---|
| 35 | +#include <net/pkt_sched.h> |
---|
| 36 | +#include <net/netfilter/nf_queue.h> |
---|
| 37 | +#include <net/sock.h> |
---|
| 38 | +#include <linux/ip.h> |
---|
| 39 | +#include <linux/ipv6.h> |
---|
| 40 | +#include <linux/if_vlan.h> |
---|
| 41 | +#include <linux/if_pppox.h> |
---|
| 42 | +#include <net/ip.h> |
---|
| 43 | +#include <net/ipv6.h> |
---|
| 44 | + |
---|
| 45 | +static int imq_nf_queue(struct nf_queue_entry *entry, unsigned queue_num); |
---|
| 46 | + |
---|
| 47 | +static nf_hookfn imq_nf_hook; |
---|
| 48 | + |
---|
| 49 | +static struct nf_hook_ops imq_ops[] = { |
---|
| 50 | + { |
---|
| 51 | + /* imq_ingress_ipv4 */ |
---|
| 52 | + .hook = imq_nf_hook, |
---|
| 53 | + .pf = PF_INET, |
---|
| 54 | + .hooknum = NF_INET_PRE_ROUTING, |
---|
| 55 | +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB) |
---|
| 56 | + .priority = NF_IP_PRI_MANGLE + 1, |
---|
| 57 | +#else |
---|
| 58 | + .priority = NF_IP_PRI_NAT_DST + 1, |
---|
| 59 | +#endif |
---|
| 60 | + }, |
---|
| 61 | + { |
---|
| 62 | + /* imq_egress_ipv4 */ |
---|
| 63 | + .hook = imq_nf_hook, |
---|
| 64 | + .pf = PF_INET, |
---|
| 65 | + .hooknum = NF_INET_POST_ROUTING, |
---|
| 66 | +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA) |
---|
| 67 | + .priority = NF_IP_PRI_LAST, |
---|
| 68 | +#else |
---|
| 69 | + .priority = NF_IP_PRI_NAT_SRC - 1, |
---|
| 70 | +#endif |
---|
| 71 | + }, |
---|
| 72 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
---|
| 73 | + { |
---|
| 74 | + /* imq_ingress_ipv6 */ |
---|
| 75 | + .hook = imq_nf_hook, |
---|
| 76 | + .pf = PF_INET6, |
---|
| 77 | + .hooknum = NF_INET_PRE_ROUTING, |
---|
| 78 | +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB) |
---|
| 79 | + .priority = NF_IP6_PRI_MANGLE + 1, |
---|
| 80 | +#else |
---|
| 81 | + .priority = NF_IP6_PRI_NAT_DST + 1, |
---|
| 82 | +#endif |
---|
| 83 | + }, |
---|
| 84 | + { |
---|
| 85 | + /* imq_egress_ipv6 */ |
---|
| 86 | + .hook = imq_nf_hook, |
---|
| 87 | + .pf = PF_INET6, |
---|
| 88 | + .hooknum = NF_INET_POST_ROUTING, |
---|
| 89 | +#if defined(CONFIG_IMQ_BEHAVIOR_AA) || defined(CONFIG_IMQ_BEHAVIOR_BA) |
---|
| 90 | + .priority = NF_IP6_PRI_LAST, |
---|
| 91 | +#else |
---|
| 92 | + .priority = NF_IP6_PRI_NAT_SRC - 1, |
---|
| 93 | +#endif |
---|
| 94 | + }, |
---|
| 95 | +#endif |
---|
| 96 | +}; |
---|
| 97 | + |
---|
| 98 | +#if defined(CONFIG_IMQ_NUM_DEVS) |
---|
| 99 | +static int numdevs = CONFIG_IMQ_NUM_DEVS; |
---|
| 100 | +#else |
---|
| 101 | +static int numdevs = IMQ_MAX_DEVS; |
---|
| 102 | +#endif |
---|
| 103 | + |
---|
| 104 | +static struct net_device *imq_devs_cache[IMQ_MAX_DEVS]; |
---|
| 105 | + |
---|
| 106 | +#define IMQ_MAX_QUEUES 32 |
---|
| 107 | +static int numqueues = 1; |
---|
| 108 | +static u32 imq_hashrnd; |
---|
| 109 | +static int imq_dev_accurate_stats = 1; |
---|
| 110 | + |
---|
| 111 | +static inline __be16 pppoe_proto(const struct sk_buff *skb) |
---|
| 112 | +{ |
---|
| 113 | + return *((__be16 *)(skb_mac_header(skb) + ETH_HLEN + |
---|
| 114 | + sizeof(struct pppoe_hdr))); |
---|
| 115 | +} |
---|
| 116 | + |
---|
| 117 | +static u16 imq_hash(struct net_device *dev, struct sk_buff *skb) |
---|
| 118 | +{ |
---|
| 119 | + unsigned int pull_len; |
---|
| 120 | + u16 protocol = skb->protocol; |
---|
| 121 | + u32 addr1, addr2; |
---|
| 122 | + u32 hash, ihl = 0; |
---|
| 123 | + union { |
---|
| 124 | + u16 in16[2]; |
---|
| 125 | + u32 in32; |
---|
| 126 | + } ports; |
---|
| 127 | + u8 ip_proto; |
---|
| 128 | + |
---|
| 129 | + pull_len = 0; |
---|
| 130 | + |
---|
| 131 | +recheck: |
---|
| 132 | + switch (protocol) { |
---|
| 133 | + case htons(ETH_P_8021Q): { |
---|
| 134 | + if (unlikely(skb_pull(skb, VLAN_HLEN) == NULL)) |
---|
| 135 | + goto other; |
---|
| 136 | + |
---|
| 137 | + pull_len += VLAN_HLEN; |
---|
| 138 | + skb->network_header += VLAN_HLEN; |
---|
| 139 | + |
---|
| 140 | + protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
---|
| 141 | + goto recheck; |
---|
| 142 | + } |
---|
| 143 | + |
---|
| 144 | + case htons(ETH_P_PPP_SES): { |
---|
| 145 | + if (unlikely(skb_pull(skb, PPPOE_SES_HLEN) == NULL)) |
---|
| 146 | + goto other; |
---|
| 147 | + |
---|
| 148 | + pull_len += PPPOE_SES_HLEN; |
---|
| 149 | + skb->network_header += PPPOE_SES_HLEN; |
---|
| 150 | + |
---|
| 151 | + protocol = pppoe_proto(skb); |
---|
| 152 | + goto recheck; |
---|
| 153 | + } |
---|
| 154 | + |
---|
| 155 | + case htons(ETH_P_IP): { |
---|
| 156 | + const struct iphdr *iph = ip_hdr(skb); |
---|
| 157 | + |
---|
| 158 | + if (unlikely(!pskb_may_pull(skb, sizeof(struct iphdr)))) |
---|
| 159 | + goto other; |
---|
| 160 | + |
---|
| 161 | + addr1 = iph->daddr; |
---|
| 162 | + addr2 = iph->saddr; |
---|
| 163 | + |
---|
| 164 | + ip_proto = !(ip_hdr(skb)->frag_off & htons(IP_MF | IP_OFFSET)) ? |
---|
| 165 | + iph->protocol : 0; |
---|
| 166 | + ihl = ip_hdrlen(skb); |
---|
| 167 | + |
---|
| 168 | + break; |
---|
| 169 | + } |
---|
| 170 | +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
---|
| 171 | + case htons(ETH_P_IPV6): { |
---|
| 172 | + const struct ipv6hdr *iph = ipv6_hdr(skb); |
---|
| 173 | + __be16 fo = 0; |
---|
| 174 | + |
---|
| 175 | + if (unlikely(!pskb_may_pull(skb, sizeof(struct ipv6hdr)))) |
---|
| 176 | + goto other; |
---|
| 177 | + |
---|
| 178 | + addr1 = iph->daddr.s6_addr32[3]; |
---|
| 179 | + addr2 = iph->saddr.s6_addr32[3]; |
---|
| 180 | + ihl = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &ip_proto, |
---|
| 181 | + &fo); |
---|
| 182 | + if (unlikely(ihl < 0)) |
---|
| 183 | + goto other; |
---|
| 184 | + |
---|
| 185 | + break; |
---|
| 186 | + } |
---|
| 187 | +#endif |
---|
| 188 | + default: |
---|
| 189 | +other: |
---|
| 190 | + if (pull_len != 0) { |
---|
| 191 | + skb_push(skb, pull_len); |
---|
| 192 | + skb->network_header -= pull_len; |
---|
| 193 | + } |
---|
| 194 | + |
---|
| 195 | + return (u16)(ntohs(protocol) % dev->real_num_tx_queues); |
---|
| 196 | + } |
---|
| 197 | + |
---|
| 198 | + if (addr1 > addr2) |
---|
| 199 | + swap(addr1, addr2); |
---|
| 200 | + |
---|
| 201 | + switch (ip_proto) { |
---|
| 202 | + case IPPROTO_TCP: |
---|
| 203 | + case IPPROTO_UDP: |
---|
| 204 | + case IPPROTO_DCCP: |
---|
| 205 | + case IPPROTO_ESP: |
---|
| 206 | + case IPPROTO_AH: |
---|
| 207 | + case IPPROTO_SCTP: |
---|
| 208 | + case IPPROTO_UDPLITE: { |
---|
| 209 | + if (likely(skb_copy_bits(skb, ihl, &ports.in32, 4) >= 0)) { |
---|
| 210 | + if (ports.in16[0] > ports.in16[1]) |
---|
| 211 | + swap(ports.in16[0], ports.in16[1]); |
---|
| 212 | + break; |
---|
| 213 | + } |
---|
| 214 | + /* fall-through */ |
---|
| 215 | + } |
---|
| 216 | + default: |
---|
| 217 | + ports.in32 = 0; |
---|
| 218 | + break; |
---|
| 219 | + } |
---|
| 220 | + |
---|
| 221 | + if (pull_len != 0) { |
---|
| 222 | + skb_push(skb, pull_len); |
---|
| 223 | + skb->network_header -= pull_len; |
---|
| 224 | + } |
---|
| 225 | + |
---|
| 226 | + hash = jhash_3words(addr1, addr2, ports.in32, imq_hashrnd ^ ip_proto); |
---|
| 227 | + |
---|
| 228 | + return (u16)(((u64)hash * dev->real_num_tx_queues) >> 32); |
---|
| 229 | +} |
---|
| 230 | + |
---|
| 231 | +static inline bool sk_tx_queue_recorded(struct sock *sk) |
---|
| 232 | +{ |
---|
| 233 | + return (sk_tx_queue_get(sk) >= 0); |
---|
| 234 | +} |
---|
| 235 | + |
---|
| 236 | +static struct netdev_queue *imq_select_queue(struct net_device *dev, |
---|
| 237 | + struct sk_buff *skb) |
---|
| 238 | +{ |
---|
| 239 | + u16 queue_index = 0; |
---|
| 240 | + u32 hash; |
---|
| 241 | + |
---|
| 242 | + if (likely(dev->real_num_tx_queues == 1)) |
---|
| 243 | + goto out; |
---|
| 244 | + |
---|
| 245 | + /* IMQ can be receiving ingress or engress packets. */ |
---|
| 246 | + |
---|
| 247 | + /* Check first for if rx_queue is set */ |
---|
| 248 | + if (skb_rx_queue_recorded(skb)) { |
---|
| 249 | + queue_index = skb_get_rx_queue(skb); |
---|
| 250 | + goto out; |
---|
| 251 | + } |
---|
| 252 | + |
---|
| 253 | + /* Check if socket has tx_queue set */ |
---|
| 254 | + if (sk_tx_queue_recorded(skb->sk)) { |
---|
| 255 | + queue_index = sk_tx_queue_get(skb->sk); |
---|
| 256 | + goto out; |
---|
| 257 | + } |
---|
| 258 | + |
---|
| 259 | + /* Try use socket hash */ |
---|
| 260 | + if (skb->sk && skb->sk->sk_hash) { |
---|
| 261 | + hash = skb->sk->sk_hash; |
---|
| 262 | + queue_index = |
---|
| 263 | + (u16)(((u64)hash * dev->real_num_tx_queues) >> 32); |
---|
| 264 | + goto out; |
---|
| 265 | + } |
---|
| 266 | + |
---|
| 267 | + /* Generate hash from packet data */ |
---|
| 268 | + queue_index = imq_hash(dev, skb); |
---|
| 269 | + |
---|
| 270 | +out: |
---|
| 271 | + if (unlikely(queue_index >= dev->real_num_tx_queues)) |
---|
| 272 | + queue_index = (u16)((u32)queue_index % dev->real_num_tx_queues); |
---|
| 273 | + |
---|
| 274 | + skb_set_queue_mapping(skb, queue_index); |
---|
| 275 | + return netdev_get_tx_queue(dev, queue_index); |
---|
| 276 | +} |
---|
| 277 | + |
---|
| 278 | +static struct net_device_stats *imq_get_stats(struct net_device *dev) |
---|
| 279 | +{ |
---|
| 280 | + return &dev->stats; |
---|
| 281 | +} |
---|
| 282 | + |
---|
| 283 | +/* called for packets kfree'd in qdiscs at places other than enqueue */ |
---|
| 284 | +static void imq_skb_destructor(struct sk_buff *skb) |
---|
| 285 | +{ |
---|
| 286 | + struct nf_queue_entry *entry = skb->nf_queue_entry; |
---|
| 287 | + |
---|
| 288 | + skb->nf_queue_entry = NULL; |
---|
| 289 | + |
---|
| 290 | + if (entry) { |
---|
| 291 | + nf_queue_entry_release_refs(entry); |
---|
| 292 | + kfree(entry); |
---|
| 293 | + } |
---|
| 294 | + |
---|
| 295 | + skb_restore_cb(skb); /* kfree backup */ |
---|
| 296 | +} |
---|
| 297 | + |
---|
| 298 | +static void imq_done_check_queue_mapping(struct sk_buff *skb, |
---|
| 299 | + struct net_device *dev) |
---|
| 300 | +{ |
---|
| 301 | + unsigned int queue_index; |
---|
| 302 | + |
---|
| 303 | + /* Don't let queue_mapping be left too large after exiting IMQ */ |
---|
| 304 | + if (likely(skb->dev != dev && skb->dev != NULL)) { |
---|
| 305 | + queue_index = skb_get_queue_mapping(skb); |
---|
| 306 | + if (unlikely(queue_index >= skb->dev->real_num_tx_queues)) { |
---|
| 307 | + queue_index = (u16)((u32)queue_index % |
---|
| 308 | + skb->dev->real_num_tx_queues); |
---|
| 309 | + skb_set_queue_mapping(skb, queue_index); |
---|
| 310 | + } |
---|
| 311 | + } else { |
---|
| 312 | + /* skb->dev was IMQ device itself or NULL, be on safe side and |
---|
| 313 | + * just clear queue mapping. |
---|
| 314 | + */ |
---|
| 315 | + skb_set_queue_mapping(skb, 0); |
---|
| 316 | + } |
---|
| 317 | +} |
---|
| 318 | + |
---|
| 319 | +static netdev_tx_t imq_dev_xmit(struct sk_buff *skb, struct net_device *dev) |
---|
| 320 | +{ |
---|
| 321 | + struct nf_queue_entry *entry = skb->nf_queue_entry; |
---|
| 322 | + |
---|
[efa4154] | 323 | + rcu_read_lock(); |
---|
| 324 | + |
---|
[6936b89] | 325 | + skb->nf_queue_entry = NULL; |
---|
| 326 | + netif_trans_update(dev); |
---|
| 327 | + |
---|
| 328 | + dev->stats.tx_bytes += skb->len; |
---|
| 329 | + dev->stats.tx_packets++; |
---|
| 330 | + |
---|
| 331 | + if (unlikely(entry == NULL)) { |
---|
| 332 | + /* We don't know what is going on here.. packet is queued for |
---|
| 333 | + * imq device, but (probably) not by us. |
---|
| 334 | + * |
---|
| 335 | + * If this packet was not send here by imq_nf_queue(), then |
---|
| 336 | + * skb_save_cb() was not used and skb_free() should not show: |
---|
| 337 | + * WARNING: IMQ: kfree_skb: skb->cb_next:.. |
---|
| 338 | + * and/or |
---|
| 339 | + * WARNING: IMQ: kfree_skb: skb->nf_queue_entry... |
---|
| 340 | + * |
---|
| 341 | + * However if this message is shown, then IMQ is somehow broken |
---|
| 342 | + * and you should report this to linuximq.net. |
---|
| 343 | + */ |
---|
| 344 | + |
---|
| 345 | + /* imq_dev_xmit is black hole that eats all packets, report that |
---|
| 346 | + * we eat this packet happily and increase dropped counters. |
---|
| 347 | + */ |
---|
| 348 | + |
---|
| 349 | + dev->stats.tx_dropped++; |
---|
| 350 | + dev_kfree_skb(skb); |
---|
| 351 | + |
---|
[efa4154] | 352 | + rcu_read_unlock(); |
---|
[6936b89] | 353 | + return NETDEV_TX_OK; |
---|
| 354 | + } |
---|
| 355 | + |
---|
| 356 | + skb_restore_cb(skb); /* restore skb->cb */ |
---|
| 357 | + |
---|
| 358 | + skb->imq_flags = 0; |
---|
| 359 | + skb->destructor = NULL; |
---|
| 360 | + |
---|
| 361 | + imq_done_check_queue_mapping(skb, dev); |
---|
| 362 | + |
---|
| 363 | + nf_reinject(entry, NF_ACCEPT); |
---|
| 364 | + |
---|
[efa4154] | 365 | + rcu_read_unlock(); |
---|
[6936b89] | 366 | + return NETDEV_TX_OK; |
---|
| 367 | +} |
---|
| 368 | + |
---|
| 369 | +static struct net_device *get_imq_device_by_index(int index) |
---|
| 370 | +{ |
---|
| 371 | + struct net_device *dev = NULL; |
---|
| 372 | + struct net *net; |
---|
| 373 | + char buf[8]; |
---|
| 374 | + |
---|
| 375 | + /* get device by name and cache result */ |
---|
| 376 | + snprintf(buf, sizeof(buf), "imq%d", index); |
---|
| 377 | + |
---|
| 378 | + /* Search device from all namespaces. */ |
---|
| 379 | + for_each_net(net) { |
---|
| 380 | + dev = dev_get_by_name(net, buf); |
---|
| 381 | + if (dev) |
---|
| 382 | + break; |
---|
| 383 | + } |
---|
| 384 | + |
---|
| 385 | + if (WARN_ON_ONCE(dev == NULL)) { |
---|
| 386 | + /* IMQ device not found. Exotic config? */ |
---|
| 387 | + return ERR_PTR(-ENODEV); |
---|
| 388 | + } |
---|
| 389 | + |
---|
| 390 | + imq_devs_cache[index] = dev; |
---|
| 391 | + dev_put(dev); |
---|
| 392 | + |
---|
| 393 | + return dev; |
---|
| 394 | +} |
---|
| 395 | + |
---|
| 396 | +static struct nf_queue_entry *nf_queue_entry_dup(struct nf_queue_entry *e) |
---|
| 397 | +{ |
---|
| 398 | + struct nf_queue_entry *entry = kmemdup(e, e->size, GFP_ATOMIC); |
---|
| 399 | + if (entry) { |
---|
| 400 | + nf_queue_entry_get_refs(entry); |
---|
[efa4154] | 401 | + return entry; |
---|
[6936b89] | 402 | + } |
---|
| 403 | + return NULL; |
---|
| 404 | +} |
---|
| 405 | + |
---|
| 406 | +#ifdef CONFIG_BRIDGE_NETFILTER |
---|
| 407 | +/* When called from bridge netfilter, skb->data must point to MAC header |
---|
| 408 | + * before calling skb_gso_segment(). Else, original MAC header is lost |
---|
| 409 | + * and segmented skbs will be sent to wrong destination. |
---|
| 410 | + */ |
---|
| 411 | +static void nf_bridge_adjust_skb_data(struct sk_buff *skb) |
---|
| 412 | +{ |
---|
| 413 | + if (skb->nf_bridge) |
---|
| 414 | + __skb_push(skb, skb->network_header - skb->mac_header); |
---|
| 415 | +} |
---|
| 416 | + |
---|
| 417 | +static void nf_bridge_adjust_segmented_data(struct sk_buff *skb) |
---|
| 418 | +{ |
---|
| 419 | + if (skb->nf_bridge) |
---|
| 420 | + __skb_pull(skb, skb->network_header - skb->mac_header); |
---|
| 421 | +} |
---|
| 422 | +#else |
---|
| 423 | +#define nf_bridge_adjust_skb_data(s) do {} while (0) |
---|
| 424 | +#define nf_bridge_adjust_segmented_data(s) do {} while (0) |
---|
| 425 | +#endif |
---|
| 426 | + |
---|
| 427 | +static void free_entry(struct nf_queue_entry *entry) |
---|
| 428 | +{ |
---|
| 429 | + nf_queue_entry_release_refs(entry); |
---|
| 430 | + kfree(entry); |
---|
| 431 | +} |
---|
| 432 | + |
---|
| 433 | +static int __imq_nf_queue(struct nf_queue_entry *entry, struct net_device *dev); |
---|
| 434 | + |
---|
| 435 | +static int __imq_nf_queue_gso(struct nf_queue_entry *entry, |
---|
| 436 | + struct net_device *dev, struct sk_buff *skb) |
---|
| 437 | +{ |
---|
| 438 | + int ret = -ENOMEM; |
---|
| 439 | + struct nf_queue_entry *entry_seg; |
---|
| 440 | + |
---|
| 441 | + nf_bridge_adjust_segmented_data(skb); |
---|
| 442 | + |
---|
| 443 | + if (skb->next == NULL) { /* last packet, no need to copy entry */ |
---|
| 444 | + struct sk_buff *gso_skb = entry->skb; |
---|
| 445 | + entry->skb = skb; |
---|
| 446 | + ret = __imq_nf_queue(entry, dev); |
---|
| 447 | + if (ret) |
---|
| 448 | + entry->skb = gso_skb; |
---|
| 449 | + return ret; |
---|
| 450 | + } |
---|
| 451 | + |
---|
| 452 | + skb->next = NULL; |
---|
| 453 | + |
---|
| 454 | + entry_seg = nf_queue_entry_dup(entry); |
---|
| 455 | + if (entry_seg) { |
---|
| 456 | + entry_seg->skb = skb; |
---|
| 457 | + ret = __imq_nf_queue(entry_seg, dev); |
---|
| 458 | + if (ret) |
---|
| 459 | + free_entry(entry_seg); |
---|
| 460 | + } |
---|
| 461 | + return ret; |
---|
| 462 | +} |
---|
| 463 | + |
---|
| 464 | +static int imq_nf_queue(struct nf_queue_entry *entry, unsigned queue_num) |
---|
| 465 | +{ |
---|
| 466 | + struct sk_buff *skb, *segs; |
---|
| 467 | + struct net_device *dev; |
---|
| 468 | + unsigned int queued; |
---|
| 469 | + int index, retval, err; |
---|
| 470 | + |
---|
| 471 | + index = entry->skb->imq_flags & IMQ_F_IFMASK; |
---|
| 472 | + if (unlikely(index > numdevs - 1)) { |
---|
| 473 | + if (net_ratelimit()) |
---|
| 474 | + pr_warn("IMQ: invalid device specified, highest is %u\n", |
---|
| 475 | + numdevs - 1); |
---|
| 476 | + retval = -EINVAL; |
---|
| 477 | + goto out_no_dev; |
---|
| 478 | + } |
---|
| 479 | + |
---|
| 480 | + /* check for imq device by index from cache */ |
---|
| 481 | + dev = imq_devs_cache[index]; |
---|
| 482 | + if (unlikely(!dev)) { |
---|
| 483 | + dev = get_imq_device_by_index(index); |
---|
| 484 | + if (IS_ERR(dev)) { |
---|
| 485 | + retval = PTR_ERR(dev); |
---|
| 486 | + goto out_no_dev; |
---|
| 487 | + } |
---|
| 488 | + } |
---|
| 489 | + |
---|
| 490 | + if (unlikely(!(dev->flags & IFF_UP))) { |
---|
| 491 | + entry->skb->imq_flags = 0; |
---|
| 492 | + retval = -ECANCELED; |
---|
| 493 | + goto out_no_dev; |
---|
| 494 | + } |
---|
| 495 | + |
---|
| 496 | + /* Since 3.10.x, GSO handling moved here as result of upstream commit |
---|
| 497 | + * a5fedd43d5f6c94c71053a66e4c3d2e35f1731a2 (netfilter: move |
---|
| 498 | + * skb_gso_segment into nfnetlink_queue module). |
---|
| 499 | + * |
---|
| 500 | + * Following code replicates the gso handling from |
---|
| 501 | + * 'net/netfilter/nfnetlink_queue_core.c':nfqnl_enqueue_packet(). |
---|
| 502 | + */ |
---|
| 503 | + |
---|
| 504 | + skb = entry->skb; |
---|
| 505 | + |
---|
| 506 | + switch (entry->state.pf) { |
---|
| 507 | + case NFPROTO_IPV4: |
---|
| 508 | + skb->protocol = htons(ETH_P_IP); |
---|
| 509 | + break; |
---|
| 510 | + case NFPROTO_IPV6: |
---|
| 511 | + skb->protocol = htons(ETH_P_IPV6); |
---|
| 512 | + break; |
---|
| 513 | + } |
---|
| 514 | + |
---|
| 515 | + if (!skb_is_gso(entry->skb)) |
---|
| 516 | + return __imq_nf_queue(entry, dev); |
---|
| 517 | + |
---|
| 518 | + nf_bridge_adjust_skb_data(skb); |
---|
| 519 | + segs = skb_gso_segment(skb, 0); |
---|
| 520 | + /* Does not use PTR_ERR to limit the number of error codes that can be |
---|
| 521 | + * returned by nf_queue. For instance, callers rely on -ECANCELED to |
---|
| 522 | + * mean 'ignore this hook'. |
---|
| 523 | + */ |
---|
| 524 | + err = -ENOBUFS; |
---|
| 525 | + if (IS_ERR(segs)) |
---|
| 526 | + goto out_err; |
---|
| 527 | + queued = 0; |
---|
| 528 | + err = 0; |
---|
| 529 | + do { |
---|
| 530 | + struct sk_buff *nskb = segs->next; |
---|
| 531 | + if (nskb && nskb->next) |
---|
| 532 | + nskb->cb_next = NULL; |
---|
| 533 | + if (err == 0) |
---|
| 534 | + err = __imq_nf_queue_gso(entry, dev, segs); |
---|
| 535 | + if (err == 0) |
---|
| 536 | + queued++; |
---|
| 537 | + else |
---|
| 538 | + kfree_skb(segs); |
---|
| 539 | + segs = nskb; |
---|
| 540 | + } while (segs); |
---|
| 541 | + |
---|
| 542 | + if (queued) { |
---|
| 543 | + if (err) /* some segments are already queued */ |
---|
| 544 | + free_entry(entry); |
---|
| 545 | + kfree_skb(skb); |
---|
| 546 | + return 0; |
---|
| 547 | + } |
---|
| 548 | + |
---|
| 549 | +out_err: |
---|
| 550 | + nf_bridge_adjust_segmented_data(skb); |
---|
| 551 | + retval = err; |
---|
| 552 | +out_no_dev: |
---|
| 553 | + return retval; |
---|
| 554 | +} |
---|
| 555 | + |
---|
| 556 | +static int __imq_nf_queue(struct nf_queue_entry *entry, struct net_device *dev) |
---|
| 557 | +{ |
---|
| 558 | + struct sk_buff *skb_orig, *skb, *skb_shared, *skb_popd; |
---|
| 559 | + struct Qdisc *q; |
---|
| 560 | + struct sk_buff *to_free = NULL; |
---|
| 561 | + struct netdev_queue *txq; |
---|
| 562 | + spinlock_t *root_lock; |
---|
| 563 | + int users; |
---|
| 564 | + int retval = -EINVAL; |
---|
| 565 | + unsigned int orig_queue_index; |
---|
| 566 | + |
---|
| 567 | + dev->last_rx = jiffies; |
---|
| 568 | + |
---|
| 569 | + skb = entry->skb; |
---|
| 570 | + skb_orig = NULL; |
---|
| 571 | + |
---|
| 572 | + /* skb has owner? => make clone */ |
---|
| 573 | + if (unlikely(skb->destructor)) { |
---|
| 574 | + skb_orig = skb; |
---|
| 575 | + skb = skb_clone(skb, GFP_ATOMIC); |
---|
| 576 | + if (unlikely(!skb)) { |
---|
| 577 | + retval = -ENOMEM; |
---|
| 578 | + goto out; |
---|
| 579 | + } |
---|
| 580 | + skb->cb_next = NULL; |
---|
| 581 | + entry->skb = skb; |
---|
| 582 | + } |
---|
| 583 | + |
---|
| 584 | + dev->stats.rx_bytes += skb->len; |
---|
| 585 | + dev->stats.rx_packets++; |
---|
| 586 | + |
---|
| 587 | + if (!skb->dev) { |
---|
| 588 | + /* skb->dev == NULL causes problems, try the find cause. */ |
---|
| 589 | + if (net_ratelimit()) { |
---|
| 590 | + dev_warn(&dev->dev, |
---|
| 591 | + "received packet with skb->dev == NULL\n"); |
---|
| 592 | + dump_stack(); |
---|
| 593 | + } |
---|
| 594 | + |
---|
| 595 | + skb->dev = dev; |
---|
| 596 | + } |
---|
| 597 | + |
---|
| 598 | + /* Disables softirqs for lock below */ |
---|
| 599 | + rcu_read_lock_bh(); |
---|
| 600 | + |
---|
| 601 | + /* Multi-queue selection */ |
---|
| 602 | + orig_queue_index = skb_get_queue_mapping(skb); |
---|
| 603 | + txq = imq_select_queue(dev, skb); |
---|
| 604 | + |
---|
| 605 | + q = rcu_dereference(txq->qdisc); |
---|
| 606 | + if (unlikely(!q->enqueue)) |
---|
| 607 | + goto packet_not_eaten_by_imq_dev; |
---|
| 608 | + |
---|
| 609 | + skb->nf_queue_entry = entry; |
---|
| 610 | + root_lock = qdisc_lock(q); |
---|
| 611 | + spin_lock(root_lock); |
---|
| 612 | + |
---|
[efa4154] | 613 | + users = refcount_read(&skb->users); |
---|
[6936b89] | 614 | + |
---|
| 615 | + skb_shared = skb_get(skb); /* increase reference count by one */ |
---|
| 616 | + |
---|
| 617 | + /* backup skb->cb, as qdisc layer will overwrite it */ |
---|
| 618 | + skb_save_cb(skb_shared); |
---|
| 619 | + qdisc_enqueue_root(skb_shared, q, &to_free); /* might kfree_skb */ |
---|
[efa4154] | 620 | + if (likely(refcount_read(&skb_shared->users) == users + 1)) { |
---|
[6936b89] | 621 | + bool validate; |
---|
| 622 | + |
---|
| 623 | + kfree_skb(skb_shared); /* decrease reference count by one */ |
---|
| 624 | + |
---|
| 625 | + skb->destructor = &imq_skb_destructor; |
---|
| 626 | + |
---|
| 627 | + skb_popd = qdisc_dequeue_skb(q, &validate); |
---|
| 628 | + |
---|
| 629 | + /* cloned? */ |
---|
| 630 | + if (unlikely(skb_orig)) |
---|
| 631 | + kfree_skb(skb_orig); /* free original */ |
---|
| 632 | + |
---|
| 633 | + spin_unlock(root_lock); |
---|
| 634 | + |
---|
| 635 | +#if 0 |
---|
| 636 | + /* schedule qdisc dequeue */ |
---|
| 637 | + __netif_schedule(q); |
---|
| 638 | +#else |
---|
| 639 | + if (likely(skb_popd)) { |
---|
| 640 | + /* Note that we validate skb (GSO, checksum, ...) outside of locks */ |
---|
| 641 | + if (validate) |
---|
| 642 | + skb_popd = validate_xmit_skb_list(skb_popd, dev); |
---|
| 643 | + |
---|
| 644 | + if (skb_popd) { |
---|
| 645 | + int dummy_ret; |
---|
| 646 | + int cpu = smp_processor_id(); /* ok because BHs are off */ |
---|
| 647 | + |
---|
| 648 | + txq = skb_get_tx_queue(dev, skb_popd); |
---|
| 649 | + /* |
---|
| 650 | + IMQ device will not be frozen or stoped, and it always be successful. |
---|
| 651 | + So we need not check its status and return value to accelerate. |
---|
| 652 | + */ |
---|
| 653 | + if (imq_dev_accurate_stats && txq->xmit_lock_owner != cpu) { |
---|
| 654 | + HARD_TX_LOCK(dev, txq, cpu); |
---|
| 655 | + if (!netif_xmit_frozen_or_stopped(txq)) { |
---|
| 656 | + dev_hard_start_xmit(skb_popd, dev, txq, &dummy_ret); |
---|
| 657 | + } |
---|
| 658 | + HARD_TX_UNLOCK(dev, txq); |
---|
| 659 | + } else { |
---|
| 660 | + if (!netif_xmit_frozen_or_stopped(txq)) { |
---|
| 661 | + dev_hard_start_xmit(skb_popd, dev, txq, &dummy_ret); |
---|
| 662 | + } |
---|
| 663 | + } |
---|
| 664 | + } |
---|
| 665 | + } else { |
---|
| 666 | + /* No ready skb, then schedule it */ |
---|
| 667 | + __netif_schedule(q); |
---|
| 668 | + } |
---|
| 669 | +#endif |
---|
| 670 | + rcu_read_unlock_bh(); |
---|
| 671 | + retval = 0; |
---|
| 672 | + goto out; |
---|
| 673 | + } else { |
---|
| 674 | + skb_restore_cb(skb_shared); /* restore skb->cb */ |
---|
| 675 | + skb->nf_queue_entry = NULL; |
---|
| 676 | + /* |
---|
| 677 | + * qdisc dropped packet and decreased skb reference count of |
---|
| 678 | + * skb, so we don't really want to and try refree as that would |
---|
| 679 | + * actually destroy the skb. |
---|
| 680 | + */ |
---|
| 681 | + spin_unlock(root_lock); |
---|
| 682 | + goto packet_not_eaten_by_imq_dev; |
---|
| 683 | + } |
---|
| 684 | + |
---|
| 685 | +packet_not_eaten_by_imq_dev: |
---|
| 686 | + skb_set_queue_mapping(skb, orig_queue_index); |
---|
| 687 | + rcu_read_unlock_bh(); |
---|
| 688 | + |
---|
| 689 | + /* cloned? restore original */ |
---|
| 690 | + if (unlikely(skb_orig)) { |
---|
| 691 | + kfree_skb(skb); |
---|
| 692 | + entry->skb = skb_orig; |
---|
| 693 | + } |
---|
| 694 | + retval = -1; |
---|
| 695 | +out: |
---|
| 696 | + if (unlikely(to_free)) { |
---|
| 697 | + kfree_skb_list(to_free); |
---|
| 698 | + } |
---|
| 699 | + return retval; |
---|
| 700 | +} |
---|
| 701 | +static unsigned int imq_nf_hook(void *priv, |
---|
| 702 | + struct sk_buff *skb, |
---|
| 703 | + const struct nf_hook_state *state) |
---|
| 704 | +{ |
---|
| 705 | + return (skb->imq_flags & IMQ_F_ENQUEUE) ? NF_IMQ_QUEUE : NF_ACCEPT; |
---|
| 706 | +} |
---|
| 707 | + |
---|
| 708 | +static int imq_close(struct net_device *dev) |
---|
| 709 | +{ |
---|
| 710 | + netif_stop_queue(dev); |
---|
| 711 | + return 0; |
---|
| 712 | +} |
---|
| 713 | + |
---|
| 714 | +static int imq_open(struct net_device *dev) |
---|
| 715 | +{ |
---|
| 716 | + netif_start_queue(dev); |
---|
| 717 | + return 0; |
---|
| 718 | +} |
---|
| 719 | + |
---|
[efa4154] | 720 | +static struct device_type imq_device_type = { |
---|
| 721 | + .name = "imq", |
---|
| 722 | +}; |
---|
| 723 | + |
---|
[6936b89] | 724 | +static const struct net_device_ops imq_netdev_ops = { |
---|
| 725 | + .ndo_open = imq_open, |
---|
| 726 | + .ndo_stop = imq_close, |
---|
| 727 | + .ndo_start_xmit = imq_dev_xmit, |
---|
| 728 | + .ndo_get_stats = imq_get_stats, |
---|
| 729 | +}; |
---|
| 730 | + |
---|
| 731 | +static void imq_setup(struct net_device *dev) |
---|
| 732 | +{ |
---|
| 733 | + dev->netdev_ops = &imq_netdev_ops; |
---|
| 734 | + dev->type = ARPHRD_VOID; |
---|
| 735 | + dev->mtu = 16000; /* too small? */ |
---|
| 736 | + dev->tx_queue_len = 11000; /* too big? */ |
---|
| 737 | + dev->flags = IFF_NOARP; |
---|
| 738 | + dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | |
---|
| 739 | + NETIF_F_GSO | NETIF_F_HW_CSUM | |
---|
| 740 | + NETIF_F_HIGHDMA; |
---|
| 741 | + dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | |
---|
| 742 | + IFF_TX_SKB_SHARING); |
---|
| 743 | +} |
---|
| 744 | + |
---|
[efa4154] | 745 | +static int imq_validate(struct nlattr *tb[], struct nlattr *data[], |
---|
| 746 | + struct netlink_ext_ack *extack) |
---|
[6936b89] | 747 | +{ |
---|
| 748 | + int ret = 0; |
---|
| 749 | + |
---|
| 750 | + if (tb[IFLA_ADDRESS]) { |
---|
| 751 | + if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) { |
---|
| 752 | + ret = -EINVAL; |
---|
| 753 | + goto end; |
---|
| 754 | + } |
---|
| 755 | + if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) { |
---|
| 756 | + ret = -EADDRNOTAVAIL; |
---|
| 757 | + goto end; |
---|
| 758 | + } |
---|
| 759 | + } |
---|
| 760 | + return 0; |
---|
| 761 | +end: |
---|
| 762 | + pr_warn("IMQ: imq_validate failed (%d)\n", ret); |
---|
| 763 | + return ret; |
---|
| 764 | +} |
---|
| 765 | + |
---|
| 766 | +static struct rtnl_link_ops imq_link_ops __read_mostly = { |
---|
| 767 | + .kind = "imq", |
---|
| 768 | + .priv_size = 0, |
---|
| 769 | + .setup = imq_setup, |
---|
| 770 | + .validate = imq_validate, |
---|
| 771 | +}; |
---|
| 772 | + |
---|
| 773 | +static const struct nf_queue_handler imq_nfqh = { |
---|
| 774 | + .outfn = imq_nf_queue, |
---|
| 775 | +}; |
---|
| 776 | + |
---|
[efa4154] | 777 | +static int __net_init imq_nf_register(struct net *net) |
---|
[6936b89] | 778 | +{ |
---|
[efa4154] | 779 | + return nf_register_net_hooks(net, imq_ops, |
---|
| 780 | + ARRAY_SIZE(imq_ops)); |
---|
| 781 | +}; |
---|
| 782 | + |
---|
| 783 | +static void __net_exit imq_nf_unregister(struct net *net) |
---|
| 784 | +{ |
---|
| 785 | + nf_unregister_net_hooks(net, imq_ops, |
---|
| 786 | + ARRAY_SIZE(imq_ops)); |
---|
| 787 | +}; |
---|
| 788 | + |
---|
| 789 | +static struct pernet_operations imq_net_ops = { |
---|
| 790 | + .init = imq_nf_register, |
---|
| 791 | + .exit = imq_nf_unregister, |
---|
| 792 | +}; |
---|
[6936b89] | 793 | + |
---|
[efa4154] | 794 | +static int __net_init imq_init_hooks(void) |
---|
| 795 | +{ |
---|
| 796 | + int ret; |
---|
[6936b89] | 797 | + nf_register_queue_imq_handler(&imq_nfqh); |
---|
| 798 | + |
---|
[efa4154] | 799 | + ret = register_pernet_subsys(&imq_net_ops); |
---|
[6936b89] | 800 | + if (ret < 0) |
---|
| 801 | + nf_unregister_queue_imq_handler(); |
---|
| 802 | + |
---|
| 803 | + return ret; |
---|
| 804 | +} |
---|
| 805 | + |
---|
[efa4154] | 806 | +#ifdef CONFIG_LOCKDEP |
---|
| 807 | + static struct lock_class_key imq_netdev_addr_lock_key; |
---|
| 808 | + |
---|
| 809 | + static void __init imq_dev_set_lockdep_one(struct net_device *dev, |
---|
| 810 | + struct netdev_queue *txq, void *arg) |
---|
| 811 | + { |
---|
| 812 | + /* |
---|
| 813 | + * the IMQ transmit locks can be taken recursively, |
---|
| 814 | + * for example with one IMQ rule for input- and one for |
---|
| 815 | + * output network devices in iptables! |
---|
| 816 | + * until we find a better solution ignore them. |
---|
| 817 | + */ |
---|
| 818 | + lockdep_set_novalidate_class(&txq->_xmit_lock); |
---|
| 819 | + } |
---|
| 820 | + |
---|
| 821 | + static void imq_dev_set_lockdep_class(struct net_device *dev) |
---|
| 822 | + { |
---|
| 823 | + lockdep_set_class_and_name(&dev->addr_list_lock, |
---|
| 824 | + &imq_netdev_addr_lock_key, "_xmit_addr_IMQ"); |
---|
| 825 | + netdev_for_each_tx_queue(dev, imq_dev_set_lockdep_one, NULL); |
---|
| 826 | +} |
---|
| 827 | +#else |
---|
| 828 | + static inline void imq_dev_set_lockdep_class(struct net_device *dev) |
---|
| 829 | + { |
---|
| 830 | + } |
---|
| 831 | +#endif |
---|
| 832 | + |
---|
[6936b89] | 833 | +static int __init imq_init_one(int index) |
---|
| 834 | +{ |
---|
| 835 | + struct net_device *dev; |
---|
| 836 | + int ret; |
---|
| 837 | + |
---|
| 838 | + dev = alloc_netdev_mq(0, "imq%d", NET_NAME_UNKNOWN, imq_setup, numqueues); |
---|
| 839 | + if (!dev) |
---|
| 840 | + return -ENOMEM; |
---|
| 841 | + |
---|
| 842 | + ret = dev_alloc_name(dev, dev->name); |
---|
| 843 | + if (ret < 0) |
---|
| 844 | + goto fail; |
---|
| 845 | + |
---|
| 846 | + dev->rtnl_link_ops = &imq_link_ops; |
---|
[efa4154] | 847 | + SET_NETDEV_DEVTYPE(dev, &imq_device_type); |
---|
[6936b89] | 848 | + ret = register_netdevice(dev); |
---|
| 849 | + if (ret < 0) |
---|
| 850 | + goto fail; |
---|
| 851 | + |
---|
[efa4154] | 852 | + imq_dev_set_lockdep_class(dev); |
---|
| 853 | + |
---|
[6936b89] | 854 | + return 0; |
---|
| 855 | +fail: |
---|
| 856 | + free_netdev(dev); |
---|
| 857 | + return ret; |
---|
| 858 | +} |
---|
| 859 | + |
---|
| 860 | +static int __init imq_init_devs(void) |
---|
| 861 | +{ |
---|
| 862 | + int err, i; |
---|
| 863 | + |
---|
| 864 | + if (numdevs < 1 || numdevs > IMQ_MAX_DEVS) { |
---|
| 865 | + pr_err("IMQ: numdevs has to be betweed 1 and %u\n", |
---|
| 866 | + IMQ_MAX_DEVS); |
---|
| 867 | + return -EINVAL; |
---|
| 868 | + } |
---|
| 869 | + |
---|
| 870 | + if (numqueues < 1 || numqueues > IMQ_MAX_QUEUES) { |
---|
| 871 | + pr_err("IMQ: numqueues has to be betweed 1 and %u\n", |
---|
| 872 | + IMQ_MAX_QUEUES); |
---|
| 873 | + return -EINVAL; |
---|
| 874 | + } |
---|
| 875 | + |
---|
| 876 | + get_random_bytes(&imq_hashrnd, sizeof(imq_hashrnd)); |
---|
| 877 | + |
---|
| 878 | + rtnl_lock(); |
---|
| 879 | + err = __rtnl_link_register(&imq_link_ops); |
---|
| 880 | + |
---|
| 881 | + for (i = 0; i < numdevs && !err; i++) |
---|
| 882 | + err = imq_init_one(i); |
---|
| 883 | + |
---|
| 884 | + if (err) { |
---|
| 885 | + __rtnl_link_unregister(&imq_link_ops); |
---|
| 886 | + memset(imq_devs_cache, 0, sizeof(imq_devs_cache)); |
---|
| 887 | + } |
---|
| 888 | + rtnl_unlock(); |
---|
| 889 | + |
---|
| 890 | + return err; |
---|
| 891 | +} |
---|
| 892 | + |
---|
| 893 | +static int __init imq_init_module(void) |
---|
| 894 | +{ |
---|
| 895 | + int err; |
---|
| 896 | + |
---|
| 897 | +#if defined(CONFIG_IMQ_NUM_DEVS) |
---|
| 898 | + BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS > 16); |
---|
| 899 | + BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS < 2); |
---|
| 900 | + BUILD_BUG_ON(CONFIG_IMQ_NUM_DEVS - 1 > IMQ_F_IFMASK); |
---|
| 901 | +#endif |
---|
| 902 | + |
---|
| 903 | + err = imq_init_devs(); |
---|
| 904 | + if (err) { |
---|
| 905 | + pr_err("IMQ: Error trying imq_init_devs(net)\n"); |
---|
| 906 | + return err; |
---|
| 907 | + } |
---|
| 908 | + |
---|
| 909 | + err = imq_init_hooks(); |
---|
| 910 | + if (err) { |
---|
| 911 | + pr_err(KERN_ERR "IMQ: Error trying imq_init_hooks()\n"); |
---|
| 912 | + rtnl_link_unregister(&imq_link_ops); |
---|
| 913 | + memset(imq_devs_cache, 0, sizeof(imq_devs_cache)); |
---|
| 914 | + return err; |
---|
| 915 | + } |
---|
| 916 | + |
---|
| 917 | + pr_info("IMQ driver loaded successfully. (numdevs = %d, numqueues = %d, imq_dev_accurate_stats = %d)\n", |
---|
| 918 | + numdevs, numqueues, imq_dev_accurate_stats); |
---|
| 919 | + |
---|
| 920 | +#if defined(CONFIG_IMQ_BEHAVIOR_BA) || defined(CONFIG_IMQ_BEHAVIOR_BB) |
---|
| 921 | + pr_info("\tHooking IMQ before NAT on PREROUTING.\n"); |
---|
| 922 | +#else |
---|
| 923 | + pr_info("\tHooking IMQ after NAT on PREROUTING.\n"); |
---|
| 924 | +#endif |
---|
| 925 | +#if defined(CONFIG_IMQ_BEHAVIOR_AB) || defined(CONFIG_IMQ_BEHAVIOR_BB) |
---|
| 926 | + pr_info("\tHooking IMQ before NAT on POSTROUTING.\n"); |
---|
| 927 | +#else |
---|
| 928 | + pr_info("\tHooking IMQ after NAT on POSTROUTING.\n"); |
---|
| 929 | +#endif |
---|
| 930 | + |
---|
| 931 | + return 0; |
---|
| 932 | +} |
---|
| 933 | + |
---|
| 934 | +static void __exit imq_unhook(void) |
---|
| 935 | +{ |
---|
[efa4154] | 936 | + unregister_pernet_subsys(&imq_net_ops); |
---|
[6936b89] | 937 | + nf_unregister_queue_imq_handler(); |
---|
| 938 | +} |
---|
| 939 | + |
---|
| 940 | +static void __exit imq_cleanup_devs(void) |
---|
| 941 | +{ |
---|
| 942 | + rtnl_link_unregister(&imq_link_ops); |
---|
| 943 | + memset(imq_devs_cache, 0, sizeof(imq_devs_cache)); |
---|
| 944 | +} |
---|
| 945 | + |
---|
| 946 | +static void __exit imq_exit_module(void) |
---|
| 947 | +{ |
---|
| 948 | + imq_unhook(); |
---|
| 949 | + imq_cleanup_devs(); |
---|
| 950 | + pr_info("IMQ driver unloaded successfully.\n"); |
---|
| 951 | +} |
---|
| 952 | + |
---|
| 953 | +module_init(imq_init_module); |
---|
| 954 | +module_exit(imq_exit_module); |
---|
| 955 | + |
---|
| 956 | +module_param(numdevs, int, 0); |
---|
| 957 | +module_param(numqueues, int, 0); |
---|
| 958 | +module_param(imq_dev_accurate_stats, int, 0); |
---|
| 959 | +MODULE_PARM_DESC(numdevs, "number of IMQ devices (how many imq* devices will be created)"); |
---|
| 960 | +MODULE_PARM_DESC(numqueues, "number of queues per IMQ device"); |
---|
| 961 | +MODULE_PARM_DESC(imq_dev_accurate_stats, "Notify if need the accurate imq device stats"); |
---|
| 962 | + |
---|
| 963 | +MODULE_AUTHOR("https://github.com/imq/linuximq"); |
---|
| 964 | +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See https://github.com/imq/linuximq/wiki for more information."); |
---|
| 965 | +MODULE_LICENSE("GPL"); |
---|
| 966 | +MODULE_ALIAS_RTNL_LINK("imq"); |
---|
[efa4154] | 967 | diff -Naupr linux-4.14_orig/drivers/net/Kconfig linux-4.14/drivers/net/Kconfig |
---|
| 968 | --- linux-4.14_orig/drivers/net/Kconfig 2017-11-13 01:46:13.000000000 +0700 |
---|
| 969 | +++ linux-4.14/drivers/net/Kconfig 2017-11-13 11:46:45.844089945 +0700 |
---|
| 970 | @@ -277,6 +277,125 @@ config RIONET_RX_SIZE |
---|
| 971 | depends on RIONET |
---|
| 972 | default "128" |
---|
| 973 | |
---|
| 974 | +config IMQ |
---|
| 975 | + tristate "IMQ (intermediate queueing device) support" |
---|
| 976 | + depends on NETDEVICES && NETFILTER |
---|
| 977 | + ---help--- |
---|
| 978 | + The IMQ device(s) is used as placeholder for QoS queueing |
---|
| 979 | + disciplines. Every packet entering/leaving the IP stack can be |
---|
| 980 | + directed through the IMQ device where it's enqueued/dequeued to the |
---|
| 981 | + attached qdisc. This allows you to treat network devices as classes |
---|
| 982 | + and distribute bandwidth among them. Iptables is used to specify |
---|
| 983 | + through which IMQ device, if any, packets travel. |
---|
| 984 | + |
---|
| 985 | + More information at: https://github.com/imq/linuximq |
---|
| 986 | + |
---|
| 987 | + To compile this driver as a module, choose M here: the module |
---|
| 988 | + will be called imq. If unsure, say N. |
---|
| 989 | + |
---|
| 990 | +choice |
---|
| 991 | + prompt "IMQ behavior (PRE/POSTROUTING)" |
---|
| 992 | + depends on IMQ |
---|
| 993 | + default IMQ_BEHAVIOR_AB |
---|
| 994 | + help |
---|
| 995 | + This setting defines how IMQ behaves in respect to its |
---|
| 996 | + hooking in PREROUTING and POSTROUTING. |
---|
| 997 | + |
---|
| 998 | + IMQ can work in any of the following ways: |
---|
| 999 | + |
---|
| 1000 | + PREROUTING | POSTROUTING |
---|
| 1001 | + -----------------|------------------- |
---|
| 1002 | + #1 After NAT | After NAT |
---|
| 1003 | + #2 After NAT | Before NAT |
---|
| 1004 | + #3 Before NAT | After NAT |
---|
| 1005 | + #4 Before NAT | Before NAT |
---|
| 1006 | + |
---|
| 1007 | + The default behavior is to hook before NAT on PREROUTING |
---|
| 1008 | + and after NAT on POSTROUTING (#3). |
---|
| 1009 | + |
---|
| 1010 | + This settings are specially usefull when trying to use IMQ |
---|
| 1011 | + to shape NATed clients. |
---|
| 1012 | + |
---|
| 1013 | + More information can be found at: https://github.com/imq/linuximq |
---|
| 1014 | + |
---|
| 1015 | + If not sure leave the default settings alone. |
---|
| 1016 | + |
---|
| 1017 | +config IMQ_BEHAVIOR_AA |
---|
| 1018 | + bool "IMQ AA" |
---|
| 1019 | + help |
---|
| 1020 | + This setting defines how IMQ behaves in respect to its |
---|
| 1021 | + hooking in PREROUTING and POSTROUTING. |
---|
| 1022 | + |
---|
| 1023 | + Choosing this option will make IMQ hook like this: |
---|
| 1024 | + |
---|
| 1025 | + PREROUTING: After NAT |
---|
| 1026 | + POSTROUTING: After NAT |
---|
| 1027 | + |
---|
| 1028 | + More information can be found at: https://github.com/imq/linuximq |
---|
| 1029 | + |
---|
| 1030 | + If not sure leave the default settings alone. |
---|
| 1031 | + |
---|
| 1032 | +config IMQ_BEHAVIOR_AB |
---|
| 1033 | + bool "IMQ AB" |
---|
| 1034 | + help |
---|
| 1035 | + This setting defines how IMQ behaves in respect to its |
---|
| 1036 | + hooking in PREROUTING and POSTROUTING. |
---|
| 1037 | + |
---|
| 1038 | + Choosing this option will make IMQ hook like this: |
---|
| 1039 | + |
---|
| 1040 | + PREROUTING: After NAT |
---|
| 1041 | + POSTROUTING: Before NAT |
---|
| 1042 | + |
---|
| 1043 | + More information can be found at: https://github.com/imq/linuximq |
---|
| 1044 | + |
---|
| 1045 | + If not sure leave the default settings alone. |
---|
| 1046 | + |
---|
| 1047 | +config IMQ_BEHAVIOR_BA |
---|
| 1048 | + bool "IMQ BA" |
---|
| 1049 | + help |
---|
| 1050 | + This setting defines how IMQ behaves in respect to its |
---|
| 1051 | + hooking in PREROUTING and POSTROUTING. |
---|
| 1052 | + |
---|
| 1053 | + Choosing this option will make IMQ hook like this: |
---|
| 1054 | + |
---|
| 1055 | + PREROUTING: Before NAT |
---|
| 1056 | + POSTROUTING: After NAT |
---|
| 1057 | + |
---|
| 1058 | + More information can be found at: https://github.com/imq/linuximq |
---|
| 1059 | + |
---|
| 1060 | + If not sure leave the default settings alone. |
---|
| 1061 | + |
---|
| 1062 | +config IMQ_BEHAVIOR_BB |
---|
| 1063 | + bool "IMQ BB" |
---|
| 1064 | + help |
---|
| 1065 | + This setting defines how IMQ behaves in respect to its |
---|
| 1066 | + hooking in PREROUTING and POSTROUTING. |
---|
| 1067 | + |
---|
| 1068 | + Choosing this option will make IMQ hook like this: |
---|
| 1069 | + |
---|
| 1070 | + PREROUTING: Before NAT |
---|
| 1071 | + POSTROUTING: Before NAT |
---|
| 1072 | + |
---|
| 1073 | + More information can be found at: https://github.com/imq/linuximq |
---|
| 1074 | + |
---|
| 1075 | + If not sure leave the default settings alone. |
---|
| 1076 | + |
---|
| 1077 | +endchoice |
---|
| 1078 | + |
---|
| 1079 | +config IMQ_NUM_DEVS |
---|
| 1080 | + int "Number of IMQ devices" |
---|
| 1081 | + range 2 16 |
---|
| 1082 | + depends on IMQ |
---|
| 1083 | + default "16" |
---|
| 1084 | + help |
---|
| 1085 | + This setting defines how many IMQ devices will be created. |
---|
| 1086 | + |
---|
| 1087 | + The default value is 16. |
---|
| 1088 | + |
---|
| 1089 | + More information can be found at: https://github.com/imq/linuximq |
---|
| 1090 | + |
---|
| 1091 | + If not sure leave the default settings alone. |
---|
| 1092 | + |
---|
| 1093 | config TUN |
---|
| 1094 | tristate "Universal TUN/TAP device driver support" |
---|
| 1095 | depends on INET |
---|
| 1096 | diff -Naupr linux-4.14_orig/drivers/net/Makefile linux-4.14/drivers/net/Makefile |
---|
| 1097 | --- linux-4.14_orig/drivers/net/Makefile 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1098 | +++ linux-4.14/drivers/net/Makefile 2017-11-13 11:46:45.844089945 +0700 |
---|
| 1099 | @@ -13,6 +13,7 @@ obj-$(CONFIG_DUMMY) += dummy.o |
---|
| 1100 | obj-$(CONFIG_EQUALIZER) += eql.o |
---|
| 1101 | obj-$(CONFIG_IFB) += ifb.o |
---|
| 1102 | obj-$(CONFIG_MACSEC) += macsec.o |
---|
| 1103 | +obj-$(CONFIG_IMQ) += imq.o |
---|
| 1104 | obj-$(CONFIG_MACVLAN) += macvlan.o |
---|
| 1105 | obj-$(CONFIG_MACVTAP) += macvtap.o |
---|
| 1106 | obj-$(CONFIG_MII) += mii.o |
---|
| 1107 | diff -Naupr linux-4.14_orig/include/linux/imq.h linux-4.14/include/linux/imq.h |
---|
| 1108 | --- linux-4.14_orig/include/linux/imq.h 1970-01-01 07:00:00.000000000 +0700 |
---|
| 1109 | +++ linux-4.14/include/linux/imq.h 2017-11-13 11:46:45.844089945 +0700 |
---|
[6936b89] | 1110 | @@ -0,0 +1,13 @@ |
---|
| 1111 | +#ifndef _IMQ_H |
---|
| 1112 | +#define _IMQ_H |
---|
| 1113 | + |
---|
| 1114 | +/* IFMASK (16 device indexes, 0 to 15) and flag(s) fit in 5 bits */ |
---|
| 1115 | +#define IMQ_F_BITS 5 |
---|
| 1116 | + |
---|
| 1117 | +#define IMQ_F_IFMASK 0x0f |
---|
| 1118 | +#define IMQ_F_ENQUEUE 0x10 |
---|
| 1119 | + |
---|
| 1120 | +#define IMQ_MAX_DEVS (IMQ_F_IFMASK + 1) |
---|
| 1121 | + |
---|
| 1122 | +#endif /* _IMQ_H */ |
---|
| 1123 | + |
---|
[efa4154] | 1124 | diff -Naupr linux-4.14_orig/include/linux/netdevice.h linux-4.14/include/linux/netdevice.h |
---|
| 1125 | --- linux-4.14_orig/include/linux/netdevice.h 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1126 | +++ linux-4.14/include/linux/netdevice.h 2017-11-13 11:46:45.844089945 +0700 |
---|
| 1127 | @@ -1771,6 +1771,11 @@ struct net_device { |
---|
| 1128 | /* |
---|
| 1129 | * Cache lines mostly used on receive path (including eth_type_trans()) |
---|
| 1130 | */ |
---|
| 1131 | + |
---|
| 1132 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1133 | + unsigned long last_rx; |
---|
| 1134 | +#endif |
---|
| 1135 | + |
---|
| 1136 | /* Interface address info used in eth_type_trans() */ |
---|
| 1137 | unsigned char *dev_addr; |
---|
| 1138 | |
---|
| 1139 | @@ -3631,6 +3636,19 @@ static inline void netif_tx_unlock_bh(st |
---|
[6936b89] | 1140 | } \ |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | +#define HARD_TX_LOCK_BH(dev, txq) { \ |
---|
| 1144 | + if ((dev->features & NETIF_F_LLTX) == 0) { \ |
---|
| 1145 | + __netif_tx_lock_bh(txq); \ |
---|
| 1146 | + } \ |
---|
| 1147 | +} |
---|
| 1148 | + |
---|
| 1149 | +#define HARD_TX_UNLOCK_BH(dev, txq) { \ |
---|
| 1150 | + if ((dev->features & NETIF_F_LLTX) == 0) { \ |
---|
| 1151 | + __netif_tx_unlock_bh(txq); \ |
---|
| 1152 | + } \ |
---|
| 1153 | +} |
---|
| 1154 | + |
---|
| 1155 | + |
---|
| 1156 | static inline void netif_tx_disable(struct net_device *dev) |
---|
| 1157 | { |
---|
| 1158 | unsigned int i; |
---|
[efa4154] | 1159 | diff -Naupr linux-4.14_orig/include/linux/netfilter/xt_IMQ.h linux-4.14/include/linux/netfilter/xt_IMQ.h |
---|
| 1160 | --- linux-4.14_orig/include/linux/netfilter/xt_IMQ.h 1970-01-01 07:00:00.000000000 +0700 |
---|
| 1161 | +++ linux-4.14/include/linux/netfilter/xt_IMQ.h 2017-11-13 11:46:45.847423298 +0700 |
---|
[6936b89] | 1162 | @@ -0,0 +1,9 @@ |
---|
| 1163 | +#ifndef _XT_IMQ_H |
---|
| 1164 | +#define _XT_IMQ_H |
---|
| 1165 | + |
---|
| 1166 | +struct xt_imq_info { |
---|
| 1167 | + unsigned int todev; /* target imq device */ |
---|
| 1168 | +}; |
---|
| 1169 | + |
---|
| 1170 | +#endif /* _XT_IMQ_H */ |
---|
| 1171 | + |
---|
[efa4154] | 1172 | diff -Naupr linux-4.14_orig/include/linux/netfilter_ipv4/ipt_IMQ.h linux-4.14/include/linux/netfilter_ipv4/ipt_IMQ.h |
---|
| 1173 | --- linux-4.14_orig/include/linux/netfilter_ipv4/ipt_IMQ.h 1970-01-01 07:00:00.000000000 +0700 |
---|
| 1174 | +++ linux-4.14/include/linux/netfilter_ipv4/ipt_IMQ.h 2017-11-13 11:46:45.847423298 +0700 |
---|
[6936b89] | 1175 | @@ -0,0 +1,10 @@ |
---|
| 1176 | +#ifndef _IPT_IMQ_H |
---|
| 1177 | +#define _IPT_IMQ_H |
---|
| 1178 | + |
---|
| 1179 | +/* Backwards compatibility for old userspace */ |
---|
| 1180 | +#include <linux/netfilter/xt_IMQ.h> |
---|
| 1181 | + |
---|
| 1182 | +#define ipt_imq_info xt_imq_info |
---|
| 1183 | + |
---|
| 1184 | +#endif /* _IPT_IMQ_H */ |
---|
| 1185 | + |
---|
[efa4154] | 1186 | diff -Naupr linux-4.14_orig/include/linux/netfilter_ipv6/ip6t_IMQ.h linux-4.14/include/linux/netfilter_ipv6/ip6t_IMQ.h |
---|
| 1187 | --- linux-4.14_orig/include/linux/netfilter_ipv6/ip6t_IMQ.h 1970-01-01 07:00:00.000000000 +0700 |
---|
| 1188 | +++ linux-4.14/include/linux/netfilter_ipv6/ip6t_IMQ.h 2017-11-13 11:46:45.847423298 +0700 |
---|
[6936b89] | 1189 | @@ -0,0 +1,10 @@ |
---|
| 1190 | +#ifndef _IP6T_IMQ_H |
---|
| 1191 | +#define _IP6T_IMQ_H |
---|
| 1192 | + |
---|
| 1193 | +/* Backwards compatibility for old userspace */ |
---|
| 1194 | +#include <linux/netfilter/xt_IMQ.h> |
---|
| 1195 | + |
---|
| 1196 | +#define ip6t_imq_info xt_imq_info |
---|
| 1197 | + |
---|
| 1198 | +#endif /* _IP6T_IMQ_H */ |
---|
| 1199 | + |
---|
[efa4154] | 1200 | diff -Naupr linux-4.14_orig/include/linux/skbuff.h linux-4.14/include/linux/skbuff.h |
---|
| 1201 | --- linux-4.14_orig/include/linux/skbuff.h 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1202 | +++ linux-4.14/include/linux/skbuff.h 2017-11-13 11:46:45.847423298 +0700 |
---|
| 1203 | @@ -41,6 +41,10 @@ |
---|
[6936b89] | 1204 | #include <linux/in6.h> |
---|
| 1205 | #include <linux/if_packet.h> |
---|
| 1206 | #include <net/flow.h> |
---|
| 1207 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1208 | +#include <linux/imq.h> |
---|
| 1209 | +#endif |
---|
| 1210 | + |
---|
| 1211 | |
---|
| 1212 | /* The interface for checksum offload between the stack and networking drivers |
---|
| 1213 | * is as follows... |
---|
[efa4154] | 1214 | @@ -581,7 +585,7 @@ typedef unsigned int sk_buff_data_t; |
---|
| 1215 | typedef unsigned char *sk_buff_data_t; |
---|
| 1216 | #endif |
---|
| 1217 | |
---|
| 1218 | -/** |
---|
| 1219 | +/** |
---|
| 1220 | * struct sk_buff - socket buffer |
---|
| 1221 | * @next: Next buffer in list |
---|
| 1222 | * @prev: Previous buffer in list |
---|
| 1223 | @@ -684,6 +688,9 @@ struct sk_buff { |
---|
[6936b89] | 1224 | * first. This is owned by whoever has the skb queued ATM. |
---|
| 1225 | */ |
---|
| 1226 | char cb[48] __aligned(8); |
---|
| 1227 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1228 | + void *cb_next; |
---|
| 1229 | +#endif |
---|
| 1230 | |
---|
| 1231 | unsigned long _skb_refdst; |
---|
| 1232 | void (*destructor)(struct sk_buff *skb); |
---|
[efa4154] | 1233 | @@ -693,6 +700,9 @@ struct sk_buff { |
---|
[6936b89] | 1234 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
---|
[efa4154] | 1235 | unsigned long _nfct; |
---|
[6936b89] | 1236 | #endif |
---|
| 1237 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1238 | + struct nf_queue_entry *nf_queue_entry; |
---|
| 1239 | +#endif |
---|
| 1240 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
| 1241 | struct nf_bridge_info *nf_bridge; |
---|
| 1242 | #endif |
---|
[efa4154] | 1243 | @@ -772,6 +782,9 @@ struct sk_buff { |
---|
| 1244 | #ifdef CONFIG_NET_SWITCHDEV |
---|
[6936b89] | 1245 | __u8 offload_fwd_mark:1; |
---|
| 1246 | #endif |
---|
| 1247 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1248 | + __u8 imq_flags:IMQ_F_BITS; |
---|
| 1249 | +#endif |
---|
[efa4154] | 1250 | #ifdef CONFIG_NET_CLS_ACT |
---|
| 1251 | __u8 tc_skip_classify:1; |
---|
| 1252 | __u8 tc_at_ingress:1; |
---|
| 1253 | @@ -870,7 +883,7 @@ static inline bool skb_pfmemalloc(const |
---|
| 1254 | */ |
---|
| 1255 | static inline struct dst_entry *skb_dst(const struct sk_buff *skb) |
---|
| 1256 | { |
---|
| 1257 | - /* If refdst was not refcounted, check we still are in a |
---|
| 1258 | + /* If refdst was not refcounted, check we still are in a |
---|
| 1259 | * rcu_read_lock section |
---|
| 1260 | */ |
---|
| 1261 | WARN_ON((skb->_skb_refdst & SKB_DST_NOREF) && |
---|
| 1262 | @@ -960,6 +973,12 @@ void skb_tx_error(struct sk_buff *skb); |
---|
[6936b89] | 1263 | void consume_skb(struct sk_buff *skb); |
---|
[efa4154] | 1264 | void __consume_stateless_skb(struct sk_buff *skb); |
---|
[6936b89] | 1265 | void __kfree_skb(struct sk_buff *skb); |
---|
| 1266 | + |
---|
| 1267 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1268 | +int skb_save_cb(struct sk_buff *skb); |
---|
| 1269 | +int skb_restore_cb(struct sk_buff *skb); |
---|
| 1270 | +#endif |
---|
| 1271 | + |
---|
| 1272 | extern struct kmem_cache *skbuff_head_cache; |
---|
| 1273 | |
---|
| 1274 | void kfree_skb_partial(struct sk_buff *skb, bool head_stolen); |
---|
[efa4154] | 1275 | @@ -3785,8 +3804,12 @@ static inline void __nf_copy(struct sk_b |
---|
| 1276 | dst->_nfct = src->_nfct; |
---|
| 1277 | nf_conntrack_get(skb_nfct(src)); |
---|
[6936b89] | 1278 | #endif |
---|
| 1279 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
[efa4154] | 1280 | + dst->imq_flags = src->imq_flags; |
---|
| 1281 | + dst->nf_queue_entry = src->nf_queue_entry; |
---|
[6936b89] | 1282 | +#endif |
---|
| 1283 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
---|
[efa4154] | 1284 | - dst->nf_bridge = src->nf_bridge; |
---|
| 1285 | + dst->nf_bridge = src->nf_bridge; |
---|
[6936b89] | 1286 | nf_bridge_get(src->nf_bridge); |
---|
[efa4154] | 1287 | #endif |
---|
| 1288 | #if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) || defined(CONFIG_NF_TABLES) |
---|
| 1289 | diff -Naupr linux-4.14_orig/include/net/netfilter/nf_queue.h linux-4.14/include/net/netfilter/nf_queue.h |
---|
| 1290 | --- linux-4.14_orig/include/net/netfilter/nf_queue.h 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1291 | +++ linux-4.14/include/net/netfilter/nf_queue.h 2017-11-13 11:46:45.847423298 +0700 |
---|
| 1292 | @@ -31,6 +31,12 @@ struct nf_queue_handler { |
---|
[6936b89] | 1293 | void nf_register_queue_handler(struct net *net, const struct nf_queue_handler *qh); |
---|
| 1294 | void nf_unregister_queue_handler(struct net *net); |
---|
| 1295 | void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict); |
---|
| 1296 | +void nf_queue_entry_release_refs(struct nf_queue_entry *entry); |
---|
| 1297 | + |
---|
| 1298 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1299 | +void nf_register_queue_imq_handler(const struct nf_queue_handler *qh); |
---|
| 1300 | +void nf_unregister_queue_imq_handler(void); |
---|
| 1301 | +#endif |
---|
| 1302 | |
---|
| 1303 | void nf_queue_entry_get_refs(struct nf_queue_entry *entry); |
---|
| 1304 | void nf_queue_entry_release_refs(struct nf_queue_entry *entry); |
---|
[efa4154] | 1305 | diff -Naupr linux-4.14_orig/include/net/pkt_sched.h linux-4.14/include/net/pkt_sched.h |
---|
| 1306 | --- linux-4.14_orig/include/net/pkt_sched.h 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1307 | +++ linux-4.14/include/net/pkt_sched.h 2017-11-13 11:46:45.850756651 +0700 |
---|
| 1308 | @@ -109,6 +109,8 @@ int sch_direct_xmit(struct sk_buff *skb, |
---|
[6936b89] | 1309 | |
---|
| 1310 | void __qdisc_run(struct Qdisc *q); |
---|
| 1311 | |
---|
| 1312 | +struct sk_buff *qdisc_dequeue_skb(struct Qdisc *q, bool *validate); |
---|
| 1313 | + |
---|
| 1314 | static inline void qdisc_run(struct Qdisc *q) |
---|
| 1315 | { |
---|
| 1316 | if (qdisc_run_begin(q)) |
---|
[efa4154] | 1317 | diff -Naupr linux-4.14_orig/include/net/sch_generic.h linux-4.14/include/net/sch_generic.h |
---|
| 1318 | --- linux-4.14_orig/include/net/sch_generic.h 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1319 | +++ linux-4.14/include/net/sch_generic.h 2017-11-13 11:46:45.850756651 +0700 |
---|
| 1320 | @@ -567,6 +567,13 @@ static inline int qdisc_enqueue(struct s |
---|
[6936b89] | 1321 | return sch->enqueue(skb, sch, to_free); |
---|
| 1322 | } |
---|
| 1323 | |
---|
| 1324 | +static inline int qdisc_enqueue_root(struct sk_buff *skb, struct Qdisc *sch, |
---|
| 1325 | + struct sk_buff **to_free) |
---|
| 1326 | +{ |
---|
| 1327 | + qdisc_skb_cb(skb)->pkt_len = skb->len; |
---|
| 1328 | + return qdisc_enqueue(skb, sch, to_free) & NET_XMIT_MASK; |
---|
| 1329 | +} |
---|
| 1330 | + |
---|
| 1331 | static inline bool qdisc_is_percpu_stats(const struct Qdisc *q) |
---|
| 1332 | { |
---|
| 1333 | return q->flags & TCQ_F_CPUSTATS; |
---|
[efa4154] | 1334 | diff -Naupr linux-4.14_orig/include/uapi/linux/netfilter.h linux-4.14/include/uapi/linux/netfilter.h |
---|
| 1335 | --- linux-4.14_orig/include/uapi/linux/netfilter.h 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1336 | +++ linux-4.14/include/uapi/linux/netfilter.h 2017-11-13 11:46:45.850756651 +0700 |
---|
[6936b89] | 1337 | @@ -14,7 +14,8 @@ |
---|
| 1338 | #define NF_QUEUE 3 |
---|
| 1339 | #define NF_REPEAT 4 |
---|
[efa4154] | 1340 | #define NF_STOP 5 /* Deprecated, for userspace nf_queue compatibility. */ |
---|
[6936b89] | 1341 | -#define NF_MAX_VERDICT NF_STOP |
---|
| 1342 | +#define NF_IMQ_QUEUE 6 |
---|
| 1343 | +#define NF_MAX_VERDICT NF_IMQ_QUEUE |
---|
| 1344 | |
---|
| 1345 | /* we overload the higher bits for encoding auxiliary data such as the queue |
---|
| 1346 | * number or errno values. Not nice, but better than additional function |
---|
[efa4154] | 1347 | diff -Naupr linux-4.14_orig/net/core/dev.c linux-4.14/net/core/dev.c |
---|
| 1348 | --- linux-4.14_orig/net/core/dev.c 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1349 | +++ linux-4.14/net/core/dev.c 2017-11-13 11:46:45.854090004 +0700 |
---|
| 1350 | @@ -143,6 +143,9 @@ |
---|
| 1351 | #include <linux/hrtimer.h> |
---|
[6936b89] | 1352 | #include <linux/netfilter_ingress.h> |
---|
| 1353 | #include <linux/crash_dump.h> |
---|
| 1354 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1355 | +#include <linux/imq.h> |
---|
| 1356 | +#endif |
---|
[efa4154] | 1357 | #include <linux/sctp.h> |
---|
| 1358 | #include <net/udp_tunnel.h> |
---|
[6936b89] | 1359 | |
---|
[efa4154] | 1360 | @@ -2971,7 +2974,12 @@ static int xmit_one(struct sk_buff *skb, |
---|
[6936b89] | 1361 | unsigned int len; |
---|
| 1362 | int rc; |
---|
| 1363 | |
---|
| 1364 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1365 | + if ((!list_empty(&ptype_all) || !list_empty(&dev->ptype_all)) && |
---|
| 1366 | + !(skb->imq_flags & IMQ_F_ENQUEUE)) |
---|
| 1367 | +#else |
---|
| 1368 | if (!list_empty(&ptype_all) || !list_empty(&dev->ptype_all)) |
---|
| 1369 | +#endif |
---|
| 1370 | dev_queue_xmit_nit(skb, dev); |
---|
| 1371 | |
---|
| 1372 | len = skb->len; |
---|
[efa4154] | 1373 | @@ -3010,6 +3018,8 @@ out: |
---|
[6936b89] | 1374 | return skb; |
---|
| 1375 | } |
---|
| 1376 | |
---|
| 1377 | +EXPORT_SYMBOL_GPL(dev_hard_start_xmit); |
---|
| 1378 | + |
---|
| 1379 | static struct sk_buff *validate_xmit_vlan(struct sk_buff *skb, |
---|
| 1380 | netdev_features_t features) |
---|
| 1381 | { |
---|
[efa4154] | 1382 | diff -Naupr linux-4.14_orig/net/core/skbuff.c linux-4.14/net/core/skbuff.c |
---|
| 1383 | --- linux-4.14_orig/net/core/skbuff.c 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1384 | +++ linux-4.14/net/core/skbuff.c 2017-11-13 11:46:45.854090004 +0700 |
---|
| 1385 | @@ -82,6 +82,87 @@ struct kmem_cache *skbuff_head_cache __r |
---|
[6936b89] | 1386 | static struct kmem_cache *skbuff_fclone_cache __read_mostly; |
---|
| 1387 | int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS; |
---|
| 1388 | EXPORT_SYMBOL(sysctl_max_skb_frags); |
---|
| 1389 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1390 | +static struct kmem_cache *skbuff_cb_store_cache __read_mostly; |
---|
| 1391 | +#endif |
---|
| 1392 | + |
---|
| 1393 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1394 | +/* Control buffer save/restore for IMQ devices */ |
---|
| 1395 | +struct skb_cb_table { |
---|
| 1396 | + char cb[48] __aligned(8); |
---|
| 1397 | + void *cb_next; |
---|
| 1398 | + atomic_t refcnt; |
---|
| 1399 | +}; |
---|
| 1400 | + |
---|
| 1401 | +static DEFINE_SPINLOCK(skb_cb_store_lock); |
---|
| 1402 | + |
---|
| 1403 | +int skb_save_cb(struct sk_buff *skb) |
---|
| 1404 | +{ |
---|
| 1405 | + struct skb_cb_table *next; |
---|
| 1406 | + |
---|
| 1407 | + next = kmem_cache_alloc(skbuff_cb_store_cache, GFP_ATOMIC); |
---|
| 1408 | + if (!next) |
---|
| 1409 | + return -ENOMEM; |
---|
| 1410 | + |
---|
| 1411 | + BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb)); |
---|
| 1412 | + |
---|
| 1413 | + memcpy(next->cb, skb->cb, sizeof(skb->cb)); |
---|
| 1414 | + next->cb_next = skb->cb_next; |
---|
| 1415 | + |
---|
| 1416 | + atomic_set(&next->refcnt, 1); |
---|
| 1417 | + |
---|
| 1418 | + skb->cb_next = next; |
---|
| 1419 | + return 0; |
---|
| 1420 | +} |
---|
| 1421 | +EXPORT_SYMBOL(skb_save_cb); |
---|
| 1422 | + |
---|
| 1423 | +int skb_restore_cb(struct sk_buff *skb) |
---|
| 1424 | +{ |
---|
| 1425 | + struct skb_cb_table *next; |
---|
| 1426 | + |
---|
| 1427 | + if (!skb->cb_next) |
---|
| 1428 | + return 0; |
---|
| 1429 | + |
---|
| 1430 | + next = skb->cb_next; |
---|
| 1431 | + |
---|
| 1432 | + BUILD_BUG_ON(sizeof(skb->cb) != sizeof(next->cb)); |
---|
| 1433 | + |
---|
| 1434 | + memcpy(skb->cb, next->cb, sizeof(skb->cb)); |
---|
| 1435 | + skb->cb_next = next->cb_next; |
---|
| 1436 | + |
---|
| 1437 | + spin_lock(&skb_cb_store_lock); |
---|
| 1438 | + |
---|
| 1439 | + if (atomic_dec_and_test(&next->refcnt)) |
---|
| 1440 | + kmem_cache_free(skbuff_cb_store_cache, next); |
---|
| 1441 | + |
---|
| 1442 | + spin_unlock(&skb_cb_store_lock); |
---|
| 1443 | + |
---|
| 1444 | + return 0; |
---|
| 1445 | +} |
---|
| 1446 | +EXPORT_SYMBOL(skb_restore_cb); |
---|
| 1447 | + |
---|
| 1448 | +static void skb_copy_stored_cb(struct sk_buff * , const struct sk_buff * ) __attribute__ ((unused)); |
---|
| 1449 | +static void skb_copy_stored_cb(struct sk_buff *new, const struct sk_buff *__old) |
---|
| 1450 | +{ |
---|
| 1451 | + struct skb_cb_table *next; |
---|
| 1452 | + struct sk_buff *old; |
---|
| 1453 | + |
---|
| 1454 | + if (!__old->cb_next) { |
---|
| 1455 | + new->cb_next = NULL; |
---|
| 1456 | + return; |
---|
| 1457 | + } |
---|
| 1458 | + |
---|
| 1459 | + spin_lock(&skb_cb_store_lock); |
---|
| 1460 | + |
---|
| 1461 | + old = (struct sk_buff *)__old; |
---|
| 1462 | + |
---|
| 1463 | + next = old->cb_next; |
---|
| 1464 | + atomic_inc(&next->refcnt); |
---|
| 1465 | + new->cb_next = next; |
---|
| 1466 | + |
---|
| 1467 | + spin_unlock(&skb_cb_store_lock); |
---|
| 1468 | +} |
---|
| 1469 | +#endif |
---|
| 1470 | |
---|
| 1471 | /** |
---|
| 1472 | * skb_panic - private function for out-of-line support |
---|
[efa4154] | 1473 | @@ -615,6 +696,28 @@ void skb_release_head_state(struct sk_bu |
---|
[6936b89] | 1474 | WARN_ON(in_irq()); |
---|
| 1475 | skb->destructor(skb); |
---|
| 1476 | } |
---|
| 1477 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1478 | + /* |
---|
| 1479 | + * This should not happen. When it does, avoid memleak by restoring |
---|
| 1480 | + * the chain of cb-backups. |
---|
| 1481 | + */ |
---|
| 1482 | + while (skb->cb_next != NULL) { |
---|
| 1483 | + if (net_ratelimit()) |
---|
| 1484 | + pr_warn("IMQ: kfree_skb: skb->cb_next: %08x\n", |
---|
| 1485 | + (unsigned int)(uintptr_t)skb->cb_next); |
---|
| 1486 | + |
---|
| 1487 | + skb_restore_cb(skb); |
---|
| 1488 | + } |
---|
| 1489 | + /* |
---|
| 1490 | + * This should not happen either, nf_queue_entry is nullified in |
---|
| 1491 | + * imq_dev_xmit(). If we have non-NULL nf_queue_entry then we are |
---|
| 1492 | + * leaking entry pointers, maybe memory. We don't know if this is |
---|
| 1493 | + * pointer to already freed memory, or should this be freed. |
---|
| 1494 | + * If this happens we need to add refcounting, etc for nf_queue_entry. |
---|
| 1495 | + */ |
---|
| 1496 | + if (skb->nf_queue_entry && net_ratelimit()) |
---|
| 1497 | + pr_warn("%s\n", "IMQ: kfree_skb: skb->nf_queue_entry != NULL"); |
---|
| 1498 | +#endif |
---|
| 1499 | #if IS_ENABLED(CONFIG_NF_CONNTRACK) |
---|
[efa4154] | 1500 | nf_conntrack_put(skb_nfct(skb)); |
---|
[6936b89] | 1501 | #endif |
---|
[efa4154] | 1502 | @@ -804,6 +907,10 @@ static void __copy_skb_header(struct sk_ |
---|
[6936b89] | 1503 | new->sp = secpath_get(old->sp); |
---|
| 1504 | #endif |
---|
| 1505 | __nf_copy(new, old, false); |
---|
| 1506 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1507 | + new->cb_next = NULL; |
---|
| 1508 | + /*skb_copy_stored_cb(new, old);*/ |
---|
| 1509 | +#endif |
---|
| 1510 | |
---|
| 1511 | /* Note : this field could be in headers_start/headers_end section |
---|
| 1512 | * It is not yet because we do not want to have a 16 bit hole |
---|
[efa4154] | 1513 | @@ -3902,6 +4009,13 @@ void __init skb_init(void) |
---|
[6936b89] | 1514 | 0, |
---|
| 1515 | SLAB_HWCACHE_ALIGN|SLAB_PANIC, |
---|
| 1516 | NULL); |
---|
| 1517 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1518 | + skbuff_cb_store_cache = kmem_cache_create("skbuff_cb_store_cache", |
---|
| 1519 | + sizeof(struct skb_cb_table), |
---|
| 1520 | + 0, |
---|
| 1521 | + SLAB_HWCACHE_ALIGN|SLAB_PANIC, |
---|
| 1522 | + NULL); |
---|
| 1523 | +#endif |
---|
| 1524 | } |
---|
| 1525 | |
---|
[efa4154] | 1526 | static int |
---|
| 1527 | diff -Naupr linux-4.14_orig/net/netfilter/core.c linux-4.14/net/netfilter/core.c |
---|
| 1528 | --- linux-4.14_orig/net/netfilter/core.c 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1529 | +++ linux-4.14/net/netfilter/core.c 2017-11-13 14:16:05.896850774 +0700 |
---|
| 1530 | @@ -474,6 +474,11 @@ int nf_hook_slow(struct sk_buff *skb, st |
---|
| 1531 | if (ret == 0) |
---|
| 1532 | ret = -EPERM; |
---|
| 1533 | return ret; |
---|
| 1534 | + case NF_IMQ_QUEUE: |
---|
| 1535 | + ret = nf_queue(skb, state, e, s, verdict); |
---|
| 1536 | + if (ret == -ECANCELED) |
---|
| 1537 | + continue; |
---|
| 1538 | + return ret; |
---|
| 1539 | case NF_QUEUE: |
---|
| 1540 | ret = nf_queue(skb, state, e, s, verdict); |
---|
| 1541 | if (ret == 1) |
---|
| 1542 | diff -Naupr linux-4.14_orig/net/netfilter/Kconfig linux-4.14/net/netfilter/Kconfig |
---|
| 1543 | --- linux-4.14_orig/net/netfilter/Kconfig 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1544 | +++ linux-4.14/net/netfilter/Kconfig 2017-11-13 11:46:45.857423358 +0700 |
---|
| 1545 | @@ -867,6 +867,18 @@ config NETFILTER_XT_TARGET_LOG |
---|
[6936b89] | 1546 | |
---|
| 1547 | To compile it as a module, choose M here. If unsure, say N. |
---|
| 1548 | |
---|
| 1549 | +config NETFILTER_XT_TARGET_IMQ |
---|
| 1550 | + tristate '"IMQ" target support' |
---|
| 1551 | + depends on NETFILTER_XTABLES |
---|
| 1552 | + depends on IP_NF_MANGLE || IP6_NF_MANGLE |
---|
| 1553 | + select IMQ |
---|
| 1554 | + default m if NETFILTER_ADVANCED=n |
---|
| 1555 | + help |
---|
| 1556 | + This option adds a `IMQ' target which is used to specify if and |
---|
| 1557 | + to which imq device packets should get enqueued/dequeued. |
---|
| 1558 | + |
---|
| 1559 | + To compile it as a module, choose M here. If unsure, say N. |
---|
| 1560 | + |
---|
| 1561 | config NETFILTER_XT_TARGET_MARK |
---|
| 1562 | tristate '"MARK" target support' |
---|
| 1563 | depends on NETFILTER_ADVANCED |
---|
[efa4154] | 1564 | diff -Naupr linux-4.14_orig/net/netfilter/Makefile linux-4.14/net/netfilter/Makefile |
---|
| 1565 | --- linux-4.14_orig/net/netfilter/Makefile 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1566 | +++ linux-4.14/net/netfilter/Makefile 2017-11-13 11:46:45.857423358 +0700 |
---|
| 1567 | @@ -125,6 +125,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += |
---|
[6936b89] | 1568 | obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o |
---|
| 1569 | obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o |
---|
| 1570 | obj-$(CONFIG_NETFILTER_XT_TARGET_HMARK) += xt_HMARK.o |
---|
| 1571 | +obj-$(CONFIG_NETFILTER_XT_TARGET_IMQ) += xt_IMQ.o |
---|
| 1572 | obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o |
---|
| 1573 | obj-$(CONFIG_NETFILTER_XT_TARGET_LOG) += xt_LOG.o |
---|
| 1574 | obj-$(CONFIG_NETFILTER_XT_TARGET_NETMAP) += xt_NETMAP.o |
---|
[efa4154] | 1575 | diff -Naupr linux-4.14_orig/net/netfilter/nf_queue.c linux-4.14/net/netfilter/nf_queue.c |
---|
| 1576 | --- linux-4.14_orig/net/netfilter/nf_queue.c 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1577 | +++ linux-4.14/net/netfilter/nf_queue.c 2017-11-13 14:25:21.436864671 +0700 |
---|
| 1578 | @@ -1,4 +1,4 @@ |
---|
| 1579 | -/* |
---|
| 1580 | + /* |
---|
| 1581 | * Rusty Russell (C)2000 -- This code is GPL. |
---|
| 1582 | * Patrick McHardy (c) 2006-2012 |
---|
| 1583 | */ |
---|
[6936b89] | 1584 | @@ -27,6 +27,23 @@ |
---|
| 1585 | * receives, no matter what. |
---|
| 1586 | */ |
---|
| 1587 | |
---|
| 1588 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
| 1589 | +static const struct nf_queue_handler __rcu *queue_imq_handler __read_mostly; |
---|
| 1590 | + |
---|
| 1591 | +void nf_register_queue_imq_handler(const struct nf_queue_handler *qh) |
---|
| 1592 | +{ |
---|
| 1593 | + rcu_assign_pointer(queue_imq_handler, qh); |
---|
| 1594 | +} |
---|
| 1595 | +EXPORT_SYMBOL_GPL(nf_register_queue_imq_handler); |
---|
| 1596 | + |
---|
| 1597 | +void nf_unregister_queue_imq_handler(void) |
---|
| 1598 | +{ |
---|
| 1599 | + RCU_INIT_POINTER(queue_imq_handler, NULL); |
---|
| 1600 | + synchronize_rcu(); |
---|
| 1601 | +} |
---|
| 1602 | +EXPORT_SYMBOL_GPL(nf_unregister_queue_imq_handler); |
---|
| 1603 | +#endif |
---|
| 1604 | + |
---|
| 1605 | /* return EBUSY when somebody else is registered, return EEXIST if the |
---|
| 1606 | * same handler is registered, return 0 in case of success. */ |
---|
| 1607 | void nf_register_queue_handler(struct net *net, const struct nf_queue_handler *qh) |
---|
[efa4154] | 1608 | @@ -113,16 +130,29 @@ EXPORT_SYMBOL_GPL(nf_queue_nf_hook_drop) |
---|
[6936b89] | 1609 | |
---|
| 1610 | static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, |
---|
[efa4154] | 1611 | const struct nf_hook_entries *entries, |
---|
| 1612 | - unsigned int index, unsigned int queuenum) |
---|
| 1613 | + unsigned int index, unsigned int verdict) |
---|
[6936b89] | 1614 | { |
---|
| 1615 | int status = -ENOENT; |
---|
| 1616 | struct nf_queue_entry *entry = NULL; |
---|
| 1617 | const struct nf_afinfo *afinfo; |
---|
| 1618 | const struct nf_queue_handler *qh; |
---|
| 1619 | struct net *net = state->net; |
---|
| 1620 | + unsigned int queuetype = verdict & NF_VERDICT_MASK; |
---|
| 1621 | + unsigned int queuenum = verdict >> NF_VERDICT_QBITS; |
---|
| 1622 | |
---|
| 1623 | /* QUEUE == DROP if no one is waiting, to be safe. */ |
---|
| 1624 | - qh = rcu_dereference(net->nf.queue_handler); |
---|
[efa4154] | 1625 | + |
---|
[6936b89] | 1626 | + if (queuetype == NF_IMQ_QUEUE) { |
---|
| 1627 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
[efa4154] | 1628 | + qh = rcu_dereference(queue_imq_handler); |
---|
[6936b89] | 1629 | +#else |
---|
[efa4154] | 1630 | + BUG(); |
---|
| 1631 | + goto err_unlock; |
---|
[6936b89] | 1632 | +#endif |
---|
| 1633 | + } else { |
---|
| 1634 | + qh = rcu_dereference(net->nf.queue_handler); |
---|
| 1635 | + } |
---|
| 1636 | + |
---|
| 1637 | if (!qh) { |
---|
| 1638 | status = -ESRCH; |
---|
| 1639 | goto err; |
---|
[efa4154] | 1640 | @@ -169,8 +199,16 @@ int nf_queue(struct sk_buff *skb, struct |
---|
| 1641 | { |
---|
[6936b89] | 1642 | int ret; |
---|
| 1643 | |
---|
[efa4154] | 1644 | - ret = __nf_queue(skb, state, entries, index, verdict >> NF_VERDICT_QBITS); |
---|
| 1645 | + ret = __nf_queue(skb, state, entries, index, verdict); |
---|
[6936b89] | 1646 | if (ret < 0) { |
---|
[efa4154] | 1647 | + |
---|
[6936b89] | 1648 | +#if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE) |
---|
[efa4154] | 1649 | + /* IMQ Bypass */ |
---|
| 1650 | + if (ret == -ECANCELED && skb->imq_flags == 0) { |
---|
| 1651 | + return 1; |
---|
| 1652 | + } |
---|
[6936b89] | 1653 | +#endif |
---|
[efa4154] | 1654 | + |
---|
[6936b89] | 1655 | if (ret == -ESRCH && |
---|
[efa4154] | 1656 | (verdict & NF_VERDICT_FLAG_QUEUE_BYPASS)) |
---|
| 1657 | return 1; |
---|
| 1658 | @@ -256,6 +294,7 @@ next_hook: |
---|
[6936b89] | 1659 | local_bh_enable(); |
---|
| 1660 | break; |
---|
| 1661 | case NF_QUEUE: |
---|
| 1662 | + case NF_IMQ_QUEUE: |
---|
[efa4154] | 1663 | err = nf_queue(skb, &entry->state, hooks, i, verdict); |
---|
| 1664 | if (err == 1) |
---|
| 1665 | goto next_hook; |
---|
| 1666 | diff -Naupr linux-4.14_orig/net/netfilter/xt_IMQ.c linux-4.14/net/netfilter/xt_IMQ.c |
---|
| 1667 | --- linux-4.14_orig/net/netfilter/xt_IMQ.c 1970-01-01 07:00:00.000000000 +0700 |
---|
| 1668 | +++ linux-4.14/net/netfilter/xt_IMQ.c 2017-11-13 11:46:45.857423358 +0700 |
---|
[6936b89] | 1669 | @@ -0,0 +1,72 @@ |
---|
| 1670 | +/* |
---|
| 1671 | + * This target marks packets to be enqueued to an imq device |
---|
| 1672 | + */ |
---|
| 1673 | +#include <linux/module.h> |
---|
| 1674 | +#include <linux/skbuff.h> |
---|
| 1675 | +#include <linux/netfilter/x_tables.h> |
---|
| 1676 | +#include <linux/netfilter/xt_IMQ.h> |
---|
| 1677 | +#include <linux/imq.h> |
---|
| 1678 | + |
---|
| 1679 | +static unsigned int imq_target(struct sk_buff *pskb, |
---|
| 1680 | + const struct xt_action_param *par) |
---|
| 1681 | +{ |
---|
| 1682 | + const struct xt_imq_info *mr = par->targinfo; |
---|
| 1683 | + |
---|
| 1684 | + pskb->imq_flags = (mr->todev & IMQ_F_IFMASK) | IMQ_F_ENQUEUE; |
---|
| 1685 | + |
---|
| 1686 | + return XT_CONTINUE; |
---|
| 1687 | +} |
---|
| 1688 | + |
---|
| 1689 | +static int imq_checkentry(const struct xt_tgchk_param *par) |
---|
| 1690 | +{ |
---|
| 1691 | + struct xt_imq_info *mr = par->targinfo; |
---|
| 1692 | + |
---|
| 1693 | + if (mr->todev > IMQ_MAX_DEVS - 1) { |
---|
| 1694 | + pr_warn("IMQ: invalid device specified, highest is %u\n", |
---|
| 1695 | + IMQ_MAX_DEVS - 1); |
---|
| 1696 | + return -EINVAL; |
---|
| 1697 | + } |
---|
| 1698 | + |
---|
| 1699 | + return 0; |
---|
| 1700 | +} |
---|
| 1701 | + |
---|
| 1702 | +static struct xt_target xt_imq_reg[] __read_mostly = { |
---|
| 1703 | + { |
---|
| 1704 | + .name = "IMQ", |
---|
| 1705 | + .family = AF_INET, |
---|
| 1706 | + .checkentry = imq_checkentry, |
---|
| 1707 | + .target = imq_target, |
---|
| 1708 | + .targetsize = sizeof(struct xt_imq_info), |
---|
| 1709 | + .table = "mangle", |
---|
| 1710 | + .me = THIS_MODULE |
---|
| 1711 | + }, |
---|
| 1712 | + { |
---|
| 1713 | + .name = "IMQ", |
---|
| 1714 | + .family = AF_INET6, |
---|
| 1715 | + .checkentry = imq_checkentry, |
---|
| 1716 | + .target = imq_target, |
---|
| 1717 | + .targetsize = sizeof(struct xt_imq_info), |
---|
| 1718 | + .table = "mangle", |
---|
| 1719 | + .me = THIS_MODULE |
---|
| 1720 | + }, |
---|
| 1721 | +}; |
---|
| 1722 | + |
---|
| 1723 | +static int __init imq_init(void) |
---|
| 1724 | +{ |
---|
| 1725 | + return xt_register_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg)); |
---|
| 1726 | +} |
---|
| 1727 | + |
---|
| 1728 | +static void __exit imq_fini(void) |
---|
| 1729 | +{ |
---|
| 1730 | + xt_unregister_targets(xt_imq_reg, ARRAY_SIZE(xt_imq_reg)); |
---|
| 1731 | +} |
---|
| 1732 | + |
---|
| 1733 | +module_init(imq_init); |
---|
| 1734 | +module_exit(imq_fini); |
---|
| 1735 | + |
---|
| 1736 | +MODULE_AUTHOR("https://github.com/imq/linuximq"); |
---|
| 1737 | +MODULE_DESCRIPTION("Pseudo-driver for the intermediate queue device. See https://github.com/imq/linuximq/wiki for more information."); |
---|
| 1738 | +MODULE_LICENSE("GPL"); |
---|
| 1739 | +MODULE_ALIAS("ipt_IMQ"); |
---|
| 1740 | +MODULE_ALIAS("ip6t_IMQ"); |
---|
| 1741 | + |
---|
[efa4154] | 1742 | diff -Naupr linux-4.14_orig/net/sched/sch_generic.c linux-4.14/net/sched/sch_generic.c |
---|
| 1743 | --- linux-4.14_orig/net/sched/sch_generic.c 2017-11-13 01:46:13.000000000 +0700 |
---|
| 1744 | +++ linux-4.14/net/sched/sch_generic.c 2017-11-13 11:46:45.857423358 +0700 |
---|
| 1745 | @@ -158,6 +158,14 @@ trace: |
---|
[6936b89] | 1746 | return skb; |
---|
| 1747 | } |
---|
| 1748 | |
---|
| 1749 | +struct sk_buff *qdisc_dequeue_skb(struct Qdisc *q, bool *validate) |
---|
| 1750 | +{ |
---|
| 1751 | + int packets; |
---|
| 1752 | + |
---|
| 1753 | + return dequeue_skb(q, validate, &packets); |
---|
| 1754 | +} |
---|
| 1755 | +EXPORT_SYMBOL(qdisc_dequeue_skb); |
---|
| 1756 | + |
---|
| 1757 | /* |
---|
| 1758 | * Transmit possibly several skbs, and handle the return status as |
---|
| 1759 | * required. Owning running seqcount bit guarantees that |
---|