/* * A generic implementation of binary search for the Linux kernel * * Copyright (C) 2008-2009 Ksplice, Inc. * Author: Tim Abbott * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; version 2. */ #include #include /* * bsearch - binary search an array of elements * @key: pointer to item being searched for * @base: pointer to first element to search * @num: number of elements * @size: size of each element * @cmp: pointer to comparison function * * This function does a binary search on the given array. The * contents of the array should already be in ascending sorted order * under the provided comparison function. * * Note that the key need not have the same type as the elements in * the array, e.g. key could be a string and the comparison function * could compare the string with the struct's name field. However, if * the key and elements in the array are of the same type, you can use * the same comparison function for both sort() and bsearch(). */ void *bsearch(const void *key, const void *base, size_t num, size_t size, int (*cmp)(const void *key, const void *elt)) { size_t start = 0, end = num; int result; while (start < end) { size_t mid = start + (end - start) / 2; result = cmp(key, base + mid * size); if (result < 0) end = mid; else if (result > 0) start = mid + 1; else return (void *)base + mid * size; } return NULL; } EXPORT_SYMBOL(bsearch); 8c3c55ca4e953044'>refslogtreecommitdiff
diff options
context:
space:
mode:
authorYotam Gigi <yotamg@mellanox.com>2017-02-01 15:30:02 +0200
committerDavid S. Miller <davem@davemloft.net>2017-02-03 15:16:45 -0500
commit1ce8460496c05379c66edc178c3c55ca4e953044 (patch)
treeb20cd3585da85f00946feb48549d5cdc7c87e2b5 /include
parent1d5e7c859e81a66674d194c346119d154d31e9dc (diff)
net: Introduce ife encapsulation module
This module is responsible for the ife encapsulation protocol encode/decode logics. That module can: - ife_encode: encode skb and reserve space for the ife meta header - ife_decode: decode skb and extract the meta header size - ife_tlv_meta_encode - encodes one tlv entry into the reserved ife header space. - ife_tlv_meta_decode - decodes one tlv entry from the packet - ife_tlv_meta_next - advance to the next tlv Reviewed-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: Yotam Gigi <yotamg@mellanox.com> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Roman Mashak <mrv@mojatatu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/net/ife.h51
-rw-r--r--include/uapi/linux/Kbuild1
-rw-r--r--include/uapi/linux/ife.h18
3 files changed, 70 insertions, 0 deletions
diff --git a/include/net/ife.h b/include/net/ife.h
new file mode 100644