From e560c727a5a29b4cf90c08d1b722059614cf5af5 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sun, 11 Jan 2015 21:32:39 +0000 Subject: [PATCH] More strict message checking. FossilOrigin-Name: 66228f5dc19b06d83bb49d77bafd74155b88cb8e6633c34b400bd0633f7111b3 --- src/capwap/cwread_discovery_response.c | 54 ++++++++++++++++++++------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/capwap/cwread_discovery_response.c b/src/capwap/cwread_discovery_response.c index f7453548..7de9deaf 100644 --- a/src/capwap/cwread_discovery_response.c +++ b/src/capwap/cwread_discovery_response.c @@ -30,31 +30,61 @@ #include +struct eparm { + int *mand; + struct ac_info *acinfo; +}; -static int acinfo_readelem_discovery_resp(void * a,int type,uint8_t* msgelem,int len) + +static int acinfo_readelem_discovery_resp(void * eparm,int type,uint8_t* msgelem,int len) { - - struct ac_info * acinfo = (struct ac_info *)a; - cw_log_debug1("Process discovery resp msgelem, type=%d, len=%d\n",type,len); - - if (acinfo_readelem_ac_descriptor(acinfo,type,msgelem,len)) - return 1; - - if (acinfo_readelem_ac_name(acinfo,type,msgelem,len)) - return 1; + cw_dbg_msgelem(CWMSG_DISCOVERY_RESPONSE, type, msgelem, len); - if (acinfo_readelem_ctrl_ip_addr(acinfo,type,msgelem,len)) + struct eparm *e = (struct eparm *) eparm; + + + if (acinfo_readelem_ac_descriptor(e->acinfo,type,msgelem,len)) + goto foundX; + + if (acinfo_readelem_ac_name(e->acinfo,type,msgelem,len)) + goto foundX; + + if (acinfo_readelem_ctrl_ip_addr(e->acinfo,type,msgelem,len)){ + cw_mand_elem_found(e->mand, XCWMSGELEM_CAPWAP_CONTROL_IP_ADDRESS); return 1; + } return 0; + + foundX: + cw_mand_elem_found(e->mand, type); + return 1; + } void cwread_discovery_response(struct ac_info * acinfo, uint8_t * msg, int len) { - cw_foreach_msgelem(msg,len,acinfo_readelem_discovery_resp,acinfo); + int mand[] = { + CWMSGELEM_AC_DESCRIPTOR, + CWMSGELEM_AC_NAME, + XCWMSGELEM_CAPWAP_CONTROL_IP_ADDRESS, + XCWMSGELEM_CAPWAP_RADIO_INFO, + + -1 + }; + + + struct eparm eparm; + eparm.acinfo = acinfo; + eparm.mand = mand; + + + cw_foreach_msgelem(msg,len,acinfo_readelem_discovery_resp,&eparm); + + cw_dbg_missing_mand_elems_(0, CWMSG_DISCOVERY_RESPONSE, eparm.mand); }