bool EVEPacketDispatcher::DispatchPacket( PyPacket* packet ) { switch( packet->type ) { case AUTHENTICATION_REQ: { //check the string part, just for good measure if( packet->type_string != "macho.AuthenticationReq" ) { sLog.Error("EVEPacketDispatcher","Received AUTHENTICATION_RSP with invalid type string '%s'", packet->type_string.c_str()); return false; } AuthenticationReq req; if( !req.Decode( packet->payload ) ) { sLog.Error("EVEPacketDispatcher","Failed to decode AuthenticationReq"); return false; } return Handle_AuthenticationReq( packet, req ); } case AUTHENTICATION_RSP: { //check the string part, just for good measure if( packet->type_string != "macho.AuthenticationRsp" ) { sLog.Error("EVEPacketDispatcher","Received AUTHENTICATION_RSP with invalid type string '%s'", packet->type_string.c_str()); return false; } AuthenticationRsp rsp; if( !rsp.Decode( packet->payload ) ) { sLog.Error("EVEPacketDispatcher","Failed to decode AuthenticationRsp"); return false; } return Handle_AuthenticationRsp( packet, rsp ); } case CALL_REQ: { //check the string part, just for good measure if( packet->type_string != "macho.CallReq" ) { sLog.Error("EVEPacketDispatcher","Received CALL_REQ with invalid type string '%s'", packet->type_string.c_str()); return false; } PyCallStream call; if( !call.Decode( packet->type_string, packet->payload )) { sLog.Error("EVEPacketDispatcher","Failed to convert packet into a call stream"); return false; } return Handle_CallReq( packet, call ); } case CALL_RSP: { //check the string part, just for good measure if( packet->type_string != "macho.CallRsp" ) { sLog.Error("EVEPacketDispatcher","Received CALL_RSP with invalid type string '%s'", packet->type_string.c_str()); return false; } //TODO: decode substream in tuple return Handle_CallRsp( packet ); } break; case NOTIFICATION: { //check the string part, just for good measure if( packet->type_string != "macho.Notification" ) { sLog.Error("EVEPacketDispatcher","Received NOTIFICATION with invalid type string '%s'", packet->type_string.c_str()); return false; } return Handle_Notify( packet ); } case ERRORRESPONSE: { //check the string part, just for good measure if( packet->type_string != "macho.ErrorResponse" ) { sLog.Error("EVEPacketDispatcher","Received ERRORRESPONSE with invalid type string '%s'", packet->type_string.c_str()); return false; } ErrorResponse error; if( !error.Decode( packet->payload ) ) { sLog.Error("EVEPacketDispatcher","Failed to decode Error Response"); return false; } return Handle_ErrorResponse( packet, error ); } case SESSIONCHANGENOTIFICATION: { //check the string part, just for good measure if( packet->type_string != "macho.SessionChangeNotification" ) { sLog.Error("EVEPacketDispatcher","Received SESSIONCHANGENOTIFICATION with invalid type string '%s'", packet->type_string.c_str()); return false; } SessionChangeNotification sessionChange; if( !sessionChange.Decode( packet->payload ) ) { sLog.Error("EVEPacketDispatcher","Failed to decode session change notification"); return false; } return Handle_SessionChange( packet, sessionChange ); } case PING_REQ: { //check the string part, just for good measure if( packet->type_string != "macho.PingReq" ) { sLog.Error("EVEPacketDispatcher","Received PING_REQ with invalid type string '%s'", packet->type_string.c_str()); return false; } return Handle_PingReq( packet ); } case PING_RSP: { //check the string part, just for good measure if( packet->type_string != "macho.PingRsp" ) { sLog.Error("EVEPacketDispatcher","Received PING_RSP with invalid type string '%s'", packet->type_string.c_str()); return false; } return Handle_PingRsp( packet ); } default: { return Handle_Other( packet ); } } }
int bbgp() { unsigned char buf[BGP_SIZE]; struct bgp *bgp_hdr; int n; // handle the open negotiations if (handle_bgp_open()) { // return if they fail return(0); } // send our update with our one route if (Send_Update()) { return(0); } // established loop while ((n = read(STDIN_FILENO, buf, BGP_SIZE)) == BGP_SIZE) { // handle update/notification/keepalive messages bgp_hdr = (struct bgp *)buf; switch(bgp_hdr->bgp_type) { case BGP_NOTIFICATION: // if (debug) fprintf(stderr,"Received BGP Notification\n"); // pass this off to the notification message handler if (Handle_Notify(bgp_hdr->bgp_len)) { return (-1); } break; case BGP_KEEPALIVE: // if (debug) fprintf(stderr,"Received BGP Keepalive\n"); // make sure the keepalive is of valid length if (bgp_hdr->bgp_len != htons(BGP_SIZE)) { bgp_send_notification(BGP_NOTIFY_MAJOR_MSG, BGP_NOTIFY_MINOR_MSG_LEN); return(-1); } // store the time when we received this peer.last_ack = time(NULL); // if (debug) print_rib(); break; case BGP_UPDATE: // pass this off to the update message handler // if (debug) fprintf(stderr,"Received BGP Update length %d\n", ntohs(bgp_hdr->bgp_len)); if (Handle_Update(ntohs(bgp_hdr->bgp_len))) { return(-1); } break; default: // invalid type // if (debug) fprintf(stderr,"Received invalid message type (%d)\n", bgp_hdr->bgp_type); bgp_send_notification(BGP_NOTIFY_MAJOR_MSG, BGP_NOTIFY_MINOR_MSG_TYPE); return(-1); } } // if we got here, the while loop received an invalid length bgp packet // if (debug) fprintf(stderr,"Received invalid length (%d) packet, errno: %s\n", n, sys_errlist[errno]); fflush(stderr); bgp_send_notification(BGP_NOTIFY_MAJOR_MSG, BGP_NOTIFY_MINOR_MSG_LEN); return(-1); }