src/lib/byteorder.c in trema-0.2.5 vs src/lib/byteorder.c in trema-0.2.6
- old
+ new
@@ -176,22 +176,48 @@
memset( dst->pad, 0, sizeof( dst->pad ) );
dst->queue_id = ntohl( src->queue_id );
}
+static void
+copy_action_vendor_body( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src, size_t body_length ) {
+ assert( src != NULL );
+ assert( dst != NULL );
+
+ if ( body_length > 0 ) {
+ const void *body_src = ( const char * ) src + sizeof( struct ofp_action_vendor_header );
+ void *body_dst = ( char * ) dst + sizeof( struct ofp_action_vendor_header );
+ bcopy( body_src, body_dst, body_length );
+ }
+}
+
+
void
ntoh_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src ) {
assert( src != NULL );
assert( dst != NULL );
dst->type = ntohs( src->type );
dst->len = ntohs( src->len );
dst->vendor = ntohl( src->vendor );
+ copy_action_vendor_body( dst, src, dst->len - sizeof( struct ofp_action_vendor_header ) );
}
void
+hton_action_vendor( struct ofp_action_vendor_header *dst, const struct ofp_action_vendor_header *src ) {
+ assert( src != NULL );
+ assert( dst != NULL );
+
+ dst->type = htons( src->type );
+ dst->len = htons( src->len );
+ dst->vendor = htonl( src->vendor );
+ copy_action_vendor_body( dst, src, src->len - sizeof( struct ofp_action_vendor_header ) );
+}
+
+
+void
ntoh_action( struct ofp_action_header *dst, const struct ofp_action_header *src ) {
assert( src != NULL );
assert( dst != NULL );
switch ( ntohs( src->type ) ) {
@@ -300,16 +326,16 @@
dst->hard_timeout = ntohs( fs->hard_timeout );
memset( &dst->pad2, 0, sizeof( dst->pad2 ) );
dst->cookie = ntohll( fs->cookie );
dst->packet_count = ntohll( fs->packet_count );
dst->byte_count = ntohll( fs->byte_count );
-
+
uint16_t actions_length = ( uint16_t ) ( ntohs( fs->length ) - offsetof( struct ofp_flow_stats, actions ) );
struct ofp_action_header *ah_src = fs->actions;
struct ofp_action_header *ah_dst = dst->actions;
-
+
while ( actions_length >= sizeof( struct ofp_action_header ) ) {
ntoh_action( ah_dst, ah_src );
actions_length = ( uint16_t ) ( actions_length - ah_dst->len );
ah_src = ( struct ofp_action_header * ) ( ( char * ) ah_src + ah_dst->len );
ah_dst = ( struct ofp_action_header * ) ( ( char * ) ah_dst + ah_dst->len );
@@ -343,11 +369,11 @@
uint16_t actions_length = ( uint16_t ) ( fs->length - offsetof( struct ofp_flow_stats, actions ) );
struct ofp_action_header *ah_src = fs->actions;
struct ofp_action_header *ah_dst = dst->actions;
-
+
while ( actions_length >= sizeof( struct ofp_action_header ) ) {
hton_action( ah_dst, ah_src );
actions_length = ( uint16_t ) ( actions_length - ah_src->len );
ah_dst = ( struct ofp_action_header * ) ( ( char * ) ah_dst + ah_src->len );
ah_src = ( struct ofp_action_header * ) ( ( char * ) ah_src + ah_src->len );
@@ -431,11 +457,11 @@
struct ofp_queue_prop_header *ph = xcalloc( 1, ntohs( src->len ) );
memcpy( ph, src, ntohs( src->len ) );
dst->property = ntohs( ph->property );
dst->len = ntohs( ph->len );
-
+
if ( dst->property == OFPQT_MIN_RATE ) {
struct ofp_queue_prop_min_rate *mr_src = ( struct ofp_queue_prop_min_rate * ) ph;
struct ofp_queue_prop_min_rate *mr_dst = ( struct ofp_queue_prop_min_rate * ) dst;
mr_dst->rate = ntohs( mr_src->rate );
@@ -455,10 +481,10 @@
struct ofp_queue_prop_header *ph = xcalloc( 1, src->len );
memcpy( ph, src, src->len );
dst->property = htons( ph->property );
dst->len = htons( ph->len );
-
+
if ( src->property == OFPQT_MIN_RATE ) {
struct ofp_queue_prop_min_rate *mr_src = ( struct ofp_queue_prop_min_rate * ) ph;
struct ofp_queue_prop_min_rate *mr_dst = ( struct ofp_queue_prop_min_rate * ) dst;
mr_dst->rate = htons( mr_src->rate );