Netadm Project: Anonymous CVS downloadLicense :GPL version 2 netadm project |
![]() |
it is now raw text version. linuxpark@users.sf.net or parkjeho@hotmail.com, 2006. 02. 12. (sun) 23:39:59 KST also netadm@kernelproject.org :-) [ IO for Configuration ] #includeint loadconf(sm_t * csm, char *fn); csm: pointer of shared memory. fn: path of config file. desc: loadconf function load configuration to shared meory which pointed csm. int saveconf(sm_t * csm); csm: pointer of shared memory. desc: saveconf save current configuration in shared momory to configuration file. [ Interanl Procedure ] #include the procdure which list below are the main internal handler, but develper must not call these directly. it must be call through syscmd(), or sysclist() for example, char **error; error = syscmd(CMD_DEL_TC_POL, delPolicy, EOA); CMD_DEL_TC_POL is mapped to del_tc_pol () function in conftab.o so syscmd(CMD_DEL_TC_POL, ...) will call del_tc_pol function internally. if you want more infomation, please refer to "request handler" section. void list_apinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list AP infomation which are current available. void add_apinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: add AP infomation which are current available. void list_snmpcomm(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list SNMP community which was add previously. void add_snmpcomm(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: add SNMP community. void list_phymacspec(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the type of wireless interface of remote AP. for example, 802.11a/b/g void list_sysinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the system infomation of remote machine. this function use SNMP query library. void list_ifinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the interface of remote machine. this infomation is used for monitoring of remote machine. this function use SNMP query library. void list_ipinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the IP infomation of remote machine. this can be router or AP this infomation is used for monitoring of remote machine. this function use SNMP query library. void list_tcpinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the TCP infomation of remote machine. this can be router or AP this function use SNMP query library. void list_udpinfo(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the UDP infomation of remote machine. this can be router or AP this function use SNMP query library. void list_ccktpower(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the CCK power value of remote CISCO AP. please refer to the site below. http://jhpark.guideline.co.kr/data/PROJECT/mds/devel/modules/AP_CONTROLL/802.1x-SNMP.txt void list_ofdmtpower(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the OFDM power value of remote CISCO AP. please refer to the site below. http://jhpark.guideline.co.kr/data/PROJECT/mds/devel/modules/AP_CONTROLL/802.1x-SNMP.txt void list_clientpower(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list the client power value of remote CISCO AP. please refer to the site below. http://jhpark.guideline.co.kr/data/PROJECT/mds/devel/modules/AP_CONTROLL/802.1x-SNMP.txt void set_txpower(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: setup the client power value of remote CISCO AP. please refer to the site below. http://jhpark.guideline.co.kr/data/PROJECT/mds/devel/modules/AP_CONTROLL/802.1x-SNMP.txt void list_if(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list information of local interface. void list_tc_maxbw(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list maximum bandwidth infomation of each local interface. void add_tc_maxbw(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: setup maximum bandwidth infomation of specified interface. void del_tc_maxbw(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: delete maximum bandwidth infomation of specified interface. void list_tc_class(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list registered class infomation which user have setup void add_tc_class(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: register a class infomation. void del_tc_class(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: delete a class which user have registered. void list_tc_filter(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list registered user filter. void add_tc_filter(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: register filter. void del_tc_filter(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: delete a filter which user have registered. void list_tc_pol(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list QoS policies infomation which user have registed. void add_tc_pol(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: register QoS policies. void del_tc_pol(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: delete QoS policies which user have registed. void tc_apply(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: apply QoS policy void list_hostpol(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: list flow control policy. void add_hostpol(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: add flow control policy. void del_hostpol(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: delete flow control policy. void hostpol_apply(int argc, char *argv[], int modify, frp_t fr); argc: the number of input argument. argv: input argument. this is the del desc: apply flow control policy. void list_auto(int argc, char *argv[], int modify, frp_t fr); obsolete void set_auto(int argc, char *argv[], int modify, frp_t fr); obsolete void auto_apply(int argc, char *argv[], int modify, frp_t fr); obsolete [ UTILS FOR IPC ] #include void frinit(frp_t fr); fr: fr include ipc query result. fr->p will include the main result of the query. desc: this is internal function for IPC. initialize fr object. void frerr(frp_t fr, ipc_ret_e ret, char *fmt, ...); fr: fr include ipc query result. ret: return value of the query. fmt: error message. desc: output the error. char *mapidtostr(sys_strmap_t * map, int id); obsolete. int mapstrtoid(sys_strmap_t * map, char *str); obsolete. char *mapidtostr(sys_strmap_t * map, int id); obsolete. int frerrmap(frp_t fr, ipc_ret_e ret, char *key, sys_strmap_t * map); obsolete. void frfree(frp_t fr); fr: fr include ipc query result. fr->p will include the main result of the query. desc: this is internal function for IPC. free fr object. fr_t *ipc_msg(sys_cmd_e cmd, void *p, unsigned short plen, int argc); cmd: the number of handler which is defined in confproc.c p: argument which is passed from syscmd or sysclist function. plen: length of p argc: number of argument. desc: this function is internal function. it is called by syscmd or sysclist. int cshmattach(sm_t ** csm); csm: pointer to the shared memory. desc: this function attach to the main shared memory which admd daemon initialized. if any daemon want to shared configuration, this function must be called in daemon initializing routine. int cshmdetach(sm_t * csm); csm: pointer to the shared memory. desc: this function detach from main shared memory. [ Definition of global variable ] #include global.h define a lot of macro variable. this macro will be used globaly. /* package naming , version , copyright - start */ /* P A C K A G E, V E R S I O N N A M I N G */ #define SZPKGNAME "Netadm network control system" #define SZSYSCOPYRIGHT "GPL v2" #define SZSYSVERSION "v0.1" /* this must be changed whenver new version is released */ /* SYS Kernel module interface - start */ #define PKG_NAME SZPKGNAME /* SYS Kernel module interface - end */ #define SZKMODNODE DEVICE_NAME /* package naming , version , copyright - end */ /* P A T H D E F I N I T I O N */ #define SZTCPATH "/sbin" #define SZIPTABLESPATH "/sbin" #define SZMAINPATH "/usr/local/gwc" #define SZMASTCONF "/usr/local/gwc/etc/config" #define SYSMASTEXP "bin" #define SZHTMLPATH "html" #define SZMISCPATH "misc" #define SZCONFIG "config" #define SZCLI "gwccli" #define SZRUNSHELL "gwc" /* exe, config file path - end */ #define SZFWCSSFRTLD "/tmp/.SYS_RTLD" #define SZIPC_CLI_TO_ADMD "/tmp/.NETADM_GWC.CLI_WITH_ADMD" /* temporary file for IPC (unix domain)*/ #define SZSYSCIPC SZIPC_CLI_TO_ADMD #define SZSYSCSIPC SZSYSIPC #define SZPFDEV "/dev/pf" /* device file for packet filtering */ #define SYSCMAXLINE 256 #define SYSCOKSTR "OK" #define CONFMAGIC "#SYS" #define MAXCFGLINE 1024 #define SZEXTWELCOME "welcome" #define ADMEXEPATH MODUTILPATH /* various buffer len definition */ /* B U F F E R L E N G T H D E F I N I T I O N */ #define MAXBUF 8192 /* default max buffer length */ #define MINBUF MAXBUF/32 /* default min buffer length */ #define BUFLEN 8192/4 #define MAXFNLEN 256 #define MAXCMDLEN 16 #if !defined BUFSIZ #define BUFSIZ MAXBUF/2 #endif #define BUFFER_LEN MAXBUF /* T I M E O U T D E F I N I T I O N */ #define DEFTIMEOUT 3600 /* default timeout of any daemon */ #define APC_ADMD_TIMEOUT 10 #define AUTOAPPLY_TIMEOUT 50000 [ LINKED LIST FOR INTERNAL USAGE ] #include this library provides linkedlist algorithm. #define nextnode(X) ((X) = (X)->next) #define listhead(X) ((X)->head) #define listcount(X) ((X)->count) #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL) #define getdata(X) ((X)->data) struct list *list_new(); void list_free(struct list *); void listnode_add(struct list *, void *); void listnode_add_sort(struct list *, void *); void listnode_add_after(struct list *, struct listnode *, void *); void listnode_delete(struct list *, void *); struct listnode *listnode_lookup(struct list *, void *); void list_delete(struct list *); void list_delete_all_node(struct list *); void list_delete_node(list, listnode); void list_add_node_prev(list, listnode, void *); void list_add_node_next(list, listnode, void *); void list_add_list(list, list); #define LIST_LOOP(L,V,N) #define LISTNODE_ADD(L,N) #define LISTNODE_DELETE(L,N) [ MESSAGE DEFINITION ] #include if developer define or use message, he define in this header file. and when he define any message, the format of macro variable must keep the type below. /* Note ! * * INFO_: INFOrmation */ /* EM_ : Error Message */ /* EMT_ : Error Message Title */ /* STR_ : normal STRing */ /* TAB_ : TABle string */ /* FORM_: FORM table string */ Here are the definitions in gwc-v0.1-pre1 #define INFO_CLI_LISTAPINFO "List AP infomation." #define INFO_CLI_ADDAPINFO "Add AP Network infomation." #define INFO_CLI_LISTSNMPCOMM "List SNMP commnunity infomation." #define INFO_CLI_ADDSNMPCOMM "Add SNMP community infomation." #define INFO_CLI_LISTPHYMACSPEC "List phycal interface mac spec infomation." #define INFO_CLI_LISTSYSINFO "List current AP system infomation." #define INFO_CLI_LISTIFINFO "List current IF infomation." #define INFO_CLI_LISTIPINFO "List current IP infomation." #define INFO_CLI_LISTTCPINFO "List current TCP infomation." #define INFO_CLI_LISTUDPINFO "List current UDP infomation." #define INFO_CLI_LISTCCKTPOWER "List current CCK transmitter power" #define INFO_CLI_LISTOFDMTPOWER "List current OFDM transmitter power" #define INFO_CLI_LISTCLIENTPOWER "List current Client power" #define INFO_CLI_SETTXPOWER "Set current Tx Power" #define INFO_CLI_LIST_IF "List Interface infomation" #define INFO_CLI_LIST_TC_MAXBW "List the maximum bandwidth of a interfaces" #define INFO_CLI_ADD_TC_MAXBW "Add the maximum bandwidth of a specfied interface" #define INFO_CLI_DEL_TC_MAXBW "Delete the maximum bandwidth info of a specfied interface" #define INFO_CLI_LIST_TC_CLASS "List Traffic Control class infomation" #define INFO_CLI_ADD_TC_CLASS "Add Traffic Control Class" #define INFO_CLI_DEL_TC_CLASS "Delete Traffic Control Class" #define INFO_CLI_LIST_TC_FILTER "List Traffic Control Filter" #define INFO_CLI_ADD_TC_FILTER "Add Traffic Control Filter" #define INFO_CLI_DEL_TC_FILTER "Delete Traffic Control Filter" #define INFO_CLI_LIST_TC_POL "List Traffic Control Policy" #define INFO_CLI_ADD_TC_POL "Add Traffic Control Policy" #define INFO_CLI_DEL_TC_POL "Delete Traffic Control Policy" #define INFO_CLI_TC_APPLY "Apply Traffic Control Policy" #define INFO_CLI_LIST_HOSTPOL "List host policy{pakcet control|modify seq of TCP}" #define INFO_CLI_ADD_HOSTPOL "Add host policy{packet control|modify seq of TCP}" #define INFO_CLI_DEL_HOSTPOL "Delete host policy{packet control|modify seq of TCP}" #define INFO_CLI_HOSTPOL_APPLY "Apply host policy{packet control|modify seq of TCP}" #define INFO_CLI_LIST_AUTO "List the setup config of auto test" #define INFO_CLI_SET_AUTO "Set the setup config of auto test " #define INFO_CLI_AUTO_APPLY "Apply the Auto test config" /* STR_ : normal STRing */ #define STR_STATE "qry_state" #define STR_TARGET "target" #define STR_AP_IP "target_ip" #define STR_AP_MASK "target_mask" #define STR_SNMP "snmp" #define STR_COMMUNITY "snmp_community" #define STR_RADIO_IDX "radio_idx" #define STR_INTERFACE "interface" #define STR_TC_DEV "tc_dev" #define STR_TC_CLASS "tc_class" #define STR_TC_FILTER "tc_filter" #define STR_TC_POLICY "tc_policy" #define STR_HOST_POLICY "host_policy" #define STR_AUTO_TEST "auto_test" /* EM_ : Error Message */ #define EM_OBJNOTFOUND "Can't found the object(%s)" #define EM_NOTAVAILABLEREQ "It(%s) is not supported" #define EM_NOTAVAILABLESVC "It(%s) is not available service" #define EM_AUTHCON "Can't connect to Auth Server" #define EM_WRITE "Write error" #define EM_READ "Read error" #define EM_NOUSER "User does not exist" #define EM_EMPTYNAME "Enter User Name" #define EM_DUPUSER "User already exist" #define EM_PASSWD "Passwd incorret" #define EM_EMPTYPASS "Enter Passwd" #define EM_PASSINIT "User passwd does not initialized" #define EM_BLOCKUSR "Blocked count" #define EM_AUTHDBIO "Auth DB error" #define EM_SKEYIO "Key file error" #define EM_NOMEMORY "Not enough memory" #define EM_USERPERM "Permission error" #define EM_MSGBUFSIZ "Not enough buffer" #define EM_AUTHCONN "Can't connect" #define EM_INTERN "Internal error" #define EM_SYSTEM "Internal Function error" #define EM_WRONGDATA "Input error of internal auth routine" #define EM_AUTHTYPE "Inout error of authentification type" #define EM_EXPDATE "Expire date error" #define EM_EMPTYBAD "Maximum bad trial" #define EM_PWLENGTH "Password size error" #define EM_PASSFORM "Bad password error" #define EM_EXPPASSWD "Password expired" #define EM_DELADMIN "Can't delete system admin" #define EM_AUTHPUBLIC "Normal user can't login" [ SYSLOG WRAPPER ] #include syslog wrapper functions are defined here. you can use sysl_log function directly or you can use out() macro function which is defined in sysutils.h this out macro will be replaced when USE_SYSLOG macro is define. if USE_SYSLOG is not defined and DEBUG macro is defined, out macro fn will be replaced with just printf. /* * Don't use standard I/O, But Use this syslog * * [ USAGE Format ] * sysl_open( binary name, LOG TYPE); * : binary name : system daemon name or daemon name * : LOG TYPE: System daemon -> SYSL_SYSTEM * Daemon for any purpose -> SYSL_DAEMON * Config concerned -> SYSL_DAEMON * * sysl_log( LOG PRIORITY, LOG CATAGORY, ...); * : LOG PRIORITY : [SYSL_SYSTEM | SYSL_DAEMON | SYS_CONFIG ] * : LOG CATAGORI : Serveral types of Log * * sysl_close: * : close syslog stream * * parkjeho@hotmail.com * */ /* * LOG PRIORITY */ #define SYSLA LOG_ALERT /* ALERT LOG */ #define SYSLE LOG_ERR /* ERROR LOG */ #define SYSLW LOG_WARNING /* WARNING LOG */ #define SYSLI LOG_INFO /* INFO LOG */ #define SYSLD LOG_DEBUG /* DEBUG LOG */ #define SYSLQ LOG_CRIT /* CBQ LOG */ /* * LOG TYPE */ #define SYSL_SYSTEM 'S' #define SYSL_DAEMON 'D' #define SYSL_CONFIG 'C' /* * LOG CATAGORY */ #define SYSL_ACT 0x00000001 /* SYS System start/stop */ #define SYSL_LOG 0x00000002 /* LOG start/stop */ /* This must be extended to several types of log */ #define SYSL_SYS_FAULT 0x00000010 /* System Fault */ #define SYSL_PROC_FAULT 0x00000020 /* Process Fault */ #define SYSL_AUTH_FAULT 0x00000040 /* Process Fault */ #define SYSL_PROC_INFO 0x00000080 /* Daemon log */ #define SYSL_PATH "/tmp/.sysla" void sysl_open(const char *, const char); /* ident, type */ void sysl_log(int, int, const char *, ...); /* priority, message */ void sysl_close(); [ DEFINITION OF EACH OBJECT ] #include this file define all of object. and then all objects will be included in sysshm.h. as you assume, sysshm header file define shared memory for system configuration. #define DL 32 #define OL 16 #define MAXCMD 256 #define MAXCOMMNAME 32 #define MAXHOSTNAME 256 #define MB 1000000 #define KB 1000 typedef struct { char *str; int id; } sys_strmap_t; typedef struct { struct in_addr addr; unsigned short mask; } sys_net_t; /* 802dot11 radio interface */ /* type */ /* Cisco PHYMACSPEC MIB definition */ #define IEEE802DOT11A 1 #define IEEE802DOT11B 2 #define IEEE802DOT11G 3 #define MAXNUM_AUTOTHREAD IEEE802DOT11G /* 802dot11 POWER module */ #define CCKPW_SHIFT 0 #define OFDMPW_SHIFT 8 #define CLIENTPW_SHIFT 16 #define CCKPW_MASK 0x000000FF #define OFDMPW_MASK 0x0000FF00 #define CLIENTPW_MASK 0x00FF0000 #define PWTYPE_CCK 0 #define PWTYPE_OFDM 1 #define PWTYPE_CLIENT 2 #define MAX_PWTYPE PWTYPE_CLIENT #define PWTYPE_APPLY MAX_PWTYPE + 1 typedef struct { int idx; /* if index in AP */ int type; /* type of 802dot11 */ int maxpw; /* the ratio of radio */ /* ------------------- * [ 0XABCBDFGH ] * GH : cck power * DF : ofdm power * CB : client power */ double cck_qdelay; /* average delay time during SNMP query */ double ofdm_qdelay; double client_qdelay; } sys_802dot11if_t; typedef struct { char if_name[OL]; char if_hostname[MAXHOSTNAME]; struct in_addr if_addr; struct in_addr if_mask; int bw; int root_id; int root_made; } sys_if_t; #define TC_DEV_MAXBW 1000001 /* kbyte, so about 1Gbyte */ typedef struct { char if_name[OL]; int bw; } sys_tc_dev_t; /* TODO: no need */ #define MAXBW 100 /* % */ typedef struct { char name[OL]; unsigned short bw; /* % */ int pid; int id; int class_made; char if_name[OL]; } sys_tc_class_t; typedef enum { APC_TC_FILTER_TYPE_TOS = 0, APC_TC_FILTER_TYPE_PROTO, } sys_tc_filter_type_e; typedef enum { APC_TC_PROTO_TCP = IPPROTO_TCP, APC_TC_PROTO_UDP = IPPROTO_UDP, } sys_tc_proto_type_e; typedef struct { sys_tc_proto_type_e type; unsigned short port; } sys_tc_proto_t; #define APC_FILTER_TYPE_TOS 0x00000000 #define APC_FILTER_TYPE_PROTO 0x00000001 /* RFC 1349, 4 Specification of the TOS Field 0 1 2 3 4 5 6 7 +-----+-----+-----+-----+-----+-----+-----+-----+ | | | | | PRECEDENCE | TOS | MBZ | | | | | +-----+-----+-----+-----+-----+-----+-----+-----+ spec> pkg generator apc assumption: default class > 1000 -- minimize delay -> class A ( setting is user dependent ) 0100 -- maximize throughput -> class B 0010 -- maximize reliability -> class C 0001 -- minimize monetary cost -> class D 0000 -- normal service -> class E */ #define APC_TOS_TYPE_MD 0x10 #define APC_TOS_TYPE_MT 0x08 #define APC_TOS_TYPE_MR 0x04 #define APC_TOS_TYPE_MMC 0x02 #define APC_TOS_TYPE_NS 0x00 typedef struct { int tos; char name[OL / 4]; char nf_name[MAXCOMMNAME]; } sys_tc_tos_t; typedef struct { char name[OL]; sys_tc_filter_type_e type; union { unsigned char tos; sys_tc_proto_t proto; } u; } sys_tc_filter_t; #define NOMARK 0 #define USEMARK 1 #define NOPOL 0 #define USEPOL 1 typedef struct { char name[OL]; char filter_name[OL]; char class_name[OL]; int mark_used; char mark_name[OL / 4]; } sys_tc_pol_t; /* sys_host_pol_t/flag */ #define BLOCK_HOST 0x0001 #define MODIFY_SEQ 0x0002 #define MAX_PKTRATE 65535 typedef struct { /* struct in_addr ip; */ char name[OL]; int ip; unsigned short flag; int max_pktrate; } sys_host_pol_t; #define AUTO_STATE_INIT 0 #define AUTO_STATE_S1 1 #define AUTO_STATE_M1 2 #define AUTO_STATE_S2 3 #define AUTO_STATE_M2 4 #define MIN_AUTO_SINT 1 #define MAX_AUTO_SINT 2147 /* If one step is over 35.783 min, error will occur */ #define MIN_AUTO_MINT MIN_AUTO_SINT #define MAX_AUTO_MINT MAX_AUTO_SINT #define AUTO_FROMMIN 0 #define AUTO_FROMMAX 1 #define MIN_AUTO_CNUM 1 #define MAX_AUTO_CNUM 1280 /* * timer thread arg for each radio type */ typedef struct { int type; int state; } arg_t; typedef struct { int sint_1; /* stopping interval */ int sint_2; int mint_1; /* moving interval */ int mint_2; int ilevel; /* 0: from min, 1: from max */ int cnum; /* number of cycle */ } sys_autoconf_t; [ DEFINITION OF INTERFACE BETWEEN PF AND USER PROCESS ] #include this file define the type of query between user process and pf module. #define IOCTLWIBRO_MAGIC 't' typedef struct { __u32 ip; __u32 max_pktrate; } __attribute__ ((packed)) wibro_kuio_msg_t; /* IOCTLWIBRO_REGISTER_SRCBLOCK is used to register the host which will be blocked * or controlled packet flow */ #define IOCTLWIBRO_REGISTER_SRCBLOCK _IO (IOCTLWIBRO_MAGIC, 0) /* IOCTLWIBRO_REGISTER_MODSEQ is used to reigster the host which will be * modified its IP header */ #define IOCTLWIBRO_REGISTER_MODSEQ _IO (IOCTLWIBRO_MAGIC, 1) /* IOCTLWIBRO_UNREGISTER_HOST is used to unregister a host */ #define IOCTLWIBRO_UNREGISTER_HOST _IO (IOCTLWIBRO_MAGIC, 2) #define IOCTLWIBRO_MAXNR 3 [ DEFINITION OF IPC ] #include #define MAXARGC 20 /* maximum number of argc */ #define IPC_TIMEOUT 10 /* default IPC timeout */ /* ipc_ret_e define error number for IPC, this number will be used in ferror */ typedef enum { RET_OK = 0, RET_EUNKNOWN = -1, RET_EWRITE = -2, RET_EREAD = -3, RET_EPARAM = -4, RET_EVER = -5, RET_EMSGID = -6, RET_EMALLOC = -7, RET_EUSAGE = -8, RET_EINTERNAL = -9, RET_ENOTUNIQ = -10, RET_EIMPLEMENT = -11, RET_ENOTFOUND = -12, RET_EFOPEN = -13, RET_EFSTAT = -14, RET_EBACKUP = -15, RET_EUNLINK = -16, RET_EFRESTORE = -17, RET_EUSED = -18, RET_EPROTOCOL = -19, RET_EPORTRANGE = -20, RET_EICMPTYPE = -21, RET_EREFERENCE = -22, RET_ETOOUSER = -23, RET_EREPLY = -24, RET_EBUF = -25, RET_ETIMEOUT = -26, RET_EFACCESS = -27, RET_EOPEN = -50, RET_EIOCTL = -51, RET_ECONFIG = -60, } ipc_ret_e; /* fr_t define the result of IPC */ typedef struct { ipc_ret_e ret; char *p; unsigned short len; unsigned short cols; unsigned short rows; int islist; int errcnt; int errlen; char errmsg[1024]; } *frp_t, fr_t; /* func ret */ /* sys_cmd_e define the index of procedure */ typedef enum { /* user process use this cmd idx */ CMD_LIST_APINFO = 0, CMD_ADD_APINFO, CMD_LIST_SNMPCOMM, CMD_ADD_SNMPCOMM, CMD_LIST_PHYMACSPEC, CMD_LIST_SYSINFO, CMD_LIST_IFINFO, CMD_LIST_IPINFO, CMD_LIST_TCPINFO, CMD_LIST_UDPINFO, CMD_LIST_CCKTPW, CMD_LIST_OFDMTPW, CMD_LIST_CLIENTPW, CMD_SET_TXPW, CMD_LIST_IF, CMD_LIST_TC_MAXBW, CMD_ADD_TC_MAXBW, CMD_DEL_TC_MAXBW, CMD_LIST_TC_CLASS, CMD_ADD_TC_CLASS, CMD_DEL_TC_CLASS, CMD_LIST_TC_FILTER, CMD_ADD_TC_FILTER, CMD_DEL_TC_FILTER, CMD_LIST_TC_POL, CMD_ADD_TC_POL, CMD_DEL_TC_POL, CMD_TC_APPLY, CMD_LIST_HOSTPOL, CMD_ADD_HOSTPOL, CMD_DEL_HOSTPOL, CMD_HOSTPOL_APPLY, CMD_LIST_AUTO, CMD_SET_AUTO, CMD_AUTO_APPLY, } sys_cmd_e; typedef void (*cmdcallback_t) (int argc, char *argv[], int modify, frp_t fr); typedef struct { sys_cmd_e cmd; char *key; cmdcallback_t func; char *hlp; } sys_cmd_t; /* the functions below are used for IPC in external process and they are exported */ void *syscmd(sys_cmd_e cmd, ...); void syscmdfree(char *cp); void sysclistfree(char **list); char **sysclist(sys_cmd_e cmd, char *what, int *pcols, int *prows); #define RELAY_BUFSZ 8192 [ DEFINITION OF ERROR NUMBER ] #define RELAY_BUFSZ 8192 #define SYS_ECLOSED -1 #define SYS_ETIMEOUT -2 #define SYS_EBUF -3 #define SYS_EGETSOCKNAME -4 #define SYS_EGETPEERNAME -5 #define SYS_ENATOPEN -6 #define SYS_EIOCTL -7 #define SYS_EINVADDR -8 #define SYS_ECRESOCK -9 #define SYS_ECONN -10 #define SYS_EREAD -11 #define SYS_EWRITE -12 #define SYS_EPROTOCOL -13 #define SYS_EINVPORT -14 #define SYS_ESETSOCKOPT -15 #define SYS_EBIND -16 #define SYS_ELISTEN -17 #define SYS_EFCNTL -18 int sys_getl(int fd, char *buf, int len, int timeout); int sys_putlbuf(int fd, char *buf); int sys_putl(int fd, char *fmt, ...); int sys_relay(int ifd, int rfd, int timeout, int *pread, int *pwritten); int sys_sendfile(int s, char *fn); int sys_connect(char *dstaddr, unsigned short dstport); int sys_listen(unsigned short port); int sys_maptoa(char *hostname, char *buf, int len); int sys_blockingmode(int s, int yes); int sys_ipclisten(void); int sys_ipcconn(void); int sys_ipcclean(void); int sys_write(int fd, char *buf, int len, int timeout); int sys_read(int fd, char *buf, int len, int timeout); int sys_eat(int fd); [ DEFINITION OF MAIN SYSTEM CONFIGURATION ] #include "sysdef.h" #ifndef __SYS_SHM_INCLUDED #define __SYS_SHM_INCLUDED #define APCSHMID 0x64376329 /* state definition flag */ #define AP_NET_VALID 0x00000001 #define CM_VALID 0x00000002 #define QRY_VALID (AP_NET_VALID | CM_VALID) /* target definition flag of csm */ #define TARGET_GW 0x00000000 #define TARGET_AP 0x00000001 #define TARGET_CISCO_AP 0x00000002 /* snmp, SNMP support definition flag of csm */ #define SNMP_NOSUPPORT 0x00000000 #define SNMP_SUPPORT 0x00000001 /* * Warning : there is a case when no more shared memory is available */ #define MAXSHM_RADIO 24 #define MAXSHM_IF 6 #define MAXSHM_TC_CLASS 64 #define MAXSHM_TC_FILTER 64 #define MAXSHM_TC_POL 1024 #define MAXSHM_HOST_POL 1024 #define MUTEX_LOCK 1 #define MUTEX_UNLOCK 0 typedef struct { int state; /* state being able to query */ int target; /* flag whether target is gw, ap, or CISCO ap */ sys_net_t ap; /* network infomation of AP or general gw */ int snmp; /* flag whether target can support SNMP */ char community[MAXCOMMNAME]; /* SNMP community */ int shared_mutex; /* shared mutex for radio state */ int ridx_slot; sys_802dot11if_t radiodev[MAXSHM_RADIO]; int ifcnt; sys_if_t dev[MAXSHM_IF]; int maxbw; int tcifcnt; /* TC dev info for its max bandwidth */ sys_tc_dev_t tc_dev[MAXSHM_IF]; int cscnt; sys_tc_class_t glass[MAXSHM_TC_CLASS]; int ftcnt; sys_tc_filter_t filter[MAXSHM_TC_FILTER]; int polused; int polcnt; sys_tc_pol_t pol[MAXSHM_TC_POL]; int hpolcnt; /* error packet */ sys_host_pol_t hostpol[MAXSHM_HOST_POL]; sys_autoconf_t auto_test; } sm_t; sm_t *csm; [ DEFINITION OF SNMP LIBRARY FUNCTION ] /* * SNMP lib ERROR TYPE */ #define SYS_EARG -1 #define SYS_EUSAGE -2 #define SYS_EOPEN -3 #define SYS_EMKPDU -4 #ifdef SYS_ETIMEOUT #undef SYS_ETIMEOUT #endif #define SYS_ETIMEOUT -5 #define SYS_EUNKNOWN -6 #define SYS_EPARSE -7 #define SYS_EQUERY -8 #define SYS_EOID -9 #define SYS_EMIB -10 #define SYS_ERESPONSE -11 int snmpget(int, char **, frp_t); int snmpgetnext(int, char **, frp_t); int snmpset(int, char **, frp_t); /* * usage : * int ac; * char *buf[8]; * buf[0] = strdup("snmpwalk"); * buf[1] = strdup("-Os"); * buf[2] = strdup("-c"); * buf[3] = strdup("public"); * buf[4] = strdup("-v"); * buf[5] = strdup("1"); * buf[6] = strdup("192.168.200.199 "); * buf[7] = strdup("tcp"); * ac = 8; * snmpwalk(ac, buf); */ int snmpwalk(int, char **, frp_t); [ DEFINITION OF TIMING ] #include #include #include #include /* E X A M P L E */ /* int main(int argc, char **argv) { struct timeval *p; double e; p = sys_timer_start(); sys_delay (atoi(argv[1])); e = sys_timer_end(p); return 1; } */ struct timeval *sys_timer_start(void); double sys_timer_end(struct timeval *time0); double sys_rearrange_etime(int checkcnt, struct timeval *p[]); void sys_tvadd(struct timeval *tsum, struct timeval *t0, struct timeval *t1); void sys_tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval *t0); void sys_delay(int us); char *sys_sprint_time(void); [ UTILS FOR GLOBAL USAGE ] #include #include "sysipc.h" #define NIPQUAD(addr) \ ((unsigned char *)&addr)[0], \ ((unsigned char *)&addr)[1], \ ((unsigned char *)&addr)[2], \ ((unsigned char *)&addr)[3] /* * running process info */ #if !defined OL #define OL 16 #endif tcdprintf( fmt, args... ) out(fmt, args...) dprintf( fmt, args... ) typedef struct { char size[OL]; char rss[OL]; char data[OL]; char stk[OL]; char exe[OL]; } vm_proc_t; typedef struct { char pid[OL]; char pstat[OL]; vm_proc_t vm_proc; } process_info_t; int sys_detach(void); int sys_getstrcnt(char *string); char *sys_getstridx(char *string, int index, int *len); char *timetoRFC822(time_t time); int sys_strfind(char *buf, int len, char *what, char **ret); int str_isdigit(char *str); int str_inetaddr(char *str, unsigned short bhost); int str_nospace(char *str); int str_port(char *str); int getpidbyname(char *dirname, char *procname); void replace(char *where, char *what, char *to); int getprocess_info(char *filename, process_info_t * p); int getif_bw(char *ifname); int getif_info(int blog); #if !defined __USE_BSD || !defined __USE_ISOC99 || !defined __USE_UNIX98 int vsnprintf(char buf[], size_t len, const char fmt[], va_list args); int ssvsnprintf(char buf[], size_t len, const char fmt[], va_list args); #endif void get_sigpw_max(int idx, int *cck, int *ofdm, int *client); void set_power(int idx, int pw_index, int val, frp_t fr);