blob: df07c2124acf021789cba890d83d76c2be722078 [file] [log] [blame]
/************************************************************************
*¹¦ÄܽéÉÜ£º×ÔÑÐʵÏÖµÄioctl½Ó¿Ú²ÎÊý¶¨Òå
*¸ºÔðÈË£º
*±¸·ÝÈË£º
*ÐÞ¸ÄÈÕ£º
*ÐÞ¸ÄÄÚÈÝ£º
*°æ±¾ºÅ£º
************************************************************************/
#ifndef _ZXIC_IOCTL_H_
#define _ZXIC_IOCTL_H_
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#ifdef _MBB_OS_UCLINUX
#include <stdint.h>
#endif
#define NIOCTL_MAGIC 'x'
#define NIOCTL_MAX_NR 32 //IOCTL¿ÉÓÃÃüÁîµÄ×î´ó¸öÊý
#define NIOCTL_READ _IO(NIOCTL_MAGIC,0)
/*»ñÈ¡¶þ²ãÁÚ¾ÓÁбíÖÐmacµØÖ·ºÍ³ö¿Údevname*/
#define NIOCGPCINFO _IOWR(NIOCTL_MAGIC,1,ioctl_data)
/*»ñÈ¡ÍøÂçÉ豸tx¡¢rx¡¢dropµÈͳ¼Æ£¬ÍøÂçÉ豸״̬ÐÅÏ¢*/
#define NIOCGSTATS _IOWR(NIOCTL_MAGIC,2,ioctl_data)
/*ÉèÖÃÄں˲ÎÊýͨÓÃÃüÁÀýÈçfastnat/fastbr/leak/brmoniterµÈ¿ª¹Ø»ò¼¶±ð*/
#define NIOCSKPARAM _IOWR(NIOCTL_MAGIC,3,ioctl_data)
/*»ñÈ¡skbÉêÇë³É¹¦/ʧ°Ü¸öÊýͳ¼Æ*/
#define NIOCGSKBCNT _IOR(NIOCTL_MAGIC,4,ioctl_data)
/*»ñÈ¡fastnat ×î´óÁ´½ÓÊý*/
#define NIOCGFASTMAXLINKS _IOR(NIOCTL_MAGIC,7,ioctl_data)//È·¶¨ºóÐøÊÇ·ñ»¹ÒªÊ¹ÓÃ
/*»ñÈ¡×Ô´ò¿ªÍ³¼Æ¿ª¹ØÖ®ºó£¬skb µÄµ±Ç°¸öÊý¡¢Ë²¼ä·åÖµµÈͳ¼ÆÐÅÏ¢¡¢skb¿½±´´ÎÊý¡¢skbÍ·À©Õ¹´ÎÊý
skbÔÚÈíÖжÏÊÍ·Å´ÎÊý*/
#define NIOCGSKBNUM _IOWR(NIOCTL_MAGIC,13,ioctl_data)
/*ÉèÖÃÄÚºËskb dumpÆ¥ÅäÐÅÏ¢£¬ÀýÈçÆ¥ÅäÌØ¶¨macµØÖ·¡¢IPµØÖ·*/
#define NIOCGSKBDUMP _IOR(NIOCTL_MAGIC,14,ioctl_data)
/*ÉèÖÃÄÚºËtcpdump ¿ª¹Ø*/
#define NIOCSTCPDUMP _IOR(NIOCTL_MAGIC,15,ioctl_data)
/**/
#define NIOCPDP _IOR(NIOCTL_MAGIC,17,ioctl_data)
/**/
#define NIOCFLUSHFLAG _IOR(NIOCTL_MAGIC,18,ioctl_data)
#define NIOCGKPARAM _IOR(NIOCTL_MAGIC,19,ioctl_data)
#define NIOCGSLAB _IOR(NIOCTL_MAGIC,21,ioctl_data)
/*add by jiangjing,»ñÈ¡init_netÖÐËùÓÐÍøÂçÉ豸µÄÃû³ÆºÍ״̬ÐÅÏ¢*/
#define NIOCGDEVLIST _IOR(NIOCTL_MAGIC, 22, ioctl_data)
/*add by zhangpeimin£¬»ñÈ¡SKB FASTµ±Ç°Í³¼ÆÐÅÏ¢*/
#define NIOCGSKBFAST _IOR(NIOCTL_MAGIC, 24, ioctl_data)
#define NIOCGMAXMSG _IOR(NIOCTL_MAGIC, 25, ioctl_data)
#define NIOCGPTYPE _IOR(NIOCTL_MAGIC, 26, ioctl_data)
#define NIOCGPSINFO _IOR(NIOCTL_MAGIC, 27, ioctl_data)
#define NIOCGHASH _IOR(NIOCTL_MAGIC, 28, ioctl_data)
/*»ñÈ¡µ±Ç°TCP¶ª°üͳ¼ÆÐÅÏ¢*/
#define NIOCGPKTLOST _IOR(NIOCTL_MAGIC, 29, ioctl_data)
/*»ñÈ¡±¾µØTCPÌ×½Ó×Öͳ¼ÆÐÅÏ¢*/
#define NIOCGTCPSOCKSTATS _IOR(NIOCTL_MAGIC, 30, ioctl_data)
#define NIOCTL_MAX_MSGLEN 128 //×Ö·û´®ÀàÐͲÎÊýÖµµÄ×î´ó³¤¶È
#define NIOCTL_MAX_NAMELEN 20 //²ÎÊýÃû³ÆµÄ×î´ó³¤¶È
/*
ͨÓÃioctlµÄ²ÎÊýÀàÐÍ£¬µ±²ÎÊýֵΪ×Ö·û´®Ê±£¬Ê¹ÓÃbuf±äÁ¿ÓëÄں˽»»¥£»
µ±²ÎÊýֵΪÕûÐÍʱ£¬Ê¹ÓÃvalue±äÁ¿ÓëÄں˽»»¥
*/
typedef struct {
unsigned int size; //×Ö·û´®ÀàÐͲÎÊýµÄ³¤¶È£¬¶ÔÓÚÕûÐͲÎÊý£¬¸ÃÖµ½¨Ò鸳ֵΪ0
char name[NIOCTL_MAX_NAMELEN]; //²ÎÊýÃû³Æ£¬ÀýÈçfastnat¡¢fastbr¡¢leak
unsigned char buf[NIOCTL_MAX_MSGLEN]; //×Ö·û´®ÀàÐͲÎÊýÖµ£¬ÀýÈçon/off
void *data; //×Ô¶¨Òå½á¹¹Ìå
int value; //ÕûÐͲÎÊýÖµ£¬ÀýÈç0/1/2/3
} __attribute__((packed)) ioctl_data;
enum dev_opt_state {
DEV_UNOPT = 0, //ÈôÓû§Î´×öÈκβÙ×÷£¬³õʼֵΪ0
DEV_NOPRESENT, //¶ÔÓ¦!netif_device_presentÒì³££¬±íÃ÷Çý¶¯µ×²ãÉÐδ׼±¸ºÃ
DEV_OPENED, //dev is opened
DEV_OPEN_FAIL, //open fail
DEV_CLOSED, //dev is closed
};
//ÍøÂçÌí¼Ó£¬Í³¼ÆÍøÂç²ãÃæÊÕ·¢°üÇé¿ö
struct net_dev_skbinfo {
unsigned long rx_packets; //Çý¶¯·¢ËÍÀ´µÄÊý¾Ý°ü¸öÊý£¬ÔÚnetif_rxÍ·ÀÛ¼Ó
unsigned long tx_packets; //·¢Ë͸øÇý¶¯µÄÊý¾Ý°ü¸öÊý£¬ÔÚdev_queue_xmitÍ·ÀÛ¼Ó
unsigned long rx_bytes; //×Ö½ÚÊý
unsigned long tx_bytes; //×Ö½ÚÊý
unsigned long rx_dropped; //netif_rxÄÚ²¿Á÷³ÌÖÐËùÓÐÒì³£ÊÍ·ÅskbµÄÀÛ¼Ó£¬Èç´ïµ½netdev_max_backlogÈë¶ÓÁÐÉÏÏÞ¶ø¶ª°ü
unsigned long tx_dropped; //dev_queue_xmitÄÚ²¿Á÷³ÌÖÐËùÓÐÒì³£ÊÍ·ÅskbµÄÀÛ¼Ó£¬Èç(txq->xmit_lock_owner == cpu)Ôì³ÉµÄ¶ª°ü
};
/* ¸Ã½á¹¹ÌåÖеÄËùÓÐÐÅÏ¢½ÔÓÉÇý¶¯¸³Öµ£¬ÍøÂç×é²»»á¸³Öµ */
//Õâ¸ö½á¹¹Ì屨ÐëºÍ <linux/netdevice.h>ÖеÄnet_device_stats±£³ÖÒ»ÖÂ
struct net_dev_stats {
unsigned long rx_packets;
unsigned long tx_packets;
unsigned long rx_bytes;
unsigned long tx_bytes;
unsigned long rx_errors; //Ðè¼à¿Ø
unsigned long tx_errors; //Ðè¼à¿Ø
unsigned long rx_dropped; //Ðè¼à¿Ø
unsigned long tx_dropped; //Ðè¼à¿Ø
unsigned long multicast;
unsigned long collisions;
unsigned long rx_length_errors; //Ðè¼à¿Ø
unsigned long rx_over_errors; //Ðè¼à¿Ø
unsigned long rx_crc_errors; //Ðè¼à¿Ø
unsigned long rx_frame_errors; //Ðè¼à¿Ø
unsigned long rx_fifo_errors; //Ðè¼à¿Ø
unsigned long rx_missed_errors; //Ðè¼à¿Ø
unsigned long tx_aborted_errors; //Ðè¼à¿Ø
unsigned long tx_carrier_errors; //Ðè¼à¿Ø
unsigned long tx_fifo_errors; //Ðè¼à¿Ø
unsigned long tx_heartbeat_errors; //Ðè¼à¿Ø
unsigned long tx_window_errors; //Ðè¼à¿Ø
unsigned long rx_compressed;
unsigned long tx_compressed;
};
enum netdev_queue_state {
__QUEUE_STATE_DRV_XOFF,
__QUEUE_STATE_STACK_XOFF,
__QUEUE_STATE_FROZEN,
};
struct dev_ioctl_info {
char dev_name[20];
struct net_dev_skbinfo stats_dbg; //ÍøÂçÌí¼ÓµÄ£¬Í³¼ÆÍøÂç²ãÃæÊÕ·¢°üÇé¿ö
struct net_dev_stats skb_status; //Êý¾ÝÊÕ·¢Í³¼ÆÖµ£¬¸Ãֵȫ²¿ÓÉÇý¶¯¸³ÖµµÄ£¬ÍøÂç²»¸³Öµ
unsigned int flags; //IFF_UPµÈ
unsigned char operstate; //ĿǰûɶÓÃ
unsigned long state; //µ×²ãÇý¶¯×´Ì¬£¬__LINK_STATE_NOCARRIER
int net_flag; //Óû§ifconfigµÄ½á¹û״̬£¬ÈçDEV_OPEN_FAIL
unsigned long que_state; //¶ÓÁÐ״̬£¬¶ÔÓ¦ dev->_tx[0].state£¬Èç__QUEUE_STATE_DRV_XOFF
unsigned int num_tx_queues; //TX¶ÓÁÐÊýÁ¿£¬¶àÊýÇý¶¯Ê¹ÓÃΨһ¶ÓÁУ¬ÔòֵΪ1
};
//ÓëÄÚºËskb_using_msg ½á¹¹ÌåÒ»ÖÂ
struct skb_ioctl_info {
unsigned long skb_all;
unsigned long skb_tocp;
unsigned long skb_fromcp;
unsigned long skb_data_num;
unsigned long skb_data_size;
unsigned long skb_stop;
unsigned long skb_lock;
unsigned long skb_panic;
unsigned long skb_fail;
};
struct skb_fast_ioctl_info {
int skb_num4; //½ÓÊÕµ½µÄV4Êý¾Ý°ü
int skb_num6; //½ÓÊÕµ½µÄV6Êý¾Ý°ü
int skb_big_num; //len³¤¶È³¬¹ý1000µÄÊý¾Ý°ü£¬º¬V4ºÍV6
int skb_small_num; //len³¤¶ÈСÓÚ100µÄÊý¾Ý°ü£¬º¬V4ºÍV6
int skb_bytes4; //½ÓÊÕµ½µÄV4Êý¾Ý°ü×Ö½ÚÊý
int skb_bytes6; //½ÓÊÕµ½µÄV6Êý¾Ý°ü×Ö½ÚÊý
int skb_unknown; //½ÓÊÕµ½µÄδ֪ЭÒéÊý¾Ý°ü£¬°üÀ¨ARPµÈ·ÇV4ºÍV6µÄ±¨ÎÄ
int skb_tcpnum; //½ÓÊÕµ½µÄtcpÊý¾Ý°ü£¬º¬V4ºÍV6£¬µ«²»º¬fastbrµÄ±¨ÎÄ
int skb_udpnum; //½ÓÊÕµ½µÄudpÊý¾Ý°ü£¬º¬V4ºÍV6£¬µ«²»º¬fastbrµÄ±¨ÎÄ
int broadcast_num4; //½ÓÊÕµ½µÄV4¹ã²¥°ü
int broadcast_num6; //½ÓÊÕµ½µÄV6¹ã²¥°ü
int multicast_num4; //½ÓÊÕµ½µÄV4×é²¥±¨
int multicast_num6; //½ÓÊÕµ½µÄV6×é²¥±¨
int fastnat_num; //fastnat³É¹¦µÄ±¨ÎÄ
int fast6_num; //fast6³É¹¦µÄ±¨ÎÄ
int fastbr_num; //fastbr³É¹¦µÄ±¨ÎÄ
int fastnat_level; //²Î¿´FAST_NET_DEVICE
int fastbr_level; //²¼¶ûÀàÐÍ
//ÏÂÃæ¼¸¸öֵΪÀÛ¼ÓÖµ£¬ÐÔÄÜÏà¹Ø
int irqfree_num; //ͨ¹ýÈíÖжÏÊͷŵÄskb£¬ÐÔÄÜÏà¹Ø
int skbcopy_num; //Êý¾Ý¿½±´µÄskb£¬ÐÔÄÜÏà¹Ø
int cache_copy; //net_cacheÔ´Îļþ½øÐп½±´µÄÀÛ»ý¼ÆÊý£¬ÐÔÄÜÏà¹Ø
int skbflood_num; //·ººéµÄskb£¬ÐÔÄÜÏà¹Ø
int errfree_num; //devÔ´ÎļþÖдíÎóÊͷŵÄskb¼ÆÊý£¬°üÀ¨SKB_QUEUE_STOPºÍSKB_QUEUE_LOCKÁ½¸ö¼ÆÊýÖµ
int frag_num; //½ÓÊÕµ½µÄ·ÖƬ±¨ÎÄ£¬ÐÔÄÜÏà¹Ø
int mtu_num; //fastÖÐÊý¾Ý³¤¶È´óÓÚ³ö¿Údev MTUʱ£¬fastʧ°Ü¸öÊýͳ¼Æ
int fast_loop; //ͶµÝ¸øÇý¶¯£¬ÓÖ´ÓÇý¶¯ÊÕµ½µÄÒì³£»Ø»·¸öÊýͳ¼Æ
int skb_alloc_fail ; //ÉêÇëskbʧ°ÜµÄ¸öÊýÀÛ¼ÓÖµ
int xmit_lock_num; //xmit_lock_owner±»Ëø×¡Ôì³ÉµÄ¶ª°üµÄÀÛ¼Ó¼ÆÊý£¬Çý¶¯Ôì³ÉµÄ
int xmit_stop_num; //!netif_xmit_stopped(txq)Ôì³ÉµÄ¶ª°üµÄÀÛ¼Ó¼ÆÊý£¬Çý¶¯Ôì³ÉµÄ
int br_mac_change_num; //ÍøÇÅmacµØÖ·±»¸Ä±ä´ÎÊý
int fast_tcpdump_num; //fast×¥°üÊý
int fast_switch; //fast×Ó¹¦ÄÜλͼ¿ª¹Ø
int fast_local4_rcv_num; //±¾µØfast_local4³É¹¦½ÓÊÕ±¨ÎÄ
int fast_local6_rcv_num; //±¾µØfast_local6³É¹¦½ÓÊÕ±¨ÎÄ
int fast_local4_output_num; //±¾µØfast_local4³É¹¦·¢Ëͱ¨ÎÄ
int fast_local6_output_num; //±¾µØfast_local6³É¹¦·¢Ëͱ¨ÎÄ
};
#define SLAB_NUM 21
enum slabinfo_file {
SKB_SLAB = 0,
BRFDB_SLAB,
DST_SLAB,
FIB_TRIE_SLAB,
FLOW_SLAB,
INETPEER_SLAB,
INET_HASHTABLES_SLAB,
INET_TIMEWAIT_SOCK_SLAB,
MYSOCKET_SLAB,
NF_CONNTRACK_CORE_SLAB,
NF_CONNTRACK_EXCEPT_SLAB,
REQUEST_SOCK_SLAB,
SOCK_SLAB,
SOCKET_SLAB,
XFRM6_TUNNEL_SLAB,
XT_HASHLIMIT_SLAB,
SOCK_ALLOC_PAGES,
IP6_OUTPUT_ALLOC_PAGES,
IP_OUTPUT_ALLOC_PAGES,
SKB_ALLOC_PAGES,
};
struct slab_info {
int num[SLAB_NUM][2];
};
#define HASH_ARRAY_COUNT 512
struct hash_info {
int max_hash_size;
int current_hash_num;
int hash[HASH_ARRAY_COUNT][2];
int current_array_size;
};
struct neigh_info {
unsigned int ip_len; //IPµØÖ·³¤¶È£¬Çø·ÖV4ºÍV6
unsigned char ip_addr[IPV4ADDLEN_MAX];
unsigned char mac_addr[MAX_MACADDR_LEN];
};
#define MAX_NEIGH_NUM 20
struct dev_neigh_info {
unsigned int num;
struct neigh_info neigh_nod[MAX_NEIGH_NUM];
};
enum dev_layer {
L3_DEV = 0, //²ã3É豸
BR_DEV, //ÍøÇŵÄL3ÌØÊâÉ豸
L2_DEV, //L2²ãÉ豸
};
enum {
LOCAL_L3DEV = 0,
LOCAL_BR_PORT,
NEIGH_AND_DSTDEV,
DEV_STATISTIC,
};
enum IFMAC_ERR {
ZERO_ADDRERR = 1,
MULTICAST_ADDRERR,
BROADCAST_ADDRERR,
};
/*add by jiangjing*/
struct dev_and_neigh {
char name[20];
unsigned char dev_layer; //ָʾ¸Ã±¾µØÍø¿ÚµÄЭÒé²ã£¬²Î¼ûºêÖµL3_DEV
/*MACµØÖ·,IPv4µØÖ·*/
unsigned char mac_addr[20]; //±¾µØÍø¿ÚµØÖ·
unsigned int ipv4_addr; //±¾µØÍø¿ÚIPµØÖ·
struct dev_neigh_info dev_neigh; //¸Ã±¾µØÍø¿ÚЯ´øµÄÔ¶³ÌÁÚ¾ÓµØÖ·ÐÅÏ¢Êý×é
int mac_errtype;
};
#define MAX_DEV_NUM 30
/*Íø¿ÚÏà¹ØµÄÐÅÏ¢*/
struct devlist_ioctl_info {
unsigned int num; //±¾µØÓÐÐ§Íø¿ÚµÄ¸öÊý
struct dev_and_neigh info[MAX_DEV_NUM]; //±¾µØÓÐÐ§Íø¿ÚµÄ¾ßÌåÐÅÏ¢²ÎÊý
};
/****×ÊԴʹÓü°ÉÏÏÞÐÅÏ¢£¬ËùÓбê×¼ÄÚºËÓÐÉÏÏÞÇé¿öµÄ£¬½ÔÐè¼ì²â£¬ÒÔ·ÀÖ¹Òì³£·¢Éú****/
struct net_max_check_msg {
/*nf_conntrack*/
unsigned long nf_conntrack_max; //nf_conntrack_max = 4832
unsigned long nf_conntrack_now; //net->ct.count
/*enqueue*/
int netdev_max_backlog; //netdev_max_backlog=1000
int input_queue_len; //²Î¿´enqueue_to_backlog½Ó¿ÚʵÏÖ
int rx_dropped; //ÒòΪÈë¶ÓÁÐÒÑÂúÔì³ÉµÄÈë¶ÓÁжª°üµÄÀÛ¼ÓÖµ
/*ÐÔÄÜÏà¹Ø*/
int fastnat_link_max; //nf_conntrack_max
int fastnat_link_now; //working_list.count
int fast6_link_max; //nf_conntrack_max
int fast6_link_now; //working_list6.count
/*ÍøÂçÄÚºËÔËÐÐʱµÄͳ¼ÆÖµ£¬ÖØµã¹Ø×¢½á¹¹ÌåµÄÉêÇëµã*/
unsigned long br_mac_change; //ÍøÇÅmacµØÖ·±»¸Ä±ä´ÎÊý
unsigned long neigh_alloc; //neighbourÉêÇë´ÎÊý
unsigned long neigh_free; //neighbourÊͷŵãÀÛ¼ÓÖµ
unsigned long br_neigh_vary; //ÇŵãµÄ³ö¿ÚdevµÄmacµØÖ·±»¶à¸öpc¹²Ïí
unsigned long conn_alloc; //connÉêÇë´ÎÊýÀÛ¼ÓÖµ
unsigned long conn_free; //connÊͷŵãÀÛ¼ÓÖµ
unsigned long brfdb_alloc; //ÇŵãÉêÇë´ÎÊýÀÛ¼ÓÖµ
unsigned long dst_alloc; //dst_entryÉêÇëÀÛ¼ÓÖµ
unsigned long dst_free; //dst_entryÊͷŵãÀÛ¼ÓÖµ
unsigned long hh_update; //hh¶þ²ãmacÍ·¸üÐÂÀÛ¼ÓÖµ
unsigned long rt_cache_invalid; //Çå¿Õ·ÓÉcacheµÄÀÛ¼ÓÖµ
unsigned long rt_hash_add; //ÐÂÔört_hash_table½ÚµãµÄÀÛ¼ÓÖµ
unsigned long rt_hash_del; //ɾ³ýrt_hash_table½ÚµãµÄÀÛ¼ÓÖµ
unsigned long ssmac_change_indev; //ͬһԴMACµØÖ·Èë¿Údev¸Ä±äµÄ´ÎÊý
};
struct ptype_info {
unsigned long ptype_all[5];
unsigned long ptype_base[15];
};
struct pkt_lost_stats {
unsigned int send_drops;
unsigned int send_drop_bytes;
unsigned int recv_drops;
unsigned int recv_drop_bytes;
unsigned int total_packets;
unsigned int total_bytes;
};
struct pkt_lost_info {
struct pkt_lost_stats stats[2]; /*0:origin·½Ïò£¬1:reply·½Ïò*/
};
struct tcp_sock_stat {
unsigned long tcp_recv_num;
unsigned long tcp_send_num;
unsigned long tcp_retrans_num;
unsigned long tcp_recv_drops;
unsigned long tcp_send_drops;
unsigned long tcp_rst_send;
unsigned long tcp_rst_recv;
};
//½Ó¿ÚÉùÃ÷
extern int netioctl_handle(int cmd, void *val);
#endif //end _ZXIC_IOCTL_H_