summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2003-12-17 12:40:34 +0000
committerru <ru@FreeBSD.org>2003-12-17 12:40:34 +0000
commit1df45259591c8233ac65b0031774b50f3b791df4 (patch)
treecb79deb87f430caf11f013eff4540c587f790642 /sys
parent6c49c65d276d185a38c2dffb97067fbb1faf4b60 (diff)
downloadFreeBSD-src-1df45259591c8233ac65b0031774b50f3b791df4.zip
FreeBSD-src-1df45259591c8233ac65b0031774b50f3b791df4.tar.gz
Made the Ethernet address parse type standard.
OK'ed by: archie
Diffstat (limited to 'sys')
-rw-r--r--sys/netgraph/ng_bridge.c6
-rw-r--r--sys/netgraph/ng_ether.c59
-rw-r--r--sys/netgraph/ng_ether.h5
-rw-r--r--sys/netgraph/ng_parse.c58
-rw-r--r--sys/netgraph/ng_parse.h8
5 files changed, 69 insertions, 67 deletions
diff --git a/sys/netgraph/ng_bridge.c b/sys/netgraph/ng_bridge.c
index 445f3e6..b352890 100644
--- a/sys/netgraph/ng_bridge.c
+++ b/sys/netgraph/ng_bridge.c
@@ -77,7 +77,6 @@
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/ng_bridge.h>
-#include <netgraph/ng_ether.h>
#ifdef NG_SEPARATE_MALLOC
MALLOC_DEFINE(M_NETGRAPH_BRIDGE, "netgraph_bridge", "netgraph bridge node ");
@@ -172,7 +171,7 @@ ng_bridge_getTableLength(const struct ng_parse_type *type,
/* Parse type for struct ng_bridge_host_ary */
static const struct ng_parse_struct_field ng_bridge_host_type_fields[]
- = NG_BRIDGE_HOST_TYPE_INFO(&ng_ether_enaddr_type);
+ = NG_BRIDGE_HOST_TYPE_INFO(&ng_parse_enaddr_type);
static const struct ng_parse_type ng_bridge_host_type = {
&ng_parse_struct_type,
&ng_bridge_host_type_fields
@@ -287,9 +286,6 @@ static struct ng_type ng_bridge_typestruct = {
};
NETGRAPH_INIT(bridge, &ng_bridge_typestruct);
-/* Depend on ng_ether so we can use the Ethernet parse type */
-MODULE_DEPEND(ng_bridge, ng_ether, 1, 1, 1);
-
/******************************************************************
NETGRAPH NODE METHODS
******************************************************************/
diff --git a/sys/netgraph/ng_ether.c b/sys/netgraph/ng_ether.c
index 8cfd053..b1756d0 100644
--- a/sys/netgraph/ng_ether.c
+++ b/sys/netgraph/ng_ether.c
@@ -109,19 +109,6 @@ static ng_rcvdata_t ng_ether_rcvdata;
static ng_disconnect_t ng_ether_disconnect;
static int ng_ether_mod_event(module_t mod, int event, void *data);
-/* Parse type for an Ethernet address */
-static ng_parse_t ng_enaddr_parse;
-static ng_unparse_t ng_enaddr_unparse;
-const struct ng_parse_type ng_ether_enaddr_type = {
- NULL,
- NULL,
- NULL,
- ng_enaddr_parse,
- ng_enaddr_unparse,
- NULL, /* no such thing as a "default" EN address */
- 0
-};
-
/* List of commands and how to convert arguments to/from ASCII */
static const struct ng_cmdlist ng_ether_cmdlist[] = {
{
@@ -143,13 +130,13 @@ static const struct ng_cmdlist ng_ether_cmdlist[] = {
NGM_ETHER_GET_ENADDR,
"getenaddr",
NULL,
- &ng_ether_enaddr_type
+ &ng_parse_enaddr_type
},
{
NGM_ETHER_COOKIE,
NGM_ETHER_SET_ENADDR,
"setenaddr",
- &ng_ether_enaddr_type,
+ &ng_parse_enaddr_type,
NULL
},
{
@@ -653,48 +640,6 @@ ng_ether_disconnect(hook_p hook)
return (0);
}
-static int
-ng_enaddr_parse(const struct ng_parse_type *type,
- const char *s, int *const off, const u_char *const start,
- u_char *const buf, int *const buflen)
-{
- char *eptr;
- u_long val;
- int i;
-
- if (*buflen < ETHER_ADDR_LEN)
- return (ERANGE);
- for (i = 0; i < ETHER_ADDR_LEN; i++) {
- val = strtoul(s + *off, &eptr, 16);
- if (val > 0xff || eptr == s + *off)
- return (EINVAL);
- buf[i] = (u_char)val;
- *off = (eptr - s);
- if (i < ETHER_ADDR_LEN - 1) {
- if (*eptr != ':')
- return (EINVAL);
- (*off)++;
- }
- }
- *buflen = ETHER_ADDR_LEN;
- return (0);
-}
-
-static int
-ng_enaddr_unparse(const struct ng_parse_type *type,
- const u_char *data, int *off, char *cbuf, int cbuflen)
-{
- int len;
-
- len = snprintf(cbuf, cbuflen, "%02x:%02x:%02x:%02x:%02x:%02x",
- data[*off], data[*off + 1], data[*off + 2],
- data[*off + 3], data[*off + 4], data[*off + 5]);
- if (len >= cbuflen)
- return (ERANGE);
- *off += ETHER_ADDR_LEN;
- return (0);
-}
-
/******************************************************************
INITIALIZATION
******************************************************************/
diff --git a/sys/netgraph/ng_ether.h b/sys/netgraph/ng_ether.h
index 013b433..98a0b4c 100644
--- a/sys/netgraph/ng_ether.h
+++ b/sys/netgraph/ng_ether.h
@@ -65,10 +65,5 @@ enum {
NGM_ETHER_SET_AUTOSRC, /* enable/disable src addr override */
};
-#ifdef _KERNEL
-/* Ethernet address parse type */
-extern const struct ng_parse_type ng_ether_enaddr_type;
-#endif /* _KERNEL */
-
#endif /* _NETGRAPH_NG_ETHER_H_ */
diff --git a/sys/netgraph/ng_parse.c b/sys/netgraph/ng_parse.c
index cff5fcb..58389e8 100644
--- a/sys/netgraph/ng_parse.c
+++ b/sys/netgraph/ng_parse.c
@@ -48,6 +48,8 @@
#include <sys/malloc.h>
#include <sys/ctype.h>
+#include <net/ethernet.h>
+
#include <netinet/in.h>
#include <netgraph/ng_message.h>
@@ -999,6 +1001,62 @@ const struct ng_parse_type ng_parse_ipaddr_type = {
};
/************************************************************************
+ ETHERNET ADDRESS TYPE
+ ************************************************************************/
+
+static int
+ng_enaddr_parse(const struct ng_parse_type *type,
+ const char *s, int *const off, const u_char *const start,
+ u_char *const buf, int *const buflen)
+{
+ char *eptr;
+ u_long val;
+ int i;
+
+ if (*buflen < ETHER_ADDR_LEN)
+ return (ERANGE);
+ for (i = 0; i < ETHER_ADDR_LEN; i++) {
+ val = strtoul(s + *off, &eptr, 16);
+ if (val > 0xff || eptr == s + *off)
+ return (EINVAL);
+ buf[i] = (u_char)val;
+ *off = (eptr - s);
+ if (i < ETHER_ADDR_LEN - 1) {
+ if (*eptr != ':')
+ return (EINVAL);
+ (*off)++;
+ }
+ }
+ *buflen = ETHER_ADDR_LEN;
+ return (0);
+}
+
+static int
+ng_enaddr_unparse(const struct ng_parse_type *type,
+ const u_char *data, int *off, char *cbuf, int cbuflen)
+{
+ int len;
+
+ len = snprintf(cbuf, cbuflen, "%02x:%02x:%02x:%02x:%02x:%02x",
+ data[*off], data[*off + 1], data[*off + 2],
+ data[*off + 3], data[*off + 4], data[*off + 5]);
+ if (len >= cbuflen)
+ return (ERANGE);
+ *off += ETHER_ADDR_LEN;
+ return (0);
+}
+
+const struct ng_parse_type ng_parse_enaddr_type = {
+ NULL,
+ NULL,
+ NULL,
+ ng_enaddr_parse,
+ ng_enaddr_unparse,
+ NULL,
+ 0
+};
+
+/************************************************************************
BYTE ARRAY TYPE
************************************************************************/
diff --git a/sys/netgraph/ng_parse.h b/sys/netgraph/ng_parse.h
index 00b8240..e8df669 100644
--- a/sys/netgraph/ng_parse.h
+++ b/sys/netgraph/ng_parse.h
@@ -442,6 +442,14 @@ extern const struct ng_parse_type ng_parse_hint64_type;
extern const struct ng_parse_type ng_parse_ipaddr_type;
/*
+ * ETHERNET ADDRESS TYPE
+ *
+ * Default value: None
+ * Additional info: None required
+ */
+extern const struct ng_parse_type ng_parse_enaddr_type;
+
+/*
* VARIABLE LENGTH BYTE ARRAY TYPE
*
* The bytes are displayed in hex. The ASCII form may be either an
OpenPOWER on IntegriCloud