[PATCH v5 03/22] VLAN: Create new data type for VLAN description.

Michael Braun michael-dev
Tue Nov 19 11:46:54 PST 2013


This hides away the details of the currently in-use VLAN model
and is preparing for adding tagged VLAN support later on.
Implementing this as inline functions lets the compiler create
as fast code as before the change.

Signed-hostap: Michael Braun <michael-dev at fami-braun.de>
---
 hostapd/Makefile  |    1 +
 src/common/vlan.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/common/vlan.h |   26 ++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 src/common/vlan.c
 create mode 100644 src/common/vlan.h

diff --git a/hostapd/Makefile b/hostapd/Makefile
index 5ceaf4e..6f888d4 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -56,6 +56,7 @@ OBJS += ../src/ap/ieee802_11_shared.o
 OBJS += ../src/ap/beacon.o
 
 OBJS_c = hostapd_cli.o ../src/common/wpa_ctrl.o ../src/utils/os_$(CONFIG_OS).o
+OBJS_c += ../src/common/vlan.o
 
 NEED_RC4=y
 NEED_AES=y
diff --git a/src/common/vlan.c b/src/common/vlan.c
new file mode 100644
index 0000000..4317a0d
--- /dev/null
+++ b/src/common/vlan.c
@@ -0,0 +1,50 @@
+/*
+ * hostapd / VLAN definitions and helpers functions
+ * Copyright (c) 2013, Michael Braun <michael-dev at fami-braun.de>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "vlan.h"
+
+void vlan_alloc(struct vlan_description *dst, const int untagged)
+{
+	dst->untagged = untagged;
+}
+
+void vlan_alloc_copy(struct vlan_description *dst,
+                     const struct vlan_description *src)
+{
+	dst->untagged = src->untagged;
+}
+
+void vlan_free(struct vlan_description *dst)
+{
+	dst->untagged = 0;
+}
+
+int vlan_cmp(const struct vlan_description *a,
+             const struct vlan_description *b)
+{
+	if (!a && !b)
+		return 1;
+	if (!a || !b)
+		return 0;
+	return (a->untagged == b->untagged);
+}
+
+int vlan_untagged(const struct vlan_description *a)
+{
+	if (!a)
+		return 0;
+	return a->untagged;
+}
+
+int vlan_notempty(const struct vlan_description *a)
+{
+	if (!a)
+		return 0;
+	return a->untagged;
+}
+
diff --git a/src/common/vlan.h b/src/common/vlan.h
new file mode 100644
index 0000000..a340ce2
--- /dev/null
+++ b/src/common/vlan.h
@@ -0,0 +1,26 @@
+/*
+ * hostapd / VLAN definitions and helpers functions
+ * Copyright (c) 2013, Michael Braun <michael-dev at fami-braun.de>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef HOSTAPD_VLAN_H
+#define HOSTAPD_VLAN_H
+
+#define VLAN_NULL (struct vlan_description) {0}
+struct vlan_description {
+	int untagged;
+};
+
+void vlan_alloc(struct vlan_description *dst, const int untagged);
+void vlan_alloc_copy(struct vlan_description *dst,
+                     const struct vlan_description *src);
+void vlan_free(struct vlan_description *dst);
+int vlan_cmp(const struct vlan_description *a,
+             const struct vlan_description *b);
+int vlan_untagged(const struct vlan_description *a);
+int vlan_notempty(const struct vlan_description *a);
+
+#endif




More information about the Hostap mailing list