netpoll.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. #include <linux/smp_lock.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <linux/string.h>
  15. #include <linux/inetdevice.h>
  16. #include <linux/inet.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/netpoll.h>
  19. #include <linux/sched.h>
  20. #include <linux/delay.h>
  21. #include <linux/rcupdate.h>
  22. #include <linux/workqueue.h>
  23. #include <net/tcp.h>
  24. #include <net/udp.h>
  25. #include <asm/unaligned.h>
  26. /*
  27. * We maintain a small pool of fully-sized skbs, to make sure the
  28. * message gets out even in extreme OOM situations.
  29. */
  30. #define MAX_UDP_CHUNK 1460
  31. #define MAX_SKBS 32
  32. #define MAX_QUEUE_DEPTH (MAX_SKBS / 2)
  33. static DEFINE_SPINLOCK(skb_list_lock);
  34. static int nr_skbs;
  35. static struct sk_buff *skbs;
  36. static DEFINE_SPINLOCK(queue_lock);
  37. static int queue_depth;
  38. static struct sk_buff *queue_head, *queue_tail;
  39. static atomic_t trapped;
  40. #define NETPOLL_RX_ENABLED 1
  41. #define NETPOLL_RX_DROP 2
  42. #define MAX_SKB_SIZE \
  43. (MAX_UDP_CHUNK + sizeof(struct udphdr) + \
  44. sizeof(struct iphdr) + sizeof(struct ethhdr))
  45. static void zap_completion_queue(void);
  46. static void queue_process(void *p)
  47. {
  48. unsigned long flags;
  49. struct sk_buff *skb;
  50. while (queue_head) {
  51. spin_lock_irqsave(&queue_lock, flags);
  52. skb = queue_head;
  53. queue_head = skb->next;
  54. if (skb == queue_tail)
  55. queue_head = NULL;
  56. queue_depth--;
  57. spin_unlock_irqrestore(&queue_lock, flags);
  58. dev_queue_xmit(skb);
  59. }
  60. }
  61. static DECLARE_WORK(send_queue, queue_process, NULL);
  62. void netpoll_queue(struct sk_buff *skb)
  63. {
  64. unsigned long flags;
  65. if (queue_depth == MAX_QUEUE_DEPTH) {
  66. __kfree_skb(skb);
  67. return;
  68. }
  69. spin_lock_irqsave(&queue_lock, flags);
  70. if (!queue_head)
  71. queue_head = skb;
  72. else
  73. queue_tail->next = skb;
  74. queue_tail = skb;
  75. queue_depth++;
  76. spin_unlock_irqrestore(&queue_lock, flags);
  77. schedule_work(&send_queue);
  78. }
  79. static int checksum_udp(struct sk_buff *skb, struct udphdr *uh,
  80. unsigned short ulen, u32 saddr, u32 daddr)
  81. {
  82. if (uh->check == 0)
  83. return 0;
  84. if (skb->ip_summed == CHECKSUM_HW)
  85. return csum_tcpudp_magic(
  86. saddr, daddr, ulen, IPPROTO_UDP, skb->csum);
  87. skb->csum = csum_tcpudp_nofold(saddr, daddr, ulen, IPPROTO_UDP, 0);
  88. return csum_fold(skb_checksum(skb, 0, skb->len, skb->csum));
  89. }
  90. /*
  91. * Check whether delayed processing was scheduled for our NIC. If so,
  92. * we attempt to grab the poll lock and use ->poll() to pump the card.
  93. * If this fails, either we've recursed in ->poll() or it's already
  94. * running on another CPU.
  95. *
  96. * Note: we don't mask interrupts with this lock because we're using
  97. * trylock here and interrupts are already disabled in the softirq
  98. * case. Further, we test the poll_owner to avoid recursion on UP
  99. * systems where the lock doesn't exist.
  100. *
  101. * In cases where there is bi-directional communications, reading only
  102. * one message at a time can lead to packets being dropped by the
  103. * network adapter, forcing superfluous retries and possibly timeouts.
  104. * Thus, we set our budget to greater than 1.
  105. */
  106. static void poll_napi(struct netpoll *np)
  107. {
  108. int budget = 16;
  109. if (test_bit(__LINK_STATE_RX_SCHED, &np->dev->state) &&
  110. np->poll_owner != smp_processor_id() &&
  111. spin_trylock(&np->poll_lock)) {
  112. np->rx_flags |= NETPOLL_RX_DROP;
  113. atomic_inc(&trapped);
  114. np->dev->poll(np->dev, &budget);
  115. atomic_dec(&trapped);
  116. np->rx_flags &= ~NETPOLL_RX_DROP;
  117. spin_unlock(&np->poll_lock);
  118. }
  119. }
  120. void netpoll_poll(struct netpoll *np)
  121. {
  122. if(!np->dev || !netif_running(np->dev) || !np->dev->poll_controller)
  123. return;
  124. /* Process pending work on NIC */
  125. np->dev->poll_controller(np->dev);
  126. if (np->dev->poll)
  127. poll_napi(np);
  128. zap_completion_queue();
  129. }
  130. static void refill_skbs(void)
  131. {
  132. struct sk_buff *skb;
  133. unsigned long flags;
  134. spin_lock_irqsave(&skb_list_lock, flags);
  135. while (nr_skbs < MAX_SKBS) {
  136. skb = alloc_skb(MAX_SKB_SIZE, GFP_ATOMIC);
  137. if (!skb)
  138. break;
  139. skb->next = skbs;
  140. skbs = skb;
  141. nr_skbs++;
  142. }
  143. spin_unlock_irqrestore(&skb_list_lock, flags);
  144. }
  145. static void zap_completion_queue(void)
  146. {
  147. unsigned long flags;
  148. struct softnet_data *sd = &get_cpu_var(softnet_data);
  149. if (sd->completion_queue) {
  150. struct sk_buff *clist;
  151. local_irq_save(flags);
  152. clist = sd->completion_queue;
  153. sd->completion_queue = NULL;
  154. local_irq_restore(flags);
  155. while (clist != NULL) {
  156. struct sk_buff *skb = clist;
  157. clist = clist->next;
  158. if(skb->destructor)
  159. dev_kfree_skb_any(skb); /* put this one back */
  160. else
  161. __kfree_skb(skb);
  162. }
  163. }
  164. put_cpu_var(softnet_data);
  165. }
  166. static struct sk_buff * find_skb(struct netpoll *np, int len, int reserve)
  167. {
  168. int once = 1, count = 0;
  169. unsigned long flags;
  170. struct sk_buff *skb = NULL;
  171. zap_completion_queue();
  172. repeat:
  173. if (nr_skbs < MAX_SKBS)
  174. refill_skbs();
  175. skb = alloc_skb(len, GFP_ATOMIC);
  176. if (!skb) {
  177. spin_lock_irqsave(&skb_list_lock, flags);
  178. skb = skbs;
  179. if (skb) {
  180. skbs = skb->next;
  181. skb->next = NULL;
  182. nr_skbs--;
  183. }
  184. spin_unlock_irqrestore(&skb_list_lock, flags);
  185. }
  186. if(!skb) {
  187. count++;
  188. if (once && (count == 1000000)) {
  189. printk("out of netpoll skbs!\n");
  190. once = 0;
  191. }
  192. netpoll_poll(np);
  193. goto repeat;
  194. }
  195. atomic_set(&skb->users, 1);
  196. skb_reserve(skb, reserve);
  197. return skb;
  198. }
  199. static void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
  200. {
  201. int status;
  202. repeat:
  203. if(!np || !np->dev || !netif_running(np->dev)) {
  204. __kfree_skb(skb);
  205. return;
  206. }
  207. /* avoid recursion */
  208. if(np->poll_owner == smp_processor_id() ||
  209. np->dev->xmit_lock_owner == smp_processor_id()) {
  210. if (np->drop)
  211. np->drop(skb);
  212. else
  213. __kfree_skb(skb);
  214. return;
  215. }
  216. spin_lock(&np->dev->xmit_lock);
  217. np->dev->xmit_lock_owner = smp_processor_id();
  218. /*
  219. * network drivers do not expect to be called if the queue is
  220. * stopped.
  221. */
  222. if (netif_queue_stopped(np->dev)) {
  223. np->dev->xmit_lock_owner = -1;
  224. spin_unlock(&np->dev->xmit_lock);
  225. netpoll_poll(np);
  226. goto repeat;
  227. }
  228. status = np->dev->hard_start_xmit(skb, np->dev);
  229. np->dev->xmit_lock_owner = -1;
  230. spin_unlock(&np->dev->xmit_lock);
  231. /* transmit busy */
  232. if(status) {
  233. netpoll_poll(np);
  234. goto repeat;
  235. }
  236. }
  237. void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
  238. {
  239. int total_len, eth_len, ip_len, udp_len;
  240. struct sk_buff *skb;
  241. struct udphdr *udph;
  242. struct iphdr *iph;
  243. struct ethhdr *eth;
  244. udp_len = len + sizeof(*udph);
  245. ip_len = eth_len = udp_len + sizeof(*iph);
  246. total_len = eth_len + ETH_HLEN + NET_IP_ALIGN;
  247. skb = find_skb(np, total_len, total_len - len);
  248. if (!skb)
  249. return;
  250. memcpy(skb->data, msg, len);
  251. skb->len += len;
  252. udph = (struct udphdr *) skb_push(skb, sizeof(*udph));
  253. udph->source = htons(np->local_port);
  254. udph->dest = htons(np->remote_port);
  255. udph->len = htons(udp_len);
  256. udph->check = 0;
  257. iph = (struct iphdr *)skb_push(skb, sizeof(*iph));
  258. /* iph->version = 4; iph->ihl = 5; */
  259. put_unaligned(0x45, (unsigned char *)iph);
  260. iph->tos = 0;
  261. put_unaligned(htons(ip_len), &(iph->tot_len));
  262. iph->id = 0;
  263. iph->frag_off = 0;
  264. iph->ttl = 64;
  265. iph->protocol = IPPROTO_UDP;
  266. iph->check = 0;
  267. put_unaligned(htonl(np->local_ip), &(iph->saddr));
  268. put_unaligned(htonl(np->remote_ip), &(iph->daddr));
  269. iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
  270. eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);
  271. eth->h_proto = htons(ETH_P_IP);
  272. memcpy(eth->h_source, np->local_mac, 6);
  273. memcpy(eth->h_dest, np->remote_mac, 6);
  274. skb->dev = np->dev;
  275. netpoll_send_skb(np, skb);
  276. }
  277. static void arp_reply(struct sk_buff *skb)
  278. {
  279. struct arphdr *arp;
  280. unsigned char *arp_ptr;
  281. int size, type = ARPOP_REPLY, ptype = ETH_P_ARP;
  282. u32 sip, tip;
  283. struct sk_buff *send_skb;
  284. struct netpoll *np = skb->dev->np;
  285. if (!np) return;
  286. /* No arp on this interface */
  287. if (skb->dev->flags & IFF_NOARP)
  288. return;
  289. if (!pskb_may_pull(skb, (sizeof(struct arphdr) +
  290. (2 * skb->dev->addr_len) +
  291. (2 * sizeof(u32)))))
  292. return;
  293. skb->h.raw = skb->nh.raw = skb->data;
  294. arp = skb->nh.arph;
  295. if ((arp->ar_hrd != htons(ARPHRD_ETHER) &&
  296. arp->ar_hrd != htons(ARPHRD_IEEE802)) ||
  297. arp->ar_pro != htons(ETH_P_IP) ||
  298. arp->ar_op != htons(ARPOP_REQUEST))
  299. return;
  300. arp_ptr = (unsigned char *)(arp+1) + skb->dev->addr_len;
  301. memcpy(&sip, arp_ptr, 4);
  302. arp_ptr += 4 + skb->dev->addr_len;
  303. memcpy(&tip, arp_ptr, 4);
  304. /* Should we ignore arp? */
  305. if (tip != htonl(np->local_ip) || LOOPBACK(tip) || MULTICAST(tip))
  306. return;
  307. size = sizeof(struct arphdr) + 2 * (skb->dev->addr_len + 4);
  308. send_skb = find_skb(np, size + LL_RESERVED_SPACE(np->dev),
  309. LL_RESERVED_SPACE(np->dev));
  310. if (!send_skb)
  311. return;
  312. send_skb->nh.raw = send_skb->data;
  313. arp = (struct arphdr *) skb_put(send_skb, size);
  314. send_skb->dev = skb->dev;
  315. send_skb->protocol = htons(ETH_P_ARP);
  316. /* Fill the device header for the ARP frame */
  317. if (np->dev->hard_header &&
  318. np->dev->hard_header(send_skb, skb->dev, ptype,
  319. np->remote_mac, np->local_mac,
  320. send_skb->len) < 0) {
  321. kfree_skb(send_skb);
  322. return;
  323. }
  324. /*
  325. * Fill out the arp protocol part.
  326. *
  327. * we only support ethernet device type,
  328. * which (according to RFC 1390) should always equal 1 (Ethernet).
  329. */
  330. arp->ar_hrd = htons(np->dev->type);
  331. arp->ar_pro = htons(ETH_P_IP);
  332. arp->ar_hln = np->dev->addr_len;
  333. arp->ar_pln = 4;
  334. arp->ar_op = htons(type);
  335. arp_ptr=(unsigned char *)(arp + 1);
  336. memcpy(arp_ptr, np->dev->dev_addr, np->dev->addr_len);
  337. arp_ptr += np->dev->addr_len;
  338. memcpy(arp_ptr, &tip, 4);
  339. arp_ptr += 4;
  340. memcpy(arp_ptr, np->remote_mac, np->dev->addr_len);
  341. arp_ptr += np->dev->addr_len;
  342. memcpy(arp_ptr, &sip, 4);
  343. netpoll_send_skb(np, send_skb);
  344. }
  345. int __netpoll_rx(struct sk_buff *skb)
  346. {
  347. int proto, len, ulen;
  348. struct iphdr *iph;
  349. struct udphdr *uh;
  350. struct netpoll *np = skb->dev->np;
  351. if (!np->rx_hook)
  352. goto out;
  353. if (skb->dev->type != ARPHRD_ETHER)
  354. goto out;
  355. /* check if netpoll clients need ARP */
  356. if (skb->protocol == __constant_htons(ETH_P_ARP) &&
  357. atomic_read(&trapped)) {
  358. arp_reply(skb);
  359. return 1;
  360. }
  361. proto = ntohs(eth_hdr(skb)->h_proto);
  362. if (proto != ETH_P_IP)
  363. goto out;
  364. if (skb->pkt_type == PACKET_OTHERHOST)
  365. goto out;
  366. if (skb_shared(skb))
  367. goto out;
  368. iph = (struct iphdr *)skb->data;
  369. if (!pskb_may_pull(skb, sizeof(struct iphdr)))
  370. goto out;
  371. if (iph->ihl < 5 || iph->version != 4)
  372. goto out;
  373. if (!pskb_may_pull(skb, iph->ihl*4))
  374. goto out;
  375. if (ip_fast_csum((u8 *)iph, iph->ihl) != 0)
  376. goto out;
  377. len = ntohs(iph->tot_len);
  378. if (skb->len < len || len < iph->ihl*4)
  379. goto out;
  380. if (iph->protocol != IPPROTO_UDP)
  381. goto out;
  382. len -= iph->ihl*4;
  383. uh = (struct udphdr *)(((char *)iph) + iph->ihl*4);
  384. ulen = ntohs(uh->len);
  385. if (ulen != len)
  386. goto out;
  387. if (checksum_udp(skb, uh, ulen, iph->saddr, iph->daddr) < 0)
  388. goto out;
  389. if (np->local_ip && np->local_ip != ntohl(iph->daddr))
  390. goto out;
  391. if (np->remote_ip && np->remote_ip != ntohl(iph->saddr))
  392. goto out;
  393. if (np->local_port && np->local_port != ntohs(uh->dest))
  394. goto out;
  395. np->rx_hook(np, ntohs(uh->source),
  396. (char *)(uh+1),
  397. ulen - sizeof(struct udphdr));
  398. kfree_skb(skb);
  399. return 1;
  400. out:
  401. if (atomic_read(&trapped)) {
  402. kfree_skb(skb);
  403. return 1;
  404. }
  405. return 0;
  406. }
  407. int netpoll_parse_options(struct netpoll *np, char *opt)
  408. {
  409. char *cur=opt, *delim;
  410. if(*cur != '@') {
  411. if ((delim = strchr(cur, '@')) == NULL)
  412. goto parse_failed;
  413. *delim=0;
  414. np->local_port=simple_strtol(cur, NULL, 10);
  415. cur=delim;
  416. }
  417. cur++;
  418. printk(KERN_INFO "%s: local port %d\n", np->name, np->local_port);
  419. if(*cur != '/') {
  420. if ((delim = strchr(cur, '/')) == NULL)
  421. goto parse_failed;
  422. *delim=0;
  423. np->local_ip=ntohl(in_aton(cur));
  424. cur=delim;
  425. printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n",
  426. np->name, HIPQUAD(np->local_ip));
  427. }
  428. cur++;
  429. if ( *cur != ',') {
  430. /* parse out dev name */
  431. if ((delim = strchr(cur, ',')) == NULL)
  432. goto parse_failed;
  433. *delim=0;
  434. strlcpy(np->dev_name, cur, sizeof(np->dev_name));
  435. cur=delim;
  436. }
  437. cur++;
  438. printk(KERN_INFO "%s: interface %s\n", np->name, np->dev_name);
  439. if ( *cur != '@' ) {
  440. /* dst port */
  441. if ((delim = strchr(cur, '@')) == NULL)
  442. goto parse_failed;
  443. *delim=0;
  444. np->remote_port=simple_strtol(cur, NULL, 10);
  445. cur=delim;
  446. }
  447. cur++;
  448. printk(KERN_INFO "%s: remote port %d\n", np->name, np->remote_port);
  449. /* dst ip */
  450. if ((delim = strchr(cur, '/')) == NULL)
  451. goto parse_failed;
  452. *delim=0;
  453. np->remote_ip=ntohl(in_aton(cur));
  454. cur=delim+1;
  455. printk(KERN_INFO "%s: remote IP %d.%d.%d.%d\n",
  456. np->name, HIPQUAD(np->remote_ip));
  457. if( *cur != 0 )
  458. {
  459. /* MAC address */
  460. if ((delim = strchr(cur, ':')) == NULL)
  461. goto parse_failed;
  462. *delim=0;
  463. np->remote_mac[0]=simple_strtol(cur, NULL, 16);
  464. cur=delim+1;
  465. if ((delim = strchr(cur, ':')) == NULL)
  466. goto parse_failed;
  467. *delim=0;
  468. np->remote_mac[1]=simple_strtol(cur, NULL, 16);
  469. cur=delim+1;
  470. if ((delim = strchr(cur, ':')) == NULL)
  471. goto parse_failed;
  472. *delim=0;
  473. np->remote_mac[2]=simple_strtol(cur, NULL, 16);
  474. cur=delim+1;
  475. if ((delim = strchr(cur, ':')) == NULL)
  476. goto parse_failed;
  477. *delim=0;
  478. np->remote_mac[3]=simple_strtol(cur, NULL, 16);
  479. cur=delim+1;
  480. if ((delim = strchr(cur, ':')) == NULL)
  481. goto parse_failed;
  482. *delim=0;
  483. np->remote_mac[4]=simple_strtol(cur, NULL, 16);
  484. cur=delim+1;
  485. np->remote_mac[5]=simple_strtol(cur, NULL, 16);
  486. }
  487. printk(KERN_INFO "%s: remote ethernet address "
  488. "%02x:%02x:%02x:%02x:%02x:%02x\n",
  489. np->name,
  490. np->remote_mac[0],
  491. np->remote_mac[1],
  492. np->remote_mac[2],
  493. np->remote_mac[3],
  494. np->remote_mac[4],
  495. np->remote_mac[5]);
  496. return 0;
  497. parse_failed:
  498. printk(KERN_INFO "%s: couldn't parse config at %s!\n",
  499. np->name, cur);
  500. return -1;
  501. }
  502. int netpoll_setup(struct netpoll *np)
  503. {
  504. struct net_device *ndev = NULL;
  505. struct in_device *in_dev;
  506. np->poll_lock = SPIN_LOCK_UNLOCKED;
  507. np->poll_owner = -1;
  508. if (np->dev_name)
  509. ndev = dev_get_by_name(np->dev_name);
  510. if (!ndev) {
  511. printk(KERN_ERR "%s: %s doesn't exist, aborting.\n",
  512. np->name, np->dev_name);
  513. return -1;
  514. }
  515. np->dev = ndev;
  516. ndev->np = np;
  517. if (!ndev->poll_controller) {
  518. printk(KERN_ERR "%s: %s doesn't support polling, aborting.\n",
  519. np->name, np->dev_name);
  520. goto release;
  521. }
  522. if (!netif_running(ndev)) {
  523. unsigned long atmost, atleast;
  524. printk(KERN_INFO "%s: device %s not up yet, forcing it\n",
  525. np->name, np->dev_name);
  526. rtnl_shlock();
  527. if (dev_change_flags(ndev, ndev->flags | IFF_UP) < 0) {
  528. printk(KERN_ERR "%s: failed to open %s\n",
  529. np->name, np->dev_name);
  530. rtnl_shunlock();
  531. goto release;
  532. }
  533. rtnl_shunlock();
  534. atleast = jiffies + HZ/10;
  535. atmost = jiffies + 4*HZ;
  536. while (!netif_carrier_ok(ndev)) {
  537. if (time_after(jiffies, atmost)) {
  538. printk(KERN_NOTICE
  539. "%s: timeout waiting for carrier\n",
  540. np->name);
  541. break;
  542. }
  543. cond_resched();
  544. }
  545. /* If carrier appears to come up instantly, we don't
  546. * trust it and pause so that we don't pump all our
  547. * queued console messages into the bitbucket.
  548. */
  549. if (time_before(jiffies, atleast)) {
  550. printk(KERN_NOTICE "%s: carrier detect appears"
  551. " untrustworthy, waiting 4 seconds\n",
  552. np->name);
  553. msleep(4000);
  554. }
  555. }
  556. if (!memcmp(np->local_mac, "\0\0\0\0\0\0", 6) && ndev->dev_addr)
  557. memcpy(np->local_mac, ndev->dev_addr, 6);
  558. if (!np->local_ip) {
  559. rcu_read_lock();
  560. in_dev = __in_dev_get(ndev);
  561. if (!in_dev || !in_dev->ifa_list) {
  562. rcu_read_unlock();
  563. printk(KERN_ERR "%s: no IP address for %s, aborting\n",
  564. np->name, np->dev_name);
  565. goto release;
  566. }
  567. np->local_ip = ntohl(in_dev->ifa_list->ifa_local);
  568. rcu_read_unlock();
  569. printk(KERN_INFO "%s: local IP %d.%d.%d.%d\n",
  570. np->name, HIPQUAD(np->local_ip));
  571. }
  572. if(np->rx_hook)
  573. np->rx_flags = NETPOLL_RX_ENABLED;
  574. return 0;
  575. release:
  576. ndev->np = NULL;
  577. np->dev = NULL;
  578. dev_put(ndev);
  579. return -1;
  580. }
  581. void netpoll_cleanup(struct netpoll *np)
  582. {
  583. if (np->dev)
  584. np->dev->np = NULL;
  585. dev_put(np->dev);
  586. np->dev = NULL;
  587. }
  588. int netpoll_trap(void)
  589. {
  590. return atomic_read(&trapped);
  591. }
  592. void netpoll_set_trap(int trap)
  593. {
  594. if (trap)
  595. atomic_inc(&trapped);
  596. else
  597. atomic_dec(&trapped);
  598. }
  599. EXPORT_SYMBOL(netpoll_set_trap);
  600. EXPORT_SYMBOL(netpoll_trap);
  601. EXPORT_SYMBOL(netpoll_parse_options);
  602. EXPORT_SYMBOL(netpoll_setup);
  603. EXPORT_SYMBOL(netpoll_cleanup);
  604. EXPORT_SYMBOL(netpoll_send_udp);
  605. EXPORT_SYMBOL(netpoll_poll);
  606. EXPORT_SYMBOL(netpoll_queue);