Example #1
0
void
test_parse_ether_succeeds() {
  buffer *buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) );

  assert_int_equal( parse_ether( buffer ), true );

  free_buffer( buffer );
}
Example #2
0
void free_nsqd_connection(struct NSQDConnection *conn)
{
    if (conn) {
        free_buffer(conn->command_buf);
        free_buffered_socket(conn->bs);
        free(conn);
    }
}
Example #3
0
/**
 * largebuffer_cleanup - cleanup callback for large buffers
 * @buf: buffer to be cleaned
 *
 * This function is used as the cleanup callback for large buffer and
 * will free all buffers used in the large buffer chain. This does mean
 * that the free_buffer call done after calling cleanup will be
 * passed an already-freed buffer, but that case is accounted for in
 * free_buffer and results in a no-op. Always returns 0.
 */
static uint8_t largebuffer_cleanup(buffer_t *buf) {
  buf = buf->pvt.buffer.first;
  while (buf != NULL) {
    free_buffer(buf);
    buf = buf->pvt.buffer.next;
  }
  return 0;
}
Example #4
0
static void vbi_buffer_release(struct videobuf_queue *vq,
			       struct videobuf_buffer *vb)
{
	struct cx231xx_buffer *buf =
	    container_of(vb, struct cx231xx_buffer, vb);

	free_buffer(vq, buf);
}
Example #5
0
VALUE
getRbString(buffer *buf)
{
  VALUE o;
  o = rb_str_new(buf->buf, buf->len);
  free_buffer(buf);
  return o;
}
Example #6
0
bool
delete_pcap_packet( buffer *packet ) {
  assert( packet != NULL );
  
  free_buffer( packet );

  return true;
}
Example #7
0
static void
send_packet_out( packet_in packet_in, openflow_actions *actions ) {
  buffer *frame = duplicate_buffer( packet_in.data );
  fill_ether_padding( frame );

  buffer *packet_out = create_packet_out(
    get_transaction_id(),
    UINT32_MAX,
    packet_in.in_port,
    actions,
    frame
  );

  free_buffer( frame );
  send_openflow_message( packet_in.datapath_id, packet_out );
  free_buffer( packet_out );
}
Example #8
0
static void
send_features_request( sw_entry *sw ) {
  uint32_t id = get_transaction_id();
  buffer *buf = create_features_request( id );
  send_openflow_message( sw->datapath_id, buf );
  free_buffer( buf );
  debug( "Sent switch features request to %#" PRIx64 ".", sw->datapath_id );
}
Example #9
0
void
test_parse_ether_vlan_succeeds() {
  buffer *buffer = setup_dummy_vlan_packet( );

  assert_int_equal( parse_ether( buffer ), true );

  free_buffer( buffer );
}
Example #10
0
static void
test_parse_packet_fails_if_data_is_NULL() {
  buffer *null_data = alloc_buffer( );

  expect_assert_failure( parse_packet( null_data ) );

  free_buffer( null_data );
}
Example #11
0
static void
handle_switch_ready( uint64_t datapath_id, void *user_data ) {
  UNUSED( user_data );

  buffer *message = create_features_request( get_transaction_id() );
  send_openflow_message( datapath_id, message );
  free_buffer( message );
}
Example #12
0
void
service_recv_from_application( uint16_t message_type, buffer *buf ) {
   openflow_service_header_t *message;
   uint64_t datapath_id;
   uint16_t service_name_length;
   char *service_name;

  if ( buf->length < sizeof( openflow_service_header_t ) + sizeof( struct ofp_header ) ) {
    error( "Too short openflow application message(%zu).", buf->length );
    free_buffer( buf );

    return;
  }

  message = buf->data;
  datapath_id = ntohll( message->datapath_id );
  service_name_length = ntohs( message->service_name_length );
  service_name = remove_front_buffer( buf, sizeof( openflow_service_header_t ) );
  if ( service_name_length < 1 ) {
    error( "Invalid service name length %u.", service_name_length );
    free_buffer( buf );

    return;
  }
  if ( service_name[ service_name_length - 1 ] != '\0' ) {
    error( "Service name is not null terminated." );
    free_buffer( buf );

    return;
  }
  remove_front_buffer( buf, service_name_length );

  switch ( message_type ) {
  case MESSENGER_OPENFLOW_MESSAGE:
    handle_openflow_message( &datapath_id, service_name, buf );
    break;
  case MESSENGER_OPENFLOW_DISCONNECT_REQUEST:
    free_buffer( buf );
    handle_openflow_disconnect_request( &datapath_id );
    break;
  default:
    error( "Unknown message type %d.", message_type );
    free_buffer( buf );
    break;
  }
}
Example #13
0
request_t*
create_request(PyObject* reader)
{
    int cs = 0;

    if(reader == NULL)
    {
        PyErr_SetString(PyExc_ValueError, "Reader must not be NULL.");
        return NULL;
    }

    request_t* ret = (request_t*) malloc(sizeof(request_t));
    if(ret == NULL)
    {
        PyErr_NoMemory();
        return NULL;
    }

    memset(ret, '\0', sizeof(request_t));
    ret->port = 80;
    ret->reader = reader;
    
    ret->headers = PyList_New(0);
    if(ret->headers == NULL)
    {
        PyErr_NoMemory();
        return NULL;
    }
    
    ret->genbuf = init_buffer(64*1024);
    if(ret->genbuf == NULL)
    {
        free(ret);
        PyErr_NoMemory();
        return NULL;
    }
    
    ret->uribuf = init_buffer(64*1024);
    if(ret->uribuf == NULL)
    {
        free_buffer(ret->genbuf);
        free(ret);
        PyErr_NoMemory();
        return NULL;
    }

    
#line 1936 "./c_src/request.c"
	{
	cs = http_req_parser_start;
	}

#line 412 "./c_src/request.rl"
    
    ret->cs = cs;
    
    return ret;
}
Example #14
0
int export_dives_xslt(const char *filename, const bool selected, const int units, const char *export_xslt)
{
	FILE *f;
	struct membuffer buf = { 0 };
	xmlDoc *doc;
	xsltStylesheetPtr xslt = NULL;
	xmlDoc *transformed;
	int res = 0;
	char *params[3];
	int pnr = 0;
	char unitstr[3];

	if (verbose)
		fprintf(stderr, "export_dives_xslt with stylesheet %s\n", export_xslt);

	if (!filename)
		return report_error("No filename for export");

	/* Save XML to file and convert it into a memory buffer */
	save_dives_buffer(&buf, selected);

	/*
	 * Parse the memory buffer into XML document and
	 * transform it to selected export format, finally dumping
	 * the XML into a character buffer.
	 */
	doc = xmlReadMemory(buf.buffer, buf.len, "divelog", NULL, 0);
	free_buffer(&buf);
	if (!doc)
		return report_error("Failed to read XML memory");

	/* Convert to export format */
	xslt = get_stylesheet(export_xslt);
	if (!xslt)
		return report_error("Failed to open export conversion stylesheet");

	snprintf(unitstr, 3, "%d", units);
	params[pnr++] = "units";
	params[pnr++] = unitstr;
	params[pnr++] = NULL;

	transformed = xsltApplyStylesheet(xslt, doc, (const char **)params);
	xmlFreeDoc(doc);

	/* Write the transformed export to file */
	f = subsurface_fopen(filename, "w");
	if (f) {
		xsltSaveResultToFile(f, transformed, xslt);
		fclose(f);
		/* Check write errors? */
	} else {
		res = report_error("Failed to open %s for writing (%s)", filename, strerror(errno));
	}
	xsltFreeStylesheet(xslt);
	xmlFreeDoc(transformed);

	return res;
}
Example #15
0
file *rl_decode(const char *data, long size) {
    int i;
    byte_buffer *buff = new_buffer(size);
    memcpy(buff->buffer, data, size);

    // 1. Get size of each run.
    uchar bytes[2];
    for (i = 0; i < 2; ++i) {
        bytes[i] = get_next_byte(buff);
    }
    const ushort NUM_BITS = *((ushort *)bytes);

    // 2. Decode data
    int zeros = 1;
    int remaining = 8 * size;
    int max_len = (4 * size)/3;

    byte_buffer *output = new_buffer(max_len);
    i = 0;

    while (remaining > NUM_BITS) {
        int bits = read_length(buff, NUM_BITS);
        for (i = 0; i < bits; ++i) {
            if (zeros) {
                append_bit_to_buffer(output, 0);
            } else {
                append_bit_to_buffer(output, 1);
            }
        }
        zeros = (zeros == 0)? 1 : 0;
        remaining -= NUM_BITS;
    }

    // 3. Convert output buffer to file
    file *f = (file *)malloc(sizeof(file));
    f->size = (long)output->current_byte;
    f->data = (char *)malloc(f->size);
    memcpy(f->data, output->buffer, f->size);

    // 4. Free resources
    free_buffer(output);
    free_buffer(buff);

    return f;
}
Example #16
0
int read_back (netbuffer_t *H, void *__data, int len) {
  netbuffer_t *X = H->prev, *Y;
  int s, w = 0;
  char *data = __data ? (char *) __data + len : 0;
  if (H->pptr) {
    if (len > H->unprocessed_bytes) {
      len = H->unprocessed_bytes;
    }
  } else {
    if (len > H->total_bytes) {
      len = H->total_bytes;
    }
  }

  if (X->wptr == X->rptr && X != H) {
    X = X->prev;
  }

  while (len > 0) {
    s = X->wptr - (X->pptr ? X->pptr : X->rptr);
    if (s > len) { s = len; }
    if (s > 0) {
      X->wptr -= s;
      if (data) {
	memcpy (data -= s, X->wptr, s);
      }
      w += s;
      len -= s;
    }
    if (X->rptr == X->wptr) {
      if (X == H) { 
	X->rptr = X->wptr = X->start;
	if (X->pptr) {
	  X->pptr = X->wptr;
	}
	break;
      } else {
	Y = X->prev;
	assert (H->extra > 0);
	Y->next = H;
	H->prev = Y;
	free_buffer (X);
	H->extra--;
	X = Y;
      }
    } else if (X->wptr == X->pptr) {
      break;
    }
  }

  if (H->pptr) {
    H->unprocessed_bytes -= w;
  } else {
    H->total_bytes -= w;
  }
  return w;
}
Example #17
0
void
test_parse_ether_fails_if_type_is_trancated_payload_ieee8023() {
  buffer *buffer = setup_dummy_snap_packet( );
  packet_info( buffer )->l2_data.eth->type = htons( sizeof( ether_header_t ) + sizeof( snap_header_t ) );

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Example #18
0
static void
handle_switch_ready( uint64_t datapath_id, void *user_data ) {
  UNUSED( user_data );

  uint32_t id = get_transaction_id();
  buffer *buf = create_features_request( id );
  send_openflow_message( datapath_id, buf );
  free_buffer( buf );
}
Example #19
0
void
test_parse_ether_fails_if_llc_is_unsupported_llc_snap() {
  buffer *buffer = setup_dummy_snap_packet( );
  ( ( snap_header_t * ) packet_info( buffer )->vtag )->llc[ 2 ] = 1;

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Example #20
0
void
test_parse_ether_fails_if_type_is_trancated_vlan() {
  buffer *buffer = setup_dummy_ether_packet(sizeof( ether_header_t ) );
  packet_info( buffer )->l2_data.eth->type = htons( ETH_ETHTYPE_TPID );

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Example #21
0
 ~MadDeque()
 {
     while(m_begin_iterator != m_end_iterator)
     {
         (m_begin_iterator.ptr)->~T();
         ++m_begin_iterator;
     }
     free_buffer();
 }
Example #22
0
void
test_parse_ether_fails_if_mac_address_is_wrong_mac() {
  buffer *buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) );
  packet_info( buffer )->l2_data.eth->macsa[ 0 ] = 0xff;

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Example #23
0
void
test_parse_ether_fails_if_ether_data_is_NULL() {
  buffer *buffer = setup_dummy_vlan_packet( );
  packet_info( buffer )->l2_data.eth = NULL;

  expect_assert_failure( parse_ether( buffer ) );

  free_buffer( buffer );
}
static int mx1_videobuf_prepare(struct videobuf_queue *vq,
		struct videobuf_buffer *vb, enum v4l2_field field)
{
	struct soc_camera_device *icd = vq->priv_data;
	struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
	int ret;
	int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
						icd->current_fmt->host_fmt);

	if (bytes_per_line < 0)
		return bytes_per_line;

	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
		vb, vb->baddr, vb->bsize);

	
	WARN_ON(!list_empty(&vb->queue));

	BUG_ON(NULL == icd->current_fmt);

	buf->inwork = 1;

	if (buf->code	!= icd->current_fmt->code ||
	    vb->width	!= icd->user_width ||
	    vb->height	!= icd->user_height ||
	    vb->field	!= field) {
		buf->code	= icd->current_fmt->code;
		vb->width	= icd->user_width;
		vb->height	= icd->user_height;
		vb->field	= field;
		vb->state	= VIDEOBUF_NEEDS_INIT;
	}

	vb->size = bytes_per_line * vb->height;
	if (0 != vb->baddr && vb->bsize < vb->size) {
		ret = -EINVAL;
		goto out;
	}

	if (vb->state == VIDEOBUF_NEEDS_INIT) {
		ret = videobuf_iolock(vq, vb, NULL);
		if (ret)
			goto fail;

		vb->state = VIDEOBUF_PREPARED;
	}

	buf->inwork = 0;

	return 0;

fail:
	free_buffer(vq, buf);
out:
	buf->inwork = 0;
	return ret;
}
Example #25
0
void
test_parse_ether_fails_if_packet_size_is_short_ethernet_size() {
  buffer *buffer = setup_dummy_ether_packet( sizeof( ether_header_t ) );
  buffer->length = sizeof( ether_header_t ) - ETH_ADDRLEN;

  assert_int_equal( parse_ether( buffer ), false );

  free_buffer( buffer );
}
Example #26
0
static void
test_calloc_packet_info_succeeds() {
  buffer *buf = alloc_buffer_with_length( sizeof( struct iphdr ) );

  calloc_packet_info( buf );
  assert_true( buf->user_data != NULL );

  free_buffer( buf );
}
Example #27
0
static int mx1_videobuf_prepare(struct videobuf_queue *vq,
		struct videobuf_buffer *vb, enum v4l2_field field)
{
	struct soc_camera_device *icd = vq->priv_data;
	struct mx1_buffer *buf = container_of(vb, struct mx1_buffer, vb);
	int ret;

	dev_dbg(icd->parent, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
		vb, vb->baddr, vb->bsize);

	/* Added list head initialization on alloc */
	WARN_ON(!list_empty(&vb->queue));

	BUG_ON(NULL == icd->current_fmt);

	/*
	 * I think, in buf_prepare you only have to protect global data,
	 * the actual buffer is yours
	 */
	buf->inwork = 1;

	if (buf->code	!= icd->current_fmt->code ||
	    vb->width	!= icd->user_width ||
	    vb->height	!= icd->user_height ||
	    vb->field	!= field) {
		buf->code	= icd->current_fmt->code;
		vb->width	= icd->user_width;
		vb->height	= icd->user_height;
		vb->field	= field;
		vb->state	= VIDEOBUF_NEEDS_INIT;
	}

	vb->size = icd->sizeimage;
	if (0 != vb->baddr && vb->bsize < vb->size) {
		ret = -EINVAL;
		goto out;
	}

	if (vb->state == VIDEOBUF_NEEDS_INIT) {
		ret = videobuf_iolock(vq, vb, NULL);
		if (ret)
			goto fail;

		vb->state = VIDEOBUF_PREPARED;
	}

	buf->inwork = 0;

	return 0;

fail:
	free_buffer(vq, buf);
out:
	buf->inwork = 0;
	return ret;
}
Example #28
0
static void
test_parse_packet_vtag_icmpv4_echo_reply_succeeds() {
  const char filename[] = "./unittests/lib/test_packets/vtag_icmp_echo_rep.cap";
  buffer *buffer = store_packet_to_buffer( filename );

  assert_true( parse_packet( buffer ) );

  packet_info *packet_info = buffer->user_data;

  assert_int_equal( packet_info->format, ETH_VTAG_IPV4_ICMPV4 );

  u_char macda[] = { 0x00, 0x1f, 0x3c, 0x48, 0xad, 0x3a };
  u_char macsa[] = { 0x00, 0x13, 0xd3, 0x40, 0x2e, 0x22 };
  assert_memory_equal( packet_info->eth_macda, macda, ETH_ADDRLEN );
  assert_memory_equal( packet_info->eth_macsa, macsa, ETH_ADDRLEN );

  assert_int_equal( packet_info->vlan_tci, 0x6f9f );
  assert_int_equal( packet_info->vlan_tpid, ETH_ETHTYPE_TPID );
  assert_int_equal( packet_info->vlan_prio, 3 );
  assert_int_equal( packet_info->vlan_cfi, 0 );
  assert_int_equal( packet_info->vlan_vid, 0x0f9f );

  assert_int_equal( packet_info->eth_type, ETH_ETHTYPE_IPV4 );

  assert_int_equal( packet_info->l2_payload_length, 60 );

  assert_int_equal( packet_info->ipv4_version, 4 );
  assert_int_equal( packet_info->ipv4_ihl, 5 );
  assert_int_equal( packet_info->ipv4_tos, 0 );
  assert_int_equal( packet_info->ipv4_tot_len, 0x3c );
  assert_int_equal( packet_info->ipv4_id, 0x1652 );
  assert_int_equal( packet_info->ipv4_frag_off, 0 );
  assert_int_equal( packet_info->ipv4_ttl, 0x40 );
  assert_int_equal( packet_info->ipv4_protocol, IPPROTO_ICMP );
  assert_int_equal( packet_info->ipv4_checksum, 0xa2d3 );
  assert_int_equal( packet_info->ipv4_saddr, 0xc0a82001 );
  assert_int_equal( packet_info->ipv4_daddr, 0xc0a8204a );

  assert_int_equal( packet_info->l3_payload_length, 40 );

  assert_int_equal( packet_info->icmpv4_type, ICMP_TYPE_ECHOREP );
  assert_int_equal( packet_info->icmpv4_code, 0 );
  assert_int_equal( packet_info->icmpv4_id, 1024 );
  assert_int_equal( packet_info->icmpv4_seq, 24576 );

  uint16_t sample = ntohs( *( uint16_t * ) packet_info->l4_payload );
  assert_int_equal( sample, 0x6162 );
  assert_int_equal( packet_info->l4_payload_length, 32 );

  assert_false( packet_type_icmpv4_echo_request( buffer ) );
  assert_false( packet_type_icmpv4_dst_unreach( buffer ) );
  assert_false( packet_type_icmpv4_redirect( buffer ) );
  assert_true( packet_type_icmpv4_echo_reply( buffer ) );

  free_buffer( buffer );
}
/*
 *	deallocate a tuple data structure
 */
void	free_tuple( TUPLE *tuple)
{
	if( tuple)
	{
		free_buffer( tuple->buffer, tuple->length);
		free( tuple);
		data.memory -= sizeof( TUPLE);
	}
	return;
}
Example #30
0
static void
set_miss_send_len_maximum( uint64_t datapath_id ) {
  uint32_t id = get_transaction_id();
  const uint16_t config_flags = OFPC_FRAG_NORMAL;
  const uint16_t miss_send_len = UINT16_MAX;
  buffer *buf = create_set_config( id, config_flags, miss_send_len );
  send_openflow_message( datapath_id, buf );

  free_buffer( buf );
}