void udp_out(struct finsFrame* ff) { /* read the FDF and make sure everything is correct*/ if (ff->dataOrCtrl != 0) { // release FDF here return; } if (ff->dataFrame.directionFlag != 1) { // release FDF here return; } if (ff->destinationID != UDPID) { // release FDF here return; } struct udp_packet packet; struct udp_metadata_parsed* meta = ff->dataFrame.metaData; /* constructs the UDP packet from the FDF and the meta data */ unsigned char* ptrToPDU = ff->dataFrame.pdu; /* assigns a pointer to the PDU location*/ ptrToPDU -= U_HEADER_LEN; /* moves the pointer 8 bytes to account for those empty 8 bytes*/ memcpy(&packet.u_data,ptrToPDU, ff->dataFrame.pduLength); /* Copies the actual data into the data section of the UDP packet. The +U_HEADER_LEN is because of leaving 8 bytes free in the input Queue */ packet.u_dst = meta->u_destPort; /* gets the destination port from the metadata */ packet.u_src = meta->u_srcPort; /* gets the source port from the metadata */ packet.u_len = ff->dataFrame.pduLength + U_HEADER_LEN; /* calculates the UDP length by adding the UDP header length to the length of the data */ meta->u_pslen = packet.u_len; meta->u_prcl = UDP_PROTOCOL; packet.u_cksum = 0; /* stores a value of zero in the checksum field so that it can be calculated */ packet.u_cksum = UDP_checksum(&packet, meta); /* calculates ands stores the real checksum in the checksum field */ /* need to be careful in the line ^ above ^, the metadata needs to have the source and destination IPS in order to calculate the checksum */ //printf("The checksum Value is %d", packet.u_cksum); memcpy(&(ff->dataFrame.pdu), &packet, U_HEADER_LEN); /* copies the UDP packet into the memory that has been allocated for the PDU */ /* creates a new FDF to be sent out */ struct finsFrame* newFF = create_ff(DATA, DOWN, IPID, packet.u_len, ff->dataFrame.pdu, ff->dataFrame.metaData); udpStat.totalSent++; //sendToSwitch(newFDF); }
void udp_in(struct finsFrame* ff) { PRINT_DEBUG("UDP_in has been just called"); /* read the FDF and make sure everything is correct*/ if (ff->dataOrCtrl != 0) { // release FDF here PRINT_ERROR("it is not data"); return; } if (ff->dataFrame.directionFlag != 0) { // release FDF here PRINT_ERROR("wrong direction"); return; } if (ff->destinationID != UDPID) { // release FDF here PRINT_ERROR("wrong destination ID"); return; } /* point to the necessary data in the FDF */ struct udp_packet* packet = (struct udp_packet*)ff->dataFrame.pdu; struct udp_metadata_parsed* meta = (struct udp_metadata_parsed*)ff->dataFrame.metaData; /* begins checking the UDP packets integrity */ if (meta->u_pslen != htons(packet->u_len)) { PRINT_DEBUG("UDP length:%u", packet->u_len); udpStat.mismatchingLengths++; udpStat.totalBadDatagrams ++; PRINT_ERROR("wrong length"); return; } if (meta->u_prcl != UDP_PROTOCOL) { udpStat.wrongProtocol++; udpStat.totalBadDatagrams++; PRINT_ERROR("it is not UDP segment, I wont parse it"); return; } /* the packet is does not have an "Ignore checksum" value and fails the checksum, it is thrown away */ if (packet->u_cksum != IGNORE_CHEKSUM ){ if(UDP_checksum(packet, meta) != 0) { udpStat.badChecksum++; udpStat.totalBadDatagrams ++; PRINT_ERROR("checksum ERROR"); return; } }else{ udpStat.noChecksum++; } /* put the header into the meta data*/ meta->u_destPort = packet->u_dst; meta->u_srcPort = packet->u_src; /* construct a FDF to send to the sockets */ ff->dataFrame.pdu += U_HEADER_LEN; struct finsFrame newFF; newFF = create_ff(DATA, UP, SOCKETSTUBID, ((int)(ff->dataFrame.pdu) - U_HEADER_LEN), (ff->dataFrame.pdu), (unsigned char*)meta); sendToSwitch(&newFF); }
Program compile_ff_program(int flags) { const auto shader_input = create_ff(flags); return compile_program(shader_input.vs, shader_input.fs, shader_input.debug_name); }
void udp_out(struct finsFrame* ff) { struct finsFrame* newFF; struct udp_metadata_parsed parsed_meta; /* read the FDF and make sure everything is correct*/ if (ff->dataOrCtrl != DATA) { // release FDF here return; } if (ff->dataFrame.directionFlag != DOWN) { // release FDF here return; } if (ff->destinationID.id != UDPID) { // release FDF here return; } PRINT_DEBUG("UDP_out"); print_finsFrame(ff); struct udp_header packet; struct udp_packet check_packet; u_char test[100]; metadata* meta = (ff->dataFrame).metaData; u_char *udp_dataunit = (u_char *)malloc( (ff->dataFrame).pduLength + U_HEADER_LEN ); /** constructs the UDP packet from the FDF and the meta data */ PRINT_DEBUG("%d", ff->dataFrame.pduLength); uint32_t dstbuf; uint32_t srcbuf; uint32_t dstip; uint32_t srcip; PRINT_DEBUG("UDP_out"); metadata_readFromElement(meta,"dstport",&dstbuf); metadata_readFromElement(meta,"srcport",&srcbuf); metadata_readFromElement(meta,"dstip",&dstip); metadata_readFromElement(meta,"srcip",&srcip); /** fixing the values because of the conflict between uint16 type and * the 32 bit META_INT_TYPE */ packet.u_dst = dstbuf; packet.u_src = srcbuf; PRINT_DEBUG("%d, %d", (packet.u_dst),(packet.u_src)); (packet.u_dst) = htons(packet.u_dst); (packet.u_src) = htons(packet.u_src); /* calculates the UDP length by adding the UDP header length to the length of the data */ int packet_length; packet_length= ( ((ff->dataFrame).pduLength) + U_HEADER_LEN );; packet.u_len = htons( ((ff->dataFrame).pduLength) + U_HEADER_LEN ); /** TODO ignore the checksum for now * Will be fixed later */ /** Invalidation disabled value = 0xfed2*/ parsed_meta.u_destPort = htons( packet.u_dst); parsed_meta.u_srcPort = htons( packet.u_src); parsed_meta.u_IPdst = htonl( dstip); parsed_meta.u_IPsrc = htonl( dstip); parsed_meta.u_pslen = htons( packet_length); parsed_meta.u_prcl = htons( UDP_PROTOCOL); packet.u_cksum = 0; memcpy(&check_packet,&packet,U_HEADER_LEN); memcpy(&check_packet,ff->dataFrame.pdu,ff->dataFrame.pduLength); packet.u_cksum = UDP_checksum(&check_packet,&parsed_meta); /* stores a value of zero in the checksum field so that it can be calculated */ PRINT_DEBUG("%d,%d,%d,%d", packet.u_src,packet.u_dst,packet.u_len,packet.u_cksum); // packet.u_cksum = UDP_checksum(&packet, meta); /* calculates ands stores the real checksum in the checksum field */ /* need to be careful in the line ^ above ^, the metadata needs to have the source and destination IPS in order to calculate the checksum */ //printf("The checksum Value is %d", packet.u_cksum); int i=0; while (i < ff->dataFrame.pduLength) { PRINT_DEBUG("%d",ff->dataFrame.pdu[i]); i++; } PRINT_DEBUG("UDP_out"); memcpy(udp_dataunit, &packet, U_HEADER_LEN); /* copies the UDP packet into the memory that has been allocated for the PDU */ // PRINT_DEBUG("%d, %d",(ff->dataFrame).pdu, ff->dataFrame.pduLength); memcpy(udp_dataunit + U_HEADER_LEN ,(ff->dataFrame).pdu, ff->dataFrame.pduLength); /* moves the pointer 8 bytes to account for those empty 8 bytes*/; // PRINT_DEBUG("%d",packet.u_len); /** memcpy(test, udp_dataunit, packet_length); test [packet_length] = '\0'; i=0; while (i < packet_length) { PRINT_DEBUG("%d",test[i]); i++; } //free (ff->dataFrame.pdu); PRINT_DEBUG("%s",test); PRINT_DEBUG("%d",udp_dataunit); */ ff->dataFrame.pdu = udp_dataunit; /* creates a new FDF to be sent out */ PRINT_DEBUG("%d",ff->dataFrame.pdu); PRINT_DEBUG("UDP_out"); newFF = create_ff(DATA, DOWN, IPV4ID, packet_length, ff->dataFrame.pdu, ff->dataFrame.metaData); PRINT_DEBUG("%d",newFF->dataFrame.pdu); print_finsFrame(newFF); udpStat.totalSent++; PRINT_DEBUG("UDP_out"); sendToSwitch(newFF); }