Skip to content
Snippets Groups Projects
0007-backport-gluon-ebtables-limit-arp.patch 73.8 KiB
Newer Older
+/* 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