~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/netconsole.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
242
242
}
243
243
 
244
244
/*
245
 
 * Wrapper over simple_strtol (base 10) with sanity and range checking.
246
 
 * We return (signed) long only because we may want to return errors.
247
 
 * Do not use this to convert numbers that are allowed to be negative.
248
 
 */
249
 
static long strtol10_check_range(const char *cp, long min, long max)
250
 
{
251
 
        long ret;
252
 
        char *p = (char *) cp;
253
 
 
254
 
        WARN_ON(min < 0);
255
 
        WARN_ON(max < min);
256
 
 
257
 
        ret = simple_strtol(p, &p, 10);
258
 
 
259
 
        if (*p && (*p != '\n')) {
260
 
                printk(KERN_ERR "netconsole: invalid input\n");
261
 
                return -EINVAL;
262
 
        }
263
 
        if ((ret < min) || (ret > max)) {
264
 
                printk(KERN_ERR "netconsole: input %ld must be between "
265
 
                                "%ld and %ld\n", ret, min, max);
266
 
                return -EINVAL;
267
 
        }
268
 
 
269
 
        return ret;
270
 
}
271
 
 
272
 
/*
273
245
 * Attribute operations for netconsole_target.
274
246
 */
275
247
 
327
299
                             const char *buf,
328
300
                             size_t count)
329
301
{
 
302
        int enabled;
330
303
        int err;
331
 
        long enabled;
332
304
 
333
 
        enabled = strtol10_check_range(buf, 0, 1);
334
 
        if (enabled < 0)
335
 
                return enabled;
 
305
        err = kstrtoint(buf, 10, &enabled);
 
306
        if (err < 0)
 
307
                return err;
 
308
        if (enabled < 0 || enabled > 1)
 
309
                return -EINVAL;
336
310
 
337
311
        if (enabled) {  /* 1 */
338
312
 
384
358
                                const char *buf,
385
359
                                size_t count)
386
360
{
387
 
        long local_port;
388
 
#define __U16_MAX       ((__u16) ~0U)
 
361
        int rv;
389
362
 
390
363
        if (nt->enabled) {
391
364
                printk(KERN_ERR "netconsole: target (%s) is enabled, "
394
367
                return -EINVAL;
395
368
        }
396
369
 
397
 
        local_port = strtol10_check_range(buf, 0, __U16_MAX);
398
 
        if (local_port < 0)
399
 
                return local_port;
400
 
 
401
 
        nt->np.local_port = local_port;
402
 
 
 
370
        rv = kstrtou16(buf, 10, &nt->np.local_port);
 
371
        if (rv < 0)
 
372
                return rv;
403
373
        return strnlen(buf, count);
404
374
}
405
375
 
407
377
                                 const char *buf,
408
378
                                 size_t count)
409
379
{
410
 
        long remote_port;
411
 
#define __U16_MAX       ((__u16) ~0U)
 
380
        int rv;
412
381
 
413
382
        if (nt->enabled) {
414
383
                printk(KERN_ERR "netconsole: target (%s) is enabled, "
417
386
                return -EINVAL;
418
387
        }
419
388
 
420
 
        remote_port = strtol10_check_range(buf, 0, __U16_MAX);
421
 
        if (remote_port < 0)
422
 
                return remote_port;
423
 
 
424
 
        nt->np.remote_port = remote_port;
425
 
 
 
389
        rv = kstrtou16(buf, 10, &nt->np.remote_port);
 
390
        if (rv < 0)
 
391
                return rv;
426
392
        return strnlen(buf, count);
427
393
}
428
394
 
463
429
                                size_t count)
464
430
{
465
431
        u8 remote_mac[ETH_ALEN];
466
 
        char *p = (char *) buf;
467
 
        int i;
468
432
 
469
433
        if (nt->enabled) {
470
434
                printk(KERN_ERR "netconsole: target (%s) is enabled, "
473
437
                return -EINVAL;
474
438
        }
475
439
 
476
 
        for (i = 0; i < ETH_ALEN - 1; i++) {
477
 
                remote_mac[i] = simple_strtoul(p, &p, 16);
478
 
                if (*p != ':')
479
 
                        goto invalid;
480
 
                p++;
481
 
        }
482
 
        remote_mac[ETH_ALEN - 1] = simple_strtoul(p, &p, 16);
483
 
        if (*p && (*p != '\n'))
484
 
                goto invalid;
485
 
 
 
440
        if (!mac_pton(buf, remote_mac))
 
441
                return -EINVAL;
 
442
        if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n')
 
443
                return -EINVAL;
486
444
        memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN);
487
445
 
488
446
        return strnlen(buf, count);
489
 
 
490
 
invalid:
491
 
        printk(KERN_ERR "netconsole: invalid input\n");
492
 
        return -EINVAL;
493
447
}
494
448
 
495
449
/*
667
621
        bool stopped = false;
668
622
 
669
623
        if (!(event == NETDEV_CHANGENAME || event == NETDEV_UNREGISTER ||
670
 
              event == NETDEV_BONDING_DESLAVE || event == NETDEV_GOING_DOWN))
 
624
              event == NETDEV_RELEASE || event == NETDEV_JOIN))
671
625
                goto done;
672
626
 
673
627
        spin_lock_irqsave(&target_list_lock, flags);
678
632
                        case NETDEV_CHANGENAME:
679
633
                                strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ);
680
634
                                break;
 
635
                        case NETDEV_RELEASE:
 
636
                        case NETDEV_JOIN:
681
637
                        case NETDEV_UNREGISTER:
682
638
                                /*
683
639
                                 * rtnl_lock already held
684
640
                                 */
685
641
                                if (nt->np.dev) {
 
642
                                        spin_unlock_irqrestore(
 
643
                                                              &target_list_lock,
 
644
                                                              flags);
686
645
                                        __netpoll_cleanup(&nt->np);
 
646
                                        spin_lock_irqsave(&target_list_lock,
 
647
                                                          flags);
687
648
                                        dev_put(nt->np.dev);
688
649
                                        nt->np.dev = NULL;
 
650
                                        netconsole_target_put(nt);
689
651
                                }
690
 
                                /* Fall through */
691
 
                        case NETDEV_GOING_DOWN:
692
 
                        case NETDEV_BONDING_DESLAVE:
693
652
                                nt->enabled = 0;
694
653
                                stopped = true;
695
654
                                break;
698
657
                netconsole_target_put(nt);
699
658
        }
700
659
        spin_unlock_irqrestore(&target_list_lock, flags);
701
 
        if (stopped && (event == NETDEV_UNREGISTER || event == NETDEV_BONDING_DESLAVE))
 
660
        if (stopped) {
702
661
                printk(KERN_INFO "netconsole: network logging stopped on "
703
 
                        "interface %s as it %s\n",  dev->name,
704
 
                        event == NETDEV_UNREGISTER ? "unregistered" : "released slaves");
 
662
                       "interface %s as it ", dev->name);
 
663
                switch (event) {
 
664
                case NETDEV_UNREGISTER:
 
665
                        printk(KERN_CONT "unregistered\n");
 
666
                        break;
 
667
                case NETDEV_RELEASE:
 
668
                        printk(KERN_CONT "released slaves\n");
 
669
                        break;
 
670
                case NETDEV_JOIN:
 
671
                        printk(KERN_CONT "is joining a master device\n");
 
672
                        break;
 
673
                }
 
674
        }
705
675
 
706
676
done:
707
677
        return NOTIFY_DONE;