Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
+/* check for problems with nulls */
+ void driver4()
+{
+ uint8_t buf[1];
+ uint32_t h,i,state[HASHSTATE];
+
+
+ buf[0] = ~0;
+ for (i=0; i<HASHSTATE; ++i) state[i] = 1;
+ printf("These should all be different\n");
+ for (i=0, h=0; i<8; ++i)
+ {
+ h = hashlittle(buf, 0, h);
+ printf("%2ld 0-byte strings, hash is %.8x\n", i, h);
+ }
+}
+
+void driver5()
+{
+ uint32_t b,c;
+ b=0, c=0, hashlittle2("", 0, &c, &b);
+ printf("hash is %.8lx %.8lx\n", c, b); /* deadbeef deadbeef */
+ b=0xdeadbeef, c=0, hashlittle2("", 0, &c, &b);
+ printf("hash is %.8lx %.8lx\n", c, b); /* bd5b7dde deadbeef */
+ b=0xdeadbeef, c=0xdeadbeef, hashlittle2("", 0, &c, &b);
+ printf("hash is %.8lx %.8lx\n", c, b); /* 9c093ccd bd5b7dde */
+ b=0, c=0, hashlittle2("Four score and seven years ago", 30, &c, &b);
+ printf("hash is %.8lx %.8lx\n", c, b); /* 17770551 ce7226e6 */
+ b=1, c=0, hashlittle2("Four score and seven years ago", 30, &c, &b);
+ printf("hash is %.8lx %.8lx\n", c, b); /* e3607cae bd371de4 */
+ b=0, c=1, hashlittle2("Four score and seven years ago", 30, &c, &b);
+ printf("hash is %.8lx %.8lx\n", c, b); /* cd628161 6cbea4b3 */
+ c = hashlittle("Four score and seven years ago", 30, 0);
+ printf("hash is %.8lx\n", c); /* 17770551 */
+ c = hashlittle("Four score and seven years ago", 30, 1);
+ printf("hash is %.8lx\n", c); /* cd628161 */
+}
+
+
+int main()
+{
+ driver1(); /* test that the key is hashed: used for timings */
+ driver2(); /* test that whole key is hashed thoroughly */
+ driver3(); /* test that nothing but the key is hashed */
+ driver4(); /* test hashing multiple buffers (all buffers are null) */
+ driver5(); /* test the hash against known vectors */
+ return 1;
+}
+
+#endif /* SELF_TEST */
diff --git a/package/gluon-ebtables-limit-arp/src/lookup3.h b/package/gluon-ebtables-limit-arp/src/lookup3.h
new file mode 100644
index 00000000..321ad4b6
--- /dev/null
+++ b/package/gluon-ebtables-limit-arp/src/lookup3.h
@@ -0,0 +1,6 @@
+#include <stdint.h> /* defines uint32_t etc */
+
+uint32_t hashword(
+const uint32_t *k, /* the key, an array of uint32_t values */
+size_t length, /* the length of the key, in uint32_ts */
+uint32_t initval); /* the previous hash, or an arbitrary value */
diff --git a/package/gluon-ebtables-limit-arp/src/mac.c b/package/gluon-ebtables-limit-arp/src/mac.c
new file mode 100644
index 00000000..863c540e
--- /dev/null
+++ b/package/gluon-ebtables-limit-arp/src/mac.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2017 Linus Lüssing <linus.luessing@c0d3.blue>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ * License-Filename: LICENSE
+ */
+
+#include <linux/if_ether.h>
+#include <stdio.h>
+#include <string.h>
+#include "mac.h"
+
+#define ETH_STRLEN (sizeof("aa:bb:cc:dd:ee:ff") - 1)
+
+char mntoa_buf[ETH_STRLEN+1];
+
+int mac_aton(const char *cp, struct mac_addr *mac)
+{
+ struct mac_addr m;
+ int ret;
+
+ if (strlen(cp) != ETH_STRLEN)
+ return 0;
+
+ memset(&m, 0, sizeof(m));
+
+ ret = sscanf(cp, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+ &m.storage[0], &m.storage[1], &m.storage[2],
+ &m.storage[3], &m.storage[4], &m.storage[5]);
+
+ if (ret != ETH_ALEN)
+ return 0;
+
+ *mac = m;
+ return 1;
+}
+
+char *mac_ntoa(struct mac_addr *mac)
+{
+ unsigned char *m = mac->storage;
+
+ snprintf(mntoa_buf, sizeof(mntoa_buf),
+ "%02x:%02x:%02x:%02x:%02x:%02x",
+ m[0], m[1], m[2], m[3], m[4], m[5]);
+
+ return mntoa_buf;
+}
diff --git a/package/gluon-ebtables-limit-arp/src/mac.h b/package/gluon-ebtables-limit-arp/src/mac.h
new file mode 100644
index 00000000..11567ade
--- /dev/null
+++ b/package/gluon-ebtables-limit-arp/src/mac.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Linus Lüssing <linus.luessing@c0d3.blue>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ * License-Filename: LICENSE
+ */
+
+#ifndef _MAC_H_
+#define _MAC_H_
+
+struct mac_addr {
+ /* 8 instead of 6 for multiples of uint32_t for hashword() */
+ unsigned char storage[8];
+};
+
+int mac_aton(const char *cp, struct mac_addr *mac);
+char *mac_ntoa(struct mac_addr *mac);
+
+static inline int mac_is_multicast(struct mac_addr *addr)
+{
+ return addr->storage[0] & 0x01;
+}
+
+#endif /* _MAC_H_ */
--
2.11.0