GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / net / atm / mpoa_proc.c
blob648b451fa0dc8a7813e6851876938e407feefedf
1 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
3 #ifdef CONFIG_PROC_FS
4 #include <linux/errno.h>
5 #include <linux/kernel.h>
6 #include <linux/string.h>
7 #include <linux/mm.h>
8 #include <linux/module.h>
9 #include <linux/proc_fs.h>
10 #include <linux/time.h>
11 #include <linux/seq_file.h>
12 #include <linux/uaccess.h>
13 #include <linux/atmmpc.h>
14 #include <linux/atm.h>
15 #include <linux/gfp.h>
16 #include "mpc.h"
17 #include "mpoa_caches.h"
20 * mpoa_proc.c: Implementation MPOA client's proc
21 * file system statistics
24 #define dprintk(format, args...) \
25 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args) /* debug */
27 #define ddprintk(format, args...) \
28 do { if (0) \
29 printk(KERN_DEBUG "mpoa:%s: " format, __FILE__, ##args);\
30 } while (0)
32 #define STAT_FILE_NAME "mpc" /* Our statistic file's name */
34 extern struct mpoa_client *mpcs;
35 extern struct proc_dir_entry *atm_proc_root; /* from proc.c. */
37 static int proc_mpc_open(struct inode *inode, struct file *file);
38 static ssize_t proc_mpc_write(struct file *file, const char __user *buff,
39 size_t nbytes, loff_t *ppos);
41 static int parse_qos(const char *buff);
44 * Define allowed FILE OPERATIONS
46 static const struct file_operations mpc_file_operations = {
47 .owner = THIS_MODULE,
48 .open = proc_mpc_open,
49 .read = seq_read,
50 .llseek = seq_lseek,
51 .write = proc_mpc_write,
52 .release = seq_release,
56 * Returns the state of an ingress cache entry as a string
58 static const char *ingress_state_string(int state)
60 switch (state) {
61 case INGRESS_RESOLVING:
62 return "resolving ";
63 case INGRESS_RESOLVED:
64 return "resolved ";
65 case INGRESS_INVALID:
66 return "invalid ";
67 case INGRESS_REFRESHING:
68 return "refreshing ";
71 return "";
75 * Returns the state of an egress cache entry as a string
77 static const char *egress_state_string(int state)
79 switch (state) {
80 case EGRESS_RESOLVED:
81 return "resolved ";
82 case EGRESS_PURGE:
83 return "purge ";
84 case EGRESS_INVALID:
85 return "invalid ";
88 return "";
92 static void *mpc_start(struct seq_file *m, loff_t *pos)
94 loff_t l = *pos;
95 struct mpoa_client *mpc;
97 if (!l--)
98 return SEQ_START_TOKEN;
99 for (mpc = mpcs; mpc; mpc = mpc->next)
100 if (!l--)
101 return mpc;
102 return NULL;
105 static void *mpc_next(struct seq_file *m, void *v, loff_t *pos)
107 struct mpoa_client *p = v;
108 (*pos)++;
109 return v == SEQ_START_TOKEN ? mpcs : p->next;
112 static void mpc_stop(struct seq_file *m, void *v)
117 * READING function - called when the /proc/atm/mpoa file is read from.
119 static int mpc_show(struct seq_file *m, void *v)
121 struct mpoa_client *mpc = v;
122 int i;
123 in_cache_entry *in_entry;
124 eg_cache_entry *eg_entry;
125 struct timeval now;
126 unsigned char ip_string[16];
128 if (v == SEQ_START_TOKEN) {
129 atm_mpoa_disp_qos(m);
130 return 0;
133 seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num);
134 seq_printf(m, "Ingress Entries:\nIP address State Holding time Packets fwded VPI VCI\n");
135 do_gettimeofday(&now);
137 for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) {
138 sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip);
139 seq_printf(m, "%-16s%s%-14lu%-12u",
140 ip_string,
141 ingress_state_string(in_entry->entry_state),
142 in_entry->ctrl_info.holding_time -
143 (now.tv_sec-in_entry->tv.tv_sec),
144 in_entry->packets_fwded);
145 if (in_entry->shortcut)
146 seq_printf(m, " %-3d %-3d",
147 in_entry->shortcut->vpi,
148 in_entry->shortcut->vci);
149 seq_printf(m, "\n");
152 seq_printf(m, "\n");
153 seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id State Holding time Packets recvd Latest IP addr VPI VCI\n");
154 for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) {
155 unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr;
156 for (i = 0; i < ATM_ESA_LEN; i++)
157 seq_printf(m, "%02x", p[i]);
158 seq_printf(m, "\n%-16lu%s%-14lu%-15u",
159 (unsigned long)ntohl(eg_entry->ctrl_info.cache_id),
160 egress_state_string(eg_entry->entry_state),
161 (eg_entry->ctrl_info.holding_time -
162 (now.tv_sec-eg_entry->tv.tv_sec)),
163 eg_entry->packets_rcvd);
165 /* latest IP address */
166 sprintf(ip_string, "%pI4", &eg_entry->latest_ip_addr);
167 seq_printf(m, "%-16s", ip_string);
169 if (eg_entry->shortcut)
170 seq_printf(m, " %-3d %-3d",
171 eg_entry->shortcut->vpi,
172 eg_entry->shortcut->vci);
173 seq_printf(m, "\n");
175 seq_printf(m, "\n");
176 return 0;
179 static const struct seq_operations mpc_op = {
180 .start = mpc_start,
181 .next = mpc_next,
182 .stop = mpc_stop,
183 .show = mpc_show
186 static int proc_mpc_open(struct inode *inode, struct file *file)
188 return seq_open(file, &mpc_op);
191 static ssize_t proc_mpc_write(struct file *file, const char __user *buff,
192 size_t nbytes, loff_t *ppos)
194 char *page, *p;
195 unsigned len;
197 if (nbytes == 0)
198 return 0;
200 if (nbytes >= PAGE_SIZE)
201 nbytes = PAGE_SIZE-1;
203 page = (char *)__get_free_page(GFP_KERNEL);
204 if (!page)
205 return -ENOMEM;
207 for (p = page, len = 0; len < nbytes; p++, len++) {
208 if (get_user(*p, buff++)) {
209 free_page((unsigned long)page);
210 return -EFAULT;
212 if (*p == '\0' || *p == '\n')
213 break;
216 *p = '\0';
218 if (!parse_qos(page))
219 printk("mpoa: proc_mpc_write: could not parse '%s'\n", page);
221 free_page((unsigned long)page);
223 return len;
226 static int parse_qos(const char *buff)
228 /* possible lines look like this
229 * add 130.230.54.142 tx=max_pcr,max_sdu rx=max_pcr,max_sdu
231 unsigned char ip[4];
232 int tx_pcr, tx_sdu, rx_pcr, rx_sdu;
233 __be32 ipaddr;
234 struct atm_qos qos;
236 memset(&qos, 0, sizeof(struct atm_qos));
238 if (sscanf(buff, "del %hhu.%hhu.%hhu.%hhu",
239 ip, ip+1, ip+2, ip+3) == 4) {
240 ipaddr = *(__be32 *)ip;
241 return atm_mpoa_delete_qos(atm_mpoa_search_qos(ipaddr));
244 if (sscanf(buff, "add %hhu.%hhu.%hhu.%hhu tx=%d,%d rx=tx",
245 ip, ip+1, ip+2, ip+3, &tx_pcr, &tx_sdu) == 6) {
246 rx_pcr = tx_pcr;
247 rx_sdu = tx_sdu;
248 } else if (sscanf(buff, "add %hhu.%hhu.%hhu.%hhu tx=%d,%d rx=%d,%d",
249 ip, ip+1, ip+2, ip+3, &tx_pcr, &tx_sdu, &rx_pcr, &rx_sdu) != 8)
250 return 0;
252 ipaddr = *(__be32 *)ip;
253 qos.txtp.traffic_class = ATM_CBR;
254 qos.txtp.max_pcr = tx_pcr;
255 qos.txtp.max_sdu = tx_sdu;
256 qos.rxtp.traffic_class = ATM_CBR;
257 qos.rxtp.max_pcr = rx_pcr;
258 qos.rxtp.max_sdu = rx_sdu;
259 qos.aal = ATM_AAL5;
260 dprintk("parse_qos(): setting qos paramameters to tx=%d,%d rx=%d,%d\n",
261 qos.txtp.max_pcr, qos.txtp.max_sdu,
262 qos.rxtp.max_pcr, qos.rxtp.max_sdu);
264 atm_mpoa_add_qos(ipaddr, &qos);
265 return 1;
269 * INITIALIZATION function - called when module is initialized/loaded.
271 int mpc_proc_init(void)
273 struct proc_dir_entry *p;
275 p = proc_create(STAT_FILE_NAME, 0, atm_proc_root, &mpc_file_operations);
276 if (!p) {
277 pr_err("Unable to initialize /proc/atm/%s\n", STAT_FILE_NAME);
278 return -ENOMEM;
280 return 0;
284 * DELETING function - called when module is removed.
286 void mpc_proc_clean(void)
288 remove_proc_entry(STAT_FILE_NAME, atm_proc_root);
291 #endif /* CONFIG_PROC_FS */