예제 #1
0
/*
 * READING function - called when the /proc/atm/mpoa file is read from.
 */
static int mpc_show(struct seq_file *m, void *v)
{
	struct mpoa_client *mpc = v;
	int i;
	in_cache_entry *in_entry;
	eg_cache_entry *eg_entry;
	struct timeval now;
	unsigned char ip_string[16];

	if (v == SEQ_START_TOKEN) {
		atm_mpoa_disp_qos(m);
		return 0;
	}

	seq_printf(m, "\nInterface %d:\n\n", mpc->dev_num);
	seq_printf(m, "Ingress Entries:\nIP address      State      Holding time  Packets fwded  VPI  VCI\n");
	do_gettimeofday(&now);

	for (in_entry = mpc->in_cache; in_entry; in_entry = in_entry->next) {
		sprintf(ip_string, "%pI4", &in_entry->ctrl_info.in_dst_ip);
		seq_printf(m, "%-16s%s%-14lu%-12u",
			   ip_string,
			   ingress_state_string(in_entry->entry_state),
			   in_entry->ctrl_info.holding_time -
			   (now.tv_sec-in_entry->tv.tv_sec),
			   in_entry->packets_fwded);
		if (in_entry->shortcut)
			seq_printf(m, "   %-3d  %-3d",
				   in_entry->shortcut->vpi,
				   in_entry->shortcut->vci);
		seq_printf(m, "\n");
	}

	seq_printf(m, "\n");
	seq_printf(m, "Egress Entries:\nIngress MPC ATM addr\nCache-id        State      Holding time  Packets recvd  Latest IP addr   VPI VCI\n");
	for (eg_entry = mpc->eg_cache; eg_entry; eg_entry = eg_entry->next) {
		unsigned char *p = eg_entry->ctrl_info.in_MPC_data_ATM_addr;
		for (i = 0; i < ATM_ESA_LEN; i++)
			seq_printf(m, "%02x", p[i]);
		seq_printf(m, "\n%-16lu%s%-14lu%-15u",
			   (unsigned long)ntohl(eg_entry->ctrl_info.cache_id),
			   egress_state_string(eg_entry->entry_state),
			   (eg_entry->ctrl_info.holding_time -
			    (now.tv_sec-eg_entry->tv.tv_sec)),
			   eg_entry->packets_rcvd);

		/* latest IP address */
		sprintf(ip_string, "%pI4", &eg_entry->latest_ip_addr);
		seq_printf(m, "%-16s", ip_string);

		if (eg_entry->shortcut)
			seq_printf(m, " %-3d %-3d",
				   eg_entry->shortcut->vpi,
				   eg_entry->shortcut->vci);
		seq_printf(m, "\n");
	}
	seq_printf(m, "\n");
	return 0;
}
예제 #2
0
/*
 * READING function - called when the /proc/atm/mpoa file is read from.
 */
static ssize_t proc_mpc_read(struct file *file, char *buff,
			     size_t count, loff_t *pos){
        unsigned long page = 0;
	unsigned char *temp;
        ssize_t length  = 0;
	int i = 0;
	struct mpoa_client *mpc = mpcs;
	in_cache_entry *in_entry;
	eg_cache_entry *eg_entry;
	struct timeval now;
	unsigned char ip_string[16];
	if(count < 0)
	        return -EINVAL;
	if(count == 0)
	        return 0;
	page = get_free_page(GFP_KERNEL);
	if(!page)
	        return -ENOMEM;
	atm_mpoa_disp_qos((char *)page, &length);
	while(mpc != NULL){
	        length += print_header((char *)page + length, mpc);
		length += sprintf((char *)page + length,"Ingress Entries:\nIP address      State      Holding time  Packets fwded  VPI  VCI\n");
		in_entry = mpc->in_cache;
		do_gettimeofday(&now);
		while(in_entry != NULL){
		        temp = (unsigned char *)&in_entry->ctrl_info.in_dst_ip;                        sprintf(ip_string,"%d.%d.%d.%d", temp[0], temp[1], temp[2], temp[3]);
		        length += sprintf((char *)page + length,"%-16s%s%-14lu%-12u", ip_string, ingress_state_string(in_entry->entry_state), (in_entry->ctrl_info.holding_time-(now.tv_sec-in_entry->tv.tv_sec)), in_entry->packets_fwded);
			if(in_entry->shortcut)
			        length += sprintf((char *)page + length,"   %-3d  %-3d",in_entry->shortcut->vpi,in_entry->shortcut->vci);
			length += sprintf((char *)page + length,"\n");
			in_entry = in_entry->next;
		}
		length += sprintf((char *)page + length,"\n");
		eg_entry = mpc->eg_cache;
		length += sprintf((char *)page + length,"Egress Entries:\nIngress MPC ATM addr\nCache-id        State      Holding time  Packets recvd  Latest IP addr   VPI VCI\n");
		while(eg_entry != NULL){
		  for(i=0;i<ATM_ESA_LEN;i++){
		          length += sprintf((char *)page + length,"%02x",eg_entry->ctrl_info.in_MPC_data_ATM_addr[i]);}  
		        length += sprintf((char *)page + length,"\n%-16lu%s%-14lu%-15u",(unsigned long) ntohl(eg_entry->ctrl_info.cache_id), egress_state_string(eg_entry->entry_state), (eg_entry->ctrl_info.holding_time-(now.tv_sec-eg_entry->tv.tv_sec)), eg_entry->packets_rcvd);
			
			/* latest IP address */
			temp = (unsigned char *)&eg_entry->latest_ip_addr;
			sprintf(ip_string, "%d.%d.%d.%d", temp[0], temp[1], temp[2], temp[3]);
			length += sprintf((char *)page + length, "%-16s", ip_string);

			if(eg_entry->shortcut)
			        length += sprintf((char *)page + length," %-3d %-3d",eg_entry->shortcut->vpi,eg_entry->shortcut->vci);
			length += sprintf((char *)page + length,"\n");
			eg_entry = eg_entry->next;
		}
		length += sprintf((char *)page + length,"\n");
		mpc = mpc->next;
	}

	if (*pos >= length) length = 0;
	else {
	  if ((count + *pos) > length) count = length - *pos;
	  if (copy_to_user(buff, (char *)page , count)) {
 		  free_page(page);
		  return -EFAULT;
          }
	  *pos += count;
	}

 	free_page(page);
        return length;
}