]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
99824461 | 2 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
1da177e4 LT |
3 | |
4 | #ifdef CONFIG_PROC_FS | |
5 | #include <linux/errno.h> | |
6 | #include <linux/kernel.h> | |
f7d57453 | 7 | #include <linux/string.h> |
1da177e4 LT |
8 | #include <linux/mm.h> |
9 | #include <linux/module.h> | |
10 | #include <linux/proc_fs.h> | |
d750dbdc | 11 | #include <linux/ktime.h> |
1da177e4 | 12 | #include <linux/seq_file.h> |
f1e10049 | 13 | #include <linux/uaccess.h> |
1da177e4 LT |
14 | #include <linux/atmmpc.h> |
15 | #include <linux/atm.h> | |
5a0e3ad6 | 16 | #include <linux/gfp.h> |
1da177e4 LT |
17 | #include "mpc.h" |
18 | #include "mpoa_caches.h" | |
19 | ||
20 | /* | |
21 | * mpoa_proc.c: Implementation MPOA client's proc | |
f7d57453 | 22 | * file system statistics |
1da177e4 LT |
23 | */ |
24 | ||
25 | #if 1 | |
b50c2ea7 JP |
26 | #define dprintk(format, args...) \ |
27 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */ | |
1da177e4 | 28 | #else |
b50c2ea7 JP |
29 | #define dprintk(format, args...) \ |
30 | do { if (0) \ | |
31 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\ | |
32 | } while (0) | |
33 | #endif | |
34 | ||
35 | #if 0 | |
36 | #define ddprintk(format, args...) \ | |
37 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */ | |
38 | #else | |
39 | #define ddprintk(format, args...) \ | |
40 | do { if (0) \ | |
41 | printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\ | |
42 | } while (0) | |
1da177e4 LT |
43 | #endif |
44 | ||
45 | #define STAT_FILE_NAME "mpc" /* Our statistic file's name */ | |
46 | ||
47 | extern struct mpoa_client *mpcs; | |
48 | extern struct proc_dir_entry *atm_proc_root; /* from proc.c. */ | |
49 | ||
50 | static int proc_mpc_open(struct inode *inode, struct file *file); | |
51 | static ssize_t proc_mpc_write(struct file *file, const char __user *buff, | |
f7d57453 | 52 | size_t nbytes, loff_t *ppos); |
1da177e4 LT |
53 | |
54 | static int parse_qos(const char *buff); | |
55 | ||
97a32539 AD |
56 | static const struct proc_ops mpc_proc_ops = { |
57 | .proc_open = proc_mpc_open, | |
58 | .proc_read = seq_read, | |
59 | .proc_lseek = seq_lseek, | |
60 | .proc_write = proc_mpc_write, | |
61 | .proc_release = seq_release, | |
1da177e4 LT |
62 | }; |
63 | ||
64 | /* | |
65 | * Returns the state of an ingress cache entry as a string | |
66 | */ | |
f1e10049 JP |
67 | static const char *ingress_state_string(int state) |
68 | { | |
69 | switch (state) { | |
1da177e4 | 70 | case INGRESS_RESOLVING: |
f7d57453 | 71 | return "resolving "; |
1da177e4 | 72 | case INGRESS_RESOLVED: |
f7d57453 | 73 | return "resolved "; |
1da177e4 | 74 | case INGRESS_INVALID: |
f7d57453 | 75 | return "invalid "; |
1da177e4 | 76 | case INGRESS_REFRESHING: |
f7d57453 | 77 | return "refreshing "; |
1da177e4 | 78 | } |
f1e10049 JP |
79 | |
80 | return ""; | |
1da177e4 LT |
81 | } |
82 | ||
83 | /* | |
84 | * Returns the state of an egress cache entry as a string | |
85 | */ | |
f1e10049 JP |
86 | static const char *egress_state_string(int state) |
87 | { | |
88 | switch (state) { | |
1da177e4 | 89 | case EGRESS_RESOLVED: |
f7d57453 | 90 | return "resolved "; |
1da177e4 | 91 | case EGRESS_PURGE: |
f7d57453 | 92 | return "purge "; |
1da177e4 | 93 | case EGRESS_INVALID: |
f7d57453 | 94 | return "invalid "; |
1da177e4 | 95 | } |
f1e10049 JP |
96 | |
97 | return ""; | |
1da177e4 LT |
98 | } |
99 | ||
100 | /* | |
101 | * FIXME: mpcs (and per-mpc lists) have no locking whatsoever. | |
102 | */ | |
103 | ||
104 | static void *mpc_start(struct seq_file *m, loff_t *pos) | |
105 | { | |
106 | loff_t l = *pos; | |
107 | struct mpoa_client *mpc; | |
108 | ||
109 | if (!l--) | |
110 | return SEQ_START_TOKEN; | |
111 | for (mpc = mpcs; mpc; mpc = mpc->next) | |
112 | if (!l--) | |
113 | return mpc; | |
114 | return NULL; | |
115 | } | |
116 | ||
117 | static void *mpc_next(struct seq_file *m, void *v, loff_t *pos) | |
118 | { | |
119 | struct mpoa_client *p = v; | |
120 | (*pos)++; | |
121 | return v == SEQ_START_TOKEN ? mpcs : p->next; | |
122 | } | |
123 | ||
124 | static void mpc_stop(struct seq_file *m, void *v) | |
125 | { | |
126 | } | |
127 | ||
128 | /* | |
129 | * READING function - called when the /proc/atm/mpoa file is read from. | |
130 | */ | |
131 | static int mpc_show(struct seq_file *m, void *v) | |
132 | { | |
133 | struct mpoa_client *mpc = v; | |
1da177e4 LT |
134 | int i; |
135 | in_cache_entry *in_entry; | |
136 | eg_cache_entry *eg_entry; | |
d750dbdc | 137 | time64_t now; |
1da177e4 LT |
138 | unsigned char ip_string[16]; |
139 | ||
140 | if (v == SEQ_START_TOKEN) { | |
141 | atm_mpoa_disp_qos(m); | |
142 | return 0; | |
143 | } | |
144 | ||
f7d57453 | 145 | seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num); |
1da177e4 | 146 | seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n"); |
d750dbdc | 147 | now = ktime_get_seconds(); |
1da177e4 LT |
148 | |
149 | for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) { | |
d750dbdc TR |
150 | unsigned long seconds_delta = now - in_entry->time; |
151 | ||
f1e10049 | 152 | sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip); |
1da177e4 | 153 | seq_printf(m, "%-16s%s%-14lu%-12u", |
f1e10049 JP |
154 | ip_string, |
155 | ingress_state_string(in_entry->entry_state), | |
156 | in_entry->ctrl_info.holding_time - | |
d750dbdc | 157 | seconds_delta, |
f1e10049 | 158 | in_entry->packets_fwded); |
1da177e4 | 159 | if (in_entry->shortcut) |
f1e10049 JP |
160 | seq_printf(m, " %-3d %-3d", |
161 | in_entry->shortcut->vpi, | |
162 | in_entry->shortcut->vci); | |
1da177e4 LT |
163 | seq_printf(m, "\n"); |
164 | } | |
165 | ||
166 | seq_printf(m, "\n"); | |
167 | seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n"); | |
168 | for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) { | |
169 | unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr; | |
d750dbdc TR |
170 | unsigned long seconds_delta = now - eg_entry->time; |
171 | ||
f1e10049 | 172 | for (i = 0; i < ATM_ESA_LEN; i++) |
1da177e4 LT |
173 | seq_printf(m, "%02x", p[i]); |
174 | seq_printf(m, "\n%-16lu%s%-14lu%-15u", | |
175 | (unsigned long)ntohl(eg_entry->ctrl_info.cache_id), | |
176 | egress_state_string(eg_entry->entry_state), | |
d750dbdc | 177 | (eg_entry->ctrl_info.holding_time - seconds_delta), |
1da177e4 | 178 | eg_entry->packets_rcvd); |
f7d57453 | 179 | |
1da177e4 | 180 | /* latest IP address */ |
f1e10049 | 181 | sprintf(ip_string, "%pI4", &eg_entry->latest_ip_addr); |
1da177e4 LT |
182 | seq_printf(m, "%-16s", ip_string); |
183 | ||
184 | if (eg_entry->shortcut) | |
f1e10049 JP |
185 | seq_printf(m, " %-3d %-3d", |
186 | eg_entry->shortcut->vpi, | |
187 | eg_entry->shortcut->vci); | |
1da177e4 LT |
188 | seq_printf(m, "\n"); |
189 | } | |
190 | seq_printf(m, "\n"); | |
191 | return 0; | |
192 | } | |
193 | ||
56b3d975 | 194 | static const struct seq_operations mpc_op = { |
1da177e4 LT |
195 | .start = mpc_start, |
196 | .next = mpc_next, | |
197 | .stop = mpc_stop, | |
198 | .show = mpc_show | |
199 | }; | |
200 | ||
201 | static int proc_mpc_open(struct inode *inode, struct file *file) | |
202 | { | |
203 | return seq_open(file, &mpc_op); | |
204 | } | |
205 | ||
206 | static ssize_t proc_mpc_write(struct file *file, const char __user *buff, | |
f7d57453 | 207 | size_t nbytes, loff_t *ppos) |
1da177e4 | 208 | { |
f7d57453 | 209 | char *page, *p; |
95c96174 | 210 | unsigned int len; |
1da177e4 | 211 | |
f7d57453 | 212 | if (nbytes == 0) |
1da177e4 LT |
213 | return 0; |
214 | ||
f7d57453 | 215 | if (nbytes >= PAGE_SIZE) |
1da177e4 LT |
216 | nbytes = PAGE_SIZE-1; |
217 | ||
f7d57453 YH |
218 | page = (char *)__get_free_page(GFP_KERNEL); |
219 | if (!page) | |
1da177e4 LT |
220 | return -ENOMEM; |
221 | ||
d8bde3bf | 222 | for (p = page, len = 0; len < nbytes; p++) { |
f7d57453 | 223 | if (get_user(*p, buff++)) { |
1da177e4 LT |
224 | free_page((unsigned long)page); |
225 | return -EFAULT; | |
226 | } | |
d8bde3bf | 227 | len += 1; |
f7d57453 YH |
228 | if (*p == '\0' || *p == '\n') |
229 | break; | |
230 | } | |
1da177e4 | 231 | |
f7d57453 | 232 | *p = '\0'; |
1da177e4 LT |
233 | |
234 | if (!parse_qos(page)) | |
f7d57453 YH |
235 | printk("mpoa: proc_mpc_write: could not parse '%s'\n", page); |
236 | ||
237 | free_page((unsigned long)page); | |
1da177e4 | 238 | |
f7d57453 | 239 | return len; |
1da177e4 LT |
240 | } |
241 | ||
242 | static int parse_qos(const char *buff) | |
243 | { | |
f7d57453 YH |
244 | /* possible lines look like this |
245 | * add 130.230.54.142 tx=max_pcr,max_sdu rx=max_pcr,max_sdu | |
246 | */ | |
247 | unsigned char ip[4]; | |
1da177e4 | 248 | int tx_pcr, tx_sdu, rx_pcr, rx_sdu; |
f7d57453 YH |
249 | __be32 ipaddr; |
250 | struct atm_qos qos; | |
251 | ||
252 | memset(&qos, 0, sizeof(struct atm_qos)); | |
1da177e4 LT |
253 | |
254 | if (sscanf(buff, "del %hhu.%hhu.%hhu.%hhu", | |
255 | ip, ip+1, ip+2, ip+3) == 4) { | |
30d492da | 256 | ipaddr = *(__be32 *)ip; |
1da177e4 LT |
257 | return atm_mpoa_delete_qos(atm_mpoa_search_qos(ipaddr)); |
258 | } | |
259 | ||
260 | if (sscanf(buff, "add %hhu.%hhu.%hhu.%hhu tx=%d,%d rx=tx", | |
261 | ip, ip+1, ip+2, ip+3, &tx_pcr, &tx_sdu) == 6) { | |
262 | rx_pcr = tx_pcr; | |
263 | rx_sdu = tx_sdu; | |
264 | } else if (sscanf(buff, "add %hhu.%hhu.%hhu.%hhu tx=%d,%d rx=%d,%d", | |
265 | ip, ip+1, ip+2, ip+3, &tx_pcr, &tx_sdu, &rx_pcr, &rx_sdu) != 8) | |
266 | return 0; | |
267 | ||
f7d57453 | 268 | ipaddr = *(__be32 *)ip; |
1da177e4 LT |
269 | qos.txtp.traffic_class = ATM_CBR; |
270 | qos.txtp.max_pcr = tx_pcr; | |
271 | qos.txtp.max_sdu = tx_sdu; | |
272 | qos.rxtp.traffic_class = ATM_CBR; | |
273 | qos.rxtp.max_pcr = rx_pcr; | |
274 | qos.rxtp.max_sdu = rx_sdu; | |
f7d57453 | 275 | qos.aal = ATM_AAL5; |
f42cf8d6 | 276 | dprintk("parse_qos(): setting qos parameters to tx=%d,%d rx=%d,%d\n", |
b50c2ea7 JP |
277 | qos.txtp.max_pcr, qos.txtp.max_sdu, |
278 | qos.rxtp.max_pcr, qos.rxtp.max_sdu); | |
1da177e4 LT |
279 | |
280 | atm_mpoa_add_qos(ipaddr, &qos); | |
281 | return 1; | |
282 | } | |
283 | ||
284 | /* | |
285 | * INITIALIZATION function - called when module is initialized/loaded. | |
286 | */ | |
287 | int mpc_proc_init(void) | |
288 | { | |
289 | struct proc_dir_entry *p; | |
290 | ||
97a32539 | 291 | p = proc_create(STAT_FILE_NAME, 0, atm_proc_root, &mpc_proc_ops); |
1da177e4 | 292 | if (!p) { |
99824461 | 293 | pr_err("Unable to initialize /proc/atm/%s\n", STAT_FILE_NAME); |
f7d57453 YH |
294 | return -ENOMEM; |
295 | } | |
1da177e4 LT |
296 | return 0; |
297 | } | |
298 | ||
299 | /* | |
300 | * DELETING function - called when module is removed. | |
301 | */ | |
302 | void mpc_proc_clean(void) | |
303 | { | |
f1e10049 | 304 | remove_proc_entry(STAT_FILE_NAME, atm_proc_root); |
1da177e4 LT |
305 | } |
306 | ||
1da177e4 | 307 | #endif /* CONFIG_PROC_FS */ |