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