int zmq::curve_server_t::process_handshake_command (msg_t *msg_) { int rc = 0; switch (state) { case expect_hello: rc = process_hello (msg_); break; case expect_initiate: rc = process_initiate (msg_); break; default: // Temporary support for security debugging puts ("CURVE I: invalid handshake command"); errno = EPROTO; rc = -1; break; } if (rc == 0) { rc = msg_->close (); errno_assert (rc == 0); rc = msg_->init (); errno_assert (rc == 0); } return rc; }
int zmq::curve_server_t::process_handshake_command (msg_t *msg_) { int rc = 0; switch (state) { case waiting_for_hello: rc = process_hello (msg_); break; case waiting_for_initiate: rc = process_initiate (msg_); break; default: // TODO I think this is not a case reachable with a misbehaving // client. It is not an "invalid handshake command", but would be // trying to process a handshake command in an invalid state, // which is purely under control of this peer. // Therefore, it should be changed to zmq_assert (false); // CURVE I: invalid handshake command session->get_socket ()->event_handshake_failed_protocol ( session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNSPECIFIED); errno = EPROTO; rc = -1; break; } if (rc == 0) { rc = msg_->close (); errno_assert (rc == 0); rc = msg_->init (); errno_assert (rc == 0); } return rc; }
int zmq::curve_server_t::process_handshake_message (msg_t *msg_) { int rc = 0; switch (state) { case expect_hello: rc = process_hello (msg_); if (rc == 0) state = send_welcome; break; case expect_initiate: rc = process_initiate (msg_); if (rc == 0) state = expecting_zap_reply? expect_zap_reply: send_ready; break; default: errno = EPROTO; rc = -1; break; } if (rc == 0) { rc = msg_->close (); errno_assert (rc == 0); rc = msg_->init (); errno_assert (rc == 0); } return rc; }
void process_packet(int socket) { unsigned char *buffer; int size = 0; struct sockaddr_in recv_addr; struct iphdr *ipheader; struct ospfhdr *ospfheader; unsigned int iphdr_len, recv_addr_len; struct ospf_interface *oiface; buffer = malloc(sizeof(*buffer)*REPLAY_PACKET_BUFFER); memset(&recv_addr,0,sizeof(recv_addr)); recv_addr_len = sizeof(recv_addr); size = recvfrom(socket, buffer, REPLAY_PACKET_BUFFER, 0, (struct sockaddr *)&recv_addr, &recv_addr_len); if(size>0) { oiface = find_oiface_by_socket(socket); if(recv_addr.sin_addr.s_addr != oiface->iface->ip.s_addr) { ipheader = (struct iphdr *)buffer; iphdr_len = ipheader->ihl*4; ospfheader = (struct ospfhdr *)(buffer+iphdr_len); switch(ospfheader->mesg_type) { case OSPF_MESG_HELLO: process_hello(buffer+iphdr_len,ipheader->saddr,ipheader->daddr,((unsigned int)ntohs(ospfheader->packet_length)),oiface); break; case OSPF_MESG_DBDESC: process_dbdesc(buffer+iphdr_len,ipheader->saddr,ipheader->daddr,((unsigned int)ntohs(ospfheader->packet_length)),oiface); break; case OSPF_MESG_LSR: process_lsr(buffer+iphdr_len,ipheader->saddr,ipheader->daddr,((unsigned int)ntohs(ospfheader->packet_length)),oiface); break; case OSPF_MESG_LSU: process_lsu(buffer+iphdr_len,ipheader->saddr,ipheader->daddr,((unsigned int)ntohs(ospfheader->packet_length)),oiface); break; case OSPF_MESG_LSACK: process_lsack(buffer+iphdr_len,ipheader->saddr,ipheader->daddr,((unsigned int)ntohs(ospfheader->packet_length)),oiface); break; } } } else { //error reading in packet } free(buffer); }
int zmq::plain_mechanism_t::process_handshake_command (msg_t *msg_) { int rc = 0; switch (state) { case waiting_for_hello: rc = process_hello (msg_); if (rc == 0) state = expecting_zap_reply? waiting_for_zap_reply: sending_welcome; break; case waiting_for_welcome: rc = process_welcome (msg_); if (rc == 0) state = sending_initiate; break; case waiting_for_initiate: rc = process_initiate (msg_); if (rc == 0) state = sending_ready; break; case waiting_for_ready: rc = process_ready (msg_); if (rc == 0) state = ready; break; default: // Temporary support for security debugging puts ("PLAIN I: invalid handshake command"); errno = EPROTO; rc = -1; break; } if (rc == 0) { rc = msg_->close (); errno_assert (rc == 0); rc = msg_->init (); errno_assert (rc == 0); } return rc; }
/** * Processes a received HELLO message. */ void olsr_process_received_hello(struct olsrv2 *olsr, struct message_header *m, union olsr_ip_addr *in_if, union olsr_ip_addr *from_addr) { struct hello_message message; if (hello_change_structure(olsr, &message, m) == OLSR_FALSE) {// wiss: bi 3abi kell el ma3loumet bel "message" w iza fet lahon ma3neta tghayar el form ...bisir bi tayer el message //Fix for Memory Loss // wiss: sar fi deformation bel message men tayerou olsr_free_hello_packet(&message); return; } process_hello(olsr, &message, in_if, from_addr); olsr_free_hello_packet(&message); olsr->stat.numHelloReceived++; if(DEBUG_OLSRV2) { olsr_printf("Increment Hello Message Received Count to %d\n", olsr->stat.numHelloReceived); } return; }
void *recv_loop(void *p) { uint8_t buf[BUFFER_SIZE]; interface *iface; ospf_header *ospfhdr; neighbor *nbr; in_addr_t src; while (*(int *)p) { iface = recv_ospf(sock, buf, BUFFER_SIZE, &src); ospfhdr = (ospf_header *)(buf + sizeof(struct iphdr)); /* check if the packet is from myself */ if (ospfhdr->router_id == myid) continue; for (nbr = iface->nbrs; nbr; nbr = nbr->next) if (ospfhdr->router_id == nbr->router_id) break; switch (ospfhdr->type) { case OSPF_TYPE_HELLO: process_hello(iface, nbr, ospfhdr, src); break; case OSPF_TYPE_DD: process_dd(iface, nbr, ospfhdr); break; case OSPF_TYPE_LSR: process_lsr(nbr, ospfhdr);break; case OSPF_TYPE_LSU: process_lsu(iface->a, nbr, ospfhdr);break; case OSPF_TYPE_LSACK: process_ack(nbr, ospfhdr);break; default: break; } } return NULL; }
int ipc_evaluate_message(union olsr_message *olsr_in) { int ipc_pack = 0; olsr_u8_t type; int msgsize; char itoa_buf[10]; olsr_u8_t vtime; union olsr_ip_addr *originator; /* Find size, vtime, originator and type - same for IPv4 and 6 */ type = olsr_in->v4.olsr_msgtype; msgsize = ntohs(olsr_in->v4.olsr_msgsize); vtime = olsr_in->v4.olsr_vtime; originator = (union olsr_ip_addr *)&olsr_in->v4.originator; gui_itoa(msgsize, itoa_buf); switch (type) { case HELLO_MESSAGE: //printf("Received HELLO packet\n"); if (!freeze_packets) packet_list_add("HELLO", ip_to_string(originator), itoa_buf); if (ipversion == AF_INET) { process_hello(msgsize, vtime, originator, (union hello_message *)&olsr_in->v4.message.hello); } else { process_hello(msgsize, vtime, originator, (union hello_message *)&olsr_in->v6.message.hello); } break; case TC_MESSAGE: if (!freeze_packets) packet_list_add("TC", ip_to_string(originator), itoa_buf); if (ipversion == AF_INET) { process_tc(msgsize, vtime, originator, (union tc_message *)&olsr_in->v4.message.tc); //printf("Received TC packet from %s\n", ip_to_string(&m->olsr_tc->tc_origaddr)); } else { process_tc(msgsize, vtime, originator, (union tc_message *)&olsr_in->v6.message.tc); //printf("Received TC packet from %s\n", ip_to_string(&m->olsr_tc->tc_origaddr)); } break; case MID_MESSAGE: if (!freeze_packets) packet_list_add("MID", ip_to_string(originator), itoa_buf); if (ipversion == AF_INET) { process_mid(msgsize, vtime, originator, (union mid_message *)&olsr_in->v4.message.mid); //printf("Received MID packet from %s\n", ip_to_string(&m->olsr_mid->mid_origaddr)); } else { process_mid(msgsize, vtime, originator, (union mid_message *)&olsr_in->v6.message.mid); //printf("Received MID packet from %s\n", ip_to_string(&m->olsr_mid->mid_origaddr)); } break; case HNA_MESSAGE: if (!freeze_packets) packet_list_add("HNA", ip_to_string(originator), itoa_buf); if (ipversion == AF_INET) { process_hna(msgsize, vtime, originator, (union hna_message *)&olsr_in->v4.message.hna); //printf("Received HNA packet\n"); } else { process_hna(msgsize, vtime, originator, (union hna_message *)&olsr_in->v6.message.hna); //printf("Received HNA packet\n"); } break; case IPC_MESSAGE: //printf("Received IPC packet\n"); ipc_pack = 1; /* Don't add to buffer */ ipc_eval_route_packet((struct routemsg *)olsr_in); break; case IPC_NET: //printf("Received IPC packet\n"); ipc_pack = 1; /* Don't add to buffer */ ipc_eval_net_info((struct netmsg *)olsr_in); break; default: if (!freeze_packets) { char unk_label[8]; sprintf(unk_label, "%d", type); packet_list_add(unk_label, ip_to_string(originator), itoa_buf); } printf("Unknown packet type %d\n", type); break; } if (!freeze_packets && !ipc_pack) { add_packet_to_buffer(olsr_in, msgsize); } return 1; }