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

📄 dhcp_comm.h

📁 wimax bs模拟器
💻 H
📖 第 1 页 / 共 3 页
字号:

struct in_addrs {
	unsigned int num;
	struct in_addr addr[4];
};

struct ip_pairs {
	unsigned int num;
	struct in_addr addr[4];
};

struct chaddr {
	unsigned char htype;
	unsigned char hlen;
	char			haddr [MAX_HLEN];
};

struct relay_acl {
	unsigned int num;
	struct in_addr relay;
	struct in_addr subnet_mask;
};

struct vendor_class_id
{
	unsigned char type;
	unsigned char len;
	char			id[MAXOPT];
};

struct user_class_id
{
	unsigned char type;
	unsigned char len;
	char			id[MAXOPT];
};
	
/*
 * DHCP Resource Related
 */
 
struct dhcp_binding;

#define DHCP_RES_MAGIC0	0xCBEA0036
#define DHCP_RES_MAGIC1	0x0036CBEA

#define DHCP_RES_GOOD(pRes)	(NULL != (pRes) && (pRes)->drMagic0 == DHCP_RES_MAGIC0 && (pRes)->drMagic1 == DHCP_RES_MAGIC1)
#define DHCP_RES_MAGIC_SET(pRes) do {if(NULL !=(pRes)) {(pRes)->drMagic0 = DHCP_RES_MAGIC0;(pRes)->drMagic1 = DHCP_RES_MAGIC1;}}while(0)

#define DHCP_ACT_NULL			0x0		/* NULL state for dhcp resource */
#define DHCP_ACT_PROXY			0x1         /* proxy state for dhcp resource */
#define DHCP_ACT_PROXY_LAP	0x2         /* proxy-lap state for dhcp resource */
#define DHCP_ACT_RELAY			0x3         /* relay state for dhcp resource */

#define DHCP_RES_IS_NULL(pRes) 			(NULL != (pRes) && (pRes)->dhcp_acting == DHCP_ACT_NULL)
#define DHCP_RES_IS_PROXY(pRes) 		(NULL != (pRes) && (pRes)->dhcp_acting == DHCP_ACT_PROXY)
#define DHCP_RES_IS_PROXY_LAP(pRes) 	(NULL != (pRes) && (pRes)->dhcp_acting == DHCP_ACT_PROXY_LAP)
#define DHCP_RES_IS_RELAY(pRes) 		(NULL != (pRes) && (pRes)->dhcp_acting == DHCP_ACT_RELAY)

typedef struct dhcp_resource {
	unsigned int	drMagic0;

	TAILQ_ENTRY(dhcp_resource)		listNode;	/*  chained in free list or binded to 1 binding */

	/* DHCP acting: 1, proxy; 2, proxy lap; 3,relay; */
	unsigned char		dhcp_acting;	
	
	unsigned char 	lap_pool_index;	/* to record lap pool index belong to (differentiate by subnet) */
	
	/* external info */
	char 	//allow_bootp,         /* boolean */
			ip_forward,          /* boolean */
			nonlocal_srcroute,   /* boolean */
			all_subnet_local,    /* boolean */
			mask_discover,       /* boolean */
			mask_supplier,       /* boolean */
			router_discover,     /* boolean */
			trailer,             /* boolean */
			ether_encap,         /* boolean */
			keepalive_garba,     /* boolean */
			//entryname [MAX_NAME + 1],  /* tag name of entry */
			//sname [MAX_SNAME + 1], /* server host name */
			//file [MAX_FILE + 1], /* boot file name */
			hostname [MAXOPT + 1];								/* _DHCP_HOSTNAME_TAG */
			//merit_dump [MAXOPT + 1],
			//dns_domain [MAXOPT + 1];
			//root_path [MAXOPT + 1],
			//extensions_path [MAXOPT + 1],
			//nis_domain [MAXOPT + 1],
			//nb_scope [MAXOPT + 1], /* NetBIOS scope */
			//nisp_domain [MAXOPT + 1]; /* NIS+ domain name */
	
		unsigned char default_ip_ttl,       /* time to live (1 - 255) */
					default_tcp_ttl,
					nb_nodetype;         /* NetBIOS node type */
//#define BNODE   0x1
//#define PNODE   0x2
//#define MNODE   0x4
//#define HNODE   0x8

	unsigned int	//bootsize,            /* bootfile size in 16 bits */
					//max_dgram_size,      /* max dgram reassembly */
					intf_mtu,            /* interface mtu */
					dhcp_t1,             /* host byte order */				/*_DHCP_T1_TAG*/
					dhcp_t2;             /* host byte order */				/*_DHCP_T2_TAG */
	//long                      time_offset;         /* offset from UTC */
	
	unsigned long		max_lease,           /* maximum lease duration	(host byte order) */
					default_lease,       /* default lease duration (host byte order) */
					//mtu_aging_timeout,   /* unsigned 32 bits integer */
					//arp_cache_timeout,
					//keepalive_inter;
					req_lease,
					offer_lease;/* just record offered lease */
					
	//struct u_shorts	mtu_plateau_table;   /* array of 16 bit ints */
	struct in_addr	siaddr,              /* ip of ASN-GW or real Server */		/*_DHCP_SERVER_ID_TAG*/
					ip_addr,             /* IP address to client(yiaddr) */		/* */
					subnet_mask;									/* _DHCP_SUBNET_MASK_TAG*/
					//swap_server,
					//brdcast_addr,
					//router_solicit;
	
	struct in_addrs	router,											/*_DHCP_ROUTER_TAG*/
					//time_server,
					//name_server,
					dns_server;       /* DNS server */					/*_DHCP_DNS_SERVER_TAG*/
					//log_server,
					//cookie_server,
					//lpr_server,
					//impress_server,
					//rls_server,       /* Resource Location Server */
					//nis_server,
					//ntp_server,
					//nbn_server;         /* NetBIOS name server */
					//nbdd_server,     /* NetBIOS dgram distrib server */
					//xfont_server,       /* X font erver */
					//xdisplay_manager,   /* X display manager */
					//nisp_server,        /* NIS+ server */
					//mobileip_ha,        /* Mobile IP Home Agent */
					//smtp_server,        /* SMTP server */
					//pop3_server,        /* POP3 server */
					//nntp_server,        /* NNTP server */
					//dflt_www_server,    /* Default WWW server */
					//dflt_finger_server, /* Default Finger server */
					//dflt_irc_server,    /* Default IRC server */
					//streettalk_server,  /* StreetTalk server */
					//stda_server;        /* STDA server */

	//struct ip_pairs	policy_filter,   
	//				static_route;

	/* internal info */
	char		valid[VALIDSIZE];		 /* indicate which are available */
	//		active[VALIDSIZE];	/* indicate which differ from Host Requirements RFC */
	
	unsigned char reqListFlag;
	char 	reqlist[VALIDSIZE];	/* indicate which tag is requested by client in _DHCP_REQ_LIST_TAG */ 
	
	struct dhcp_binding       *pBinding;	/* pointer to identifier associated with resource.*/
	
	unsigned int	drMagic1;
}St_DhcpRes;

typedef TAILQ_HEAD(DhcpRes_List, dhcp_resource) St_DhcpRes_List;



typedef struct _aep_ue_ctxt
{
	struct dhcp_binding *pDhcpInfo;
}AEP_UE_CTXT;

typedef AEP_UE_CTXT St_AepUeCtxt;

/*
 * DHCP binding related
 */
 
#define DHCP_BINDING_MAGIC0	0xDCBA6768
#define DHCP_BINDING_MAGIC1	0x6768DCBA

#define DHCP_BINDING_GOOD(pDb)	(NULL != (pDb) && (pDb)->dbMagic0 == DHCP_BINDING_MAGIC0 && (pDb)->dbMagic1 == DHCP_BINDING_MAGIC1)
#define DHCP_BINDING_MAGIC_SET(pDb) do {if(NULL !=(pDb)) {(pDb)->dbMagic0 = DHCP_BINDING_MAGIC0; (pDb)->dbMagic1 = DHCP_BINDING_MAGIC1;}}while(0)


/* hash len/key/ind */
#define DHCP_MONITOR_HASH_LEN	10	/* DHCP_TIMER_DURATION * 10 ms,must */
#define DHCP_CID_HASH_LEN			1024	/* must */
#define DHCP_R1_HASH_LEN			1024 /* must */
#define DHCP_HADDR_HASH_LEN		1024 /* must */
#define DHCP_IP_HASH_LEN			1024
#define DHCP_XID_HASH_LEN			64

#define DHCP_BIND_MON_HASHKEY(hashKey)	((hashKey) % DHCP_MONITOR_HASH_LEN)
#define DHCP_BIND_CID_HASHKEY(hashKey)	((hashKey) % DHCP_CID_HASH_LEN)
#define DHCP_BIND_R1_HASHKEY(hashKey)		((hashKey) % DHCP_CID_HASH_LEN)
#define DHCP_BIND_HADDR_HASHKEY(hashKey)	((hashKey) % DHCP_HADDR_HASH_LEN)
#define DHCP_BIND_IP_HASHKEY(hashKey)		((hashKey) % DHCP_IP_HASH_LEN)
#define DHCP_BIND_XID_HASHKEY(hashKey)	((hashKey) % DHCP_XID_HASH_LEN)

#define DHCP_NODE_HASH_CID		0x01
#define DHCP_NODE_HASH_R1			0x02
#define DHCP_NODE_HASH_MON		0x04
#define DHCP_NODE_HASH_HADDR		0x08
#define DHCP_NODE_HASH_IP			0x10
#define DHCP_NODE_HASH_XID		0x20
#define DHCP_NODE_HASH_MON_TMP	0x40

#define DHCP_NODE_HASH_SET(pDb,nodeHash)		do {if(NULL != (pDb)) {(pDb)->hashed |= (nodeHash);}}while(0)
#define DHCP_NODE_HASH_CLR(pDb,nodeHash)		do {if(NULL != (pDb)) {(pDb)->hashed &= ~(nodeHash);}}while(0)
#define DHCP_NODE_HASH_IS_SET(pDb,nodeHash)	(NULL != (pDb) && (pDb)->hashed & (nodeHash))
#define DHCP_NODE_HASH_IS_CLR(pDb,nodeHash)	(NULL != (pDb) && ((pDb)->hashed & (nodeHash)) == 0)

#define DHCP_RENEW_LATER_THAN_T1		(GC_INTERVAL*10)
#define DHCP_EXPIRE_LATER_THAN_LEASE	(2*DHCP_RENEW_LATER_THAN_T1)

typedef enum aep_dhcp_fsm_state
{
	ADFS_W4_INIT_DISCOVER = 1,
	ADFS_W4_INIT_OFFER,
	ADFS_W4_INIT_REQUEST,
	ADFS_W4_INIT_ACK,
	ADFS_NORMAL,	/* w4 renew_request or release and don't differentiate between renew and rebind */
	ADFS_W4_NORMAL_ACK
}AEP_DHCP_FSM_STATE;

typedef enum aep_dhcp_fsm_event
{
	ADFE_INIT_DISVOER,
	ADFE_INIT_OFFER,
	ADFE_INIT_REQUEST,
	ADFE_INIT_ACK,
	ADFE_INIT_NAK,
	ADFE_INIT_DECLINE,
	ADFE_INFORM,
	ADFE_NORMAL_REQUEST,
	ADFE_NORMAL_ACK,
	ADFE_NORMAL_NAK,
	ADFE_NORMAL_RELEASE
}AEP_DHCP_FSM_EVENT;



typedef struct dhcp_binding {
	unsigned int	dbMagic0;
	
	TAILQ_ENTRY(dhcp_binding)		listNode;	/* chained in freelist or monitoring list */
	
	TAILQ_ENTRY(dhcp_binding)		cidNode;	/* chained in client Id list by cid which is client id tag or haddr */
	TAILQ_ENTRY(dhcp_binding)		r1Node;		/* chained in r1 addr list by r1 addr,i.e,msId */
	TAILQ_ENTRY(dhcp_binding)		haddrNode;	/* chained in hardware list if needed by haddr */
	TAILQ_ENTRY(dhcp_binding)		ipNode;		/* chained in ip list by res->ip_addr */
	TAILQ_ENTRY(dhcp_binding)		xidNode;	/* chained in transaction id list if needed */

	/*AEP_DHCP_FSM_STATE		state;	*/
	unsigned int		state;		/* dhcp server side fsm state */
	
	unsigned char 	opt_req_mask[DHCP_OPT_MASK_SIZE]; 	/* record which req option by client */
	
	unsigned char		hashed;			/* record hashed infor */
	unsigned short	hashKey_cid;	/* record hash key of cid */
	unsigned short	hashKey_r1;		/* record hash key for r1 addr,i.e,msId */
	unsigned short	hashKey_mon;	/* record hash key of monitor the binding chained*/
	unsigned short	hashKey_mon_tmp;	/* record hash key of monitor the binding procedure */
	unsigned short	hashKey_haddr;	/* record hash key of haddr */
	
	unsigned short	hashKey_ip;		/* record hash key of ip */
	unsigned short	hashKey_xid;	/* record hash key of xid */
	

	unsigned char 	cidFlag;
	unsigned char		haddrFlag;
	struct client_id	cid;           /* hashing key. client identifier */
	struct chaddr		haddr;
	unsigned char 	r1MacAddr[6];	/* from UP */
	
	unsigned int		xid;

	/* to monitor the init procedure and renew and expire, if 0xffffffff, don't care */
	unsigned int		expire_epoch;	/* lease expiration epoch */
	unsigned int		renew_epoch;	/* renew expiration epoch */
	unsigned int		temp_epoch;	/* temporary epoch to monitor the init procedure */

	unsigned int 		renew_to_times;
	unsigned int		temp_epoch_reason;	/* temp epoch time our for what */

	
	St_AepUeCtxt		*pUeCtxt;	/* back to AEP ue context */

	struct dhcp_resource       *pRes;	/* pointer to dhcp resource including ip/netmask/lease....*/

	unsigned int relay_server;		/* to record relay server ip addr for relay */

	unsigned int msgLen;		/* real dhcp length rather than sizeof(struct dhcp) */
	unsigned int subnet_reqed;	/* with _DHCP_SUBNET_SELECTION_TAG */
	unsigned int subnet;	/* to record subnet from client by indication of _DHCP_SUBNET_SELECTION_TAG */
	
	struct vendor_class_id	vendor_id;	/* to record verdor class id from client if needed */
	struct user_class_id 	user_id;		/* to record user class id from client if need */

	
	unsigned int	dbMagic1;
}St_DhcpBinding;

typedef TAILQ_HEAD(DhcpBinding_List, dhcp_binding) St_DhcpBinding_List;




/*
 * This structure contains information for a DHCP server used to 
 * communicate with DHCP clients .
 */
#define DHCP_DOMAIN_NAME_MAX_LEN	128
typedef struct dhcp_proxy
{
	struct in_addr	primDNSServer;
	struct in_addr	secondDNSServer;
	struct in_addr	routerAddr;
	unsigned char domainName[DHCP_DOMAIN_NAME_MAX_LEN];
	unsigned int	retryCount;

⌨️ 快捷键说明

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