diff options
author | Christoph Hellwig <hch@lst.de> | 2018-04-10 15:31:50 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-05-16 01:23:35 -0400 |
commit | a3d2599b24462c762719a70bc4d2ec8e8cb52fcf (patch) | |
tree | a3b5ae4182589c9ee914d4298366377112cb260b | |
parent | 3f3942aca6da351a12543aa776467791b63b3a78 (diff) |
ipv{4,6}/udp{,lite}: simplify proc registration
Remove a couple indirections to make the code look like most other
protocols.
Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | include/net/udp.h | 20 | ||||
-rw-r--r-- | net/ipv4/udp.c | 99 | ||||
-rw-r--r-- | net/ipv4/udplite.c | 21 | ||||
-rw-r--r-- | net/ipv6/udp.c | 30 | ||||
-rw-r--r-- | net/ipv6/udplite.c | 21 |
5 files changed, 78 insertions, 113 deletions
diff --git a/include/net/udp.h b/include/net/udp.h index 0676b272f6ac..093cd323f66a 100644 --- a/include/net/udp.h +++ b/include/net/udp.h | |||
@@ -408,31 +408,27 @@ do { \ | |||
408 | #define __UDPX_INC_STATS(sk, field) __UDP_INC_STATS(sock_net(sk), field, 0) | 408 | #define __UDPX_INC_STATS(sk, field) __UDP_INC_STATS(sock_net(sk), field, 0) |
409 | #endif | 409 | #endif |
410 | 410 | ||
411 | /* /proc */ | 411 | #ifdef CONFIG_PROC_FS |
412 | int udp_seq_open(struct inode *inode, struct file *file); | ||
413 | |||
414 | struct udp_seq_afinfo { | 412 | struct udp_seq_afinfo { |
415 | char *name; | ||
416 | sa_family_t family; | 413 | sa_family_t family; |
417 | struct udp_table *udp_table; | 414 | struct udp_table *udp_table; |
418 | const struct file_operations *seq_fops; | ||
419 | struct seq_operations seq_ops; | ||
420 | }; | 415 | }; |
421 | 416 | ||
422 | struct udp_iter_state { | 417 | struct udp_iter_state { |
423 | struct seq_net_private p; | 418 | struct seq_net_private p; |
424 | sa_family_t family; | ||
425 | int bucket; | 419 | int bucket; |
426 | struct udp_table *udp_table; | ||
427 | }; | 420 | }; |
428 | 421 | ||
429 | #ifdef CONFIG_PROC_FS | 422 | void *udp_seq_start(struct seq_file *seq, loff_t *pos); |
430 | int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo); | 423 | void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos); |
431 | void udp_proc_unregister(struct net *net, struct udp_seq_afinfo *afinfo); | 424 | void udp_seq_stop(struct seq_file *seq, void *v); |
425 | |||
426 | extern const struct file_operations udp_afinfo_seq_fops; | ||
427 | extern const struct file_operations udp6_afinfo_seq_fops; | ||
432 | 428 | ||
433 | int udp4_proc_init(void); | 429 | int udp4_proc_init(void); |
434 | void udp4_proc_exit(void); | 430 | void udp4_proc_exit(void); |
435 | #endif | 431 | #endif /* CONFIG_PROC_FS */ |
436 | 432 | ||
437 | int udpv4_offload_init(void); | 433 | int udpv4_offload_init(void); |
438 | 434 | ||
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index b61a770884fa..51559a8c6e57 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -2582,12 +2582,13 @@ EXPORT_SYMBOL(udp_prot); | |||
2582 | static struct sock *udp_get_first(struct seq_file *seq, int start) | 2582 | static struct sock *udp_get_first(struct seq_file *seq, int start) |
2583 | { | 2583 | { |
2584 | struct sock *sk; | 2584 | struct sock *sk; |
2585 | struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file)); | ||
2585 | struct udp_iter_state *state = seq->private; | 2586 | struct udp_iter_state *state = seq->private; |
2586 | struct net *net = seq_file_net(seq); | 2587 | struct net *net = seq_file_net(seq); |
2587 | 2588 | ||
2588 | for (state->bucket = start; state->bucket <= state->udp_table->mask; | 2589 | for (state->bucket = start; state->bucket <= afinfo->udp_table->mask; |
2589 | ++state->bucket) { | 2590 | ++state->bucket) { |
2590 | struct udp_hslot *hslot = &state->udp_table->hash[state->bucket]; | 2591 | struct udp_hslot *hslot = &afinfo->udp_table->hash[state->bucket]; |
2591 | 2592 | ||
2592 | if (hlist_empty(&hslot->head)) | 2593 | if (hlist_empty(&hslot->head)) |
2593 | continue; | 2594 | continue; |
@@ -2596,7 +2597,7 @@ static struct sock *udp_get_first(struct seq_file *seq, int start) | |||
2596 | sk_for_each(sk, &hslot->head) { | 2597 | sk_for_each(sk, &hslot->head) { |
2597 | if (!net_eq(sock_net(sk), net)) | 2598 | if (!net_eq(sock_net(sk), net)) |
2598 | continue; | 2599 | continue; |
2599 | if (sk->sk_family == state->family) | 2600 | if (sk->sk_family == afinfo->family) |
2600 | goto found; | 2601 | goto found; |
2601 | } | 2602 | } |
2602 | spin_unlock_bh(&hslot->lock); | 2603 | spin_unlock_bh(&hslot->lock); |
@@ -2608,16 +2609,17 @@ found: | |||
2608 | 2609 | ||
2609 | static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk) | 2610 | static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk) |
2610 | { | 2611 | { |
2612 | struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file)); | ||
2611 | struct udp_iter_state *state = seq->private; | 2613 | struct udp_iter_state *state = seq->private; |
2612 | struct net *net = seq_file_net(seq); | 2614 | struct net *net = seq_file_net(seq); |
2613 | 2615 | ||
2614 | do { | 2616 | do { |
2615 | sk = sk_next(sk); | 2617 | sk = sk_next(sk); |
2616 | } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family)); | 2618 | } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != afinfo->family)); |
2617 | 2619 | ||
2618 | if (!sk) { | 2620 | if (!sk) { |
2619 | if (state->bucket <= state->udp_table->mask) | 2621 | if (state->bucket <= afinfo->udp_table->mask) |
2620 | spin_unlock_bh(&state->udp_table->hash[state->bucket].lock); | 2622 | spin_unlock_bh(&afinfo->udp_table->hash[state->bucket].lock); |
2621 | return udp_get_first(seq, state->bucket + 1); | 2623 | return udp_get_first(seq, state->bucket + 1); |
2622 | } | 2624 | } |
2623 | return sk; | 2625 | return sk; |
@@ -2633,15 +2635,16 @@ static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos) | |||
2633 | return pos ? NULL : sk; | 2635 | return pos ? NULL : sk; |
2634 | } | 2636 | } |
2635 | 2637 | ||
2636 | static void *udp_seq_start(struct seq_file *seq, loff_t *pos) | 2638 | void *udp_seq_start(struct seq_file *seq, loff_t *pos) |
2637 | { | 2639 | { |
2638 | struct udp_iter_state *state = seq->private; | 2640 | struct udp_iter_state *state = seq->private; |
2639 | state->bucket = MAX_UDP_PORTS; | 2641 | state->bucket = MAX_UDP_PORTS; |
2640 | 2642 | ||
2641 | return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN; | 2643 | return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN; |
2642 | } | 2644 | } |
2645 | EXPORT_SYMBOL(udp_seq_start); | ||
2643 | 2646 | ||
2644 | static void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 2647 | void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
2645 | { | 2648 | { |
2646 | struct sock *sk; | 2649 | struct sock *sk; |
2647 | 2650 | ||
@@ -2653,56 +2656,17 @@ static void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |||
2653 | ++*pos; | 2656 | ++*pos; |
2654 | return sk; | 2657 | return sk; |
2655 | } | 2658 | } |
2659 | EXPORT_SYMBOL(udp_seq_next); | ||
2656 | 2660 | ||
2657 | static void udp_seq_stop(struct seq_file *seq, void *v) | 2661 | void udp_seq_stop(struct seq_file *seq, void *v) |
2658 | { | 2662 | { |
2663 | struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file)); | ||
2659 | struct udp_iter_state *state = seq->private; | 2664 | struct udp_iter_state *state = seq->private; |
2660 | 2665 | ||
2661 | if (state->bucket <= state->udp_table->mask) | 2666 | if (state->bucket <= afinfo->udp_table->mask) |
2662 | spin_unlock_bh(&state->udp_table->hash[state->bucket].lock); | 2667 | spin_unlock_bh(&afinfo->udp_table->hash[state->bucket].lock); |
2663 | } | 2668 | } |
2664 | 2669 | EXPORT_SYMBOL(udp_seq_stop); | |
2665 | int udp_seq_open(struct inode *inode, struct file *file) | ||
2666 | { | ||
2667 | struct udp_seq_afinfo *afinfo = PDE_DATA(inode); | ||
2668 | struct udp_iter_state *s; | ||
2669 | int err; | ||
2670 | |||
2671 | err = seq_open_net(inode, file, &afinfo->seq_ops, | ||
2672 | sizeof(struct udp_iter_state)); | ||
2673 | if (err < 0) | ||
2674 | return err; | ||
2675 | |||
2676 | s = ((struct seq_file *)file->private_data)->private; | ||
2677 | s->family = afinfo->family; | ||
2678 | s->udp_table = afinfo->udp_table; | ||
2679 | return err; | ||
2680 | } | ||
2681 | EXPORT_SYMBOL(udp_seq_open); | ||
2682 | |||
2683 | /* ------------------------------------------------------------------------ */ | ||
2684 | int udp_proc_register(struct net *net, struct udp_seq_afinfo *afinfo) | ||
2685 | { | ||
2686 | struct proc_dir_entry *p; | ||
2687 | int rc = 0; | ||
2688 | |||
2689 | afinfo->seq_ops.start = udp_seq_start; | ||
2690 | afinfo->seq_ops.next = udp_seq_next; | ||
2691 | afinfo->seq_ops.stop = udp_seq_stop; | ||
2692 | |||
2693 | p = proc_create_data(afinfo->name, 0444, net->proc_net, | ||
2694 | afinfo->seq_fops, afinfo); | ||
2695 | if (!p) | ||
2696 | rc = -ENOMEM; | ||
2697 | return rc; | ||
2698 | } | ||
2699 | EXPORT_SYMBOL(udp_proc_register); | ||
2700 | |||
2701 | void udp_proc_unregister(struct net *net, struct udp_seq_afinfo *afinfo) | ||
2702 | { | ||
2703 | remove_proc_entry(afinfo->name, net->proc_net); | ||
2704 | } | ||
2705 | EXPORT_SYMBOL(udp_proc_unregister); | ||
2706 | 2670 | ||
2707 | /* ------------------------------------------------------------------------ */ | 2671 | /* ------------------------------------------------------------------------ */ |
2708 | static void udp4_format_sock(struct sock *sp, struct seq_file *f, | 2672 | static void udp4_format_sock(struct sock *sp, struct seq_file *f, |
@@ -2742,32 +2706,43 @@ int udp4_seq_show(struct seq_file *seq, void *v) | |||
2742 | return 0; | 2706 | return 0; |
2743 | } | 2707 | } |
2744 | 2708 | ||
2745 | static const struct file_operations udp_afinfo_seq_fops = { | 2709 | static const struct seq_operations udp_seq_ops = { |
2710 | .start = udp_seq_start, | ||
2711 | .next = udp_seq_next, | ||
2712 | .stop = udp_seq_stop, | ||
2713 | .show = udp4_seq_show, | ||
2714 | }; | ||
2715 | |||
2716 | static int udp_seq_open(struct inode *inode, struct file *file) | ||
2717 | { | ||
2718 | return seq_open_net(inode, file, &udp_seq_ops, | ||
2719 | sizeof(struct udp_iter_state)); | ||
2720 | } | ||
2721 | |||
2722 | const struct file_operations udp_afinfo_seq_fops = { | ||
2746 | .open = udp_seq_open, | 2723 | .open = udp_seq_open, |
2747 | .read = seq_read, | 2724 | .read = seq_read, |
2748 | .llseek = seq_lseek, | 2725 | .llseek = seq_lseek, |
2749 | .release = seq_release_net | 2726 | .release = seq_release_net |
2750 | }; | 2727 | }; |
2728 | EXPORT_SYMBOL(udp_afinfo_seq_fops); | ||
2751 | 2729 | ||
2752 | /* ------------------------------------------------------------------------ */ | ||
2753 | static struct udp_seq_afinfo udp4_seq_afinfo = { | 2730 | static struct udp_seq_afinfo udp4_seq_afinfo = { |
2754 | .name = "udp", | ||
2755 | .family = AF_INET, | 2731 | .family = AF_INET, |
2756 | .udp_table = &udp_table, | 2732 | .udp_table = &udp_table, |
2757 | .seq_fops = &udp_afinfo_seq_fops, | ||
2758 | .seq_ops = { | ||
2759 | .show = udp4_seq_show, | ||
2760 | }, | ||
2761 | }; | 2733 | }; |
2762 | 2734 | ||
2763 | static int __net_init udp4_proc_init_net(struct net *net) | 2735 | static int __net_init udp4_proc_init_net(struct net *net) |
2764 | { | 2736 | { |
2765 | return udp_proc_register(net, &udp4_seq_afinfo); | 2737 | if (!proc_create_data("udp", 0444, net->proc_net, &udp_afinfo_seq_fops, |
2738 | &udp4_seq_afinfo)) | ||
2739 | return -ENOMEM; | ||
2740 | return 0; | ||
2766 | } | 2741 | } |
2767 | 2742 | ||
2768 | static void __net_exit udp4_proc_exit_net(struct net *net) | 2743 | static void __net_exit udp4_proc_exit_net(struct net *net) |
2769 | { | 2744 | { |
2770 | udp_proc_unregister(net, &udp4_seq_afinfo); | 2745 | remove_proc_entry("udp", net->proc_net); |
2771 | } | 2746 | } |
2772 | 2747 | ||
2773 | static struct pernet_operations udp4_net_ops = { | 2748 | static struct pernet_operations udp4_net_ops = { |
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c index f96614e9b9a5..4a6e67bfbe0d 100644 --- a/net/ipv4/udplite.c +++ b/net/ipv4/udplite.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #define pr_fmt(fmt) "UDPLite: " fmt | 14 | #define pr_fmt(fmt) "UDPLite: " fmt |
15 | 15 | ||
16 | #include <linux/export.h> | 16 | #include <linux/export.h> |
17 | #include <linux/proc_fs.h> | ||
17 | #include "udp_impl.h" | 18 | #include "udp_impl.h" |
18 | 19 | ||
19 | struct udp_table udplite_table __read_mostly; | 20 | struct udp_table udplite_table __read_mostly; |
@@ -73,32 +74,22 @@ static struct inet_protosw udplite4_protosw = { | |||
73 | }; | 74 | }; |
74 | 75 | ||
75 | #ifdef CONFIG_PROC_FS | 76 | #ifdef CONFIG_PROC_FS |
76 | |||
77 | static const struct file_operations udplite_afinfo_seq_fops = { | ||
78 | .open = udp_seq_open, | ||
79 | .read = seq_read, | ||
80 | .llseek = seq_lseek, | ||
81 | .release = seq_release_net | ||
82 | }; | ||
83 | |||
84 | static struct udp_seq_afinfo udplite4_seq_afinfo = { | 77 | static struct udp_seq_afinfo udplite4_seq_afinfo = { |
85 | .name = "udplite", | ||
86 | .family = AF_INET, | 78 | .family = AF_INET, |
87 | .udp_table = &udplite_table, | 79 | .udp_table = &udplite_table, |
88 | .seq_fops = &udplite_afinfo_seq_fops, | ||
89 | .seq_ops = { | ||
90 | .show = udp4_seq_show, | ||
91 | }, | ||
92 | }; | 80 | }; |
93 | 81 | ||
94 | static int __net_init udplite4_proc_init_net(struct net *net) | 82 | static int __net_init udplite4_proc_init_net(struct net *net) |
95 | { | 83 | { |
96 | return udp_proc_register(net, &udplite4_seq_afinfo); | 84 | if (!proc_create_data("udplite", 0444, net->proc_net, |
85 | &udp_afinfo_seq_fops, &udplite4_seq_afinfo)) | ||
86 | return -ENOMEM; | ||
87 | return 0; | ||
97 | } | 88 | } |
98 | 89 | ||
99 | static void __net_exit udplite4_proc_exit_net(struct net *net) | 90 | static void __net_exit udplite4_proc_exit_net(struct net *net) |
100 | { | 91 | { |
101 | udp_proc_unregister(net, &udplite4_seq_afinfo); | 92 | remove_proc_entry("udplite", net->proc_net); |
102 | } | 93 | } |
103 | 94 | ||
104 | static struct pernet_operations udplite4_net_ops = { | 95 | static struct pernet_operations udplite4_net_ops = { |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index ea0730028e5d..29adddeac3e5 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -1480,31 +1480,43 @@ int udp6_seq_show(struct seq_file *seq, void *v) | |||
1480 | return 0; | 1480 | return 0; |
1481 | } | 1481 | } |
1482 | 1482 | ||
1483 | static const struct file_operations udp6_afinfo_seq_fops = { | 1483 | static const struct seq_operations udp6_seq_ops = { |
1484 | .open = udp_seq_open, | 1484 | .start = udp_seq_start, |
1485 | .next = udp_seq_next, | ||
1486 | .stop = udp_seq_stop, | ||
1487 | .show = udp6_seq_show, | ||
1488 | }; | ||
1489 | |||
1490 | static int udp6_seq_open(struct inode *inode, struct file *file) | ||
1491 | { | ||
1492 | return seq_open_net(inode, file, &udp6_seq_ops, | ||
1493 | sizeof(struct udp_iter_state)); | ||
1494 | } | ||
1495 | |||
1496 | const struct file_operations udp6_afinfo_seq_fops = { | ||
1497 | .open = udp6_seq_open, | ||
1485 | .read = seq_read, | 1498 | .read = seq_read, |
1486 | .llseek = seq_lseek, | 1499 | .llseek = seq_lseek, |
1487 | .release = seq_release_net | 1500 | .release = seq_release_net |
1488 | }; | 1501 | }; |
1502 | EXPORT_SYMBOL(udp6_afinfo_seq_fops); | ||
1489 | 1503 | ||
1490 | static struct udp_seq_afinfo udp6_seq_afinfo = { | 1504 | static struct udp_seq_afinfo udp6_seq_afinfo = { |
1491 | .name = "udp6", | ||
1492 | .family = AF_INET6, | 1505 | .family = AF_INET6, |
1493 | .udp_table = &udp_table, | 1506 | .udp_table = &udp_table, |
1494 | .seq_fops = &udp6_afinfo_seq_fops, | ||
1495 | .seq_ops = { | ||
1496 | .show = udp6_seq_show, | ||
1497 | }, | ||
1498 | }; | 1507 | }; |
1499 | 1508 | ||
1500 | int __net_init udp6_proc_init(struct net *net) | 1509 | int __net_init udp6_proc_init(struct net *net) |
1501 | { | 1510 | { |
1502 | return udp_proc_register(net, &udp6_seq_afinfo); | 1511 | if (!proc_create_data("udp6", 0444, net->proc_net, |
1512 | &udp6_afinfo_seq_fops, &udp6_seq_afinfo)) | ||
1513 | return -ENOMEM; | ||
1514 | return 0; | ||
1503 | } | 1515 | } |
1504 | 1516 | ||
1505 | void udp6_proc_exit(struct net *net) | 1517 | void udp6_proc_exit(struct net *net) |
1506 | { | 1518 | { |
1507 | udp_proc_unregister(net, &udp6_seq_afinfo); | 1519 | remove_proc_entry("udp6", net->proc_net); |
1508 | } | 1520 | } |
1509 | #endif /* CONFIG_PROC_FS */ | 1521 | #endif /* CONFIG_PROC_FS */ |
1510 | 1522 | ||
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c index 14ae32bb1f3d..a119e57196b5 100644 --- a/net/ipv6/udplite.c +++ b/net/ipv6/udplite.c | |||
@@ -12,6 +12,7 @@ | |||
12 | * 2 of the License, or (at your option) any later version. | 12 | * 2 of the License, or (at your option) any later version. |
13 | */ | 13 | */ |
14 | #include <linux/export.h> | 14 | #include <linux/export.h> |
15 | #include <linux/proc_fs.h> | ||
15 | #include "udp_impl.h" | 16 | #include "udp_impl.h" |
16 | 17 | ||
17 | static int udplitev6_rcv(struct sk_buff *skb) | 18 | static int udplitev6_rcv(struct sk_buff *skb) |
@@ -92,32 +93,22 @@ void udplitev6_exit(void) | |||
92 | } | 93 | } |
93 | 94 | ||
94 | #ifdef CONFIG_PROC_FS | 95 | #ifdef CONFIG_PROC_FS |
95 | |||
96 | static const struct file_operations udplite6_afinfo_seq_fops = { | ||
97 | .open = udp_seq_open, | ||
98 | .read = seq_read, | ||
99 | .llseek = seq_lseek, | ||
100 | .release = seq_release_net | ||
101 | }; | ||
102 | |||
103 | static struct udp_seq_afinfo udplite6_seq_afinfo = { | 96 | static struct udp_seq_afinfo udplite6_seq_afinfo = { |
104 | .name = "udplite6", | ||
105 | .family = AF_INET6, | 97 | .family = AF_INET6, |
106 | .udp_table = &udplite_table, | 98 | .udp_table = &udplite_table, |
107 | .seq_fops = &udplite6_afinfo_seq_fops, | ||
108 | .seq_ops = { | ||
109 | .show = udp6_seq_show, | ||
110 | }, | ||
111 | }; | 99 | }; |
112 | 100 | ||
113 | static int __net_init udplite6_proc_init_net(struct net *net) | 101 | static int __net_init udplite6_proc_init_net(struct net *net) |
114 | { | 102 | { |
115 | return udp_proc_register(net, &udplite6_seq_afinfo); | 103 | if (!proc_create_data("udplite6", 0444, net->proc_net, |
104 | &udp6_afinfo_seq_fops, &udplite6_seq_afinfo)) | ||
105 | return -ENOMEM; | ||
106 | return 0; | ||
116 | } | 107 | } |
117 | 108 | ||
118 | static void __net_exit udplite6_proc_exit_net(struct net *net) | 109 | static void __net_exit udplite6_proc_exit_net(struct net *net) |
119 | { | 110 | { |
120 | udp_proc_unregister(net, &udplite6_seq_afinfo); | 111 | remove_proc_entry("udplite6", net->proc_net); |
121 | } | 112 | } |
122 | 113 | ||
123 | static struct pernet_operations udplite6_net_ops = { | 114 | static struct pernet_operations udplite6_net_ops = { |