2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
29 #include "byte-order.h"
31 #include "openvswitch/types.h"
34 VLOG_DEFINE_THIS_MODULE(util);
36 COVERAGE_DEFINE(util_xalloc);
38 /* argv[0] without directory names. */
39 const char *program_name;
41 /* Ordinarily "" but set to "monitor" for a monitor process or "worker" for a
43 const char *subprogram_name = "";
45 /* --version option output. */
46 static char *program_version;
51 ovs_abort(0, "virtual memory exhausted");
55 xcalloc(size_t count, size_t size)
57 void *p = count && size ? calloc(count, size) : malloc(1);
58 COVERAGE_INC(util_xalloc);
68 return xcalloc(1, size);
74 void *p = malloc(size ? size : 1);
75 COVERAGE_INC(util_xalloc);
83 xrealloc(void *p, size_t size)
85 p = realloc(p, size ? size : 1);
86 COVERAGE_INC(util_xalloc);
94 xmemdup(const void *p_, size_t size)
96 void *p = xmalloc(size);
102 xmemdup0(const char *p_, size_t length)
104 char *p = xmalloc(length + 1);
105 memcpy(p, p_, length);
111 xstrdup(const char *s)
113 return xmemdup0(s, strlen(s));
117 xvasprintf(const char *format, va_list args)
123 va_copy(args2, args);
124 needed = vsnprintf(NULL, 0, format, args);
126 s = xmalloc(needed + 1);
128 vsnprintf(s, needed + 1, format, args2);
135 x2nrealloc(void *p, size_t *n, size_t s)
137 *n = *n == 0 ? 1 : 2 * *n;
138 return xrealloc(p, *n * s);
142 xasprintf(const char *format, ...)
147 va_start(args, format);
148 s = xvasprintf(format, args);
154 /* Similar to strlcpy() from OpenBSD, but it never reads more than 'size - 1'
155 * bytes from 'src' and doesn't return anything. */
157 ovs_strlcpy(char *dst, const char *src, size_t size)
160 size_t len = strnlen(src, size - 1);
161 memcpy(dst, src, len);
166 /* Copies 'src' to 'dst'. Reads no more than 'size - 1' bytes from 'src'.
167 * Always null-terminates 'dst' (if 'size' is nonzero), and writes a zero byte
168 * to every otherwise unused byte in 'dst'.
170 * Except for performance, the following call:
171 * ovs_strzcpy(dst, src, size);
172 * is equivalent to these two calls:
173 * memset(dst, '\0', size);
174 * ovs_strlcpy(dst, src, size);
176 * (Thus, ovs_strzcpy() is similar to strncpy() without some of the pitfalls.)
179 ovs_strzcpy(char *dst, const char *src, size_t size)
182 size_t len = strnlen(src, size - 1);
183 memcpy(dst, src, len);
184 memset(dst + len, '\0', size - len);
188 /* Prints 'format' on stderr, formatting it like printf() does. If 'err_no' is
189 * nonzero, then it is formatted with ovs_retval_to_string() and appended to
190 * the message inside parentheses. Then, terminates with abort().
192 * This function is preferred to ovs_fatal() in a situation where it would make
193 * sense for a monitoring process to restart the daemon.
195 * 'format' should not end with a new-line, because this function will add one
198 ovs_abort(int err_no, const char *format, ...)
202 va_start(args, format);
203 ovs_abort_valist(err_no, format, args);
206 /* Same as ovs_abort() except that the arguments are supplied as a va_list. */
208 ovs_abort_valist(int err_no, const char *format, va_list args)
210 ovs_error_valist(err_no, format, args);
214 /* Prints 'format' on stderr, formatting it like printf() does. If 'err_no' is
215 * nonzero, then it is formatted with ovs_retval_to_string() and appended to
216 * the message inside parentheses. Then, terminates with EXIT_FAILURE.
218 * 'format' should not end with a new-line, because this function will add one
221 ovs_fatal(int err_no, const char *format, ...)
225 va_start(args, format);
226 ovs_fatal_valist(err_no, format, args);
229 /* Same as ovs_fatal() except that the arguments are supplied as a va_list. */
231 ovs_fatal_valist(int err_no, const char *format, va_list args)
233 ovs_error_valist(err_no, format, args);
237 /* Prints 'format' on stderr, formatting it like printf() does. If 'err_no' is
238 * nonzero, then it is formatted with ovs_retval_to_string() and appended to
239 * the message inside parentheses.
241 * 'format' should not end with a new-line, because this function will add one
244 ovs_error(int err_no, const char *format, ...)
248 va_start(args, format);
249 ovs_error_valist(err_no, format, args);
253 /* Same as ovs_error() except that the arguments are supplied as a va_list. */
255 ovs_error_valist(int err_no, const char *format, va_list args)
257 int save_errno = errno;
259 if (subprogram_name[0]) {
260 fprintf(stderr, "%s(%s): ", program_name, subprogram_name);
262 fprintf(stderr, "%s: ", program_name);
265 vfprintf(stderr, format, args);
267 fprintf(stderr, " (%s)", ovs_retval_to_string(err_no));
274 /* Many OVS functions return an int which is one of:
277 * - EOF: end of file (not necessarily an error; depends on the function called)
279 * Returns the appropriate human-readable string. The caller must copy the
280 * string if it wants to hold onto it, as the storage may be overwritten on
281 * subsequent function calls.
284 ovs_retval_to_string(int retval)
286 static char unknown[48];
292 return strerror(retval);
295 return "End of file";
297 snprintf(unknown, sizeof unknown, "***unknown return value: %d***", retval);
301 /* Sets global "program_name" and "program_version" variables. Should
302 * be called at the beginning of main() with "argv[0]" as the argument
305 * 'version' should contain the version of the caller's program. If 'version'
306 * is the same as the VERSION #define, the caller is assumed to be part of Open
307 * vSwitch. Otherwise, it is assumed to be an external program linking against
308 * the Open vSwitch libraries.
310 * The 'date' and 'time' arguments should likely be called with
311 * "__DATE__" and "__TIME__" to use the time the binary was built.
312 * Alternatively, the "set_program_name" macro may be called to do this
316 set_program_name__(const char *argv0, const char *version, const char *date,
319 const char *slash = strrchr(argv0, '/');
320 program_name = slash ? slash + 1 : argv0;
322 free(program_version);
324 if (!strcmp(version, VERSION)) {
325 program_version = xasprintf("%s (Open vSwitch) "VERSION"\n"
327 program_name, date, time);
329 program_version = xasprintf("%s %s\n"
330 "Open vSwitch Library "VERSION"\n"
332 program_name, version, date, time);
336 /* Returns a pointer to a string describing the program version. The
337 * caller must not modify or free the returned string.
340 get_program_version(void)
342 return program_version;
345 /* Print the version information for the program. */
347 ovs_print_version(uint8_t min_ofp, uint8_t max_ofp)
349 printf("%s", program_version);
350 if (min_ofp || max_ofp) {
351 printf("OpenFlow versions %#x:%#x\n", min_ofp, max_ofp);
355 /* Writes the 'size' bytes in 'buf' to 'stream' as hex bytes arranged 16 per
356 * line. Numeric offsets are also included, starting at 'ofs' for the first
357 * byte in 'buf'. If 'ascii' is true then the corresponding ASCII characters
358 * are also rendered alongside. */
360 ovs_hex_dump(FILE *stream, const void *buf_, size_t size,
361 uintptr_t ofs, bool ascii)
363 const uint8_t *buf = buf_;
364 const size_t per_line = 16; /* Maximum bytes per line. */
368 size_t start, end, n;
371 /* Number of bytes on this line. */
372 start = ofs % per_line;
374 if (end - start > size)
379 fprintf(stream, "%08jx ", (uintmax_t) ROUND_DOWN(ofs, per_line));
380 for (i = 0; i < start; i++)
381 fprintf(stream, " ");
383 fprintf(stream, "%02hhx%c",
384 buf[i - start], i == per_line / 2 - 1? '-' : ' ');
387 for (; i < per_line; i++)
388 fprintf(stream, " ");
389 fprintf(stream, "|");
390 for (i = 0; i < start; i++)
391 fprintf(stream, " ");
392 for (; i < end; i++) {
393 int c = buf[i - start];
394 putc(c >= 32 && c < 127 ? c : '.', stream);
396 for (; i < per_line; i++)
397 fprintf(stream, " ");
398 fprintf(stream, "|");
400 fprintf(stream, "\n");
409 str_to_int(const char *s, int base, int *i)
412 bool ok = str_to_llong(s, base, &ll);
418 str_to_long(const char *s, int base, long *li)
421 bool ok = str_to_llong(s, base, &ll);
427 str_to_llong(const char *s, int base, long long *x)
429 int save_errno = errno;
432 *x = strtoll(s, &tail, base);
433 if (errno == EINVAL || errno == ERANGE || tail == s || *tail != '\0') {
444 str_to_uint(const char *s, int base, unsigned int *u)
446 return str_to_int(s, base, (int *) u);
450 str_to_ulong(const char *s, int base, unsigned long *ul)
452 return str_to_long(s, base, (long *) ul);
456 str_to_ullong(const char *s, int base, unsigned long long *ull)
458 return str_to_llong(s, base, (long long *) ull);
461 /* Converts floating-point string 's' into a double. If successful, stores
462 * the double in '*d' and returns true; on failure, stores 0 in '*d' and
465 * Underflow (e.g. "1e-9999") is not considered an error, but overflow
466 * (e.g. "1e9999)" is. */
468 str_to_double(const char *s, double *d)
470 int save_errno = errno;
473 *d = strtod(s, &tail);
474 if (errno == EINVAL || (errno == ERANGE && *d != 0)
475 || tail == s || *tail != '\0') {
485 /* Returns the value of 'c' as a hexadecimal digit. */
490 case '0': case '1': case '2': case '3': case '4':
491 case '5': case '6': case '7': case '8': case '9':
517 /* Returns the integer value of the 'n' hexadecimal digits starting at 's', or
518 * UINT_MAX if one of those "digits" is not really a hex digit. If 'ok' is
519 * nonnull, '*ok' is set to true if the conversion succeeds or to false if a
520 * non-hex digit is detected. */
522 hexits_value(const char *s, size_t n, bool *ok)
528 for (i = 0; i < n; i++) {
529 int hexit = hexit_value(s[i]);
536 value = (value << 4) + hexit;
544 /* Returns the current working directory as a malloc()'d string, or a null
545 * pointer if the current working directory cannot be determined. */
552 /* Get maximum path length or at least a reasonable estimate. */
553 path_max = pathconf(".", _PC_PATH_MAX);
554 size = (path_max < 0 ? 1024
555 : path_max > 10240 ? 10240
558 /* Get current working directory. */
560 char *buf = xmalloc(size);
561 if (getcwd(buf, size)) {
562 return xrealloc(buf, strlen(buf) + 1);
566 if (error != ERANGE) {
567 VLOG_WARN("getcwd failed (%s)", strerror(error));
576 all_slashes_name(const char *s)
578 return xstrdup(s[0] == '/' && s[1] == '/' && s[2] != '/' ? "//"
583 /* Returns the directory name portion of 'file_name' as a malloc()'d string,
584 * similar to the POSIX dirname() function but thread-safe. */
586 dir_name(const char *file_name)
588 size_t len = strlen(file_name);
589 while (len > 0 && file_name[len - 1] == '/') {
592 while (len > 0 && file_name[len - 1] != '/') {
595 while (len > 0 && file_name[len - 1] == '/') {
598 return len ? xmemdup0(file_name, len) : all_slashes_name(file_name);
601 /* Returns the file name portion of 'file_name' as a malloc()'d string,
602 * similar to the POSIX basename() function but thread-safe. */
604 base_name(const char *file_name)
608 end = strlen(file_name);
609 while (end > 0 && file_name[end - 1] == '/') {
614 return all_slashes_name(file_name);
618 while (start > 0 && file_name[start - 1] != '/') {
622 return xmemdup0(file_name + start, end - start);
625 /* If 'file_name' starts with '/', returns a copy of 'file_name'. Otherwise,
626 * returns an absolute path to 'file_name' considering it relative to 'dir',
627 * which itself must be absolute. 'dir' may be null or the empty string, in
628 * which case the current working directory is used.
630 * Returns a null pointer if 'dir' is null and getcwd() fails. */
632 abs_file_name(const char *dir, const char *file_name)
634 if (file_name[0] == '/') {
635 return xstrdup(file_name);
636 } else if (dir && dir[0]) {
637 char *separator = dir[strlen(dir) - 1] == '/' ? "" : "/";
638 return xasprintf("%s%s%s", dir, separator, file_name);
640 char *cwd = get_cwd();
642 char *abs_name = xasprintf("%s/%s", cwd, file_name);
651 /* Like readlink(), but returns the link name as a null-terminated string in
652 * allocated memory that the caller must eventually free (with free()).
653 * Returns NULL on error, in which case errno is set appropriately. */
655 xreadlink(const char *filename)
659 for (size = 64; ; size *= 2) {
660 char *buf = xmalloc(size);
661 ssize_t retval = readlink(filename, buf, size);
664 if (retval >= 0 && retval < size) {
677 /* Returns a version of 'filename' with symlinks in the final component
678 * dereferenced. This differs from realpath() in that:
680 * - 'filename' need not exist.
682 * - If 'filename' does exist as a symlink, its referent need not exist.
684 * - Only symlinks in the final component of 'filename' are dereferenced.
686 * The caller must eventually free the returned string (with free()). */
688 follow_symlinks(const char *filename)
694 fn = xstrdup(filename);
695 for (i = 0; i < 10; i++) {
699 if (lstat(fn, &s) != 0 || !S_ISLNK(s.st_mode)) {
703 linkname = xreadlink(fn);
705 VLOG_WARN("%s: readlink failed (%s)", filename, strerror(errno));
709 if (linkname[0] == '/') {
710 /* Target of symlink is absolute so use it raw. */
713 /* Target of symlink is relative so add to 'fn''s directory. */
714 char *dir = dir_name(fn);
716 if (!strcmp(dir, ".")) {
719 char *separator = dir[strlen(dir) - 1] == '/' ? "" : "/";
720 next_fn = xasprintf("%s%s%s", dir, separator, linkname);
731 VLOG_WARN("%s: too many levels of symlinks", filename);
733 return xstrdup(filename);
736 /* Pass a value to this function if it is marked with
737 * __attribute__((warn_unused_result)) and you genuinely want to ignore
738 * its return value. (Note that every scalar type can be implicitly
739 * converted to bool.) */
740 void ignore(bool x OVS_UNUSED) { }
742 /* Returns an appropriate delimiter for inserting just before the 0-based item
743 * 'index' in a list that has 'total' items in it. */
745 english_list_delimiter(size_t index, size_t total)
747 return (index == 0 ? ""
748 : index < total - 1 ? ", "
749 : total > 2 ? ", and "
753 /* Given a 32 bit word 'n', calculates floor(log_2('n')). This is equivalent
754 * to finding the bit position of the most significant one bit in 'n'. It is
755 * an error to call this function with 'n' == 0. */
757 log_2_floor(uint32_t n)
761 #if !defined(UINT_MAX) || !defined(UINT32_MAX)
762 #error "Someone screwed up the #includes."
763 #elif __GNUC__ >= 4 && UINT_MAX == UINT32_MAX
764 return 31 - __builtin_clz(n);
769 #define BIN_SEARCH_STEP(BITS) \
770 if (n >= (1 << BITS)) { \
779 #undef BIN_SEARCH_STEP
785 /* Given a 32 bit word 'n', calculates ceil(log_2('n')). It is an error to
786 * call this function with 'n' == 0. */
788 log_2_ceil(uint32_t n)
790 return log_2_floor(n) + !IS_POW2(n);
793 /* Returns the number of trailing 0-bits in 'n'. Undefined if 'n' == 0. */
794 #if !defined(UINT_MAX) || !defined(UINT32_MAX)
795 #error "Someone screwed up the #includes."
796 #elif __GNUC__ >= 4 && UINT_MAX == UINT32_MAX
797 /* Defined inline in util.h. */
805 #define CTZ_STEP(X) \
822 /* Returns the number of 1-bits in 'x', between 0 and 32 inclusive. */
826 /* In my testing, this implementation is over twice as fast as any other
827 * portable implementation that I tried, including GCC 4.4
828 * __builtin_popcount(), although nonportable asm("popcnt") was over 50%
831 ((((X) & (1 << 0)) != 0) + \
832 (((X) & (1 << 1)) != 0) + \
833 (((X) & (1 << 2)) != 0) + \
834 (((X) & (1 << 3)) != 0) + \
835 (((X) & (1 << 4)) != 0) + \
836 (((X) & (1 << 5)) != 0) + \
837 (((X) & (1 << 6)) != 0) + \
838 (((X) & (1 << 7)) != 0))
839 #define INIT2(X) INIT1(X), INIT1((X) + 1)
840 #define INIT4(X) INIT2(X), INIT2((X) + 2)
841 #define INIT8(X) INIT4(X), INIT4((X) + 4)
842 #define INIT16(X) INIT8(X), INIT8((X) + 8)
843 #define INIT32(X) INIT16(X), INIT16((X) + 16)
844 #define INIT64(X) INIT32(X), INIT32((X) + 32)
846 static const uint8_t popcount8[256] = {
847 INIT64(0), INIT64(64), INIT64(128), INIT64(192)
850 return (popcount8[x & 0xff] +
851 popcount8[(x >> 8) & 0xff] +
852 popcount8[(x >> 16) & 0xff] +
856 /* Returns true if the 'n' bytes starting at 'p' are zeros. */
858 is_all_zeros(const uint8_t *p, size_t n)
862 for (i = 0; i < n; i++) {
870 /* Returns true if the 'n' bytes starting at 'p' are 0xff. */
872 is_all_ones(const uint8_t *p, size_t n)
876 for (i = 0; i < n; i++) {
884 /* Copies 'n_bits' bits starting from bit 'src_ofs' in 'src' to the 'n_bits'
885 * starting from bit 'dst_ofs' in 'dst'. 'src' is 'src_len' bytes long and
886 * 'dst' is 'dst_len' bytes long.
888 * If you consider all of 'src' to be a single unsigned integer in network byte
889 * order, then bit N is the bit with value 2**N. That is, bit 0 is the bit
890 * with value 1 in src[src_len - 1], bit 1 is the bit with value 2, bit 2 is
891 * the bit with value 4, ..., bit 8 is the bit with value 1 in src[src_len -
892 * 2], and so on. Similarly for 'dst'.
894 * Required invariants:
895 * src_ofs + n_bits <= src_len * 8
896 * dst_ofs + n_bits <= dst_len * 8
897 * 'src' and 'dst' must not overlap.
900 bitwise_copy(const void *src_, unsigned int src_len, unsigned int src_ofs,
901 void *dst_, unsigned int dst_len, unsigned int dst_ofs,
904 const uint8_t *src = src_;
907 src += src_len - (src_ofs / 8 + 1);
910 dst += dst_len - (dst_ofs / 8 + 1);
913 if (src_ofs == 0 && dst_ofs == 0) {
914 unsigned int n_bytes = n_bits / 8;
918 memcpy(dst, src, n_bytes);
925 uint8_t mask = (1 << n_bits) - 1;
926 *dst = (*dst & ~mask) | (*src & mask);
930 unsigned int max_copy = 8 - MAX(src_ofs, dst_ofs);
931 unsigned int chunk = MIN(n_bits, max_copy);
932 uint8_t mask = ((1 << chunk) - 1) << dst_ofs;
935 *dst |= ((*src >> src_ofs) << dst_ofs) & mask;
952 /* Zeros the 'n_bits' bits starting from bit 'dst_ofs' in 'dst'. 'dst' is
953 * 'dst_len' bytes long.
955 * If you consider all of 'dst' to be a single unsigned integer in network byte
956 * order, then bit N is the bit with value 2**N. That is, bit 0 is the bit
957 * with value 1 in dst[dst_len - 1], bit 1 is the bit with value 2, bit 2 is
958 * the bit with value 4, ..., bit 8 is the bit with value 1 in dst[dst_len -
961 * Required invariant:
962 * dst_ofs + n_bits <= dst_len * 8
965 bitwise_zero(void *dst_, unsigned int dst_len, unsigned dst_ofs,
974 dst += dst_len - (dst_ofs / 8 + 1);
978 unsigned int chunk = MIN(n_bits, 8 - dst_ofs);
980 *dst &= ~(((1 << chunk) - 1) << dst_ofs);
990 while (n_bits >= 8) {
996 *dst &= ~((1 << n_bits) - 1);
1000 /* Sets to 1 all of the 'n_bits' bits starting from bit 'dst_ofs' in 'dst'.
1001 * 'dst' is 'dst_len' bytes long.
1003 * If you consider all of 'dst' to be a single unsigned integer in network byte
1004 * order, then bit N is the bit with value 2**N. That is, bit 0 is the bit
1005 * with value 1 in dst[dst_len - 1], bit 1 is the bit with value 2, bit 2 is
1006 * the bit with value 4, ..., bit 8 is the bit with value 1 in dst[dst_len -
1009 * Required invariant:
1010 * dst_ofs + n_bits <= dst_len * 8
1013 bitwise_one(void *dst_, unsigned int dst_len, unsigned dst_ofs,
1014 unsigned int n_bits)
1016 uint8_t *dst = dst_;
1022 dst += dst_len - (dst_ofs / 8 + 1);
1026 unsigned int chunk = MIN(n_bits, 8 - dst_ofs);
1028 *dst |= ((1 << chunk) - 1) << dst_ofs;
1038 while (n_bits >= 8) {
1044 *dst |= (1 << n_bits) - 1;
1048 /* Scans the 'n_bits' bits starting from bit 'dst_ofs' in 'dst' for 1-bits.
1049 * Returns false if any 1-bits are found, otherwise true. 'dst' is 'dst_len'
1052 * If you consider all of 'dst' to be a single unsigned integer in network byte
1053 * order, then bit N is the bit with value 2**N. That is, bit 0 is the bit
1054 * with value 1 in dst[dst_len - 1], bit 1 is the bit with value 2, bit 2 is
1055 * the bit with value 4, ..., bit 8 is the bit with value 1 in dst[dst_len -
1058 * Required invariant:
1059 * dst_ofs + n_bits <= dst_len * 8
1062 bitwise_is_all_zeros(const void *p_, unsigned int len, unsigned int ofs,
1063 unsigned int n_bits)
1065 const uint8_t *p = p_;
1071 p += len - (ofs / 8 + 1);
1075 unsigned int chunk = MIN(n_bits, 8 - ofs);
1077 if (*p & (((1 << chunk) - 1) << ofs)) {
1089 while (n_bits >= 8) {
1097 if (n_bits && *p & ((1 << n_bits) - 1)) {
1104 /* Copies the 'n_bits' low-order bits of 'value' into the 'n_bits' bits
1105 * starting at bit 'dst_ofs' in 'dst', which is 'dst_len' bytes long.
1107 * If you consider all of 'dst' to be a single unsigned integer in network byte
1108 * order, then bit N is the bit with value 2**N. That is, bit 0 is the bit
1109 * with value 1 in dst[dst_len - 1], bit 1 is the bit with value 2, bit 2 is
1110 * the bit with value 4, ..., bit 8 is the bit with value 1 in dst[dst_len -
1113 * Required invariants:
1114 * dst_ofs + n_bits <= dst_len * 8
1118 bitwise_put(uint64_t value,
1119 void *dst, unsigned int dst_len, unsigned int dst_ofs,
1120 unsigned int n_bits)
1122 ovs_be64 n_value = htonll(value);
1123 bitwise_copy(&n_value, sizeof n_value, 0,
1124 dst, dst_len, dst_ofs,
1128 /* Returns the value of the 'n_bits' bits starting at bit 'src_ofs' in 'src',
1129 * which is 'src_len' bytes long.
1131 * If you consider all of 'src' to be a single unsigned integer in network byte
1132 * order, then bit N is the bit with value 2**N. That is, bit 0 is the bit
1133 * with value 1 in src[src_len - 1], bit 1 is the bit with value 2, bit 2 is
1134 * the bit with value 4, ..., bit 8 is the bit with value 1 in src[src_len -
1137 * Required invariants:
1138 * src_ofs + n_bits <= src_len * 8
1142 bitwise_get(const void *src, unsigned int src_len,
1143 unsigned int src_ofs, unsigned int n_bits)
1145 ovs_be64 value = htonll(0);
1147 bitwise_copy(src, src_len, src_ofs,
1148 &value, sizeof value, 0,
1150 return ntohll(value);