size_t
ofl_structs_flow_stats_pack(struct ofl_flow_stats *src, struct ofp_flow_stats *dst, struct ofl_exp *exp) {
    size_t total_len, len;
    uint8_t *data;
    size_t i;

    total_len = sizeof(struct ofp_flow_stats) +
                ofl_structs_instructions_ofp_total_len(src->instructions, src->instructions_num, exp);

    dst->length = htons(total_len);
    dst->table_id = src->table_id;
    dst->pad = 0x00;
    dst->duration_sec = htonl(src->duration_sec);
    dst->duration_nsec = htonl(src->duration_nsec);
    dst->priority = htons(src->priority);
    dst->idle_timeout = htons(src->idle_timeout);
    dst->hard_timeout = htons(src->hard_timeout);
    memset(dst->pad2, 0x00, 6);
    dst->cookie = hton64(src->cookie);
    dst->packet_count = hton64(src->packet_count);
    dst->byte_count = hton64(src->byte_count);

    ofl_structs_match_pack(src->match, &(dst->match), exp);


    data = (uint8_t *)dst->instructions;

    for (i=0; i<src->instructions_num; i++) {
        len = ofl_structs_instructions_pack(src->instructions[i], (struct ofp_instruction *)data, exp);
        data += len;
    }

    return total_len;
}
示例#2
0
文件: dumppath.c 项目: 01org/opa-ff
/* Returns 0 on error, non-zero on success. */
int parse_gid(char *s, op_gid_t *gid)
{
	if (!strncmp(s,"0x",2)) {
		/* GID format */

		uint64_t prefix=0;
		uint64_t subnet=0;
		char *p, *l, *sep=":";
	
		p = strtok_r(s,sep,&l);
		if (!p) return 0;
	
		prefix = strtoull(p,NULL,0);
		if (!prefix) return 0;
	
		p = strtok_r(NULL, sep, &l);
		if (!p) return 0;
	
		subnet = strtoull(p,NULL,0);
		if (!subnet) return 0;
	
		gid->unicast.interface_id = hton64(subnet);
		gid->unicast.prefix = hton64(prefix);

		return 1;

	} else {
		/* Inet 6 format */

		return inet_pton(AF_INET6, s, gid->raw);
	}
	
}
示例#3
0
size_t
ofl_structs_flow_stats_pack(struct ofl_flow_stats *src, uint8_t *dst, struct ofl_exp *exp) {
    
    struct ofp_flow_stats *flow_stats;
    size_t total_len;
    uint8_t *data;
    size_t  i;
    
    total_len = ROUND_UP(sizeof(struct ofp_flow_stats) -4 + src->match->length,8) +
                ofl_structs_instructions_ofp_total_len(src->instructions, src->instructions_num, exp);
    
    flow_stats = (struct ofp_flow_stats*) dst;

    flow_stats->length = htons(total_len);
    flow_stats->table_id = src->table_id;
    flow_stats->pad = 0x00;
    flow_stats->duration_sec = htonl(src->duration_sec);
    flow_stats->duration_nsec = htonl(src->duration_nsec);
    flow_stats->priority = htons(src->priority);
    flow_stats->idle_timeout = htons(src->idle_timeout);
    flow_stats->hard_timeout = htons(src->hard_timeout);
    memset(flow_stats->pad2, 0x00, 6);
    flow_stats->cookie = hton64(src->cookie);
    flow_stats->packet_count = hton64(src->packet_count);
    flow_stats->byte_count = hton64(src->byte_count);
    data = (dst) + sizeof(struct ofp_flow_stats) - 4;
    
    ofl_structs_match_pack(src->match, &(flow_stats->match), data, HOST_ORDER, exp);
    data = (dst) + ROUND_UP(sizeof(struct ofp_flow_stats) -4 + src->match->length, 8);  
    
    for (i=0; i < src->instructions_num; i++) {
        data += ofl_structs_instructions_pack(src->instructions[i], (struct ofp_instruction *) data, exp);
    }
    return total_len;
}
示例#4
0
size_t
ofl_structs_bucket_counter_pack(struct ofl_bucket_counter *src, struct ofp_bucket_counter *dst) {
    dst->packet_count = hton64(src->packet_count);
    dst->byte_count = hton64(src->byte_count);

    return sizeof(struct ofp_bucket_counter);
}
static int
ofl_msg_pack_multipart_request_flow(struct ofl_msg_multipart_request_flow *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {

    struct ofp_multipart_request *req;
    struct ofp_flow_stats_request *stats;
    uint8_t *ptr;

    *buf_len = sizeof(struct ofp_multipart_request) + sizeof(struct ofp_flow_stats_request) + msg->match->length;
    *buf     = (uint8_t *)malloc(*buf_len);

    req = (struct ofp_multipart_request *)(*buf);
    stats = (struct ofp_flow_stats_request *)req->body;
    stats->table_id    =        msg->table_id;
    memset(stats->pad, 0x00, 3);
    stats->out_port    = htonl( msg->out_port);
    stats->out_group   = htonl( msg->out_group);
    memset(stats->pad2, 0x00, 4);
    stats->cookie      = hton64(msg->cookie);
    stats->cookie_mask = hton64(msg->cookie_mask);

    ptr = (*buf) + sizeof(struct ofp_multipart_request) + sizeof(struct ofp_flow_stats_request);
    ofl_structs_match_pack(msg->match, &(stats->match),ptr, HOST_ORDER, exp);

    return 0;
}
static int
ofl_msg_pack_flow_mod(struct ofl_msg_flow_mod *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {
    struct ofp_flow_mod *flow_mod;
    uint8_t *ptr;

    int i;

    *buf_len = ROUND_UP(sizeof(struct ofp_flow_mod)- 4 + msg->match->length,8) +
                ofl_structs_instructions_ofp_total_len(msg->instructions, msg->instructions_num, exp);

    *buf     = (uint8_t *)malloc(*buf_len);
    flow_mod = (struct ofp_flow_mod *)(*buf);
    flow_mod->cookie       = hton64(msg->cookie);
    flow_mod->cookie_mask  = hton64(msg->cookie_mask);
    flow_mod->table_id     =        msg->table_id;
    flow_mod->command      =        msg->command;
    flow_mod->idle_timeout = htons( msg->idle_timeout);
    flow_mod->hard_timeout = htons( msg->hard_timeout);
    flow_mod->priority     = htons( msg->priority);
    flow_mod->buffer_id    = htonl( msg->buffer_id);
    flow_mod->out_port     = htonl( msg->out_port);
    flow_mod->out_group    = htonl( msg->out_group);
    flow_mod->flags        = htons( msg->flags);
    memset(flow_mod->pad, 0x00, 2);

    ptr  = (*buf) + sizeof(struct ofp_flow_mod)- 4;
    ofl_structs_match_pack(msg->match, &(flow_mod->match), ptr, HOST_ORDER, exp);
    /* We advance counting the padded bytes */
    ptr = (*buf) + ROUND_UP(sizeof(struct ofp_flow_mod)- 4 + msg->match->length,8);
    for (i=0; i<msg->instructions_num; i++) {
        ptr += ofl_structs_instructions_pack(msg->instructions[i], (struct ofp_instruction *)ptr, exp);
    }
    return 0;
}
示例#7
0
size_t
ofl_structs_group_stats_pack(struct ofl_group_stats *src, struct ofp_group_stats *dst) {
    size_t total_len, len;
    uint8_t *data;
    size_t i;

    total_len = sizeof(struct ofp_group_stats) +
                sizeof(struct ofp_bucket_counter) * src->counters_num;

    dst->length =       htons( total_len);
    memset(dst->pad, 0x00, 2);
    dst->group_id =     htonl( src->group_id);
    dst->ref_count =    htonl( src->ref_count);
    memset(dst->pad2, 0x00, 4);
    dst->packet_count = hton64(src->packet_count);
    dst->byte_count =   hton64(src->byte_count);

    data = (uint8_t *)dst->bucket_stats;

    for (i=0; i<src->counters_num; i++) {
        len = ofl_structs_bucket_counter_pack(src->counters[i], (struct ofp_bucket_counter *)data);
        data += len;
    }

    return total_len;
}
示例#8
0
int afp_getextattr(struct afp_volume * volume, unsigned int dirid,
	unsigned short bitmap, unsigned int replysize , 
	char * pathname,
	unsigned short namelen, char * name, struct afp_extattr_info * i)
{
	struct {
		struct dsi_header dsi_header __attribute__((__packed__));
		uint8_t command;
		char pad;
		uint16_t volid ;
		uint32_t dirid ;
		uint16_t bitmap ;
		uint64_t offset ;
		uint64_t reqcount;
		uint32_t replysize;
	} __attribute__((__packed__)) *request_packet;
	struct {
		uint16_t len;
		char * name ;
	} __attribute__((__packed__)) * req2;
	struct afp_server * server = volume->server;
	unsigned int len = sizeof(*request_packet)+
		sizeof_path_header(server)+strlen(pathname)
		+1+sizeof(unsigned int) + strlen(name);
	char * p,*p2;
	int ret;
	char * msg = malloc(len);
	if (!msg) {
		log_for_client(NULL,AFPFSD,LOG_WARNING,"Out of memory\n");
		return -1;
	};
	p= msg + (sizeof(*request_packet));
	request_packet=(void *) msg;

	dsi_setup_header(server,&request_packet->dsi_header,DSI_DSICommand);
	request_packet->command=afpGetExtAttr;
	request_packet->pad=0;
	request_packet->volid=htons(volume->volid);
	request_packet->dirid=htonl(dirid);
	request_packet->offset=hton64(0);
	request_packet->reqcount=hton64(0);
	request_packet->replysize=htonl(replysize);
	copy_path(server,p,pathname,strlen(pathname));
	unixpath_to_afppath(server,p);
	p2=p+sizeof_path_header(server)+strlen(pathname);
	if (((unsigned int ) p2) & 0x1) p2++;
	req2=(void *) p2;

	req2->len=htons(namelen);
	memcpy(&req2->name,name,namelen);

	len=(p2+namelen)-msg;

	ret=dsi_send(server, (char *) request_packet,len,DSI_DEFAULT_TIMEOUT, 
		afpDelete ,(void *) i);

	free(msg);
	
	return ret;
}
static int
ofl_msg_pack_flow_removed(struct ofl_msg_flow_removed *msg, uint8_t **buf, size_t *buf_len, struct ofl_exp *exp) {
    struct ofp_flow_removed *ofr;

    uint8_t *ptr;
    *buf_len = ROUND_UP((sizeof(struct ofp_flow_removed) -4) + msg->stats->match->length ,8);
    *buf     = (uint8_t *)malloc(*buf_len);

    ofr = (struct ofp_flow_removed *)(*buf);
    ofr->cookie        = hton64(msg->stats->cookie);
    ofr->priority      = htons(msg->stats->priority);
    ofr->reason        =        msg->reason;
    ofr->table_id      =        msg->stats->table_id;
    ofr->duration_sec  = htonl( msg->stats->duration_sec);
    ofr->duration_nsec = htonl( msg->stats->duration_nsec);
    ofr->idle_timeout  = htons( msg->stats->idle_timeout);
    ofr->packet_count  = hton64(msg->stats->packet_count);
    ofr->byte_count    = hton64(msg->stats->byte_count);

    ptr = (*buf) + (sizeof(struct ofp_flow_removed) - 4);

    ofl_structs_match_pack(msg->stats->match, &(ofr->match),ptr, HOST_ORDER, exp);

    return 0;
}
示例#10
0
int afp_byterangelockext(struct afp_volume * volume,
	unsigned char flag,
	unsigned short forkid, 
	uint64_t offset,
	uint64_t len, uint64_t *generated_offset) 
{
	struct {
		struct dsi_header dsi_header __attribute__((__packed__));
		uint8_t command;
		uint8_t flag;
		uint16_t forkid;
		uint64_t offset;
		uint64_t len;
	}  __attribute__((__packed__)) request;
	int rc;

	dsi_setup_header(volume->server,&request.dsi_header,DSI_DSICommand);
	request.command=afpByteRangeLockExt;
	request.flag=flag;
	request.forkid=htons(forkid);
	request.offset=hton64(offset);
	request.len=hton64(len);
	rc=dsi_send(volume->server, (char *) &request,
		sizeof(request),DSI_DEFAULT_TIMEOUT,
		afpByteRangeLockExt,(void *) generated_offset);
	return rc;
}
示例#11
0
size_t
ofl_structs_pack_band_stats(struct ofl_meter_band_stats *src, struct ofp_meter_band_stats *dst){

    dst->packet_band_count = hton64(src->packet_band_count);
    dst->byte_band_count = hton64(src->byte_band_count);

    return sizeof(struct ofp_meter_band_stats);
}
示例#12
0
size_t
ofl_structs_queue_stats_pack(struct ofl_queue_stats *src, struct ofp_queue_stats *dst) {
    dst->port_no = htonl(src->port_no);
    dst->queue_id = htonl(src->queue_id);
    dst->tx_bytes = hton64(src->tx_bytes);
    dst->tx_packets = hton64(src->tx_packets);
    dst->tx_errors = hton64(src->tx_errors);

    return sizeof(struct ofp_queue_stats);
}
示例#13
0
size_t
ofl_structs_table_stats_pack(struct ofl_table_stats *src, struct ofp_table_stats *dst) {
    dst->table_id =    src->table_id;
    memset(dst->pad, 0x00, 3);
    dst->active_count =  htonl( src->active_count);
    dst->lookup_count =  hton64(src->lookup_count);
    dst->matched_count = hton64(src->matched_count);

    return sizeof(struct ofp_table_stats);
}
示例#14
0
/* --rpw fix: maruEncryptBlock was broken for block != to */
EXPORT void maruEncryptBlock(maruAspect *a, u_char *block, u_char *to, int len, m_u32 blockno, int flags)
{
    maruKey key;
    m_u64 *block8 = (m_u64*)block,
	      *iv8 = (m_u64*)a->whitener,
	      *to8 = (m_u64*)to;

    int keysize;
    assert((a->blockCipher->blocksize == 0) || ((len%a->blockCipher->blocksize) == 0));
    keysize = MIN(sizeof key, EITHER(a->blockCipher->keylen, sizeof key)); /* XXX careful */
    assert((keysize&7) == 0);
    maruGenBlockKey(a, &key, keysize, blockno);
    a->blockCipher->setkey(a->blockOpaque, key.data, keysize, flags);
    if (flags & MCD_ENCRYPT)
	{
	    int n;
	    m_u64 sum = 0;

	    for (n=len/8; --n>0; )
		{
		    block8[n] ^= iv8[n];
		    sum ^= block8[n];
		}
	    block8[0] ^= sum ^ hton64(blockno);
	}
    a->blockCipher->crypt(a->blockOpaque, NULL /* do the iv's by hand */, block, to, len, flags);

    /* --rpw restore contents of original block */
    if (flags & MCD_ENCRYPT && block != to)
	{
	    int n;
	    m_u64 sum = 0;

	    for (n=len/8; --n>0; )
		{
		    sum ^= block8[n];
		    block8[n] ^= iv8[n];
		}
	    block8[0] ^= sum ^ hton64(blockno);
	}
    if (flags & MCD_DECRYPT)
	{
	    int n;
	    m_u64 sum = 0;

	    for (n=len/8; --n>0; )
		{
		    sum ^= to8[n];
		    to8[n] ^= iv8[n];
		}
	    to8[0] ^= sum ^ hton64(blockno);
	}
     bzero(&key, sizeof key);
}
示例#15
0
文件: send.c 项目: Handy2015/h2o
yrmcds_error yrmcds_decr(yrmcds* c, const char* key, size_t key_len,
                         uint64_t value, int quiet, uint32_t* serial) {
    if( c == NULL || key == NULL || key_len == 0 )
        return YRMCDS_BAD_ARGUMENT;

    char extras[20];
    hton64(value, extras);
    hton64((uint64_t)0, &extras[8]);
    hton32(~(uint32_t)0, &extras[16]);
    return send_command(c, quiet ? YRMCDS_CMD_DECREMENTQ : YRMCDS_CMD_DECREMENT,
                        0, serial, key_len, key,
                        sizeof(extras), extras, 0, NULL);
}
示例#16
0
文件: osc_mem.c 项目: CNMAT/libo
t_osc_err osc_mem_encodeByteorder(unsigned char typetag, char *data, char **out)
{
	size_t size = osc_sizeof(typetag, data);
	if(!osc_mem_shouldByteswap(typetag)){
		memcpy(*out, data, size);
		return OSC_ERR_NONE;
	}
	char tmp[size];
	switch(size){
	case 1:
		break;
	case 2:
		*((uint16_t *)tmp) = hton16(*((uint16_t *)data));
		break;
	case 4:
		*((uint32_t *)tmp) = hton32(*((uint32_t *)data));
		break;
	case 8:
		*((uint64_t *)tmp) = hton64(*((uint64_t *)data));
		break;	
	case 16:
		*((uint128_t *)tmp) = hton128(*((uint128_t *)data));
		break;
	}
	memcpy(*out, tmp, size);
	return OSC_ERR_NONE;
}
示例#17
0
static int write_snoop(int fd, int type, int incoming, unsigned char *buf, int len)
{
	struct btsnoop_pkt pkt;
	struct timeval tv;
	uint32_t size = len;
	uint64_t ts;
	int err;

	if (fd < 0)
		return -1;

	memset(&tv, 0, sizeof(tv));
	gettimeofday(&tv, NULL);
	ts = (tv.tv_sec - 946684800ll) * 1000000ll + tv.tv_usec;

	pkt.size = htonl(size);
	pkt.len  = pkt.size;
	pkt.flags = ntohl(incoming & 0x01);
	pkt.drops = htonl(0);
	pkt.ts = hton64(ts + 0x00E03AB44A676000ll);

	if (type == HCI_COMMAND_PKT || type == HCI_EVENT_PKT)
		pkt.flags |= ntohl(0x02);

	err = write(fd, &pkt, BTSNOOP_PKT_SIZE);
	err = write(fd, buf, size);

	return 0;
}
static int
ofl_msg_pack_features_reply(struct ofl_msg_features_reply *msg, uint8_t **buf, size_t *buf_len) {
    struct ofp_switch_features *features;
    uint8_t *ptr;
    int i;

    *buf_len = sizeof(struct ofp_switch_features) + msg->ports_num * sizeof(struct ofp_port);
    *buf     = (uint8_t *)malloc(*buf_len);

    features = (struct ofp_switch_features *)(*buf);
    features->datapath_id  = hton64(msg->datapath_id);
    features->n_buffers    = htonl( msg->n_buffers);
    features->n_tables     =        msg->n_tables;
    memset(features->pad, 0x00, 3);
    features->capabilities = htonl( msg->capabilities);
    features->reserved = 0x00000000;

    ptr  = (*buf) + sizeof(struct ofp_switch_features);

    for (i=0; i<msg->ports_num; i++) {
        ptr += ofl_structs_port_pack(msg->ports[i], (struct ofp_port *)ptr);
    }

    return 0;
}
示例#19
0
/*
 *  status = recToBinKey(rwrec, bin_val, &index, NULL);
 *
 *    Given the SiLK Flow record 'rwrec', compute the flow-rate ratio
 *    specified by '*index', and write a binary representation of
 *    that value into 'bin_val'.
 */
static skplugin_err_t
recToBinKey(
    const rwRec            *rwrec,
    uint8_t                *bin_value,
    void                   *idx,
    void           UNUSED(**extra))
{
    uint64_t val_u64;

    switch (*((unsigned int*)(idx))) {
      case PAYLOAD_BYTES_KEY:
        val_u64 = getPayload(rwrec);
        break;
      case PAYLOAD_RATE_KEY:
        val_u64 = DOUBLE_TO_UINT64(PAYLOAD_RATE_RWREC(rwrec));
        break;
      case PCKTS_PER_SEC_KEY:
        val_u64 = DOUBLE_TO_UINT64(PCKT_RATE_RWREC(rwrec));
        break;
      case BYTES_PER_SEC_KEY:
        val_u64 = DOUBLE_TO_UINT64(BYTE_RATE_RWREC(rwrec));
        break;
      case BYTES_PER_PACKET_KEY:
        val_u64 = DOUBLE_TO_UINT64(BYTES_PER_PACKET_RWREC(rwrec));
        break;
      default:
        return SKPLUGIN_ERR_FATAL;
    }

    val_u64 = hton64(val_u64);
    memcpy(bin_value, &val_u64, RATE_BINARY_SIZE_KEY);
    return SKPLUGIN_OK;
}
static gboolean sync_send_indication(gpointer user_data)
{
	struct mcap_mcl *mcl;
	mcap_md_sync_info_ind *cmd;
	uint32_t btclock;
	uint64_t tmstamp;
	struct timespec base_time;
	int sent;

	if (!user_data)
		return FALSE;

	mcl = user_data;

	if (!caps(mcl))
		return FALSE;

	if (!get_all_clocks(mcl, &btclock, &base_time, &tmstamp))
		return FALSE;

	cmd = g_new0(mcap_md_sync_info_ind, 1);

	cmd->op = MCAP_MD_SYNC_INFO_IND;
	cmd->btclock = htonl(btclock);
	cmd->timestst = hton64(tmstamp);
	cmd->timestsa = htons(caps(mcl)->latency);

	sent = send_sync_cmd(mcl, cmd, sizeof(*cmd));
	g_free(cmd);

	return !sent;
}
示例#21
0
文件: gtpie.c 项目: Dosxiong/learngit
int gtpie_tv8(void *p, unsigned int *length, unsigned int size, uint8_t t, uint64_t v) {
  if ((*length + 9) >= size) return 1;
  ((union gtpie_member*) (p + *length))->tv8.t = hton8(t);
  ((union gtpie_member*) (p + *length))->tv8.v = hton64(v);
  *length += 9;
  return 0;
}
static int
ofl_msg_pack_packet_in(struct ofl_msg_packet_in *msg, uint8_t **buf, size_t *buf_len) {
    struct ofp_packet_in *packet_in;
    uint8_t *ptr;

    *buf_len = sizeof(struct ofp_packet_in) + ROUND_UP(msg->match->length - 4 ,8) + msg->data_length + 2;
    *buf     = (uint8_t *)malloc(*buf_len);
    packet_in = (struct ofp_packet_in *)(*buf);
    packet_in->buffer_id   = htonl(msg->buffer_id);
    packet_in->total_len   = htons(msg->total_len);
    packet_in->reason      =       msg->reason;
    packet_in->table_id    =       msg->table_id;
    packet_in->cookie      = hton64(msg->cookie);

    ptr = (*buf) + (sizeof(struct ofp_packet_in) - 4);
    ofl_structs_match_pack(msg->match,&(packet_in->match),ptr, NETWORK_ORDER, NULL);
    ptr = (*buf) + ROUND_UP((sizeof(struct ofp_packet_in)-4) + msg->match->length,8);
    /*padding bytes*/

    memset(ptr,0,2);
    /* Ethernet frame */
    if (msg->data_length > 0) {
        memcpy(ptr + 2 , msg->data, msg->data_length);
    }

    return 0;
}
示例#23
0
文件: ws.c 项目: odmanV2/freecenter
ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes)
{
	uint8_t hdr[14] = { 0 };
	size_t hlen = 2;
	uint8_t *bp;
	ssize_t raw_ret = 0;

	if (wsh->down) {
		return -1;
	}

	//printf("WRITE[%ld]-----------------------------:\n[%s]\n-----------------------------------\n", bytes, (char *) data);

	hdr[0] = (uint8_t)(oc | 0x80);

	if (bytes < 126) {
		hdr[1] = (uint8_t)bytes;
	} else if (bytes < 0x10000) {
		uint16_t *u16;

		hdr[1] = 126;
		hlen += 2;

		u16 = (uint16_t *) &hdr[2];
		*u16 = htons((uint16_t) bytes);

	} else {
		uint64_t *u64;

		hdr[1] = 127;
		hlen += 8;
		
		u64 = (uint64_t *) &hdr[2];
		*u64 = hton64(bytes);
	}

	if (wsh->write_buffer_len < (hlen + bytes + 1)) {
		void *tmp;

		wsh->write_buffer_len = hlen + bytes + 1;
		if ((tmp = realloc(wsh->write_buffer, wsh->write_buffer_len))) {
			wsh->write_buffer = tmp;
		} else {
			abort();
		}
	}
	
	bp = (uint8_t *) wsh->write_buffer;
	memcpy(bp, (void *) &hdr[0], hlen);
	memcpy(bp + hlen, data, bytes);
	
	raw_ret = ws_raw_write(wsh, bp, (hlen + bytes));

	if (raw_ret != (ssize_t) (hlen + bytes)) {
		return raw_ret;
	}
	
	return bytes;
}
示例#24
0
size_t
ofl_structs_table_stats_pack(struct ofl_table_stats *src, struct ofp_table_stats *dst) {
    dst->table_id =    src->table_id;
    memset(dst->pad, 0x00, 7);
    strncpy(dst->name, src->name, OFP_MAX_TABLE_NAME_LEN);
    dst->wildcards =     htonl( src->wildcards);
    dst->match =         htonl( src->match);
    dst->instructions =  htonl( src->instructions);
    dst->write_actions = htonl( src->write_actions);
    dst->apply_actions = htonl( src->apply_actions);
    dst->config =        htonl( src->config);
    dst->max_entries =   htonl( src->max_entries);
    dst->active_count =  htonl( src->active_count);
    dst->lookup_count =  hton64(src->lookup_count);
    dst->matched_count = hton64(src->matched_count);

    return sizeof(struct ofp_table_stats);
}
size_t
ofl_structs_match_pack(struct ofl_match_header *src, struct ofp_match *dst, struct ofl_exp *exp) {
    switch (src->type) {
        case (OFPMT_STANDARD): {
            struct ofl_match_standard *m = (struct ofl_match_standard *)src;

            dst->type =          htons( m->header.type);
            dst->length =        htons( OFPMT_STANDARD_LENGTH);
            dst->in_port =       htonl( m->in_port);
            dst->wildcards =     htonl( m->wildcards);
            memcpy(&(dst->dl_src),      &(m->dl_src),      OFP_ETH_ALEN);
            memcpy(&(dst->dl_src_mask), &(m->dl_src_mask), OFP_ETH_ALEN);
            memcpy(&(dst->dl_dst),      &(m->dl_dst),      OFP_ETH_ALEN);
            memcpy(&(dst->dl_dst_mask), &(m->dl_dst_mask), OFP_ETH_ALEN);
            dst->dl_vlan =       htons( m->dl_vlan);
            dst->dl_vlan_pcp =          m->dl_vlan_pcp;
            memset(dst->pad1, 0x00, 1);
            dst->dl_type =       htons( m->dl_type);
            dst->nw_tos =               m->nw_tos;
            dst->nw_proto =             m->nw_proto;
            dst->nw_src =               m->nw_src;
            dst->nw_src_mask =          m->nw_src_mask;
            dst->nw_dst =               m ->nw_dst;
            dst->nw_dst_mask =          m->nw_dst_mask;
            dst->tp_src =        htons( m->tp_src);
            dst->tp_dst =        htons( m->tp_dst);
            dst->mpls_label =    htonl( m->mpls_label);
            dst->mpls_tc =              m->mpls_tc;
            memset(dst->pad2, 0x00, 3);
            dst->metadata =      hton64(m->metadata);
            dst->metadata_mask = hton64(m->metadata_mask);

            return sizeof(struct ofp_match);
        }
        default: {
            if (exp == NULL || exp->match == NULL || exp->match->pack == NULL) {
                OFL_LOG_WARN(LOG_MODULE, "Trying to pack experimenter match, but no callback was given.");
                return -1;
            }
            return exp->match->pack(src, dst);
        }
    }
}
示例#26
0
int32_t
quota_dict_set_meta (dict_t *dict, char *key, const quota_meta_t *meta,
                     ia_type_t ia_type)
{
        int32_t         ret      = -1;
        quota_meta_t   *value    = NULL;

        value = GF_CALLOC (1, sizeof (quota_meta_t), gf_common_quota_meta_t);
        if (value == NULL) {
                gf_log_callingfn ("quota", GF_LOG_ERROR,
                                  "Memory allocation failed");
                goto out;
        }

        value->size = hton64 (meta->size);
        value->file_count = hton64 (meta->file_count);
        value->dir_count = hton64 (meta->dir_count);

        if (ia_type == IA_IFDIR) {
                ret = dict_set_bin (dict, key, value, sizeof (*value));
        } else {
                /* For a file we don't need to store dir_count in the
                 * quota size xattr, so we set the len of the data in the dict
                 * as 128bits, so when the posix xattrop reads the dict, it only
                 * performs operations on size and file_count
                 */
                ret = dict_set_bin (dict, key, value,
                                    sizeof (*value) - sizeof (int64_t));
        }

        if (ret < 0) {
                gf_log_callingfn ("quota", GF_LOG_ERROR, "dict set failed");
                GF_FREE (value);
        }

out:
        return ret;
}
示例#27
0
/* ###### Convert double to machine-independent form ##################### */
network_double_t doubleToNetwork(const double d)
{
   struct IeeeDouble ieee;

   if(isnan(d)) {
      // NaN
      ieee.s = 0;
      ieee.e = DBL_EXP_MAX + DBL_EXP_BIAS;
      ieee.f1 = 1;
      ieee.f2 = 1;
   } else if(isinf(d)) {
      // +/- infinity
      ieee.s = (d < 0);
      ieee.e = DBL_EXP_MAX + DBL_EXP_BIAS;
      ieee.f1 = 0;
      ieee.f2 = 0;
   } else if(d == 0.0) {
      // zero
      ieee.s = 0;
      ieee.e = 0;
      ieee.f1 = 0;
      ieee.f2 = 0;
   } else {
      // finite number
      int exp;
      double frac = frexp (fabs (d), &exp);

      while (frac < 1.0 && exp >= DBL_EXP_MIN) {
         frac = ldexp (frac, 1);
         --exp;
      }
      if (exp < DBL_EXP_MIN) {
          // denormalized number (or zero)
          frac = ldexp (frac, exp - DBL_EXP_MIN);
          exp = 0;
      } else {
         // normalized number
         CHECK((1.0 <= frac) && (frac < 2.0));
         CHECK((DBL_EXP_MIN <= exp) && (exp <= DBL_EXP_MAX));

         exp += DBL_EXP_BIAS;
         frac -= 1.0;
      }
      ieee.s = (d < 0);
      ieee.e = exp;
      ieee.f1 = (unsigned long)ldexp (frac, DBL_FRC1_BITS);
      ieee.f2 = (unsigned long)ldexp (frac, DBL_FRC_BITS);
   }
   return(hton64(*((network_double_t*)&ieee)));
}
void mcap_sync_set_req(struct mcap_mcl *mcl, uint8_t update, uint32_t btclock,
			uint64_t timestamp, mcap_sync_set_cb cb,
			gpointer user_data, GError **err)
{
	mcap_md_sync_set_req *cmd;
	struct mcap_sync_set_cbdata *cbdata;

	if (!mcl->mi->csp_enabled || !mcl->csp) {
		g_set_error(err,
			MCAP_CSP_ERROR,
			MCAP_ERROR_RESOURCE_UNAVAILABLE,
			"CSP not enabled for the instance");
		return;
	}

	if (!mcl->csp->local_caps) {
		g_set_error(err,
			MCAP_CSP_ERROR,
			MCAP_ERROR_RESOURCE_UNAVAILABLE,
			"Did not get CSP caps from slave yet");
		return;
	}

	if (mcl->csp->csp_req) {
		g_set_error(err,
			MCAP_CSP_ERROR,
			MCAP_ERROR_RESOURCE_UNAVAILABLE,
			"Pending CSP request");
		return;
	}

	mcl->csp->csp_req = MCAP_MD_SYNC_SET_REQ;
	cmd = g_new0(mcap_md_sync_set_req, 1);

	cmd->op = MCAP_MD_SYNC_SET_REQ;
	cmd->timestui = update;
	cmd->btclock = htonl(btclock);
	cmd->timestst = hton64(timestamp);

	mcl->csp->ind_expected = update;

	cbdata = g_new0(struct mcap_sync_set_cbdata, 1);
	cbdata->cb = cb;
	cbdata->user_data = user_data;
	mcl->csp->csp_priv_data = cbdata;

	send_sync_cmd(mcl, cmd, sizeof(*cmd));

	g_free(cmd);
}
static int
ofl_msg_pack_role_request(struct ofl_msg_role_request *msg, uint8_t **buf, size_t *buf_len) {
        struct ofp_role_request *req;

        *buf_len = sizeof(struct ofp_role_request);
        *buf     = (uint8_t *)malloc(*buf_len);

        req = (struct ofp_role_request *)(*buf);
        req->role =  htonl(msg->role);
        memset(req->pad,0,sizeof(req->pad));
        req->generation_id = hton64(msg->generation_id);

        return 0;
}
示例#30
0
size_t
ofl_structs_table_features_pack(struct ofl_table_features *src, struct ofp_table_features *dst, uint8_t *data,  struct ofl_exp *exp){
    size_t total_len;
    uint8_t *ptr;
    int i;


    total_len = sizeof(struct ofp_table_features) + ofl_structs_table_features_properties_ofp_total_len(src->properties,src->properties_num,exp);
    dst->table_id = src->table_id;
    memset(dst->pad, 0x0,5);
    strncpy(dst->name,src->name, OFP_MAX_TABLE_NAME_LEN);
    dst->metadata_match = hton64(src->metadata_match);
    dst->metadata_write = hton64(src->metadata_write);
    dst->config = htonl(src->config);
    dst->max_entries = htonl(src->max_entries);

    ptr = (uint8_t*) (data + sizeof(struct ofp_table_features));
    for(i = 0; i < src->properties_num; i++){
        ptr += ofl_structs_table_properties_pack(src->properties[i], (struct ofp_table_feature_prop_header*) ptr, ptr, exp);
    }
    dst->length = htons(total_len);
    return total_len;
}