Esempio n. 1
0
int w_check_rtcp_ipport(msg_t *msg)
{

	int i = 0;
	miprtcp_t *mp = NULL;
	char ipptmp[256];
	char callid[256];


	snprintf(callid, sizeof(callid), "%.*s", msg->sip.callId.len, msg->sip.callId.s);

	for (i = 0; i < msg->sip.mrp_size; i++) {
		mp = &msg->sip.mrp[i];

		if (mp->rtcp_ip.len > 0 && mp->rtcp_ip.s) {
			snprintf(ipptmp, sizeof(ipptmp), "%.*s:%d", mp->rtcp_ip.len, mp->rtcp_ip.s, mp->rtcp_port);			
			LDEBUG("RTCP CALLID: %.*s", msg->sip.callId.len, msg->sip.callId.s);
			LDEBUG("RTCP IP PORT: %s", ipptmp);

			/* one pair = one timer */
			if(!find_and_update(ipptmp, callid))			
			{
			       add_timer(ipptmp);			
                               add_ipport(ipptmp, callid);
                        }
		}
	}

	return 1;
}
Esempio n. 2
0
int dump_rtp_packet(struct pcap_pkthdr *pkthdr, u_char *packet, uint8_t proto, unsigned char *data, uint32_t len,
                 const char *ip_src, const char *ip_dst, uint16_t sport, uint16_t dport, uint8_t flags,
                                  uint16_t hdr_offset, uint8_t frag, uint16_t frag_offset, uint32_t frag_id, uint32_t ip_ver) {

        struct timeval tv;
        time_t curtime;
	char timebuffer[30];	
	rc_info_t *rcinfo = NULL;
        unsigned char *senddata;	        
        int json_len;
        
        gettimeofday(&tv,NULL);

        sendPacketsCount++;

        curtime = tv.tv_sec;
        strftime(timebuffer,30,"%m-%d-%Y  %T.",localtime(&curtime));

        if(len < 5) {
             LERR("rtcp the message is too small: %d\n", len);
             return -1;
        }

        LDEBUG("GOT RTCP %s:%d -> %s:%d. LEN: %d\n", ip_src, sport, ip_dst, dport, len);

        if(find_and_update(sip_callid, ip_src, sport, ip_dst, dport) == 0) {

            return 0;
        }
	
	if(rtcp_as_json) {		
            json_rtcp_buffer[0] = '\0';	
      	    if((json_len = capt_parse_rtcp((char *)data, len, json_rtcp_buffer, sizeof(json_rtcp_buffer))) > 0) {
      	          senddata = json_rtcp_buffer;
      	          len = strlen(json_rtcp_buffer);
      	    }
      	    else {
      	    	LDEBUG("GOODBYE or APP MESSAGE. Ignore!\n");
      	    	return 0;
      	    }
      	    
      	    LDEBUG("JSON RTCP %s\n", json_rtcp_buffer);
        }
        else senddata = data;

	rcinfo = malloc(sizeof(rc_info_t));
	memset(rcinfo, 0, sizeof(rc_info_t));
	
	LDEBUG("CALLID RTCP %s\n", sip_callid);

        rcinfo->src_port   = sport;
        rcinfo->dst_port   = dport;
        rcinfo->src_ip     = ip_src;
        rcinfo->dst_ip     = ip_dst;
        rcinfo->ip_family  = ip_ver = 4 ? AF_INET : AF_INET6 ;
        rcinfo->ip_proto   = proto;
        rcinfo->time_sec   = pkthdr->ts.tv_sec;
        rcinfo->time_usec  = pkthdr->ts.tv_usec;
        rcinfo->proto_type = rtcp_proto_type;
        /* correlation stuff */
        rcinfo->correlation_id.len = strlen(sip_callid);
        rcinfo->correlation_id.s = &sip_callid;
                        
        if(debug_proto_rtcp_enable)
            LDEBUG("SENDING PACKET: Len: [%d]\n", len);

	/* Duplcate */
	if(!send_message(rcinfo, senddata, (unsigned int) len)) {
	         LERR("Not duplicated\n");
        }        
        
        if(rcinfo) free(rcinfo);

	return 1;
}
Esempio n. 3
0
int handle_ip_pkt(struct sr_instance* sr, uint8_t* Pkt, char* interface, unsigned int len, uint8_t srcMAC[]) {

    //actually I have to pass in a uint8_t* packet not an sr_ip_pkt...

    /*
     Extract the IP header
     Header actions:
     1) check the IP checksum
     -> discard if wrong
     2) check if TTL expired
     -> send ICMP type 11 (0)
     3) check if it is our message
     -> if yes jump to "OURS:"
     Not Ours:
     1) Find the next hop in rtable
     2) Decrement TTL, recalculate Checksum
     3) Assemble new packet
     4) Send on correct interface

     OURS:
     1) Check type of packet
     -> ICMP
     -> UDP/TCP

     ICMP:
     1) Check type
     2) respond as appropriate

     UDP/TCP
     1) Pass up the stack

     */
    assert(Pkt);
    assert(sr);
    assert(interface);

    //struct sr_router* subsystem = (struct sr_router*)sr_get_subsystem(sr);
    struct sr_vns_if* myIntf = sr_get_interface(sr, interface);
    uint32_t myIP = myIntf->ip;

    struct ip* pktHdr = (struct ip*)Pkt;
    uint8_t* payload = (uint8_t*)malloc_or_die(len - 20);
    uint8_t* ptr = Pkt + 20;
    memcpy(payload, ptr, len-20);

    uint32_t originIP = pktHdr->ip_src.s_addr;

    //first thing is to update ARP - no point wasiting useful information is there!
    time_t now = time(NULL);
    int checkArp;
    checkArp = find_and_update(sr, originIP, srcMAC, now);

    if(pktHdr->ip_hl != 5) {
        //means there were IP options so unerachable (host or network?)
        printf("@@@@@@@@@@@@@@@@@@@@@@@@@@      IP hdr length was %u. Should have been 5 (e.g. 20 bytes)\n", pktHdr->ip_hl);
        uint8_t* data = (uint8_t*)malloc_or_die(28);
        memcpy(data, Pkt, 28);
        int tmp;
        tmp = create_ICMP_pkt(sr, interface, originIP, 3, 1, 0, 0, data, 28);
        return -3;
    }

    if(cksum((uint8_t*)pktHdr, 20)) {
        printf("@@@@@@@@@@@@@@@@@@@@@@    CHECKSUM 0x%hx WAS INVALID SO WE WILL DROP THE PACKET\n", pktHdr->ip_sum);
        return -2;
    }

    if(pktHdr->ip_ttl < 2) {
        printf("@@@@@@@@@@@@@@@@@@@@@@    TTL has expired so we will send back an ICMP\n");
        //get the data (IP hdr + 8 bytes of packet)
        uint8_t* data = (uint8_t*)malloc_or_die(28);
        memcpy(data, Pkt, 28);
        int tmp;
        tmp = create_ICMP_pkt(sr, interface, originIP, 11, 0, 0, 0, data, 28);
        return -1;
    }

    if(check_my_interface(sr, (uint32_t)pktHdr->ip_dst.s_addr)) {

        // printf("This is my packet so I will process it\n");

        switch(pktHdr->ip_p) {
        case IPPROTO_ICMP:
            ;
            //printf("\nThis is an IP ICMP packet of length %d\n", len);
            // printf("After removing the IP header we are left with %d bytes\n", datalen);
            int datalen = len - sizeof(struct ip);
            uint8_t* ICMP = (uint8_t*) malloc_or_die(datalen);
            //ICMP = array_cpy(Pkt->payload, datalen);
            memcpy(ICMP, payload, datalen);
            int tmp;
            tmp = process_ICMP_pkt(sr, interface, originIP, ICMP, datalen);
            return tmp;

        case IPPROTO_TCP:
            printf("TCP packet sent up the stack\n");
            sr_transport_input(Pkt);
            return 1;
        default:
            return 0;
        }
    }
    else {
        //printf("**********  Not my packet, so I will forward it\n");
        return 3;
    }
    return 0;
}