⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_udp.c

📁 No7信令,我需要交换类似的代码, 请店长审核,谢谢了,急着交换,谢谢
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** @(#) sdl_udp.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:47 ----------------------------------------------------------------------------- Copyright (c) 2001  OpenSS7 Corporation <http://www.openss7.com> Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@dallas.net> All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you.  If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users).  If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any success regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Last Modified 2001/12/11 13:15:47 by brian *****************************************************************************/#ident "@(#) sdl_udp.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:47"static char const ident[] = "sdl_udp.c,v SS7AlphaRelease(0.7.8.1) 2001/12/11 13:15:47";/* *  This is a UDP emulation of the Siganlling Data Link for use in testing and *  experimentation with the SS7 stack.  This driver obviates the need for a *  hardware card for testing the SS7 stack.  This driver is loosely based on *  the draft-bressler-sigtran-ipss7l2-00.txt SIGTRAN draft which specifies *  SS7 over TCP. * *  The UDP emulation behaves in the fashion that an actual driver would *  behave as an SDL provider; however, repetitions of FISUs and LSSUs are not *  transmitted continuously on the UDP link, only the first occurence of the *  repetition is transmitted and another occurence of the repetition is *  transmitted for every change in a received frame from UDP. * *  The UDP emulation can be run at full line (LAN) rate for transfering MSUs; *  however, for line rates below full network rate, traffic shaping is *  performed to throttle transmissions of MSUs to the average simulated rate *  in 10ms (1 tick) bursts. */#include <linux/config.h>#include <linux/version.h>#include <linux/modversions.h>#include <linux/socket.h>#include <net/sock.h>#include <linux/skbuff.h>#include <linux/module.h>#include <sys/stream.h>#include <sys/stropts.h>#include <sys/cmn_err.h>#include <sys/dki.h>#include <linux/errno.h>#include <linux/types.h>#include <linux/in.h>#include <linux/sockios.h>#include <linux/net.h>#include <linux/inet.h>#include <linux/udp.h>#ifndef __inline__#define __inline__ inline#endif#include "../debug.h"#include "../bufq.h"#include <ss7/lmi.h>#include <ss7/lmi_ioctl.h>#include <ss7/devi.h>#include <ss7/devi_ioctl.h>#include <ss7/sdli.h>#include <ss7/sdli_ioctl.h>#include "../lmi/lm.h"#include "../devi/dev.h"#include "../sdli/sdl.h"#define SDL_DESCRIP	"SS7/SDL/UDP: (Signalling Data Link over UDP) STREAMS DRIVER."#define SDL_COPYRIGHT	"Copyright (c) 1997-2001 Brian Bidulock.  All Rights Reserved."#define SDL_DEVICES	"Supports Linux Kernel UDP sockets."#define SDL_CONTACT	"Brian Bidulock <bidulock@openss7.org>"#define SDL_BANNER	SDL_DESCRIP   "\n" \			SDL_COPYRIGHT "\n" \			SDL_DEVICES   "\n" \			SDL_CONTACT   "\n"#ifdef MODULEMODULE_AUTHOR(SDL_CONTACT);MODULE_DESCRIPTION(SDL_DESCRIP);MODULE_SUPPORTED_DEVICE(SDL_DEVICES);#define MODULE_STATIC static#else#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT#define MODULE_STATIC#endif#ifdef SDL_DEBUGstatic int sdl_debug = SDL_DEBUG;#elsestatic int sdl_debug = 2;#endif#define DEBUG_LEVEL sdl_debug#if 0// #define SDL_MOD_ID		0x1111// #define SDL_MOD_NAME		"sdl_udp"// #define SDL_MIN_SDU		3// #define SDL_MAX_SDU		277// #define SDL_HIWATER		1// #define SDL_LOWATER		0#endif#ifndef SDL_UDP_CMAJOR#define SDL_UDP_CMAJOR	252 /* FIXNE: pick something    */#endif#define SDL_UDP_NMINOR	255 /* as many as possible      */typedef struct {	struct dev		dev;		/* device structure	*/	struct sockaddr_in	loc_addr;	/* local  ip/port	*/	struct sockaddr_in	rem_addr;	/* remote ip/port	*/	struct socket		*udpsock;	/* UDP socket		*/	signed long int		timestamp;	/* last tick		*/	signed long int		tickbytes;	/* bytes per tick	*/	signed long int		bytecount;	/* bytes this tick	*/	struct timer_list	wakeup;		/* wakeup timer		*/	bufq_t			txq;		/* transmit queue	*/} sdl_udpdev_t;/* *  ========================================= * *  DEVICE SPECIFIC Procedures * *  ========================================= *//* *  ----------------------------------------- * *  IOCTL * *  ----------------------------------------- */static int sdl_udp_ioctl(lmi_t *sdl, int cmd, void *arg){	size_t size = _IOC_SIZE(cmd);	sdl_udpdev_t *udp = (sdl_udpdev_t *)sdl->device;	sdl_config_t *ureq = NULL;	sdl_ulong uarg = 0;	switch (cmd)	{		case SDL_IOCTCONFIG:		case SDL_IOCSCONFIG:			if ( !arg || size < sizeof(dev_device_t) )				return EINVAL;			ureq = arg;			break;		case DEV_IOCGIFFLAGS:		case DEV_IOCGIFTYPE:		case DEV_IOCGGRPTYPE:		case DEV_IOCGIFMODE:		case DEV_IOCGIFRATE:		case DEV_IOCGIFCLOCK:		case DEV_IOCGIFCODING:		case DEV_IOCGIFLEADS:		case DEV_IOCSIFFLAGS:		case DEV_IOCSIFTYPE:		case DEV_IOCSGRPTYPE:		case DEV_IOCSIFMODE:		case DEV_IOCSIFRATE:		case DEV_IOCSIFCLOCK:		case DEV_IOCSIFCODING:		case DEV_IOCSIFLEADS:		case DEV_IOCCIFLEADS:			if ( !arg || size < sizeof(dev_ulong) )				return EINVAL;			uarg = *(dev_ulong *)arg;			break;		case SDL_IOCCCONFIG:		case SDL_IOCCMRESET:		case DEV_IOCCIFRESET:		case DEV_IOCCDISCTX:		case DEV_IOCCCONNTX:			break;	}	switch (cmd)	{		case SDL_IOCTCONFIG:		case SDL_IOCSCONFIG:		case SDL_IOCCCONFIG:		case SDL_IOCCMRESET:		case DEV_IOCCIFRESET:			break;		case DEV_IOCGIFFLAGS:			*(dev_ulong *)arg = udp->dev.iface.ifflags;			return(0);		case DEV_IOCGIFTYPE:			*(dev_ulong *)arg = udp->dev.iface.iftype;			return(0);		case DEV_IOCGGRPTYPE:			*(dev_ulong *)arg = udp->dev.iface.ifgtype;			return(0);		case DEV_IOCGIFMODE:			*(dev_ulong *)arg = udp->dev.iface.ifmode;			return(0);		case DEV_IOCGIFRATE:			*(dev_ulong *)arg = udp->dev.iface.ifrate;			return(0);		case DEV_IOCGIFCLOCK:			*(dev_ulong *)arg = udp->dev.iface.ifclock;			return(0);		case DEV_IOCGIFCODING:			*(dev_ulong *)arg = udp->dev.iface.ifcoding;			return(0);		case DEV_IOCGIFLEADS:			*(dev_ulong *)arg = udp->dev.iface.ifleads;			return(0);		case DEV_IOCSIFFLAGS:			udp->dev.iface.ifflags = uarg;			return(0);		case DEV_IOCSIFTYPE:			if ( uarg != DEV_TYPE_PACKET )				return EINVAL;			return(0);		case DEV_IOCSGRPTYPE:			if ( uarg != DEV_GTYPE_UDP )				return EINVAL;			return(0);		case DEV_IOCSIFMODE:			if ( uarg != DEV_MODE_PEER )				return EINVAL;			return(0);		case DEV_IOCSIFRATE:		{			int tdiff;			if ( uarg < 800L || uarg > 100000000L )				return EINVAL;			udp->dev.iface.ifrate = uarg;			if ( (tdiff = udp->timestamp - jiffies) > 0 )				udp->bytecount += udp->tickbytes * tdiff;			else				udp->bytecount = 0;			udp->timestamp = jiffies;			udp->tickbytes = uarg/HZ/8;			while ( udp->bytecount >= udp->tickbytes )			{				udp->bytecount -= udp->tickbytes;				udp->timestamp++;			}			return(0);		}		case DEV_IOCSIFCLOCK:			if ( uarg != DEV_CLOCK_SHAPER &&					uarg != DEV_CLOCK_TICK)				return EINVAL;			udp->dev.iface.ifclock = uarg;			return(0);		case DEV_IOCSIFCODING:			if ( uarg != DEV_CODING_NONE )				return EINVAL;			return(0);		case DEV_IOCSIFLEADS:		case DEV_IOCCIFLEADS:			if ( uarg )				return EINVAL;			return(0);		case DEV_IOCCDISCTX:			udp->dev.iface.ifflags &= ~DEV_IF_TX_RUNNING;			bufq_purge(&udp->txq);			return(0);		case DEV_IOCCCONNTX:			udp->dev.iface.ifflags |= DEV_IF_TX_RUNNING;			return(0);	}	return EOPNOTSUPP;}static dev_device_t dev_udpdev_default ={	{ },			/* iflock	*/	0,			/* ifflags	*/	DEV_TYPE_PACKET,	/* iftype	*/	DEV_GTYPE_UDP,		/* ifgtype	*/	DEV_MODE_PEER,		/* ifmode	*/	64000,			/* ifrate	*/	DEV_CLOCK_SHAPER,	/* ifclock	*/	DEV_CODING_NONE,	/* ifcoding	*/};static void sdl_udp_send(struct dev *dev);static lmi_t *sdl_udp_devatt(dev_t dev){	sdl_udpdev_t *udp;	if ( (udp = kmalloc(sizeof(sdl_udpdev_t), GFP_KERNEL)) )	{		MOD_INC_USE_COUNT;		bzero(udp, sizeof(*udp));		bcopy(&dev_udpdev_default, &udp->dev.iface, sizeof(udp->dev.iface));		udp->timestamp = jiffies;		udp->tickbytes = 1544000/HZ/8;		udp->bytecount = 0;		bufq_init(&udp->txq);		init_timer(&udp->wakeup);		udp->wakeup.data = (unsigned long)udp;		udp->wakeup.function = (void (*)(unsigned long))&sdl_udp_send;		return((lmi_t *)udp);	}	return NULL;}static intsdl_udp_open(lmi_t *lmi){	return(0);  /* can't open yet, no address */}static intsdl_udp_close(lmi_t *lmi){	sdl_udpdev_t *udp = (sdl_udpdev_t *)lmi;	bufq_purge(&udp->txq);	del_timer(&udp->wakeup);	kfree(udp);	MOD_DEC_USE_COUNT;	return(0);}static intsdl_udp_infor(lmi_t *lmi, void **ppap, int *lenp){	sdl_udpdev_t *udp = (sdl_udpdev_t *)lmi;	size_t count = 2*sizeof(struct sockaddr_in);	ensure( udp, return EINVAL );	*ppap = &udp->loc_addr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -