All pastes #459632 Raw Edit

Someone

public c v1 · immutable
#459632 ·published 2007-04-26 16:26 UTC
rendered paste body
#include <sys/types.h>#include <sys/param.h>#include <sys/proc.h>#include <sys/module.h>#include <sys/sysent.h>#include <sys/sysproto.h>#include <sys/kernel.h>#include <sys/systm.h>#include <sys/malloc.h>#include <sys/protosw.h>#include <sys/domain.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp_var.h>struct crpc_load_args {    unsigned long int *rlist;    int size;    int mode;};int crpc_load(struct thread *,register struct crpc_load_args *);struct crpc_list {    unsigned long int *rlist;    int cnt;    struct crpc_list *next;};static struct crpc_list *serv_cl=NULL,                        *clnt_cl=NULL;//static unsigned long int crpc_cnt=0;MALLOC_DECLARE(M_CRPC);MALLOC_DEFINE(M_CRPC,"crpc","CRPC checksum list");int crpc_load(struct thread * th,struct crpc_load_args *uap) {    struct crpc_list *cur;        if(uap->mode>1 || !uap->size || !uap->rlist)        return -1;        if((cur=(struct crpc_list *)malloc       (sizeof(struct crpc_list),M_CRPC,M_NOWAIT))==NULL) {        uprintf("malloc()");        return -1;    }    if((cur->rlist=(unsigned long int *)malloc       (uap->size,M_CRPC,M_NOWAIT))==NULL) {        uprintf("malloc()");        return -1;    }    if(copyin(uap->rlist,cur->rlist,uap->size)==EFAULT) {        uprintf("copyin()");        return -1;    }    cur->cnt=uap->size/sizeof(unsigned int long);        if(!uap->mode) {        serv_cl=cur;        //--        clnt_cl=serv_cl;        //--    } else {        clnt_cl=cur;    }        return 0;}#define AS(name) (sizeof(struct name)/sizeof(register_t))int	crpc_send(struct thread *,register struct sendto_args *);int	crpc_recv(struct thread *,register struct recvfrom_args *);int	crpc_send(struct thread *td,register struct sendto_args *uap) {    //int i;    //unsigned int long req;        if(clnt_cl) {        /*if(copyin(uap->buf,&req,sizeof(unsigned long))==EFAULT) {            uprintf("copyin()");            return -1;        }        uprintf("%lu ",req);        if(req) {            for(i=0;i<clnt_cl->cnt;i++) {                if(req==clnt_cl->rlist[i]) {                    i=-1;                    break;                }            }            if(i>=0)                return -1;        } else {            if(uap->len!=8)                return -1;        }*/        return(sendto(td,uap));    } else {        return -1;    }}int	crpc_recv(struct thread *td,register struct recvfrom_args *uap) {    int error;    error=recvfrom(td,uap);        return error;}static struct sysent crpc_load_sysent = {	3,	(sy_call_t *)crpc_load};static struct sysent crpc_send_sysent = {	AS(sendto_args),	(sy_call_t *)crpc_send};static struct sysent crpc_recv_sysent = {	AS(recvfrom_args),	(sy_call_t *)crpc_recv};static int load (struct module *module, int cmd, void *offt) {	int error=0;    int *iofft;    iofft=offt;        switch (cmd) {	case MOD_LOAD :		uprintf ("syscall loaded at %d\n",*iofft);		break;	case MOD_UNLOAD :		uprintf ("syscall unloaded from %d\n",*iofft);		break;	default :		error = EOPNOTSUPP;		break;	}	return error;}static int offset=210;SYSCALL_MODULE(crpc_load,&offset,&crpc_load_sysent,load,&offset);static int offset1=211;SYSCALL_MODULE(crpc_send,&offset1,&crpc_send_sysent,load,&offset1);static int offset2=212;SYSCALL_MODULE(crpc_recv,&offset2,&crpc_recv_sysent,load,&offset2);