📄 m.h
字号:
/** Copyright (c) 1998-2001 by NETsilicon Inc.** This software is copyrighted by and is the sole property of* NETsilicon. All rights, title, ownership, or other interests* in the software remain the property of NETsilicon. This* software may only be used in accordance with the corresponding* license agreement. Any unauthorized use, duplication, transmission,* distribution, or disclosure of this software is expressly forbidden.** This Copyright notice may not be removed or modified without prior* written consent of NETsilicon.** NETsilicon, reserves the right to modify this software* without notice.** NETsilicon* 411 Waverley Oaks Road USA 781.647.1234* Suite 227 http://www.netsilicon.com* Waltham, MA 02452 AmericaSales@netsilicon.com*************************************************************************** $Name: Fusion 6.52 Fusion 6.51 $* $Date: 2001/09/20 10:19:21 $* $Source: M:/psisrc/stack/incl/rcs/m.h $* $Revision: 1.21 $*************************************************************************** File Description: Definitions and Macros for dealing with the* `Message' structure**************************************************************************/#ifndef _M_#define _M_#include "config.h"#include "ccdep.h"#include "q.h"#include "std.h"#include "timer.h"#include "socket.h"#include "dsu.h"/* flags for m.m_flags */#define F_M_SELF (u16)0x0001 /* m is destined for this host */#define F_M_CLONE (u16)0x0002 /* m is cloned; don't clone again */#define F_M_EVEN (u16)0x0004 /* data must be even size, compensate */#define F_M_ORIGIN (u16)0x0008 /* packet is from this host */#define F_M_ONCE (u16)0x0010 /* packet went through something once */#define F_M_FORCE (u16)0x0020 /* packet must make it into a queue */#define F_M_ZAP (u16)0x0040 /* to be unlocked soon */#define F_M_STAY_LOCKED (u16)0x0080 /* tell s.m. not to unlock when done */#define F_M_MSM (u16)0x0100 /* currently being driven by s.m. */#define F_M_CRITICAL (u16)0x0200 /* this msg is CRITICAL now */#define F_M_URGENT (u16)0x0400 /* m contains urgent data */#define F_M_BCAST (u16)0x0800 /* m contains broadcast destination */#define F_M_MULTI (u16)0x1000 /* m contains multicast destination *//* values above must not conflict w/ F_COMM_MASK *//* Note from MM: F_COMM_MASK is defined in flags.h as: F_BS_MASK | F_FDBROADCAST F_BS_MASK is defined in flags.h as: F_BLOCKING | F_NONBLOCKING F_FDBROADCAST is defined in flags.h as: MSG_FDBROADCAST F_BLOCKING, F_NONBLOCKING are defined in flags.h as: MSG_BLOCKING, MSG_NONBLOCKING MSG_FDBROADCAST, MSG_BLOCKING, and MSG_NONBLOCKING are defined in socket.h as: 0x2000, 0x8000, 0x4000 So, that seems to use up all of the remaining bits of mm.m_flags. So, I created a new field, mm.m_flags2, because I needed more bits.*//* flags for m.m_flags2 */#define F_M_2_MCASTLOOP (u16)0x0001 /* This is a multicast packet which should be looped back as well as transmitted */#define F_M_2_ON_NDQ_QUEUE (u16) 0x0002 /* NDQ has put this message on one of its queues. For use by TCP sqxmit message disposition functions *//* flags for m_driver_flags added 1/00 RS*/#define M_DRIVER_LOCKED 0x0001 /* m buffer locked in memory by driver */#define M_DRIVER_FREE 0x0002 /* m buffer free *//* mask for messages which are 'm_dup'ed to inherit from original */#define F_M_DUP_MASK (F_M_SELF|F_M_CLONE|F_M_EVEN|F_M_ORIGIN|F_M_URGENT|F_M_BCAST)typedef struct tmq { /* timed message queues (router, ARP) */ q tmq_q; /* the message queue */ int tmq_timeouterr; /* error number to issue on timeout */ tcb tmq_tcb; /* timer control block */} tmq;/* internal message structure *//* rearranged; 'mm_dispfn' and 'mm_histi' moved to the end of the * structure to make it easier to parse dumped structures */typedef struct mm { /* mini-message */ q mm_q; /* for data queues (rq,sq,cq,hq) */ struct gq * mm_gqp; /* pointer to queue head */ q mm_mq; /* for temporary queues (router,ARP) */ q mm_wq; /* message work q */ u16 mm_flags; u16 mm_flags2; /* ran out of bits in mm_flags */ u16 mm_savpri; /* old priority if we're critical */ i16 mm_err; /* error status */ u32 mm_udsize; /* message data size (for q count) */ u32 mm_ctime; /* creation time */ u32 mm_p0; /* general parameter use */ u32 mm_p1; u32 mm_p2; union { u32 mm_up3; st (*mm_qdfn)(struct m *); } mm_p3; u32 mm_p4; u32 mm_p5; st (*mm_job)(struct m *); /* first state of this work message */ st (*mm_dispfn)(struct m *); /* function to put it away */ int (*mm_termfn)(struct m *); /* This pointer is checked by m_free() right before it calls h_free() on the message. If it is non-NULL then it executes the function which must return true (1) if the message should be h_free'd and false(0) if the message should not. This allows for a driver or other protocol layer to manage its own heap of pre-allocated buffers (Fast UDP Sockets, for example). */ u32 mm_cookie; /* Just another general purpose field that a special mm_termfn might want to use for example. Looks like all the rest (mm_p0, p1, etc.) are already used for various purposes. */#ifdef M_HISTORY#define MAXHIST 24 /* Must be multiple of 4 to maintain alignment */ u8 mm_histt[MAXHIST]; /* history type array */ union { /* remembered state history array */ st (*mmh_fn)(struct m *); /* state function called */ u32 mmh_u32; /* stuff stored by function */ } mmh[MAXHIST]; u16 mm_zhist; /* lost history counter */ u16 mm_histi; /* next available history index */#endif int mm_owners; /* keep track of OSPF ownership */} mm;#ifdef M_HISTORY#define mm_fn(i) mmh[i].mmh_fn#define mm_u32(i) mmh[i].mmh_u32#define mm_hist mm_u32#endif/* rearranged; please try to keep things which are short and important * to the front to promote readability of dumps */typedef struct m { /* a real message */ mm m_mm; /* mini-message at the beginning */ char * m_hp; /* head pointer to trimmed data */ char * m_cp; /* place holder for protocols */ char * m_phdr; /* protocol header */ char * m_tp; /* tail pointer to trimmed data */ u32 m_type; /* used by protocol level layers */ u32 m_phlen; /* protocol header length */ u16 m_pflags; /* protocol flags */ u32 m_driver_flags; /* driver specific flags added 1/00 RS */ u16 m_soindx; /* socket index (for validation) */ struct so_t * m_sop; /* socket pointer */ struct netdev * m_outndp; /* route ndp */ long int m_cid; /* circuit */ struct netdev * m_ndp; /* device pointer */ struct tcpsv_t * m_svp; /* TCP state vector pointer */ struct secure * m_secp; /* security field pointer */ so_addr m_dest; /* only one allowed */ so_addr m_src; /* other source specified */ u32 m_len; /* Length allocated by m_new for this message */ u32 m_oob; /* Amount of "out-of-band" extracted from this message. For the use of TCP which must extract out-of-band data before the message is queued to the socket's input queue, but must remember how much out-of-band data was extracted for state vector updates */} m;#define stt st(*)(struct m * mp)#define smnil (stt)0/* abbreviations to allow direct naming of mini-message structures */#define m_q m_mm.mm_q#define m_gqp m_mm.mm_gqp#define m_mq m_mm.mm_mq#define m_wq m_mm.mm_wq#define m_flags m_mm.mm_flags#define m_flags2 m_mm.mm_flags2#define m_savpri m_mm.mm_savpri#define m_err m_mm.mm_err#define m_udsize m_mm.mm_udsize#define m_ctime m_mm.mm_ctime#define m_p0 m_mm.mm_p0#define m_p1 m_mm.mm_p1#define m_p2 m_mm.mm_p2#define m_p3 m_mm.mm_p3.mm_up3#define m_qdfn m_mm.mm_p3.mm_qdfn#define m_p4 m_mm.mm_p4#define m_p5 m_mm.mm_p5#define m_job m_mm.mm_job#define m_dispfn m_mm.mm_dispfn#define m_termfn m_mm.mm_termfn #define m_owners m_mm.mm_owners#define m_cookie m_mm.mm_cookie#ifdef M_HISTORY#define m_histt(i) m_mm.mm_histt[i]#define m_fn(i) m_mm.mm_fn(i)#define m_u32(i) m_mm.mm_u32(i)#define m_hist m_u32#define m_zhist m_mm.mm_zhist#define m_histi m_mm.mm_histi#endif/* definitions of local usage of m_pX side car variables; * declare them here *//* within ICMP */#define m_icmptype m_p0 /* passed to 'icmp_dink'; router conflict */#define m_icmpcode m_p1 /* passed to 'icmp_dink'; router conflict */#define m_icmp1misc m_p2 /* only w/i ICMP */#define m_icmp2misc m_p3 /* only w/i ICMP *//* within IP */#define m_ipbctype m_p2 /* passed to 'ip_dink'; router conflict *//* within the router and ARP (timed queuing) */#define m_qdfn m_mm.mm_p3.mm_qdfn /* p3 used for queued fn */#define m_delay m_p4#define m_resolution m_p5/* between router and protocols */#define m_pfrcode m_p0#define m_pfraf m_p1/** pseudo-functions **//* manipulate 'm' and 'mm' structure fields */#define m_dsize(mp) ((int)((mp)->m_tp - (mp)->m_hp))#define m_empty(mp) ((mp)->m_tp == (mp)->m_hp)#define M_HPTR(mp,type,size) ((type *)((mp)->m_hp -= size))#define m_htrim(mp,size) ((mp)->m_phdr = (mp)->m_hp,(mp)->m_hp += ((mp)->m_phlen = size))#define m_ptr(mp,type) ((type *)((mp)->m_hp))#define m_release(mp) bC2((mp)->m_q.q_flags,F_Q_PRESERVE,F_Q_LOCKED)#define m_tptr(mp,type) ((type *)((mp)->m_tp))#define m_trim(mp,size) ((mp)->m_hp += size)#define is_origin(mp) bT1((mp)->m_flags,F_M_ORIGIN)#define is_remote(mp) bF1((mp)->m_flags,F_M_ORIGIN)export i32 m_ttrim(m * mp);/* get a socket pointer out of the m structure iff the socket still exists */#define valid_sop(mp) ((mp->m_sop && sop_tbl[mp->m_soindx] == mp->m_sop) ? mp->m_sop : (so_t *)0)/* Just to avoid changing every source file for now */#include "msm.h"/* start a work list */#define msm(mp,job) ((mp)->m_job=(job),sm_msm(mp))/* default smdispose if m_dispfn is 0 */#define smkill(mp) ((mp)->m_flags|=F_M_ZAP,msm((mp),((mp)->m_dispfn!=smnil?((mp)->m_dispfn):((mp)->m_dispfn=smdispose))))/* state machine type definitions */#ifndef M_HISTORY#define smfhist(m,f)#define smhprint(m)#define smhzap(m)#define smuhist(m,u)#endif/* timed-queue macros */#define tmq_block(qp,mp,match) (q_empty(qp) ? 0 : _tmq_block(qp, mp, match))import u32 m_extra;/* Macro to use to avoid using the msm state machine. Improves performance a little but uses more stack space. If stack overflow is not a concern, use this macro */#define AVOID_MSM/* This macro gives the size of the space that m_new will allocate, given an input "size" parameter */#ifndef NAT_ROUTER#define M_NEW_ALLOCLEN_FOR_SIZE(sz) ( ((sz + (int)m_extra) & ~(int)m_extra)+sizeof(m))#else#define M_NEW_ALLOCLEN_FOR_SIZE(sz) ( ((sz +(int)m_extra) & ~(int)m_extra)+sizeof(m) + m_growmax)#endif/* Public prototypes */import m * m_dup(m * mp);import void m_initmp(m * mp, u16 bs);import m * m_new(int size, int * errp, u16 bs);#endif /*_M_*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -