summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjason <jason@openbsd.org>2001-02-03 21:38:38 +0000
committerjason <jason@openbsd.org>2001-02-03 21:38:38 +0000
commitb8b0b912de97f17498aa7ab828c03253c36b3655 (patch)
treec24c077b8bbdf920db95b7d35a05cddfb76f9314
parentViolent cleanup of the code. Lots of effort duplication removed. (diff)
downloadwireguard-openbsd-b8b0b912de97f17498aa7ab828c03253c36b3655.tar.xz
wireguard-openbsd-b8b0b912de97f17498aa7ab828c03253c36b3655.zip
- define and use EtherIP version 3 (2 byte padded header instead of the
single byte header used in V2), and drop support for V2. - that done, remove some of the buffer copies that were used as alignment shims
-rw-r--r--sys/netinet/ip_ether.c40
-rw-r--r--sys/netinet/ip_ether.h7
2 files changed, 15 insertions, 32 deletions
diff --git a/sys/netinet/ip_ether.c b/sys/netinet/ip_ether.c
index 158eb350936..12688994052 100644
--- a/sys/netinet/ip_ether.c
+++ b/sys/netinet/ip_ether.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ether.c,v 1.22 2001/02/03 19:45:03 jason Exp $ */
+/* $OpenBSD: ip_ether.c,v 1.23 2001/02/03 21:38:38 jason Exp $ */
/*
* The author of this code is Angelos D. Keromytis (kermit@adk.gr)
@@ -97,8 +97,7 @@ etherip_input(m, va_alist)
{
union sockaddr_union ssrc, sdst;
struct ether_header eh;
- struct mbuf *mrest, *m0;
- int iphlen, clen;
+ int iphlen;
struct etherip_header eip;
u_int8_t v;
va_list ap;
@@ -154,6 +153,14 @@ etherip_input(m, va_alist)
return;
}
+ /* Finally, the pad value must be zero. */
+ if (eip.eip_pad) {
+ DPRINTF(("etherip_input(): received EtherIP invalid pad value\n"));
+ etheripstat.etherip_adrops++;
+ m_freem(m);
+ return;
+ }
+
/* Make sure the ethernet header at least is in the first mbuf. */
if (m->m_len < iphlen + sizeof(struct ether_header) +
sizeof(struct etherip_header)) {
@@ -221,32 +228,6 @@ etherip_input(m, va_alist)
/* Trim the beginning of the mbuf, to remove the ethernet header */
m_adj(m, sizeof(struct ether_header));
- /* Copy out the first MHLEN bytes of data to ensure correct alignment */
- MGETHDR(m0, M_DONTWAIT, MT_DATA);
- if (m0 == NULL) {
- m_freem(m);
- etheripstat.etherip_adrops++;
- return;
- }
- M_COPY_PKTHDR(m0, m);
- clen = min(MHLEN, m->m_pkthdr.len);
- if (m->m_pkthdr.len == clen)
- mrest = NULL;
- else {
- mrest = m_split(m, clen, M_DONTWAIT);
- if (mrest == NULL) {
- m_freem(m);
- m_freem(m0);
- etheripstat.etherip_adrops++;
- return;
- }
- }
- m0->m_next = mrest;
- m0->m_len = clen;
- m_copydata(m, 0, clen, mtod(m0, caddr_t));
- m_freem(m);
- m = m0;
-
#if NGIF > 0
/* Find appropriate gif(4) interface */
for (i = 0; i < ngif; i++) {
@@ -414,6 +395,7 @@ etherip_output(struct mbuf *m, struct tdb *tdb, struct mbuf **mp, int skip,
/* Set the version number */
eip.eip_ver = ETHERIP_VERSION & ETHERIP_VER_VERS_MASK;
+ eip.eip_pad = 0;
m_copyback(m, hlen - sizeof(struct etherip_header),
sizeof(struct etherip_header), (caddr_t)&eip);
diff --git a/sys/netinet/ip_ether.h b/sys/netinet/ip_ether.h
index 975f56e59a0..322ba90c956 100644
--- a/sys/netinet/ip_ether.h
+++ b/sys/netinet/ip_ether.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_ether.h,v 1.8 2001/02/03 19:45:04 jason Exp $ */
+/* $OpenBSD: ip_ether.h,v 1.9 2001/02/03 21:38:39 jason Exp $ */
/*
* The author of this code is Angelos D. Keromytis (angelos@adk.gr)
@@ -40,12 +40,13 @@ struct etheripstat {
};
struct etherip_header {
- u_int8_t eip_ver;
+ u_int8_t eip_ver; /* version/reserved */
+ u_int8_t eip_pad; /* required padding byte */
};
#define ETHERIP_VER_VERS_MASK 0x0f
#define ETHERIP_VER_RSVD_MASK 0xf0
-#define ETHERIP_VERSION 0x02
+#define ETHERIP_VERSION 0x03
/*
* Names for Ether-IP sysctl objects