Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *
0004  * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
0005  */
0006 #include <linux/mm.h>
0007 #include <linux/slab.h>
0008 #include <linux/sysctl.h>
0009 #include <linux/spinlock.h>
0010 #include <net/ax25.h>
0011 
0012 static int min_ipdefmode[1],        max_ipdefmode[] = {1};
0013 static int min_axdefmode[1],            max_axdefmode[] = {1};
0014 static int min_backoff[1],      max_backoff[] = {2};
0015 static int min_conmode[1],      max_conmode[] = {2};
0016 static int min_window[] = {1},      max_window[] = {7};
0017 static int min_ewindow[] = {1},     max_ewindow[] = {63};
0018 static int min_t1[] = {1},      max_t1[] = {30000};
0019 static int min_t2[] = {1},      max_t2[] = {20000};
0020 static int min_t3[1],           max_t3[] = {3600000};
0021 static int min_idle[1],         max_idle[] = {65535000};
0022 static int min_n2[] = {1},      max_n2[] = {31};
0023 static int min_paclen[] = {1},      max_paclen[] = {512};
0024 static int min_proto[1],        max_proto[] = { AX25_PROTO_MAX };
0025 #ifdef CONFIG_AX25_DAMA_SLAVE
0026 static int min_ds_timeout[1],       max_ds_timeout[] = {65535000};
0027 #endif
0028 
0029 static const struct ctl_table ax25_param_table[] = {
0030     {
0031         .procname   = "ip_default_mode",
0032         .maxlen     = sizeof(int),
0033         .mode       = 0644,
0034         .proc_handler   = proc_dointvec_minmax,
0035         .extra1     = &min_ipdefmode,
0036         .extra2     = &max_ipdefmode
0037     },
0038     {
0039         .procname   = "ax25_default_mode",
0040         .maxlen     = sizeof(int),
0041         .mode       = 0644,
0042         .proc_handler   = proc_dointvec_minmax,
0043         .extra1     = &min_axdefmode,
0044         .extra2     = &max_axdefmode
0045     },
0046     {
0047         .procname   = "backoff_type",
0048         .maxlen     = sizeof(int),
0049         .mode       = 0644,
0050         .proc_handler   = proc_dointvec_minmax,
0051         .extra1     = &min_backoff,
0052         .extra2     = &max_backoff
0053     },
0054     {
0055         .procname   = "connect_mode",
0056         .maxlen     = sizeof(int),
0057         .mode       = 0644,
0058         .proc_handler   = proc_dointvec_minmax,
0059         .extra1     = &min_conmode,
0060         .extra2     = &max_conmode
0061     },
0062     {
0063         .procname   = "standard_window_size",
0064         .maxlen     = sizeof(int),
0065         .mode       = 0644,
0066         .proc_handler   = proc_dointvec_minmax,
0067         .extra1     = &min_window,
0068         .extra2     = &max_window
0069     },
0070     {
0071         .procname   = "extended_window_size",
0072         .maxlen     = sizeof(int),
0073         .mode       = 0644,
0074         .proc_handler   = proc_dointvec_minmax,
0075         .extra1     = &min_ewindow,
0076         .extra2     = &max_ewindow
0077     },
0078     {
0079         .procname   = "t1_timeout",
0080         .maxlen     = sizeof(int),
0081         .mode       = 0644,
0082         .proc_handler   = proc_dointvec_minmax,
0083         .extra1     = &min_t1,
0084         .extra2     = &max_t1
0085     },
0086     {
0087         .procname   = "t2_timeout",
0088         .maxlen     = sizeof(int),
0089         .mode       = 0644,
0090         .proc_handler   = proc_dointvec_minmax,
0091         .extra1     = &min_t2,
0092         .extra2     = &max_t2
0093     },
0094     {
0095         .procname   = "t3_timeout",
0096         .maxlen     = sizeof(int),
0097         .mode       = 0644,
0098         .proc_handler   = proc_dointvec_minmax,
0099         .extra1     = &min_t3,
0100         .extra2     = &max_t3
0101     },
0102     {
0103         .procname   = "idle_timeout",
0104         .maxlen     = sizeof(int),
0105         .mode       = 0644,
0106         .proc_handler   = proc_dointvec_minmax,
0107         .extra1     = &min_idle,
0108         .extra2     = &max_idle
0109     },
0110     {
0111         .procname   = "maximum_retry_count",
0112         .maxlen     = sizeof(int),
0113         .mode       = 0644,
0114         .proc_handler   = proc_dointvec_minmax,
0115         .extra1     = &min_n2,
0116         .extra2     = &max_n2
0117     },
0118     {
0119         .procname   = "maximum_packet_length",
0120         .maxlen     = sizeof(int),
0121         .mode       = 0644,
0122         .proc_handler   = proc_dointvec_minmax,
0123         .extra1     = &min_paclen,
0124         .extra2     = &max_paclen
0125     },
0126     {
0127         .procname   = "protocol",
0128         .maxlen     = sizeof(int),
0129         .mode       = 0644,
0130         .proc_handler   = proc_dointvec_minmax,
0131         .extra1     = &min_proto,
0132         .extra2     = &max_proto
0133     },
0134 #ifdef CONFIG_AX25_DAMA_SLAVE
0135     {
0136         .procname   = "dama_slave_timeout",
0137         .maxlen     = sizeof(int),
0138         .mode       = 0644,
0139         .proc_handler   = proc_dointvec_minmax,
0140         .extra1     = &min_ds_timeout,
0141         .extra2     = &max_ds_timeout
0142     },
0143 #endif
0144 
0145     { } /* that's all, folks! */
0146 };
0147 
0148 int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
0149 {
0150     char path[sizeof("net/ax25/") + IFNAMSIZ];
0151     int k;
0152     struct ctl_table *table;
0153 
0154     table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
0155     if (!table)
0156         return -ENOMEM;
0157 
0158     for (k = 0; k < AX25_MAX_VALUES; k++)
0159         table[k].data = &ax25_dev->values[k];
0160 
0161     snprintf(path, sizeof(path), "net/ax25/%s", ax25_dev->dev->name);
0162     ax25_dev->sysheader = register_net_sysctl(&init_net, path, table);
0163     if (!ax25_dev->sysheader) {
0164         kfree(table);
0165         return -ENOMEM;
0166     }
0167     return 0;
0168 }
0169 
0170 void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev)
0171 {
0172     struct ctl_table_header *header = ax25_dev->sysheader;
0173     struct ctl_table *table;
0174 
0175     if (header) {
0176         ax25_dev->sysheader = NULL;
0177         table = header->ctl_table_arg;
0178         unregister_net_sysctl_table(header);
0179         kfree(table);
0180     }
0181 }