ia64/xen-unstable

changeset 6758:7ae8090e5f67

The last vnet patch was missing some files that had been added
to my tree but did not appear in 'hg diff'. This patch adds them.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Sep 12 14:11:59 2005 +0000 (2005-09-12)
parents 413c911e5780
children 888094e5ac07
files tools/vnet/Make.env tools/vnet/examples/vnet-insert tools/vnet/libxutil/mem_stream.c tools/vnet/libxutil/mem_stream.h tools/vnet/vnet-module/varp_util.c tools/vnet/vnet-module/varp_util.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/vnet/Make.env	Mon Sep 12 14:11:59 2005 +0000
     1.3 @@ -0,0 +1,20 @@
     1.4 +# -*- mode: Makefile; -*-
     1.5 +
     1.6 +export XEN_ROOT        = $(shell cd $(VNET_ROOT)/../.. && pwd)
     1.7 +export LINUX_SERIES   ?= 2.6
     1.8 +
     1.9 +DISTDIR               ?= $(XEN_ROOT)/dist
    1.10 +export DESTDIR        ?= $(DISTDIR)/install
    1.11 +
    1.12 +export VNET_MODULE_DIR = $(VNET_ROOT)/vnet-module
    1.13 +export VNETD_DIR       = $(VNET_ROOT)/vnetd
    1.14 +export LIBXUTIL_DIR    = $(VNET_ROOT)/libxutil
    1.15 +
    1.16 +export GC_DIR          = $(VNET_ROOT)/build/gc
    1.17 +export GC_INCLUDE      = $(GC_DIR)/include
    1.18 +export GC_LIB_DIR      = $(GC_DIR)/lib
    1.19 +export GC_LIB_A        = $(GC_LIB_DIR)/libgc.a
    1.20 +export GC_LIB_SO       = $(GC_LIB_DIR)/libgc.so
    1.21 +
    1.22 +#$(warning XEN_ROOT  = $(XEN_ROOT))
    1.23 +#$(warning DESTDIR   = $(DESTDIR))
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/vnet/examples/vnet-insert	Mon Sep 12 14:11:59 2005 +0000
     2.3 @@ -0,0 +1,28 @@
     2.4 +#!/bin/bash
     2.5 +
     2.6 +# Insert the vnet module if it can be found and
     2.7 +# it's not already there.
     2.8 +vnet_insert () {
     2.9 +    local module="vnet_module"
    2.10 +    local mod_dir=/lib/modules/$(uname -r)
    2.11 +    local mod_obj=""
    2.12 +
    2.13 +    if lsmod | grep -q ${module} ; then
    2.14 +        echo "VNET: ${module} loaded"
    2.15 +        return
    2.16 +    fi
    2.17 +    local mods=$(find ${mod_dir} -name "${module}.*o")
    2.18 +    if [[ ${mods} ]] ; then
    2.19 +        for mod_obj in ${mods} ; do
    2.20 +            break
    2.21 +        done
    2.22 +    fi
    2.23 +    if [ -z "${mod_obj}" ] ; then
    2.24 +        echo "VNET: ${module} not found"
    2.25 +        exit 1
    2.26 +    fi
    2.27 +    echo "VNET: Loading ${module} from ${mod_obj}"
    2.28 +    insmod ${mod_obj} "$@"
    2.29 +}
    2.30 +
    2.31 +vnet_insert "$@"
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/vnet/libxutil/mem_stream.c	Mon Sep 12 14:11:59 2005 +0000
     3.3 @@ -0,0 +1,319 @@
     3.4 +/*
     3.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     3.6 + *
     3.7 + * This library is free software; you can redistribute it and/or modify
     3.8 + * it under the terms of the GNU Lesser General Public License as published by
     3.9 + * the Free Software Foundation; either version 2.1 of the License, or
    3.10 + * (at your option) any later version.
    3.11 + *
    3.12 + * This library is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 + * GNU Lesser General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU Lesser General Public License
    3.18 + * along with this library; if not, write to the Free Software
    3.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.20 + */
    3.21 +
    3.22 +/** @file
    3.23 + * IOStream subtype for input and output to memory.
    3.24 + * Usable from user or kernel code (with __KERNEL__ defined).
    3.25 + */
    3.26 +
    3.27 +#include "sys_string.h"
    3.28 +#include "mem_stream.h"
    3.29 +#include "allocate.h"
    3.30 +
    3.31 +/** Internal state for a memory stream.
    3.32 + *
    3.33 + * The memory stream buffer is treated as a circular buffer.
    3.34 + * The lo and hi markers indicate positions in the buffer, but
    3.35 + * are not reduced modulo the buffer size. This avoids the ambiguity
    3.36 + * between a full and empty buffer when using reduced values.
    3.37 + *
    3.38 + * If x is a marker, then buf + (x % buf_n) is the corresponding
    3.39 + * pointer into the buffer. When the buffer is empty, lo == hi,
    3.40 + * and the corresponding pointers are equal. When the buffer is
    3.41 + * full, hi == lo + buf_n, and the corresponding pointers
    3.42 + * are also equal.
    3.43 + *
    3.44 + * Data is written after the high pointer and read from the lo pointer.
    3.45 + * The value hi - lo is the number of bytes in the buffer.
    3.46 + */
    3.47 +typedef struct MemData {
    3.48 +    /** Data buffer. */
    3.49 +    char *buf;
    3.50 +    /** Low marker - start of readable area. */
    3.51 +    unsigned long lo;
    3.52 +    /** High marker - end of readable area, start of writeable area. */
    3.53 +    unsigned long hi;
    3.54 +    /** Size of the buffer. */
    3.55 +    unsigned int buf_n;
    3.56 +    /** Maximum size the buffer can grow to. */
    3.57 +    unsigned int buf_max;
    3.58 +    /** Error code. */
    3.59 +    int err;
    3.60 +} MemData;
    3.61 +
    3.62 +/** Get number of bytes available to read.
    3.63 + *
    3.64 + * @param data mem stream
    3.65 + * @return bytes
    3.66 + */
    3.67 +static inline int mem_len(struct MemData *data){
    3.68 +    return data->hi - data->lo;
    3.69 +}
    3.70 +
    3.71 +/** Get available space left in the buffer.
    3.72 + *
    3.73 + * @param data mem stream
    3.74 + * @return bytes
    3.75 + */
    3.76 +static inline int mem_room(struct MemData *data){
    3.77 +    return data->buf_n - mem_len(data);
    3.78 +}
    3.79 +
    3.80 +/** Get a pointer to the start of the data in the buffer.
    3.81 + *
    3.82 + * @param data mem stream
    3.83 + * @return lo pointer
    3.84 + */
    3.85 +static inline char * mem_lo(struct MemData *data){
    3.86 +    return data->buf + (data->lo % data->buf_n);
    3.87 +}
    3.88 +
    3.89 +/** Get a pointer to the end of the data in the buffer.
    3.90 + *
    3.91 + * @param data mem stream
    3.92 + * @return hi pointer
    3.93 + */
    3.94 +static inline char * mem_hi(struct MemData *data){
    3.95 +    return data->buf + (data->hi % data->buf_n);
    3.96 +}
    3.97 +
    3.98 +/** Get a pointer to the end of the buffer.
    3.99 + *
   3.100 + * @param data mem stream
   3.101 + * @return end pointer
   3.102 + */
   3.103 +static inline char * mem_end(struct MemData *data){
   3.104 +    return data->buf + data->buf_n;
   3.105 +}
   3.106 +
   3.107 +static int mem_error(IOStream *io);
   3.108 +static int mem_close(IOStream *io);
   3.109 +static void mem_free(IOStream *io);
   3.110 +static int mem_write(IOStream *io, const void *msg, size_t n);
   3.111 +static int mem_read(IOStream *io, void *buf, size_t n);
   3.112 +
   3.113 +/** Minimum delta used to increment the buffer. */
   3.114 +static int delta_min = 256;
   3.115 +
   3.116 +/** Methods for a memory stream. */
   3.117 +static IOMethods mem_methods = {
   3.118 +    read:  mem_read,
   3.119 +    write: mem_write,
   3.120 +    error: mem_error,
   3.121 +    close: mem_close,
   3.122 +    free:  mem_free,
   3.123 +};
   3.124 +
   3.125 +/** Get the memory stream state.
   3.126 + *
   3.127 + * @param io memory stream
   3.128 + * @return state
   3.129 + */
   3.130 +static inline MemData *get_mem_data(IOStream *io){
   3.131 +    return (MemData*)io->data;
   3.132 +}
   3.133 +
   3.134 +/** Get the number of bytes available to read.
   3.135 + *
   3.136 + * @param io memory stream
   3.137 + * @return number of bytes
   3.138 + */
   3.139 +int mem_stream_avail(IOStream *io){
   3.140 +    MemData *data = get_mem_data(io);
   3.141 +    return (data->err ? -data->err : mem_len(data));
   3.142 +}
   3.143 +
   3.144 +/** Copy bytes from a memory stream into a buffer.
   3.145 + *
   3.146 + * @param data mem stream
   3.147 + * @param buf buffer
   3.148 + * @param n number of bytes to copy
   3.149 + */
   3.150 +static void mem_get(MemData *data, char *buf, size_t n){
   3.151 +    char *start = mem_lo(data);
   3.152 +    char *end = mem_end(data);
   3.153 +    if (start + n < end) {
   3.154 +        memcpy(buf, start, n);
   3.155 +    } else {
   3.156 +        int k = end - start;
   3.157 +        memcpy(buf, start, k);
   3.158 +        memcpy(buf + k, data->buf, n - k);
   3.159 +    }
   3.160 +}
   3.161 +
   3.162 +/** Copy bytes from a buffer into a memory stream.
   3.163 + *
   3.164 + * @param data mem stream
   3.165 + * @param buf buffer
   3.166 + * @param n number of bytes to copy
   3.167 + */
   3.168 +static void mem_put(MemData *data, const char *buf, size_t n){
   3.169 +    char *start = mem_hi(data);
   3.170 +    char *end = mem_end(data);
   3.171 +    if(start + n < end){
   3.172 +        memcpy(start, buf, n);
   3.173 +    } else {
   3.174 +        int k = end - start;
   3.175 +        memcpy(start, buf, k);
   3.176 +        memcpy(data->buf, buf + k, n - k);
   3.177 +    }
   3.178 +}
   3.179 +
   3.180 +/** Expand the buffer used by a memory stream.
   3.181 + *
   3.182 + * @param data mem stream
   3.183 + * @param extra number of bytes to expand by
   3.184 + * @return 0 on success, negative error otherwise
   3.185 + */
   3.186 +static int mem_expand(MemData *data, size_t extra){
   3.187 +    int err = -ENOMEM;
   3.188 +    int delta = (extra < delta_min ? delta_min : extra);
   3.189 +    if(data->buf_max > 0){
   3.190 +        int delta_max = data->buf_max - data->buf_n;
   3.191 +        if(delta > delta_max){
   3.192 +            delta = extra;
   3.193 +            if(delta > delta_max) goto exit;
   3.194 +        }
   3.195 +    }
   3.196 +    int buf_n = data->buf_n + delta;
   3.197 +    char *buf = allocate(buf_n);
   3.198 +    if(!buf) goto exit;
   3.199 +    mem_get(data, buf, mem_len(data));
   3.200 +    data->hi = mem_len(data);
   3.201 +    data->lo = 0;
   3.202 +    deallocate(data->buf);
   3.203 +    data->buf = buf;
   3.204 +    data->buf_n = buf_n;
   3.205 +    err = 0;
   3.206 +  exit:
   3.207 +    if(err){
   3.208 +        data->err = -err;
   3.209 +    }
   3.210 +    return err;
   3.211 +}
   3.212 +
   3.213 +/** Write bytes from a buffer into a memory stream.
   3.214 + * The internal buffer is expanded as needed to hold the data,
   3.215 + * up to the stream maximum (if specified). If the buffer cannot
   3.216 + * be expanded -ENOMEM is returned.
   3.217 + *
   3.218 + * @param io mem stream
   3.219 + * @param buf buffer
   3.220 + * @param n number of bytes to write
   3.221 + * @return number of bytes written on success, negative error code otherwise
   3.222 + */
   3.223 +static int mem_write(IOStream *io, const void *msg, size_t n){
   3.224 +    MemData *data = get_mem_data(io);
   3.225 +    if(data->err) return -data->err;
   3.226 +    int room = mem_room(data);
   3.227 +    if(n > room){
   3.228 +        int err = mem_expand(data, n - room);
   3.229 +        if(err) return err;
   3.230 +    }
   3.231 +    mem_put(data, msg, n);
   3.232 +    data->hi += n;
   3.233 +    return n;
   3.234 +}
   3.235 +
   3.236 +/** Read bytes from a memory stream into a buffer.
   3.237 + *
   3.238 + * @param io mem stream
   3.239 + * @param buf buffer
   3.240 + * @param n maximum number of bytes to read
   3.241 + * @return number of bytes read on success, negative error code otherwise
   3.242 + */
   3.243 +static int mem_read(IOStream *io, void *buf, size_t n){
   3.244 +    MemData *data = get_mem_data(io);
   3.245 +    if(data->err) return -data->err;
   3.246 +    int k = mem_len(data);
   3.247 +    if(n > k){
   3.248 +        n = k;
   3.249 +    }
   3.250 +    mem_get(data, buf, n);
   3.251 +    data->lo += n;
   3.252 +    return n;
   3.253 +}
   3.254 +
   3.255 +/** Test if a memory stream has an error.
   3.256 + *
   3.257 + * @param io mem stream
   3.258 + * @return 0 if ok, error code otherwise
   3.259 + */
   3.260 +static int mem_error(IOStream *io){
   3.261 +    MemData *data = get_mem_data(io);
   3.262 +    return data->err;
   3.263 +}
   3.264 +
   3.265 +/** Close a memory stream.
   3.266 + *
   3.267 + * @param io mem stream
   3.268 + * @return 0
   3.269 + */
   3.270 +static int mem_close(IOStream *io){
   3.271 +    MemData *data = get_mem_data(io);
   3.272 +    if(!data->err){
   3.273 +        data->err = ENOTCONN;
   3.274 +    }
   3.275 +    return 0;
   3.276 +}
   3.277 +
   3.278 +/** Free a memory stream.
   3.279 + *
   3.280 + * @param io mem stream
   3.281 + */
   3.282 +static void mem_free(IOStream *io){
   3.283 +    MemData *data = get_mem_data(io);
   3.284 +    deallocate(data->buf);
   3.285 +    memzero(data, sizeof(*data));
   3.286 +    deallocate(data);
   3.287 +}
   3.288 +
   3.289 +/** Allocate and initialise a memory stream.
   3.290 + *
   3.291 + * @param buf_n initial buffer size (0 means default)
   3.292 + * @param buf_max maximum buffer size (0 means no max)
   3.293 + * @return new stream (free using IOStream_close)
   3.294 + */
   3.295 +IOStream *mem_stream_new_size(size_t buf_n, size_t buf_max){
   3.296 +    int err = -ENOMEM;
   3.297 +    MemData *data = ALLOCATE(MemData);
   3.298 +    if(!data) goto exit;
   3.299 +    IOStream *io = ALLOCATE(IOStream);
   3.300 +    if(!io) goto exit;
   3.301 +    if(buf_n <= delta_min){
   3.302 +        buf_n = delta_min;
   3.303 +    }
   3.304 +    if(buf_max > 0 && buf_max < buf_n){
   3.305 +        buf_max = buf_n;
   3.306 +    }
   3.307 +    data->buf = allocate(buf_n);
   3.308 +    if(!data->buf) goto exit;
   3.309 +    data->buf_n = buf_n;
   3.310 +    data->buf_max = buf_max;
   3.311 +    io->methods = &mem_methods;
   3.312 +    io->data = data;
   3.313 +    io->nofree = 0;
   3.314 +    err = 0;
   3.315 +  exit:
   3.316 +    if(err){
   3.317 +        deallocate(data);
   3.318 +        deallocate(io);
   3.319 +        io = NULL;
   3.320 +    }
   3.321 +    return io;
   3.322 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/vnet/libxutil/mem_stream.h	Mon Sep 12 14:11:59 2005 +0000
     4.3 @@ -0,0 +1,32 @@
     4.4 +/*
     4.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     4.6 + *
     4.7 + * This library is free software; you can redistribute it and/or modify
     4.8 + * it under the terms of the GNU Lesser General Public License as published by
     4.9 + * the Free Software Foundation; either version 2.1 of the License, or
    4.10 + * (at your option) any later version.
    4.11 + *
    4.12 + * This library is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU Lesser General Public License for more details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU Lesser General Public License
    4.18 + * along with this library; if not, write to the Free Software
    4.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.20 + */
    4.21 +
    4.22 +#ifndef _XUTIL_MEM_STREAM_H_
    4.23 +#define _XUTIL_MEM_STREAM_H_
    4.24 +
    4.25 +#include "iostream.h"
    4.26 +
    4.27 +extern IOStream *mem_stream_new_size(size_t buf_n, size_t buf_max);
    4.28 +
    4.29 +extern int mem_stream_avail(IOStream *io);
    4.30 +
    4.31 +static inline IOStream *mem_stream_new(void){
    4.32 +    return mem_stream_new_size(0, 0);
    4.33 +}
    4.34 +
    4.35 +#endif /* !_XUTIL_MEM_STREAM_H_ */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/vnet/vnet-module/varp_util.c	Mon Sep 12 14:11:59 2005 +0000
     5.3 @@ -0,0 +1,77 @@
     5.4 +/*
     5.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     5.6 + *
     5.7 + * This program is free software; you can redistribute it and/or modify
     5.8 + * it under the terms of the GNU General Public License as published by the 
     5.9 + * Free Software Foundation; either version 2 of the License, or (at your
    5.10 + * option) any later version.
    5.11 + * 
    5.12 + * This program is distributed in the hope that it will be useful, but
    5.13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    5.14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
    5.15 + * for more details.
    5.16 + *
    5.17 + * You should have received a copy of the GNU General Public License along
    5.18 + * with this program; if not, write to the Free software Foundation, Inc.,
    5.19 + * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
    5.20 + *
    5.21 + */
    5.22 +
    5.23 +static int hex16(char *s, uint16_t *val)
    5.24 +{
    5.25 +    int err = -EINVAL;
    5.26 +    uint16_t v = 0;
    5.27 +    
    5.28 +    for( ; *s; s++){
    5.29 +        v <<= 4;
    5.30 +        if('0' <= *s && *s <= '9'){
    5.31 +            v |= *s - '0';
    5.32 +        } else if('A' <= *s && *s <= 'F'){
    5.33 +            v |= *s - 'A' + 10;
    5.34 +        } else if('a' <= *s && *s <= 'f'){
    5.35 +            v |= *s - 'a' + 10;
    5.36 +        } else {
    5.37 +            goto exit;
    5.38 +        }
    5.39 +    }
    5.40 +    err = 0;
    5.41 +  exit:
    5.42 +    *val = (err ? 0 : v);
    5.43 +    return err;
    5.44 +}
    5.45 +
    5.46 +int VnetId_aton(const char *s, VnetId *vnet){
    5.47 +    int err = -EINVAL;
    5.48 +    const char *p, *q;
    5.49 +    uint16_t v;
    5.50 +    char buf[5];
    5.51 +    int buf_n = sizeof(buf) - 1;
    5.52 +    int i, n;
    5.53 +    const int elts_n = 8;
    5.54 +
    5.55 +    q = s;
    5.56 +    p = strchr(q, ':');
    5.57 +    i = (p ? 0 : elts_n - 1);
    5.58 +    do {
    5.59 +        if(!p){
    5.60 +            if(i < elts_n - 1) goto exit;
    5.61 +            p = s + strlen(s);
    5.62 +        }
    5.63 +        n = p - q;
    5.64 +        if(n > buf_n) goto exit;
    5.65 +        memcpy(buf, q, n);
    5.66 +        buf[n] = '\0';
    5.67 +        err = hex16(buf, &v);
    5.68 +        if(err) goto exit;
    5.69 +        vnet->u.vnet16[i] = htons(v);
    5.70 +        q = p+1;
    5.71 +        p = strchr(q, ':');
    5.72 +        i++;
    5.73 +    } while(i < elts_n);
    5.74 +    err = 0;
    5.75 +  exit:
    5.76 +    if(err){
    5.77 +        *vnet = (VnetId){};
    5.78 +    }
    5.79 +    return err;
    5.80 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/vnet/vnet-module/varp_util.h	Mon Sep 12 14:11:59 2005 +0000
     6.3 @@ -0,0 +1,142 @@
     6.4 +/*
     6.5 + * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
     6.6 + *
     6.7 + * This program is free software; you can redistribute it and/or modify
     6.8 + * it under the terms of the GNU General Public License as published by the 
     6.9 + * Free Software Foundation; either version 2 of the License, or (at your
    6.10 + * option) any later version.
    6.11 + * 
    6.12 + * This program is distributed in the hope that it will be useful, but
    6.13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    6.14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
    6.15 + * for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU General Public License along
    6.18 + * with this program; if not, write to the Free software Foundation, Inc.,
    6.19 + * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
    6.20 + *
    6.21 + */
    6.22 +#ifndef _VNET_VARP_UTIL_H
    6.23 +#define _VNET_VARP_UTIL_H
    6.24 +
    6.25 +#include "hash_table.h"
    6.26 +
    6.27 +/** Size of a string buffer to store a varp address. */
    6.28 +#define VARP_ADDR_BUF 56
    6.29 +
    6.30 +/** Size of a string buffer to store a vnet id. */
    6.31 +#define VNET_ID_BUF 56
    6.32 +
    6.33 +#ifndef NIPQUAD
    6.34 +#define NIPQUAD(addr) \
    6.35 +	((unsigned char *)&addr)[0], \
    6.36 +	((unsigned char *)&addr)[1], \
    6.37 +	((unsigned char *)&addr)[2], \
    6.38 +	((unsigned char *)&addr)[3]
    6.39 +#endif
    6.40 +
    6.41 +#ifndef NIP6
    6.42 +#define NIP6(addr) \
    6.43 +	ntohs((addr).s6_addr16[0]), \
    6.44 +	ntohs((addr).s6_addr16[1]), \
    6.45 +	ntohs((addr).s6_addr16[2]), \
    6.46 +	ntohs((addr).s6_addr16[3]), \
    6.47 +	ntohs((addr).s6_addr16[4]), \
    6.48 +	ntohs((addr).s6_addr16[5]), \
    6.49 +	ntohs((addr).s6_addr16[6]), \
    6.50 +	ntohs((addr).s6_addr16[7])
    6.51 +#endif
    6.52 +
    6.53 +
    6.54 +static inline const char *VarpAddr_ntoa(VarpAddr *addr, char buf[VARP_ADDR_BUF])
    6.55 +{
    6.56 +    switch(addr->family){
    6.57 +    default:
    6.58 +    case AF_INET:
    6.59 +        sprintf(buf, "%u.%u.%u.%u",
    6.60 +                NIPQUAD(addr->u.ip4));
    6.61 +        break;
    6.62 +    case AF_INET6:
    6.63 +        sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    6.64 +                NIP6(addr->u.ip6));
    6.65 +        break;
    6.66 +    }
    6.67 +    return buf;
    6.68 +}
    6.69 +
    6.70 +static inline const char *VnetId_ntoa(VnetId *vnet, char buf[VNET_ID_BUF])
    6.71 +{
    6.72 +    sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    6.73 +            ntohs(vnet->u.vnet16[0]), \
    6.74 +            ntohs(vnet->u.vnet16[1]), \
    6.75 +            ntohs(vnet->u.vnet16[2]), \
    6.76 +            ntohs(vnet->u.vnet16[3]), \
    6.77 +            ntohs(vnet->u.vnet16[4]), \
    6.78 +            ntohs(vnet->u.vnet16[5]), \
    6.79 +            ntohs(vnet->u.vnet16[6]), \
    6.80 +            ntohs(vnet->u.vnet16[7]));
    6.81 +    return buf;
    6.82 +}
    6.83 +
    6.84 +extern int VnetId_aton(const char *s, VnetId *vnet);
    6.85 +
    6.86 +/** Convert an unsigned in host order to a vnet id.
    6.87 + */
    6.88 +static inline struct VnetId toVnetId(uint32_t vnetid){
    6.89 +    struct VnetId vnet = {};
    6.90 +    vnet.u.vnet32[3] = htonl(vnetid);
    6.91 +    return vnet;
    6.92 +}
    6.93 +
    6.94 +static inline uint32_t VnetId_hash(uint32_t h, VnetId *vnet)
    6.95 +{
    6.96 +    h = hash_hul(h, vnet->u.vnet32[0]);
    6.97 +    h = hash_hul(h, vnet->u.vnet32[1]);
    6.98 +    h = hash_hul(h, vnet->u.vnet32[2]);
    6.99 +    h = hash_hul(h, vnet->u.vnet32[3]);
   6.100 +    return h;
   6.101 +}
   6.102 +
   6.103 +static inline int VnetId_eq(VnetId *vnet1, VnetId *vnet2)
   6.104 +{
   6.105 +    return memcmp(vnet1, vnet2, sizeof(VnetId)) == 0;
   6.106 +}
   6.107 +
   6.108 +static inline uint32_t VarpAddr_hash(uint32_t h, VarpAddr *addr)
   6.109 +{
   6.110 +    h = hash_hul(h, addr->family);
   6.111 +    if(addr->family == AF_INET6){
   6.112 +        h = hash_hul(h, addr->u.ip6.s6_addr32[0]);
   6.113 +        h = hash_hul(h, addr->u.ip6.s6_addr32[1]);
   6.114 +        h = hash_hul(h, addr->u.ip6.s6_addr32[2]);
   6.115 +        h = hash_hul(h, addr->u.ip6.s6_addr32[3]);
   6.116 +    } else {
   6.117 +        h = hash_hul(h, addr->u.ip4.s_addr);
   6.118 +    }
   6.119 +    return h;
   6.120 +}
   6.121 +
   6.122 +static inline int VarpAddr_eq(VarpAddr *addr1, VarpAddr*addr2)
   6.123 +{
   6.124 +    return memcmp(addr1, addr2, sizeof(VarpAddr)) == 0;
   6.125 +}
   6.126 +
   6.127 +static inline uint32_t Vmac_hash(uint32_t h, Vmac *vmac)
   6.128 +{
   6.129 +    h = hash_hul(h,
   6.130 +                 (vmac->mac[0] << 24) |
   6.131 +                 (vmac->mac[1] << 16) |
   6.132 +                 (vmac->mac[2] <<  8) |
   6.133 +                 (vmac->mac[3]      ));
   6.134 +    h = hash_hul(h, 
   6.135 +                 (vmac->mac[4] <<   8) |
   6.136 +                 (vmac->mac[5]       ));
   6.137 +    return h;
   6.138 +}
   6.139 +
   6.140 +static inline int Vmac_eq(Vmac *vmac1, Vmac *vmac2)
   6.141 +{
   6.142 +    return memcmp(vmac1, vmac2, sizeof(Vmac)) == 0;
   6.143 +}
   6.144 +
   6.145 +#endif /* _VNET_VARP_UTIL_H */