Example #1
0
/*! \brief finds a connection, if id=0 uses the ip addr & port (host byte order)
 * \note WARNING: unprotected (locks) use tcpconn_get unless you really
 * know what you are doing */
struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
{

	struct tcp_connection *c;
	struct tcp_conn_alias* a;
	unsigned hash;
	
#ifdef EXTRA_DEBUG
	LM_DBG("%d  port %d\n",id, port);
	if (ip) print_ip("tcpconn_find: ip ", ip, "\n");
#endif
	if (id){
		hash=tcp_id_hash(id);
		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
#ifdef EXTRA_DEBUG
			LM_DBG("c=%p, c->id=%d, port=%d\n",c, c->id, c->rcv.src_port);
			print_ip("ip=", &c->rcv.src_ip, "\n");
#endif
			if ((id==c->id)&&(c->state!=S_CONN_BAD)) return c;
		}
	}else if (ip){
		hash=tcp_addr_hash(ip, port);
		for (a=tcpconn_aliases_hash[hash]; a; a=a->next){
#ifdef EXTRA_DEBUG
			LM_DBG("a=%p, c=%p, c->id=%d, alias port= %d port=%d\n", 
				a, a->parent, a->parent->id, a->port, a->parent->rcv.src_port);
			print_ip("ip=",&a->parent->rcv.src_ip,"\n");
#endif
			if ( (a->parent->state!=S_CONN_BAD) && (port==a->port) &&
					(ip_addr_cmp(ip, &a->parent->rcv.src_ip)) )
				return a->parent;
		}
	}
	return 0;
}
Example #2
0
bool get_route_entry(uint32_t network, uint32_t dest_ip,
                     char *interface, uint32_t *mask, uint32_t *next_hop,
                     uint32_t *metric) {

    router_entry *rentry = (router_entry*)find_entry(network);
    if (rentry == NULL) {
        printf("ROUTER: This should never happen\n");
        exit(1);
    }

    if ( (dest_ip & rentry->mask) != rentry->network ) {
        return false;
    }

    if (DEBUG) {
        uint32_t result_and = dest_ip & rentry->mask;
        printf("\n ANDED = ");
        print_ip(result_and);

        printf("\n Debug route: Dest ip:  ");
        print_ip(dest_ip);
        printf("  Network ip : ");
        print_ip(network);
        printf("\n");
    }

    *mask = rentry->mask;
    *next_hop = rentry->next_hop;
    *metric = rentry->metric;
    strcpy(interface, rentry->interface);

    return true;
}
Example #3
0
static void parse_arp(arp_hdr *a)
{
	char mac1[macbuf_size];
	char mac2[macbuf_size];
	char ip1[ipbuf_size];
	char ip2[ipbuf_size];

	print_mac(mac1, &a->snd_hw_addr);
	print_mac(mac2, &a->target_hw_addr);
	print_ip(ip1, &a->snd_prot_addr);
	print_ip(ip2, &a->target_prot_addr);

	if (PA_ARP) {
		switch(ntohs(a->op))
		{
			case arp_op_request:
				printf(" REQ from %s (%s) for %s\n", mac1, ip1, ip2);
				break;
			case arp_op_reply:
				printf(" REPLY from %s (%s), target = %s (%s)\n",
						mac1, ip1, mac2, ip2);
				break;
			case arp_op_rarp_request:
				printf(" RARP REQ from %s (%s) for %s\n", mac1, ip1, ip2);
				break;
			case arp_op_rarp_reply:
				printf(" RARP REPLY from %s (%s), target = %s (%s)\n",
						mac1, ip1, mac2, ip2);
				break;
		}
	}
}
Example #4
0
/* finds a connection, if id=0 uses the ip addr & port (host byte order)
 * WARNING: unprotected (locks) use tcpconn_get unless you really
 * know what you are doing */
struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port)
{

	struct tcp_connection *c;
	unsigned hash;
	
#ifdef EXTRA_DEBUG
	DBG("tcpconn_find: %d  port %d\n",id, port);
	print_ip("tcpconn_find: ip ", ip, "\n");
#endif
	if (id){
		hash=tcp_id_hash(id);
		for (c=tcpconn_id_hash[hash]; c; c=c->id_next){
#ifdef EXTRA_DEBUG
			DBG("c=%p, c->id=%d, port=%d\n",c, c->id, c->rcv.src_port);
			print_ip("ip=", &c->rcv.src_ip, "\n");
#endif
			if ((id==c->id)&&(c->state!=S_CONN_BAD)) return c;
		}
	}else if (ip){
		hash=tcp_addr_hash(ip, port);
		for (c=tcpconn_addr_hash[hash]; c; c=c->next){
#ifdef EXTRA_DEBUG
			DBG("c=%p, c->id=%d, port=%d\n",c, c->id, c->rcv.src_port);
			print_ip("ip=",&c->rcv.src_ip,"\n");
#endif
			if ( (c->state!=S_CONN_BAD) && (port==c->rcv.src_port) &&
					(ip_addr_cmp(ip, &c->rcv.src_ip)) )
				return c;
		}
	}
	return 0;
}
Example #5
0
void packet_in(uint8_t *data, uint16_t size)
{
    FullPacket p;


    /*    print_packet(data, size);*/
    proto_eth_demangle(&p.eth, data);
    printf("Eth received\r\n");

    if (!MAC_ADDR_EQUAL(p.eth.dst.addr, _bmac) && !MAC_ADDR_EQUAL(p.eth.dst.addr, simple_net_get_mac()))
        return;

    if (p.eth.type != PROTO_IP)
        return;

    proto_ip_demangle(&p.ip, data + IP_OFFSET);
    printf("IP received\r\n");
    printf("Src: ");
    print_ip(p.ip.src_addr);
    printf("\r\nDst: ");
    print_ip(p.ip.dst_addr);
    printf("\r\n");

    if (p.ip.protocol != PROTO_UDP)
        return;

    proto_udp_demangle(&p.udp, data + UDP_OFFSET);
    printf("UDP received %d %d\r\n", p.udp.src_port, p.udp.dst_port);

    if (p.udp.dst_port != DHCP_CLIENT_PORT || p.udp.src_port != DHCP_SERVER_PORT)
        return;
    printf("Received DHCP packet\r\n");
    proto_dhcp_demangle(&p.dhcp, data + DHCP_OFFSET);
    dhcp_process_packet(&p);
}
Example #6
0
int NSCLASS dsr_ack_opt_recv(struct dsr_ack_opt *ack)
{
	unsigned short id;
	struct in_addr dst, src, myaddr;
	int n;

	if (!ack)
		return DSR_PKT_ERROR;

	myaddr = my_addr();

	dst.s_addr = ack->dst;
	src.s_addr = ack->src;
	id = ntohs(ack->id);

	LOG_DBG("ACK dst=%s src=%s id=%u\n", print_ip(dst), print_ip(src), id);

	if (dst.s_addr != myaddr.s_addr)
		return DSR_PKT_ERROR;

	/* Purge packets buffered for this next hop */
	n = maint_buf_del_all_id(src, id);

	LOG_DBG("Removed %d packets from maint buf\n", n);
	
	return DSR_PKT_NONE;
}
void
print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr *gw)
{
    print_ip("Board IP:       ", ip);
    print_ip("Netmask :       ", mask);
    print_ip("Gateway :       ", gw);
}
Example #8
0
struct net* mk_new_net(struct ip_addr* ip, struct ip_addr* mask)
{
	struct net* n;
	int warning;
	int r;
	
	warning=0;
	if ((ip->af != mask->af) || (ip->len != mask->len)){
		LM_CRIT("trying to use a different mask family"
				" (eg. ipv4/ipv6mask or ipv6/ipv4mask)\n");
		goto error;
	}
	n=(struct net*)pkg_malloc(sizeof(struct net));
	if (n==0){ 
		LM_CRIT("memory allocation failure\n");
		goto error;
	}
	n->ip=*ip;
	n->mask=*mask;
	for (r=0; r<n->ip.len/4; r++) { /*ipv4 & ipv6 addresses are multiple of 4*/
		n->ip.u.addr32[r] &= n->mask.u.addr32[r];
		if (n->ip.u.addr32[r]!=ip->u.addr32[r]) warning=1;
	};
	if (warning){
		LM_WARN("invalid network address/netmask "
					"combination fixed...\n");
		print_ip("original network address:", ip, "/");
		print_ip("", mask, "\n");
		print_ip("fixed    network address:", &(n->ip), "/");
		print_ip("", &(n->mask), "\n");
	};
	return n;
error:
	return 0;
}
Example #9
0
void print_net(struct net* net)
{
	if (net==0){
		LOG(L_WARN, "ERROR: print net: null pointer\n");
		return;
	}
	print_ip("", &net->ip, "/"); print_ip("", &net->mask, "");
}
Example #10
0
void print_net(struct net* net)
{
	if (net==0){
		LM_WARN("null pointer\n");
		return;
	}
	print_ip("", &net->ip, "/"); print_ip("", &net->mask, "");
}
Example #11
0
void __forwarding_table_show_a(uint32_t subnet, uint32_t mask, uint32_t next_hop,
                               char * interface, void * userdata, int * finished)
{
    print_t print = (print_t)userdata;

    print_ip(subnet,print);print("\t");
    print_ip(mask,print);print("\t");
    print_ip(next_hop,print);print("\t");
    print("%s\n",interface);
}
Example #12
0
void border_printNodes(struct ip_list *list) {
    printf("Im Netz verfügbare Knoten:\n");
    int i;
    for (i = 0; i < size_ip(list); i++) {
        printf("%d: ", i);
        print_ip(get_ip(list, i));
        uint8_t *tmp = get_via(list, i);
        if (tmp != NULL) {
            printf(" via ");
            print_ip(tmp);
        }
        printf("\n");
    }
}
Example #13
0
//*******************************************************************************************
//
// Function : standby_display
// Description : display board status such as AVR ip, server ip, countdown time, temparature
//
//*******************************************************************************************
void standby_display ( void )
{
	BYTE generic_buf[64];

	// update lcd display flag not set, exit from function
	if ( flag1.bits.update_display == 0 )
		return;
	flag1.bits.update_display = 0;
	// lcd display is displaying other information, wait until busy flag clear
	if ( flag1.bits.lcd_busy )
		return;
	// now displaying menu information, wait until exit from menu
	if ( menu_index )
		return;

	// display status on lcd line 1
	lcd_putc ( '\f' );
	lcd_print ( (BYTE*)standby_list[ standby_cursor - 1 ] );

	// display status devices on lcd line 2
	lcd_putc ( '\n' );
	if ( standby_cursor == 1 )
	{
		print_devices (generic_buf,ind_device_cur);
		
	}
	// display avr ip
	if ( standby_cursor == 2 )
	{
		print_ip ( generic_buf, (BYTE*)&avr_ip, 0 );
	}
	// display server ip
	else if ( standby_cursor == 3 )
	{
		print_ip ( generic_buf, (BYTE*)&server_ip, 0 );
	}
	// display countdown timer
	else if ( standby_cursor == 4 )
	{
		print_time ( generic_buf, count_time, 0 );
	}
	// display current temparature
	else if ( standby_cursor == 5 )
	{
		print_temp ( generic_buf );
	}
	lcd_print ( generic_buf );
}
Example #14
0
//*******************************************************************************************
//
// Function : display_menu
// Description : display LCD user interface menu on LCD
//
//*******************************************************************************************
void display_menu(void)
{
	BYTE generic_buf[64];

	if( menu_index == 0)
		return;

	// display menu title on lcd first line
	lcd_putc( '\f' );
	lcd_print ( (BYTE *)menu_list[ menu_index - 1 ] );
	
	// display menu detail on lcd second line
	lcd_putc( '\n' );
	if( menu_index == 1 )//MENU_MAIN)
	{
		lcd_print( (BYTE *)menu_list[ submenu_index ] );
	}
	// setup avr ip address
	else if( menu_index == 2 )
	{
		print_ip ( generic_buf, (BYTE*)&avr_ip, setting_cursor+1 );
		lcd_print ( generic_buf );
	}
	// setup server ip address
	else if(menu_index == 3 )
	{
		print_ip ( generic_buf, (BYTE*)&server_ip, setting_cursor+1 );
		lcd_print ( generic_buf );
	}
	// setup countdown timer for send temparature
	else if ( menu_index == 4 )
	{
		print_time ( generic_buf, count_time, setting_cursor+1 );
		lcd_print ( generic_buf );
	}
	// ping server
	else if ( menu_index == 5 )
	{
		print_ip ( generic_buf, (BYTE*)&server_ip, 1 );
		lcd_print ( generic_buf );
	}
	// send temparature now
	//else if ( menu_index == 6 )
	//{
	//	lcd_put ( ASCII_CURSOR );
	//	lcd_print_p ( PSTR ( "OK" ) );
	//}
}
Example #15
0
static int kaodv_netlink_receive_peer(unsigned char type, void *msg,
				      unsigned int len)
{
	int ret = 0;
	struct kaodv_rt_msg *m;
	struct kaodv_conf_msg *cm;
	struct expl_entry e;

	KAODV_DEBUG("Received msg: %s", kaodv_msg_type_to_str(type));

	switch (type) {
	case KAODVM_ADDROUTE:
		if (len < sizeof(struct kaodv_rt_msg))
			return -EINVAL;

		m = (struct kaodv_rt_msg *)msg;

		ret = kaodv_expl_get(m->dst, &e);

		if (ret > 0) {
			ret = kaodv_expl_update(m->dst, m->nhop, m->time,
						m->flags, m->ifindex);
		} else {
			ret = kaodv_expl_add(m->dst, m->nhop, m->time,
					     m->flags, m->ifindex);
		}
		printk(KERN_DEBUG "kaodv: KAODVM_ADDROUTE!\n");
		kaodv_queue_set_verdict(KAODV_QUEUE_SEND, m->dst);
		break;
	case KAODVM_DELROUTE:
		if (len < sizeof(struct kaodv_rt_msg))
			return -EINVAL;

		m = (struct kaodv_rt_msg *)msg;
		kaodv_expl_del(m->dst);
		kaodv_queue_set_verdict(KAODV_QUEUE_DROP, m->dst);
		break;
	case KAODVM_NOROUTE_FOUND:
		if (len < sizeof(struct kaodv_rt_msg))
			return -EINVAL;

		m = (struct kaodv_rt_msg *)msg;
		KAODV_DEBUG("No route found for %s", print_ip(m->dst));
		kaodv_queue_set_verdict(KAODV_QUEUE_DROP, m->dst);
		break;
	case KAODVM_CONFIG:
		if (len < sizeof(struct kaodv_conf_msg))
			return -EINVAL;

		cm = (struct kaodv_conf_msg *)msg;
		active_route_timeout = cm->active_route_timeout;
		qual_th = cm->qual_th;
		is_gateway = cm->is_gateway;
		break;
	default:
		printk("kaodv-netlink: Unknown message type\n");
		ret = -EINVAL;
	}
	return ret;
}
Example #16
0
File: inarpd.c Project: ago/inarp
void add_route(device *dev, int family, unsigned char *ip)
{
	unsigned int i, len = (family == AF_INET ? IP_ADDR_LEN : IP6_ADDR_LEN);

	for (i = 0; i < dev->route_cnt; i++)
		if ((dev->route[i].family == family) &&
		    !memcmp(dev->route[i].peer, ip, len)) {
			dev->route[i].peer_time = time(NULL);
			return; /* already added */
		}

	if (i == MAX_ADDRESSES) {
		print_dbg(1, "Too many peer IP addresses on device %s\n",
				dev->name);
		return;
	}

	printf("Device %s peer IP is ", dev->name);
	print_ip(family, ip);
	putchar('\n');

	dev->route[dev->route_cnt].family = family;
	memcpy(dev->route[dev->route_cnt].peer, ip, len);
	dev->route[dev->route_cnt++].peer_time = time(NULL);
}
Example #17
0
int dsr_hw_header_create(struct dsr_pkt *dp, struct sk_buff *skb)
{

	struct sockaddr broadcast =
	    { AF_UNSPEC, {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} };
	struct neighbor_info neigh_info;

	if (dp->dst.s_addr == DSR_BROADCAST)
		memcpy(neigh_info.hw_addr.sa_data, broadcast.sa_data, ETH_ALEN);
	else {
		/* Get hardware destination address */
		if (neigh_tbl_query(dp->nxt_hop, &neigh_info) < 0) {
			DEBUG
			    ("Could not get hardware address for next hop %s\n",
			     print_ip(dp->nxt_hop));
			return -1;
		}
	}

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
	if (skb->dev->hard_header) {
		skb->dev->hard_header(skb, skb->dev, ETH_P_IP,
				      neigh_info.hw_addr.sa_data, 0, skb->len);
	} else {
		DEBUG("Missing hard_header\n");
		return -1;
	}
#else
	dev_hard_header(skb, skb->dev, ETH_P_IP,
			neigh_info.hw_addr.sa_data, 0, skb->len);	
#endif
	return 0;
}
Example #18
0
File: inarpd.c Project: ago/inarp
void expire_routes(void)
{
	device *dev = first;
	while (dev) {
		if (dev->active && dev->add_route) {
			unsigned int i = 0;
			while (i < dev->route_cnt) {
				if (time(NULL) - dev->route[i].peer_time >
				    INARP_TIMEOUT) {
					printf("Device %s peer ", dev->name);
					print_ip(dev->route[i].family,
						  dev->route[i].peer);
					printf(" is no longer active\n");
					dev->route_cnt--;
					memcpy(&dev->route[i],
					       &dev->route[i + 1],
					       (MAX_ADDRESSES - i - 1) *
					       sizeof(route_t));
					continue;
				}
				i++;
			}
		}
		dev = dev->next;
	}
}
Example #19
0
static void cmd_ping(BaseSequentialStream *chp, int argc, char *argv[])
{
    uint32_t remoteHostIp;
    (void)argv;
    if (argc != 1)
    {
        chprintf(chp, "Usage:\r\n");
        chprintf(chp, "ping <hostname>\r\n");
        return;
    }


    chprintf(chp,"Looking up IP of %s...\r\n", argv[0]);
    gethostbyname(argv[0], strlen(argv[0]), &remoteHostIp);
    chprintf(chp,"Pinging...", NULL); print_ip(chp, (const char *) &remoteHostIp);
    remoteHostIp = htonl(remoteHostIp);

    memset((void *)&cc3000AsyncData.ping, 0, sizeof(cc3000AsyncData.ping));
    netapp_ping_send(&remoteHostIp, 3, 10, 3000);

    while (cc3000AsyncData.ping.present != TRUE)
    {
        chThdSleep(MS2ST(100));
    }
    chprintf(chp,"--Ping Results--:\r\n", NULL);
    chprintf(chp,"Number of Packets Sent: %u\r\n", cc3000AsyncData.ping.report.packets_sent);
    chprintf(chp,"Number of Packet Received: %u\r\n", cc3000AsyncData.ping.report.packets_received);
    chprintf(chp,"Min Round Time: %u\r\n", cc3000AsyncData.ping.report.min_round_time);
    chprintf(chp,"Max Round Time: %u\r\n", cc3000AsyncData.ping.report.max_round_time);
    chprintf(chp,"Avg Round Time: %u\r\n", cc3000AsyncData.ping.report.avg_round_time);
    chprintf(chp,"--End of Ping Results--\r\n", NULL);

}
Example #20
0
void dhcp_process_packet(FullPacket *p)
{
    DhcpHead *dhcp = &p->dhcp;
    uint8_t *current = dhcp->options + 4;

    for ( ; current <= dhcp->options + 64 && *current != OPTION_END; current += current[1]+2 /* 2 == size of code + len */)
    {
        if (*current != OPTION_DHCP_MESSAGE_TYPE)
            continue;
        switch(current[2])
        {
        case DHCPOFFER:
            printf("DHCPOFFER ip: ");
            print_ip(dhcp->yiaddr);
            printf("\r\n");
            dhcp_request(p);
            return;
        case DHCPACK:
            printf("ACK Received\r\n");
            dhcp_handle_ack(p);
            return;
        default:
            break;
        }
    }
}
Example #21
0
static void parse_dhcp_clnt(dhcp *d)
{
	char ip1[ipbuf_size];
	char ip2[ipbuf_size];
	char ip3[ipbuf_size];
	char ip4[ipbuf_size];

	print_ip(ip1, &d->clnt_addr);
	print_ip(ip2, &d->your_addr);
	print_ip(ip3, &d->server_addr);
	print_ip(ip4, &d->gateway_addr);

	printf("    [DHCP/Clnt] op %x ", d->op);
	printf("CLNT %s YOUR %s\n", ip1, ip2);
	printf("                SRV %s GW %s\n", ip3, ip4);
}
Example #22
0
void do_ip( char * data )
{
	global.packet_ip ++;

	struct iphdr *pip;         
	pip = ( struct iphdr * ) data;    /* pip = point to ip layer */
	if( global.print_flag_ip )
		print_ip( pip );
	
	char * pdata = data + pip->ihl * 4;
	
	switch( pip->protocol ){
		case IPPROTO_ICMP:
			do_icmp( pdata );
			break;
		case IPPROTO_IGMP:
			do_igmp( pdata );
			break;
		case IPPROTO_TCP:
			do_tcp( pdata );
			break;
		case IPPROTO_UDP:
			do_udp( pdata );
			break;
		default:
			printf("IP: 未知其上层协议.\n");
			break;
	}
}
Example #23
0
void do_ip(void *p)
{
	struct iphdr *ip = p;

	g.packet_ip++;

	if(g.print_flag_ip)
		print_ip(ip);

	void *data = ip;

	data += ip->ihl << 2;

	switch(ip->protocol)
	{
		case IPPROTO_TCP:
			do_tcp(data);
			break;
		case IPPROTO_UDP:
			do_udp(data);
			break;
		case IPPROTO_ICMP:
			do_icmp(data);
			break;
		case IPPROTO_IGMP:
			do_igmp(data);
			break;
	}
}
Example #24
0
void dhcp_handle_ack(FullPacket *p)
{
    printf("DHCP Server: ");
    print_ip(ntohl(dhcp_get_option_simple(p->dhcp.options+4, OPTION_DHCP_SERVER_IDENTIFIER)));
    printf("\r\n");

    printf("My ip: ");
    print_ip(p->dhcp.yiaddr);
    printf("\r\n");
    printf("Subnet mask: ");
    print_ip(ntohl(dhcp_get_option_simple(p->dhcp.options+4, OPTION_SUBNET_MASK)));
    printf("\r\n");
    printf("Router: ");
    print_ip(ntohl(dhcp_get_option_simple(p->dhcp.options+4, OPTION_ROUTER)));
    printf("\r\n");
    printf("Lease time: %d s\r\n", ntohl(dhcp_get_option_simple(p->dhcp.options+4, OPTION_DHCP_LEASE_TIME)));
}
Example #25
0
void print_iphdr(struct iphdr *ip)
{
	print_boundary();
	printf("|");

	print_data(ip->version,1,0);

	print_data(ip->ihl,10,0);

	print_data(ip->tos,100,0);

	print_data(ntohs(ip->tot_len),10000,1);

	print_boundary();
	printf("|");

	print_data(ip->id,10000,3);

	print_data(ip->frag_off,10000,1);

	print_boundary();
	printf("|");

	print_data(ip->ttl,100,1);

	print_data(ip->protocol,100,0);

	print_data(ip->check,10000,1);

	print_boundary();
	printf("|");

	struct sockaddr_in s;

	s.sin_addr.s_addr=ip->saddr;
	print_ip(s);

	print_boundary();
	printf("|");

	s.sin_addr.s_addr=ip->daddr;
	print_ip(s);

	print_boundary();
	printf("\n\n");
}
Example #26
0
struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
									struct socket_info* ba, int type, 
									int state)
{
	struct tcp_connection *c;
	
	c=(struct tcp_connection*)shm_malloc(sizeof(struct tcp_connection));
	if (c==0){
		LM_ERR("shared memory allocation failure\n");
		goto error;
	}
	memset(c, 0, sizeof(struct tcp_connection)); /* zero init */
	c->s=sock;
	c->fd=-1; /* not initialized */
	if (lock_init(&c->write_lock)==0){
		LM_ERR("init lock failed\n");
		goto error;
	}
	
	c->rcv.src_su=*su;
	
	c->refcnt=0;
	su2ip_addr(&c->rcv.src_ip, su);
	c->rcv.src_port=su_getport(su);
	c->rcv.bind_address=ba;
	if (ba){
		c->rcv.dst_ip=ba->address;
		c->rcv.dst_port=ba->port_no;
	}
	print_ip("tcpconn_new: new tcp connection to: ", &c->rcv.src_ip, "\n");
	LM_DBG("on port %d, type %d\n", c->rcv.src_port, type);
	init_tcp_req(&c->req);
	c->id=(*connection_id)++;
	c->rcv.proto_reserved1=0; /* this will be filled before receive_message*/
	c->rcv.proto_reserved2=0;
	c->state=state;
	c->extra_data=0;
#ifdef USE_TLS
	if (type==PROTO_TLS){
		if (tls_tcpconn_init(c, sock)==-1) goto error;
	}else
#endif /* USE_TLS*/
	{
		c->type=PROTO_TCP;
		c->rcv.proto=PROTO_TCP;
		c->timeout=get_ticks()+tcp_con_lifetime;
	}
	c->flags|=F_CONN_REMOVED;
	
	tcp_connections_no++;
	return c;
	
error:
	if (c) shm_free(c);
	return 0;
}
Example #27
0
static l4_uint16_t parse_ip(ip_hdr *ip)
{
	char ip1[ipbuf_size];
	char ip2[ipbuf_size];

	print_ip(ip1, &ip->src_addr);
	print_ip(ip2, &ip->dest_addr);

	unsigned char hlen = (ip->ver_hlen & 0x0F) * sizeof(int);

#if 0
	printf("  [IP] version %d, hlen %d, services %d, plen %d, id %d\n",
	       (ip->ver_hlen & 0xF0) >> 4,
	       (ip->ver_hlen & 0x0F),
	       ip->services,
	       ntohs(ip->plen),
	       ntohs(ip->id));
	printf("       flags %x, offset %x, ttl %d, proto %s (%d)\n",
	       (ntohs(ip->flags_frag_offset) & 0x70000000) >> 13,
	       (ntohs(ip->flags_frag_offset) & 0x1FFFFFFF),
	       ip->ttl, ip_proto_str(ip->proto), ip->proto);
	printf("       csum %x, src %s, dest %s\n",
	       ntohs(ip->checksum), ip1, ip2);
#endif

	switch(ip->proto)
	{
		case ip_proto_icmp:
			if (PA_ICMP) parse_icmp((icmp_hdr*)((char*)ip + hlen));
			return ip_proto_icmp;
			break;
		case ip_proto_tcp:
			if (PA_TCP) parse_tcp((tcp_hdr*)((char*)ip + hlen));
			return ip_proto_tcp;
			break;
		case ip_proto_udp:
			if (PA_UDP)  ;
			return parse_udp((udp_hdr*)((char*)ip + hlen));
			break;
		default:
			break;
	}
}
Example #28
0
static struct tcp_connection* tcpconn_new(int sock, union sockaddr_union* su,
							struct socket_info* si, int state, int flags)
{
	struct tcp_connection *c;

	c=(struct tcp_connection*)shm_malloc(sizeof(struct tcp_connection));
	if (c==0){
		LM_ERR("shared memory allocation failure\n");
		return 0;
	}
	memset(c, 0, sizeof(struct tcp_connection)); /* zero init */
	c->s=sock;
	c->fd=-1; /* not initialized */
	if (lock_init(&c->write_lock)==0){
		LM_ERR("init lock failed\n");
		goto error0;
	}

	c->rcv.src_su=*su;

	c->refcnt=0;
	su2ip_addr(&c->rcv.src_ip, su);
	c->rcv.src_port=su_getport(su);
	c->rcv.bind_address = si;
	c->rcv.dst_ip = si->address;
	c->rcv.dst_port = si->port_no;
	print_ip("tcpconn_new: new tcp connection to: ", &c->rcv.src_ip, "\n");
	LM_DBG("on port %d, proto %d\n", c->rcv.src_port, si->proto);
	c->id=(*connection_id)++;
	c->rcv.proto_reserved1=0; /* this will be filled before receive_message*/
	c->rcv.proto_reserved2=0;
	c->state=state;
	c->extra_data=0;
	c->type = si->proto;
	c->rcv.proto = si->proto;
	/* start with the default conn lifetime */
	c->lifetime = get_ticks()+tcp_con_lifetime;
	c->flags|=F_CONN_REMOVED|flags;

	if (protos[si->proto].net.conn_init &&
	protos[si->proto].net.conn_init(c)<0) {
		LM_ERR("failed to do proto %d specific init for conn %p\n",
			si->proto,c);
		goto error1;
	}

	tcp_connections_no++;
	return c;

error1:
	lock_destroy(&c->write_lock);
error0:
	shm_free(c);
	return 0;
}
Example #29
0
void dijkstra_print_links_list( linked_list_t *links )
{
	list_item_t *link;

	printf( "---- start print_links (length: %d) --\n", links->length );
	printf( "----  TO  -----+------ Weight ---+\n" );

	for ( link= links->head; link != NULL; link= link->next ) {
		uint32_t temp= *((uint32_t*)link->data);
		if ( temp == INFINITY )
			printf( "%s\t|\tINF\n",
				print_ip(link->key) );
		else
			printf( "%s\t|\t%d\n",
				print_ip(link->key),
				temp );
	}

	printf( "---- end print_links (length: %d) --\n", links->length );
}
Example #30
0
void dijkstra_print_links( links_t *links )
{
	link_from_t *node;
	link_to_t *link;

	printf( "---- start print_links (length: %d) --\n", links->length );
	printf( "----- FROM -----+----  TO  -----+------ Weight ---+\n" );

	for ( node= links->head; node != NULL; node= node->next_node ) {
		for (link= node->links; link != NULL; link= link->next_link) {
			printf( "---- \t%s\t|\t",
				print_ip(node->ip) );
			printf( "%s\t|\t%d\n",
				print_ip(link->ip),
				link->distance );
		}
	}

	printf( "---- end print_links (length: %d) --\n", links->length );
}