📄 inet.c
字号:
/***************************************************************************** @(#) inet.c,v LiS-2_16_18-8(1.1.4.5) 2004/02/29 01:44:41 ----------------------------------------------------------------------------- Copyright (c) 2001-2004 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). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee. See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2004/02/29 01:44:41 by brian *****************************************************************************/#ident "@(#) inet.c,v LiS-2_16_18-8(1.1.4.5) 2004/02/29 01:44:41"static char const ident[] = "inet.c,v LiS-2_16_18-8(1.1.4.5) 2004/02/29 01:44:41";/* * This driver provides the functionality of IP (Internet Protocol) over a * connectionless network provider (NPI). It provides a STREAMS-based * encapsulation of the Linux IP stack. */#include <linux/config.h>#include <linux/version.h>#ifdef CONFIG_MODVERSIONS#include <linux/modversions.h>#endif#include <linux/module.h>#include <linux/net.h>#include <linux/in.h>#include <linux/un.h>#include <linux/ip.h>#include <net/sock.h>#include <net/tcp.h>#ifdef HAVE_TCP_OPENREQ_CACHEP_ADDR#include <linux/slab.h>static kmem_cache_t **const _tcp_openreq_cachep_location = (kmem_cache_t **) (HAVE_TCP_OPENREQ_CACHEP_ADDR);#undef tcp_openreq_cachep#define tcp_openreq_cachep (*_tcp_openreq_cachep_location)#endif#include <sys/stream.h>#include <sys/cmn_err.h>#include <sys/tihdr.h>// #include <xti.h>#include <xti_inet.h>#undef CONFIG_SCTP#undef CONFIG_SCTP_MODULE#define LINUX_2_4 1#if defined CONFIG_SCTP || defined CONFIG_SCTP_MODULE#include <netinet/sctp.h>#endif#include "debug.h"#include "bufq.h"#define SS_DESCRIP "UNIX SYSTEM V RELEASE 4.2 FAST STREAMS FOR LINUX"#define SS_COPYRIGHT "Copyright (c) 1997-2004 OpenSS7 Corporation. All Rights Reserved."#define SS_REVISION "LfS inet.c,v LiS-2_16_18-8(1.1.4.5) 2004/02/29 01:44:41"#define SS_DEVICE "SVR 4.2 STREAMS INET Drivers (NET4)"#define SS_CONTACT "Brian Bidulock <bidulock@openss7.org>"#define SS_LICENSE "GPL"#define SS_BANNER SS_DESCRIP "\n" \ SS_COPYRIGHT "\n" \ SS_REVISION "\n" \ SS_DEVICE "\n" \ SS_CONTACT "\n"#define SS_SPLASH SS_DEVICE " - " \ SS_REVISION "\n"MODULE_AUTHOR(SS_CONTACT);MODULE_DESCRIPTION(SS_DESCRIP);MODULE_SUPPORTED_DEVICE(SS_DEVICE);MODULE_LICENSE(SS_LICENSE);#ifndef SS_MOD_NAME# ifdef CONFIG_STREAMS_INET_NAME# define SS_MOD_NAME CONFIG_STREAMS_INET_NAME# else# define SS_MOD_NAME "inet"# endif#endif#ifndef SS_CMAJOR# ifdef CONFIG_STREAMS_INET_MAJOR# define SS_CMAJOR CONFIG_STREAMS_INET_MAJOR# else# define SS_CMAJOR 30# endif#endifstatic unsigned short major = SS_CMAJOR;MODULE_PARM(major, "b");MODULE_PARM_DESC(major, "Major device number for STREAMS NET4 driver (0 for allocation).");#ifndef SS_CMAJOR#define SS_CMAJOR 30#endif#define IP_CMINOR 32#define FIRST_CMINOR 33#define ICMP_CMINOR 33#define GGP_CMINOR 34#define IPIP_CMINOR 35#define TCP_CMINOR 36#define EGP_CMINOR 37#define PUP_CMINOR 38#define UDP_CMINOR 39#define IDP_CMINOR 40#define RAWIP_CMINOR 41#define TICOTS_ORD_CMINOR 42#define TICOTS_CMINOR 43#define TICLTS_CMINOR 44#define LAST_CMINOR 44#define FREE_CMINOR 50#ifndef SS_NMAJOR#define SS_NMAJOR 4#define SS_NMINOR 256#endif/* * ========================================================================= * * STREAMS Definitions * * ========================================================================= */STATIC struct module_info ss_minfo = { mi_idnum:SS_CMAJOR, /* Module ID number */ mi_idname:SS_MOD_NAME, /* Module name */ mi_minpsz:0, /* Min packet size accepted */ mi_maxpsz:INFPSZ, /* Max packet size accepted */ mi_hiwat:1 << 15, /* Hi water mark */ mi_lowat:1 << 10 /* Lo water mark */};STATIC int ss_open(queue_t *, dev_t *, int, int, cred_t *);STATIC int ss_close(queue_t *, int, cred_t *);STATIC int ss_rput(queue_t *, mblk_t *);STATIC int ss_rsrv(queue_t *);STATIC struct qinit ss_rinit = { qi_putp:ss_rput, /* Read put (msg from below) */ qi_srvp:ss_rsrv, /* Read queue service */ qi_qopen:ss_open, /* Each open */ qi_qclose:ss_close, /* Last close */ qi_minfo:&ss_minfo, /* Information */};STATIC int ss_wput(queue_t *, mblk_t *);STATIC int ss_wsrv(queue_t *);STATIC struct qinit ss_winit = { qi_putp:ss_wput, /* Write put (msg from above) */ qi_srvp:ss_wsrv, /* Write queue service */ qi_minfo:&ss_minfo, /* Information */};STATIC struct streamtab ss_info = { st_rdinit:&ss_rinit, /* Upper read queue */ st_wrinit:&ss_winit, /* Lower read queue */};/* * Queue put and service return values */#define QR_DONE 0#define QR_ABSORBED 1#define QR_TRIMMED 2#define QR_LOOP 3#define QR_PASSALONG 4#define QR_PASSFLOW 5#define QR_DISABLE 6#define QR_STRIP 7/* * TLI interface state flags */#define TSF_UNBND ( 1 << TS_UNBND )#define TSF_WACK_BREQ ( 1 << TS_WACK_BREQ )#define TSF_WACK_UREQ ( 1 << TS_WACK_UREQ )#define TSF_IDLE ( 1 << TS_IDLE )#ifdef TS_WACK_OPTREQ#define TSF_WACK_OPTREQ ( 1 << TS_WACK_OPTREQ )#endif#define TSF_WACK_CREQ ( 1 << TS_WACK_CREQ )#define TSF_WCON_CREQ ( 1 << TS_WCON_CREQ )#define TSF_WRES_CIND ( 1 << TS_WRES_CIND )#define TSF_WACK_CRES ( 1 << TS_WACK_CRES )#define TSF_DATA_XFER ( 1 << TS_DATA_XFER )#define TSF_WIND_ORDREL ( 1 << TS_WIND_ORDREL )#define TSF_WREQ_ORDREL ( 1 << TS_WREQ_ORDREL )#define TSF_WACK_DREQ6 ( 1 << TS_WACK_DREQ6 )#define TSF_WACK_DREQ7 ( 1 << TS_WACK_DREQ7 )#define TSF_WACK_DREQ9 ( 1 << TS_WACK_DREQ9 )#define TSF_WACK_DREQ10 ( 1 << TS_WACK_DREQ10 )#define TSF_WACK_DREQ11 ( 1 << TS_WACK_DREQ11 )#define TSF_NOSTATES ( 1 << TS_NOSTATES )#define TSM_WACK_DREQ (TSF_WACK_DREQ6 \ |TSF_WACK_DREQ7 \ |TSF_WACK_DREQ9 \ |TSF_WACK_DREQ10 \ |TSF_WACK_DREQ11)#define TSM_LISTEN (TSF_IDLE \ |TSF_WRES_CIND)#define TSM_CONNECTED (TSF_WCON_CREQ\ |TSF_WRES_CIND\ |TSF_DATA_XFER\ |TSF_WIND_ORDREL\ |TSF_WREQ_ORDREL)#define TSM_DISCONN (TSF_IDLE\ |TSF_UNBND)#define TSM_INDATA (TSF_DATA_XFER\ |TSF_WIND_ORDREL)#define TSM_OUTDATA (TSF_DATA_XFER\ |TSF_WREQ_ORDREL)#ifndef T_PROVIDER#define T_PROVIDER 0#define T_USER 1#endif/* * Socket state masks *//* * TCP state masks */#define TCPM_CLOSING (TCPF_CLOSE\ |TCPF_TIME_WAIT\ |TCPF_CLOSE_WAIT)#define TCPM_CONNIND (TCPF_SYN_RECV\ |TCPF_ESTABLISHED\ |TCPF_LISTEN)/* * ========================================================================= * * IP Private Datastructures * * ========================================================================= */typedef struct ss_dflt { struct ip_options opt; /* T_IP_OPTIONS */ ulong tos; /* T_IP_TOS */ ulong ttl; /* T_IP_TTL */ ulong reuse; /* T_IP_REUSE_ADDR */ ulong norte; /* T_IP_DONTROUTE */ ulong bcast; /* T_IP_BROADCAST */ ulong nodly; /* T_TCP_NODELAY, T_SCTP_NODELAY */ ulong mss; /* T_TCP_MAXSEG */ ulong alive; /* T_TCP_KEEPALIVE */ ulong csum; /* T_UDP_CHECKSUM */#if defined CONFIG_SCTP || defined CONFIG_SCTP_MODULE ulong cork; /* T_SCTP_CORK */ ulong ppi; /* T_SCTP_PPI */ ulong sid; /* T_SCTP_SID */ ulong ssn; /* T_SCTP_SSN */ ulong tsn; /* T_SCTP_TSN */ ulong recvopt; /* T_SCTP_RECVOPT */ ulong clife; /* T_SCTP_COOKIE_LIFE */ ulong sack; /* T_SCTP_SACK_DELAY */ ulong prtx; /* T_SCTP_PATH_MAX_RETRANS */ ulong artx; /* T_SCTP_ASSOC_MAX_RETRANS */ ulong irtx; /* T_SCTP_MAX_INIT_RETRIES */ ulong hitvl; /* T_SCTP_HEARTBEAT_ITVL */ ulong rtoinit; /* T_SCTP_RTO_INITIAL */ ulong rtomin; /* T_SCTP_RTO_MIN */ ulong rtomax; /* T_SCTP_RTO_MAX */ ulong ostr; /* T_SCTP_OSTREAMS */ ulong istr; /* T_SCTP_ISTREAMS */ ulong cinc; /* T_SCTP_COOKIE_INC */ ulong titvl; /* T_SCTP_THROTTLE_ITVL */ ulong mac; /* T_SCTP_MAC_TYPE */#endif} ss_dflt_t;typedef struct ss_profile { struct { uint family; uint type; uint protocol; } prot; struct T_info_ack info;} ss_profile_t;typedef struct ss_protocol { struct ss_protocol *next; /* list linkage */ struct ss_protocol **prev; /* list linkage */ atomic_t refcnt; /* reference count */ lis_spin_lock_t lock; /* structure lock */ void (*put) (struct ss_protocol *); /* release function */ struct ss_protocol *(*get) (struct ss_protocol *); /* acquire function */ ulong type; /* structure type */ ulong id; /* structure id */ ulong state; /* state */ ulong flags; /* flags */ int ps_family; int ps_type; int ps_protocol; dev_t ps_dev; int ps_flags;} ss_protocol_t;struct ss_protocol *ss_protosw = NULL;typedef struct inet { struct inet *next; /* list of all IP-Users */ struct inet **prev; /* list of all IP-Users */ size_t refcnt; /* structure reference count */ lis_spin_lock_t lock; /* structure lock */ ushort cmajor; /* major device number */ ushort cminor; /* minor device number */ queue_t *rq; /* associated read queue */ queue_t *wq; /* associated write queue */ cred_t cred; /* credientials */ lis_spin_lock_t qlock; /* queue lock */ queue_t *rwait; /* RD queue waiting on lock */ queue_t *wwait; /* WR queue waiting on lock */ uint rbid; /* RD buffer call id */ uint wbid; /* WR buffer call id */ int ioc_state; /* transparent ioctl state */ ushort port; /* port/protocol number */ int tcp_state; /* tcp state history */ ss_profile_t p; /* protocol profile */ struct { void (*state_change) (struct sock *); void (*data_ready) (struct sock *, int); void (*write_space) (struct sock *); void (*error_report) (struct sock *); } cb_save; /* call back holder */ struct sockaddr src; /* bound address */ struct sockaddr dst; /* connected address */ ss_dflt_t options; /* protocol options */ unsigned char _pad[40]; /* pad for options */ bufq_t conq; /* connection queue */ uint conind; /* number of connection indications */ struct socket *sock; /* socket pointer */} ss_t;#define PRIV(__q) ((ss_t *)((__q)->q_ptr))#define SOCK_PRIV(__sk) ((ss_t *)(__sk)->user_data)typedef struct ss_opts { uint flags; /* success flags */ struct ip_options *opt; /* T_IP_OPTIONS */ ulong *tos; /* T_IP_TOS */ ulong *ttl; /* T_IP_TTL */ ulong *reuse; /* T_IP_REUSE_ADDR */ ulong *norte; /* T_IP_DONTROUTE */ ulong *bcast; /* T_IP_BROADCAST */ ulong *nodly; /* T_TCP_NODELAY, T_SCTP_NODELAY */ ulong *mss; /* T_TCP_MAXSEG */ ulong *alive; /* T_TCP_KEEPALIVE */ ulong *csum; /* T_UDP_CHECKSUM */ ulong *ropt; struct in_pktinfo *pkinfo;#if defined CONFIG_SCTP || defined CONFIG_SCTP_MODULE ulong *cork; /* T_SCTP_CORK */ ulong *ppi; /* T_SCTP_PPI */ ulong *sid; /* T_SCTP_SID */ ulong *ssn; /* T_SCTP_SSN */ ulong *tsn; /* T_SCTP_TSN */ ulong *recvopt; /* T_SCTP_RECVOPT */ ulong *clife; /* T_SCTP_COOKIE_LIFE */ ulong *sack; /* T_SCTP_SACK_DELAY */ ulong *prtx; /* T_SCTP_PATH_MAX_RETRANS */ ulong *artx; /* T_SCTP_ASSOC_MAX_RETRANS */ ulong *irtx; /* T_SCTP_MAX_INIT_RETRIES */ ulong *hitvl; /* T_SCTP_HEARTBEAT_ITVL */ ulong *rtoinit; /* T_SCTP_RTO_INITIAL */ ulong *rtomin; /* T_SCTP_RTO_MIN */ ulong *rtomax; /* T_SCTP_RTO_MAX */ ulong *ostr; /* T_SCTP_OSTREAMS */ ulong *istr; /* T_SCTP_ISTREAMS */ ulong *cinc; /* T_SCTP_COOKIE_INC */ ulong *titvl; /* T_SCTP_THROTTLE_ITVL */ ulong *mac; /* T_SCTP_MAC_TYPE */ struct t_sctp_hb *hb; /* T_SCTP_HB */ struct t_sctp_rto *rto; /* T_SCTP_RTO */ struct t_sctp_status *stat; /* T_SCTP_STATUS */ ulong *debug; /* T_SCTP_DEBUG */#endif} ss_opts_t;#define ip_default_opt { 0, }#define ip_default_tos 1#define ip_default_ttl 64#define ip_default_reuse 1#define ip_default_norte 1#define ip_default_bcast 1#define tcp_default_nodly 1#define tcp_default_mss 576#define tcp_default_alive 1#define udp_default_csum 0#define TF_IP_OPTIONS (1<< 0)#define TF_IP_TOS (1<< 1)#define TF_IP_TTL (1<< 2)#define TF_IP_REUSEADDR (1<< 3)#define TF_IP_DONTROUTE (1<< 4)#define TF_IP_BROADCAST (1<< 5)#define TF_IP_PKTINFO (1<< 6)#define TF_IP_RETOPTS (1<< 7)#define TF_TCP_NODELAY (1<< 8)#define TF_TCP_MAXSEG (1<< 9)#define TF_TCP_KEEPALIVE (1<<10)#define TF_UDP_CHECKSUM (1<<11)#if defined CONFIG_SCTP || defined CONFIG_SCTP_MODULE#define TF_SCTP_NODELAY TF_TCP_NODELAY#define TF_SCTP_MAXSEG TF_TCP_MAXSEG#define TF_SCTP_CORK (1<<10)#define TF_SCTP_PPI (1<<11)#define TF_SCTP_SID (1<<12)#define TF_SCTP_SSN (1<<13)#define TF_SCTP_TSN (1<<14)#define TF_SCTP_RECVOPT (1<<15)#define TF_SCTP_COOKIE_LIFE (1<<16)#define TF_SCTP_SACK_DELAY (1<<17)#define TF_SCTP_MAX_RETRANS (1<<18)#define TF_SCTP_ASSOC_MAX_RETRANS (1<<19)#define TF_SCTP_MAX_INIT_RETRIES (1<<20)#define TF_SCTP_HEARTBEAT_ITVL (1<<21)#define TF_SCTP_RTO_INITIAL (1<<22)#define TF_SCTP_RTO_MIN (1<<23)#define TF_SCTP_RTO_MAX (1<<24)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -