/* coplog.c */ #define DPRINTK #include "copdefs.h" #define LOGRECS (64 * 1024) static int lognext; static phdrlog_t cop_log[LOGRECS]; int cop_openlog( struct inode *inode, struct file *fp); int cop_releaselog( struct inode *inode, struct file *fp); int cop_ioctl( struct inode *inode, struct file *fp, unsigned int func_code, unsigned long arg); #define COP_MAJOR 199 static struct file_operations cop_fops = { ioctl: cop_ioctl, /* ioctl */ open: cop_openlog, /* open */ release: cop_releaselog, /* release */ }; static int cd_registered; /**/ void cop_initlog(void) { int rc2; if ((rc2 = register_chrdev(COP_MAJOR, "copm", &cop_fops))) printk( "cop_log: cannot register chr dev; received %d\n", rc2); else cd_registered = 1; printk("cop_log: registered \n"); } /**/ void cop_resetlog(void) { lognext = 0; } /**/ void cop_rmlog(void) { int rc; if (cd_registered); rc = unregister_chrdev(COP_MAJOR, "copm"); printk("cop rmlog rc = %d \n", rc); } /**/ void cop_addrec( int opcode, cop_sock_t *npo, cop_hdr_t *nph) { phdrlog_t *log; int this_cpu; struct sock *sk = (struct sock *)npo; // printk("locking log \n"); cop_lock(&npo->cop_loglock, LOGLOCK); // printk("locked log \n"); log = cop_log + lognext; this_cpu = smp_processor_id(); this_cpu = skb_queue_len(&sk->sk_receive_queue); log->op = opcode; log->seq = nph->seq; log->ack = nph->ack; log->win = nph->win; log->nxtsnd = npo->nxtsnd; log->nxtrcv = npo->nxtrcv; log->nxtack = npo->lastack; log->cpuid = this_cpu; log->jiffies = jiffies; lognext += 1; if (lognext == LOGRECS) lognext = 0; cop_unlock(&npo->cop_loglock, LOGLOCK); // printk("unlocked log \n"); } /**/ /* Character device open entry point */ int cop_openlog( struct inode *inode, struct file *fp) { printk("cop log opened \n"); return(0); } /**/ /* Character device release */ int cop_releaselog( struct inode *inode, struct file *fp) { printk("cop log closed \n"); return(0); } /**/ /* Character device ioctl entry point */ int cop_ioctl( struct inode *inode, struct file *fp, unsigned int func_code, unsigned long arg) { unsigned int *word; int rc; int n; word = (unsigned int *)arg; printk("cop_ioctl: code %d \n", func_code); switch(func_code) { default: n = copy_to_user(word, cop_log, lognext * sizeof(phdrlog_t)); rc = lognext * sizeof(phdrlog_t); printk("cop_ioctl: copied %d \n", lognext); lognext = 0; return(rc); break; } return(0); }