netpoll.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. /*
  2. * Common framework for low-level network console, dump, and debugger code
  3. *
  4. * Sep 8 2003 Matt Mackall <mpm@selenic.com>
  5. *
  6. * based on the netconsole code from:
  7. *
  8. * Copyright (C) 2001 Ingo Molnar <mingo@redhat.com>
  9. * Copyright (C) 2002 Red Hat, Inc.
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/moduleparam.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/etherdevice.h>
  15. #include <linux/string.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/inetdevice.h>
  18. #include <linux/inet.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/netpoll.h>
  21. #include <linux/sched.h>
  22. #include <linux/delay.h>
  23. #include <linux/rcupdate.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/slab.h>
  26. #include <linux/export.h>
  27. #include <linux/if_vlan.h>
  28. #include <net/tcp.h>
  29. #include <net/udp.h>
  30. #include <net/addrconf.h>
  31. #include <net/ndisc.h>
  32. #include <net/ip6_checksum.h>
  33. #include <asm/unaligned.h>
  34. #include <trace/events/napi.h>
  35. /*
  36. * We maintain a small pool of fully-sized skbs, to make sure the
  37. * message gets out even in extreme OOM situations.
  38. */
  39. #define MAX_UDP_CHUNK 1460
  40. #define MAX_SKBS 32
  41. static struct sk_buff_head skb_pool;
  42. static atomic_t trapped;
  43. static struct srcu_struct netpoll_srcu;
  44. #define USEC_PER_POLL 50
  45. #define NETPOLL_RX_ENABLED 1
  46. #define NETPOLL_RX_DROP 2
  47. #define MAX_SKB_SIZE \
  48. (sizeof(struct ethhdr) + \
  49. sizeof(struct iphdr) + \
  50. sizeof(struct udphdr) + \
  51. MAX_UDP_CHUNK)
  52. static void zap_completion_queue(void);
  53. static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo);
  54. static unsigned int carrier_timeout = 4;
  55. module_param(carrier_timeout, uint, 0644);
  56. #define np_info(np, fmt, ...) \
  57. pr_info("%s: " fmt, np->name, ##__VA_ARGS__)
  58. #define np_err(np, fmt, ...) \
  59. pr_err("%s: " fmt, np->name, ##__VA_ARGS__)
  60. #define np_notice(np, fmt, ...) \
  61. pr_notice("%s: " fmt, np->name, ##__VA_ARGS__)
  62. static void queue_process(struct work_struct *work)
  63. {
  64. struct netpoll_info *npinfo =
  65. container_of(work, struct netpoll_info, tx_work.work);
  66. struct sk_buff *skb;
  67. unsigned long flags;
  68. while ((skb = skb_dequeue(&npinfo->txq))) {
  69. struct net_device *dev = skb->dev;
  70. const struct net_device_ops *ops = dev->netdev_ops;
  71. struct netdev_queue *txq;
  72. if (!netif_device_present(dev) || !netif_running(dev)) {
  73. __kfree_skb(skb);
  74. continue;
  75. }
  76. txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
  77. local_irq_save(flags);
  78. __netif_tx_lock(txq, smp_processor_id());
  79. if (netif_xmit_frozen_or_stopped(txq) ||
  80. ops->ndo_start_xmit(skb, dev) != NETDEV_TX_OK) {
  81. skb_queue_head(&npinfo->txq, skb);
  82. __netif_tx_unlock(txq);
  83. local_irq_restore(flags);
  84. schedule_delayed_work(&npinfo->tx_work, HZ/10);
  85. return;
  86. }
  87. __netif_tx_unlock(txq);
  88. local_irq_restore(flags);
  89. }
  90. }
  91. static __sum16 checksum_udp(struct sk_buff *skb, struct udphdr *uh,
  92. unsigned short ulen, __be32 saddr, __be32 daddr)
  93. {
  94. __wsum psum;
  95. if (uh->check == 0 || skb_csum_unnecessary(skb))
  96. return 0;
  97. psum = csum_tcpudp_nofold(saddr, daddr, ulen, IPPROTO_UDP, 0);
  98. if (skb->ip_summed == CHECKSUM_COMPLETE &&
  99. !csum_fold(csum_add(psum, skb->csum)))
  100. return 0;
  101. skb->csum = psum;
  102. return __skb_checksum_complete(skb);
  103. }
  104. /*
  105. * Check whether delayed processing was scheduled for our NIC. If so,
  106. * we attempt to grab the poll lock and use ->poll() to pump the card.
  107. * If this fails, either we've recursed in ->poll() or it's already
  108. * running on another CPU.
  109. *
  110. * Note: we don't mask interrupts with this lock because we're using
  111. * trylock here and interrupts are already disabled in the softirq
  112. * case. Further, we test the poll_owner to avoid recursion on UP
  113. * systems where the lock doesn't exist.
  114. *
  115. * In cases where there is bi-directional communications, reading only
  116. * one message at a time can lead to packets being dropped by the
  117. * network adapter, forcing superfluous retries and possibly timeouts.
  118. * Thus, we set our budget to greater than 1.
  119. */
  120. static int poll_one_napi(struct netpoll_info *npinfo,
  121. struct napi_struct *napi, int budget)
  122. {
  123. int work;
  124. /* net_rx_action's ->poll() invocations and our's are
  125. * synchronized by this test which is only made while
  126. * holding the napi->poll_lock.
  127. */
  128. if (!test_bit(NAPI_STATE_SCHED, &napi->state))
  129. return budget;
  130. npinfo->rx_flags |= NETPOLL_RX_DROP;
  131. atomic_inc(&trapped);
  132. set_bit(NAPI_STATE_NPSVC, &napi->state);
  133. work = napi->poll(napi, budget);
  134. trace_napi_poll(napi);
  135. clear_bit(NAPI_STATE_NPSVC, &napi->state);
  136. atomic_dec(&trapped);
  137. npinfo->rx_flags &= ~NETPOLL_RX_DROP;
  138. return budget - work;
  139. }
  140. static void poll_napi(struct net_device *dev)
  141. {
  142. struct napi_struct *napi;
  143. int budget = 16;
  144. list_for_each_entry(napi, &dev->napi_list, dev_list) {
  145. if (napi->poll_owner != smp_processor_id() &&
  146. spin_trylock(&napi->poll_lock)) {
  147. budget = poll_one_napi(rcu_dereference_bh(dev->npinfo),
  148. napi, budget);
  149. spin_unlock(&napi->poll_lock);
  150. if (!budget)
  151. break;
  152. }
  153. }
  154. }
  155. static void service_neigh_queue(struct netpoll_info *npi)
  156. {
  157. if (npi) {
  158. struct sk_buff *skb;
  159. while ((skb = skb_dequeue(&npi->neigh_tx)))
  160. netpoll_neigh_reply(skb, npi);
  161. }
  162. }
  163. static void netpoll_poll_dev(struct net_device *dev)
  164. {
  165. const struct net_device_ops *ops;
  166. struct netpoll_info *ni = rcu_dereference_bh(dev->npinfo);
  167. /* Don't do any rx activity if the dev_lock mutex is held
  168. * the dev_open/close paths use this to block netpoll activity
  169. * while changing device state
  170. */
  171. if (!mutex_trylock(&dev->npinfo->dev_lock))
  172. return;
  173. if (!dev || !netif_running(dev))
  174. return;
  175. ops = dev->netdev_ops;
  176. if (!ops->ndo_poll_controller)
  177. return;
  178. /* Process pending work on NIC */
  179. ops->ndo_poll_controller(dev);
  180. poll_napi(dev);
  181. mutex_unlock(&dev->npinfo->dev_lock);
  182. if (dev->flags & IFF_SLAVE) {
  183. if (ni) {
  184. struct net_device *bond_dev;
  185. struct sk_buff *skb;
  186. struct netpoll_info *bond_ni;
  187. bond_dev = netdev_master_upper_dev_get_rcu(dev);
  188. bond_ni = rcu_dereference_bh(bond_dev->npinfo);
  189. while ((skb = skb_dequeue(&ni->neigh_tx))) {
  190. skb->dev = bond_dev;
  191. skb_queue_tail(&bond_ni->neigh_tx, skb);
  192. }
  193. }
  194. }
  195. service_neigh_queue(ni);
  196. zap_completion_queue();
  197. }
  198. int netpoll_rx_disable(struct net_device *dev)
  199. {
  200. struct netpoll_info *ni;
  201. int idx;
  202. might_sleep();
  203. idx = srcu_read_lock(&netpoll_srcu);
  204. ni = srcu_dereference(dev->npinfo, &netpoll_srcu);
  205. if (ni)
  206. mutex_lock(&ni->dev_lock);
  207. srcu_read_unlock(&netpoll_srcu, idx);
  208. return 0;
  209. }
  210. EXPORT_SYMBOL(netpoll_rx_disable);
  211. void netpoll_rx_enable(struct net_device *dev)
  212. {
  213. struct netpoll_info *ni;
  214. rcu_read_lock();
  215. ni = rcu_dereference(dev->npinfo);
  216. if (ni)
  217. mutex_unlock(&ni->dev_lock);
  218. rcu_read_unlock();
  219. }
  220. EXPORT_SYMBOL(netpoll_rx_enable);
  221. static void refill_skbs(void)
  222. {
  223. struct sk_buff *skb;
  224. unsigned long flags;
  225. spin_lock_irqsave(&skb_pool.lock, flags);
  226. while (skb_pool.qlen < MAX_SKBS) {
  227. skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC);
  228. if (!skb)
  229. break;
  230. __skb_queue_tail(&skb_pool, skb);
  231. }
  232. spin_unlock_irqrestore(&skb_pool.lock, flags);
  233. }
  234. static void zap_completion_queue(void)
  235. {
  236. unsigned long flags;
  237. struct softnet_data *sd = &get_cpu_var(softnet_data);
  238. if (sd->completion_queue) {
  239. struct sk_buff *clist;
  240. local_irq_save(flags);
  241. clist = sd->completion_queue;
  242. sd->completion_queue = NULL;
  243. local_irq_restore(flags);
  244. while (clist != NULL) {
  245. struct sk_buff *skb = clist;
  246. clist = clist->next;
  247. if (skb->destructor) {
  248. atomic_inc(&skb->users);
  249. dev_kfree_skb_any(skb); /* put this one back */
  250. } else {
  251. __kfree_skb(skb);
  252. }
  253. }
  254. }
  255. put_cpu_var(softnet_data);
  256. }
  257. static struct sk_buff *find_skb(struct netpoll *np, int len, int reserve)
  258. {
  259. int count = 0;
  260. struct sk_buff *skb;
  261. zap_completion_queue();
  262. refill_skbs();
  263. repeat:
  264. skb = alloc_skb(len, GFP_ATOMIC);
  265. if (!skb)
  266. skb = skb_dequeue(&skb_pool);
  267. if (!skb) {
  268. if (++count < 10) {
  269. netpoll_poll_dev(np->dev);
  270. goto repeat;
  271. }
  272. return NULL;
  273. }
  274. atomic_set(&skb->users, 1);
  275. skb_reserve(skb, reserve);
  276. return skb;
  277. }
  278. static int netpoll_owner_active(struct net_device *dev)
  279. {
  280. struct napi_struct *napi;
  281. list_for_each_entry(napi, &dev->napi_list, dev_list) {
  282. if (napi->poll_owner == smp_processor_id())
  283. return 1;
  284. }
  285. return 0;
  286. }
  287. /* call with IRQ disabled */
  288. void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
  289. struct net_device *dev)
  290. {
  291. int status = NETDEV_TX_BUSY;
  292. unsigned long tries;
  293. const struct net_device_ops *ops = dev->netdev_ops;
  294. /* It is up to the caller to keep npinfo alive. */
  295. struct netpoll_info *npinfo;
  296. WARN_ON_ONCE(!irqs_disabled());
  297. npinfo = rcu_dereference_bh(np->dev->npinfo);
  298. if (!npinfo || !netif_running(dev) || !netif_device_present(dev)) {
  299. __kfree_skb(skb);
  300. return;
  301. }
  302. /* don't get messages out of order, and no recursion */
  303. if (skb_queue_len(&npinfo->txq) == 0 && !netpoll_owner_active(dev)) {
  304. struct netdev_queue *txq;
  305. txq = netdev_pick_tx(dev, skb);
  306. /* try until next clock tick */
  307. for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
  308. tries > 0; --tries) {
  309. if (__netif_tx_trylock(txq)) {
  310. if (!netif_xmit_stopped(txq)) {
  311. if (vlan_tx_tag_present(skb) &&
  312. !(netif_skb_features(skb) & NETIF_F_HW_VLAN_TX)) {
  313. skb = __vlan_put_tag(skb, vlan_tx_tag_get(skb));
  314. if (unlikely(!skb))
  315. break;
  316. skb->vlan_tci = 0;
  317. }
  318. status = ops->ndo_start_xmit(skb, dev);
  319. if (status == NETDEV_TX_OK)
  320. txq_trans_update(txq);
  321. }
  322. __netif_tx_unlock(txq);
  323. if (status == NETDEV_TX_OK)
  324. break;
  325. }
  326. /* tickle device maybe there is some cleanup */
  327. netpoll_poll_dev(np->dev);
  328. udelay(USEC_PER_POLL);
  329. }
  330. WARN_ONCE(!irqs_disabled(),
  331. "netpoll_send_skb_on_dev(): %s enabled interrupts in poll (%pF)\n",
  332. dev->name, ops->ndo_start_xmit);
  333. }
  334. if (status != NETDEV_TX_OK) {
  335. skb_queue_tail(&npinfo->txq, skb);
  336. schedule_delayed_work(&npinfo->tx_work,0);
  337. }
  338. }
  339. EXPORT_SYMBOL(netpoll_send_skb_on_dev);
  340. void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
  341. {
  342. int total_len, ip_len, udp_len;
  343. struct sk_buff *skb;
  344. struct udphdr *udph;
  345. struct iphdr *iph;
  346. struct ethhdr *eth;
  347. static atomic_t ip_ident;
  348. struct ipv6hdr *ip6h;
  349. udp_len = len + sizeof(*udph);
  350. if (np->ipv6)
  351. ip_len = udp_len + sizeof(*ip6h);
  352. else
  353. ip_len = udp_len + sizeof(*iph);
  354. total_len = ip_len + LL_RESERVED_SPACE(np->dev);
  355. skb = find_skb(np, total_len + np->dev->needed_tailroom,
  356. total_len - len);
  357. if (!skb)
  358. return;
  359. skb_copy_to_linear_data(skb, msg, len);
  360. skb_put(skb, len);
  361. skb_push(skb, sizeof(*udph));
  362. skb_reset_transport_header(skb);
  363. udph = udp_hdr(skb);
  364. udph->source = htons(np->local_port);
  365. udph->dest = htons(np->remote_port);
  366. udph->len = htons(udp_len);
  367. if (np->ipv6) {
  368. udph->check = 0;
  369. udph->check = csum_ipv6_magic(&np->local_ip.in6,
  370. &np->remote_ip.in6,
  371. udp_len, IPPROTO_UDP,
  372. csum_partial(udph, udp_len, 0));
  373. if (udph->check == 0)
  374. udph->check = CSUM_MANGLED_0;
  375. skb_push(skb, sizeof(*ip6h));
  376. skb_reset_network_header(skb);
  377. ip6h = ipv6_hdr(skb);
  378. /* ip6h->version = 6; ip6h->priority = 0; */
  379. put_unaligned(0x60, (unsigned char *)ip6h);
  380. ip6h->flow_lbl[0] = 0;
  381. ip6h->flow_lbl[1] = 0;
  382. ip6h->flow_lbl[2] = 0;
  383. ip6h->payload_len = htons(sizeof(struct udphdr) + len);
  384. ip6h->nexthdr = IPPROTO_UDP;
  385. ip6h->hop_limit = 32;
  386. ip6h->saddr = np->local_ip.in6;
  387. ip6h->daddr = np->remote_ip.in6;
  388. eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
  389. skb_reset_mac_header(skb);
  390. skb->protocol = eth->h_proto = htons(ETH_P_IPV6);
  391. } else {
  392. udph->check = 0;
  393. udph->check = csum_tcpudp_magic(np->local_ip.ip,
  394. np->remote_ip.ip,
  395. udp_len, IPPROTO_UDP,
  396. csum_partial(udph, udp_len, 0));
  397. if (udph->check == 0)
  398. udph->check = CSUM_MANGLED_0;
  399. skb_push(skb, sizeof(*iph));
  400. skb_reset_network_header(skb);
  401. iph = ip_hdr(skb);
  402. /* iph->version = 4; iph->ihl = 5; */
  403. put_unaligned(0x45, (unsigned char *)iph);
  404. iph->tos = 0;
  405. put_unaligned(htons(ip_len), &(iph->tot_len));
  406. iph->id = htons(atomic_inc_return(&ip_ident));
  407. iph->frag_off = 0;
  408. iph->ttl = 64;
  409. iph->protocol = IPPROTO_UDP;
  410. iph->check = 0;
  411. put_unaligned(np->local_ip.ip, &(iph->saddr));
  412. put_unaligned(np->remote_ip.ip, &(iph->daddr));
  413. iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
  414. eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
  415. skb_reset_mac_header(skb);
  416. skb->protocol = eth->h_proto = htons(ETH_P_IP);
  417. }
  418. memcpy(eth->h_source, np->dev->dev_addr, ETH_ALEN);
  419. memcpy(eth->h_dest, np->remote_mac, ETH_ALEN);
  420. skb->dev = np->dev;
  421. netpoll_send_skb(np, skb);
  422. }
  423. EXPORT_SYMBOL(netpoll_send_udp);
  424. static void netpoll_neigh_reply(struct sk_buff *skb, struct netpoll_info *npinfo)
  425. {
  426. int size, type = ARPOP_REPLY;
  427. __be32 sip, tip;
  428. unsigned char *sha;
  429. struct sk_buff *send_skb;
  430. struct netpoll *np, *tmp;
  431. unsigned long flags;
  432. int hlen, tlen;
  433. int hits = 0, proto;
  434. if (list_empty(&npinfo->rx_np))
  435. return;
  436. /* Before checking the packet, we do some early
  437. inspection whether this is interesting at all */
  438. spin_lock_irqsave(&npinfo->rx_lock, flags);
  439. list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
  440. if (np->dev == skb->dev)
  441. hits++;
  442. }
  443. spin_unlock_irqrestore(&npinfo->rx_lock, flags);
  444. /* No netpoll struct is using this dev */
  445. if (!hits)
  446. return;
  447. proto = ntohs(eth_hdr(skb)->h_proto);
  448. if (proto == ETH_P_IP) {
  449. struct arphdr *arp;
  450. unsigned char *arp_ptr;
  451. /* No arp on this interface */
  452. if (skb->dev->flags & IFF_NOARP)
  453. return;
  454. if (!pskb_may_pull(skb, arp_hdr_len(skb->dev)))
  455. return;
  456. skb_reset_network_header(skb);
  457. skb_reset_transport_header(skb);
  458. arp = arp_hdr(skb);
  459. if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
  460. arp->ar_hrd != htons(ARPHRD_IEEE802)) ||
  461. arp->ar_pro != htons(ETH_P_IP) ||
  462. arp->ar_op != htons(ARPOP_REQUEST))
  463. return;
  464. arp_ptr = (unsigned char *)(arp+1);
  465. /* save the location of the src hw addr */
  466. sha = arp_ptr;
  467. arp_ptr += skb->dev->addr_len;
  468. memcpy(&sip, arp_ptr, 4);
  469. arp_ptr += 4;
  470. /* If we actually cared about dst hw addr,
  471. it would get copied here */
  472. arp_ptr += skb->dev->addr_len;
  473. memcpy(&tip, arp_ptr, 4);
  474. /* Should we ignore arp? */
  475. if (ipv4_is_loopback(tip) || ipv4_is_multicast(tip))
  476. return;
  477. size = arp_hdr_len(skb->dev);
  478. spin_lock_irqsave(&npinfo->rx_lock, flags);
  479. list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
  480. if (tip != np->local_ip.ip)
  481. continue;
  482. hlen = LL_RESERVED_SPACE(np->dev);
  483. tlen = np->dev->needed_tailroom;
  484. send_skb = find_skb(np, size + hlen + tlen, hlen);
  485. if (!send_skb)
  486. continue;
  487. skb_reset_network_header(send_skb);
  488. arp = (struct arphdr *) skb_put(send_skb, size);
  489. send_skb->dev = skb->dev;
  490. send_skb->protocol = htons(ETH_P_ARP);
  491. /* Fill the device header for the ARP frame */
  492. if (dev_hard_header(send_skb, skb->dev, ETH_P_ARP,
  493. sha, np->dev->dev_addr,
  494. send_skb->len) < 0) {
  495. kfree_skb(send_skb);
  496. continue;
  497. }
  498. /*
  499. * Fill out the arp protocol part.
  500. *
  501. * we only support ethernet device type,
  502. * which (according to RFC 1390) should
  503. * always equal 1 (Ethernet).
  504. */
  505. arp->ar_hrd = htons(np->dev->type);
  506. arp->ar_pro = htons(ETH_P_IP);
  507. arp->ar_hln = np->dev->addr_len;
  508. arp->ar_pln = 4;
  509. arp->ar_op = htons(type);
  510. arp_ptr = (unsigned char *)(arp + 1);
  511. memcpy(arp_ptr, np->dev->dev_addr, np->dev->addr_len);
  512. arp_ptr += np->dev->addr_len;
  513. memcpy(arp_ptr, &tip, 4);
  514. arp_ptr += 4;
  515. memcpy(arp_ptr, sha, np->dev->addr_len);
  516. arp_ptr += np->dev->addr_len;
  517. memcpy(arp_ptr, &sip, 4);
  518. netpoll_send_skb(np, send_skb);
  519. /* If there are several rx_hooks for the same address,
  520. we're fine by sending a single reply */
  521. break;
  522. }
  523. spin_unlock_irqrestore(&npinfo->rx_lock, flags);
  524. } else if( proto == ETH_P_IPV6) {
  525. #if IS_ENABLED(CONFIG_IPV6)
  526. struct nd_msg *msg;
  527. u8 *lladdr = NULL;
  528. struct ipv6hdr *hdr;
  529. struct icmp6hdr *icmp6h;
  530. const struct in6_addr *saddr;
  531. const struct in6_addr *daddr;
  532. struct inet6_dev *in6_dev = NULL;
  533. struct in6_addr *target;
  534. in6_dev = in6_dev_get(skb->dev);
  535. if (!in6_dev || !in6_dev->cnf.accept_ra)
  536. return;
  537. if (!pskb_may_pull(skb, skb->len))
  538. return;
  539. msg = (struct nd_msg *)skb_transport_header(skb);
  540. __skb_push(skb, skb->data - skb_transport_header(skb));
  541. if (ipv6_hdr(skb)->hop_limit != 255)
  542. return;
  543. if (msg->icmph.icmp6_code != 0)
  544. return;
  545. if (msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION)
  546. return;
  547. saddr = &ipv6_hdr(skb)->saddr;
  548. daddr = &ipv6_hdr(skb)->daddr;
  549. size = sizeof(struct icmp6hdr) + sizeof(struct in6_addr);
  550. spin_lock_irqsave(&npinfo->rx_lock, flags);
  551. list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
  552. if (!ipv6_addr_equal(daddr, &np->local_ip.in6))
  553. continue;
  554. hlen = LL_RESERVED_SPACE(np->dev);
  555. tlen = np->dev->needed_tailroom;
  556. send_skb = find_skb(np, size + hlen + tlen, hlen);
  557. if (!send_skb)
  558. continue;
  559. send_skb->protocol = htons(ETH_P_IPV6);
  560. send_skb->dev = skb->dev;
  561. skb_reset_network_header(send_skb);
  562. skb_put(send_skb, sizeof(struct ipv6hdr));
  563. hdr = ipv6_hdr(send_skb);
  564. *(__be32*)hdr = htonl(0x60000000);
  565. hdr->payload_len = htons(size);
  566. hdr->nexthdr = IPPROTO_ICMPV6;
  567. hdr->hop_limit = 255;
  568. hdr->saddr = *saddr;
  569. hdr->daddr = *daddr;
  570. send_skb->transport_header = send_skb->tail;
  571. skb_put(send_skb, size);
  572. icmp6h = (struct icmp6hdr *)skb_transport_header(skb);
  573. icmp6h->icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT;
  574. icmp6h->icmp6_router = 0;
  575. icmp6h->icmp6_solicited = 1;
  576. target = (struct in6_addr *)skb_transport_header(send_skb) + sizeof(struct icmp6hdr);
  577. *target = msg->target;
  578. icmp6h->icmp6_cksum = csum_ipv6_magic(saddr, daddr, size,
  579. IPPROTO_ICMPV6,
  580. csum_partial(icmp6h,
  581. size, 0));
  582. if (dev_hard_header(send_skb, skb->dev, ETH_P_IPV6,
  583. lladdr, np->dev->dev_addr,
  584. send_skb->len) < 0) {
  585. kfree_skb(send_skb);
  586. continue;
  587. }
  588. netpoll_send_skb(np, send_skb);
  589. /* If there are several rx_hooks for the same address,
  590. we're fine by sending a single reply */
  591. break;
  592. }
  593. spin_unlock_irqrestore(&npinfo->rx_lock, flags);
  594. #endif
  595. }
  596. }
  597. static bool pkt_is_ns(struct sk_buff *skb)
  598. {
  599. struct nd_msg *msg;
  600. struct ipv6hdr *hdr;
  601. if (skb->protocol != htons(ETH_P_ARP))
  602. return false;
  603. if (!pskb_may_pull(skb, sizeof(struct ipv6hdr) + sizeof(struct nd_msg)))
  604. return false;
  605. msg = (struct nd_msg *)skb_transport_header(skb);
  606. __skb_push(skb, skb->data - skb_transport_header(skb));
  607. hdr = ipv6_hdr(skb);
  608. if (hdr->nexthdr != IPPROTO_ICMPV6)
  609. return false;
  610. if (hdr->hop_limit != 255)
  611. return false;
  612. if (msg->icmph.icmp6_code != 0)
  613. return false;
  614. if (msg->icmph.icmp6_type != NDISC_NEIGHBOUR_SOLICITATION)
  615. return false;
  616. return true;
  617. }
  618. int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo)
  619. {
  620. int proto, len, ulen;
  621. int hits = 0;
  622. const struct iphdr *iph;
  623. struct udphdr *uh;
  624. struct netpoll *np, *tmp;
  625. if (list_empty(&npinfo->rx_np))
  626. goto out;
  627. if (skb->dev->type != ARPHRD_ETHER)
  628. goto out;
  629. /* check if netpoll clients need ARP */
  630. if (skb->protocol == htons(ETH_P_ARP) && atomic_read(&trapped)) {
  631. skb_queue_tail(&npinfo->neigh_tx, skb);
  632. return 1;
  633. } else if (pkt_is_ns(skb) && atomic_read(&trapped)) {
  634. skb_queue_tail(&npinfo->neigh_tx, skb);
  635. return 1;
  636. }
  637. if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
  638. skb = vlan_untag(skb);
  639. if (unlikely(!skb))
  640. goto out;
  641. }
  642. proto = ntohs(eth_hdr(skb)->h_proto);
  643. if (proto != ETH_P_IP && proto != ETH_P_IPV6)
  644. goto out;
  645. if (skb->pkt_type == PACKET_OTHERHOST)
  646. goto out;
  647. if (skb_shared(skb))
  648. goto out;
  649. if (proto == ETH_P_IP) {
  650. if (!pskb_may_pull(skb, sizeof(struct iphdr)))
  651. goto out;
  652. iph = (struct iphdr *)skb->data;
  653. if (iph->ihl < 5 || iph->version != 4)
  654. goto out;
  655. if (!pskb_may_pull(skb, iph->ihl*4))
  656. goto out;
  657. iph = (struct iphdr *)skb->data;
  658. if (ip_fast_csum((u8 *)iph, iph->ihl) != 0)
  659. goto out;
  660. len = ntohs(iph->tot_len);
  661. if (skb->len < len || len < iph->ihl*4)
  662. goto out;
  663. /*
  664. * Our transport medium may have padded the buffer out.
  665. * Now We trim to the true length of the frame.
  666. */
  667. if (pskb_trim_rcsum(skb, len))
  668. goto out;
  669. iph = (struct iphdr *)skb->data;
  670. if (iph->protocol != IPPROTO_UDP)
  671. goto out;
  672. len -= iph->ihl*4;
  673. uh = (struct udphdr *)(((char *)iph) + iph->ihl*4);
  674. ulen = ntohs(uh->len);
  675. if (ulen != len)
  676. goto out;
  677. if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr))
  678. goto out;
  679. list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
  680. if (np->local_ip.ip && np->local_ip.ip != iph->daddr)
  681. continue;
  682. if (np->remote_ip.ip && np->remote_ip.ip != iph->saddr)
  683. continue;
  684. if (np->local_port && np->local_port != ntohs(uh->dest))
  685. continue;
  686. np->rx_hook(np, ntohs(uh->source),
  687. (char *)(uh+1),
  688. ulen - sizeof(struct udphdr));
  689. hits++;
  690. }
  691. } else {
  692. #if IS_ENABLED(CONFIG_IPV6)
  693. const struct ipv6hdr *ip6h;
  694. if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
  695. goto out;
  696. ip6h = (struct ipv6hdr *)skb->data;
  697. if (ip6h->version != 6)
  698. goto out;
  699. len = ntohs(ip6h->payload_len);
  700. if (!len)
  701. goto out;
  702. if (len + sizeof(struct ipv6hdr) > skb->len)
  703. goto out;
  704. if (pskb_trim_rcsum(skb, len + sizeof(struct ipv6hdr)))
  705. goto out;
  706. ip6h = ipv6_hdr(skb);
  707. if (!pskb_may_pull(skb, sizeof(struct udphdr)))
  708. goto out;
  709. uh = udp_hdr(skb);
  710. ulen = ntohs(uh->len);
  711. if (ulen != skb->len)
  712. goto out;
  713. if (udp6_csum_init(skb, uh, IPPROTO_UDP))
  714. goto out;
  715. list_for_each_entry_safe(np, tmp, &npinfo->rx_np, rx) {
  716. if (!ipv6_addr_equal(&np->local_ip.in6, &ip6h->daddr))
  717. continue;
  718. if (!ipv6_addr_equal(&np->remote_ip.in6, &ip6h->saddr))
  719. continue;
  720. if (np->local_port && np->local_port != ntohs(uh->dest))
  721. continue;
  722. np->rx_hook(np, ntohs(uh->source),
  723. (char *)(uh+1),
  724. ulen - sizeof(struct udphdr));
  725. hits++;
  726. }
  727. #endif
  728. }
  729. if (!hits)
  730. goto out;
  731. kfree_skb(skb);
  732. return 1;
  733. out:
  734. if (atomic_read(&trapped)) {
  735. kfree_skb(skb);
  736. return 1;
  737. }
  738. return 0;
  739. }
  740. void netpoll_print_options(struct netpoll *np)
  741. {
  742. np_info(np, "local port %d\n", np->local_port);
  743. if (np->ipv6)
  744. np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.in6);
  745. else
  746. np_info(np, "local IPv4 address %pI4\n", &np->local_ip.ip);
  747. np_info(np, "interface '%s'\n", np->dev_name);
  748. np_info(np, "remote port %d\n", np->remote_port);
  749. if (np->ipv6)
  750. np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.in6);
  751. else
  752. np_info(np, "remote IPv4 address %pI4\n", &np->remote_ip.ip);
  753. np_info(np, "remote ethernet address %pM\n", np->remote_mac);
  754. }
  755. EXPORT_SYMBOL(netpoll_print_options);
  756. static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
  757. {
  758. const char *end;
  759. if (!strchr(str, ':') &&
  760. in4_pton(str, -1, (void *)addr, -1, &end) > 0) {
  761. if (!*end)
  762. return 0;
  763. }
  764. if (in6_pton(str, -1, addr->in6.s6_addr, -1, &end) > 0) {
  765. #if IS_ENABLED(CONFIG_IPV6)
  766. if (!*end)
  767. return 1;
  768. #else
  769. return -1;
  770. #endif
  771. }
  772. return -1;
  773. }
  774. int netpoll_parse_options(struct netpoll *np, char *opt)
  775. {
  776. char *cur=opt, *delim;
  777. int ipv6;
  778. if (*cur != '@') {
  779. if ((delim = strchr(cur, '@')) == NULL)
  780. goto parse_failed;
  781. *delim = 0;
  782. if (kstrtou16(cur, 10, &np->local_port))
  783. goto parse_failed;
  784. cur = delim;
  785. }
  786. cur++;
  787. if (*cur != '/') {
  788. if ((delim = strchr(cur, '/')) == NULL)
  789. goto parse_failed;
  790. *delim = 0;
  791. ipv6 = netpoll_parse_ip_addr(cur, &np->local_ip);
  792. if (ipv6 < 0)
  793. goto parse_failed;
  794. else
  795. np->ipv6 = (bool)ipv6;
  796. cur = delim;
  797. }
  798. cur++;
  799. if (*cur != ',') {
  800. /* parse out dev name */
  801. if ((delim = strchr(cur, ',')) == NULL)
  802. goto parse_failed;
  803. *delim = 0;
  804. strlcpy(np->dev_name, cur, sizeof(np->dev_name));
  805. cur = delim;
  806. }
  807. cur++;
  808. if (*cur != '@') {
  809. /* dst port */
  810. if ((delim = strchr(cur, '@')) == NULL)
  811. goto parse_failed;
  812. *delim = 0;
  813. if (*cur == ' ' || *cur == '\t')
  814. np_info(np, "warning: whitespace is not allowed\n");
  815. if (kstrtou16(cur, 10, &np->remote_port))
  816. goto parse_failed;
  817. cur = delim;
  818. }
  819. cur++;
  820. /* dst ip */
  821. if ((delim = strchr(cur, '/')) == NULL)
  822. goto parse_failed;
  823. *delim = 0;
  824. ipv6 = netpoll_parse_ip_addr(cur, &np->remote_ip);
  825. if (ipv6 < 0)
  826. goto parse_failed;
  827. else if (np->ipv6 != (bool)ipv6)
  828. goto parse_failed;
  829. else
  830. np->ipv6 = (bool)ipv6;
  831. cur = delim + 1;
  832. if (*cur != 0) {
  833. /* MAC address */
  834. if (!mac_pton(cur, np->remote_mac))
  835. goto parse_failed;
  836. }
  837. netpoll_print_options(np);
  838. return 0;
  839. parse_failed:
  840. np_info(np, "couldn't parse config at '%s'!\n", cur);
  841. return -1;
  842. }
  843. EXPORT_SYMBOL(netpoll_parse_options);
  844. int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp)
  845. {
  846. struct netpoll_info *npinfo;
  847. const struct net_device_ops *ops;
  848. unsigned long flags;
  849. int err;
  850. np->dev = ndev;
  851. strlcpy(np->dev_name, ndev->name, IFNAMSIZ);
  852. if ((ndev->priv_flags & IFF_DISABLE_NETPOLL) ||
  853. !ndev->netdev_ops->ndo_poll_controller) {
  854. np_err(np, "%s doesn't support polling, aborting\n",
  855. np->dev_name);
  856. err = -ENOTSUPP;
  857. goto out;
  858. }
  859. if (!ndev->npinfo) {
  860. npinfo = kmalloc(sizeof(*npinfo), gfp);
  861. if (!npinfo) {
  862. err = -ENOMEM;
  863. goto out;
  864. }
  865. npinfo->rx_flags = 0;
  866. INIT_LIST_HEAD(&npinfo->rx_np);
  867. spin_lock_init(&npinfo->rx_lock);
  868. mutex_init(&npinfo->dev_lock);
  869. skb_queue_head_init(&npinfo->neigh_tx);
  870. skb_queue_head_init(&npinfo->txq);
  871. INIT_DELAYED_WORK(&npinfo->tx_work, queue_process);
  872. atomic_set(&npinfo->refcnt, 1);
  873. ops = np->dev->netdev_ops;
  874. if (ops->ndo_netpoll_setup) {
  875. err = ops->ndo_netpoll_setup(ndev, npinfo, gfp);
  876. if (err)
  877. goto free_npinfo;
  878. }
  879. } else {
  880. npinfo = ndev->npinfo;
  881. atomic_inc(&npinfo->refcnt);
  882. }
  883. npinfo->netpoll = np;
  884. if (np->rx_hook) {
  885. spin_lock_irqsave(&npinfo->rx_lock, flags);
  886. npinfo->rx_flags |= NETPOLL_RX_ENABLED;
  887. list_add_tail(&np->rx, &npinfo->rx_np);
  888. spin_unlock_irqrestore(&npinfo->rx_lock, flags);
  889. }
  890. /* last thing to do is link it to the net device structure */
  891. rcu_assign_pointer(ndev->npinfo, npinfo);
  892. return 0;
  893. free_npinfo:
  894. kfree(npinfo);
  895. out:
  896. return err;
  897. }
  898. EXPORT_SYMBOL_GPL(__netpoll_setup);
  899. int netpoll_setup(struct netpoll *np)
  900. {
  901. struct net_device *ndev = NULL;
  902. struct in_device *in_dev;
  903. int err;
  904. rtnl_lock();
  905. if (np->dev_name) {
  906. struct net *net = current->nsproxy->net_ns;
  907. ndev = __dev_get_by_name(net, np->dev_name);
  908. }
  909. if (!ndev) {
  910. np_err(np, "%s doesn't exist, aborting\n", np->dev_name);
  911. err = -ENODEV;
  912. goto unlock;
  913. }
  914. dev_hold(ndev);
  915. if (netdev_master_upper_dev_get(ndev)) {
  916. np_err(np, "%s is a slave device, aborting\n", np->dev_name);
  917. err = -EBUSY;
  918. goto put;
  919. }
  920. if (!netif_running(ndev)) {
  921. unsigned long atmost, atleast;
  922. np_info(np, "device %s not up yet, forcing it\n", np->dev_name);
  923. err = dev_open(ndev);
  924. if (err) {
  925. np_err(np, "failed to open %s\n", ndev->name);
  926. goto put;
  927. }
  928. rtnl_unlock();
  929. atleast = jiffies + HZ/10;
  930. atmost = jiffies + carrier_timeout * HZ;
  931. while (!netif_carrier_ok(ndev)) {
  932. if (time_after(jiffies, atmost)) {
  933. np_notice(np, "timeout waiting for carrier\n");
  934. break;
  935. }
  936. msleep(1);
  937. }
  938. /* If carrier appears to come up instantly, we don't
  939. * trust it and pause so that we don't pump all our
  940. * queued console messages into the bitbucket.
  941. */
  942. if (time_before(jiffies, atleast)) {
  943. np_notice(np, "carrier detect appears untrustworthy, waiting 4 seconds\n");
  944. msleep(4000);
  945. }
  946. rtnl_lock();
  947. }
  948. if (!np->local_ip.ip) {
  949. if (!np->ipv6) {
  950. in_dev = __in_dev_get_rtnl(ndev);
  951. if (!in_dev || !in_dev->ifa_list) {
  952. np_err(np, "no IP address for %s, aborting\n",
  953. np->dev_name);
  954. err = -EDESTADDRREQ;
  955. goto put;
  956. }
  957. np->local_ip.ip = in_dev->ifa_list->ifa_local;
  958. np_info(np, "local IP %pI4\n", &np->local_ip.ip);
  959. } else {
  960. #if IS_ENABLED(CONFIG_IPV6)
  961. struct inet6_dev *idev;
  962. err = -EDESTADDRREQ;
  963. idev = __in6_dev_get(ndev);
  964. if (idev) {
  965. struct inet6_ifaddr *ifp;
  966. read_lock_bh(&idev->lock);
  967. list_for_each_entry(ifp, &idev->addr_list, if_list) {
  968. if (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)
  969. continue;
  970. np->local_ip.in6 = ifp->addr;
  971. err = 0;
  972. break;
  973. }
  974. read_unlock_bh(&idev->lock);
  975. }
  976. if (err) {
  977. np_err(np, "no IPv6 address for %s, aborting\n",
  978. np->dev_name);
  979. goto put;
  980. } else
  981. np_info(np, "local IPv6 %pI6c\n", &np->local_ip.in6);
  982. #else
  983. np_err(np, "IPv6 is not supported %s, aborting\n",
  984. np->dev_name);
  985. err = -EINVAL;
  986. goto put;
  987. #endif
  988. }
  989. }
  990. /* fill up the skb queue */
  991. refill_skbs();
  992. err = __netpoll_setup(np, ndev, GFP_KERNEL);
  993. if (err)
  994. goto put;
  995. rtnl_unlock();
  996. return 0;
  997. put:
  998. dev_put(ndev);
  999. unlock:
  1000. rtnl_unlock();
  1001. return err;
  1002. }
  1003. EXPORT_SYMBOL(netpoll_setup);
  1004. static int __init netpoll_init(void)
  1005. {
  1006. skb_queue_head_init(&skb_pool);
  1007. init_srcu_struct(&netpoll_srcu);
  1008. return 0;
  1009. }
  1010. core_initcall(netpoll_init);
  1011. static void rcu_cleanup_netpoll_info(struct rcu_head *rcu_head)
  1012. {
  1013. struct netpoll_info *npinfo =
  1014. container_of(rcu_head, struct netpoll_info, rcu);
  1015. skb_queue_purge(&npinfo->neigh_tx);
  1016. skb_queue_purge(&npinfo->txq);
  1017. /* we can't call cancel_delayed_work_sync here, as we are in softirq */
  1018. cancel_delayed_work(&npinfo->tx_work);
  1019. /* clean after last, unfinished work */
  1020. __skb_queue_purge(&npinfo->txq);
  1021. /* now cancel it again */
  1022. cancel_delayed_work(&npinfo->tx_work);
  1023. kfree(npinfo);
  1024. }
  1025. void __netpoll_cleanup(struct netpoll *np)
  1026. {
  1027. struct netpoll_info *npinfo;
  1028. unsigned long flags;
  1029. npinfo = np->dev->npinfo;
  1030. if (!npinfo)
  1031. return;
  1032. if (!list_empty(&npinfo->rx_np)) {
  1033. spin_lock_irqsave(&npinfo->rx_lock, flags);
  1034. list_del(&np->rx);
  1035. if (list_empty(&npinfo->rx_np))
  1036. npinfo->rx_flags &= ~NETPOLL_RX_ENABLED;
  1037. spin_unlock_irqrestore(&npinfo->rx_lock, flags);
  1038. }
  1039. synchronize_srcu(&netpoll_srcu);
  1040. if (atomic_dec_and_test(&npinfo->refcnt)) {
  1041. const struct net_device_ops *ops;
  1042. ops = np->dev->netdev_ops;
  1043. if (ops->ndo_netpoll_cleanup)
  1044. ops->ndo_netpoll_cleanup(np->dev);
  1045. RCU_INIT_POINTER(np->dev->npinfo, NULL);
  1046. call_rcu_bh(&npinfo->rcu, rcu_cleanup_netpoll_info);
  1047. }
  1048. }
  1049. EXPORT_SYMBOL_GPL(__netpoll_cleanup);
  1050. static void rcu_cleanup_netpoll(struct rcu_head *rcu_head)
  1051. {
  1052. struct netpoll *np = container_of(rcu_head, struct netpoll, rcu);
  1053. __netpoll_cleanup(np);
  1054. kfree(np);
  1055. }
  1056. void __netpoll_free_rcu(struct netpoll *np)
  1057. {
  1058. call_rcu_bh(&np->rcu, rcu_cleanup_netpoll);
  1059. }
  1060. EXPORT_SYMBOL_GPL(__netpoll_free_rcu);
  1061. void netpoll_cleanup(struct netpoll *np)
  1062. {
  1063. if (!np->dev)
  1064. return;
  1065. rtnl_lock();
  1066. __netpoll_cleanup(np);
  1067. rtnl_unlock();
  1068. dev_put(np->dev);
  1069. np->dev = NULL;
  1070. }
  1071. EXPORT_SYMBOL(netpoll_cleanup);
  1072. int netpoll_trap(void)
  1073. {
  1074. return atomic_read(&trapped);
  1075. }
  1076. EXPORT_SYMBOL(netpoll_trap);
  1077. void netpoll_set_trap(int trap)
  1078. {
  1079. if (trap)
  1080. atomic_inc(&trapped);
  1081. else
  1082. atomic_dec(&trapped);
  1083. }
  1084. EXPORT_SYMBOL(netpoll_set_trap);