Example #1
0
void log_pkt_fields(AODV_msg * msg)
{

    RREQ *rreq;
    RREP *rrep;
    RERR *rerr;

    switch (msg->type) {
    case AODV_RREQ:
	rreq = (RREQ *) msg;
	log(LOG_DEBUG, 0,
	    "rreq->flags:%s rreq->hopcount=%d rreq->rreq_id=%ld",
	    rreq_flags_to_str(rreq), rreq->hcnt, ntohl(rreq->rreq_id));
	log(LOG_DEBUG, 0, "rreq->dest_addr:%s rreq->dest_seqno=%lu",
	    ip_to_str(ntohl(rreq->dest_addr)), ntohl(rreq->dest_seqno));
	log(LOG_DEBUG, 0, "rreq->source_addr:%s rreq->orig_seqno=%ld",
	    ip_to_str(ntohl(rreq->orig_addr)), ntohl(rreq->orig_seqno));
	break;
    case AODV_RREP:
	rrep = (RREP *) msg;
	log(LOG_DEBUG, 0, "rrep->flags:%s rrep->hcnt=%d",
	    rrep_flags_to_str(rrep), rrep->hcnt);
	log(LOG_DEBUG, 0, "rrep->dest_addr:%s rrep->dest_seqno=%d",
	    ip_to_str(ntohl(rrep->dest_addr)), ntohl(rrep->dest_seqno));
	log(LOG_DEBUG, 0, "rrep->orig_addr:%s rrep->lifetime=%d",
	    ip_to_str(ntohl(rrep->orig_addr)), ntohl(rrep->lifetime));
	break;
    case AODV_RERR:
	rerr = (RERR *) msg;
	log(LOG_DEBUG, 0, "rerr->dest_count:%d", rerr->dest_count);
	break;
    }
}
Example #2
0
void
rrep_ack_process(RREP_ack * rrep_ack, int rrep_acklen, u_int32_t ip_src,
		 u_int32_t ip_dst)
{
    rt_table_t *rt_entry;

    rt_entry = rt_table_find(ip_src);

    if (rt_entry == NULL) {
#ifdef DEBUG
	log(LOG_WARNING, 0,
	    "rrep_ack_process: No RREP_ACK expected for %s",
	    ip_to_str(ip_src));
#endif
	return;
    }
#ifdef DEBUG
    log(LOG_DEBUG, 0, "rrep_ack_process: Received RREP_ACK from %s",
	ip_to_str(ip_src));
#endif

    /* Remove unexpired timer for this RREP_ACK */
    if (rt_entry->ack_timer.used)
	timer_remove(&rt_entry->ack_timer);
}
Example #3
0
void precursor_add(rt_table_t *rt_entry, u_int32_t addr) {
  precursor_t *pr_entry;

  /* Sanity check */
  if(rt_entry == NULL)
    return;

  pr_entry = rt_entry->precursors;

  /* Check if the node is already in the precursors list. */
  for (; pr_entry != NULL; pr_entry = pr_entry->next)
    if (pr_entry->neighbor == addr) 
      return;

  if((pr_entry = (precursor_t *) malloc(sizeof(precursor_t))) == NULL) {
    perror("Could not allocate memory for precursor node!!\n");
    exit(-1);
  }
#ifdef DEBUG
  log(LOG_INFO, 0, "precursor_add: Adding precursor %s to rte %s", 
      ip_to_str(addr), ip_to_str(rt_entry->dest));
#endif
  /* Insert first in precursors list */
  pr_entry->neighbor = addr;
  pr_entry->next = rt_entry->precursors;
  rt_entry->precursors = pr_entry;
}
Example #4
0
void precursor_remove(rt_table_t *rt_entry, u_int32_t addr) {
  precursor_t *curr, *prev;
  
  /* Sanity check */
  if(rt_entry == NULL)
    return;

  prev = NULL;
  curr = rt_entry->precursors;
 
  while(curr != NULL) {
    if(curr->neighbor == addr) { /* <----- SEGFAULT HERE */
#ifdef DEBUG
      log(LOG_INFO, 0, "precursor_remove: Removing precursor %s from rte %s", 
	  ip_to_str(addr), ip_to_str(rt_entry->dest));
#endif
      if(prev == NULL)
	/* We are about to remove the first entry.. */
	rt_entry->precursors = curr->next;
      else 
	prev->next = curr->next;

      free(curr);
      return;
    }
    prev = curr;
    curr = curr->next;
  }
}
Example #5
0
/* This is called when we stop receiveing hello messages from a
   node. For now this is basically the same as a route timeout. */
void NS_CLASS hello_timeout(void *arg)
{
    rt_table_t *rt;
    struct timeval now;

    rt = (rt_table_t *) arg;

    if (!rt)
        return;

    gettimeofday(&now, NULL);

    DEBUG(LOG_DEBUG, 0, "LINK/HELLO FAILURE %s last HELLO: %d",
          ip_to_str(rt->dest_addr), timeval_diff(&now, &rt->last_hello_time));

    if (rt && rt->state == VALID && !(rt->flags & RT_UNIDIR)) {

        /* If the we can repair the route, then mark it to be
           repaired.. */
        if (local_repair && rt->hcnt <= MAX_REPAIR_TTL) {
            rt->flags |= RT_REPAIR;
            DEBUG(LOG_DEBUG, 0, "Marking %s for REPAIR",
                  ip_to_str(rt->dest_addr));
#ifdef NS_PORT
            /* Buffer pending packets from interface queue */
            interfaceQueue((nsaddr_t) rt->dest_addr.s_addr, IFQ_BUFFER);
#endif
        }
        neighbor_link_break(rt);
    }
}
Example #6
0
bool mysql_save_http_data(THttpStats* data_item)
{
    if(comm_mysql_connect() != COMM_MYSQL_OK)
    {
        fprintf(stderr, "[HTTP] Could not connect to DB\n");
        return false;
    }

    MYSQL* con = comm_mysql_get_connection();

    char* str_src_ip;
    char* str_dst_ip;
    ip_to_str(data_item->source_ip, &str_src_ip);
    ip_to_str(data_item->destination_ip, &str_dst_ip);

    char query[COMM_MYSQL_QUERY_SIZE];

    sprintf(query, " \
        SELECT * FROM HttpAnalyzerDatas \
        WHERE SourceIp = \'%s\' AND DestinationIp = \'%s\' AND Method = \'%d\'",
        str_src_ip, str_dst_ip, data_item->method);
    mysql_query(con, query);
    MYSQL_RES* result = mysql_store_result(con);

    if(mysql_num_rows(result) > 0)
    {
        sprintf(query, " \
            UPDATE HttpAnalyzerDatas \
            SET Quantity= %u \
            WHERE SourceIp = \'%s\' AND DestinationIp = \'%s\' AND Method = \'%d\'",
            data_item->quantity,
            str_src_ip, str_dst_ip, data_item->method);
        mysql_query(con, query);
    }
Example #7
0
static void dissect_vektor_igrp (tvbuff_t *tvb, proto_tree *igrp_vektor_tree, guint8 network)
{
	proto_item *ti;
	guint8 *ptr_addr,addr[5];

	addr[0]=network;
	addr[1]=tvb_get_guint8(tvb,0);
	addr[2]=tvb_get_guint8(tvb,1);
	addr[3]=tvb_get_guint8(tvb,2);
	addr[4]=0;

	ptr_addr=addr;
	if (network==0) ptr_addr=&addr[1];

	ti = proto_tree_add_text (igrp_vektor_tree, tvb, 0 ,14,
	  "Entry for network %s", ip_to_str(ptr_addr)) ;
	igrp_vektor_tree =  proto_item_add_subtree(ti,ett_igrp_net);
	proto_tree_add_text (igrp_vektor_tree, tvb, 0 ,3,"Network     = %s",ip_to_str(ptr_addr)) ;
	proto_tree_add_text (igrp_vektor_tree, tvb, 3 ,3,"Delay       = %d",tvb_get_ntoh24(tvb,3)) ;
	proto_tree_add_text (igrp_vektor_tree, tvb, 6 ,3,"Bandwidth   = %d",tvb_get_ntoh24(tvb,6)) ;
	proto_tree_add_text (igrp_vektor_tree, tvb, 9 ,2,"MTU         = %d  bytes",tvb_get_ntohs(tvb,9)) ;
	proto_tree_add_text (igrp_vektor_tree, tvb, 11,1,"Reliability = %d",tvb_get_guint8(tvb,11)) ;
	proto_tree_add_text (igrp_vektor_tree, tvb, 12,1,"Load        = %d",tvb_get_guint8(tvb,12)) ;
	proto_tree_add_text (igrp_vektor_tree, tvb, 13,1,"Hop count   = %d  hops",tvb_get_guint8(tvb,13)) ;
}
Example #8
0
/* this will build libpcap filter text that will only
   pass the packets related to the stream. There is a
   chance that two streams could intersect, but not a
   very good one */
char*
build_follow_filter( packet_info *pi ) {
  char* buf;
  int len;
  conversation_t *conv=NULL;
  struct tcp_analysis *tcpd;

  if( ((pi->net_src.type == AT_IPv4 && pi->net_dst.type == AT_IPv4) ||
       (pi->net_src.type == AT_IPv6 && pi->net_dst.type == AT_IPv6))
	&& pi->ipproto == IP_PROTO_TCP 
        && (conv=find_conversation(pi->fd->num, &pi->src, &pi->dst, pi->ptype,
              pi->srcport, pi->destport, 0)) != NULL ) {
    /* TCP over IPv4 */
    tcpd=get_tcp_conversation_data(conv, pi);
    if (tcpd) {
      buf = g_strdup_printf("tcp.stream eq %d", tcpd->stream);
      tcp_stream_to_follow = tcpd->stream;
      if (pi->net_src.type == AT_IPv4) {
        len = 4;
        is_ipv6 = FALSE;
      } else {
        len = 16;
        is_ipv6 = TRUE;
      }
    } else {
      return NULL;
    }
  }
  else if( pi->net_src.type == AT_IPv4 && pi->net_dst.type == AT_IPv4
	   && pi->ipproto == IP_PROTO_UDP ) {
  /* UDP over IPv4 */
    buf = g_strdup_printf(
	     "(ip.addr eq %s and ip.addr eq %s) and (udp.port eq %d and udp.port eq %d)",
	     ip_to_str((guint8 *)pi->net_src.data),
	     ip_to_str((guint8 *)pi->net_dst.data),
	     pi->srcport, pi->destport );
    len = 4;
    is_ipv6 = FALSE;
  }
  else if( pi->net_src.type == AT_IPv6 && pi->net_dst.type == AT_IPv6
	&& pi->ipproto == IP_PROTO_UDP ) {
    /* UDP over IPv6 */
    buf = g_strdup_printf(
	     "(ipv6.addr eq %s and ipv6.addr eq %s) and (udp.port eq %d and udp.port eq %d)",
	     ip6_to_str((const struct e_in6_addr *)pi->net_src.data),
	     ip6_to_str((const struct e_in6_addr *)pi->net_dst.data),
	     pi->srcport, pi->destport );
    len = 16;
    is_ipv6 = TRUE;
  }
  else {
    return NULL;
  }
  memcpy(ip_address[0], pi->net_src.data, len);
  memcpy(ip_address[1], pi->net_dst.data, len);
  port[0] = pi->srcport;
  port[1] = pi->destport;
  return buf;
}
Example #9
0
void hello_send(void *arg) {
  RREP *rrep;
  AODV_ext *ext = NULL;
  u_int8_t flags = 0;
  u_int64_t time_expired;
  rt_table_t *entry;
  int msg_size = RREP_SIZE;

  time_expired = get_currtime() - this_host->bcast_time;

  /* This check will ensure we don't send unnecessary hello msgs, in case
     we have sent other bcast msgs within HELLO_INTERVAL */
  if (time_expired >= HELLO_INTERVAL) {
    
#ifdef DEBUG_HELLO
    log(LOG_DEBUG, 0, "SEND_BCAST: sending Hello to %s", 
	ip_to_str(AODV_BROADCAST));   
#endif
    rrep = rrep_create(flags, 0, 0, this_host->ipaddr, this_host->seqno, 
		       this_host->ipaddr, ALLOWED_HELLO_LOSS*HELLO_INTERVAL);
    
    /* Assemble a RREP extension which contain our neighbor set... */
    if(unidir_hack) {
      u_int32_t neigh;
      int i;
      
      ext = (AODV_ext *)((char *)rrep + RREP_SIZE);
      ext->type = RREP_HELLO_NEIGHBOR_SET_EXT;
      ext->length = 0;
      for(i = 0; i < RT_TABLESIZE; i++) {
	entry = routing_table[i];
	while(entry != NULL) {
	  /* If an entry has an active hello timer, we asume that we are
	     receiving hello messages from that node... */
	  if(entry->hello_timer_id != 0) {
#ifdef DEBUG_HELLO
	    log(LOG_INFO, 0, "hello_send: Adding %s to hello neighbor set ext",
		ip_to_str(entry->dest));
#endif
	    neigh = htonl(entry->dest);
	    memcpy(AODV_EXT_NEXT(ext), &neigh, 4);
	    ext->length += 4;
	  }
	  entry = entry->next;
	}
      }
      if(ext->length)
	msg_size = RREP_SIZE + AODV_EXT_SIZE(ext);    
    }
    
    aodv_socket_send((AODV_msg *)rrep, AODV_BROADCAST, msg_size, 1);
    
    timer_new(HELLO_INTERVAL, hello_send, NULL);
  }
  else {
    timer_new((HELLO_INTERVAL - time_expired), hello_send, NULL);
  }
}
void NS_CLASS local_repair_timeout(void *arg)
{
    rt_table_t *rt;
    struct in_addr rerr_dest;
    RERR *rerr = NULL;

    rt = (rt_table_t *) arg;

    if (!rt)
        return;

    rerr_dest.s_addr = AODV_BROADCAST;	/* Default destination */

    /* Unset the REPAIR flag */
    rt->flags &= ~RT_REPAIR;

#ifndef NS_PORT
    nl_send_del_route_msg(rt->dest_addr, rt->next_hop, rt->hcnt);
#endif
    /* Route should already be invalidated. */

    if (rt->nprec) {

        rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno);

        if (rt->nprec == 1) {
            rerr_dest = FIRST_PREC(rt->precursors)->neighbor;

            aodv_socket_send((AODV_msg *) rerr, rerr_dest,
                             RERR_CALC_SIZE(rerr), 1,
                             &DEV_IFINDEX(rt->ifindex));
        } else {
            int i;

            for (i = 0; i < MAX_NR_INTERFACES; i++) {
                if (!DEV_NR(i).enabled)
                    continue;
                aodv_socket_send((AODV_msg *) rerr, rerr_dest,
                                 RERR_CALC_SIZE(rerr), 1,
                                 &DEV_NR(i));
            }
        }
        DEBUG(LOG_DEBUG, 0, "Sending RERR about %s to %s",
              ip_to_str(rt->dest_addr), ip_to_str(rerr_dest));
    }
    precursor_list_destroy(rt);

    /* Purge any packets that may be queued */
    /* packet_queue_set_verdict(rt->dest_addr, PQ_DROP); */

    rt->rt_timer.handler = &NS_CLASS route_delete_timeout;
    timer_set_timeout(&rt->rt_timer, DELETE_PERIOD);

    DEBUG(LOG_DEBUG, 0, "%s removed in %u msecs",
          ip_to_str(rt->dest_addr), DELETE_PERIOD);
}
static void
dissect_aruba_adp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_tree *ti = NULL;
  proto_tree *aruba_adp_tree = NULL;
  guint16 type;
  const guint8 *src_mac;
  const guint8 *switchip;


  col_set_str(pinfo->cinfo, COL_PROTOCOL, "ADP");
  col_clear(pinfo->cinfo, COL_INFO);


  if (tree) {
    ti = proto_tree_add_item(tree, proto_aruba_adp, tvb, 0, 0, FALSE);
    aruba_adp_tree = proto_item_add_subtree(ti, ett_aruba_adp);

    proto_tree_add_item(aruba_adp_tree, hf_adp_version, tvb, 0, 2, FALSE);
  }
  type = tvb_get_ntohs(tvb, 2);

  if (tree) {
    proto_tree_add_item(aruba_adp_tree, hf_adp_type, tvb, 2, 2, FALSE); 

    proto_tree_add_item(aruba_adp_tree, hf_adp_id, tvb, 4, 2, FALSE);
  }

  switch(type){
    case ADP_REQUEST:

      proto_tree_add_item(aruba_adp_tree, hf_adp_mac, tvb, 6, 6, FALSE);
      src_mac = tvb_get_ptr(tvb, 6, 6);

      if (check_col(pinfo->cinfo, COL_INFO))
        col_add_fstr(pinfo->cinfo, COL_INFO, "ADP Request Src MAC: %s", ether_to_str(src_mac));

      proto_item_append_text(ti, ", Request Src MAC: %s", ether_to_str(src_mac));
      break;
     
    case ADP_RESPONSE:
       
      proto_tree_add_item(aruba_adp_tree, hf_adp_switchip, tvb, 6, 4, FALSE);
      switchip = tvb_get_ptr(tvb, 6, 4);
        
      if (check_col(pinfo->cinfo, COL_INFO))
        col_add_fstr(pinfo->cinfo, COL_INFO, "ADP Response Switch IP: %s", ip_to_str(switchip));
     
      proto_item_append_text(ti, ", Response Switch IP: %s", ip_to_str(switchip)); 
      break;
      
    default:
        break;
        
  }
}
Example #12
0
void NS_CLASS rrep_send(RREP * rrep, rt_table_t * rev_rt,
			rt_table_t * fwd_rt, int size)
{
	u_int8_t rrep_flags = 0;
	struct in_addr dest;

	if (!rev_rt) {
		DEBUG(LOG_WARNING, 0, "Can't send RREP, rev_rt = NULL!");
		return;
	}

	dest.s_addr = rrep->dest_addr;

	/* Check if we should request a RREP-ACK */
	if ((rev_rt->state == VALID && rev_rt->flags & RT_UNIDIR) ||
	    (rev_rt->hcnt == 1 && unidir_hack)) {
		rt_table_t *neighbor = rt_table_find(rev_rt->next_hop);

		if (neighbor && neighbor->state == VALID
		    && !neighbor->ack_timer.used) {
			/* If the node we received a RREQ for is a neighbor we are
			   probably facing a unidirectional link... Better request a
			   RREP-ack */
			rrep_flags |= RREP_ACK;
			neighbor->flags |= RT_UNIDIR;

			/* Must remove any pending hello timeouts when we set the
			   RT_UNIDIR flag, else the route may expire after we begin to
			   ignore hellos... */
			timer_remove(&neighbor->hello_timer);
			neighbor_link_break(neighbor);

			DEBUG(LOG_DEBUG, 0, "Link to %s is unidirectional!",
			      ip_to_str(neighbor->dest_addr));

			timer_set_timeout(&neighbor->ack_timer, NEXT_HOP_WAIT);
		}
	}

	DEBUG(LOG_DEBUG, 0, "Sending RREP to next hop %s about %s->%s",
	      ip_to_str(rev_rt->next_hop), ip_to_str(rev_rt->dest_addr),
	      ip_to_str(dest));

	aodv_socket_send((AODV_msg *) rrep, rev_rt->next_hop, size, MAXTTL,
			 &DEV_IFINDEX(rev_rt->ifindex));

	/* Update precursor lists */
	if (fwd_rt) {
		precursor_add(fwd_rt, rev_rt->next_hop);
		precursor_add(rev_rt, fwd_rt->next_hop);
	}

	if (!llfeedback && optimized_hellos)
		hello_start();
}
Example #13
0
rt_table_t *rt_table_update(rt_table_t * rt_entry, u_int32_t next,
			    u_int8_t hops, u_int32_t seqno,
			    u_int32_t newlife, u_int16_t flags)
{
    int ret;
    
    /* If this previously was an expired route, but will now be active again
       we must add it to the kernel routing table... */
    if (rt_entry->hcnt == INFTY && hops != INFTY) {
	rt_entry->rt_timer.handler = route_expire_timeout;
	ret = k_add_rte(rt_entry->dest_addr, next, 0, hops, rt_entry->ifindex);

	if (ret < 0)
	    log(LOG_WARNING, errno, 
		"rt_table_update: Could not add kernel route!");
#ifdef DEBUG
	else
	    log(LOG_INFO, 0,
		"rt_table_update: Added kernel route for expired %s",
		ip_to_str(rt_entry->dest_addr));
#endif
    } else if (rt_entry->next_hop != 0 && 
	       rt_entry->next_hop != next) {
#ifdef DEBUG
	log(LOG_INFO, 0, "rt_table_update: rt_entry->nxt_addr=%s, next=%s",
	    ip_to_str(rt_entry->next_hop), ip_to_str(next));
#endif
	precursor_list_destroy(rt_entry);
	ret = k_chg_rte(rt_entry->dest_addr, next, 0, hops, rt_entry->ifindex);
    
	if (ret < 0)
	    log(LOG_WARNING, errno, 
		"rt_table_update: Could not update kernel route!");
    }
    
    rt_entry->dest_seqno = seqno;
    rt_entry->last_life = newlife;
    rt_entry->flags = flags;
    rt_entry->next_hop = next;
    rt_entry->last_hcnt = rt_entry->hcnt;
    rt_entry->hcnt = hops;

    if (hops > 1) {
	rt_entry->last_hello_time.tv_sec = 0;
	rt_entry->last_hello_time.tv_usec = 0;
	rt_entry->hello_cnt = 0;
    }
    /* If newlife = 0 the timer and the expire time should not be
       updated... */
    if (newlife != 0)
	rt_table_update_timeout(rt_entry, newlife);

    return rt_entry;
}
Example #14
0
void udpService( )
{
  static DhcpState prevState = DhcpStateNone;
  
  // poll() queries the DHCP library for its current state (all possible values
  // are shown in the switch statement below). This way, you can find out if a
  // lease has been obtained or is in the process of being renewed, without
  // blocking your sketch. Therefore, you could display an error message or
  // something if a lease cannot be obtained within reasonable time.
  // Also, poll() will actually run the DHCP module, just like maintain(), so
  // you should call either of these two methods at least once within your
  // loop() section, or you risk losing your DHCP lease when it expires!
  DhcpState state = EthernetDHCP.poll();

  if (prevState != state) {

    switch (state) {
      case DhcpStateDiscovering:
        p("DHCP Discover\n");
        break;
      case DhcpStateRequesting:
        Serial.print("DHCP Request\n");
        break;
      case DhcpStateRenewing:
        Serial.print("DHCP Renew\n");
        break;
      case DhcpStateLeased: {
        Serial.println("DHCP Obtained\n");

        // Since we're here, it means that we now have a DHCP lease, so we
        // print out some information.
        const byte* ipAddr = EthernetDHCP.ipAddress();
        const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
        const byte* dnsAddr = EthernetDHCP.dnsIpAddress();

        p(" IP address: %s\n", ip_to_str(ipAddr));
        p("    Gateway: %s\n", ip_to_str(gatewayAddr));
        p("        DNS: %s\n", ip_to_str(dnsAddr));

        if ( ! active ) {
          p("Starting NTP handler on port %u\n", localPort ) ;
          Udp.begin(localPort);
          active = true;
        }
        break;
      }
    }
    prevState = state;
  }
}
/*
 * Handles one Auto-RP map entry. Returns the new offset.
 */
static int do_auto_rp_map(tvbuff_t *tvb, int offset, proto_tree *auto_rp_tree)
{
        proto_item *ti;
        proto_tree *map_tree;
        guint8 group_count;
        guint32 rp_addr;      /* In network byte order */
        int i;

        rp_addr = tvb_get_ipv4(tvb, offset);
        group_count = tvb_get_guint8(tvb, offset + 5);

                               /* sizeof map header + n * sizeof encoded group addresses */
        ti = proto_tree_add_text(auto_rp_tree, tvb, offset, 6 + group_count * 6,
                                 "RP %s: %u group%s", ip_to_str((void *)&rp_addr),
                                 group_count, plurality(group_count, "", "s"));
        map_tree = proto_item_add_subtree(ti, ett_auto_rp_map);

        proto_tree_add_ipv4(map_tree, hf_auto_rp_rp_addr, tvb, offset, 4, rp_addr);
        offset += 4;
        proto_tree_add_uint(map_tree, hf_auto_rp_pim_ver, tvb, offset, 1, tvb_get_guint8(tvb, offset));
        offset++;
        proto_tree_add_text(map_tree, tvb, offset, 1, "Number of groups this RP maps to: %u", group_count);
        offset++;

        for (i = 0; i < group_count; i++) {
                proto_item *gi;
                proto_tree *grp_tree;
                guint8 sign, mask_len;
                guint32 group_addr;     /* In network byte order */

                sign = tvb_get_guint8(tvb, offset);
                mask_len = tvb_get_guint8(tvb, offset + 1);
                group_addr = tvb_get_ipv4(tvb, offset + 2);
                gi = proto_tree_add_text(map_tree, tvb, offset, 6, "Group %s/%u (%s)",
                                         ip_to_str((void *)&group_addr), mask_len,
                                         val_to_str(sign&AUTO_RP_SIGN_MASK, auto_rp_mask_sign_vals, ""));
                grp_tree = proto_item_add_subtree(gi, ett_auto_rp_group);

                proto_tree_add_uint(grp_tree, hf_auto_rp_prefix_sgn, tvb, offset, 1, sign);
                offset++;
                proto_tree_add_uint(grp_tree, hf_auto_rp_mask_len, tvb, offset, 1, mask_len);
                offset++;
                proto_tree_add_ipv4(grp_tree, hf_auto_rp_group_prefix, tvb, offset, 4, group_addr);
                offset += 4;

        }

        return offset;
}
Example #16
0
int nl_set_ifaddr(struct in_addr ifaddr, struct in_addr bcaddr, int ifindex)
{
	struct {
		struct ifaddrmsg ifa;
		struct {
			struct rtattr rta;
			struct in_addr addr;
		} data[3];
	} m;

	memset(&m, 0, sizeof(m));

	m.ifa.ifa_family = AF_INET;
	
	if (IN_CLASSA(ifaddr.s_addr))
		m.ifa.ifa_prefixlen = IN_CLASSA_NSHIFT;
	else if (IN_CLASSB(ifaddr.s_addr))
		m.ifa.ifa_prefixlen = IN_CLASSB_NSHIFT;
	else if (IN_CLASSC(ifaddr.s_addr))
		m.ifa.ifa_prefixlen = IN_CLASSC_NSHIFT;
	else if (IN_CLASSD(ifaddr.s_addr))
		m.ifa.ifa_prefixlen = 0;

	m.ifa.ifa_prefixlen = 24;
	m.ifa.ifa_flags = 0; //IFA_F_PERMANENT;
	m.ifa.ifa_scope = RT_SCOPE_UNIVERSE;
	m.ifa.ifa_index = ifindex;
	
	m.data[0].rta.rta_len = RTA_LENGTH(sizeof(ifaddr));
	m.data[0].rta.rta_type = IFA_LOCAL;
	m.data[0].addr.s_addr = ifaddr.s_addr;
	
	m.data[1].rta.rta_len = RTA_LENGTH(sizeof(ifaddr));
	m.data[1].rta.rta_type = IFA_ADDRESS;
	m.data[1].addr.s_addr = ifaddr.s_addr;

	m.data[2].rta.rta_len = RTA_LENGTH(sizeof(ifaddr));
	m.data[2].rta.rta_type = IFA_BROADCAST;
	m.data[2].addr.s_addr = bcaddr.s_addr;

	
	DEBUG(LOG_DEBUG, 0, "Sending new ifaddr %s %s netlink message index=%d", 
	      ip_to_str(ifaddr),
	      ip_to_str(bcaddr),
	      ifindex);

	return nl_create_and_send_msg(rtnlsock, RTM_NEWADDR, &m, sizeof(m));
}
Example #17
0
File: nl.c Project: Naturekid/MSVR
int nl_send_del_route_msg(struct in_addr dest, struct in_addr next_hop, int metric)
{
    int index = -1;
    struct {
        struct nlmsghdr n;
        struct cpc_rt_msg m;
    } areq;

    fprintf(stderr, "Send DEL_ROUTE to kernel: %s\n", ip_to_str(dest));

    memset(&areq, 0, sizeof(areq));

    areq.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct cpc_rt_msg));
    areq.n.nlmsg_type = CPC_ROUTE_DEL;
    areq.n.nlmsg_flags = NLM_F_REQUEST;

    areq.m.dst = dest.s_addr;
    areq.m.nhop = next_hop.s_addr;
    areq.m.time = 0;

    if (nl_send(&nlsock, &areq.n) < 0) {
        cpc_debug("Failed to send netlink message\n");
        return -1;
    }

    return nl_kern_route(RTM_DELROUTE, 0, AF_INET, index, &dest, &next_hop,
            NULL, metric);
}
Example #18
0
bool Firewall::tcp_firewall_check(uint32_t ip_address, uint16_t udp_port, KadUDPKey& udp_key)
{
    unsigned int packet_size = 19;

    unsigned char *packet = new unsigned char[packet_size];

    uint16_t kad_tcp_port = TCPServer::get_instance().get_tcp_port();
    unsigned char client_id_buffer[16];
    Kad::get_instance().get_client_id().to_buffer(client_id_buffer);

    memcpy(packet, &kad_tcp_port, 2);
    memcpy(&(packet[2]), client_id_buffer, 16);

    unsigned char connect_options = Kad::get_instance().get_connect_options(true, false);
    memcpy(&(packet[18]), &connect_options, 1);

    uint128_t null_id(0);

    WriteLog("Sending " << LOG_MESSAGE_NAME("KADEMLIA_FIREWALLED2_REQ") << " to " << ip_to_str(ip_address) << ":" << udp_port);
    bool ret = Kad::get_instance().send_kad_packet(ip_address, udp_port, null_id, udp_key, KADEMLIA_FIREWALLED2_REQ, packet, packet_size);

    // We need to add the IP address to check that we don't receive any
    // unwanted firewall confirmation
    _firewall_requests.push_back(ip_address);

    delete [] packet;

    return ret;
}
Example #19
0
static inline int llf_print_event(struct iw_event *event,
				  struct iw_range *iwrange, int has_iwrange)
{
    char buffer[128];
    struct in_addr ip;
    rt_table_t *rt;

    /* Now, let's decode the event */
    switch (event->cmd) {

    case IWEVTXDROP:
	DEBUG(LOG_DEBUG, 0, "Tx packet dropped:%s",
	      iw_pr_ether(buffer, event->u.addr.sa_data));


	if (mac_to_ip(&event->u.addr, &ip, this_host.devs[0].ifname) != 0) {
	    DEBUG(LOG_DEBUG, 0, "failed mac_to_ip");
	    return 0;
	}
	//printf("IP=%s\n", ip_to_str(ip));

	rt = rt_table_find(ip);

	if (rt)
	    neighbor_link_break(rt);
	else
	    DEBUG(LOG_DEBUG, 0, "no route for ip=%s", ip_to_str(ip));
	break;

    default:
	DEBUG(LOG_DEBUG, 0, "(Unknown Wireless event 0x%04X)", event->cmd);
    }

    return 0;
}
Example #20
0
File: nl.c Project: Naturekid/MSVR
int nl_send_with_data(char *p, int n, struct in_addr dst)
{
    struct {
        struct nlmsghdr n;
        struct cpc_stateless_msg m;
    } req;

    fprintf(stderr, "Send DROP_QUEUE to kernel: %s\n", ip_to_str(dst));

    memset(&req, 0, sizeof(req));

    req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct cpc_stateless_msg));
    req.n.nlmsg_type = CPC_SEND_WITH_DATA;
    req.n.nlmsg_flags = NLM_F_REQUEST;

    req.m.p = p;
    req.m.n = n;
    req.m.dst = dst.s_addr;

    if (nl_send(&nlsock, &req.n) < 0) {
        cpc_debug("Failed to send netlink message\n");
        return -1;
    }
    return 0;
}
Example #21
0
static void
dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version,
		      proto_tree *tree)
{
    proto_item *ti;
    proto_tree *rip_vektor_tree;
    guint32 metric;

    metric = tvb_get_ntohl(tvb, offset+16);
    ti = proto_tree_add_text(tree, tvb, offset,
			     RIP_ENTRY_LENGTH, "IP Address: %s, Metric: %u",
			     ip_to_str(tvb_get_ptr(tvb, offset+4, 4)), metric);
    rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec);

    proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, FALSE);
    if (version == RIPv2) {
	proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2,
			FALSE);
    }

    proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, FALSE);

    if (version == RIPv2) {
	proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4,
			    FALSE);
	proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4,
			    FALSE);
    }
    proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb,
			offset+16, 4, metric);
}
Example #22
0
File: log.c Project: wdlth/hiawatha
/* Log garbage sent by a client.
 */
void log_garbage(t_session *session) {
	int i, spaces = 2;
	FILE *fp;
	char str[TIMESTAMP_SIZE + IP_ADDRESS_SIZE];

	if ((session->config->garbage_logfile == NULL) || (session->request == NULL)) {
		return;
	}

	for (i = 0; i < session->bytes_in_buffer; i++) {
		if (session->request[i] == '\0') {
			if (spaces > 0) {
				session->request[i] = ' ';
				spaces--;
			} else {
				session->request[i] = '\r';
			}
		}
	}

	if ((fp = fopen(session->config->garbage_logfile, "a")) == NULL) {
		return;
	}

	ip_to_str(str, &(session->ip_address), IP_ADDRESS_SIZE);
	strcat(str, "|");
	print_timestamp(str + strlen(str));
	fprintf(fp, "%s%s"EOL, str, session->request);
	fclose(fp);
}
Example #23
0
void show_request_to_admins(char *method, char *uri, char *http_version, t_ip_addr *ip_addr,
                            t_http_header *headers, int response_code, off_t bytes_sent) {
	bool generated = false;
	char message[1024], *format, ip_str[MAX_IP_STR_LEN + 1], *hostname, *user_agent;
	t_admin *admin;

	admin = adminlist;
	while (admin != NULL) {
		if (admin->show_requests) {
			if (generated == false) {
				if ((hostname = get_http_header("Host:", headers)) == NULL) {
					hostname = "-";
				}
				if ((user_agent = get_http_header("User-Agent:", headers)) == NULL) {
					user_agent = "-";
				}
				ip_to_str(ip_addr, ip_str, MAX_IP_STR_LEN);

				format = "  %s %s %s\n"
				         "  Host: %s\n"
				         "  Client IP: %s\n"
						 "  User agent: %s\n"
				         "  Result: %d, %ld bytes sent\n\n";
				if (snprintf(message, 1023, format, method, uri, http_version, hostname, ip_str, user_agent, response_code, (long)bytes_sent) > 1023) {
					sprintf(message, "(error generating request information message)\n");
				}
				generated = true;
			}

			fprintf(admin->fp, "%s", message);
			fflush(admin->fp);
		}
		admin = admin->next;
	}
}
Example #24
0
void rt_table_destroy() {
  int i = 0;
  rt_table_t *entry, *tmp;

  for(i = 0; i < RT_TABLESIZE; i++) {
    entry = routing_table[i];
     while(entry != NULL) {
       /* Destroy and free memory used by precursor list for this
          entry */
#ifdef DEBUG
       log(LOG_INFO, 0, "routing_table_destroy: Clearing bucket %d", i);
#endif
       precursor_list_destroy(entry);

       if(!IS_INFTY(entry->hcnt)) {
	 k_del_rte(entry->dest, 0, 0);
	/*   k_del_arp(entry->dest); */
#ifdef DEBUG
	 log(LOG_INFO, 0, "routing_table_destroy: Removing kernel route %s", 
	     ip_to_str(entry->dest));
#endif
       }
       tmp = entry;
       entry = entry->next;
       /* Free memory used by this route entry */
       free(tmp);
     }
  }
}
Example #25
0
int nl_send_no_route_found_msg(struct in_addr dest)
{
	DEBUG(LOG_DEBUG, 0, "Send NOROUTE_FOUND to kernel: %s",
	      ip_to_str(dest));
	
	return nl_create_and_send_msg(nlsock, KAODVM_NOROUTE_FOUND, &dest, sizeof(dest));
}
Example #26
0
void NS_CLASS local_repair_timeout(void *arg)
{
    rt_table_t *rt;
    u_int32_t rerr_dest = AODV_BROADCAST;
    RERR *rerr = NULL;

    rt = (rt_table_t *) arg;

    if (!rt)
	return;

    /* Unset the REPAIR flag */
    rt->flags &= ~RT_REPAIR;

    rt->rt_timer.handler = &NS_CLASS route_delete_timeout;
    timer_set_timeout(&rt->rt_timer, DELETE_PERIOD);

    DEBUG(LOG_DEBUG, 0, "%s removed in %u msecs",
	  ip_to_str(rt->dest_addr), DELETE_PERIOD);

    /* Route should already be invalidated. */

    if (rt->nprec) {

	rerr = rerr_create(0, rt->dest_addr, rt->dest_seqno);

	if (rt->nprec == 1) {
	    rerr_dest = FIRST_PREC(rt->precursors)->neighbor;

	    aodv_socket_send((AODV_msg *) rerr, rerr_dest, 
			     RERR_CALC_SIZE(rerr), 1,
			     &DEV_IFINDEX(rt->ifindex));
	} else {
	    int i;

	    for (i = 0; i < MAX_NR_INTERFACES; i++) {
		if (!DEV_NR(i).enabled)
		    continue;
		aodv_socket_send((AODV_msg *) rerr, rerr_dest,
				 RERR_CALC_SIZE(rerr), 1, &DEV_NR(i));
	    }
	}
	DEBUG(LOG_DEBUG, 0, "Sending RERR about %s to %s",
	      ip_to_str(rt->dest_addr), ip_to_str(rerr_dest));
    }
    precursor_list_destroy(rt);
}
Example #27
0
rt_table_t* rt_table_update(rt_table_t *entry, u_int32_t next, u_int8_t hops, 
			    u_int32_t seqno, u_int32_t newlife, u_int16_t flags) {
  /* If the next hop for some reason has changed - update kernel
     routing table. */
  if ((entry->next_hop != 0) && 
      (entry->next_hop != next) &&
      !IS_INFTY(entry->hcnt)) {
#ifdef DEBUG
    log(LOG_INFO, 0, "rt_table_update: entry->nxt_addr=%s, next=%s", 
	ip_to_str(entry->next_hop), ip_to_str(next));
#endif 
    if(k_chg_rte(entry->dest, next, 0, hops) < 0)
      fprintf(stderr, "rt_table_update: Could not update kernel routing table!!!\n");
  }

  /* If this previously was an expired route, but will now be active again
     we must add it to the kernel routing table... */
  if(IS_INFTY(entry->hcnt) && !IS_INFTY(hops)) {
    
    /* We should also update our own sequence number whenever our
       neighbor set changes.  (AODV draft v.8, section 8.4.1.) */
    if(hops == 1)
      this_host->seqno++;
#ifdef DEBUG
    log(LOG_INFO, 0, "rt_table_update: Adding KERNEL route for expired %s", 
	ip_to_str(entry->dest));
#endif
    if(entry->dest == next)
      k_add_rte(entry->dest, 0, 0, hops);
    else
      k_add_rte(entry->dest, next, 0, hops);
  }
  entry->dest_seqno = seqno;
  entry->last_life = newlife;
  entry->flags |= flags;
  entry->next_hop = next;
  entry->last_hcnt = entry->hcnt;
  entry->hcnt = hops;


   /* If newlife = 0 the timer and the expire time should not be
     updated... */
  if(newlife != 0) 
    rt_table_update_timeout(entry, newlife);

  return entry;
}
Example #28
0
void rreq_blacklist_timeout(void *arg) {
    struct blacklist *bl_entry;
    bl_entry = (struct blacklist *)arg;
#ifdef DEBUG
    log(LOG_DEBUG, 0, "rreq_blacklist_timeout: %s", ip_to_str(bl_entry->dest_addr));
#endif
    bl_entry->timer_id = 0;
    rreq_blacklist_remove(bl_entry->dest_addr);
}
Example #29
0
void seek_list_print()
{
    seek_list_t *entry;

    for (entry = seek_list_head; entry != NULL; entry = entry->next) {
	printf("%s %u %d %d\n", ip_to_str(entry->dest_addr),
	       entry->dest_seqno, entry->reqs, entry->ttl);
    }
}
Example #30
0
File: nl.c Project: Naturekid/MSVR
    static void
nl_rt_callback(int sock)
{
    int len, attrlen;
    socklen_t addrlen;
    struct nlmsghdr *nlm;
    struct nlmsgerr *nlmerr;
    char buf[BUFLEN];
    struct ifaddrmsg *ifm;
    struct rtattr *rta;

    addrlen = sizeof(struct sockaddr_nl);

    len = recvfrom(sock, buf, BUFLEN, 0,
            (struct sockaddr *)&peer, &addrlen);
    if (len <= 0)
        return;

    nlm = (struct nlmsghdr *)buf;

    switch (nlm->nlmsg_type) {
        case NLMSG_ERROR:
            nlmerr = (struct nlmsgerr *)NLMSG_DATA(nlm);
            if (nlmerr->error == 0) {
                fprintf(stderr, "NLMSG_ACK\n");
            } else {
                fprintf(stderr, "NLMSG_ERROR, error=%d type=%s",
                        nlmerr->error, 
                        cpc_msg_type_to_str(nlmerr->msg.nlmsg_type));
            }
            break;
        case RTM_NEWLINK:
            cpc_debug("RTM_NEWLINK\n");
            break;
        case RTM_NEWADDR:
            ifm = (struct ifaddrmsg *)NLMSG_DATA(nlm);

            rta = (struct rtattr *)((char *)ifm + sizeof(ifm));
            attrlen = nlm->nlmsg_len - sizeof(struct nlmsghdr) -
                sizeof(struct ifaddrmsg);

            for ( ; RTA_OK(rta, attrlen); rta = RTA_NEXT(rta, attrlen)) {
                struct in_addr ifaddr;

                memcpy(&ifaddr, RTA_DATA(rta), RTA_PAYLOAD(rta));

                fprintf(stderr, "Interface index %d changed address to %s",
                        ifm->ifa_index, ip_to_str(ifaddr));
            }
            break;
        case RTM_NEWROUTE:
            break;
        default:
            fprintf(stderr, "CPC: Got msg type %d\n", nlm->nlmsg_type);
            break;
    }
}