Ejemplo n.º 1
0
static void handle_cmd_get_kb_info_all(int client_fd)
{
    int rv, len;
    fsa_kb_info *ki;
    unsigned char *response;

    /* get info on all running/stopped kbs on this host */
    int err;
    ki = fsab_get_local_kb_info_all(&err);
    if (ki == NULL) {
        send_error_message(client_fd, "failed to get local kb info");
        return;
    }

    /* encode response to send back to client */
    response = fsap_encode_rsp_get_kb_info_all(ki, &len);
    fsa_kb_info_free(ki); /* done with kb info now */
    if (response == NULL) {
        send_error_message(client_fd, "failed to encode response");
        return;
    }

    fsa_error(LOG_DEBUG, "response size is %d bytes", len);

    /* send entire response back to client */
    rv = fsa_sendall(client_fd, response, &len);
    free(response); /* done with response buffer */
    if (rv == -1) {
        fsa_error(LOG_ERR, "failed to send response to client: %s",
                  strerror(errno));
        return;
    }

    fsa_error(LOG_DEBUG, "%d bytes sent to client", len);
}
Ejemplo n.º 2
0
static void
handle_flow_mod_mod( const uint32_t transaction_id, const uint64_t cookie, 
                     const uint64_t cookie_mask, const uint8_t table_id,
                     const uint16_t idle_timeout, const uint16_t hard_timeout,
                     const uint16_t priority, const uint32_t buffer_id,
                     const uint16_t flags, const oxm_matches *oxm,
                     const openflow_instructions *instructions,
                     const bool strict, struct protocol *protocol ) {

  match *match = create_match( );
  if ( oxm != NULL && oxm->n_matches > 0 ) {
    for ( list_element *e = oxm->list; e != NULL; e = e->next ) {
      oxm_match_header *hdr = e->data;
      assign_match( match, hdr );
    }
  }

  instruction_set *ins_set = create_instruction_set();
  if ( instructions != NULL ) {
    OFDPE ret = assign_instructions( ins_set, instructions->list );
    if ( ret != OFDPE_SUCCESS ) {
      send_error_message( transaction_id, OFPET_FLOW_MOD_FAILED, OFPBIC_UNSUP_INST );
      delete_instruction_set( ins_set );
      delete_match( match );
      return;
    }
  }

  OFDPE ret = update_or_add_flow_entry( table_id, match, cookie, cookie_mask, priority, idle_timeout, hard_timeout,
                                        flags, strict, ins_set );
  delete_instruction_set( ins_set );
  delete_match( match );
  if ( ret != OFDPE_SUCCESS ) {
    uint16_t type = OFPET_FLOW_MOD_FAILED;
    uint16_t code = OFPFMFC_UNKNOWN;
    get_ofp_error( ret, &type, &code );
    send_error_message( transaction_id, type, code );
    return;
  }

  if ( buffer_id != OFP_NO_BUFFER ) {
    action_list *actions = create_action_list();
    action *action = create_action_output( OFPP_TABLE, UINT16_MAX );
    append_action( actions, action );
    ret = execute_packet_out( buffer_id, 0, actions, NULL );
    delete_action_list( actions );
    if ( ret != OFDPE_SUCCESS ) {
      uint16_t type = OFPET_FLOW_MOD_FAILED;
      uint16_t code = OFPFMFC_UNKNOWN;
      get_ofp_error( ret, &type, &code );
      send_error_message( transaction_id, type, code );
      return;
    }
    wakeup_datapath( protocol );
  }
}
Ejemplo n.º 3
0
static void
_handle_meter_mod_add( const uint32_t transaction_id, const uint16_t flags, const uint32_t meter_id, const list_element *bands ) {
    OFDPE ret = add_meter_entry( flags, meter_id, bands );
    if ( ret != OFDPE_SUCCESS ) {
        uint16_t type, code;
        if ( get_ofp_error( ret, &type, &code ) == true ) {
            send_error_message( transaction_id, type, code );
        } else {
            send_error_message( transaction_id, OFPET_METER_MOD_FAILED, OFPMMFC_UNKNOWN );
        }
    }
}
Ejemplo n.º 4
0
static void
_handle_meter_mod_delete( const uint32_t transaction_id, const uint32_t meter_id ) {
    OFDPE ret = delete_meter_entry( meter_id );
    if ( ret != OFDPE_SUCCESS ) {
        uint16_t type, code;
        if ( get_ofp_error( ret, &type, &code ) == true ) {
            send_error_message( transaction_id, type, code );
        } else {
            send_error_message( transaction_id, OFPET_METER_MOD_FAILED, OFPMMFC_UNKNOWN );
        }
    }
}
Ejemplo n.º 5
0
/* get all information about a specific kb on this host, send to client */
static void handle_cmd_get_kb_info(int client_fd, uint16_t datasize)
{
    int rv, len, err;
    fsa_kb_info *ki;
    unsigned char *response;
    unsigned char *kb_name;

    kb_name = get_string_from_client(client_fd, datasize);
    if (kb_name == NULL) {
        /* errors already logged/handled */
        return;
    }

    /* should already have been checked by client */
    if (!fsa_is_valid_kb_name((const char *)kb_name)) {
        fsa_error(LOG_CRIT, "Invalid kb name received from client");
        send_error_message(client_fd, "kb name invalid");
        free(kb_name);
        return;
    }

    ki = fsab_get_local_kb_info(kb_name, &err);
    free(kb_name); /* done with kb_name */
    if (ki == NULL || err == ADM_ERR_KB_NOT_EXISTS) {
        send_error_message(client_fd, "failed to get local kb info");
        return;
    }

    /* encode message for client */
    response = fsap_encode_rsp_get_kb_info(ki, &len);
    fsa_kb_info_free(ki);
    if (response == NULL) {
        send_error_message(client_fd, "failed to encode kb info");
        return;
    }

    fsa_error(LOG_DEBUG, "response size is %d bytes", len);

    /* send entire response back to client */
    rv = fsa_sendall(client_fd, response, &len);
    free(response); /* done with response buffer */
    if (rv == -1) {
        fsa_error(LOG_ERR, "failed to send response to client: %s",
                  strerror(errno));
        return;
    }

    fsa_error(LOG_DEBUG, "%d bytes sent to client", len);
}
/// Function receives the data message from lower layer.
/// Data is formatted to Attribute-Value Pairs.
/// Look at eap_tlv_header_c and eap_tlv_message_data_c.
EAP_FUNC_EXPORT eap_status_e eap_plugin_server_message_if_c::process_data(const void * const data, const u32_t length)
{
	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		EAP_TRACE_FLAGS_NEVER,
		(EAPL("eap_plugin_server_message_if_c::process_data()"),
		data,
		length));

	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, TRACE_FLAGS_DEFAULT, "returns: eap_plugin_server_message_if_c::process_message()");

	eap_status_e status(eap_status_process_general_error);

	{
		eap_process_tlv_message_data_c message(m_am_tools);

		if (message.get_is_valid() == false)
		{
			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

			status = eap_status_allocation_error;

			(void) send_error_message(
				status,
				eap_tlv_message_type_function_none);

			return EAP_STATUS_RETURN(m_am_tools, status);
		}

		status = message.set_message_data(length, data);
		if (status != eap_status_ok)
		{
			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

			(void) send_error_message(
				status,
				eap_tlv_message_type_function_none);

			return EAP_STATUS_RETURN(m_am_tools, status);
		}

		status = process_message(&message);
	}

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
	return EAP_STATUS_RETURN(m_am_tools, status);
}
Ejemplo n.º 7
0
/* create a single kb */
static void handle_cmd_create_kb(int client_fd, uint16_t datasize)
{
    int rv, err;
    unsigned char *msg = NULL;
    int exit_val; /* exit value from 4s-backend-setup */

    /* unpack client data into buffer */
    unsigned char *buf = (unsigned char *)malloc(datasize);
    rv = recv_from_client(client_fd, buf, datasize);
    if (rv <= 0) {
        /* errors already logged/handled */
        free(buf);
        return;
    }

    /* parse buffer into kb setup args struct */
    fsa_kb_setup_args *ksargs = fsap_decode_cmd_create_kb(buf);
    fsa_error(LOG_DEBUG, "ksargs->name: %s", ksargs->name);
    fsa_error(LOG_DEBUG, "ksargs->node_id: %d", ksargs->node_id);
    fsa_error(LOG_DEBUG, "ksargs->cluster_size: %d", ksargs->cluster_size);
    fsa_error(LOG_DEBUG, "ksargs->num_segments: %d", ksargs->num_segments);
    fsa_error(LOG_DEBUG, "ksargs->mirror_segments: %d",ksargs->mirror_segments);
    fsa_error(LOG_DEBUG, "ksargs->model_files: %d", ksargs->model_files);
    fsa_error(LOG_DEBUG, "ksargs->delete_existing: %d",ksargs->delete_existing);

    /* should already have been checked by client */
    if (!fsa_is_valid_kb_name((const char *)ksargs->name)) {
        fsa_error(LOG_CRIT, "Invalid store name received from client");
        send_error_message(client_fd, "store name invalid");
        fsa_kb_setup_args_free(ksargs);
    }

    rv = fsab_create_local_kb(ksargs, &exit_val, &msg, &err);

    /* encode message for client */
    int len;
    unsigned char *response =
        fsap_encode_rsp_create_kb(err, ksargs->name, msg, &len);

    fsa_error(LOG_DEBUG, "sending err: %d, kb_name: %s, msg: %s",
              err, ksargs->name, msg);

    fsa_kb_setup_args_free(ksargs);
    free(msg);

    fsa_error(LOG_DEBUG, "response size is %d bytes", len);

    /* send entire response back to client */
    rv = fsa_sendall(client_fd, response, &len);
    free(response);
    if (rv == -1) {
        fsa_error(LOG_ERR, "failed to send response to client: %s",
                  strerror(errno));
        return;
    }

    fsa_error(LOG_DEBUG, "%d bytes sent to client", len);
}
Ejemplo n.º 8
0
static void
_handle_table_mod( uint32_t transaction_id, uint8_t table_id, uint32_t config,
  void *user_data ) {
  UNUSED( user_data );
  
  if ( set_flow_table_config( table_id, config ) != OFDPE_SUCCESS ) {
    send_error_message( transaction_id, OFPET_TABLE_MOD_FAILED, OFPTMFC_EPERM );    
  }
}
Ejemplo n.º 9
0
static void process_handle_error(int err, struct nl_msg* msg) {
	struct nlmsghdr *nl_hdr;
	struct genlmsghdr* genl_hdr;

	uint8_t cmd;
	uint32_t seq;
	
	nl_hdr = nlmsg_hdr(msg);
	genl_hdr = nl_msg_genlhdr(msg);
	cmd = genl_hdr->cmd;
	seq = nl_hdr->nlmsg_seq;

	send_error_message(err, seq, ans_mapping[cmd]);
}
Ejemplo n.º 10
0
// protocol to datapath message.
static void
_handle_set_config( const uint32_t transaction_id, const uint16_t flags, uint16_t miss_send_len, void *user_data ) {
  UNUSED( user_data );

  switch_config config;
  memset( &config, 0, sizeof( switch_config ) );
  config.flags = flags;
  config.miss_send_len = miss_send_len;
  OFDPE ret = set_switch_config( &config );
  if ( ret != OFDPE_SUCCESS ) {
    uint16_t type = OFPET_SWITCH_CONFIG_FAILED;
    uint16_t code = OFPSCFC_EPERM;
    get_ofp_error( ret, &type, &code );
    send_error_message( transaction_id, type, code );
  }
}
Ejemplo n.º 11
0
/* delete a single kb */
static void handle_cmd_delete_kb(int client_fd, uint16_t datasize)
{
    int rv, err;
    unsigned char *msg = NULL;
    int exit_val; /* exit value from 4s-backend-delete */

    /* datasize = num chars in kb name */
    unsigned char *kb_name = get_string_from_client(client_fd, datasize);
    if (kb_name == NULL) {
        /* errors already logged/handled */
        return;
    }

    /* should already have been checked by client */
    if (!fsa_is_valid_kb_name((const char *)kb_name)) {
        fsa_error(LOG_CRIT, "Invalid kb name received from client");
        send_error_message(client_fd, "kb name invalid");
        free(kb_name);
        return;
    }

    rv = fsab_delete_local_kb(kb_name, &exit_val, &msg, &err);

    /* encode message for client */
    int len;
    unsigned char *response =
        fsap_encode_rsp_delete_kb(err, kb_name, msg, &len);

    fsa_error(LOG_DEBUG, "sending err: %d, kb_name: %s, msg: %s",
              err, kb_name, msg);

    free(msg);
    free(kb_name);

    fsa_error(LOG_DEBUG, "response size is %d bytes", len);

    /* send entire response back to client */
    rv = fsa_sendall(client_fd, response, &len);
    free(response); /* done with response buffer */
    if (rv == -1) {
        fsa_error(LOG_ERR, "failed to send response to client: %s",
                  strerror(errno));
        return;
    }

    fsa_error(LOG_DEBUG, "%d bytes sent to client", len);
}
Ejemplo n.º 12
0
static void
_handle_port_mod( uint32_t transaction_id, uint32_t port_no, uint8_t hw_addr[],
                  uint32_t config, uint32_t mask, uint32_t advertise, void *user_data ) {
  UNUSED( hw_addr );
  UNUSED( advertise );
  UNUSED( user_data );
  
  /*
   * the update_port_config() performs a port lookup.
   */
  OFDPE ret = update_port( port_no, config, mask );
  if ( ret != OFDPE_SUCCESS ) {
    uint16_t type = OFPET_PORT_MOD_FAILED;
    uint16_t code = OFPPMFC_EPERM;
    get_ofp_error( ret, &type, &code );
    send_error_message( transaction_id, type, code );
  }
}
Ejemplo n.º 13
0
static void
_handle_hello( const uint32_t transaction_id, const uint8_t version, const buffer *version_data, void *user_data ) {
  UNUSED( user_data );
  debug( "Hello received ( transaction_id = %#x, version = %#x ).", transaction_id, version );

  struct ofp_hello_elem_versionbitmap *versionbitmap = ( struct ofp_hello_elem_versionbitmap * ) version_data->data;
  const uint32_t ofp_versions[ 1 ] = { OFP_VERSION };
  
  uint32_t bitmap = versionbitmap->bitmaps[ 0 ];
  if ( ( bitmap & ( ( uint32_t ) 1 << ofp_versions[ 0 ] ) ) != ( ( uint32_t ) ofp_versions[ 0 ] ) ) {
    buffer *hello_buf = create_hello_elem_versionbitmap( transaction_id, ofp_versions,
      sizeof( ofp_versions ) / sizeof( ofp_versions[ 0 ] ) );
    switch_send_openflow_message( hello_buf );
    free_buffer( hello_buf );
  } else {
    send_error_message( transaction_id, OFPET_HELLO_FAILED, OFPHFC_INCOMPATIBLE );
  }
}
Ejemplo n.º 14
0
static void
_handle_get_config_request( const uint32_t transaction_id, void * user_data ) {
  UNUSED( user_data );
  
  switch_config config;
  memset( &config, 0, sizeof( switch_config ) );

  OFDPE ret = get_switch_config( &config );
  if ( ret != OFDPE_SUCCESS ) {
    uint16_t type = OFPET_BAD_REQUEST;
    uint16_t code = OFPBRC_EPERM;
    get_ofp_error( ret, &type, &code );
    send_error_message( transaction_id, type, code );
  }

  buffer *get_config_reply = create_get_config_reply( transaction_id, config.flags, config.miss_send_len );
  switch_send_openflow_message( get_config_reply );
  free_buffer( get_config_reply );
}
Ejemplo n.º 15
0
static void
handle_flow_mod_delete( const uint32_t transaction_id, const uint64_t cookie,
                        const uint64_t cookie_mask, const uint8_t table_id,
                        const uint16_t idle_timeout, const uint16_t hard_timeout,
                        const uint16_t priority, const uint32_t buffer_id,
                        const uint32_t out_port, const uint32_t out_group,
                        const uint16_t flags, const oxm_matches *oxm_match,
                        const openflow_instructions *instructions,
                        const bool strict ) {

  UNUSED( idle_timeout );
  UNUSED( hard_timeout );
  UNUSED( priority );
  UNUSED( buffer_id );
  UNUSED( flags );
  UNUSED( instructions );
  
  match *match = create_match();
  if ( oxm_match != NULL && oxm_match->n_matches > 0 ) {
    for ( list_element *e = oxm_match->list; e != NULL; e = e->next ) {
      oxm_match_header *hdr = e->data;
      assign_match( match, hdr );
    }
  }

  OFDPE ret = OFDPE_FAILED;
  if ( strict ) {
    ret = delete_flow_entry_strict( table_id, match, cookie, cookie_mask, priority, out_port, out_group );
  }
  else {
    ret = delete_flow_entries( table_id, match, cookie, cookie_mask, out_port, out_group );
  }

  if ( ret != OFDPE_SUCCESS ) {
    uint16_t type = OFPET_FLOW_MOD_FAILED;
    uint16_t code = OFPFMFC_UNKNOWN;
    get_ofp_error( ret, &type, &code );
    send_error_message( transaction_id, type, code );
  }

  delete_match( match );
}
Ejemplo n.º 16
0
static void
_handle_group_mod( const uint32_t transaction_id,
        const uint16_t command,
        const uint8_t type,
        const uint32_t group_id,
        const list_element *buckets,
        void *user_data ) {
  UNUSED( user_data );
  switch( command ) {
    case OFPGC_ADD:
      handle_group_add( transaction_id, type, group_id, buckets );
    break;
    case OFPGC_MODIFY:
      handle_group_mod_mod( transaction_id, type, group_id, buckets );
    break;
    case OFPGC_DELETE:
      handle_group_mod_delete( transaction_id, group_id );
    break;
    default:
      send_error_message( transaction_id, OFPET_GROUP_MOD_FAILED, OFPGMFC_BAD_COMMAND );
    break;
  }
}
Ejemplo n.º 17
0
static void
_handle_multipart_request( uint32_t transaction_id, uint16_t type, uint16_t flags, const buffer *body, void *user_data ) {

  struct protocol *protocol = user_data;
  assert( protocol );
  if ( save_outstanding_request( &protocol->ctrl, transaction_id, type, flags ) == -1 ) {
    send_error_message( transaction_id, OFPET_BAD_REQUEST, OFPBRC_MULTIPART_BUFFER_OVERFLOW );
    return;
  }
  const uint32_t capabilities = protocol->ctrl.capabilities;
  switch( type ) {
    case OFPMP_DESC: {
      // the request body is empty
      handle_desc( transaction_id, protocol->args->progname );
    }
    break;
    case OFPMP_FLOW: {
      const struct ofp_flow_stats_request *req = ( const struct ofp_flow_stats_request * ) body->data;
      handle_flow_stats( req, transaction_id, capabilities );
    }
    break;
    case OFPMP_AGGREGATE: {
      const struct ofp_aggregate_stats_request *req = ( const struct ofp_aggregate_stats_request * ) body->data;
      handle_aggregate_stats( req, transaction_id, capabilities );
    }
    break;
    case OFPMP_TABLE: {
      // no request body is included with this type.
      handle_table_stats( transaction_id, capabilities );
    }
    break;
    case OFPMP_PORT_STATS: {
      const struct ofp_port_stats_request *req = ( const struct ofp_port_stats_request * ) body->data;
      handle_port_stats( req, transaction_id, capabilities );
    }
    break;
    case OFPMP_PORT_DESC: {
      // no request body is included with this type.
      handle_port_desc( transaction_id );
    }
    break;
    case OFPMP_QUEUE: {
      const struct ofp_queue_stats_request *req = ( const struct ofp_queue_stats_request * ) body->data;
      handle_queue_stats( req, transaction_id, capabilities );
    }
    break;
    case OFPMP_GROUP: {
      const struct ofp_group_stats_request *req = ( const struct ofp_group_stats_request * ) body->data;
      handle_group_stats( req, transaction_id, capabilities );
    }
    break;
    case OFPMP_GROUP_DESC: {
      // the request body is empty.
      handle_group_desc( transaction_id, capabilities );
    }
    break;
    case OFPMP_GROUP_FEATURES: {
      handle_group_features( transaction_id, capabilities );
    }
    break;
    case OFPMP_METER: {
      const struct ofp_meter_multipart_request *req = ( const struct ofp_meter_multipart_request * ) body->data;
      handle_meter_stats( req, transaction_id );
    }
    break;
    case OFPMP_METER_CONFIG: {
      const struct ofp_meter_multipart_request *req = ( const struct ofp_meter_multipart_request * ) body->data;
      handle_meter_config( req, transaction_id );
    }
    break;
    case OFPMP_METER_FEATURES: {
      handle_meter_features( transaction_id );
    }
    break;
    case OFPMP_TABLE_FEATURES: {
      /*
       * TODO Currently the setting of table features not supported by datapath
       */
      handle_table_features( transaction_id );
    }
    break;
    case OFPMP_EXPERIMENTER: {
      const struct ofp_experimenter_multipart_header *em_hdr = ( const struct ofp_experimenter_multipart_header * ) body->data;
      handle_experimenter_stats( em_hdr, transaction_id );
    }
    break;
    default:
      send_error_message( transaction_id, OFPET_BAD_REQUEST, OFPBRC_BAD_MULTIPART );
    break;
  }
}
Ejemplo n.º 18
0
void process_request(char* code_sign_key) {
    PLATFORM* platform;
    int retval;
    double last_rpc_time, x;
    struct tm *rpc_time_tm;
    bool ok_to_send_work = !config.dont_send_jobs;
    bool have_no_work = false;
    char buf[256];
    HOST initial_host;
    unsigned int i;
    time_t t;

    memset(&g_reply->wreq, 0, sizeof(g_reply->wreq));

    // if client has sticky files we don't need any more, tell it
    //
    do_file_delete_regex();

    // if different major version of BOINC, just send a message
    //
    if (wrong_core_client_version()
        || unacceptable_os()
        || unacceptable_cpu()
    ) {
        ok_to_send_work = false;
    }

    // if no jobs reported and none to send, return without accessing DB
    //
    if (!ok_to_send_work && !g_request->results.size()) {
        return;
    }

    warn_user_if_core_client_upgrade_scheduled();

    if (requesting_work()) {
        if (config.locality_scheduling || config.locality_scheduler_fraction || config.enable_assignment) {
            have_no_work = false;
        } else {
            lock_sema();
            have_no_work = ssp->no_work(g_pid);
            if (have_no_work) {
                g_wreq->no_jobs_available = true;
            }
            unlock_sema();
        }
    }

    // If:
    // - there's no work,
    // - a config flag is set,
    // - client isn't returning results,
    // - this isn't an initial RPC,
    // - client is requesting work
    // then return without accessing the DB.
    // This is an efficiency hack for when servers are overloaded
    //
    if (
        have_no_work
        && config.nowork_skip
        && requesting_work()
        && (g_request->results.size() == 0)
        && (g_request->hostid != 0)
    ) {
        g_reply->insert_message("No work available", "low");
        g_reply->set_delay(DELAY_NO_WORK_SKIP);
        if (!config.msg_to_host && !config.enable_vda) {
            log_messages.printf(MSG_NORMAL, "No work - skipping DB access\n");
            return;
        }
    }

    // FROM HERE ON DON'T RETURN; "goto leave" instead
    // (because ssp->no_work() may have tagged an entry in the work array
    // with our process ID)

    retval = open_database();
    if (retval) {
        send_error_message("Server can't open database", 3600);
        g_reply->project_is_down = true;
        goto leave;
    }

    retval = authenticate_user();
    if (retval) goto leave;
    if (g_reply->user.id == 0) {
        log_messages.printf(MSG_CRITICAL, "No user ID!\n");
    }
    initial_host = g_reply->host;
    g_reply->host.rpc_seqno = g_request->rpc_seqno;

    g_reply->nucleus_only = false;

    log_request();

#if 0
    // if you need to debug a problem w/ a particular host or user,
    // edit the following
    //
    if (g_reply->user.id == XX || g_reply.host.id == YY) {
        config.sched_debug_level = 3;
        config.debug_send = true;
        ...
    }
void perform_actions(int sock,char *input_file)
{
	char buffer[169] = {0};
	
	char output_file[300] = {0};
	
    strcpy(output_file,input_file);
    strcat(output_file,".decrypted");
    //printf("Output_file: %s\n",output_file);
    
	while(1)
	{	
		memset(buffer,0,169);
		int x = receive_msg(sock,buffer);
		switch(x)
		{
			case HANDSHAKE:
			{
				//printf("Server handshake has arrived on client\n");
				send_handshake_response(sock);
				
				FILE *fd = fopen(input_file,"r");
				FILE *foutput = fopen(output_file,"w");
				
				// Here come all the requests.
				while(read_line(fd, buffer))
				{
					//printf("%s\n",buffer);
					send_decryption_request(sock,buffer,strlen(buffer));
					x = receive_msg(sock,buffer);
					if(x != RESPONSE_MESSAGE)
					{
						perror("Wrong server response");
						break;
					}
					int msg_len = *((int *)(buffer+sizeof(int)));
					for(int i = 0; i < msg_len; i++)
					{
						// printf("%c",buffer[i+2*sizeof(int)]);
						fprintf(foutput,"%c",buffer[i+2*sizeof(int)]);
					} fprintf(foutput,"\n");
				}
				
				fclose(foutput);
				fclose(fd);
				send_end_of_request(sock);
				return;
				break;
			}
//			case RESPONSE_MESSAGE:
//			{
//				printf("Server response message has arrived on client\n");
//				dump_payload(buffer);
//				break;
//			}
			case ERROR_MESSAGE:
			{
				printf("Error message has arrived on client\n");
				dump_payload(buffer);
				return;
				break;
			}
			default:
			{
				printf("Unknown %d msg type has arrived on client\n",x);
				char aux[] = "Unknown msg type has arrived on client";
				send_error_message(sock,aux,strlen(aux));
				return;
				break;
			}
		}
	} // End while
}
Ejemplo n.º 20
0
static void start_or_stop_kb_all(int client_fd, int action)
{
    int rv, err;
    int n_kbs = 0;
    int max_kb_len = 0;

    /* get all local kbs */
    fsa_kb_info *ki = fsab_get_local_kb_info_all(&err);
    if (ki == NULL) {
        if (err == 0) {
            /* no kbs on this host */
            send_expect_n_kb(client_fd, 0, 0);
        }
        else {
            send_error_message(client_fd, "failed to read store information");
        }
        return;
    }

    /* count number of kbs */
    for (fsa_kb_info *p = ki; p != NULL; p = p->next) {
        int kb_len = strlen((char *)p->name);
        if (kb_len > max_kb_len) {
            max_kb_len = kb_len;
        }
        n_kbs += 1;
    }

    /* tell client to expect a message for each */
    rv = send_expect_n_kb(client_fd, n_kbs, max_kb_len);
    if (rv == -1) {
        /* failed to send message to client, so give up */
        fsa_kb_info_free(ki);
        return;
    }

    int exit_val; /* ignored for now */
    unsigned char *msg = NULL; /* sent back to client */
    int return_val; /* sent back to client */

    int len; /* response length */
    unsigned char *response = NULL; /* response buffer */

    for (fsa_kb_info *p = ki; p != NULL; p = p->next) {
        if (action == STOP_STORES) {
            rv = fsab_stop_local_kb(p->name, &err);
        }
        else if (action == START_STORES) {
            rv = fsab_start_local_kb(p->name, &exit_val, &msg, &err);
        }

        if (rv < 0) {
            return_val = err;
        }
        else {
            return_val = ADM_ERR_OK;
        }

        /* encode message for client */
        if (action == STOP_STORES) {
            response =
                fsap_encode_rsp_stop_kb(return_val, p->name, msg, &len);
        }
        else if (action == START_STORES) {
            response =
                fsap_encode_rsp_start_kb(return_val, p->name, msg, &len);
        }

        if (msg != NULL) {
            free(msg);
            msg = NULL;
        }

        fsa_error(LOG_DEBUG, "response size is %d bytes", len);

        /* send entire response back to client */
        rv = fsa_sendall(client_fd, response, &len);
        free(response); /* done with response buffer */
        response = NULL;
        if (rv == -1) {
            fsa_error(LOG_ERR, "failed to send response to client: %s",
                      strerror(errno));
            continue;
        }

        fsa_error(LOG_DEBUG, "%d bytes sent to client", len);
    }

    fsa_kb_info_free(ki);
}
Ejemplo n.º 21
0
static void
handle_flow_mod_add( const uint32_t transaction_id, const uint64_t cookie, 
                     const uint64_t cookie_mask, const uint8_t table_id,
                     const uint16_t idle_timeout, const uint16_t hard_timeout,
                     const uint16_t priority, const uint32_t buffer_id,
                     const uint16_t flags, const oxm_matches *oxm,
                     const openflow_instructions *instructions,
                     struct protocol *protocol ) {
  UNUSED( cookie_mask );
  /*
   * currently if flags set OFPFF_SEND_FLOW_REM and OFPFF_RESET_COUNTS are the only allowed value.
   */
  if ( ( flags & ~( OFPFF_SEND_FLOW_REM | OFPFF_RESET_COUNTS ) ) != 0 ) {
    send_error_message( transaction_id, OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_FLAGS );
    return;
  }
  /*
   * The use of OFPTT_ALL is only valid for delete requests.
   */
  if ( table_id == OFPTT_ALL ) {
    send_error_message( transaction_id, OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_TABLE_ID );
    return;
  }

  /*
   * If no buffered packet is associated with a flow mod it must be set
   * to OFP_NO_BUFFER otherwise it must be equal to the buffer_id sent to
   * controller by a packet-in message.
   */

  match *match = create_match();
  if ( oxm != NULL && oxm->n_matches > 0 ) {
    
#ifdef DEBUG    
    char oxm_str[ 2048 ];
    match_to_string( oxm, oxm_str, sizeof( oxm_str ) );
    printf( "%s\n", oxm_str );
#endif
    
    for ( list_element *e = oxm->list; e != NULL; e = e->next ) {
      oxm_match_header *hdr = e->data;
      assign_match( match, hdr );
    }
  }

  instruction_set *instruction_set = create_instruction_set();
  if ( instructions != NULL ) {
    OFDPE ret = assign_instructions( instruction_set, instructions->list );
    if ( ret != OFDPE_SUCCESS ) {
      send_error_message( transaction_id, OFPET_FLOW_MOD_FAILED, OFPBIC_UNSUP_INST );
      delete_instruction_set( instruction_set );
      delete_match( match );
      return;
    }
  }

  /*
   * When a flow entry is inserted in a table, its flags field is set with the
   * values from the message.
   * When a flow entry is inserted in a table, its idle_timeout and
   * hard_timeout fields are set with the values from the message.
   * When a flow entry is inserted in a table through an OFPFC_ADD message,
   * its cookie field is set to the provided value
   */
  flow_entry *new_entry = alloc_flow_entry( match, instruction_set, priority,
                                            idle_timeout, hard_timeout, flags, cookie );
  if ( new_entry == NULL ) {
    /*
     * TODO we should send a more appropriate error once we worked out the
     * datapath errors.
     */
    delete_instruction_set( instruction_set );
    delete_match( match );
    send_error_message( transaction_id, OFPET_FLOW_MOD_FAILED, OFPFMFC_UNKNOWN );
    return;
  }

  OFDPE ret = add_flow_entry( table_id, new_entry, flags );
  if ( ret != OFDPE_SUCCESS ) {
    error( "Failed to add a flow entry ( ret = %d ).", ret );
    delete_instruction_set( instruction_set );
    delete_match( match );

    uint16_t type = OFPET_FLOW_MOD_FAILED;
    uint16_t code = OFPFMFC_UNKNOWN;
    get_ofp_error( ret, &type, &code );
    send_error_message( transaction_id, type, code );
    return;
  }

  if ( buffer_id != OFP_NO_BUFFER ) {
    action_list *actions = create_action_list();
    action *action = create_action_output( OFPP_TABLE, UINT16_MAX );
    append_action( actions, action );
    ret = execute_packet_out( buffer_id, 0, actions, NULL );
    delete_action_list( actions );
    if ( ret != OFDPE_SUCCESS ) {
      uint16_t type = OFPET_FLOW_MOD_FAILED;
      uint16_t code = OFPFMFC_UNKNOWN;
      get_ofp_error( ret, &type, &code );
      send_error_message( transaction_id, type, code );
      return;
    }
    wakeup_datapath( protocol );
  }
}
Ejemplo n.º 22
0
static void
_handle_flow_mod( const uint32_t transaction_id,
                  const uint64_t cookie,
                  const uint64_t cookie_mask,
                  const uint8_t table_id,
                  const uint8_t command,
                  const uint16_t idle_timeout,
                  const uint16_t hard_timeout,
                  const uint16_t priority,
                  const uint32_t buffer_id,
                  const uint32_t out_port,
                  const uint32_t out_group,
                  const uint16_t flags,
                  const oxm_matches *oxm,
                  const openflow_instructions *instructions,
                  void *user_data
  ) {
  assert( user_data );
  struct protocol *protocol = user_data;
  bool strict = false;

  switch ( command ) {
    case OFPFC_ADD:
      /*
       * The cookie_mask field is ignored for this command.
       * TODO the datapath flow entry contains no buffer_id field to set.
       * From observation datapath buffers every packet regardless of buffer_id
       */
      handle_flow_mod_add( transaction_id, cookie, cookie_mask,
                           table_id, idle_timeout, hard_timeout,
                           priority, buffer_id, flags, oxm,
                           instructions, protocol );
    break;
    case OFPFC_MODIFY:
      /*
       * The idle_timeout and hard_timeout fields are ignored.
       * Also the out_port and out_group fields are ignored.
       * When a flow entry is matched or modified the flags field is ignored.
       * When a flow entry is modified its cookie field is unchanged.
       */
      handle_flow_mod_mod( transaction_id, cookie, cookie_mask, table_id,
                           idle_timeout, hard_timeout, priority, buffer_id,
                           flags, oxm, instructions, strict, protocol );
    break;
    case OFPFC_MODIFY_STRICT:
      strict = true;
      handle_flow_mod_mod( transaction_id, cookie, cookie_mask, table_id,
                           idle_timeout, hard_timeout, priority, buffer_id,
                           flags, oxm, instructions, strict, protocol );
    break;
    case OFPFC_DELETE:
      /*
       * The out_port and out_group introduce a constraint when matching
       * flow entries.
       */
      handle_flow_mod_delete( transaction_id, cookie, cookie_mask,
                              table_id, idle_timeout, hard_timeout,
                              priority, buffer_id, out_port,
                              out_group, flags, oxm,
                              instructions, strict );
    break;
    case OFPFC_DELETE_STRICT:
      strict = true;
      handle_flow_mod_delete( transaction_id, cookie, cookie_mask, table_id,
                              idle_timeout, hard_timeout, priority, buffer_id,
                              out_port, out_group, flags, oxm,
                              instructions, strict );
    break;
    default:
      warn( "Undefined flow mod command type %d", command );
      send_error_message( transaction_id, OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_COMMAND );
    break;
  }
}
Ejemplo n.º 23
0
void process_request(char* code_sign_key) {
    PLATFORM* platform;
    int retval;
    double last_rpc_time, x;
    struct tm *rpc_time_tm;
    bool ok_to_send_work = !config.dont_send_jobs;
    bool have_no_work = false;
    char buf[256];
    HOST initial_host;
    unsigned int i;
    time_t t;

    memset(&g_reply->wreq, 0, sizeof(g_reply->wreq));

    // if client has sticky files we don't need any more, tell it
    //
    do_file_delete_regex();

    // if different major version of BOINC, just send a message
    //
    if (wrong_core_client_version()
            || unacceptable_os()
            || unacceptable_cpu()
       ) {
        ok_to_send_work = false;
    }

    // if no jobs reported and none to send, return without accessing DB
    //
    if (!ok_to_send_work && !g_request->results.size()) {
        return;
    }

    warn_user_if_core_client_upgrade_scheduled();

    if (requesting_work()) {
        if (config.locality_scheduling || config.locality_scheduler_fraction || config.enable_assignment) {
            have_no_work = false;
        } else {
            lock_sema();
            have_no_work = ssp->no_work(g_pid);
            if (have_no_work) {
                g_wreq->no_jobs_available = true;
            }
            unlock_sema();
        }
    }

    // If:
    // - there's no work,
    // - a config flag is set,
    // - client isn't returning results,
    // - this isn't an initial RPC,
    // - client is requesting work
    // then return without accessing the DB.
    // This is an efficiency hack for when servers are overloaded
    //
    if (
        have_no_work
        && config.nowork_skip
        && requesting_work()
        && (g_request->results.size() == 0)
        && (g_request->hostid != 0)
    ) {
        g_reply->insert_message("No work available", "low");
        g_reply->set_delay(DELAY_NO_WORK_SKIP);
        if (!config.msg_to_host && !config.enable_vda) {
            log_messages.printf(MSG_NORMAL, "No work - skipping DB access\n");
            return;
        }
    }

    // FROM HERE ON DON'T RETURN; "goto leave" instead
    // (because ssp->no_work() may have tagged an entry in the work array
    // with our process ID)

    retval = open_database();
    if (retval) {
        send_error_message("Server can't open database", 3600);
        g_reply->project_is_down = true;
        goto leave;
    }

    retval = authenticate_user();
    if (retval) goto leave;
    if (g_reply->user.id == 0) {
        log_messages.printf(MSG_CRITICAL, "No user ID!\n");
    }
    initial_host = g_reply->host;
    g_reply->host.rpc_seqno = g_request->rpc_seqno;

    g_reply->nucleus_only = false;

    log_request();

    // is host blacklisted?
    //
    if (g_reply->host._max_results_day == -1) {
        send_error_message("Not accepting requests from this host", 86400);
        goto leave;
    }

    if (strlen(config.sched_lockfile_dir)) {
        int pid_with_lock = lock_sched();
        if (pid_with_lock > 0) {
            log_messages.printf(MSG_CRITICAL,
                                "Another scheduler instance [PID=%d] is running for this host\n",
                                pid_with_lock
                               );
        } else if (pid_with_lock) {
            log_messages.printf(MSG_CRITICAL,
                                "Error acquiring lock for [HOST#%d]\n", g_reply->host.id
                               );
        }
        if (pid_with_lock) {
            send_error_message(
                "Another scheduler instance is running for this host", 60
            );
            goto leave;
        }
    }

    // in deciding whether it's a new day,
    // add a random factor (based on host ID)
    // to smooth out network traffic over the day
    //
    retval = rand();
    srand(g_reply->host.id);
    x = drand()*86400;
    srand(retval);
    last_rpc_time = g_reply->host.rpc_time;
    t = (time_t)(g_reply->host.rpc_time + x);
    rpc_time_tm = localtime(&t);
    g_request->last_rpc_dayofyear = rpc_time_tm->tm_yday;

    t = time(0);
    g_reply->host.rpc_time = t;
    t += (time_t)x;
    rpc_time_tm = localtime(&t);
    g_request->current_rpc_dayofyear = rpc_time_tm->tm_yday;

    retval = modify_host_struct(g_reply->host);

    // write time stats to disk if present
    //
    if (g_request->have_time_stats_log) {
        write_time_stats_log();
    }

    // look up the client's platform(s) in the DB
    //
    platform = ssp->lookup_platform(g_request->platform.name);
    if (platform) g_request->platforms.list.push_back(platform);

    // if primary platform is anonymous, ignore alternate platforms
    //
    if (strcmp(g_request->platform.name, "anonymous")) {
        for (i=0; i<g_request->alt_platforms.size(); i++) {
            platform = ssp->lookup_platform(g_request->alt_platforms[i].name);
            if (platform) g_request->platforms.list.push_back(platform);
        }
    }
    if (g_request->platforms.list.size() == 0) {
        sprintf(buf, "%s %s",
                _("This project doesn't support computers of type"),
                g_request->platform.name
               );
        g_reply->insert_message(buf, "notice");
        log_messages.printf(MSG_CRITICAL,
                            "[HOST#%d] platform '%s' not found\n",
                            g_reply->host.id, g_request->platform.name
                           );
        g_reply->set_delay(DELAY_PLATFORM_UNSUPPORTED);
        goto leave;
    }

    handle_global_prefs();

    read_host_app_versions();
    update_n_jobs_today();

    handle_results();
    handle_file_xfer_results();
    if (config.enable_vda) {
        handle_vda();
    }

    // Do this before resending lost jobs
    //
    if (bad_install_type()) {
        ok_to_send_work = false;
    }
    if (!requesting_work()) {
        ok_to_send_work = false;
    }
    send_work_setup();

    if (g_request->have_other_results_list) {
        if (ok_to_send_work
                && (config.resend_lost_results || g_wreq->resend_lost_results)
                && !g_request->results_truncated
           ) {
            if (resend_lost_work()) {
                ok_to_send_work = false;
            }
        }
        if (config.send_result_abort) {
            send_result_abort();
        }
    }

    if (requesting_work()) {
        if (!send_code_sign_key(code_sign_key)) {
            ok_to_send_work = false;
        }

        if (have_no_work) {
            if (config.debug_send) {
                log_messages.printf(MSG_NORMAL,
                                    "[send] No jobs in shmem cache\n"
                                   );
            }
        }

        // if last RPC was within config.min_sendwork_interval, don't send work
        //
        if (!have_no_work && ok_to_send_work) {
            if (config.min_sendwork_interval) {
                double diff = dtime() - last_rpc_time;
                if (diff < config.min_sendwork_interval) {
                    ok_to_send_work = false;
                    log_messages.printf(MSG_NORMAL,
                                        "Not sending work - last request too recent: %f\n", diff
                                       );
                    sprintf(buf,
                            "Not sending work - last request too recent: %d sec", (int)diff
                           );
                    g_reply->insert_message(buf, "low");

                    // the 1.01 is in case client's clock
                    // is slightly faster than ours
                    //
                    g_reply->set_delay(1.01*config.min_sendwork_interval);
                }
            }
            if (ok_to_send_work) {
                send_work();
            }
        }
        if (g_wreq->no_jobs_available) {
            g_reply->insert_message("Project has no tasks available", "low");
        }
    }


    handle_msgs_from_host();
    if (config.msg_to_host) {
        handle_msgs_to_host();
    }

    update_host_record(initial_host, g_reply->host, g_reply->user);
    write_host_app_versions();

leave:
    if (!have_no_work) {
        ssp->restore_work(g_pid);
    }
}
EAP_FUNC_EXPORT eap_status_e eap_plugin_server_message_if_c::process_message(eap_process_tlv_message_data_c * const message)
{
	// Parses message data composed of Attribute-Value Pairs.

	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		EAP_TRACE_FLAGS_NEVER,
		(EAPL("eap_plugin_server_message_if_c::process_message()"),
		message->get_message_data(),
		message->get_message_data_length()));

	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, TRACE_FLAGS_DEFAULT, "returns: eap_plugin_server_message_if_c::process_message()");

	eap_array_c<eap_tlv_header_c> parameters(m_am_tools);

	eap_status_e status = message->parse_message_data(&parameters);
	if (status != eap_status_ok)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

		(void) send_error_message(
			status,
			eap_tlv_message_type_function_none);

		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	if (parameters.get_object_count() == 0)
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

		status = eap_status_illegal_parameter;

		(void) send_error_message(
			status,
			eap_tlv_message_type_function_none);

		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	const eap_tlv_header_c * const function_header = parameters.get_object(eap_message_payload_index_function);
	if (function_header == 0
		|| (function_header->get_type() != eap_tlv_message_type_error
			&& function_header->get_type() != eap_tlv_message_type_function))
	{
		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

		status = eap_status_illegal_parameter;

		(void) send_error_message(
			status,
			eap_tlv_message_type_function_none);

		return EAP_STATUS_RETURN(m_am_tools, status);
	}

	if (function_header->get_type() == eap_tlv_message_type_error)
	{
		status = process_message_type_error(&parameters);
	}
	else // function_header->get_type() == eap_tlv_message_type_function
	{
		eap_tlv_message_type_function_e function(eap_tlv_message_type_function_none);

		status = message->get_parameter_data(function_header, &function);
		if (status != eap_status_ok)
		{
			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);

			(void) send_error_message(
				status,
				eap_tlv_message_type_function_none);

			return EAP_STATUS_RETURN(m_am_tools, status);
		}

		EAP_TRACE_DEBUG(
			m_am_tools, 
			TRACE_FLAGS_DEFAULT, 
			(EAPL("eap_plugin_server_message_if_c::process_message(): this = 0x%08x, message=%d=%s\n"),
			this,
			function,
			eap_process_tlv_message_data_c::get_function_string(function)));

		switch(function)
		{
		case eap_tlv_message_type_function_plugin_get_configuration:
			status = get_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_set_configuration:
			status = set_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_copy_configuration:
			status = copy_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_delete_configuration:
			status = delete_configuration(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_set_index:
			status = set_index(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_get_type_info:
			status = get_type_info(&parameters);
			break;
		case eap_tlv_message_type_function_plugin_invoke_ui:
			status = invoke_ui(&parameters);
			break;
		default:
			EAP_TRACE_ERROR(
				m_am_tools,
				TRACE_FLAGS_DEFAULT,
				(EAPL("ERROR: process_data(): unknown function %d.\n"),
				 function));

			status = eap_status_illegal_parameter;

			EAP_ASSERT_ANYWAY_TOOLS(m_am_tools);
		};

		if (status != eap_status_ok
			&& status != eap_status_success
			&& status != eap_status_pending_request
			&& status != eap_status_completed_request
			&& status != eap_status_drop_packet_quietly)
		{
			(void) send_error_message(
				status,
				function);
		}
	}

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
	return EAP_STATUS_RETURN(m_am_tools, status);
}